Skip to content

feat: memory anchors — independent searchable file bookmarks - #18

Merged
wefio merged 4 commits into
mainfrom
docs/memory-anchors
Sep 2, 2026
Merged

feat: memory anchors — independent searchable file bookmarks#18
wefio merged 4 commits into
mainfrom
docs/memory-anchors

Conversation

@wefio

@wefio wefio commented Sep 2, 2026

Copy link
Copy Markdown
Owner

What

First-principles redesign of how an Agent reaches file content through NMG (docs/design/memory-anchors-design.md). Drops the full-text file index in favor of sparse, Agent-authored anchors (bookmarks) as an independent searchable source.

Problem: the Agent repeatedly searches around for things it already knows exist. NMG memory stores "there is this thing", but not "where it lives". The old file-content-source (full-text file index) was usable but maintenance-heavy (scope file, incremental crawler, file FTS) and returned unanchored trigram fragments.

Design (first principles): three layers — memory (long-lived, "there is this thing"), anchor/bookmark ("its content is here"), file (content host). The Agent remembers that a thing exists; anchors cheaply and objectively reach its content. No need to remember file:line (high-churn, fragile) — the anchor relocates by content snippet.

Changes

  • store: anchors table + FTS (label/snippet); remember() writes anchor rows and auto-appends anchor_ref markers (open markers channel, zero migration); searchAnchors/getAnchorsByIds.
  • service: remember accepts anchors; search returns anchor hits resolved to current line (snippet relocation, stale when absent).
  • CLI: --anchor PATH::SNIPPET[::LABEL] on remember; ANCHORS: section on human search output.
  • DSH plugin: nmg_remember accepts anchors; search surface renders anchor=path:line.
  • tests: anchors.test.ts (write/markers/search/duplicate).
  • docs: memory-anchors-design.md; file-content-source-design.md marked superseded.

Verification

  • Verified end-to-end on the real store: remember with anchor → search returns ANCHORS: docs/design/memory-anchors-design.md:43 anchors 设计决策节 (snippet resolved to line 43).
  • Stale detection verified (snippet absent → "(stale)").
  • tsc clean, docs:check 0 errors, complexity gate passes, core tests green.

Supersedes the file-content-source full-text file index design (#17).

First-principles redesign of how an Agent reaches file content through NMG.
Drops the full-text file index (file-content-source) in favor of sparse,
Agent-authored anchors: independent searchable rows (path, snippet, label),
content-anchored (relocation not line numbers), linked to memory via the
open-string markers channel (anchor_ref). Writing is active; recall is
active + passive. Surveyed haido/gptme/agentic-bookmarks/ai-memory for the
anchor + objective-staleness pattern.

File-content-source-design is marked superseded; its 'files are not memory'
and separated-presentation conclusions carry forward.
Implements the memory-anchors design (docs/design/memory-anchors-design.md):
file bookmarks attached to memories, searchable alongside memory.

- store: anchors table + anchors_fts (label/snippet) in schema; remember()
  writes anchor rows and auto-appends anchor_ref markers (open markers
  channel, zero migration on existing data); searchAnchors/getAnchorsByIds
  in retrieval mixin. Duplicate memory writes do not duplicate anchors.
- service: remember params accept anchors; search attaches resolved anchor
  hits (snippet relocated to line against projectDir, stale when absent).
- CLI: --anchor PATH::SNIPPET[::LABEL] on remember; ANCHORS: section on
  human search output.
- DSH plugin: nmg_remember accepts anchors; search surface renders
  anchor=path:line entries.
- tests: anchors.test.ts covers write/markers/search/duplicate paths.

Complexity gate passes; write path refactored into #planAnchorWrites /
#insertAnchorRows / mergeMarkers to hold rememberInner at baseline.
- remove unused AnchorRecord import in service
- extract readLinesSafe module helper (no useless assignment)
- prettier formatting on touched files
Template guides PR description (what/why/changes) and pre-merge checks:
local quality (verify:static, test:product), RCP (board goal, agent:verify
reconcile, owned files only), and CI completion via the CI Status Snapshot
(.nmg-ci/status.json conclusion=success, failures=[]) instead of polling
individual jobs. Aligns with ci-cd-and-quality.md proof-before-trust.
@wefio
wefio merged commit e1763b8 into main Sep 2, 2026
7 checks passed
@wefio
wefio deleted the docs/memory-anchors branch September 2, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant