claude-mem-lite 6.33.0 → 6.34.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 +11 -0
- package/README.zh-CN.md +8 -0
- package/hook-llm.mjs +64 -11
- package/hook.mjs +40 -3
- 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.34.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.34.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,17 @@ 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.34.0
|
|
243
|
+
|
|
244
|
+
**The session summary reads every turn's last reply; nothing to run, and the schema version stays
|
|
245
|
+
49.** To go back, pin `claude-mem-lite@6.33.0` and delete `runtime/turn-replies-*.json` from the
|
|
246
|
+
data directory: 6.33.0 never reads them.
|
|
247
|
+
|
|
248
|
+
- **The session summary model reads each turn's last reply**, not only the observations and
|
|
249
|
+
prompts. Stop keeps each turn's last reply, scrubbed, in `runtime/`.
|
|
250
|
+
- **The secret scrubber erases Hugging Face, DigitalOcean, PyPI, Shopify and Groq tokens.**
|
|
251
|
+
- See CHANGELOG.md.
|
|
252
|
+
|
|
242
253
|
## Upgrading to 6.33.0
|
|
243
254
|
|
|
244
255
|
**`uninstall --purge` leaves your own files in a relocated data directory; nothing to run, and the
|
package/README.zh-CN.md
CHANGED
|
@@ -201,6 +201,14 @@ rm -rf ~/claude-mem-lite/ # 首个发布版之前的非隐藏目录(不是
|
|
|
201
201
|
repos/ # 浅克隆的源代码仓库
|
|
202
202
|
```
|
|
203
203
|
|
|
204
|
+
## 升级到 6.34.0
|
|
205
|
+
|
|
206
|
+
**会话摘要会读每一轮的最后回复;不用执行任何操作,schema 版本仍是 49。** 想退回,请固定 `claude-mem-lite@6.33.0`,并删掉数据目录里的 `runtime/turn-replies-*.json`:6.33.0 不读它们。
|
|
207
|
+
|
|
208
|
+
- **会话摘要模型除了观察和提示,还读每一轮的最后回复。** Stop 把每一轮的最后回复脱敏后存在 `runtime/`。
|
|
209
|
+
- **密钥脱敏会抹掉 Hugging Face、DigitalOcean、PyPI、Shopify 和 Groq 的令牌。**
|
|
210
|
+
- 详见 CHANGELOG.md。
|
|
211
|
+
|
|
204
212
|
## 升级到 6.33.0
|
|
205
213
|
|
|
206
214
|
**数据目录改过位置时,`uninstall --purge` 不再删你自己的文件;不用执行任何操作,schema 版本仍是 49。** 第一次打开数据库时会给 `events` 加一个可空列,旧版本会忽略它。想退回,请固定 `claude-mem-lite@6.32.0`。
|
package/hook-llm.mjs
CHANGED
|
@@ -28,6 +28,7 @@ import { BG_LLM_TIMEOUT_MS } from './haiku-client.mjs';
|
|
|
28
28
|
import { scrubRecord, scrubFilePaths } from './lib/scrub-record.mjs';
|
|
29
29
|
import { mergeModelSummary, 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,52 @@ 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
|
+
|
|
1743
1757
|
/**
|
|
1744
1758
|
* The final reply as the summary prompt carries it: scrubbed whole first, so a secret
|
|
1745
1759
|
* straddling a cut is never half-kept, then cut to head + tail with the omitted length named.
|
|
1746
1760
|
* Cuts land on code-point boundaries. Empty for an empty or missing reply.
|
|
1747
1761
|
*/
|
|
1748
|
-
export function summaryReplyExcerpt(reply) {
|
|
1762
|
+
export function summaryReplyExcerpt(reply, head = SUMMARY_REPLY_HEAD, tail = SUMMARY_REPLY_TAIL) {
|
|
1749
1763
|
const text = scrubSecrets(String(reply ?? '')).trim();
|
|
1750
1764
|
const points = Array.from(text);
|
|
1751
|
-
if (points.length <=
|
|
1752
|
-
const omitted = points.length -
|
|
1753
|
-
return `${points.slice(0,
|
|
1765
|
+
if (points.length <= head + tail) return text;
|
|
1766
|
+
const omitted = points.length - head - tail;
|
|
1767
|
+
return `${points.slice(0, head).join('')}\n[… ${omitted} characters omitted …]\n${points.slice(-tail).join('')}`;
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
/**
|
|
1771
|
+
* D22: the turns block of the summary prompt, oldest first, or '' for fewer than two turns with
|
|
1772
|
+
* text. The last turn is the final reply and keeps the D19 cut.
|
|
1773
|
+
* @param {string[]} replies each turn's last assistant text, oldest first
|
|
1774
|
+
*/
|
|
1775
|
+
function summaryTurnsBlock(replies) {
|
|
1776
|
+
const turns = (Array.isArray(replies) ? replies : []).filter((r) => typeof r === 'string' && r.trim());
|
|
1777
|
+
if (turns.length < 2) return '';
|
|
1778
|
+
const n = turns.length;
|
|
1779
|
+
const cut = (r, i) =>
|
|
1780
|
+
i === n - 1 ? summaryReplyExcerpt(r) : summaryReplyExcerpt(r, SUMMARY_TURN_HEAD, SUMMARY_TURN_TAIL);
|
|
1781
|
+
const block = (i) => `[Turn ${i + 1} of ${n}${i === n - 1 ? ', final' : ''}]\n${cut(turns[i], i)}`;
|
|
1782
|
+
const idx = turns.map((_, i) => i);
|
|
1783
|
+
if (n <= SUMMARY_TURNS_FIRST + SUMMARY_TURNS_LAST) return idx.map(block).join('\n\n');
|
|
1784
|
+
const omitted = n - SUMMARY_TURNS_FIRST - SUMMARY_TURNS_LAST;
|
|
1785
|
+
return [
|
|
1786
|
+
...idx.slice(0, SUMMARY_TURNS_FIRST).map(block),
|
|
1787
|
+
`[… ${omitted} turns omitted …]`,
|
|
1788
|
+
...idx.slice(-SUMMARY_TURNS_LAST).map(block),
|
|
1789
|
+
].join('\n\n');
|
|
1754
1790
|
}
|
|
1755
1791
|
|
|
1756
1792
|
/**
|
|
@@ -1778,15 +1814,18 @@ export function mergeSummaryRows(observations, events) {
|
|
|
1778
1814
|
* `userPrompts` the raw prompt texts in order; both are cut here. `finalReply`, when given, is
|
|
1779
1815
|
* the session's last assistant message (D19): it goes into the user part behind the same input
|
|
1780
1816
|
* guard, and the system part says the outcome it reports wins. Without one the prompt is the
|
|
1781
|
-
* one shipped before D19, byte for byte.
|
|
1817
|
+
* one shipped before D19, byte for byte. `turnReplies` (D22), each turn's last reply oldest
|
|
1818
|
+
* first, replaces the final reply when it holds two or more turns with text (its last one IS
|
|
1819
|
+
* the final reply); with fewer the prompt is the D19 one.
|
|
1782
1820
|
*/
|
|
1783
|
-
export function buildSessionSummaryPrompt({ project, observations, userPrompts, finalReply }) {
|
|
1821
|
+
export function buildSessionSummaryPrompt({ project, observations, userPrompts, finalReply, turnReplies }) {
|
|
1784
1822
|
const obsList = observations
|
|
1785
1823
|
.map((o, i) => `${i + 1}. [${o.type}] ${o.title}${o.narrative ? ': ' + truncate(o.narrative, 200) : ''}`)
|
|
1786
1824
|
.join('\n');
|
|
1787
1825
|
const prompts = userPrompts.map((p) => truncate(p, 300));
|
|
1788
1826
|
const promptCtx = prompts.length > 0 ? `\nUser requests: ${prompts.join(' → ')}\n` : '';
|
|
1789
|
-
const
|
|
1827
|
+
const turns = summaryTurnsBlock(turnReplies);
|
|
1828
|
+
const reply = turns ? '' : summaryReplyExcerpt(finalReply);
|
|
1790
1829
|
|
|
1791
1830
|
// cso F#4: split system/user. The userPrompts content is the single highest-leakage path
|
|
1792
1831
|
// for memory poisoning — putting it in the user role behind an explicit boundary is the
|
|
@@ -1797,14 +1836,17 @@ ${MEMORY_INPUT_GUARD}
|
|
|
1797
1836
|
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
1837
|
lessons: Only genuinely non-obvious insights (debugging discoveries, gotchas, architectural reasons). Empty array if routine.
|
|
1799
1838
|
key_decisions: Only decisions with lasting impact (library choices, architecture, data model). Include reasoning. Empty array if none.${
|
|
1800
|
-
|
|
1839
|
+
turns
|
|
1801
1840
|
? `
|
|
1841
|
+
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.`
|
|
1842
|
+
: reply
|
|
1843
|
+
? `
|
|
1802
1844
|
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.`
|
|
1803
|
-
|
|
1845
|
+
: ''
|
|
1804
1846
|
}`;
|
|
1805
1847
|
const user = `Project: ${project}${promptCtx}
|
|
1806
1848
|
Observations (${observations.length} total):
|
|
1807
|
-
${obsList}${reply ? `\n\nFinal reply:\n${reply}` : ''}`;
|
|
1849
|
+
${obsList}${turns ? `\n\nReplies, one per turn, oldest first:\n${turns}` : reply ? `\n\nFinal reply:\n${reply}` : ''}`;
|
|
1808
1850
|
return { system, user };
|
|
1809
1851
|
}
|
|
1810
1852
|
|
|
@@ -1879,7 +1921,18 @@ export async function handleLLMSummary() {
|
|
|
1879
1921
|
)
|
|
1880
1922
|
.all(sessionId)
|
|
1881
1923
|
.map((p) => p.prompt_text);
|
|
1882
|
-
|
|
1924
|
+
// D19 + D22 (D#825): every turn's last reply, as Stop recorded them under this session
|
|
1925
|
+
// (lib/turn-replies.mjs). Two or more show every turn; one is the final reply; none gives the
|
|
1926
|
+
// prompt without a reply. The Stop worker and the /clear or /compact one read the same record,
|
|
1927
|
+
// so neither depends on which transcript it was handed or what was written there since.
|
|
1928
|
+
const turnReplies = readTurnReplies(RUNTIME_DIR, sessionId);
|
|
1929
|
+
const prompt = buildSessionSummaryPrompt({
|
|
1930
|
+
project,
|
|
1931
|
+
observations: recentObs,
|
|
1932
|
+
userPrompts,
|
|
1933
|
+
finalReply: turnReplies.at(-1) ?? null,
|
|
1934
|
+
turnReplies,
|
|
1935
|
+
});
|
|
1883
1936
|
|
|
1884
1937
|
if (!(await acquireLLMSlot())) {
|
|
1885
1938
|
debugLog('WARN', 'llm-summary', 'semaphore timeout, skipping summary');
|
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);
|
|
@@ -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.34.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.34.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.34.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.
|