Skip to content

fix: keep a small agent-memory instance safe to prune and search - #68

Merged
hmbanan666 merged 1 commit into
mainfrom
fix/agent-memory-instance
Nov 17, 2026
Merged

hmbanan666 merged 1 commit into
mainfrom
fix/agent-memory-instance

Conversation

@hmbanan666

Copy link
Copy Markdown
Owner

Fixes the feedback from a small agent-memory instance (processor off, notes written with remember, a few markdown imports). No MCP tools were added. The public tools stay search, remember, read, and timeline.

Done

P1. Prune no longer wipes rootless imports. import markdown --prune retires only sources whose recorded root is that directory. Sources imported before roots were stored are left alone unless --prune-legacy is passed. An existing folder with no markdown files is refused unless --force. A missing path is refused even with --force, and nothing is retired. context doc restore <doc id|source id> and context source restore <source id> undo a retirement.

P2. Tiny corpora can be strong. Below CONTEXT_GROUNDING_MARGIN_MIN_CORPUS records (default 6) the centroid margin is skipped and the lexical-only rules apply, so an exact match can be strong and an off-topic query stays none. Corpora of 6 or more, including the existing 7-passage margin tests, keep the margin.

P3. Search can withhold ungrounded cards. search accepts whenNone: "empty" or "keep". Omitting it follows CONTEXT_SEARCH_WHEN_NONE, which defaults to keep. empty clears sources, items, and relations, leaves grounding: "none", and sets cardsOmitted: "grounding-none".

P4. Owner CLI. context remember uses the same validation and write path as MCP remember (--area, repeatable --project, --kind note, text from arguments or stdin). context token list shows the token name, used, and lastUsed. context token revoke --name <name> revokes every token for that client name. An accepted access or CLI token, including a successful remember, sets used and lastUsed. The OAuth one-time used bit on codes and refresh tokens is unchanged.

Cheap extras. --help, no args, and an unknown command print the command list. Real command errors print their message. context project create explains the id character rules, suggests a slug when the id contains a dot, and lists existing project ids. context status prints active and retired sources, documents, knowledge items, tokens, projects, and processor on/off. Source excerpts end on a sentence or word boundary. When items is empty and the processor is off, search adds itemsHint.

Skipped

None of the requested items. A missing folder is not prunable with --force; there is no import root to match, so the command refuses and retires nothing.

Evidence

pnpm run check (lint, typecheck, tests): 55 files, 283 tests, all passed.

Friction

  1. The slow part was reading how used is stored. On the order of a quarter hour, in src/auth-store.ts and src/oauth.ts, not waiting on a tool. TokenRecord.used is the one-time replay bit for authorization codes and refresh tokens. lastUsed lived only on the client and was updated for every accepted bearer token. context token list showed used and hid both the name and any timestamp, so a CLI token that had successfully called remember still looked unused. Setup, pnpm install, and pnpm run check were fast (install about 4s, full check about 27s). One CLI test failed because the help text says remember, not context remember; that was a one-line assertion fix.
  2. No workaround a healthy repo should not need. The margin floor is 6 because the existing public margin tests use 7 passages and had to keep the margin path. That constraint is commented next to the default.
  3. scripts/context.ts turned almost every failure into Context command failed, including the usage error it had just built, so CLI requires CONTEXT_PUBLIC_URL never reached the terminal. docs/imports.md documented the fix: report processor-off and prune removed markdown #67 regression as intended behavior: a rootless source was treated as part of whichever folder was pruned. Import failures still emit a fixed JSON reason unless the message matches a small allowlist, so a new import error can stay opaque. vp check and vp test print a note that the built-in command is not the npm script. That did not block the run.
  4. A comment on markdownPruneCandidates that rootless rows are not members of every folder, and a comment that the public margin tests assume a corpus of at least 7, would have made the two constants obvious. Separating the OAuth replay bit from a display lastUsed on the token record would have made the token-list bug a direct edit instead of a cross-file read.
Open in Web Open in Cursor 

Prune no longer retires markdown sources that have no recorded root
unless --prune-legacy is set, and an empty folder is refused unless
--force. Corpora under six records skip the centroid margin so an exact
match can be strong. Search can return no cards when grounding is none.
The owner CLI can remember, restore a retirement, and see token use.

Co-authored-by: Nick Kosarev <nick@kosarev.space>
@hmbanan666
hmbanan666 merged commit 30c6f09 into main Nov 17, 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.

2 participants