Skip to content

Let a plugin read memories by id with getMemories - #46

Merged
kriszyp merged 3 commits into
mainfrom
feat/get-memories-by-id
Nov 13, 2026
Merged

kriszyp merged 3 commits into
mainfrom
feat/get-memories-by-id

Conversation

@kriszyp

@kriszyp kriszyp commented Nov 13, 2026 •

Copy link
Copy Markdown
Member
Kris's daughter sends three dogs to fetch the datefruit clusters tagged one to five, and they come back in tag order with one tag unmatched

⊙ Problem

A plugin that builds data from memories, such as cluster summaries, must re-read specific memories' current text and vectors. scanMemories only walks every memory in creation order. Without a by-id read, the plugin would copy text and vectors into its own table, and withdrawal, the content flag and rescoping would have to clear that copy too (#36).

💡 Solution

  • getMemories(ids) returns the rows for those ids, in the order asked. Unknown ids are left out.
  • Rows match scanMemories rows, embedding included, in every status. The caller decides eligibility.
  • Trusted in-process code only: no principal, no scope check.
  • It reaches the running plugin from another app, as scanMemories does.
  • DESIGN.md and the changelog cover it. No version bump.

🤔 One search per 100 ids, not one get per id

Reviewers suggested Memory.get for each id. I kept the search: the repo already uses an or search over ids for sets. It uses a get only for a single id (src/provenance.ts). The brief asked for batched reads. Nothing here measures either way, and the PR claims no speedup. Switch if a benchmark favors gets.

⚖️ Alternatives

  • scanMemories and filter by id — walks every row; a missing id forces a full walk.
  • Consumer reads the table itself — skips the runtime registry, so another app's copy would not reach the running plugin.
  • Consumer keeps its own copy of text and vectors — withdrawal, the flag and rescoping would have to clear it too.

Planning verdict better-alternative-exists (a get per id) was overruled as above.

🔧 Changes

✅ Verification

  • npm test: 477 of 477 pass on Node 26.2 (new: order, omitted ids, every status, batching, failure, bad input, cross-app forwarding, older-runtime fallback). CI runs Node 22 and 24.
  • npm run test:integration: 75 of 75 pass on a real Harper, including a second app that calls getMemories under both module loaders.
  • Not a snapshot: rows are read as each query runs. A plugin building output from several rows must guard its publication and recheck eligibility (DESIGN.md says so).

🤖 Generated by Claude Sonnet 5.5 via Claude Code; posted via @kriszyp.

Related PRs: #45 independent (merged; this adds getMemories beside its scanMemories)
Complexity: medium

Deferred findings

Origin — the dispatch brief this PR was written from

Add getMemories(ids) to agent-memory: a trusted, in-process read of Memory rows by id for derived-index plugins, beside the scanMemories added in PR #45 (Let another plugin scan memories and add bootstrap sections and search annotations). Export it from the package index and publish it on the runtime registry exactly as scanMemories is (additive MemoryRuntime member; a copy of the package in another app forwards to the running plugin). Update DESIGN.md Extension points and CHANGELOG [Unreleased]. Do not cut the release; 0.1.5 is released right after this merges.

Acceptance

Unit tests: returns found rows in input order with embedding and scopes, omits unknown ids, returns withdrawn/superseded rows; cross-app test (same pattern as the scanMemories cross-copy test) shows a second package copy forwarding to the running plugin. DESIGN.md and CHANGELOG updated. CI green on Node 22 and 24. Do not bump the version or release.

Dispatch: task agent-memory-get-memories · queued by kris-session · ran by claude/sonnet/high · worker kzyp-xps-1

Ready-For-Promotion: fa429d7 urgency=normal late=none

Review-Coverage: authored=claude; ran=cursor-composer,gemini,codex; adjudicated=domain; declined=cursor-grok,muse; rounds=3; full=3 @ fa429d7

Review-Attention: read ~3m (decisions: do-less-alternative, requirement-shift, missing-id-omitted, all-statuses-by-default, size-limit-advisory, all-status-read, missing-ids-dropped, array-not-iterable, or-search-batching) @ fa429d7

kriszyp and others added 3 commits November 12, 2026 22:27
A derived-index plugin that re-summarizes a cluster needs its members' current text and embeddings. Reading them by id beside scanMemories keeps memory content in one place, where withdrawal, the content flag and rescoping already apply.

Dispatch-Task: agent-memory-get-memories
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… older-runtime paths

Dispatch-Task: agent-memory-get-memories
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…op narrating comments

Dispatch-Task: agent-memory-get-memories
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@kriszyp
kriszyp marked this pull request as ready for review November 13, 2026 06:03
@kriszyp
kriszyp merged commit a40f74d into main Nov 13, 2026
2 checks passed
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