Expand description
Autonomous memory pipeline (omp local-backend port).
Implements the documented two-phase background job used by the
local memory backend in omp:
- Phase 1 (per-session extraction): for each past session that has changed since it was last processed, an LLM is asked to distill durable signal. The output is a single small JSON record per thread.
- Phase 2 (cross-session consolidation): periodically, the
extraction outputs are fed to a second LLM pass that produces
three artifacts on disk under
<memory-root>/:MEMORY.md— long-term memory documentmemory_summary.md— compact summary injected at session startskills/<name>/SKILL.md(+ optional scripts/templates/examples)
This module is intentionally self-contained: it owns its own
SQLite tables (via the same MemoryDb connection as the rest of
the memory store when present, otherwise a separate file) so the
pipeline can run independently of MemoryBackend. The background
spawn hook lives in services::start_memory_pipeline (wired from
bootstrap).
Code-only reference ports (MIT):
packages/coding-agent/src/memories/index.tspackages/coding-agent/src/memories/storage.tspackages/coding-agent/src/memory-backend/local-backend.tspackages/coding-agent/src/prompts/memories/*.mdpackages/coding-agent/src/internal-urls/memory-protocol.ts
Phases 1 and 2 require an LLM Model + Provider (oxicode-ai). When
neither is available, the worker logs once and skips — the
pipeline never panics and never blocks session boot.
All helpers here are functional (no global state, no side effects on import). The runtime spawn is opt-in.
Structs§
- Consolidation
File - One file under
skills/<name>/<bucket>/<path>. - Consolidation
Output - JSON payload returned by the Stage-2 LLM.
- Consolidation
Skill - A consolidated skill as supplied by the Stage-2 model.
- Stage1
Output Shape - Stage-1 output JSON shape (omp
stage_one_system.md).
Constants§
- CONSOLIDATION_
SYSTEM_ PROMPT - System prompt for cross-session consolidation (omp
consolidation_system.md). - CONSOLIDATION_
USER_ TEMPLATE - User-turn template for cross-session consolidation (omp
consolidation.md). Variables:{{raw_memories}}(joined string of stage1 outputs),{{rollout_summaries}}(joined string). - DEFAULT_
GLOBAL_ HEARTBEAT_ SECONDS - Phase 2 heartbeat refresh interval (must be < lease).
- DEFAULT_
GLOBAL_ LEASE_ SECONDS - Lease seconds for Phase 2 ownership tokens (prevents two oxicode processes from double-consolidating).
- DEFAULT_
MAX_ ROLLOUTS_ PER_ STARTUP - Hard cap on the number of sessions processed per startup.
- DEFAULT_
MAX_ ROLLOUT_ AGE_ DAYS - Sessions older than this are not processed by Phase 1.
- DEFAULT_
MIN_ ROLLOUT_ IDLE_ HOURS - Sessions active more recently than this are skipped (still in use).
- DEFAULT_
MODEL_ TOKEN_ BUDGET - Token cap passed to the model for Stage 1 / Stage 2 inputs.
- DEFAULT_
SUMMARY_ INJECTION_ TOKEN_ LIMIT - Sum of
memory_summary.mdkept under this many bytes is read into the system prompt directly. - LEARNED_
MD - MEMORY_
MD - Filenames of the canonical artifacts under
<memory-root>/. - MEMORY_
SUMMARY_ MD - READ_
PATH_ LEARNED_ TEMPLATE - Suggested rendered block when
learned.mdexists. - READ_
PATH_ PROMPT - Read-path prompt (omp
read-path.md). Compactly injected at session start so the agent treats memory as advisory context. - READ_
PATH_ SUMMARY_ TEMPLATE - Suggested rendered block when a
memory_summary.mdexists. - STAGE_
ONE_ SYSTEM_ PROMPT - System prompt for per-session extraction (omp
stage_one_system.md). - STAGE_
ONE_ USER_ TEMPLATE - User-turn template for per-session extraction (omp
stage_one_input.md).
Functions§
- load_
consolidated_ artifacts - Load
<memory_root>/MEMORY.mdand<memory_root>/memory_summary.mdif present. Either can beNoneif the file does not exist. - memory_
root - Resolve
<home>/.oxicode/memory/<encoded-cwd>/for the current cwd. MirrorsencodeProjectPathin omp’sindex.ts:let encoded = "--" + cwd.trim_start_matches(['/','\\']).replace(['/','\\',':'], "-") + "--"; - parse_
consolidation_ output - Parse a strict-JSON consolidation payload (Stage-2 model output)
into the
ConsolidationOutputshape. Strips ```json fences defensively. - parse_
stage1_ output - Parse a strict-JSON Stage-1 payload.
- redact_
line - Redact obvious token patterns from a single line. Returns the redacted line unchanged if no patterns match.
- redact_
secrets - Redact secrets across a multi-line string.
- render_
read_ path - Render
read-path.mdwith optional summary and learned blocks. - sanitize_
skill_ name - Sanitize a model-supplied skill name into a safe directory name.
- sanitize_
skill_ relative_ path - Sanitize a path within a
skills/<bucket>/<path>so it cannot escape the bucket root. - write_
consolidation_ artifacts - Write the three consolidation artifacts under
memory_root.