dsh-memory-bond 0.3.0-beta.0 → 1.0.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/CHANGELOG.md +6 -7
- package/README.md +125 -91
- package/README.zh-CN.md +122 -92
- package/SECURITY.md +29 -0
- package/dist/audit.js +155 -80
- package/dist/automatic.js +10 -2
- package/dist/client.js +2035 -0
- package/dist/command-scope.js +4 -4
- package/dist/commands.js +15 -9
- package/dist/consolidation-store.js +87 -20
- package/dist/consolidation.js +2 -6
- package/dist/domain.js +8 -4
- package/dist/encoder.js +46 -5
- package/dist/file-import-store.js +120 -0
- package/dist/file-import.js +265 -0
- package/dist/foreground-attempts.js +91 -0
- package/dist/guidance.js +133 -92
- package/dist/host.js +13 -0
- package/dist/index-policy.js +91 -48
- package/dist/index.js +102 -40
- package/dist/knowledge-hooks.js +70 -27
- package/dist/knowledge.js +2 -3
- package/dist/maintenance-store.js +38 -4
- package/dist/maintenance.js +29 -5
- package/dist/personal.js +37 -0
- package/dist/policy.js +45 -47
- package/dist/prompt-copy.js +93 -0
- package/dist/proposal-receipts.js +70 -0
- package/dist/proposal-review.js +656 -0
- package/dist/propose-contract.js +32 -36
- package/dist/question-answers.js +86 -29
- package/dist/retrieval.js +25 -8
- package/dist/scope-narrowing.js +49 -0
- package/dist/search-index.js +93 -13
- package/dist/semantic.js +69 -207
- package/dist/service.js +633 -204
- package/dist/sharing.js +7 -13
- package/dist/sources.js +28 -3
- package/dist/store.js +432 -96
- package/dist/tool-experience.js +87 -0
- package/dist/turn-review-store.js +83 -16
- package/dist/turn-review.js +155 -59
- package/dist/ui.js +128 -26
- package/dist/vector-index.js +69 -33
- package/docs/architecture.zh-CN.md +52 -0
- package/docs/benchmark.zh-CN.md +60 -0
- package/docs/benchmarks/repository-tasks.json +5355 -0
- package/docs/images/bond-memory-principle-en.svg +644 -0
- package/docs/images/bond-memory-principle-zh.svg +644 -0
- package/docs/images/bond-memory-principle.drawio +644 -0
- package/docs/images/memory-settings-en.png +0 -0
- package/docs/images/memory-settings-zh.png +0 -0
- package/docs/images/memory-turn-recalled-en.png +0 -0
- package/docs/images/memory-turn-recalled-zh.png +0 -0
- package/docs/images/memory-turn-saved-en.png +0 -0
- package/docs/images/memory-turn-saved-zh.png +0 -0
- package/docs/media/memory-bond-name-en.gif +0 -0
- package/docs/media/memory-bond-name-en.mp4 +0 -0
- package/docs/media/memory-bond-name-zh.gif +0 -0
- package/docs/media/memory-bond-name-zh.mp4 +0 -0
- package/locale/detail.en.md +5 -1
- package/locale/detail.zh.md +5 -1
- package/locale/en.json +338 -0
- package/locale/zh.json +338 -0
- package/native/embeddings/NOTICE.md +2 -2
- package/package.json +39 -19
- package/scripts/benchmark-bond.mjs +72 -0
- package/scripts/benchmark-conditions.mjs +144 -0
- package/scripts/benchmark-example.mjs +37 -0
- package/scripts/benchmark-scale.mjs +119 -0
- package/scripts/benchmark-scenarios.mjs +57 -0
- package/scripts/benchmark-tasks.mjs +244 -0
- package/src/audit.ts +144 -85
- package/src/automatic.ts +12 -2
- package/src/command-scope.ts +4 -4
- package/src/commands.ts +12 -8
- package/src/consolidation-store.ts +80 -18
- package/src/consolidation.ts +2 -6
- package/src/domain.ts +9 -4
- package/src/encoder.ts +46 -6
- package/src/file-import-store.ts +139 -0
- package/src/file-import.ts +256 -0
- package/src/foreground-attempts.ts +97 -0
- package/src/guidance.ts +138 -102
- package/src/host.ts +22 -2
- package/src/index-policy.ts +93 -46
- package/src/index.ts +87 -43
- package/src/knowledge-hooks.ts +71 -29
- package/src/knowledge.ts +2 -3
- package/src/maintenance-store.ts +37 -4
- package/src/maintenance.ts +25 -5
- package/src/personal.ts +36 -0
- package/src/policy.ts +55 -52
- package/src/prompt-copy.ts +99 -0
- package/src/proposal-receipts.ts +59 -0
- package/src/proposal-review.ts +614 -0
- package/src/propose-contract.ts +31 -35
- package/src/question-answers.ts +99 -29
- package/src/retrieval.ts +26 -9
- package/src/scope-narrowing.ts +58 -0
- package/src/search-index.ts +94 -14
- package/src/semantic.ts +67 -188
- package/src/service.ts +595 -210
- package/src/sharing.ts +7 -14
- package/src/sources.ts +26 -4
- package/src/store.ts +434 -97
- package/src/tool-experience.ts +93 -0
- package/src/turn-review-store.ts +86 -15
- package/src/turn-review.ts +142 -60
- package/src/ui.ts +122 -27
- package/src/vector-index.ts +57 -29
- package/client/index.js +0 -1186
- package/design/dsh-memory-plugin-design.md +0 -46
- package/design/dsh-memory-plugin-evaluation.md +0 -135
- package/design/evaluations/locomo-conv-26-2026-12-03.json +0 -252
- package/design/evaluations/locomo-conv-26-paired-2026-12-03.json +0 -549
- package/design/evaluations/locomo-conv-26-write-replay-2026-12-03.json +0 -289
- package/design/evaluations/project-memory-tasks-2026-12-03.json +0 -1059
- package/design/memory-lifecycle-consolidation.excalidraw +0 -1212
- package/design/memory-lifecycle-consolidation.mobile.excalidraw +0 -1083
- package/design/memory-lifecycle-consolidation.mobile.svg +0 -2
- package/design/memory-lifecycle-consolidation.mobile.zh-CN.excalidraw +0 -1083
- package/design/memory-lifecycle-consolidation.mobile.zh-CN.svg +0 -94
- package/design/memory-lifecycle-consolidation.svg +0 -2
- package/design/memory-lifecycle-consolidation.zh-CN.excalidraw +0 -1212
- package/design/memory-lifecycle-consolidation.zh-CN.svg +0 -94
- package/design/memory-lifecycle.excalidraw +0 -2105
- package/design/memory-lifecycle.mobile.excalidraw +0 -1896
- package/design/memory-lifecycle.mobile.svg +0 -95
- package/design/memory-lifecycle.mobile.zh-CN.excalidraw +0 -1896
- package/design/memory-lifecycle.mobile.zh-CN.svg +0 -97
- package/design/memory-lifecycle.svg +0 -95
- package/design/memory-lifecycle.zh-CN.excalidraw +0 -2105
- package/design/memory-lifecycle.zh-CN.svg +0 -97
- package/native/embeddings/LICENSE +0 -21
- package/native/embeddings/en/model.onnx +0 -4
- package/native/embeddings/en/vocab.txt +0 -30522
- package/native/embeddings/runtime/LICENSE +0 -21
- package/native/embeddings/runtime/ThirdPartyNotices.txt +0 -6156
- package/native/embeddings/runtime/ort-wasm-simd-threaded.mjs +0 -70
- package/native/embeddings/runtime/ort-wasm-simd-threaded.wasm +0 -0
- package/native/embeddings/runtime/ort.wasm.min.mjs +0 -7
- package/native/embeddings/worker.mjs +0 -97
- package/native/embeddings/zh/model.onnx +0 -0
- package/native/embeddings/zh/vocab.txt +0 -21128
package/dist/audit.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { resolve, sep } from 'node:path';
|
|
3
3
|
import { bashScope, literalActionCommand } from "./command-scope.js";
|
|
4
|
+
import { indexHintRefs } from "./index-policy.js";
|
|
4
5
|
import { indexName, latestTurn } from "./service.js";
|
|
5
6
|
import { messageText, } from "./host.js";
|
|
6
7
|
export function searchContext(agent, domain, generation) {
|
|
@@ -9,6 +10,14 @@ export function searchContext(agent, domain, generation) {
|
|
|
9
10
|
}
|
|
10
11
|
// Pinning can change the public result without creating a new revision.
|
|
11
12
|
export const searchRowDigest = (row) => createHash('sha256').update(JSON.stringify(row)).digest('hex');
|
|
13
|
+
const bodyDigest = (row) => searchRowDigest([row.id, row.rev, row.action]);
|
|
14
|
+
function writeReceiptBodies(results) {
|
|
15
|
+
if (!Array.isArray(results))
|
|
16
|
+
return [];
|
|
17
|
+
return results.flatMap(row => (row?.status === 'saved' || row?.status === 'duplicate') && typeof row.id === 'string' &&
|
|
18
|
+
Number.isSafeInteger(row.rev) && typeof row.stored?.action === 'string' && row.stored.action
|
|
19
|
+
? [{ id: row.id, rev: row.rev, bodyDigest: searchRowDigest([row.id, row.rev, row.stored]) }] : []);
|
|
20
|
+
}
|
|
12
21
|
const refsIn = (text) => Array.from(text.matchAll(/\b(mem-[\da-f-]+)@(\d+)\b/gi), (m) => ({ id: m[1], rev: Number(m[2]) }));
|
|
13
22
|
export function registerAudit(memory, isAgentLoopRequest) {
|
|
14
23
|
const ctx = memory.ctx;
|
|
@@ -16,12 +25,12 @@ export function registerAudit(memory, isAgentLoopRequest) {
|
|
|
16
25
|
const lookups = new WeakMap();
|
|
17
26
|
const visibleSearches = new WeakMap();
|
|
18
27
|
const commands = new WeakMap();
|
|
19
|
-
const
|
|
28
|
+
const requestMeta = (agent, step) => ({
|
|
20
29
|
agent: agent.id,
|
|
21
30
|
store: memory.storeId(agent.session),
|
|
22
|
-
turn:
|
|
23
|
-
step:
|
|
24
|
-
|
|
31
|
+
turn: step?.turn,
|
|
32
|
+
step: step?.step,
|
|
33
|
+
retry: step && step.attempts - 1,
|
|
25
34
|
});
|
|
26
35
|
function lookupTable(session) {
|
|
27
36
|
let table = lookups.get(session);
|
|
@@ -36,37 +45,54 @@ export function registerAudit(memory, isAgentLoopRequest) {
|
|
|
36
45
|
}
|
|
37
46
|
return table;
|
|
38
47
|
}
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
memory.append(agent.session, 'plugin:project-memory/lookup', { callId: call, domainId: d.id, refs });
|
|
48
|
+
const rememberLookup = (agent, call, read) => {
|
|
49
|
+
lookupTable(agent.session).set(call, read);
|
|
50
|
+
if (read.refs.length)
|
|
51
|
+
memory.append(agent.session, 'plugin:project-memory/lookup', { callId: call, domainId: read.domain, refs: read.refs });
|
|
44
52
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// Unlike 'session/event'/'tools/result', a listener error here is NOT contained by the host
|
|
52
|
-
// and would abort the whole model stream - a store failure must degrade, not propagate.
|
|
53
|
+
const lookUp = (agent, d, call, rows, searchContext) => {
|
|
54
|
+
const refs = rows.map(row => ({ id: row.id, rev: row.rev, bodyDigest: bodyDigest(row) }));
|
|
55
|
+
rememberLookup(agent, call, { domain: d.id, refs, searchContext });
|
|
56
|
+
};
|
|
57
|
+
function auditRequest(req) {
|
|
58
|
+
// A failure in the host classifier or memory store must not interrupt the model stream.
|
|
53
59
|
try {
|
|
54
|
-
|
|
60
|
+
if (!isAgentLoopRequest(req))
|
|
61
|
+
return;
|
|
62
|
+
const generation = memory.assistantGeneration();
|
|
63
|
+
if (generation === undefined)
|
|
64
|
+
return;
|
|
65
|
+
const agent = req.sessionId ? ctx.agents.get(req.sessionId) : undefined;
|
|
55
66
|
if (agent)
|
|
56
67
|
visibleSearches.delete(agent);
|
|
57
68
|
const d = memory.domain(agent);
|
|
58
69
|
if (!agent || !d)
|
|
59
|
-
return
|
|
70
|
+
return;
|
|
71
|
+
const step = steps.get(agent.session);
|
|
72
|
+
if (step) {
|
|
73
|
+
step.exposed = [];
|
|
74
|
+
step.generation = generation;
|
|
75
|
+
step.attempts++;
|
|
76
|
+
}
|
|
60
77
|
const messages = req.messages;
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
78
|
+
const snapshots = messages.filter(m => m.source?.kind === 'runtime-context');
|
|
79
|
+
const latest = snapshots.at(-1);
|
|
80
|
+
const refs = [];
|
|
81
|
+
for (const snapshot of snapshots) {
|
|
82
|
+
const value = snapshot.source?.sections?.find(s => s.name === indexName)?.text;
|
|
83
|
+
// DSH can retain earlier reminders in the physical request. A superseded body
|
|
84
|
+
// counts as visible, while only a current body can credit a later command.
|
|
85
|
+
if (!value || !messageText(snapshot).includes(value))
|
|
86
|
+
continue;
|
|
87
|
+
for (const line of value.split('\n')) {
|
|
66
88
|
const trailing = line.match(/\[(mem-[\da-f-]+)@(\d+)\]$/i);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
89
|
+
if (trailing)
|
|
90
|
+
refs.push({ id: trailing[1], rev: Number(trailing[2]), actionable: snapshot === latest });
|
|
91
|
+
else
|
|
92
|
+
for (const ref of indexHintRefs(line))
|
|
93
|
+
refs.push({ ...ref, hintOnly: true });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
70
96
|
let context;
|
|
71
97
|
let shown;
|
|
72
98
|
for (const message of messages) {
|
|
@@ -75,56 +101,86 @@ export function registerAudit(memory, isAgentLoopRequest) {
|
|
|
75
101
|
const read = lookupTable(agent.session).get(message.toolCallId);
|
|
76
102
|
if (read?.domain !== d.id)
|
|
77
103
|
continue;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
104
|
+
if (message.isError) {
|
|
105
|
+
const denial = read.refs.find(ref => ref.denial);
|
|
106
|
+
if (denial && denial.bodyDigest === searchRowDigest(messageText(message)))
|
|
107
|
+
refs.push({ id: denial.id, rev: denial.rev });
|
|
108
|
+
continue;
|
|
83
109
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
110
|
+
let result;
|
|
111
|
+
try {
|
|
112
|
+
result = JSON.parse(messageText(message));
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const trusted = new Map(read.refs.map(ref => [ref.id, ref.bodyDigest]));
|
|
118
|
+
if (Array.isArray(result?.results)) {
|
|
119
|
+
for (const row of writeReceiptBodies(result.results))
|
|
120
|
+
if (trusted.get(row.id) === row.bodyDigest)
|
|
121
|
+
refs.push({ id: row.id, rev: row.rev, actionable: true });
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const rows = Array.isArray(result?.rules) ? result.rules : Array.isArray(result?.items) ? result.items : [result];
|
|
125
|
+
const currentSearch = read.searchContext && Array.isArray(result?.rules) &&
|
|
126
|
+
read.searchContext === (context ??= searchContext(agent, d, generation));
|
|
127
|
+
if (currentSearch)
|
|
96
128
|
shown ??= new Map();
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
129
|
+
for (const row of rows) {
|
|
130
|
+
// Compaction, a bare pointer and an alreadyShown row can all retain an ID without the body.
|
|
131
|
+
if (typeof row?.action !== 'string' || !row.action || trusted.get(row.id) !== bodyDigest(row))
|
|
132
|
+
continue;
|
|
133
|
+
refs.push({ id: row.id, rev: row.rev, viaLookup: true, actionable: true });
|
|
134
|
+
if (currentSearch)
|
|
135
|
+
shown.set(row.id, searchRowDigest(row));
|
|
100
136
|
}
|
|
101
137
|
}
|
|
102
138
|
if (context && shown)
|
|
103
139
|
visibleSearches.set(agent, { context, rows: shown });
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
140
|
+
// A lookup body takes precedence over a pointer or proactive copy of the same revision.
|
|
141
|
+
const exposures = new Map();
|
|
142
|
+
for (const ref of refs) {
|
|
143
|
+
const key = ref.id + '@' + ref.rev;
|
|
144
|
+
const previous = exposures.get(key);
|
|
145
|
+
if (!previous)
|
|
146
|
+
exposures.set(key, ref);
|
|
147
|
+
else {
|
|
148
|
+
previous.hintOnly = previous.hintOnly && ref.hintOnly;
|
|
149
|
+
previous.actionable ||= ref.actionable;
|
|
150
|
+
previous.viaLookup ||= ref.viaLookup;
|
|
151
|
+
}
|
|
109
152
|
}
|
|
110
|
-
const retry = step ? step.attempts++ : 0;
|
|
111
153
|
// The request can already contain a revision another session has just withdrawn.
|
|
112
154
|
// recordDelivery checks historical membership inside its transaction.
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
|
|
155
|
+
if (exposures.size) {
|
|
156
|
+
const unique = [...exposures.values()];
|
|
157
|
+
const meta = requestMeta(agent, step);
|
|
158
|
+
for (const scope of memory.scopes(agent, d)) {
|
|
159
|
+
const recorded = memory.store.recordDelivery(scope.id, agent.id, unique, meta);
|
|
160
|
+
if (step)
|
|
161
|
+
step.exposed.push(...recorded.map(ref => ({ ...ref, domain: scope.id })));
|
|
162
|
+
}
|
|
116
163
|
}
|
|
117
164
|
}
|
|
118
165
|
catch (error) {
|
|
119
166
|
ctx.logger.warn('项目记忆无法记录本步引用:' + (error instanceof Error ? error.message : String(error)));
|
|
120
167
|
}
|
|
168
|
+
}
|
|
169
|
+
ctx.on('llm/stream', (req, next) => {
|
|
170
|
+
auditRequest(req);
|
|
121
171
|
return next();
|
|
122
172
|
});
|
|
123
|
-
|
|
173
|
+
function auditEvent(session, event) {
|
|
174
|
+
if (event.seq < session.inheritedEventCount)
|
|
175
|
+
return;
|
|
124
176
|
if (event.type === 'step/start') {
|
|
125
177
|
steps.set(session, { turn: String(event.data.turn), step: event.data.step, attempts: 0, exposed: [] });
|
|
126
178
|
return;
|
|
127
179
|
}
|
|
180
|
+
if (event.type === 'turn/start' || event.type === 'turn/end' || event.type === 'step/end') {
|
|
181
|
+
steps.delete(session);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
128
184
|
if (!['tool/call', 'tool/result', 'assistant/message'].includes(event.type))
|
|
129
185
|
return;
|
|
130
186
|
const completed = event.type === 'tool/result' ? event.data.message?.toolCallId : undefined;
|
|
@@ -136,17 +192,17 @@ export function registerAudit(memory, isAgentLoopRequest) {
|
|
|
136
192
|
return;
|
|
137
193
|
const agent = ctx.agents.get(session.id);
|
|
138
194
|
const d = memory.domain(agent);
|
|
139
|
-
if (!agent || !d)
|
|
195
|
+
if (!agent || agent.session !== session || !d)
|
|
140
196
|
return;
|
|
141
197
|
const step = steps.get(session);
|
|
142
198
|
const refs = step?.generation === generation ? step.exposed : [];
|
|
143
199
|
if (event.type === 'assistant/message') {
|
|
200
|
+
if (!step || event.data.turn !== Number(step.turn) || event.data.step !== step.step)
|
|
201
|
+
return;
|
|
144
202
|
for (const ref of refsIn(messageText(event.data.message))) {
|
|
145
|
-
const
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
memory.current(owner, ref.id, ref.rev))
|
|
149
|
-
memory.store.audit(owner.id, agent.id, 'cite', meta(agent, { ...ref, seq: event.seq }));
|
|
203
|
+
const observed = refs.find(r => r.id === ref.id && r.rev === ref.rev);
|
|
204
|
+
if (observed && memory.scopes(agent, d).some(scope => scope.id === observed.domain))
|
|
205
|
+
memory.store.audit(observed.domain, agent.id, 'cite', { ...requestMeta(agent, step), ...ref, seq: event.seq });
|
|
150
206
|
}
|
|
151
207
|
}
|
|
152
208
|
else if (event.type === 'tool/call' && event.data.name === 'bash') {
|
|
@@ -161,8 +217,10 @@ export function registerAudit(memory, isAgentLoopRequest) {
|
|
|
161
217
|
if (!scope)
|
|
162
218
|
return;
|
|
163
219
|
const { command, cwd, directory } = scope;
|
|
220
|
+
const scopes = memory.scopes(agent, { ...d, cwd });
|
|
164
221
|
const matching = refs.filter((r) => {
|
|
165
|
-
const
|
|
222
|
+
const owner = r.actionable && scopes.find(scope => scope.id === r.domain);
|
|
223
|
+
const row = owner && memory.current(owner, r.id, r.rev);
|
|
166
224
|
return (row &&
|
|
167
225
|
literalActionCommand(row.action) === command &&
|
|
168
226
|
(!row.paths.length ||
|
|
@@ -176,33 +234,50 @@ export function registerAudit(memory, isAgentLoopRequest) {
|
|
|
176
234
|
let byCall = commands.get(session);
|
|
177
235
|
if (!byCall)
|
|
178
236
|
commands.set(session, (byCall = new Map()));
|
|
179
|
-
|
|
237
|
+
const request = requestMeta(agent, step);
|
|
238
|
+
byCall.set(event.data.callId, { generation, domain: d.id, refs: matching, cwd, command, request });
|
|
180
239
|
for (const ref of matching)
|
|
181
|
-
memory.store.audit(
|
|
240
|
+
memory.store.audit(ref.domain, agent.id, 'attempt', { ...request, ...ref, call: event.data.callId, seq: event.seq });
|
|
182
241
|
}
|
|
183
242
|
else if (record?.generation === generation && record.domain === d.id) {
|
|
184
243
|
for (const ref of record.refs)
|
|
185
|
-
memory.store.audit(
|
|
186
|
-
...ref,
|
|
244
|
+
memory.store.audit(ref.domain, agent.id, 'tool_result', {
|
|
245
|
+
...record.request, ...ref,
|
|
187
246
|
call: completed,
|
|
188
247
|
seq: event.seq,
|
|
189
248
|
outcome: event.data.message?.isError ? 'error' : 'recorded',
|
|
190
|
-
})
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
ctx.on('session/event', (session, event) => {
|
|
253
|
+
try {
|
|
254
|
+
auditEvent(session, event);
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
ctx.logger.warn('项目记忆无法记录本次会话回执:' + String(error));
|
|
191
258
|
}
|
|
192
|
-
});
|
|
193
|
-
ctx.on('tools/result', (exec, result) => {
|
|
194
|
-
if (!exec.agent || exec.name !== 'bash')
|
|
195
|
-
return;
|
|
196
|
-
const record = commands.get(exec.agent.session)?.get(exec.callId);
|
|
197
|
-
if (!record || record.generation !== memory.assistantGeneration() ||
|
|
198
|
-
record.domain !== memory.domain(exec.agent)?.id || result.value?.cwd !== record.cwd)
|
|
199
|
-
return;
|
|
200
|
-
const outcome = Number.isSafeInteger(result.value.exitCode) ? result.value.exitCode : 'unknown';
|
|
201
|
-
for (const ref of record.refs)
|
|
202
|
-
memory.store.audit(record.domain, exec.agent.id, 'bash_result', meta(exec.agent, { ...ref, call: exec.callId, outcome }));
|
|
203
259
|
});
|
|
204
260
|
return {
|
|
205
261
|
expanded: lookUp,
|
|
262
|
+
wrote(agent, domain, call, results) {
|
|
263
|
+
const refs = writeReceiptBodies(results);
|
|
264
|
+
if (refs.length)
|
|
265
|
+
rememberLookup(agent, call, { domain: domain.id, refs });
|
|
266
|
+
},
|
|
267
|
+
blocked(agent, domain, call, ref, reason) {
|
|
268
|
+
const digest = searchRowDigest('Error: ' + reason);
|
|
269
|
+
rememberLookup(agent, call, { domain: domain.id, refs: [{ ...ref, bodyDigest: digest, denial: true }] });
|
|
270
|
+
},
|
|
271
|
+
executed(exec, command, cwd, exitCode) {
|
|
272
|
+
if (!exec.agent)
|
|
273
|
+
return;
|
|
274
|
+
const record = commands.get(exec.agent.session)?.get(exec.callId);
|
|
275
|
+
if (!record || record.generation !== memory.assistantGeneration() || record.domain !== memory.domain(exec.agent)?.id ||
|
|
276
|
+
record.command !== command || record.cwd !== cwd)
|
|
277
|
+
return;
|
|
278
|
+
for (const ref of record.refs)
|
|
279
|
+
memory.store.audit(ref.domain, exec.agent.id, 'bash_result', { ...record.request, ...ref, call: exec.callId, outcome: exitCode });
|
|
280
|
+
},
|
|
206
281
|
shownSearchRows(agent, context) {
|
|
207
282
|
const seen = visibleSearches.get(agent);
|
|
208
283
|
return seen?.context === context ? seen.rows : undefined;
|
package/dist/automatic.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
const noStore = /(?:不要|别|不用|不需要|不许|禁止|请勿|无需)(?:再|把.{0,24})?(?:记住|记下|记录|记忆|保存|存储|存下|记到|加入记忆|记入)|别记|不要记|(?:不用|不必|无需)记|请忘(?:掉|记)|不留(?:记录|记忆)|忘(?:记|掉)我的|(?:清除|删除|移除).{0,12}(?:记忆|记录|名字|姓名|偏好)|\b(?:do not|don['’]t|never)\s+(?:ever\s+)?(?:remember|memorize|save|store|retain|record|keep)|\b(?:forget|erase|delete|remove)\s+(?:this|that|my|the (?:memory|name|preference))|\b(?:not for (?:memory|storage)|off the record|private browsing)\b|\b(?:do not|don['’]t) want.{0,25}(?:saved|stored|remembered|retained)/iu;
|
|
2
|
-
const secret = /(?:令牌|(?:api\s*)?token|one[- ]time code|otp|pin)\s*(?:[是为:=]|is\b)\s*\S
|
|
2
|
+
const secret = /(?:令牌|(?:api\s*)?token|one[- ]time code|otp|pin)\s*(?:[是为:=]|is\b)\s*\S|\b(?:password|passwd|passphrase|secret|private key|api[-_ ]?key|access[-_ ]?token|refresh[-_ ]?token|seed phrase|verification code|recovery code)\b|\bauthorization\s*:[ \t]*\S|-----BEGIN\s+[^\n]*KEY-----|\b(?:sk-[a-z0-9_-]{12,}|gh[pousr]_[a-z0-9_]{12,}|AKIA[A-Z0-9]{16}|eyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.)/iu;
|
|
3
|
+
// Recognized provider credentials and credential-bearing URIs are excluded from retention and team exports.
|
|
4
|
+
const credentialValue = /-----BEGIN [^\n]*PRIVATE KEY-----|\b(?:sk-[a-zA-Z0-9_-]{12,}|AIza[A-Za-z0-9_-]{20,}|gh[pousr]_[A-Za-z0-9_]{16,}|github_pat_[A-Za-z0-9_]{20,}|glpat-[A-Za-z0-9_-]{16,}|npm_[A-Za-z0-9]{20,}|hf_[A-Za-z0-9]{20,}|xoxb-[A-Za-z0-9-]{10,}|sk_live_[A-Za-z0-9]{10,}|rk_test_[A-Za-z0-9]{10,}|whsec_[A-Za-z0-9]{10,}|(?:AKIA|ASIA)[A-Z0-9]{16}|(?:LTAI|AKID)[A-Za-z0-9]{12,}|eyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.)\b|[a-z][a-z0-9+.-]*:\/\/[^\s/:@]+:[^\s/@]+@|\b(?:password|passwd|passphrase|secret|private[ _-]?key|api[ _-]?key|access[ _-]?token|refresh[ _-]?token|token|authorization)\b\s*(?:[::=]|is\b)\s*\S+/iu;
|
|
5
|
+
// The complete academic noun 密码学 ends at a word delimiter. Keep the conservative
|
|
6
|
+
// credential interpretation for a possessive label, an assignment, or an unseparated value.
|
|
7
|
+
const credentialLabel = /的密码|密码(?!学(?=$|[\s。!?,、;()「」“”.!?,;()]))|口令|密钥|私钥|助记词|验证码|访问令牌|安全码/u;
|
|
8
|
+
export function containsCredential(text) {
|
|
9
|
+
return credentialValue.test(text) || credentialLabel.test(text);
|
|
10
|
+
}
|
|
3
11
|
export function skipsAutomaticMemory(text) {
|
|
4
|
-
return text.length > 32000 || noStore.test(text) || secret.test(text);
|
|
12
|
+
return text.length > 32000 || noStore.test(text) || secret.test(text) || containsCredential(text) || /(?:^|\s)--(?:token|authorization|auth|credential)\s+\S/iu.test(text);
|
|
5
13
|
}
|
|
6
14
|
export function refusesAutomaticMemory(text) {
|
|
7
15
|
return noStore.test(text);
|