Skip to main content

Module memory_summary

Module memory_summary 

Source
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 document
    • memory_summary.md — compact summary injected at session start
    • skills/<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.ts
  • packages/coding-agent/src/memories/storage.ts
  • packages/coding-agent/src/memory-backend/local-backend.ts
  • packages/coding-agent/src/prompts/memories/*.md
  • packages/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§

ConsolidationFile
One file under skills/<name>/<bucket>/<path>.
ConsolidationOutput
JSON payload returned by the Stage-2 LLM.
ConsolidationSkill
A consolidated skill as supplied by the Stage-2 model.
Stage1OutputShape
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.md kept 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.md exists.
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.md exists.
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.md and <memory_root>/memory_summary.md if present. Either can be None if the file does not exist.
memory_root
Resolve <home>/.oxicode/memory/<encoded-cwd>/ for the current cwd. Mirrors encodeProjectPath in omp’s index.ts: let encoded = "--" + cwd.trim_start_matches(['/','\\']).replace(['/','\\',':'], "-") + "--";
parse_consolidation_output
Parse a strict-JSON consolidation payload (Stage-2 model output) into the ConsolidationOutput shape. 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.md with 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.