claude-mem-lite 6.30.15 → 6.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +22 -0
- package/README.zh-CN.md +10 -0
- package/format-utils.mjs +6 -2
- package/hook.mjs +4 -2
- package/lib/edge-attribution.mjs +6 -3
- package/lib/error-recall-core.mjs +1 -1
- package/lib/error-recall-gate.mjs +58 -1
- package/lib/file-edge-match.mjs +92 -3
- package/lib/recall-shown.mjs +19 -6
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/scripts/pre-tool-recall.js +64 -7
- package/search-scoring.mjs +5 -0
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"plugins": [
|
|
10
10
|
{
|
|
11
11
|
"name": "claude-mem-lite",
|
|
12
|
-
"version": "6.
|
|
12
|
+
"version": "6.31.0",
|
|
13
13
|
"source": "./",
|
|
14
14
|
"homepage": "https://github.com/sdsrss/claude-mem-lite",
|
|
15
15
|
"description": "Persistent long-term memory for Claude Code via MCP — captures coding decisions, bugfixes, and context across sessions. FTS5 BM25 keyword search with episode batching. Single SQLite DB, no external services. A lighter, lower-cost alternative to claude-mem (episode batching + a smaller model; cost savings are an internal estimate, not a measured benchmark)."
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-mem-lite",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.31.0",
|
|
4
4
|
"description": "Persistent long-term memory for Claude Code via MCP — captures coding decisions, bugfixes, and context across sessions. FTS5 BM25 keyword search with episode batching. Single SQLite DB, no external services. A lighter, lower-cost alternative to claude-mem (episode batching + a smaller model; cost savings are an internal estimate, not a measured benchmark).",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "sdsrss"
|
package/README.md
CHANGED
|
@@ -239,6 +239,25 @@ rm -rf ~/claude-mem-lite/ # unhidden data dir from before the first release (n
|
|
|
239
239
|
repos/ # Shallow-cloned source repos
|
|
240
240
|
```
|
|
241
241
|
|
|
242
|
+
## Upgrading to 6.31.0
|
|
243
|
+
|
|
244
|
+
**Recall injects less that does not apply to the step at hand; nothing to run, and the schema
|
|
245
|
+
version stays 49.** Each change that drops an injection has a switch back; to undo the text
|
|
246
|
+
changes, pin `claude-mem-lite@6.30.15`.
|
|
247
|
+
|
|
248
|
+
- **PreToolUse recall no longer injects the lesson of a same-named file in another directory of
|
|
249
|
+
the project** (`src/mcp/server/mod.rs` when you edit `src/snapshot/mod.rs`). Bare names, worktree
|
|
250
|
+
copies, paths outside the project, spellings that cannot be placed and paths that name no file
|
|
251
|
+
now (a file that moved) still match. Back: `CLAUDE_MEM_PRETOOL_PATH_PRECISION=off`.
|
|
252
|
+
- **Error recall shows a thread a memory once while the thread lasts**, not once per 30 minutes.
|
|
253
|
+
Back: `CLAUDE_MEM_ERROR_RECALL_REPEAT_MIN=30`.
|
|
254
|
+
- **Error recall reads an exit-0 git command's output without the commit records git prints** (a
|
|
255
|
+
subject such as `fix: a traceback on …`) and stays silent when nothing left reads as a failure;
|
|
256
|
+
the record shapes are listed under `CLAUDE_MEM_ERROR_RECALL_GIT_RECORD` below. Back:
|
|
257
|
+
`CLAUDE_MEM_ERROR_RECALL_GIT_RECORD=off`.
|
|
258
|
+
- **Text only:** the error-recall block no longer ends with `→ Use mem_get(…)`; the MCP server
|
|
259
|
+
instructions list the flags of `defer add` and `save`. Details in CHANGELOG.md.
|
|
260
|
+
|
|
242
261
|
## Upgrading to 6.29.0
|
|
243
262
|
|
|
244
263
|
**Chinese text in lessons, facts, concepts and aliases becomes searchable, and the database opens
|
|
@@ -1205,6 +1224,7 @@ claude-mem-lite.
|
|
|
1205
1224
|
| `CLAUDE_MEM_SUMMARY_TAIL` | `0`/`off` stops Stop from using the head of the final reply (first 120 characters, code blocks and line-leading markers removed) as a session's Completed line when that reply has no Done / Not done / Failed / Uncertain section; Completed then falls back to observation titles, as before v6.18.0; a line already written gives way to the titles at the session's next turn. A later reply under 400 characters does not replace an earlier one. | _(on)_ |
|
|
1206
1225
|
| `CLAUDE_MEM_EPISODE_INPUT_FILTER` | What the episode summarizer may learn from. A subagent's tool calls stay out of the episode buffer unless they edit a file inside the project, and mutation probes (mutate → RED run → restore) and the agent's own failing inline scripts (a patch's `anchor not found`) are dropped before a window is saved or summarized — replayed over the 30 audited events, this removes 3 of the 16 that were wrong outright; with `CLAUDE_MEM_LESSON_GROUNDING` none of the 16 lessons is injected. `off` restores the unfiltered input. | _(on)_ |
|
|
1207
1226
|
| `CLAUDE_MEM_BASH_RECALL` | File recall before a Bash command that views (`cat`, `sed -n`, `head`…) or writes (`sed -i`, `cat > f`, a python patch…) a file, like the Read / Edit recall. A bash prefilter keeps Node from starting for other commands. `off` disables this leg only. | _(on)_ |
|
|
1227
|
+
| `CLAUDE_MEM_PRETOOL_PATH_PRECISION` | `off` restores the name-only file match of PreToolUse recall. **On by default** (R3 O1): a lesson recorded for a same-named file in another directory of the project (`src/mcp/server/mod.rs` when you edit `src/snapshot/mod.rs`, the root `README.md` when you edit `tasks/x/README.md`) is not injected; bare names, Claude Code worktree copies, paths outside the project, spellings that cannot be placed (`../`, `~/`, a drive letter) and paths that name no file now (a file that moved) still match. Paths are compared as POSIX paths, so on a native Windows host the match is unchanged. 210 of 4,037 injected rows on 194 transcripts were such a different file. | _(on)_ |
|
|
1208
1228
|
| `CLAUDE_MEM_LESSON_GROUNDING` | An auto-captured event keeps its lesson only when the lesson quotes the window's own diagnosis (a failing output line, a comment the edit added, or the commit message); otherwise the row is kept without it at importance 1, below every injection face. `off` keeps unquoted lessons. | _(on)_ |
|
|
1209
1229
|
| `CLAUDE_MEM_LESSON_OUTPUT_CAP` | An auto-captured lesson that shares four consecutive words with TOOL OUTPUT (a command's printed text or a tool's response, which whoever controls that output can write) is kept off the injection faces: an event keeps its row and lesson, searchable, at importance 1; a `change` observation, whose importance later reads can raise, loses the lesson, and the lesson-less row is then dropped like any other (kept only with `CLAUDE_MEM_KEEP_LOW_SIGNAL=1`). Four shared words of filler ("is not in the") count too, so a lesson quoting your own comment or commit message is demoted when it also happens to share such a run with output in the same window. The row's title is not checked. `off` restores the model's importance and the lesson. | _(on)_ |
|
|
1210
1230
|
| `MEM_NO_AUTO_ADOPT` | Global opt-out for auto-adopt (v2.82.0+). `1` stops auto-adopt across **all** projects — no injected steering, no new local file (`CLAUDE.local.md` or `.claude/rules/claude-mem-lite.md`), and no sync of an existing `CLAUDE.md` or local block (those stay, and keep loading, until `claude-mem-lite unadopt`). For per-project opt-out use `claude-mem-lite adopt --disable` instead (writes a durable `<memdir>/.mem-no-auto-adopt` sentinel that survives marker deletion). | _(disabled)_ |
|
|
@@ -1244,6 +1264,8 @@ benchmark and A/B harness are calibrated against — changing them invalidates t
|
|
|
1244
1264
|
| `CLAUDE_MEM_ERROR_RECALL_BM25_MIN` | Relevance floor for the error-recall surface (memories injected after a failed Bash command). **Off by default.** Setting it to `10.5` (the calibrated value) makes the surface stay silent when its best-matching memory is not actually about the failure — the whole set is dropped, never trimmed row-by-row. **It is a real trade, not a free win:** measured on a live database at that threshold, injections fall ~37% and ~39% of firings go silent, concentrated in projects with few memories. Off by default because nothing shows the dropped rows were noise. Explore with `node benchmark/error-recall-suite.mjs --sweep`. | `0` (off) |
|
|
1245
1265
|
| `CLAUDE_MEM_ERROR_RECALL_RERANK` | `off` restores the flat keyword ordering of the error-recall surface. **On by default**, and unlike the floor above it removes nothing: memories that share only the failed command's vocabulary are demoted below memories that mention the failure itself, and when a project has none of the latter the result is unchanged. Measured on a live database over 52 real failing commands × 15 projects: the lead memory matched no error term in 42.3% of firings before, 21.5% after, with the injected row count identical. | _(on)_ |
|
|
1246
1266
|
| `CLAUDE_MEM_ERROR_RECALL_ON_FAILURE` | `off` stops the plugin from recalling memories when a Bash command **fails at the host level**. On by default. Claude Code delivers failed tool calls to a separate `PostToolUseFailure` hook event, so before this the surface only ever saw commands that exited `0` while printing error-ish text — a genuinely failing build recalled nothing. Denials from your own guardrails (sandbox, policy hooks, declined permission prompts) and commands you interrupted are never recalled for. | _(on)_ |
|
|
1267
|
+
| `CLAUDE_MEM_ERROR_RECALL_REPEAT_MIN` | Minutes after which error recall may show a thread a memory it already showed. **By default not again while the thread lasts**: the record is cleared when the main thread's context starts over (`/compact`, `/clear`, a new session) and by the 24 h runtime GC; a subagent keeps its own record for its whole run (R3 O3; the earlier default was 30 minutes). `30` restores the old window. | _(whole thread)_ |
|
|
1268
|
+
| `CLAUDE_MEM_ERROR_RECALL_GIT_RECORD` | `off` lets error recall fire again on an exit-0 git command whose output no longer reads as a failure once the commit records git prints are set aside. **On by default** (D#717): 6 of 422 exit-0 firings on the maintainer's transcripts (2026-11-03) turned on such records alone. The records set aside are a line starting `[<branch> <sha>] `, a one-line log entry `<sha> subject` whose sha holds a letter (after any `--graph` columns), and a line starting `commit <40-hex sha>` with the header fields and indented message under it; the command must run `git log`, `show`, `commit`, `cherry-pick`, `revert`, `merge`, `rebase` or `reflog`. The rest of the output is judged as before. | _(on)_ |
|
|
1247
1269
|
| `CLAUDE_MEM_UPS_IDENTIFIER_BYPASS` | `0` disables the bypass that lets an exact identifier match skip the score floors. | _(on)_ |
|
|
1248
1270
|
| `CLAUDE_MEM_UPS_PROMPT_FALLBACK_LIMIT` | How many past-prompt rows the fallback arm may return. | `1` |
|
|
1249
1271
|
| `MEM_COVERAGE_THRESHOLD` | Fraction of query terms a memory must cover to qualify (∈ [0,1]). | `0.4` |
|
package/README.zh-CN.md
CHANGED
|
@@ -201,6 +201,15 @@ rm -rf ~/claude-mem-lite/ # 首个发布版之前的非隐藏目录(不是
|
|
|
201
201
|
repos/ # 浅克隆的源代码仓库
|
|
202
202
|
```
|
|
203
203
|
|
|
204
|
+
## 升级到 6.31.0
|
|
205
|
+
|
|
206
|
+
**召回注入的内容里,和当前这一步无关的更少了;不用执行任何操作,schema 版本仍是 49。** 每项会少注入内容的改动都有开关可以退回;要撤销纯文本的改动,请固定 `claude-mem-lite@6.30.15`。
|
|
207
|
+
|
|
208
|
+
- **PreToolUse 召回不再注入项目里另一个目录下同名文件的教训**(编辑 `src/snapshot/mod.rs` 时不再给 `src/mcp/server/mod.rs` 的)。裸文件名、worktree 副本、项目之外的路径、无法定位的写法,以及现在已不存在的路径(文件移走了)仍会匹配。退回:`CLAUDE_MEM_PRETOOL_PATH_PRECISION=off`。
|
|
209
|
+
- **同一条记忆,error recall 在同一个线程里只给一次**,不再是每 30 分钟可以再给一次。退回:`CLAUDE_MEM_ERROR_RECALL_REPEAT_MIN=30`。
|
|
210
|
+
- **error recall 读取退出码为 0 的 git 命令的输出时,先去掉 git 打印的提交记录**(比如标题 `fix: a traceback on …`),剩下的内容不再被判为失败就不注入。去掉的是三种行:以 `[<分支> <sha>] ` 开头的行;一行一条的日志 `<sha> 标题`,sha 里至少有一个字母(前面可以有 `--graph` 的列);以 `commit <40 位 sha>` 开头的行,以及它下面的头字段和缩进的提交说明。命令里必须有 `git log`、`show`、`commit`、`cherry-pick`、`revert`、`merge`、`rebase` 或 `reflog`。退回:`CLAUDE_MEM_ERROR_RECALL_GIT_RECORD=off`。
|
|
211
|
+
- **纯文本改动:** error-recall 块末尾不再有 `→ Use mem_get(…)` 这一行;MCP server instructions 列出了 `defer add` 和 `save` 的参数。详见 CHANGELOG.md。
|
|
212
|
+
|
|
204
213
|
## 升级到 6.29.0
|
|
205
214
|
|
|
206
215
|
**lesson、facts、concepts 和 aliases 里的中文变得可以搜到;更新后的数据库打开会逐步补上这些索引,不会拖住钩子。** 没有 schema 版本变化:本版打开过的数据库,6.28.1 仍能打开、搜索和写入。要退回,请等补完之后再退:还没补到的行,在 6.28.1 下会缺少粘在中文上的英文标识符。
|
|
@@ -905,6 +914,7 @@ npm run benchmark:gate # CI 门控:指标回退超过 5% 容差时失败
|
|
|
905
914
|
| `CLAUDE_MEM_SESSION_EVENTS` | 设为 `1`/`on` 时恢复 SessionStart 的 `### Key Events` 一节(`events` 表中最近的高重要度条目)。**v6.13.0 起默认关闭**:对 30 条 event 的核验只有 2 条属实、16 条错误。UserPromptSubmit 的 events 块与 PreToolUse 召回按查询匹配,保持开启;`mem_search` 仍可检索全部 event。 | _(关闭)_ |
|
|
906
915
|
| `CLAUDE_MEM_EPISODE_INPUT_FILTER` | 决定 episode 摘要器能从哪些输入里学。子代理的工具调用不进入 episode 缓冲(修改项目内文件的除外);变异探针(改文件 → 跑红 → 还原)和 agent 自己失败的内联脚本(补丁的 `anchor not found`)在保存或摘要前被剔除——在 30 条已核验 event 上重放,这一项直接去掉 16 条错误中的 3 条;配合 `CLAUDE_MEM_LESSON_GROUNDING`,16 条错误教训一条都不会被注入。设为 `off` 恢复未过滤的输入。 | _(开启)_ |
|
|
907
916
|
| `CLAUDE_MEM_BASH_RECALL` | 在查看(`cat`、`sed -n`、`head`…)或写入(`sed -i`、`cat > f`、python 补丁…)文件的 Bash 命令执行前做文件召回,与 Read / Edit 召回相同。bash 预过滤让其他命令不启动 Node。设为 `off` 只关闭这一路。 | _(开启)_ |
|
|
917
|
+
| `CLAUDE_MEM_PRETOOL_PATH_PRECISION` | 设为 `off` 恢复 PreToolUse 召回只按文件名匹配的旧行为。**默认开启**(R3 O1):项目里另一个目录下同名文件的教训不再注入(编辑 `src/snapshot/mod.rs` 时不再给 `src/mcp/server/mod.rs` 的,编辑 `tasks/x/README.md` 时不再给根目录 `README.md` 的);裸文件名、Claude Code worktree 副本、项目之外的路径、无法定位的写法(`../`、`~/`、盘符),以及现在已不存在的路径(文件移走了)仍会匹配。路径按 POSIX 规则比较,所以在原生 Windows 主机上匹配行为不变。194 个会话记录里,4,037 个注入行中有 210 个属于这种不同的文件。 | _(开启)_ |
|
|
908
918
|
| `CLAUDE_MEM_LESSON_GROUNDING` | 自动捕获的 event 只有在教训引用了本窗口自己的诊断文字(失败输出行、编辑新增的注释或提交信息)时才保留教训;否则保留这一行但去掉教训,importance 降为 1,低于所有注入面的门槛。设为 `off` 保留未引用原文的教训。 | _(开启)_ |
|
|
909
919
|
| `CLAUDE_MEM_LESSON_OUTPUT_CAP` | 自动捕获的教训如果和**工具输出**(命令打印的文字或工具返回的内容,能控制这段输出的人就能写它)有连续 4 个词相同,就不会进入注入面:event 保留这一行和教训、仍可搜索,importance 降为 1;`change` 类 observation 的 importance 之后会被读取次数抬高,所以改为去掉教训,没有教训的这一行随后会像其他同类行一样被丢弃(只有设了 `CLAUDE_MEM_KEEP_LOW_SIGNAL=1` 才保留)。连续 4 个虚词(例如 "is not in the")也算,所以引用你自己的注释或提交信息的教训,只要碰巧和同一窗口的输出共有这样一串词,也会被降级。这一行的标题不在检查范围内。设为 `off` 恢复模型给出的 importance 和教训。 | _(开启)_ |
|
|
910
920
|
| `MEM_NO_AUTO_ADOPT` | auto-adopt 全局关闭开关(v2.82.0+)。设为 `1` 在**所有**项目停止自动 adopt——不注入引导文本、不新建本地文件(`CLAUDE.local.md` 或 `.claude/rules/claude-mem-lite.md`),也不同步已有的 `CLAUDE.md` 或本地托管块(这些托管块会保留并继续加载,直到 `claude-mem-lite unadopt`)。项目级关闭走 `claude-mem-lite adopt --disable`(写 `<memdir>/.mem-no-auto-adopt` 哨兵,存活于 marker 删除)。 | _(禁用)_ |
|
package/format-utils.mjs
CHANGED
|
@@ -263,6 +263,11 @@ export function neutralizeSkillDelimiters(s) {
|
|
|
263
263
|
* moment a fix is needed. Later rows stay as #ID pointers to keep the injected
|
|
264
264
|
* payload bounded (one body, not three). Upstream noise gating (low-signal title
|
|
265
265
|
* exclusion) is the SELECT's job (see triggerErrorRecall).
|
|
266
|
+
*
|
|
267
|
+
* No `→ Use mem_get(ids=[…]) for details.` footer (R3 O4,
|
|
268
|
+
* docs/audits/20261103-r3-optimization-plan.md): on 194 transcripts it closed 622
|
|
269
|
+
* blocks and MCP mem_get was called 3 times. The header line is the surface the
|
|
270
|
+
* citation extractors and benchmark/injection-budget.mjs key on, so it stays.
|
|
266
271
|
* @param {Array<{id:number,type:string,title:string,lesson_learned?:string}>} rows
|
|
267
272
|
* @returns {string} stdout block (trailing newline) or '' when there are no rows
|
|
268
273
|
*/
|
|
@@ -280,8 +285,7 @@ export function formatErrorRecallHints(rows) {
|
|
|
280
285
|
}
|
|
281
286
|
return head;
|
|
282
287
|
});
|
|
283
|
-
|
|
284
|
-
return `[claude-mem-lite] Related memories found for this error:\n${lines.join('\n')}\n \u2192 Use mem_get(ids=[${ids}]) for details.\n`;
|
|
288
|
+
return `[claude-mem-lite] Related memories found for this error:\n${lines.join('\n')}\n`;
|
|
285
289
|
}
|
|
286
290
|
|
|
287
291
|
/**
|
package/hook.mjs
CHANGED
|
@@ -1010,7 +1010,8 @@ async function handlePostToolUse() {
|
|
|
1010
1010
|
|
|
1011
1011
|
/**
|
|
1012
1012
|
* N2 (session-history analysis r2): stay silent on a deliberate TDD RED and on an exit-0
|
|
1013
|
-
* command that merely PRINTS error text
|
|
1013
|
+
* command that merely PRINTS error text; D#717 adds an exit-0 git command whose failure words
|
|
1014
|
+
* all sit in the commit records the gate sets aside. The decision is lib/error-recall-gate.mjs; this
|
|
1014
1015
|
* hands it the episode buffer the hook already keeps (read without the lock: a snapshot is
|
|
1015
1016
|
* enough, and writeEpisode replaces the file by rename) and meters what it silenced, so the
|
|
1016
1017
|
* suppressed volume is readable next to `error_recall` rather than inferred from its drop.
|
|
@@ -1070,7 +1071,8 @@ function triggerErrorRecall(db, toolInput, response, opts = {}) {
|
|
|
1070
1071
|
});
|
|
1071
1072
|
if (!selected) return;
|
|
1072
1073
|
// Per-thread dedup, like the PreToolUse and UserPromptSubmit faces: a red/green loop re-sent
|
|
1073
|
-
// the identical block on every failing run (lib/recall-shown.mjs
|
|
1074
|
+
// the identical block on every failing run (lib/recall-shown.mjs errorRecallRepeatMs: once per
|
|
1075
|
+
// thread until compaction, R3 O3).
|
|
1074
1076
|
const shownPath = errorRecallShownPath(RUNTIME_DIR, opts.thread);
|
|
1075
1077
|
const shown = readErrorRecallShown(shownPath);
|
|
1076
1078
|
const rows = selected.rows.filter((r) => !shown.has(String(r.id)));
|
package/lib/edge-attribution.mjs
CHANGED
|
@@ -57,9 +57,12 @@ export function readPreRecallFileEdges(runtimeDir, ccSessionId) {
|
|
|
57
57
|
* Resolve one session's pre-tool file-edge injections as hit (cited) or miss
|
|
58
58
|
* (uncited), updating the per-edge counters on observation_files.
|
|
59
59
|
*
|
|
60
|
-
* Edge matching uses the
|
|
61
|
-
* lib/file-edge-match.mjs is the shared source
|
|
62
|
-
*
|
|
60
|
+
* Edge matching uses the same SQL clause as pre-tool-recall's trigger query —
|
|
61
|
+
* lib/file-edge-match.mjs is the shared source. The clause is name-based, so
|
|
62
|
+
* for an injected row it credits every edge with the file's name, including an
|
|
63
|
+
* edge of a same-named file in another directory that the row also carries.
|
|
64
|
+
* The trigger additionally drops rows whose every same-named edge is another
|
|
65
|
+
* project file (edgesNameOtherFile, R3 O1).
|
|
63
66
|
*
|
|
64
67
|
* Semantics mirror applyCitationDecay's split idempotency keys:
|
|
65
68
|
* - miss: guarded on last_resolved_session_id — never double-streaks a session.
|
|
@@ -164,7 +164,7 @@ export function errorRecallSql(limit = ERROR_RECALL_LIMIT) {
|
|
|
164
164
|
-- This surface INLINES rows[0].lesson_learned into the model context, so an
|
|
165
165
|
-- unfiltered SELECT handed a retracted lesson to the agent verbatim while its
|
|
166
166
|
-- correction trailed as a bare pointer. compressed_into is filtered too, not
|
|
167
|
-
-- only for symmetry: the block
|
|
167
|
+
-- only for symmetry: the block names every row by its #id, and a
|
|
168
168
|
-- COMPRESSED_PENDING_PURGE row is queued for deletion by maintain purge_stale,
|
|
169
169
|
-- so that pointer would resolve to nothing.
|
|
170
170
|
AND ${liveObsFilterSql('o')}
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
// tdd-red the agent has just written the test and runs it to WATCH it fail.
|
|
9
9
|
// data-print an exit-0 inline script or `gh … --log-failed` whose OUTPUT is somebody
|
|
10
10
|
// else's error text (a transcript line, a CI log, the script's own assert).
|
|
11
|
+
// git-record an exit-0 git command whose output reads as a failure only through the commit
|
|
12
|
+
// records withoutGitRecords sets aside (D#717).
|
|
11
13
|
//
|
|
12
14
|
// Reach, measured before this shipped (2026-09-26, tree fa66e5d, 196 session transcripts,
|
|
13
15
|
// pre-DB firings through the shipped trigger): tdd-red 229 of 858 PostToolUse firings and
|
|
@@ -95,6 +97,54 @@ function hasRepoSourceFrame(response, projectDir) {
|
|
|
95
97
|
return false;
|
|
96
98
|
}
|
|
97
99
|
|
|
100
|
+
// ─── git-record (D#717) ──────────────────────────────────────────────────────
|
|
101
|
+
//
|
|
102
|
+
// `git commit -m "fix: a traceback on …" && git log --oneline` succeeded, and its output is the
|
|
103
|
+
// record of commits whose subjects name failures. The R3 session fired on exactly that;
|
|
104
|
+
// over every transcript on the maintainer's machine (2026-11-03) 6 of 422 exit-0 firings turned on
|
|
105
|
+
// such records alone (docs/audits/20261103-r3-optimization-plan.md §9.3). Only git's own record
|
|
106
|
+
// shapes are removed, and only when the command runs a subcommand that prints them; whatever else
|
|
107
|
+
// the output says is judged again by the shipped trigger.
|
|
108
|
+
// CLAUDE_MEM_ERROR_RECALL_GIT_RECORD=off restores the firing.
|
|
109
|
+
|
|
110
|
+
const GIT_RECORD_CMD_RE =
|
|
111
|
+
/\bgit\s+(?:(?:-[cC]\s+\S+|--?[\w-]+(?:=\S+)?)\s+)*(?:log|show|commit|cherry-pick|revert|merge|rebase|reflog)\b/;
|
|
112
|
+
// `[main 1a2b3c4] subject`, `[main (root-commit) 1a2b3c4] …`, `[detached HEAD 1a2b3c4] …`
|
|
113
|
+
const COMMIT_RESULT_LINE_RE = /^\[[^\]\n]* [0-9a-f]{7,40}\] /;
|
|
114
|
+
// `1a2b3c4 subject`, `1a2b3c4 (HEAD -> main) subject`, behind `--graph`'s `* | / \` columns.
|
|
115
|
+
// No bare leading spaces: an indented hex run is not a record git prints. At least one letter:
|
|
116
|
+
// an all-digit run can be a log line's epoch timestamp, and a sha that happens to be all digits
|
|
117
|
+
// only keeps the old firing.
|
|
118
|
+
const ONELINE_RECORD_RE = /^(?:[*|\\/][*|\\/ ]*)?(?=\d*[a-f])[0-9a-f]{7,40}(?: \([^)\n]*\))? \S/;
|
|
119
|
+
// `commit <sha>` opens the default format: header fields, then the message indented by 4 spaces.
|
|
120
|
+
const COMMIT_HEADER_RE = /^commit [0-9a-f]{40}\b/;
|
|
121
|
+
const COMMIT_FIELD_RE = /^(?:Merge|Author|AuthorDate|Commit|CommitDate|Date):/;
|
|
122
|
+
|
|
123
|
+
/** The output without the commit records git printed: result lines, one-line logs, full headers. */
|
|
124
|
+
function withoutGitRecords(text) {
|
|
125
|
+
const kept = [];
|
|
126
|
+
let inRecord = false;
|
|
127
|
+
for (const line of String(text || '').split('\n')) {
|
|
128
|
+
if (COMMIT_HEADER_RE.test(line)) {
|
|
129
|
+
inRecord = true;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (inRecord) {
|
|
133
|
+
if (line === '' || line.startsWith(' ') || COMMIT_FIELD_RE.test(line)) continue;
|
|
134
|
+
inRecord = false;
|
|
135
|
+
}
|
|
136
|
+
if (COMMIT_RESULT_LINE_RE.test(line) || ONELINE_RECORD_RE.test(line)) continue;
|
|
137
|
+
kept.push(line);
|
|
138
|
+
}
|
|
139
|
+
return kept.join('\n');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function gitRecordGateOn() {
|
|
143
|
+
return !['0', 'off', 'false', 'no'].includes(
|
|
144
|
+
String(process.env.CLAUDE_MEM_ERROR_RECALL_GIT_RECORD ?? '').toLowerCase(),
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
98
148
|
/**
|
|
99
149
|
* Should this error-recall firing stay silent?
|
|
100
150
|
*
|
|
@@ -105,7 +155,7 @@ function hasRepoSourceFrame(response, projectDir) {
|
|
|
105
155
|
* (extractFileTargets' `writes`), since the call is appended to the buffer only after
|
|
106
156
|
* recall ran; `exitZero` is true on the PostToolUse path, where the host has routed every
|
|
107
157
|
* non-zero exit elsewhere.
|
|
108
|
-
* @returns {{reason: 'tdd-red'|'data-print'}|null} null ⇒ fire as before.
|
|
158
|
+
* @returns {{reason: 'tdd-red'|'data-print'|'git-record'}|null} null ⇒ fire as before.
|
|
109
159
|
*/
|
|
110
160
|
export function errorRecallSuppression({
|
|
111
161
|
cmd,
|
|
@@ -124,5 +174,12 @@ export function errorRecallSuppression({
|
|
|
124
174
|
// failure path (PostToolUseFailure) keeps it.
|
|
125
175
|
if (exitZero && isDataPrintingCommand(command) && !hasRepoSourceFrame(response, projectDir))
|
|
126
176
|
return { reason: 'data-print' };
|
|
177
|
+
if (
|
|
178
|
+
exitZero &&
|
|
179
|
+
GIT_RECORD_CMD_RE.test(command) &&
|
|
180
|
+
gitRecordGateOn() &&
|
|
181
|
+
!detectBashSignificance({ command }, withoutGitRecords(response)).isHardError
|
|
182
|
+
)
|
|
183
|
+
return { reason: 'git-record' };
|
|
127
184
|
return null;
|
|
128
185
|
}
|
package/lib/file-edge-match.mjs
CHANGED
|
@@ -45,10 +45,12 @@
|
|
|
45
45
|
// same two lines as `basenameAnySep`; that copy was deleted in the same round once
|
|
46
46
|
// its only consumer went, so this file is now the sole home.
|
|
47
47
|
//
|
|
48
|
-
// The
|
|
49
|
-
// `node:path`, and pre-tool-recall.js already imports it for inferProject.
|
|
48
|
+
// The node:path builtin is free, and the project-utils.mjs import does not cost that either: it is
|
|
49
|
+
// a leaf over `node:path`, and pre-tool-recall.js already imports it for inferProject.
|
|
50
|
+
import { existsSync } from 'node:fs';
|
|
51
|
+
import { posix } from 'node:path';
|
|
50
52
|
import { likeLiteral } from '../project-utils.mjs';
|
|
51
|
-
// The
|
|
53
|
+
// The third import, and it costs no more than the second: scrub-record.mjs ->
|
|
52
54
|
// secret-scrub.mjs -> lib/private-strip.mjs are three regex-only leaves — no
|
|
53
55
|
// node builtins, no DB handle, nothing child_process-shaped. Checked rather
|
|
54
56
|
// than asserted, because the dependency note in this file has been wrong twice.
|
|
@@ -285,3 +287,90 @@ export function fileMatchParams(rawFilePath) {
|
|
|
285
287
|
// written '\\' — so the JS string carries two backslash characters.
|
|
286
288
|
return [filePath, fname, `%/${escaped}`, `%\\\\${escaped}`];
|
|
287
289
|
}
|
|
290
|
+
|
|
291
|
+
// ─── R3 O1: a same-named file in another directory is not this file ─────────
|
|
292
|
+
//
|
|
293
|
+
// fileMatchClause's `%/<basename>` arm accepts ANY directory-qualified edge with the target's
|
|
294
|
+
// name, which is how the Stop-side attribution must read a heterogeneous column (bare names,
|
|
295
|
+
// relative and absolute paths). For INJECTION it over-matches: editing src/snapshot/mod.rs pulled
|
|
296
|
+
// the lessons of src/mcp/server/mod.rs, and a README.md under tasks/ pulled the root README's. On
|
|
297
|
+
// 194 transcripts (2026-10-06..11-03, docs/audits/20261103-r3-optimization-plan.md) 210 of 4,037
|
|
298
|
+
// injected PreToolUse rows named a different file of the same project. The clause itself stays as it is —
|
|
299
|
+
// it is byte-shared with lib/edge-attribution.mjs — and pre-tool-recall.js filters its rows with
|
|
300
|
+
// this predicate instead.
|
|
301
|
+
//
|
|
302
|
+
// Only what can be PLACED is judged. Both sides are normalised and a Claude Code worktree
|
|
303
|
+
// (`.claude/worktrees/<name>/`) is read as the project root, so a lesson recorded in an agent's
|
|
304
|
+
// worktree still reaches the main tree. An absolute edge is compared with the target; a relative
|
|
305
|
+
// one as a suffix of it (see edgesNameOtherFile). A path outside the project (a /tmp copy, another
|
|
306
|
+
// repository), a relative spelling with `..`, `~`, a drive letter or a scheme, and a missing project root
|
|
307
|
+
// cannot be placed, and such a row is kept, exactly as before. Nor can a path that names no file
|
|
308
|
+
// now: a file that moved inside the project left its lessons on the old path (v6.31.0 review r1).
|
|
309
|
+
|
|
310
|
+
const WORKTREE_RE = /^\.claude\/worktrees\/[^/]+\//;
|
|
311
|
+
const WORKTREE_IN_PATH_RE = /(^|\/)\.claude\/worktrees\/[^/]+\//;
|
|
312
|
+
// Spellings that cannot be placed without a filesystem or a host: a parent step, a home tilde, a
|
|
313
|
+
// drive letter (a Windows path read on POSIX, e.g. from import-jsonl), a URL. Pre-ship review M1.
|
|
314
|
+
const UNPLACEABLE_RE = /^~|^[A-Za-z]:|^[a-z][\w+.-]*:\/\/|(?:^|\/)\.\.(?:\/|$)/i;
|
|
315
|
+
|
|
316
|
+
/** `/`-separated; absolute paths through path.posix.normalize, relative ones cleaned of `.` and `//`. */
|
|
317
|
+
function normalisePath(p) {
|
|
318
|
+
const s = String(p ?? '').replace(/\\/g, '/');
|
|
319
|
+
if (s.startsWith('/')) return posix.normalize(s);
|
|
320
|
+
return s.replace(/\/{2,}/g, '/').replace(/(^|\/)(?:\.\/)+/g, '$1');
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** An absolute path inside the project as `<root>/…` with a worktree mapped to the root; null outside. */
|
|
324
|
+
function mapIntoProject(abs, root) {
|
|
325
|
+
if (!abs.startsWith(root + '/')) return null;
|
|
326
|
+
return (root + '/' + abs.slice(root.length + 1).replace(WORKTREE_RE, '')).toLowerCase();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* True when every edge of one observation that carries the target's file name names a DIFFERENT
|
|
331
|
+
* file of the same project — the row matched fileMatchClause on its name alone. False whenever
|
|
332
|
+
* one such edge is the target, cannot be placed, or there is no such edge at all.
|
|
333
|
+
*
|
|
334
|
+
* An ABSOLUTE edge must equal the target once both are normalised and a worktree is mapped to the
|
|
335
|
+
* root — that is what tells `<root>/README.md` from `<root>/tasks/d614/README.md`. A RELATIVE edge
|
|
336
|
+
* names the target when the target's absolute path ends with it at a `/` boundary: it may have been
|
|
337
|
+
* recorded from any directory, including one ABOVE the session root (the monorepo case, pre-ship
|
|
338
|
+
* review M1), so it is not compared against the root-relative path alone.
|
|
339
|
+
*
|
|
340
|
+
* @param {string[]} storedPaths every observation_files.filename of the row
|
|
341
|
+
* @param {string} targetPath absolute path the tool reads or edits
|
|
342
|
+
* @param {string|null|undefined} projectDir the session's project root
|
|
343
|
+
* @param {{exists?: (p: string) => boolean}} [opts] the filesystem probe (a test or a replay passes its own)
|
|
344
|
+
* @returns {boolean}
|
|
345
|
+
*/
|
|
346
|
+
export function edgesNameOtherFile(storedPaths, targetPath, projectDir, { exists = existsSync } = {}) {
|
|
347
|
+
if (typeof projectDir !== 'string' || !projectDir || !Array.isArray(storedPaths)) return false;
|
|
348
|
+
const root = normalisePath(projectDir).replace(/\/+$/, '');
|
|
349
|
+
const targetAbs = normalisePath(targetPath);
|
|
350
|
+
if (!root.startsWith('/') || !targetAbs.startsWith('/')) return false;
|
|
351
|
+
const target = mapIntoProject(targetAbs, root);
|
|
352
|
+
if (!target) return false;
|
|
353
|
+
const name = basenameAnySep(targetAbs).toLowerCase();
|
|
354
|
+
const sameName = storedPaths.filter(
|
|
355
|
+
(s) => typeof s === 'string' && basenameAnySep(s.replace(/\\/g, '/')).toLowerCase() === name,
|
|
356
|
+
);
|
|
357
|
+
if (sameName.length === 0) return false;
|
|
358
|
+
for (const raw of sameName) {
|
|
359
|
+
const s = normalisePath(raw);
|
|
360
|
+
if (s.startsWith('/')) {
|
|
361
|
+
const mapped = mapIntoProject(s, root);
|
|
362
|
+
if (mapped === null || mapped === target) return false;
|
|
363
|
+
// Probed on the main tree's spelling, so a worktree removed since does not count as gone.
|
|
364
|
+
if (!exists(root + '/' + s.slice(root.length + 1).replace(WORKTREE_RE, ''))) return false;
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
// Relative, bare names included: a bare name is a suffix of every same-named target, so it is
|
|
368
|
+
// always kept.
|
|
369
|
+
if (UNPLACEABLE_RE.test(raw.replace(/\\/g, '/'))) return false;
|
|
370
|
+
// A relative edge spelled through an agent worktree is the main tree's file (delta review F1).
|
|
371
|
+
const rel = s.replace(WORKTREE_IN_PATH_RE, '$1');
|
|
372
|
+
if (target.endsWith('/' + rel.toLowerCase())) return false;
|
|
373
|
+
if (!exists(root + '/' + rel)) return false;
|
|
374
|
+
}
|
|
375
|
+
return true;
|
|
376
|
+
}
|
package/lib/recall-shown.mjs
CHANGED
|
@@ -153,11 +153,23 @@ export function markCooldownCompacted(runtimeDir, sessionId) {
|
|
|
153
153
|
/**
|
|
154
154
|
* Error recall (PostToolUse / PostToolUseFailure) had no thread dedup, unlike PreToolUse and
|
|
155
155
|
* UserPromptSubmit, so a red/green loop re-sent the identical "Related memories found for this
|
|
156
|
-
* error" block on every failing run (E2E 2026-10-16). Ids shown to a thread are skipped
|
|
157
|
-
*
|
|
158
|
-
*
|
|
156
|
+
* error" block on every failing run (E2E 2026-10-16). Ids shown to a thread are skipped from then
|
|
157
|
+
* on; compaction clears the marker (hook.mjs SessionStart), as it does the recall header, and the
|
|
158
|
+
* file is in this module's family, so the 24 h GC sweeps it.
|
|
159
|
+
*
|
|
160
|
+
* Whole thread, not 30 minutes (R3 O3, docs/audits/20261103-r3-optimization-plan.md): the
|
|
161
|
+
* 30-minute window this shipped with let the same memory back into the thread that still held it.
|
|
162
|
+
* PreToolUse shows a file's lessons once per thread for the same reason.
|
|
163
|
+
* CLAUDE_MEM_ERROR_RECALL_REPEAT_MIN=<minutes> restores a time window (30 = the old behaviour);
|
|
164
|
+
* anything that is not a positive number keeps the whole-thread default.
|
|
165
|
+
*
|
|
166
|
+
* @param {Record<string, string|undefined>} [env]
|
|
167
|
+
* @returns {number} milliseconds an id stays "shown"; Infinity = until the marker is cleared
|
|
159
168
|
*/
|
|
160
|
-
|
|
169
|
+
function errorRecallRepeatMs(env = process.env) {
|
|
170
|
+
const n = Number(env.CLAUDE_MEM_ERROR_RECALL_REPEAT_MIN);
|
|
171
|
+
return env.CLAUDE_MEM_ERROR_RECALL_REPEAT_MIN && Number.isFinite(n) && n > 0 ? n * 60 * 1000 : Infinity;
|
|
172
|
+
}
|
|
161
173
|
|
|
162
174
|
/** @returns {string|null} the thread's error-recall marker, null without a thread */
|
|
163
175
|
export function errorRecallShownPath(runtimeDir, thread) {
|
|
@@ -166,13 +178,14 @@ export function errorRecallShownPath(runtimeDir, thread) {
|
|
|
166
178
|
}
|
|
167
179
|
|
|
168
180
|
/** @returns {Map<string, number>} id → when it was shown, entries inside the window only */
|
|
169
|
-
export function readErrorRecallShown(path, now = Date.now()) {
|
|
181
|
+
export function readErrorRecallShown(path, now = Date.now(), env = process.env) {
|
|
170
182
|
const shown = new Map();
|
|
171
183
|
if (!path) return shown;
|
|
184
|
+
const windowMs = errorRecallRepeatMs(env);
|
|
172
185
|
try {
|
|
173
186
|
const v = JSON.parse(readFileSync(path, 'utf8'));
|
|
174
187
|
for (const [id, ts] of Object.entries(v?.ids || {})) {
|
|
175
|
-
if (typeof ts === 'number' && now - ts <
|
|
188
|
+
if (typeof ts === 'number' && now - ts < windowMs) shown.set(id, ts);
|
|
176
189
|
}
|
|
177
190
|
} catch {
|
|
178
191
|
/* absent or torn: nothing shown */
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-mem-lite",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.31.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "claude-mem-lite",
|
|
9
|
-
"version": "6.
|
|
9
|
+
"version": "6.31.0",
|
|
10
10
|
"os": [
|
|
11
11
|
"darwin",
|
|
12
12
|
"linux",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-mem-lite",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.31.0",
|
|
4
4
|
"description": "Persistent long-term memory for Claude Code via MCP — captures coding decisions, bugfixes, and context across sessions. FTS5 BM25 keyword search with episode batching. Single SQLite DB, no external services. A lighter, lower-cost alternative to claude-mem (episode batching + a smaller model; cost savings are an internal estimate, not a measured benchmark).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "npm@10.9.2",
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
fileMatchClause,
|
|
26
26
|
fileMatchParams,
|
|
27
27
|
basenameAnySep,
|
|
28
|
+
edgesNameOtherFile,
|
|
28
29
|
jsonArrayLikeNeedle,
|
|
29
30
|
toolEditPath,
|
|
30
31
|
} from '../lib/file-edge-match.mjs';
|
|
@@ -261,6 +262,18 @@ const EDGE_DECAY_K = Math.max(1, Number.isNaN(EDGE_DECAY_K_RAW) ? 3 : EDGE_DECAY
|
|
|
261
262
|
// environment and project pairs sit in the same bands, so the head-to-head is not
|
|
262
263
|
// era-confounded. The `(null)` bucket and the face-overall figure ARE, being
|
|
263
264
|
// dominated by legacy rows.
|
|
265
|
+
// R3 O1 (lib/file-edge-match.mjs edgesNameOtherFile): a row whose every same-named edge is ANOTHER
|
|
266
|
+
// file of this project is dropped after the SELECT. The SELECT is then PAGED until the slots are
|
|
267
|
+
// filled, because a filter downstream of a LIMIT shrinks the set instead of refilling it (the
|
|
268
|
+
// D#172 shape) — and the files this rule exists for are the ones with many same-named siblings:
|
|
269
|
+
// a fixed over-fetch of 3 left a Read of a Rust `mod.rs` silent in 8 of 122 probes on the
|
|
270
|
+
// maintainer's store (pre-ship review M2). Bounded at PATH_PRECISION_MAX_PAGES pages.
|
|
271
|
+
// CLAUDE_MEM_PRETOOL_PATH_PRECISION=off restores the name-only match and the single LIMIT.
|
|
272
|
+
const PATH_PRECISION_ON = !['0', 'off', 'false', 'no'].includes(
|
|
273
|
+
String(process.env.CLAUDE_MEM_PRETOOL_PATH_PRECISION ?? '').toLowerCase(),
|
|
274
|
+
);
|
|
275
|
+
const PATH_PRECISION_PAGE_EXTRA = 20;
|
|
276
|
+
const PATH_PRECISION_MAX_PAGES = 10;
|
|
264
277
|
const SCOPE_FILTER_ON = ['1', 'on', 'true', 'yes'].includes(
|
|
265
278
|
String(process.env.CLAUDE_MEM_SCOPE_FILTER || '').toLowerCase(),
|
|
266
279
|
);
|
|
@@ -758,9 +771,9 @@ try {
|
|
|
758
771
|
/* probe failure → unfiltered */
|
|
759
772
|
}
|
|
760
773
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
774
|
+
// `LIMIT` stays a literal keyword: tests/order-by-created-at-guard.test.mjs reads the ORDER BY
|
|
775
|
+
// clause up to it, and the switch-off text must stay what it was.
|
|
776
|
+
const obsSelect = (limitArgs) => `
|
|
764
777
|
SELECT DISTINCT o.id, o.type, o.title, o.lesson_learned
|
|
765
778
|
FROM observations o
|
|
766
779
|
JOIN observation_files of2 ON of2.obs_id = o.id
|
|
@@ -777,10 +790,54 @@ try {
|
|
|
777
790
|
${citeFactorClause('o')} DESC,
|
|
778
791
|
o.created_at_epoch DESC,
|
|
779
792
|
o.id DESC
|
|
780
|
-
LIMIT ${
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
793
|
+
LIMIT ${limitArgs}
|
|
794
|
+
`;
|
|
795
|
+
let rows;
|
|
796
|
+
if (!PATH_PRECISION_ON) {
|
|
797
|
+
rows = db.prepare(obsSelect(`${obsLimit}`)).all(project, cutoff, ...fileParams);
|
|
798
|
+
} else {
|
|
799
|
+
const page = obsLimit + PATH_PRECISION_PAGE_EXTRA;
|
|
800
|
+
const select = db.prepare(obsSelect('? OFFSET ?'));
|
|
801
|
+
const projectRoot = inferProjectDir();
|
|
802
|
+
rows = [];
|
|
803
|
+
// Rows the old single LIMIT would have FETCHED and this rule removed (the metric's unit; the
|
|
804
|
+
// dedup and merge caps downstream may still have kept some of them out — delta review F4).
|
|
805
|
+
let displaced = 0;
|
|
806
|
+
let position = 0;
|
|
807
|
+
const pushed = new Set();
|
|
808
|
+
// One read transaction for every page, so a write landing between two pages cannot shift
|
|
809
|
+
// the OFFSET under them (a repeated or a skipped row — delta review F2).
|
|
810
|
+
db.transaction(() => {
|
|
811
|
+
for (let k = 0; k < PATH_PRECISION_MAX_PAGES && rows.length < obsLimit; k++) {
|
|
812
|
+
const batch = select.all(project, cutoff, ...fileParams, page, k * page);
|
|
813
|
+
if (batch.length === 0) break;
|
|
814
|
+
// The edges the match itself may use: with CLAUDE_MEM_EDGE_DECAY on, a decayed edge is not a
|
|
815
|
+
// match, so it must not keep the row here either (pre-ship review L1).
|
|
816
|
+
const ids = batch.map((r) => r.id);
|
|
817
|
+
const edges = new Map();
|
|
818
|
+
for (const e of db
|
|
819
|
+
.prepare(
|
|
820
|
+
`SELECT of2.obs_id, of2.filename FROM observation_files of2 WHERE of2.obs_id IN (${ids.map(() => '?').join(',')}) ${edgeDecayFilter}`,
|
|
821
|
+
)
|
|
822
|
+
.all(...ids)) {
|
|
823
|
+
if (!edges.has(e.obs_id)) edges.set(e.obs_id, []);
|
|
824
|
+
edges.get(e.obs_id).push(e.filename);
|
|
825
|
+
}
|
|
826
|
+
for (const r of batch) {
|
|
827
|
+
if (rows.length >= obsLimit) break;
|
|
828
|
+
if (edgesNameOtherFile(edges.get(r.id) || [], keyPath, projectRoot)) {
|
|
829
|
+
if (position < obsLimit) displaced++;
|
|
830
|
+
} else if (!pushed.has(r.id)) {
|
|
831
|
+
pushed.add(r.id);
|
|
832
|
+
rows.push(r);
|
|
833
|
+
}
|
|
834
|
+
position++;
|
|
835
|
+
}
|
|
836
|
+
if (batch.length < page) break;
|
|
837
|
+
}
|
|
838
|
+
})();
|
|
839
|
+
if (displaced > 0) recordMetric(DATA_DIR, { event: 'pretool_path_dropped', dropped: displaced });
|
|
840
|
+
}
|
|
784
841
|
|
|
785
842
|
// T9: also query the `events` table — after T9, bugfix/lesson/decision/etc.
|
|
786
843
|
// route here instead of observations, so we must read both sources to keep
|
package/search-scoring.mjs
CHANGED
|
@@ -51,6 +51,11 @@ const INSTRUCTIONS_BASE = [
|
|
|
51
51
|
` ${CLI_INVOKE} recent 5 — latest observations`,
|
|
52
52
|
` ${CLI_INVOKE} get 42,43 — full details by ID`,
|
|
53
53
|
` ${CLI_INVOKE} timeline --anchor 42 — chronological context`,
|
|
54
|
+
// R3 O6: the write verbs with their flags, so a CLI write does not start with a `help` call
|
|
55
|
+
// (the full help is 15.7 KB).
|
|
56
|
+
// tests/instructions-cli-write-lines.test.mjs runs both lines as written.
|
|
57
|
+
` ${CLI_INVOKE} defer add "<title>" --priority 1|2|3 --detail "<why>" — cross-session TODO (3 = urgent)`,
|
|
58
|
+
` ${CLI_INVOKE} save "<what happened>" --type bugfix --lesson "<root cause + fix>" --files <path> — save a lesson (--files ties it to file recall)`,
|
|
54
59
|
'',
|
|
55
60
|
'MCP tools: mem_search, mem_recent, mem_save, mem_get, mem_recall, mem_timeline (plus mem_defer/mem_defer_list/mem_defer_drop for cross-session TODOs). If already loaded, call directly (warm server, fastest path). In tool-heavy sessions these are deferred behind ToolSearch — if using one would cost a ToolSearch load first, run the Bash CLI above instead: one call, not two. Neither needs a PATH/CLI install.',
|
|
56
61
|
'mem_save: Save non-obvious insights (bugfix lessons, architecture decisions).',
|