Files
oh-my-pi/packages/coding-agent/src/memory-backend/local-backend.ts
T
metaphorics 9662844853 feat(coding-agent): support the local memory backend in the learn tool
The `learn` tool previously required a `hindsight`/`mnemopi` backend. It now
also works when `memory.backend` is `local` (the file-based rollout backend):
lessons append to a `learned.md` under the project's memory root, kept separate
from the consolidation artifacts so a consolidation pass never clobbers them,
and are injected into future sessions alongside the memory summary.

- memories: `saveLearnedLesson` (newest-first, deduped, count- and per-field
  size-capped, secret-redacted, injection-neutralized) with per-path write
  serialization; `buildMemoryToolDeveloperInstructions` reads `learned.md` and
  shares one injection budget with the summary; `redactSecrets` extended with
  GitHub/npm/Slack/Google token prefixes.
- local backend: implements `save()`; status reports `writable: true`.
- learn tool: `local` execute branch; `createIf`/`isToolAllowed`/auto-include
  and the standing guidance extended to `local`; local saves tier as a `write`
  approval.
- read-path prompt: renders the learned-lessons block when present.
- Lessons are injection-neutralized and secret-redacted on BOTH write and read
  (they render unescaped into the system prompt).

Also moves the auto-learn CHANGELOG entry out of the released [15.12.6] section
(a cherry-pick artifact) back under [Unreleased] and notes the local backend.

Tests: local storage (format, dedup, cap, redaction incl. provider/delimiter-
split tokens, concurrency), read-back (with/without summary, off-gating, raw
hand-edited file), tool gating + write-approval tiering.
2026-06-14 12:03:13 +09:00

46 lines
1.3 KiB
TypeScript

import {
buildMemoryToolDeveloperInstructions,
clearMemoryData,
enqueueMemoryConsolidation,
saveLearnedLesson,
startMemoryStartupTask,
} from "../memories";
import type { MemoryBackend } from "./types";
/**
* Wraps the existing `memories/` module as a `MemoryBackend`.
*
* The rollout-summarisation pipeline (rollouts → SQLite → memory_summary.md) is
* delegated unchanged. On top of it, `save()` persists `learn`-tool lessons to
* `learned.md` (so `status()` reports `writable: true`); structured search is
* still unavailable.
*/
export const localBackend: MemoryBackend = {
id: "local",
start(options) {
startMemoryStartupTask(options);
},
async buildDeveloperInstructions(agentDir, settings) {
return buildMemoryToolDeveloperInstructions(agentDir, settings);
},
async clear(agentDir, cwd) {
await clearMemoryData(agentDir, cwd);
},
async enqueue(agentDir, cwd) {
enqueueMemoryConsolidation(agentDir, cwd);
},
async save(context, input) {
return saveLearnedLesson(context.agentDir, context.cwd, input);
},
async status() {
return {
backend: "local" as const,
active: true,
writable: true,
searchable: false,
message:
"Local rollout-summary memory is active; lessons from the `learn` tool are saved to learned.md. Structured search is not available.",
};
},
};