@chenhw7/dsh-memory 0.1.2 → 0.3.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/README.md +115 -109
- package/README.zh-CN.md +117 -108
- package/cordis.patch.yml +13 -8
- package/lib/client/index.js +616 -185
- package/lib/context/conflict.d.ts +19 -2
- package/lib/context/conflict.d.ts.map +1 -1
- package/lib/context/conflict.js +33 -0
- package/lib/context/conflict.js.map +1 -1
- package/lib/context/index.d.ts +34 -10
- package/lib/context/index.d.ts.map +1 -1
- package/lib/context/index.js +195 -24
- package/lib/context/index.js.map +1 -1
- package/lib/context/policy.d.ts +28 -1
- package/lib/context/policy.d.ts.map +1 -1
- package/lib/context/policy.js +60 -3
- package/lib/context/policy.js.map +1 -1
- package/lib/index.d.ts +27 -7
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +22 -0
- package/lib/index.js.map +1 -1
- package/lib/notes/index.d.ts +66 -0
- package/lib/notes/index.d.ts.map +1 -0
- package/lib/notes/index.js +180 -0
- package/lib/notes/index.js.map +1 -0
- package/lib/notes/render.d.ts +32 -0
- package/lib/notes/render.d.ts.map +1 -0
- package/lib/notes/render.js +68 -0
- package/lib/notes/render.js.map +1 -0
- package/lib/notes/scope.d.ts +35 -0
- package/lib/notes/scope.d.ts.map +1 -0
- package/lib/notes/scope.js +44 -0
- package/lib/notes/scope.js.map +1 -0
- package/lib/notes/settings.d.ts +35 -0
- package/lib/notes/settings.d.ts.map +1 -0
- package/lib/notes/settings.js +36 -0
- package/lib/notes/settings.js.map +1 -0
- package/lib/notes/writer.d.ts +32 -0
- package/lib/notes/writer.d.ts.map +1 -0
- package/lib/notes/writer.js +71 -0
- package/lib/notes/writer.js.map +1 -0
- package/lib/review/accumulator.d.ts +53 -18
- package/lib/review/accumulator.d.ts.map +1 -1
- package/lib/review/accumulator.js +176 -36
- package/lib/review/accumulator.js.map +1 -1
- package/lib/review/dedup.d.ts +16 -3
- package/lib/review/dedup.d.ts.map +1 -1
- package/lib/review/dedup.js +21 -4
- package/lib/review/dedup.js.map +1 -1
- package/lib/review/extract.d.ts +81 -5
- package/lib/review/extract.d.ts.map +1 -1
- package/lib/review/extract.js +224 -31
- package/lib/review/extract.js.map +1 -1
- package/lib/review/index.d.ts +15 -2
- package/lib/review/index.d.ts.map +1 -1
- package/lib/review/index.js +137 -55
- package/lib/review/index.js.map +1 -1
- package/lib/scanner.d.ts +15 -0
- package/lib/scanner.d.ts.map +1 -1
- package/lib/scanner.js +20 -0
- package/lib/scanner.js.map +1 -1
- package/lib/store/bm25.d.ts +48 -0
- package/lib/store/bm25.d.ts.map +1 -0
- package/lib/store/bm25.js +115 -0
- package/lib/store/bm25.js.map +1 -0
- package/lib/store/index.d.ts +26 -3
- package/lib/store/index.d.ts.map +1 -1
- package/lib/store/index.js +111 -68
- package/lib/store/index.js.map +1 -1
- package/lib/tool/index.d.ts +3 -1
- package/lib/tool/index.d.ts.map +1 -1
- package/lib/tool/index.js +52 -9
- package/lib/tool/index.js.map +1 -1
- package/lib/types.d.ts +17 -1
- package/lib/types.d.ts.map +1 -1
- package/package.json +35 -30
|
@@ -1,34 +1,76 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The periodic-review projection accumulator: a pure, synchronous fold over
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* session events that collects candidate memory fragments. No LLM runs here —
|
|
4
|
+
* the {@link agent/pre-step} listener drains the accumulator once it reaches
|
|
5
|
+
* the configured threshold and runs one extraction call.
|
|
6
|
+
*
|
|
7
|
+
* Signal sources (§5 of docs/PROJECT_NOTES.md):
|
|
8
|
+
* - `user/message` — keyword hits (explicit "remember" intent) and corrections
|
|
9
|
+
* (the user revises a prior statement).
|
|
10
|
+
* - `tool/call` + `tool/result` — **failure-streak pairing**: consecutive
|
|
11
|
+
* same-signature tool failures followed by a success emit one
|
|
12
|
+
* `pitfall-resolved` candidate (the workaround is verified by the success).
|
|
13
|
+
* One-shot failures no longer become candidates; the compaction/dispose
|
|
14
|
+
* flush still sees full events as the safety net.
|
|
7
15
|
*
|
|
8
16
|
* @module @chenhw7/dsh-memory/review/accumulator
|
|
9
17
|
*/
|
|
10
18
|
import { z as zod } from 'zod';
|
|
11
19
|
/** The projection key this unit owns in the {@link SessionProjectionMap}. */
|
|
12
20
|
export const MEMORY_REVIEW_PROJECTION_KEY = 'memory-review-candidates';
|
|
13
|
-
/**
|
|
21
|
+
/** The signal emitted when a failure streak is resolved by a success. */
|
|
22
|
+
export const PITFALL_RESOLVED_SIGNAL = 'pitfall-resolved';
|
|
23
|
+
/**
|
|
24
|
+
* Keyword hits in user messages: explicit instruction to remember. The
|
|
25
|
+
* collection layer only widens the funnel — admission conservatism (explicit
|
|
26
|
+
* demand or repeated theme) is enforced by the extraction prompt, so a
|
|
27
|
+
* missed pattern here is free loss while a false hit is cheap.
|
|
28
|
+
*/
|
|
14
29
|
const KEYWORD_PATTERNS = [
|
|
30
|
+
// Chinese explicit-remember intents.
|
|
15
31
|
{ name: 'keyword', re: /记住/ },
|
|
16
32
|
{ name: 'keyword', re: /别忘了/ },
|
|
17
33
|
{ name: 'keyword', re: /以后都/ },
|
|
34
|
+
{ name: 'keyword', re: /记下来/ },
|
|
35
|
+
{ name: 'keyword', re: /记一下/ },
|
|
36
|
+
{ name: 'keyword', re: /帮我记/ },
|
|
37
|
+
// English explicit-remember intents.
|
|
18
38
|
{ name: 'keyword', re: /remember\s+that/i },
|
|
19
39
|
{ name: 'keyword', re: /don'?t\s+forget/i },
|
|
20
40
|
{ name: 'keyword', re: /from\s+now\s+on/i },
|
|
41
|
+
{ name: 'keyword', re: /keep\s+in\s+mind/i },
|
|
42
|
+
{ name: 'keyword', re: /make\s+a\s+note/i },
|
|
43
|
+
{ name: 'keyword', re: /for\s+the\s+record/i },
|
|
21
44
|
];
|
|
22
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* Correction signals in user messages: the user revises a prior statement.
|
|
47
|
+
* Same funnel philosophy as the keyword patterns above.
|
|
48
|
+
*/
|
|
23
49
|
const CORRECTION_PATTERNS = [
|
|
50
|
+
// Chinese revisions of a prior statement.
|
|
24
51
|
{ name: 'correction', re: /不对/ },
|
|
25
52
|
{ name: 'correction', re: /不要/ },
|
|
53
|
+
{ name: 'correction', re: /其实是?/ },
|
|
54
|
+
{ name: 'correction', re: /应该是/ },
|
|
55
|
+
{ name: 'correction', re: /搞错了/ },
|
|
56
|
+
{ name: 'correction', re: /说错了/ },
|
|
57
|
+
// English revisions of a prior statement.
|
|
26
58
|
{ name: 'correction', re: /no,?\s+i\s+said/i },
|
|
27
59
|
{ name: 'correction', re: /that'?s\s+wrong/i },
|
|
28
60
|
{ name: 'correction', re: /actually/i },
|
|
61
|
+
{ name: 'correction', re: /i\s+meant/i },
|
|
62
|
+
{ name: 'correction', re: /no,?\s+it'?s/i },
|
|
29
63
|
];
|
|
64
|
+
/** Cap on concurrently open tool calls retained in the projection state. */
|
|
65
|
+
const OPEN_CALLS_CAP = 64;
|
|
66
|
+
/** Cap on concurrently tracked failure streaks (LRU-evicted). */
|
|
67
|
+
const OPEN_STREAKS_CAP = 8;
|
|
68
|
+
/** Maximum length of one normalized signature. */
|
|
69
|
+
const SIGNATURE_LIMIT = 120;
|
|
70
|
+
/** Maximum length of the stored per-streak error text. */
|
|
71
|
+
const STREAK_ERROR_TEXT_LIMIT = 500;
|
|
30
72
|
/** The empty-log state for the accumulator. */
|
|
31
|
-
export const emptyAccumulator = { candidates: [], count: 0 };
|
|
73
|
+
export const emptyAccumulator = { candidates: [], count: 0, openCalls: {}, openStreaks: {} };
|
|
32
74
|
/**
|
|
33
75
|
* Extract plain text from a message event's content blocks.
|
|
34
76
|
* @param event - a `user/message` or `assistant/message` session event.
|
|
@@ -70,44 +112,94 @@ export function detectSignal(text) {
|
|
|
70
112
|
return undefined;
|
|
71
113
|
}
|
|
72
114
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
115
|
+
* Argument keys that carry the "primary target" of a tool call, used to
|
|
116
|
+
* specialize a signature: `command`-style keys collapse to the first two
|
|
117
|
+
* tokens; path-style keys use the path value verbatim.
|
|
76
118
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
119
|
+
const COMMAND_KEYS = ['command', 'cmd'];
|
|
120
|
+
const PATH_KEYS = ['path', 'file', 'filePath', 'file_path', 'targetFile', 'target_file'];
|
|
121
|
+
/**
|
|
122
|
+
* Normalize a tool invocation into a failure-streak signature:
|
|
123
|
+
* `toolName:argument-key`. Shell-like `command` arguments collapse to the
|
|
124
|
+
* first two tokens (`npm test`, `pnpm build`); path-like arguments use the
|
|
125
|
+
* path; everything else falls back to the bare tool name. Unparsable
|
|
126
|
+
* argument JSON also falls back to the bare tool name.
|
|
127
|
+
* @param name - the invoked tool's name.
|
|
128
|
+
* @param argumentsJson - the raw arguments JSON string from the `tool/call` event.
|
|
129
|
+
* @returns the normalized signature (≤ {@link SIGNATURE_LIMIT} chars).
|
|
130
|
+
*/
|
|
131
|
+
export function toolSignature(name, argumentsJson) {
|
|
132
|
+
let signature = name;
|
|
133
|
+
try {
|
|
134
|
+
const args = JSON.parse(argumentsJson);
|
|
135
|
+
if (args !== null && typeof args === 'object') {
|
|
136
|
+
const record = args;
|
|
137
|
+
for (const key of COMMAND_KEYS) {
|
|
138
|
+
const value = record[key];
|
|
139
|
+
if (typeof value === 'string' && value.trim().length > 0) {
|
|
140
|
+
const tokens = value.trim().split(/\s+/).slice(0, 2).join(' ');
|
|
141
|
+
signature = `${name}:${tokens}`;
|
|
142
|
+
return signature.slice(0, SIGNATURE_LIMIT);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
for (const key of PATH_KEYS) {
|
|
146
|
+
const value = record[key];
|
|
147
|
+
if (typeof value === 'string' && value.trim().length > 0) {
|
|
148
|
+
signature = `${name}:${value.trim()}`;
|
|
149
|
+
return signature.slice(0, SIGNATURE_LIMIT);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// Unparsable arguments fall back to the bare tool name.
|
|
156
|
+
}
|
|
157
|
+
return signature.slice(0, SIGNATURE_LIMIT);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Extract a truncated failure description from a `tool/result` event that
|
|
161
|
+
* carries an error: the error identity plus the result's text blocks (nested
|
|
162
|
+
* inside each `tool-result` block's `content`).
|
|
163
|
+
* @param event - a `tool/result` session event with `data.error` present.
|
|
164
|
+
* @returns the failure description text (≤ {@link STREAK_ERROR_TEXT_LIMIT} chars).
|
|
165
|
+
*/
|
|
166
|
+
function failureDescription(event) {
|
|
80
167
|
const data = event.data;
|
|
81
|
-
if (data.error === undefined)
|
|
82
|
-
return undefined;
|
|
83
|
-
// Extract text from the result content if available, plus the error code.
|
|
84
168
|
const parts = [];
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
169
|
+
for (const block of data.message?.content ?? []) {
|
|
170
|
+
if (block.type !== 'tool-result')
|
|
171
|
+
continue;
|
|
172
|
+
for (const inner of block.content) {
|
|
173
|
+
if (inner.type === 'text' && typeof inner.text === 'string')
|
|
174
|
+
parts.push(inner.text);
|
|
90
175
|
}
|
|
91
176
|
}
|
|
92
177
|
const errorInfo = `tool error: ${data.error.name} (${data.error.code})`;
|
|
93
|
-
|
|
178
|
+
const text = parts.length > 0 ? `${errorInfo} — ${parts.join(' ')}` : errorInfo;
|
|
179
|
+
return text.slice(0, STREAK_ERROR_TEXT_LIMIT);
|
|
180
|
+
}
|
|
181
|
+
/** Evict the oldest entries of a plain-JSON record by a numeric seq accessor, in-place. */
|
|
182
|
+
function evictToCap(record, cap, seqOf) {
|
|
183
|
+
const keys = Object.keys(record);
|
|
184
|
+
if (keys.length <= cap)
|
|
185
|
+
return;
|
|
186
|
+
const sorted = [...keys].sort((a, b) => seqOf(record[a]) - seqOf(record[b]));
|
|
187
|
+
for (const key of sorted.slice(0, keys.length - cap)) {
|
|
188
|
+
delete record[key];
|
|
189
|
+
}
|
|
94
190
|
}
|
|
95
191
|
/**
|
|
96
192
|
* The projection's `apply` transition: fold one committed event into the
|
|
97
193
|
* accumulator. Returns the SAME state reference for events that do not
|
|
98
|
-
* contribute
|
|
99
|
-
*
|
|
100
|
-
* Signal sources:
|
|
101
|
-
* - `user/message` — keyword hits (explicit "remember" intent) and corrections
|
|
102
|
-
* (user revises a prior statement).
|
|
103
|
-
* - `tool/result` — tool-call failures (§3.6 richer signals): a failed tool
|
|
104
|
-
* execution may carry a durable workaround worth remembering.
|
|
194
|
+
* contribute any change (the registry's `Object.is` gate).
|
|
105
195
|
*
|
|
106
196
|
* @param state - the state covering all prior events.
|
|
107
197
|
* @param event - the next committed session event.
|
|
108
|
-
* @
|
|
198
|
+
* @param pitfallThreshold - consecutive same-signature failures required
|
|
199
|
+
* before a following success emits a `pitfall-resolved` candidate.
|
|
200
|
+
* @returns the next state (same reference when the event changes nothing).
|
|
109
201
|
*/
|
|
110
|
-
export function applyAccumulator(state, event) {
|
|
202
|
+
export function applyAccumulator(state, event, pitfallThreshold = 2) {
|
|
111
203
|
if (event.type === 'user/message') {
|
|
112
204
|
const text = messageText(event);
|
|
113
205
|
if (text === undefined)
|
|
@@ -116,14 +208,51 @@ export function applyAccumulator(state, event) {
|
|
|
116
208
|
if (signal === undefined)
|
|
117
209
|
return state;
|
|
118
210
|
const candidate = { text, signal, seq: event.seq };
|
|
119
|
-
return { candidates: [...state.candidates, candidate], count: state.count + 1 };
|
|
211
|
+
return { ...state, candidates: [...state.candidates, candidate], count: state.count + 1 };
|
|
212
|
+
}
|
|
213
|
+
if (event.type === 'tool/call') {
|
|
214
|
+
const callId = String(event.data.callId);
|
|
215
|
+
const openCalls = { ...state.openCalls, [callId]: { name: event.data.name, signature: toolSignature(event.data.name, event.data.arguments), seq: event.seq } };
|
|
216
|
+
evictToCap(openCalls, OPEN_CALLS_CAP, call => call.seq);
|
|
217
|
+
return { ...state, openCalls };
|
|
120
218
|
}
|
|
121
219
|
if (event.type === 'tool/result') {
|
|
122
|
-
const
|
|
123
|
-
|
|
220
|
+
const block = event.data.message?.content?.[0];
|
|
221
|
+
const callId = block !== undefined && block.type === 'tool-result' ? String(block.toolCallId) : undefined;
|
|
222
|
+
const call = callId !== undefined ? state.openCalls[callId] : undefined;
|
|
223
|
+
if (call === undefined)
|
|
124
224
|
return state;
|
|
125
|
-
const
|
|
126
|
-
|
|
225
|
+
const openCalls = { ...state.openCalls };
|
|
226
|
+
delete openCalls[callId];
|
|
227
|
+
if (event.data.error !== undefined) {
|
|
228
|
+
// Failure: start or extend the streak for this signature.
|
|
229
|
+
const existing = state.openStreaks[call.signature];
|
|
230
|
+
const streak = {
|
|
231
|
+
count: (existing?.count ?? 0) + 1,
|
|
232
|
+
lastErrorText: failureDescription(event),
|
|
233
|
+
firstSeq: existing?.firstSeq ?? event.seq,
|
|
234
|
+
lastSeq: event.seq,
|
|
235
|
+
};
|
|
236
|
+
const openStreaks = { ...state.openStreaks, [call.signature]: streak };
|
|
237
|
+
evictToCap(openStreaks, OPEN_STREAKS_CAP, s => s.lastSeq);
|
|
238
|
+
return { ...state, openCalls, openStreaks };
|
|
239
|
+
}
|
|
240
|
+
// Success: resolve the streak if it reached the threshold; either way the
|
|
241
|
+
// call is closed (result received) and the streak ends.
|
|
242
|
+
const streak = state.openStreaks[call.signature];
|
|
243
|
+
if (streak === undefined)
|
|
244
|
+
return { ...state, openCalls };
|
|
245
|
+
const openStreaks = { ...state.openStreaks };
|
|
246
|
+
delete openStreaks[call.signature];
|
|
247
|
+
if (streak.count < pitfallThreshold) {
|
|
248
|
+
return { ...state, openCalls, openStreaks };
|
|
249
|
+
}
|
|
250
|
+
const candidate = {
|
|
251
|
+
text: `tool "${call.name}" (signature: ${call.signature}) failed ${streak.count} time(s) before succeeding. Last error: ${streak.lastErrorText}. Streak spans seqs ${streak.firstSeq}–${streak.lastSeq}, resolved by the call at seq ${call.seq}.`,
|
|
252
|
+
signal: PITFALL_RESOLVED_SIGNAL,
|
|
253
|
+
seq: event.seq,
|
|
254
|
+
};
|
|
255
|
+
return { ...state, openCalls, openStreaks, candidates: [...state.candidates, candidate], count: state.count + 1 };
|
|
127
256
|
}
|
|
128
257
|
return state;
|
|
129
258
|
}
|
|
@@ -135,5 +264,16 @@ export const accumulatorSchema = zod.object({
|
|
|
135
264
|
seq: zod.number(),
|
|
136
265
|
})),
|
|
137
266
|
count: zod.number(),
|
|
267
|
+
openCalls: zod.record(zod.string(), zod.object({
|
|
268
|
+
name: zod.string(),
|
|
269
|
+
signature: zod.string(),
|
|
270
|
+
seq: zod.number(),
|
|
271
|
+
})),
|
|
272
|
+
openStreaks: zod.record(zod.string(), zod.object({
|
|
273
|
+
count: zod.number(),
|
|
274
|
+
lastErrorText: zod.string(),
|
|
275
|
+
firstSeq: zod.number(),
|
|
276
|
+
lastSeq: zod.number(),
|
|
277
|
+
})),
|
|
138
278
|
});
|
|
139
279
|
//# sourceMappingURL=accumulator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accumulator.js","sourceRoot":"","sources":["../../src/review/accumulator.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"accumulator.js","sourceRoot":"","sources":["../../src/review/accumulator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,CAAC,IAAI,GAAG,EAAE,MAAM,KAAK,CAAA;AAI9B,6EAA6E;AAC7E,MAAM,CAAC,MAAM,4BAA4B,GAAG,0BAA0B,CAAA;AAStE,yEAAyE;AACzE,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAAkB,CAAA;AAiDzD;;;;;GAKG;AACH,MAAM,gBAAgB,GAA8D;IAClF,qCAAqC;IACrC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE;IAC7B,EAAE,IAAI,EAAE,SAAS,EAAE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AAE,GAAG,CAAC,MAAM,CAAC;QAC7C,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE;QAClB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE;QACvB,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE;KAClB,CAAC,CAAC;IACH,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC;QAC/C,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE;QACnB,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE;QAC3B,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE;QACtB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE;KACtB,CAAC,CAAC;CACJ,CAAC,CAAA"}
|
package/lib/review/dedup.d.ts
CHANGED
|
@@ -44,13 +44,26 @@ export interface DedupCandidate {
|
|
|
44
44
|
* @returns the existing entry id to merge into, or `undefined` for a new entry.
|
|
45
45
|
*/
|
|
46
46
|
export declare function findDuplicate(candidateContent: string, candidateScope: string, existing: readonly DedupCandidate[], threshold?: number): string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Upper bound on merged content produced by {@link mergeContent}. Past this
|
|
49
|
+
* cap the merge falls back to keeping the longer side instead of appending,
|
|
50
|
+
* so repeated near-duplicate merges can never grow an entry without bound.
|
|
51
|
+
* True re-summarization of oversized entries belongs to the curator pass.
|
|
52
|
+
*/
|
|
53
|
+
export declare const MERGE_CHAR_LIMIT = 600;
|
|
47
54
|
/**
|
|
48
55
|
* Merge two memory contents into one. When the new content is a strict
|
|
49
|
-
* superset (contains the old text as a substring), the
|
|
56
|
+
* superset (contains the old text as a substring), the longer content wins
|
|
50
57
|
* outright. Otherwise, append the new content as an addendum so no
|
|
51
|
-
* information is lost
|
|
58
|
+
* information is lost — unless the concatenation would exceed `maxChars`,
|
|
59
|
+
* in which case the longer side wins instead, bounding entry growth while
|
|
60
|
+
* staying deterministic and LLM-free.
|
|
61
|
+
*
|
|
62
|
+
* @param oldContent - the stored content.
|
|
63
|
+
* @param newContent - the incoming candidate content.
|
|
64
|
+
* @param maxChars - upper bound for the concatenated form (default {@link MERGE_CHAR_LIMIT}).
|
|
52
65
|
*/
|
|
53
|
-
export declare function mergeContent(oldContent: string, newContent: string): string;
|
|
66
|
+
export declare function mergeContent(oldContent: string, newContent: string, maxChars?: number): string;
|
|
54
67
|
/**
|
|
55
68
|
* Project a MemoryEntry to the minimal shape findDuplicate needs.
|
|
56
69
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dedup.d.ts","sourceRoot":"","sources":["../../src/review/dedup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAyC9C;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAerD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CAQxE;AAED,4EAA4E;AAC5E,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC3B,gBAAgB,EAAE,MAAM,EACxB,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,SAAS,cAAc,EAAE,EACnC,SAAS,GAAE,MAAa,GACvB,MAAM,GAAG,SAAS,CAepB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"dedup.d.ts","sourceR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F;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAK5D"}
|
package/lib/review/dedup.js
CHANGED
|
@@ -118,17 +118,34 @@ export function findDuplicate(candidateContent, candidateScope, existing, thresh
|
|
|
118
118
|
}
|
|
119
119
|
return bestId;
|
|
120
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Upper bound on merged content produced by {@link mergeContent}. Past this
|
|
123
|
+
* cap the merge falls back to keeping the longer side instead of appending,
|
|
124
|
+
* so repeated near-duplicate merges can never grow an entry without bound.
|
|
125
|
+
* True re-summarization of oversized entries belongs to the curator pass.
|
|
126
|
+
*/
|
|
127
|
+
export const MERGE_CHAR_LIMIT = 600;
|
|
121
128
|
/**
|
|
122
129
|
* Merge two memory contents into one. When the new content is a strict
|
|
123
|
-
* superset (contains the old text as a substring), the
|
|
130
|
+
* superset (contains the old text as a substring), the longer content wins
|
|
124
131
|
* outright. Otherwise, append the new content as an addendum so no
|
|
125
|
-
* information is lost
|
|
132
|
+
* information is lost — unless the concatenation would exceed `maxChars`,
|
|
133
|
+
* in which case the longer side wins instead, bounding entry growth while
|
|
134
|
+
* staying deterministic and LLM-free.
|
|
135
|
+
*
|
|
136
|
+
* @param oldContent - the stored content.
|
|
137
|
+
* @param newContent - the incoming candidate content.
|
|
138
|
+
* @param maxChars - upper bound for the concatenated form (default {@link MERGE_CHAR_LIMIT}).
|
|
126
139
|
*/
|
|
127
|
-
export function mergeContent(oldContent, newContent) {
|
|
140
|
+
export function mergeContent(oldContent, newContent, maxChars = MERGE_CHAR_LIMIT) {
|
|
128
141
|
if (oldContent.includes(newContent) || newContent.includes(oldContent)) {
|
|
129
142
|
return newContent.length >= oldContent.length ? newContent : oldContent;
|
|
130
143
|
}
|
|
131
|
-
|
|
144
|
+
const merged = `${oldContent} ${newContent}`;
|
|
145
|
+
if (merged.length <= maxChars)
|
|
146
|
+
return merged;
|
|
147
|
+
// Over the cap: prefer the more informative side rather than growing forever.
|
|
148
|
+
return newContent.length >= oldContent.length ? newContent : oldContent;
|
|
132
149
|
}
|
|
133
150
|
/**
|
|
134
151
|
* Project a MemoryEntry to the minimal shape findDuplicate needs.
|
package/lib/review/dedup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dedup.js","sourceRoot":"","sources":["../../src/review/dedup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH;;;;;;GAMG;AACH,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO;IACnE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI;IACrE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IACrE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM;CACjE,CAAC,CAAA;AAEF;;;;;;;GAOG;AACH,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC7B,aAAa;IACb,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAClB,KAAK;IACL,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAC5B,QAAQ;IACR,GAAG,EAAE,GAAG,EAAE,GAAG;IACb,QAAQ;IACR,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,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AAI,MAAM,CAAC,MAAM,IAAI,QAAQ;QAAE,OAAO,MAAM,CAAA;IAC5C,8EAA8E;IAC9E,OAAO,UAAU,CAAC,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAA;AACzE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAkB;IACjD,OAAO,EAAE,EAAE,EAAE,KAAK,CAAC,EAAY,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAA;AAC/E,CAAC;AAOD,6EAA6E;AAC7E,MAAM,CAAC,MAAM,mBAAmB,GAC9B,2FAA2F;MACzF,uJAAuJ;MACvJ,wIAAwI;MACxI,0JAA0J;MAC1J,8EAA8E,CAAA;AAElF;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,eAAuB,EAAE,UAAkB;IAC1E,OAAO,qBAAqB,eAAe,uBAAuB,UAAU,EAAE,CAAA;AAChF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IACtC,IAAI,IAAI,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAA;IACtC,IAAI,IAAI,KAAK,KAAK;QAAE,OAAO,KAAK,CAAA;IAChC,OAAO,WAAW,CAAA;AACpB,CAAC"}
|
package/lib/review/extract.d.ts
CHANGED
|
@@ -16,13 +16,33 @@ import type { Context } from '@deepseek-ai/cordis';
|
|
|
16
16
|
import type { GenerateOptions, Message } from '@deepseek-ai/dsh-llm';
|
|
17
17
|
import type { Session } from '@deepseek-ai/dsh-session';
|
|
18
18
|
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
19
|
-
import type { AuditSource, MemoryCategory, MemoryScope } from '../types.ts';
|
|
19
|
+
import type { AuditSource, MemoryCategory, MemoryEntry, MemoryScope } from '../types.ts';
|
|
20
20
|
import type { MemoryStore } from '../index.ts';
|
|
21
|
-
import type
|
|
21
|
+
import { type MemoryCandidate } from './accumulator.ts';
|
|
22
22
|
/** System prompt for the periodic-review extraction. */
|
|
23
23
|
export declare const REVIEW_SYSTEM_PROMPT: string;
|
|
24
|
+
/** System prompt for the pitfall-streak extraction (failure → resolved sequences). */
|
|
25
|
+
export declare const PITFALL_SYSTEM_PROMPT: string;
|
|
24
26
|
/** System prompt for the compaction/dispose flush (方案 C). */
|
|
25
27
|
export declare const FLUSH_SYSTEM_PROMPT: string;
|
|
28
|
+
/**
|
|
29
|
+
* Strip a leading content tag (e.g. `"[procedure] "`) from extracted content.
|
|
30
|
+
* @param content - the raw extracted content.
|
|
31
|
+
* @returns the tag-stripped content and the implied category (`undefined` when untagged).
|
|
32
|
+
*/
|
|
33
|
+
export declare function stripContentTag(content: string): {
|
|
34
|
+
content: string;
|
|
35
|
+
category: MemoryCategory | undefined;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Flatten a text onto a single line. Embedded newlines in conversation
|
|
39
|
+
* fragments or stored entries could forge the line-oriented extraction
|
|
40
|
+
* protocol (fake "scope: content" rows) or corrupt the numbering structure,
|
|
41
|
+
* so every fragment and snapshot line is flattened before it reaches the LLM.
|
|
42
|
+
* @param text - the raw text.
|
|
43
|
+
* @returns the single-line form (newline runs replaced by one space).
|
|
44
|
+
*/
|
|
45
|
+
export declare function flattenFragment(text: string): string;
|
|
26
46
|
/** One parsed memory entry awaiting scanner + store validation. */
|
|
27
47
|
export interface ParsedMemory {
|
|
28
48
|
/** Which scope the extracted memory belongs to. */
|
|
@@ -54,6 +74,13 @@ export declare function renderMemorySnapshot(memory: MemoryStore | undefined): s
|
|
|
54
74
|
* @returns the model-facing user message list.
|
|
55
75
|
*/
|
|
56
76
|
export declare function buildReviewMessages(memorySnapshot: string, candidates: readonly MemoryCandidate[]): Message[];
|
|
77
|
+
/**
|
|
78
|
+
* Build the messages for the pitfall-streak extraction prompt.
|
|
79
|
+
* @param memorySnapshot - rendered current memory text (possibly empty).
|
|
80
|
+
* @param candidates - the `pitfall-resolved` candidate fragments.
|
|
81
|
+
* @returns the model-facing user message list.
|
|
82
|
+
*/
|
|
83
|
+
export declare function buildPitfallMessages(memorySnapshot: string, candidates: readonly MemoryCandidate[]): Message[];
|
|
57
84
|
/**
|
|
58
85
|
* Build the messages for the compaction/dispose flush prompt.
|
|
59
86
|
* @param fragments - the raw conversation fragments being shadowed.
|
|
@@ -75,14 +102,21 @@ export interface ExtractionModelOverride {
|
|
|
75
102
|
export declare function collectStreamText(ctx: Context, options: GenerateOptions): Promise<string>;
|
|
76
103
|
/**
|
|
77
104
|
* Run one extraction call and parse its output. Resolves the provider/model
|
|
78
|
-
* from the session's request header
|
|
79
|
-
*
|
|
105
|
+
* from the session's request header.
|
|
106
|
+
*
|
|
107
|
+
* Failure semantics: this function THROWS when no route is available or the
|
|
108
|
+
* stream fails (error/aborted/max-tokens). Callers pick the policy — the
|
|
109
|
+
* periodic-review drain must NOT consume its candidate batch on failure
|
|
110
|
+
* (the high-water mark only advances after success, so candidates are
|
|
111
|
+
* retried; dedup makes re-storing idempotent), while the fire-and-forget
|
|
112
|
+
* flush paths simply swallow the rejection at their event-listener boundary.
|
|
80
113
|
* @param ctx - context carrying the LLM seam.
|
|
81
114
|
* @param session - the session whose request header routes the call.
|
|
82
115
|
* @param system - the system prompt.
|
|
83
116
|
* @param messages - the model-facing user messages.
|
|
84
117
|
* @param signal - optional abort signal.
|
|
85
|
-
* @returns the parsed memory entries
|
|
118
|
+
* @returns the parsed memory entries on success.
|
|
119
|
+
* @throws when no provider/model route resolves or the stream fails.
|
|
86
120
|
*/
|
|
87
121
|
export declare function extractMemories(ctx: Context, session: Session, system: string, messages: Message[], signal?: AbortSignal, modelOverride?: ExtractionModelOverride): Promise<ParsedMemory[]>;
|
|
88
122
|
/**
|
|
@@ -115,8 +149,50 @@ export declare function storeMemories(ctx: Context, parsed: readonly ParsedMemor
|
|
|
115
149
|
* @param ctx - context carrying the LLM and optional memory seams.
|
|
116
150
|
* @param agent - the live agent whose session routes the call.
|
|
117
151
|
* @param candidates - the accumulated candidate fragments.
|
|
152
|
+
* @throws when an extraction call fails (no route / stream error). The drain
|
|
153
|
+
* caller treats a throw as "batch not consumed": the high-water mark stays,
|
|
154
|
+
* candidates are retried on the next threshold crossing, and dedup makes
|
|
155
|
+
* re-storing idempotent.
|
|
118
156
|
*/
|
|
119
157
|
export declare function runReviewExtraction(ctx: Context, agent: Agent, candidates: readonly MemoryCandidate[], modelOverride?: ExtractionModelOverride, judgeEnabled?: boolean): Promise<number>;
|
|
158
|
+
/** System prompt for the low-frequency curator pass (re-summarize oversized entries). */
|
|
159
|
+
export declare const CURATOR_SYSTEM_PROMPT: string;
|
|
160
|
+
/**
|
|
161
|
+
* Build the user message for the curator pass: the selected oversized entries,
|
|
162
|
+
* id-addressed so the rewrite can be applied back to the right rows.
|
|
163
|
+
* @param entries - the selected entries (id + scope + content).
|
|
164
|
+
* @returns the model-facing user message list.
|
|
165
|
+
*/
|
|
166
|
+
export declare function buildCuratorMessages(entries: readonly MemoryEntry[]): Message[];
|
|
167
|
+
/** One parsed curator output line: which entry to rewrite and its new content. */
|
|
168
|
+
export interface CuratedLine {
|
|
169
|
+
readonly id: string;
|
|
170
|
+
readonly content: string;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Parse the curator's output strictly: each non-empty line must read
|
|
174
|
+
* `<id>: <content>`, and only ids that were actually offered may appear.
|
|
175
|
+
* Unknown ids, blank content, and malformed lines are dropped — a chatty or
|
|
176
|
+
* hostile response cannot rewrite arbitrary rows.
|
|
177
|
+
* @param text - the raw model output.
|
|
178
|
+
* @param allowedIds - the ids offered in the prompt.
|
|
179
|
+
* @returns the accepted rewrite lines, in output order.
|
|
180
|
+
*/
|
|
181
|
+
export declare function parseCuratedLines(text: string, allowedIds: readonly string[]): CuratedLine[];
|
|
182
|
+
/**
|
|
183
|
+
* Run one curation pass over the given entries: rewrite via the LLM, then
|
|
184
|
+
* update each surviving row through the store contract (scanner included).
|
|
185
|
+
*
|
|
186
|
+
* Failure semantics mirrors {@link extractMemories}: throws when no route is
|
|
187
|
+
* available or the stream fails; per-row store failures are skipped so one
|
|
188
|
+
* bad rewrite never aborts the batch.
|
|
189
|
+
* @param ctx - context carrying the LLM seam and optional memory service.
|
|
190
|
+
* @param session - the session whose request header routes the call.
|
|
191
|
+
* @param selected - the oversized entries to curate.
|
|
192
|
+
* @param modelOverride - optional provider/model override.
|
|
193
|
+
* @returns the number of entries actually rewritten.
|
|
194
|
+
*/
|
|
195
|
+
export declare function runCuration(ctx: Context, session: Session, selected: readonly MemoryEntry[], modelOverride?: ExtractionModelOverride): Promise<number>;
|
|
120
196
|
/**
|
|
121
197
|
* Run the compaction/dispose flush extraction: build the flush prompt from the
|
|
122
198
|
* shadowed conversation fragments, extract, and store. Best-effort and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/review/extract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAEpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAEnD,OAAO,KAAK,EAAkB,WAAW,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/review/extract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,sBAAsB,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