Skip to main content

Runtime recall wiring

Wiring that lets every governed harness read the durable KB with bounded automatic recall. Writes are always explicit (,ai-kb remember); hooks never auto-write capsules. Skill contract: ~/.agents/skills/k-ai-kb/SKILL.md.

Persistence vs injection

PathBehavior
Explicit,ai-kb search / get / remember — any harness with CLI or agent-pull
AutomaticOnly where a safe context-injection channel exists; gated and capped

Runtimes without injection (e.g. Cursor cloud) retain explicit search/write only.

Harness matrix

Shared scripts: session_context.py (start), perturn_recall.py (per-turn), worklog_dispatcher.sh (post-tool). Adapters in repo under home/dot_* / exact_hooks/.

RuntimeSession start and warm-upPer-turn recallWorklogException
CursorsessionStart; AI_EMBED_WARM=1beforeSubmitPromptshell/tool/edit hooksTop-level additional_context; 10,000-character carrier
ClaudeSessionStart; AI_EMBED_WARM=1UserPromptSubmitPostToolUse*Local llama.cpp settings excluded
CodexSessionStart; AI_EMBED_WARM=1UserPromptSubmitPostToolUseAbsolute paths, shell wrappers, hook-specific output; re-trust after hook changes
CopilotSDK onSessionStart; payload warm-uponUserPromptSubmittedonPostToolUse*Parent-session env affects subagent writes and status/note; startup recall stays blind
OpenCodesystem transform; payload warm-upchat.messagetool.execute.afterAdapter synthesizes the shared payload shape
Pisession_start ensure; first before_agent_startbefore_agent_starttool_resultUses session-aware ,agent-memory status --json
GeminiSessionStart; AI_EMBED_WARM=1BeforeAgentAfterTool
Cursor cloudnonenonenoneExplicit agent-pull only

Shared prefix source: prefix.txt. Custom subagent profiles render it directly; manual tmux prompt wrapping uses the same text.

Without warm-up signal: session context includes ### Recall Notice (self-search mid-task). AI_AGENT_DEPTH=fast skips warm-up and per-turn retrieval.

Startup warm-start (BM25 only)

Gates in session_context.py — all must pass:

GateRule
TopicNamed via .session-topic-<id>.txt; not current or session-*
SpecNon-empty <topic>.txt becomes query
LaneBM25 only; no embedder in hook timeout
Scopeworkspace-local, domain, or universal
Output≤3 capsules under ### Relevant Learnings (,ai-kb)

Review/unbound topics: no warm-start. Separate from resident embedder warm-up (per-turn path only).

Per-turn recall gates

perturn_recall.py / Pi ai-kb-recall.tshybrid mode, dedupe via .recall-seen-<session-key>.json:

GateValue
Querycurrent prompt
Absolute cosine0.55 (best row, not rank-0 — RRF order is relevance-blind)
Relative tail floor0.85 of best cosine (0.60 for BM25 warm-start)
Scopeworkspace-local, domain, universal via --workspace-gate
Connect-onlyAI_EMBED_CONNECT_ONLY=1; unavailable worker → omit block, continue

Queries travel over stdin and are never written to process arguments. Tail trimming drops weak rows without reordering BM25 or fused/MMR results. Correction patterns may inject an anti-pattern note directive; durable writes still require verified remember.

Depth profiles (AI_AGENT_DEPTH)

Unset/invalid → balanced.

DepthBM25 startupResident warm-upFetch/injectPrompt cap (chars)Body cap (chars)Timeout
fastyesskippeddisabled
balancedyesrequested6 / 36002406s
deepyesrequested12 / 512003609s

fast removes per-turn retrieval, not thresholds. Budgets fixture-backed: recall_worklog_state_machine.py. AI_KB_RECALL_TIMEOUT can raise per-turn timeout only.

Store boundaries

,ai-kb is the sole durable semantic store. Codex auto-memory pinned off (memories = false). /tmp/specs archived daily to ~/.local/share/agent-specs-archive/ (raw preservation; no auto-KB write).

Sources and verification