claude-mem-lite 6.33.0 → 6.35.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 +28 -2
- package/README.zh-CN.md +20 -2
- package/hook-llm.mjs +82 -66
- package/hook.mjs +40 -3
- package/install.mjs +44 -7
- package/lib/fast-summary.mjs +49 -0
- package/lib/turn-replies.mjs +91 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -1
- package/secret-scrub.mjs +8 -0
- package/source-files.mjs +3 -0
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"plugins": [
|
|
10
10
|
{
|
|
11
11
|
"name": "claude-mem-lite",
|
|
12
|
-
"version": "6.
|
|
12
|
+
"version": "6.35.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.35.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,30 @@ 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.35.0
|
|
243
|
+
|
|
244
|
+
**The Last Session line names the session's main outcome more often; nothing to run, and the
|
|
245
|
+
schema version stays 49.** To go back, pin `claude-mem-lite@6.34.0`.
|
|
246
|
+
|
|
247
|
+
- **The session summary prompt's rule for the session's replies asks the model to order the work
|
|
248
|
+
it lists as completed by importance**, so the Last Session line SessionStart shows, cut to 120
|
|
249
|
+
characters, starts with the session's main finished outcome more often. The Completed field is
|
|
250
|
+
longer than before.
|
|
251
|
+
- **`uninstall --purge` no longer says `Done!` when `~/.claude-mem-lite` is a symbolic link.** The
|
|
252
|
+
purge then removes nothing and names the link.
|
|
253
|
+
- See CHANGELOG.md.
|
|
254
|
+
|
|
255
|
+
## Upgrading to 6.34.0
|
|
256
|
+
|
|
257
|
+
**The session summary reads every turn's last reply; nothing to run, and the schema version stays
|
|
258
|
+
49.** To go back, pin `claude-mem-lite@6.33.0` and delete `runtime/turn-replies-*.json` from the
|
|
259
|
+
data directory: 6.33.0 never reads them.
|
|
260
|
+
|
|
261
|
+
- **The session summary model reads each turn's last reply**, not only the observations and
|
|
262
|
+
prompts. Stop keeps each turn's last reply, scrubbed, in `runtime/`.
|
|
263
|
+
- **The secret scrubber erases Hugging Face, DigitalOcean, PyPI, Shopify and Groq tokens.**
|
|
264
|
+
- See CHANGELOG.md.
|
|
265
|
+
|
|
242
266
|
## Upgrading to 6.33.0
|
|
243
267
|
|
|
244
268
|
**`uninstall --purge` leaves your own files in a relocated data directory; nothing to run, and the
|
|
@@ -946,7 +970,7 @@ Each observation includes type, title, narrative, concepts, facts, importance (1
|
|
|
946
970
|
# git clone install:
|
|
947
971
|
node install.mjs install # Install and configure
|
|
948
972
|
node install.mjs uninstall # Remove (keep data)
|
|
949
|
-
node install.mjs uninstall --purge # Remove and delete
|
|
973
|
+
node install.mjs uninstall --purge # Remove and delete the data (see Uninstall)
|
|
950
974
|
node install.mjs status # Show current status
|
|
951
975
|
node cli.mjs doctor # Diagnose issues (cli.mjs, not install.mjs — see note)
|
|
952
976
|
node cli.mjs repair # Recover a broken install from the latest signed release
|
|
@@ -1047,13 +1071,15 @@ After it finishes, `~/.claude-mem-lite/` is back in sync with the latest release
|
|
|
1047
1071
|
# git clone:
|
|
1048
1072
|
cd claude-mem-lite
|
|
1049
1073
|
node install.mjs uninstall # Keeps ~/.claude-mem-lite/ data
|
|
1050
|
-
node install.mjs uninstall --purge # Deletes ~/.claude-mem-lite/ and
|
|
1074
|
+
node install.mjs uninstall --purge # Deletes ~/.claude-mem-lite/ and its data
|
|
1051
1075
|
|
|
1052
1076
|
# npx:
|
|
1053
1077
|
npx claude-mem-lite uninstall
|
|
1054
1078
|
npx claude-mem-lite uninstall --purge
|
|
1055
1079
|
```
|
|
1056
1080
|
|
|
1081
|
+
When `~/.claude-mem-lite` is a symbolic link, `--purge` removes nothing and names the link.
|
|
1082
|
+
|
|
1057
1083
|
Data in `~/.claude-mem-lite/` is preserved by default. Delete manually if needed:
|
|
1058
1084
|
```bash
|
|
1059
1085
|
rm -rf ~/.claude-mem-lite/
|
package/README.zh-CN.md
CHANGED
|
@@ -201,6 +201,22 @@ rm -rf ~/claude-mem-lite/ # 首个发布版之前的非隐藏目录(不是
|
|
|
201
201
|
repos/ # 浅克隆的源代码仓库
|
|
202
202
|
```
|
|
203
203
|
|
|
204
|
+
## 升级到 6.35.0
|
|
205
|
+
|
|
206
|
+
**Last Session 那一行更常写出会话最重要的结果;不用执行任何操作,schema 版本仍是 49。** 想退回,请固定 `claude-mem-lite@6.34.0`。
|
|
207
|
+
|
|
208
|
+
- **会话摘要提示里讲会话回复的那条规则,要求模型按重要性排列 completed 里的完成事项**,所以 SessionStart 显示的、截到 120 字符的 Last Session 那一行,更常以会话最重要的完成结果开头。Completed 字段比以前长。
|
|
209
|
+
- **`~/.claude-mem-lite` 是符号链接时,`uninstall --purge` 不再打印 `Done!`。** 这时 purge 什么都不删,并说明是哪个链接。
|
|
210
|
+
- 详见 CHANGELOG.md。
|
|
211
|
+
|
|
212
|
+
## 升级到 6.34.0
|
|
213
|
+
|
|
214
|
+
**会话摘要会读每一轮的最后回复;不用执行任何操作,schema 版本仍是 49。** 想退回,请固定 `claude-mem-lite@6.33.0`,并删掉数据目录里的 `runtime/turn-replies-*.json`:6.33.0 不读它们。
|
|
215
|
+
|
|
216
|
+
- **会话摘要模型除了观察和提示,还读每一轮的最后回复。** Stop 把每一轮的最后回复脱敏后存在 `runtime/`。
|
|
217
|
+
- **密钥脱敏会抹掉 Hugging Face、DigitalOcean、PyPI、Shopify 和 Groq 的令牌。**
|
|
218
|
+
- 详见 CHANGELOG.md。
|
|
219
|
+
|
|
204
220
|
## 升级到 6.33.0
|
|
205
221
|
|
|
206
222
|
**数据目录改过位置时,`uninstall --purge` 不再删你自己的文件;不用执行任何操作,schema 版本仍是 49。** 第一次打开数据库时会给 `events` 加一个可空列,旧版本会忽略它。想退回,请固定 `claude-mem-lite@6.32.0`。
|
|
@@ -730,7 +746,7 @@ Episode 缓冲区 -> 刷新为 JSON -> claude -p --model haiku -> 结构化观
|
|
|
730
746
|
# git clone 安装:
|
|
731
747
|
node install.mjs install # 安装并配置
|
|
732
748
|
node install.mjs uninstall # 移除(保留数据)
|
|
733
|
-
node install.mjs uninstall --purge #
|
|
749
|
+
node install.mjs uninstall --purge # 移除并删除数据(见「卸载」)
|
|
734
750
|
node install.mjs status # 显示当前状态
|
|
735
751
|
node cli.mjs doctor # 诊断问题(用 cli.mjs 而非 install.mjs,见下方说明)
|
|
736
752
|
node cli.mjs repair # 从最新签名发布恢复损坏的安装
|
|
@@ -796,13 +812,15 @@ T=$(mktemp -d) && U=$(curl -sL https://api.github.com/repos/sdsrss/claude-mem-li
|
|
|
796
812
|
# git clone:
|
|
797
813
|
cd claude-mem-lite
|
|
798
814
|
node install.mjs uninstall # 保留 ~/.claude-mem-lite/ 数据
|
|
799
|
-
node install.mjs uninstall --purge # 删除 ~/.claude-mem-lite/
|
|
815
|
+
node install.mjs uninstall --purge # 删除 ~/.claude-mem-lite/ 及其数据
|
|
800
816
|
|
|
801
817
|
# npx:
|
|
802
818
|
npx claude-mem-lite uninstall
|
|
803
819
|
npx claude-mem-lite uninstall --purge
|
|
804
820
|
```
|
|
805
821
|
|
|
822
|
+
`~/.claude-mem-lite` 是符号链接时,`--purge` 什么都不删,并说明是哪个链接。
|
|
823
|
+
|
|
806
824
|
数据默认保留在 `~/.claude-mem-lite/` 中。如需删除:
|
|
807
825
|
```bash
|
|
808
826
|
rm -rf ~/.claude-mem-lite/
|
package/hook-llm.mjs
CHANGED
|
@@ -26,8 +26,9 @@ import {
|
|
|
26
26
|
import { acquireLLMSlot, releaseLLMSlot, LLM_SEM_TIMEOUT } from './hook-semaphore.mjs';
|
|
27
27
|
import { BG_LLM_TIMEOUT_MS } from './haiku-client.mjs';
|
|
28
28
|
import { scrubRecord, scrubFilePaths } from './lib/scrub-record.mjs';
|
|
29
|
-
import { mergeModelSummary, summarySuperseded } from './lib/fast-summary.mjs';
|
|
29
|
+
import { mergeModelSummary, modelSummaryFields, summarySuperseded } from './lib/fast-summary.mjs';
|
|
30
30
|
import { recordMetric } from './lib/metrics.mjs';
|
|
31
|
+
import { readTurnReplies } from './lib/turn-replies.mjs';
|
|
31
32
|
import { DB_DIR } from './schema.mjs';
|
|
32
33
|
import {
|
|
33
34
|
insertObservationRow,
|
|
@@ -1740,17 +1741,62 @@ async function waitForEpisodeFlushes(flushTimeout, superseded) {
|
|
|
1740
1741
|
export const SUMMARY_REPLY_HEAD = 2000;
|
|
1741
1742
|
export const SUMMARY_REPLY_TAIL = 1000;
|
|
1742
1743
|
|
|
1744
|
+
/**
|
|
1745
|
+
* D22 — a session of two or more turns gives the summary prompt every turn's last reply, not
|
|
1746
|
+
* only the final one: on 20 multi-turn sessions the final-reply prompt left a main finished
|
|
1747
|
+
* piece of work out of `completed` in 13 (rulers.md, session summary events A/B, reading 2).
|
|
1748
|
+
* An earlier turn's reply is cut to its first SUMMARY_TURN_HEAD and last SUMMARY_TURN_TAIL
|
|
1749
|
+
* characters (the final one keeps the D19 cut), and at most the first SUMMARY_TURNS_FIRST and
|
|
1750
|
+
* the last SUMMARY_TURNS_LAST turns are shown — the cuts the D21/D22 judges read.
|
|
1751
|
+
*/
|
|
1752
|
+
export const SUMMARY_TURN_HEAD = 700;
|
|
1753
|
+
export const SUMMARY_TURN_TAIL = 300;
|
|
1754
|
+
export const SUMMARY_TURNS_FIRST = 4;
|
|
1755
|
+
export const SUMMARY_TURNS_LAST = 8;
|
|
1756
|
+
|
|
1757
|
+
/**
|
|
1758
|
+
* D26 (D#845) — the last sentence of both reply rules: `completed` ordered by importance, so the
|
|
1759
|
+
* Last Session line SessionStart cuts to 120 characters starts with the session's main finished
|
|
1760
|
+
* outcome. That line left it out in 23 of 60 calls without this sentence and 11 of 60 with it;
|
|
1761
|
+
* no other count rose by more than 1 (docs/audits/20261112-d26-reading.md). The prompt without
|
|
1762
|
+
* a reply does not carry it.
|
|
1763
|
+
*/
|
|
1764
|
+
export const SUMMARY_COMPLETED_ORDER =
|
|
1765
|
+
"Order completed by importance: begin with the session's most important finished outcome, the one a person picking this work up next most needs to know (such as a release published, a deploy live, a fix merged or a measurement's verdict), then list every other finished item. This changes only the order: keep every item and detail you would otherwise include, and an item's state is still the one given by the latest reply that mentions it.";
|
|
1766
|
+
|
|
1743
1767
|
/**
|
|
1744
1768
|
* The final reply as the summary prompt carries it: scrubbed whole first, so a secret
|
|
1745
1769
|
* straddling a cut is never half-kept, then cut to head + tail with the omitted length named.
|
|
1746
1770
|
* Cuts land on code-point boundaries. Empty for an empty or missing reply.
|
|
1747
1771
|
*/
|
|
1748
|
-
export function summaryReplyExcerpt(reply) {
|
|
1772
|
+
export function summaryReplyExcerpt(reply, head = SUMMARY_REPLY_HEAD, tail = SUMMARY_REPLY_TAIL) {
|
|
1749
1773
|
const text = scrubSecrets(String(reply ?? '')).trim();
|
|
1750
1774
|
const points = Array.from(text);
|
|
1751
|
-
if (points.length <=
|
|
1752
|
-
const omitted = points.length -
|
|
1753
|
-
return `${points.slice(0,
|
|
1775
|
+
if (points.length <= head + tail) return text;
|
|
1776
|
+
const omitted = points.length - head - tail;
|
|
1777
|
+
return `${points.slice(0, head).join('')}\n[… ${omitted} characters omitted …]\n${points.slice(-tail).join('')}`;
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
/**
|
|
1781
|
+
* D22: the turns block of the summary prompt, oldest first, or '' for fewer than two turns with
|
|
1782
|
+
* text. The last turn is the final reply and keeps the D19 cut.
|
|
1783
|
+
* @param {string[]} replies each turn's last assistant text, oldest first
|
|
1784
|
+
*/
|
|
1785
|
+
function summaryTurnsBlock(replies) {
|
|
1786
|
+
const turns = (Array.isArray(replies) ? replies : []).filter((r) => typeof r === 'string' && r.trim());
|
|
1787
|
+
if (turns.length < 2) return '';
|
|
1788
|
+
const n = turns.length;
|
|
1789
|
+
const cut = (r, i) =>
|
|
1790
|
+
i === n - 1 ? summaryReplyExcerpt(r) : summaryReplyExcerpt(r, SUMMARY_TURN_HEAD, SUMMARY_TURN_TAIL);
|
|
1791
|
+
const block = (i) => `[Turn ${i + 1} of ${n}${i === n - 1 ? ', final' : ''}]\n${cut(turns[i], i)}`;
|
|
1792
|
+
const idx = turns.map((_, i) => i);
|
|
1793
|
+
if (n <= SUMMARY_TURNS_FIRST + SUMMARY_TURNS_LAST) return idx.map(block).join('\n\n');
|
|
1794
|
+
const omitted = n - SUMMARY_TURNS_FIRST - SUMMARY_TURNS_LAST;
|
|
1795
|
+
return [
|
|
1796
|
+
...idx.slice(0, SUMMARY_TURNS_FIRST).map(block),
|
|
1797
|
+
`[… ${omitted} turns omitted …]`,
|
|
1798
|
+
...idx.slice(-SUMMARY_TURNS_LAST).map(block),
|
|
1799
|
+
].join('\n\n');
|
|
1754
1800
|
}
|
|
1755
1801
|
|
|
1756
1802
|
/**
|
|
@@ -1777,16 +1823,20 @@ export function mergeSummaryRows(observations, events) {
|
|
|
1777
1823
|
* The session summary prompt. `observations` are {type, title, narrative} newest first,
|
|
1778
1824
|
* `userPrompts` the raw prompt texts in order; both are cut here. `finalReply`, when given, is
|
|
1779
1825
|
* the session's last assistant message (D19): it goes into the user part behind the same input
|
|
1780
|
-
* guard, and the system part says the outcome it reports wins
|
|
1781
|
-
* one shipped before D19,
|
|
1826
|
+
* guard, and the system part says the outcome it reports wins and that completed is ordered by
|
|
1827
|
+
* importance (SUMMARY_COMPLETED_ORDER, D26). Without one the prompt is the one shipped before D19,
|
|
1828
|
+
* byte for byte. `turnReplies` (D22), each turn's last reply oldest
|
|
1829
|
+
* first, replaces the final reply when it holds two or more turns with text (its last one IS
|
|
1830
|
+
* the final reply); with fewer the prompt is the D19 one.
|
|
1782
1831
|
*/
|
|
1783
|
-
export function buildSessionSummaryPrompt({ project, observations, userPrompts, finalReply }) {
|
|
1832
|
+
export function buildSessionSummaryPrompt({ project, observations, userPrompts, finalReply, turnReplies }) {
|
|
1784
1833
|
const obsList = observations
|
|
1785
1834
|
.map((o, i) => `${i + 1}. [${o.type}] ${o.title}${o.narrative ? ': ' + truncate(o.narrative, 200) : ''}`)
|
|
1786
1835
|
.join('\n');
|
|
1787
1836
|
const prompts = userPrompts.map((p) => truncate(p, 300));
|
|
1788
1837
|
const promptCtx = prompts.length > 0 ? `\nUser requests: ${prompts.join(' → ')}\n` : '';
|
|
1789
|
-
const
|
|
1838
|
+
const turns = summaryTurnsBlock(turnReplies);
|
|
1839
|
+
const reply = turns ? '' : summaryReplyExcerpt(finalReply);
|
|
1790
1840
|
|
|
1791
1841
|
// cso F#4: split system/user. The userPrompts content is the single highest-leakage path
|
|
1792
1842
|
// for memory poisoning — putting it in the user role behind an explicit boundary is the
|
|
@@ -1797,14 +1847,17 @@ ${MEMORY_INPUT_GUARD}
|
|
|
1797
1847
|
JSON: {"request":"what the user was working on","completed":"specific items accomplished with file names","remaining_items":"specific unfinished items from the original request — compare investigation scope with actual changes to infer what was NOT yet done; be precise with file:issue format, or empty string if all done","next_steps":"suggested follow-up","lessons":["non-obvious insights discovered during this session"],"key_decisions":["important design choices made and WHY"]}
|
|
1798
1848
|
lessons: Only genuinely non-obvious insights (debugging discoveries, gotchas, architectural reasons). Empty array if routine.
|
|
1799
1849
|
key_decisions: Only decisions with lasting impact (library choices, architecture, data model). Include reasoning. Empty array if none.${
|
|
1800
|
-
|
|
1850
|
+
turns
|
|
1801
1851
|
? `
|
|
1802
|
-
|
|
1803
|
-
:
|
|
1852
|
+
Replies: the user message ends with the assistant's last reply of each turn, oldest first; the last one is the session's final reply. These are the assistant's own account of the outcome. completed lists the main work the replies report as done in every turn, not only the last. Work a reply reports as done (tests passed, saved, committed, fixed) is completed — never list it in remaining_items or next_steps. An item's state is the one given by the latest reply that mentions it. What is still unfinished, failed or left for later belongs in remaining_items. ${SUMMARY_COMPLETED_ORDER}`
|
|
1853
|
+
: reply
|
|
1854
|
+
? `
|
|
1855
|
+
Final reply: the user message ends with the session's final reply, the assistant's own account of the outcome. Work it reports as done (tests passed, saved, committed, fixed) is completed — never list it in remaining_items or next_steps. What it reports as unfinished, failed or left for later belongs in remaining_items. ${SUMMARY_COMPLETED_ORDER}`
|
|
1856
|
+
: ''
|
|
1804
1857
|
}`;
|
|
1805
1858
|
const user = `Project: ${project}${promptCtx}
|
|
1806
1859
|
Observations (${observations.length} total):
|
|
1807
|
-
${obsList}${reply ? `\n\nFinal reply:\n${reply}` : ''}`;
|
|
1860
|
+
${obsList}${turns ? `\n\nReplies, one per turn, oldest first:\n${turns}` : reply ? `\n\nFinal reply:\n${reply}` : ''}`;
|
|
1808
1861
|
return { system, user };
|
|
1809
1862
|
}
|
|
1810
1863
|
|
|
@@ -1879,7 +1932,18 @@ export async function handleLLMSummary() {
|
|
|
1879
1932
|
)
|
|
1880
1933
|
.all(sessionId)
|
|
1881
1934
|
.map((p) => p.prompt_text);
|
|
1882
|
-
|
|
1935
|
+
// D19 + D22 (D#825): every turn's last reply, as Stop recorded them under this session
|
|
1936
|
+
// (lib/turn-replies.mjs). Two or more show every turn; one is the final reply; none gives the
|
|
1937
|
+
// prompt without a reply. The Stop worker and the /clear or /compact one read the same record,
|
|
1938
|
+
// so neither depends on which transcript it was handed or what was written there since.
|
|
1939
|
+
const turnReplies = readTurnReplies(RUNTIME_DIR, sessionId);
|
|
1940
|
+
const prompt = buildSessionSummaryPrompt({
|
|
1941
|
+
project,
|
|
1942
|
+
observations: recentObs,
|
|
1943
|
+
userPrompts,
|
|
1944
|
+
finalReply: turnReplies.at(-1) ?? null,
|
|
1945
|
+
turnReplies,
|
|
1946
|
+
});
|
|
1883
1947
|
|
|
1884
1948
|
if (!(await acquireLLMSlot())) {
|
|
1885
1949
|
debugLog('WARN', 'llm-summary', 'semaphore timeout, skipping summary');
|
|
@@ -1900,65 +1964,17 @@ export async function handleLLMSummary() {
|
|
|
1900
1964
|
releaseLLMSlot();
|
|
1901
1965
|
}
|
|
1902
1966
|
|
|
1903
|
-
//
|
|
1904
|
-
//
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
// JSON.stringify'd separately below.)
|
|
1908
|
-
const asText = (v) =>
|
|
1909
|
-
Array.isArray(v)
|
|
1910
|
-
? v.filter((x) => typeof x === 'string' && x.trim()).join('; ')
|
|
1911
|
-
: typeof v === 'string'
|
|
1912
|
-
? v
|
|
1913
|
-
: '';
|
|
1914
|
-
|
|
1915
|
-
// Persist when ANY meaningful field is present — not just `request`. Gating on `request`
|
|
1916
|
-
// alone dropped the whole INSERT/UPDATE (losing the session's highest-value fields:
|
|
1917
|
-
// lessons + key_decisions) whenever Haiku returned an empty request string but a rich
|
|
1918
|
-
// `{completed, lessons, key_decisions}` — a common degraded shape. Downstream tolerates an
|
|
1919
|
-
// empty request: INSERT writes '' and the UPDATE keeps the row's own request (or an older row's)
|
|
1920
|
-
// when the reply's is empty. Use asText in the gate so a non-string / empty-array field can't falsely
|
|
1921
|
-
// trigger it.
|
|
1922
|
-
// Items are kept only when they are non-empty strings. Array.isArray alone stored a reply of
|
|
1923
|
-
// [123, null, {…}, "real lesson"] as-is, and SessionStart then injected
|
|
1924
|
-
// "Lessons: 123; ; [object Object]", pushing the real lesson out of its 3-item window.
|
|
1925
|
-
const textItems = (v) =>
|
|
1926
|
-
Array.isArray(v) ? v.filter((x) => typeof x === 'string' && x.trim()).map((x) => x.trim()) : [];
|
|
1927
|
-
const lessons = llmParsed ? textItems(llmParsed.lessons) : [];
|
|
1928
|
-
const keyDecisions = llmParsed ? textItems(llmParsed.key_decisions) : [];
|
|
1929
|
-
const hasSummaryContent =
|
|
1930
|
-
llmParsed &&
|
|
1931
|
-
(asText(llmParsed.request) ||
|
|
1932
|
-
asText(llmParsed.completed) ||
|
|
1933
|
-
asText(llmParsed.remaining_items) ||
|
|
1934
|
-
asText(llmParsed.next_steps) ||
|
|
1935
|
-
lessons.length > 0 ||
|
|
1936
|
-
keyDecisions.length > 0);
|
|
1937
|
-
if (hasSummaryContent) {
|
|
1967
|
+
// The reply's fields, coerced and scrubbed (lib/fast-summary.mjs), or null with nothing to
|
|
1968
|
+
// write.
|
|
1969
|
+
const safe = modelSummaryFields(llmParsed);
|
|
1970
|
+
if (safe) {
|
|
1938
1971
|
const now = new Date();
|
|
1939
|
-
const lessonsJson = lessons.length > 0 ? JSON.stringify(lessons) : null;
|
|
1940
|
-
const decisionsJson = keyDecisions.length > 0 ? JSON.stringify(keyDecisions) : null;
|
|
1941
|
-
|
|
1942
1972
|
// Upgrade the session's summary row instead of creating another. This worker runs after
|
|
1943
1973
|
// EVERY Stop (one per assistant turn) and again from SessionStart's /clear path; selecting
|
|
1944
1974
|
// only a `notes = 'fast'` row found nothing once the first run had upgraded it, and each
|
|
1945
1975
|
// later turn INSERTed (one live session: 37 rows in 65 minutes). mergeModelSummary lands
|
|
1946
1976
|
// on the session's newest row and keeps a report's Done / Not done over the model's
|
|
1947
1977
|
// (lib/fast-summary.mjs).
|
|
1948
|
-
//
|
|
1949
|
-
// Scrub LLM-output text fields at the write boundary. lessons / key_decisions are
|
|
1950
|
-
// JSON.stringify(array<string>); scrubSecrets uses opaque placeholders that preserve
|
|
1951
|
-
// JSON structure, so the JSON string is scrubbed whole.
|
|
1952
|
-
const safe = scrubRecord('session_summaries', {
|
|
1953
|
-
request: asText(llmParsed.request),
|
|
1954
|
-
investigated: asText(llmParsed.investigated),
|
|
1955
|
-
learned: asText(llmParsed.learned),
|
|
1956
|
-
completed: asText(llmParsed.completed),
|
|
1957
|
-
next_steps: asText(llmParsed.next_steps),
|
|
1958
|
-
remaining_items: asText(llmParsed.remaining_items),
|
|
1959
|
-
lessons: lessonsJson,
|
|
1960
|
-
key_decisions: decisionsJson,
|
|
1961
|
-
});
|
|
1962
1978
|
if (mergeModelSummary(db, { sessionId, project, fields: safe, now, spawnEpoch })) {
|
|
1963
1979
|
outcome('written');
|
|
1964
1980
|
} else {
|
package/hook.mjs
CHANGED
|
@@ -179,6 +179,7 @@ import {
|
|
|
179
179
|
} from './lib/citation-tracker.mjs';
|
|
180
180
|
import { resolveEdgeAttribution, readPreRecallFileEdges } from './lib/edge-attribution.mjs';
|
|
181
181
|
import { extractTailAssistantText, extractStructuredSummary } from './lib/summary-extractor.mjs';
|
|
182
|
+
import { recordTurnReply, TURN_REPLIES_PREFIX } from './lib/turn-replies.mjs';
|
|
182
183
|
import { searchRelevantMemories, formatMemoryLine, selectImperativeLesson } from './hook-memory.mjs';
|
|
183
184
|
import { searchInjectableEvents, renderInjectableEvent } from './lib/events-injection.mjs';
|
|
184
185
|
import { upsFtsQuery } from './lib/ups-query.mjs';
|
|
@@ -1257,6 +1258,9 @@ async function readStopHookInput() {
|
|
|
1257
1258
|
// collides across parallel sessions for the same project (see docs/bug.txt).
|
|
1258
1259
|
let ccSessionId = null;
|
|
1259
1260
|
let transcriptPath = null;
|
|
1261
|
+
// The host's own copy of this turn's final reply (Claude Code's Stop input, optional). Kept as
|
|
1262
|
+
// given, '' included: an empty one means the turn ended without text, not that it is unknown.
|
|
1263
|
+
let lastAssistantMessage = null;
|
|
1260
1264
|
try {
|
|
1261
1265
|
const raw = await readStdin();
|
|
1262
1266
|
const hookData = JSON.parse(raw.text);
|
|
@@ -1266,10 +1270,39 @@ async function readStopHookInput() {
|
|
|
1266
1270
|
if (typeof hookData?.transcript_path === 'string' && hookData.transcript_path.length > 0) {
|
|
1267
1271
|
transcriptPath = hookData.transcript_path;
|
|
1268
1272
|
}
|
|
1273
|
+
if (typeof hookData?.last_assistant_message === 'string') {
|
|
1274
|
+
lastAssistantMessage = hookData.last_assistant_message;
|
|
1275
|
+
}
|
|
1269
1276
|
} catch {
|
|
1270
1277
|
/* stdin unavailable — fall back to local session id */
|
|
1271
1278
|
}
|
|
1272
|
-
return { ccSessionId, transcriptPath };
|
|
1279
|
+
return { ccSessionId, transcriptPath, lastAssistantMessage };
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
/**
|
|
1283
|
+
* D#825 — record this turn's final reply under this Stop's memory session and its current prompt
|
|
1284
|
+
* number, for the summary worker (lib/turn-replies.mjs). The host's `last_assistant_message`
|
|
1285
|
+
* when it sends one; from a host that does not, the transcript's last assistant text, the reply
|
|
1286
|
+
* the Stop baseline reads. A turn answering a task notice stores no prompt, so its reply lands
|
|
1287
|
+
* on the prompt before it and replaces that reply: a turn's last reply wins. Never throws.
|
|
1288
|
+
*/
|
|
1289
|
+
function recordStopTurnReply(db, { sessionId, transcriptPath, lastAssistantMessage }) {
|
|
1290
|
+
try {
|
|
1291
|
+
const reply =
|
|
1292
|
+
lastAssistantMessage !== null
|
|
1293
|
+
? lastAssistantMessage
|
|
1294
|
+
: transcriptPath
|
|
1295
|
+
? extractTailAssistantText(transcriptPath)
|
|
1296
|
+
: null;
|
|
1297
|
+
if (!reply || !reply.trim()) return;
|
|
1298
|
+
const n =
|
|
1299
|
+
db
|
|
1300
|
+
.prepare('SELECT MAX(prompt_number) AS n FROM user_prompts WHERE content_session_id = ?')
|
|
1301
|
+
.get(sessionId)?.n ?? 0;
|
|
1302
|
+
recordTurnReply(RUNTIME_DIR, sessionId, n, reply);
|
|
1303
|
+
} catch (e) {
|
|
1304
|
+
debugCatch(e, 'stop-turn-reply');
|
|
1305
|
+
}
|
|
1273
1306
|
}
|
|
1274
1307
|
|
|
1275
1308
|
/** Flush whatever is left in the episode buffer, under the PostToolUse lock. */
|
|
@@ -1865,7 +1898,7 @@ function trackCitationsAtStop(db, { sessionId, project, ccSessionId, transcriptP
|
|
|
1865
1898
|
|
|
1866
1899
|
async function handleStop() {
|
|
1867
1900
|
// Read Claude Code's real session_id from hook stdin for parallel-session scoping.
|
|
1868
|
-
const { ccSessionId, transcriptPath } = await readStopHookInput();
|
|
1901
|
+
const { ccSessionId, transcriptPath, lastAssistantMessage } = await readStopHookInput();
|
|
1869
1902
|
|
|
1870
1903
|
// Capture session info BEFORE cleanup. All DB lookups use the mem-internal id
|
|
1871
1904
|
// (that's what handleUserPrompt wrote into user_prompts / sdk_sessions / observations
|
|
@@ -1900,6 +1933,9 @@ async function handleStop() {
|
|
|
1900
1933
|
if (!isDbBusyError(e)) throw e;
|
|
1901
1934
|
debugLog('WARN', 'stop', 'database locked by another process; this turn was not recorded');
|
|
1902
1935
|
} finally {
|
|
1936
|
+
// A read and a file write, so it records even when the writes above lost the lock (pre-ship
|
|
1937
|
+
// review of abeac529, F2); before the worker below is spawned, which reads these replies.
|
|
1938
|
+
recordStopTurnReply(db, { sessionId, transcriptPath, lastAssistantMessage });
|
|
1903
1939
|
db.close();
|
|
1904
1940
|
}
|
|
1905
1941
|
}
|
|
@@ -1980,7 +2016,8 @@ function gcStalePreRecallCooldowns() {
|
|
|
1980
2016
|
name.startsWith('.claude-mem-injected-') ||
|
|
1981
2017
|
name.startsWith('.claude-mem-keyctx-') || // D#123 Key Context marker — same per-session growth, same 24h GC
|
|
1982
2018
|
name.startsWith(BUGFIX_NUDGE_MARKER_PREFIX) || // §9-B once-per-session nudge claim — same shape
|
|
1983
|
-
name.startsWith(RECALL_SHOWN_PREFIX)
|
|
2019
|
+
name.startsWith(RECALL_SHOWN_PREFIX) || // injection budget C1/C3 per-thread marker — same shape
|
|
2020
|
+
name.startsWith(TURN_REPLIES_PREFIX); // D#825 per-session turn replies; its workers read it within minutes
|
|
1984
2021
|
if (!isCooldown && !isInjectedMarker) continue;
|
|
1985
2022
|
try {
|
|
1986
2023
|
const p = join(RUNTIME_DIR, name);
|
package/install.mjs
CHANGED
|
@@ -1973,10 +1973,47 @@ async function uninstall() {
|
|
|
1973
1973
|
let purgeIncomplete = false; // reported, and not followed by "Done!" and exit 0
|
|
1974
1974
|
if (flags.has('--purge')) {
|
|
1975
1975
|
const homeDir = join(homedir(), '.claude-mem-lite');
|
|
1976
|
-
//
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1976
|
+
// D#829: with ~/.claude-mem-lite a link, rmSync took the link alone and the run said
|
|
1977
|
+
// "Data purged" and "Done!" with the store left behind it. The target may be a directory the
|
|
1978
|
+
// user chose, and it holds the code too, so nothing is removed through the link. Nothing is
|
|
1979
|
+
// removed at all: removing the link first and leaving the rest to the relocated purge ended in
|
|
1980
|
+
// "Done!" with the store left when CLAUDE_MEM_DIR named the target by another spelling
|
|
1981
|
+
// (`<link>/`), and telling that spelling apart needs resolved paths, whose failures were read
|
|
1982
|
+
// as "the target is gone" (D#811 reviews r1 F1, r2 R2-1). One lstat decides; the link stays as
|
|
1983
|
+
// the record of where the store is.
|
|
1984
|
+
let homeIsLink = false;
|
|
1985
|
+
try {
|
|
1986
|
+
homeIsLink = lstatSync(DATA_DIR).isSymbolicLink();
|
|
1987
|
+
} catch {
|
|
1988
|
+
/* absent, or not lstat-able: existsSync below decides, as before */
|
|
1989
|
+
}
|
|
1990
|
+
if (homeIsLink) {
|
|
1991
|
+
let to = '';
|
|
1992
|
+
try {
|
|
1993
|
+
to = ` to ${readlinkSync(DATA_DIR)}`;
|
|
1994
|
+
} catch {
|
|
1995
|
+
/* raced away */
|
|
1996
|
+
}
|
|
1997
|
+
warn(
|
|
1998
|
+
`~/.claude-mem-lite is a link${to}. --purge does not delete through a link, so it removed nothing` +
|
|
1999
|
+
(MEM_DATA_DIR !== homeDir ? ` (CLAUDE_MEM_DIR ${MEM_DATA_DIR} included).` : '.'),
|
|
2000
|
+
);
|
|
2001
|
+
purgeIncomplete = true;
|
|
2002
|
+
} else if (existsSync(DATA_DIR) && DATA_DIR === homeDir) {
|
|
2003
|
+
// Always remove the homedir code/install dir (guarded to the canonical path). An entry it
|
|
2004
|
+
// may not remove threw out of here uncaught, and the relocated purge below never ran (D#815).
|
|
2005
|
+
try {
|
|
2006
|
+
rmSync(DATA_DIR, { recursive: true, force: true });
|
|
2007
|
+
// D#835 (D#829 review r2 X1): with another process deleting files in it, rmSync returned
|
|
2008
|
+
// normally and the directory, store included, was still there (7 of 12 runs on Node 26).
|
|
2009
|
+
if (existsSync(DATA_DIR)) {
|
|
2010
|
+
warn('Could not remove ~/.claude-mem-lite: it was still there when the removal returned.');
|
|
2011
|
+
purgeIncomplete = true;
|
|
2012
|
+
} else ok('Data purged (~/.claude-mem-lite/)');
|
|
2013
|
+
} catch (e) {
|
|
2014
|
+
warn(`Could not remove ~/.claude-mem-lite (${e.code || e.message}).`);
|
|
2015
|
+
purgeIncomplete = true;
|
|
2016
|
+
}
|
|
1980
2017
|
} else if (existsSync(DATA_DIR)) {
|
|
1981
2018
|
fail('DATA_DIR path mismatch, refusing to purge for safety: ' + DATA_DIR);
|
|
1982
2019
|
}
|
|
@@ -1984,8 +2021,8 @@ async function uninstall() {
|
|
|
1984
2021
|
// claude-mem-lite.db), so a mistyped CLAUDE_MEM_DIR is never touched. Even then only what
|
|
1985
2022
|
// claude-mem-lite writes there goes: the directory may be one the user keeps other files in,
|
|
1986
2023
|
// and removing it whole took those too (R32 E2E install F1, P0). It is removed only once
|
|
1987
|
-
// nothing else is left in it.
|
|
1988
|
-
if (MEM_DATA_DIR !== homeDir) {
|
|
2024
|
+
// nothing else is left in it. Not when ~/.claude-mem-lite is a link (above).
|
|
2025
|
+
if (MEM_DATA_DIR !== homeDir && !homeIsLink) {
|
|
1989
2026
|
// Not existsSync: it is false on EACCES too, so a store it could not look for was reported
|
|
1990
2027
|
// absent, then "Done!" (R32 depth-2 review M1).
|
|
1991
2028
|
let storeLookup = null;
|
|
@@ -5104,7 +5141,7 @@ Usage:
|
|
|
5104
5141
|
node install.mjs install Install (copy files to ~/.claude-mem-lite/)
|
|
5105
5142
|
node install.mjs install --dev Install dev mode (symlinks to dev dir)
|
|
5106
5143
|
node install.mjs uninstall Remove (keep data)
|
|
5107
|
-
node install.mjs uninstall --purge Remove and delete
|
|
5144
|
+
node install.mjs uninstall --purge Remove and delete the data
|
|
5108
5145
|
node install.mjs status Show current status (use --json for structured output)
|
|
5109
5146
|
node install.mjs doctor Diagnose issues (use --json for structured output)
|
|
5110
5147
|
node install.mjs cleanup Remove stale temp/staging files (use --dry-run to preview)
|
package/lib/fast-summary.mjs
CHANGED
|
@@ -456,6 +456,55 @@ export function summarySuperseded(db, sessionId, spawnEpoch) {
|
|
|
456
456
|
return Number.isFinite(latest) && latest > spawnEpoch;
|
|
457
457
|
}
|
|
458
458
|
|
|
459
|
+
/**
|
|
460
|
+
* The summary model's parsed reply as mergeModelSummary's `fields`, or null when it has nothing
|
|
461
|
+
* to write. Moved here from hook-llm.mjs's worker so a ruler replays the same cleaning.
|
|
462
|
+
* - A prose field is coerced to a string: the model sometimes returns a LIST for completed /
|
|
463
|
+
* next_steps / remaining_items, and binding a non-string to SQL threw ("Too many parameter
|
|
464
|
+
* values") and dropped the WHOLE summary, lessons and key_decisions included. Array items
|
|
465
|
+
* are joined; anything else is ''.
|
|
466
|
+
* - lessons / key_decisions keep only non-empty strings: a reply of [123, null, {…}, "real
|
|
467
|
+
* lesson"] stored as-is was injected as "Lessons: 123; ; [object Object]", pushing the real
|
|
468
|
+
* lesson out of its 3-item window.
|
|
469
|
+
* - Any meaningful field is enough, not just `request`: gating on it dropped the session's
|
|
470
|
+
* lessons and key_decisions whenever the model returned an empty request with a rich
|
|
471
|
+
* `{completed, lessons, key_decisions}`, a common degraded shape. An empty request is
|
|
472
|
+
* tolerated downstream.
|
|
473
|
+
* - Scrubbed at the write boundary. lessons / key_decisions are JSON.stringify(array<string>),
|
|
474
|
+
* scrubbed whole: the placeholders keep the JSON's structure.
|
|
475
|
+
*/
|
|
476
|
+
export function modelSummaryFields(parsed) {
|
|
477
|
+
if (!parsed) return null;
|
|
478
|
+
const asText = (v) =>
|
|
479
|
+
Array.isArray(v)
|
|
480
|
+
? v.filter((x) => typeof x === 'string' && x.trim()).join('; ')
|
|
481
|
+
: typeof v === 'string'
|
|
482
|
+
? v
|
|
483
|
+
: '';
|
|
484
|
+
const textItems = (v) =>
|
|
485
|
+
Array.isArray(v) ? v.filter((x) => typeof x === 'string' && x.trim()).map((x) => x.trim()) : [];
|
|
486
|
+
const lessons = textItems(parsed.lessons);
|
|
487
|
+
const keyDecisions = textItems(parsed.key_decisions);
|
|
488
|
+
const hasContent =
|
|
489
|
+
asText(parsed.request) ||
|
|
490
|
+
asText(parsed.completed) ||
|
|
491
|
+
asText(parsed.remaining_items) ||
|
|
492
|
+
asText(parsed.next_steps) ||
|
|
493
|
+
lessons.length > 0 ||
|
|
494
|
+
keyDecisions.length > 0;
|
|
495
|
+
if (!hasContent) return null;
|
|
496
|
+
return scrubRecord('session_summaries', {
|
|
497
|
+
request: asText(parsed.request),
|
|
498
|
+
investigated: asText(parsed.investigated),
|
|
499
|
+
learned: asText(parsed.learned),
|
|
500
|
+
completed: asText(parsed.completed),
|
|
501
|
+
next_steps: asText(parsed.next_steps),
|
|
502
|
+
remaining_items: asText(parsed.remaining_items),
|
|
503
|
+
lessons: lessons.length > 0 ? JSON.stringify(lessons) : null,
|
|
504
|
+
key_decisions: keyDecisions.length > 0 ? JSON.stringify(keyDecisions) : null,
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
|
|
459
508
|
const MODEL_TEXT_FIELDS = ['request', 'investigated', 'learned', 'next_steps'];
|
|
460
509
|
const MODEL_JSON_FIELDS = ['lessons', 'key_decisions'];
|
|
461
510
|
const SUMMARY_COLUMNS = [...MODEL_TEXT_FIELDS, 'completed', 'remaining_items', ...MODEL_JSON_FIELDS];
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// D#825 — each turn's last reply, recorded at Stop under the memory session that answered it, for
|
|
2
|
+
// the session summary worker (D19 + D22). Reading the turns back out of the transcript had to
|
|
3
|
+
// infer which session a record belonged to, and that inference was wrong on real shapes: 148 of
|
|
4
|
+
// 1,939 simulated Stops on the maintainer's transcripts (2026-11-12) took another session's turn
|
|
5
|
+
// when cut at compactions alone, 57 still with a time floor (tasks/specs/d825-summary-turn-capture.md).
|
|
6
|
+
// Stop knows its own session and is handed the reply (`last_assistant_message`), so here nothing
|
|
7
|
+
// is inferred.
|
|
8
|
+
//
|
|
9
|
+
// One file per memory session in the runtime dir, keyed by prompt number: a turn's later reply
|
|
10
|
+
// (a background task's notice answered in the same turn) replaces the earlier one, and replies
|
|
11
|
+
// given before the session's first stored prompt (number 0) come first. SessionStart's 24 h
|
|
12
|
+
// runtime sweep removes the file; a session that expires (12 h) is summarized well before.
|
|
13
|
+
|
|
14
|
+
import { readFileSync, existsSync } from 'fs';
|
|
15
|
+
import { join } from 'path';
|
|
16
|
+
import { createHash } from 'crypto';
|
|
17
|
+
import { scrubSecrets } from '../secret-scrub.mjs';
|
|
18
|
+
import { atomicWriteFileSync } from './atomic-write.mjs';
|
|
19
|
+
|
|
20
|
+
export const TURN_REPLIES_PREFIX = 'turn-replies-';
|
|
21
|
+
|
|
22
|
+
// Code points kept per reply. The longest final reply over 1,939 Stops on the maintainer's
|
|
23
|
+
// transcripts was 7,081 (p99.9 5,187; 2026-11-12), and the summary prompt cuts every reply to at
|
|
24
|
+
// most 2,000 + 1,000 itself, so the cut only bounds the file.
|
|
25
|
+
export const TURN_REPLY_MAX_CHARS = 12000;
|
|
26
|
+
const HEAD = (TURN_REPLY_MAX_CHARS * 2) / 3;
|
|
27
|
+
const TAIL = TURN_REPLY_MAX_CHARS / 3;
|
|
28
|
+
|
|
29
|
+
/** The record file of `sessionId`; a long id keeps a hash of the whole id, so its tail still counts. */
|
|
30
|
+
export function turnRepliesPath(runtimeDir, sessionId) {
|
|
31
|
+
const id = String(sessionId);
|
|
32
|
+
const safe = id.replace(/[^a-zA-Z0-9_.-]/g, '-');
|
|
33
|
+
const key =
|
|
34
|
+
safe.length <= 120
|
|
35
|
+
? safe
|
|
36
|
+
: `${safe.slice(0, 80)}-${createHash('sha256').update(id).digest('hex').slice(0, 16)}`;
|
|
37
|
+
return join(runtimeDir, `${TURN_REPLIES_PREFIX}${key}.json`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Scrubbed whole first, so a secret across the cut is never half kept; then cut to head + tail. */
|
|
41
|
+
function storedText(reply) {
|
|
42
|
+
const text = scrubSecrets(String(reply ?? '')).trim();
|
|
43
|
+
const points = Array.from(text);
|
|
44
|
+
if (points.length <= TURN_REPLY_MAX_CHARS) return text;
|
|
45
|
+
const omitted = points.length - HEAD - TAIL;
|
|
46
|
+
return `${points.slice(0, HEAD).join('')}\n[… ${omitted} characters omitted …]\n${points.slice(-TAIL).join('')}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** [promptNumber, text] pairs from the file, or [] when it is missing, unreadable or of another shape. */
|
|
50
|
+
function readPairs(file) {
|
|
51
|
+
try {
|
|
52
|
+
const turns = JSON.parse(readFileSync(file, 'utf8'))?.turns;
|
|
53
|
+
if (!Array.isArray(turns)) return [];
|
|
54
|
+
return turns.filter(
|
|
55
|
+
(t) => Array.isArray(t) && Number.isInteger(t[0]) && t[0] >= 0 && typeof t[1] === 'string' && t[1],
|
|
56
|
+
);
|
|
57
|
+
} catch {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Record `reply` as the last reply of prompt `promptNumber` in `sessionId` (0 before the first
|
|
64
|
+
* stored prompt). A blank reply records nothing. Never throws.
|
|
65
|
+
* @returns {boolean} whether the file was written
|
|
66
|
+
*/
|
|
67
|
+
export function recordTurnReply(runtimeDir, sessionId, promptNumber, reply) {
|
|
68
|
+
if (!sessionId || !Number.isInteger(promptNumber) || promptNumber < 0) return false;
|
|
69
|
+
const text = storedText(reply);
|
|
70
|
+
if (!text) return false;
|
|
71
|
+
// A missing runtime dir records nothing (the atomic writer would create it).
|
|
72
|
+
if (!existsSync(runtimeDir)) return false;
|
|
73
|
+
const file = turnRepliesPath(runtimeDir, sessionId);
|
|
74
|
+
const turns = new Map(readPairs(file));
|
|
75
|
+
turns.set(promptNumber, text);
|
|
76
|
+
try {
|
|
77
|
+
atomicWriteFileSync(file, JSON.stringify({ turns: [...turns].sort((a, b) => a[0] - b[0]) }), {
|
|
78
|
+
mode: 0o600,
|
|
79
|
+
});
|
|
80
|
+
return true;
|
|
81
|
+
} catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Each turn's last reply in `sessionId`, in prompt order; [] when none was recorded. */
|
|
87
|
+
export function readTurnReplies(runtimeDir, sessionId) {
|
|
88
|
+
if (!sessionId) return [];
|
|
89
|
+
// Written in prompt order (recordTurnReply sorts), so read in file order.
|
|
90
|
+
return readPairs(turnRepliesPath(runtimeDir, sessionId)).map((t) => t[1]);
|
|
91
|
+
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-mem-lite",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.35.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.35.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.35.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",
|
|
@@ -97,6 +97,7 @@
|
|
|
97
97
|
"lib/cooldown-path.mjs",
|
|
98
98
|
"lib/tmp-fixture-sweep.mjs",
|
|
99
99
|
"lib/summary-extractor.mjs",
|
|
100
|
+
"lib/turn-replies.mjs",
|
|
100
101
|
"lib/id-routing.mjs",
|
|
101
102
|
"lib/err-sampler.mjs",
|
|
102
103
|
"lib/hook-telemetry.mjs",
|
package/secret-scrub.mjs
CHANGED
|
@@ -297,6 +297,14 @@ export const SECRET_PATTERNS = [
|
|
|
297
297
|
],
|
|
298
298
|
// npm tokens (npm_...)
|
|
299
299
|
[/\bnpm_[a-zA-Z0-9]{36,}(?![A-Za-z0-9])/g, '***'],
|
|
300
|
+
// D#812: fixed-prefix, fixed-body provider tokens. Shapes from gitleaks (config/gitleaks.toml
|
|
301
|
+
// @ 5f6ec56c: huggingface-*, digitalocean-*, pypi-upload-token, shopify-*) and trufflehog
|
|
302
|
+
// (pkg/detectors/groq). Each body is one character class, so a failing match is linear.
|
|
303
|
+
[/\b(?:hf|api_org)_[a-zA-Z0-9]{34}(?![A-Za-z0-9])/g, '***'],
|
|
304
|
+
[/\bdo[opr]_v1_[a-f0-9]{64}(?![A-Za-z0-9])/g, '***'],
|
|
305
|
+
[/\bpypi-AgE[A-Za-z0-9_-]{50,}/g, '***'],
|
|
306
|
+
[/\bshp(?:at|ca|pa|ss)_[a-fA-F0-9]{32}(?![A-Za-z0-9])/g, '***'],
|
|
307
|
+
[/\bgsk_[a-zA-Z0-9]{52}(?![A-Za-z0-9])/g, '***'],
|
|
300
308
|
// Stripe keys (sk_live_, rk_live_, pk_live_, sk_test_, pk_test_) + webhook signing secret (whsec_)
|
|
301
309
|
[/\b[srp]k_(?:live|test)_[a-zA-Z0-9]{20,}(?![A-Za-z0-9])/g, '***'],
|
|
302
310
|
[/\bwhsec_[a-zA-Z0-9]{20,}(?![A-Za-z0-9])/g, '***'],
|
package/source-files.mjs
CHANGED
|
@@ -180,6 +180,9 @@ export const SOURCE_FILES = [
|
|
|
180
180
|
'cli/common.mjs',
|
|
181
181
|
'lib/transcript-scan.mjs',
|
|
182
182
|
'lib/summary-extractor.mjs',
|
|
183
|
+
// D#825: each turn's reply, recorded by Stop (hook.mjs) and read by the summary worker
|
|
184
|
+
// (hook-llm.mjs); both import it, so it swaps in before them.
|
|
185
|
+
'lib/turn-replies.mjs',
|
|
183
186
|
// D#69 episode-summarizer input filters + lesson grounding check. Statically imported
|
|
184
187
|
// by hook.mjs (PostToolUse capture, episode flush) and hook-llm.mjs (llm-episode) —
|
|
185
188
|
// missing it from the manifest would break both on auto-update.
|