TokenCap 將專案決策連結至適用程式碼,供 AI 編碼智能體使用
Project Memory for AI Coding Agents: Decisions Linked to the Code They Cover
TokenCap 現以專案記憶記錄保存決策、限制、注意事項及慣例,並按適用檔案將記錄加入 AI 編碼智能體的任務資料包。記錄儲存在儲存庫的 `.tokencap/memory/records.json`,每次最多加入 8 條、約 300 tokens;錨定程式碼變動時會標記為過時,工作階段擷取的提案則須人工審批。
Every repository has rules that live in someone's head. "Totals are rounded in one place only." "Don't call the payment client from a request handler." An AI coding agent never sees them unless someone pastes them into the chat again, every session.
TokenCap now stores these as project memory records and hands them to the agent with the code they apply to.
What a record is
A record has a kind (decision, constraint, gotcha or convention), a title, some text, and anchors: the files, or file and function, it applies to.
tokencap analyze memory add --kind decision \
--title "Totals are rounded to cents" \
--text "round() in src/money.js is the only rounding rule." \
--anchor src/invoice.js --anchor src/money.js:round
Records are stored in .tokencap/memory/records.json, inside your repository. Nothing is sent anywhere.
How the agent gets them
When you run tokencap ask "<task>", the task pack picks the files for the task as before. Then it adds the accepted records anchored to those files, at most 8 records and about 300 tokens, so memory can't crowd out code. A project with no records gets no memory section at all.
The same records reach agents through the MCP server (tokencap_manage_adr lists, adds, edits and supersedes them). Existing ADRs keep their own store and show up as adr-<n>.
How records stay true
A rule that no longer matches the code is worse than no rule. So when the code a record is anchored to changes, the record is flagged stale.
tokencap analyze memory stale # records whose anchored code changed
tokencap analyze memory confirm --id 1 # still true
tokencap analyze memory supersede --id 1 --title "..." # replaced by a newer rule
Session capture feeds the same store, with a person in the loop. Approving a captured session proposes its decisions as records. They are never accepted automatically: you review them with tokencap analyze memory list --proposed and approve the ones that are right. The session handoff lists the proposals next to the records for the files the session changed.
Two smaller changes
- Next step everywhere.
make,ask,analyze review,diff,healthandupdateend with oneNext:line. If the index is stale, that comes first. - Test guidance. Change review lists the tests to run, and where a missing test would go under your repository's own naming convention.
What did not change
File selection. I ran the full benchmark (235 tasks across four splits) after these changes, and recall, edit-site coverage and the median token ratio are identical to before, task by task. The 91% recall and 80% edit-site targets are still open, and I'll report on them when they move.
Install or update:
npm install -g tokencap
tokencap make
來源:DEV Community · dev.to