dsh-memory-bond 0.0.0-stage → 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 +10 -0
- package/LICENSE +21 -0
- package/README.md +181 -2
- package/README.zh-CN.md +180 -0
- package/SECURITY.md +29 -0
- package/client/memory-icon.svg +21 -0
- package/cordis.patch.yml +3 -0
- package/dist/audit.js +286 -0
- package/dist/automatic.js +16 -0
- package/dist/cache.js +40 -0
- package/dist/client.js +2035 -0
- package/dist/command-scope.js +123 -0
- package/dist/commands.js +156 -0
- package/dist/consolidation-store.js +357 -0
- package/dist/consolidation.js +182 -0
- package/dist/domain.js +245 -0
- package/dist/encoder.js +138 -0
- package/dist/export-files.js +161 -0
- 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 +242 -0
- package/dist/host.js +19 -0
- package/dist/index-policy.js +191 -0
- package/dist/index.js +349 -0
- package/dist/knowledge-hooks.js +398 -0
- package/dist/knowledge.js +359 -0
- package/dist/maintenance-episodes.js +73 -0
- package/dist/maintenance-import.js +92 -0
- package/dist/maintenance-store.js +738 -0
- package/dist/maintenance.js +376 -0
- package/dist/model-review.js +16 -0
- package/dist/personal.js +60 -0
- package/dist/policy.js +382 -0
- 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 +38 -0
- package/dist/question-answers.js +176 -0
- package/dist/retrieval.js +126 -0
- package/dist/scope-narrowing.js +49 -0
- package/dist/search-index.js +164 -0
- package/dist/search-words.js +5 -0
- package/dist/semantic.js +157 -0
- package/dist/service.js +1473 -0
- package/dist/sharing.js +289 -0
- package/dist/sources.js +149 -0
- package/dist/store.js +1578 -0
- package/dist/tool-experience.js +87 -0
- package/dist/turn-review-store.js +159 -0
- package/dist/turn-review.js +459 -0
- package/dist/ui.js +346 -0
- package/dist/vector-index.js +232 -0
- 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 +13 -0
- package/locale/detail.zh.md +13 -0
- package/locale/en.json +345 -0
- package/locale/zh.json +345 -0
- package/native/embeddings/NOTICE.md +12 -0
- package/package.json +117 -4
- 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 +286 -0
- package/src/automatic.ts +21 -0
- package/src/cache.ts +38 -0
- package/src/command-scope.ts +125 -0
- package/src/commands.ts +159 -0
- package/src/consolidation-store.ts +350 -0
- package/src/consolidation.ts +176 -0
- package/src/domain.ts +254 -0
- package/src/encoder.ts +142 -0
- package/src/export-files.ts +178 -0
- 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 +265 -0
- package/src/host.ts +119 -0
- package/src/index-policy.ts +231 -0
- package/src/index.ts +333 -0
- package/src/knowledge-hooks.ts +456 -0
- package/src/knowledge.ts +432 -0
- package/src/maintenance-episodes.ts +76 -0
- package/src/maintenance-import.ts +107 -0
- package/src/maintenance-store.ts +868 -0
- package/src/maintenance.ts +380 -0
- package/src/model-review.ts +27 -0
- package/src/personal.ts +68 -0
- package/src/policy.ts +508 -0
- 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 +39 -0
- package/src/question-answers.ts +181 -0
- package/src/retrieval.ts +133 -0
- package/src/scope-narrowing.ts +58 -0
- package/src/search-index.ts +177 -0
- package/src/search-words.ts +6 -0
- package/src/semantic.ts +178 -0
- package/src/service.ts +1488 -0
- package/src/sharing.ts +349 -0
- package/src/sources.ts +150 -0
- package/src/store.ts +1829 -0
- package/src/tool-experience.ts +93 -0
- package/src/turn-review-store.ts +158 -0
- package/src/turn-review.ts +418 -0
- package/src/ui.ts +385 -0
- package/src/vector-index.ts +228 -0
package/dist/ui.js
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
const endpoint = 'project-memory-ui/';
|
|
3
|
+
const changed = 'project-memory/ui-changed';
|
|
4
|
+
export function notifyUI(ctx, sessionId) {
|
|
5
|
+
ctx.emit(changed, sessionId);
|
|
6
|
+
}
|
|
7
|
+
function failure(code, message = code) {
|
|
8
|
+
return { ok: false, error: { code, message, details: {} } };
|
|
9
|
+
}
|
|
10
|
+
function isRef(value) {
|
|
11
|
+
if (!value || typeof value !== 'object')
|
|
12
|
+
return false;
|
|
13
|
+
const ref = value;
|
|
14
|
+
return typeof ref.id === 'string' && ref.id.length > 0 && ref.id.length <= 128 &&
|
|
15
|
+
Number.isSafeInteger(ref.rev) && Number(ref.rev) > 0;
|
|
16
|
+
}
|
|
17
|
+
function chatRule(rule) {
|
|
18
|
+
return rule.usage === 'on_demand' && rule.topic
|
|
19
|
+
? { id: rule.id, rev: rule.rev, scope: rule.scope, topic: rule.topic, usage: rule.usage }
|
|
20
|
+
: rule;
|
|
21
|
+
}
|
|
22
|
+
function hasReviewCards(value) {
|
|
23
|
+
return 'proposals' in value && Array.isArray(value.proposals) && 'rules' in value;
|
|
24
|
+
}
|
|
25
|
+
function createWatch() {
|
|
26
|
+
return { version: randomUUID(), listeners: new Set() };
|
|
27
|
+
}
|
|
28
|
+
function notifyWatch(watch) {
|
|
29
|
+
watch.version = randomUUID();
|
|
30
|
+
for (const finish of watch.listeners)
|
|
31
|
+
finish();
|
|
32
|
+
}
|
|
33
|
+
function watchVersion(watches) {
|
|
34
|
+
return watches.map(watch => watch.version).join('/');
|
|
35
|
+
}
|
|
36
|
+
function waitForChange(watches, version, signal) {
|
|
37
|
+
if (version !== watchVersion(watches) || signal.aborted)
|
|
38
|
+
return;
|
|
39
|
+
return new Promise((resolve) => {
|
|
40
|
+
const finish = () => {
|
|
41
|
+
clearTimeout(timer);
|
|
42
|
+
signal.removeEventListener('abort', finish);
|
|
43
|
+
for (const watch of watches)
|
|
44
|
+
watch.listeners.delete(finish);
|
|
45
|
+
resolve();
|
|
46
|
+
};
|
|
47
|
+
// Also observe changes originating in other DSH processes using this profile.
|
|
48
|
+
const timer = setTimeout(finish, 12_000);
|
|
49
|
+
for (const watch of watches)
|
|
50
|
+
watch.listeners.add(finish);
|
|
51
|
+
signal.addEventListener('abort', finish, { once: true });
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/** The browser receives a newly authorized projection on connect, notification and lease renewal. */
|
|
55
|
+
export function registerUI(ctx, api) {
|
|
56
|
+
ctx.inject(['connection', 'agents'], (host) => {
|
|
57
|
+
const watches = new WeakMap();
|
|
58
|
+
// Receipts contain no rule bodies. Keep at most one per visible projection per session.
|
|
59
|
+
const leases = new WeakMap();
|
|
60
|
+
const settings = createWatch();
|
|
61
|
+
const wake = (sessionId) => {
|
|
62
|
+
const session = host.agents.get(sessionId)?.session;
|
|
63
|
+
const watch = session && watches.get(session);
|
|
64
|
+
if (watch)
|
|
65
|
+
notifyWatch(watch);
|
|
66
|
+
};
|
|
67
|
+
host.on(changed, wake);
|
|
68
|
+
host.on('project-memory/consolidation-updated', () => notifyWatch(settings));
|
|
69
|
+
host.on('session/event', (session, event) => {
|
|
70
|
+
if (event.type === 'working-directory/change' || event.type === 'sandbox/mode')
|
|
71
|
+
wake(session.id);
|
|
72
|
+
});
|
|
73
|
+
const connection = host.connection;
|
|
74
|
+
async function dispatch(method, args, signal) {
|
|
75
|
+
if (!args || typeof args !== 'object' || Array.isArray(args))
|
|
76
|
+
return failure('invalid_input');
|
|
77
|
+
try {
|
|
78
|
+
const globalAllowed = () => host.get('remoteAccess')?.allows({ kind: 'global' }) !== false;
|
|
79
|
+
// This preference belongs to the browser owner and the profile, including profiles with no sessions.
|
|
80
|
+
if (['get-settings', 'set-memory-enabled', 'set-consolidation'].includes(method)) {
|
|
81
|
+
if (args.sessionId !== undefined || !globalAllowed())
|
|
82
|
+
return failure('unavailable');
|
|
83
|
+
if (method === 'get-settings')
|
|
84
|
+
await waitForChange([settings], args.version, signal);
|
|
85
|
+
if (signal.aborted || !globalAllowed())
|
|
86
|
+
return failure('unavailable');
|
|
87
|
+
const readOnly = host.get('sandboxPolicy')?.resolve({}).mode === 'read-only';
|
|
88
|
+
if (method !== 'get-settings') {
|
|
89
|
+
if (readOnly)
|
|
90
|
+
return failure('read_only', '当前配置处于只读模式');
|
|
91
|
+
if (typeof args.enabled !== 'boolean')
|
|
92
|
+
return failure('invalid_input');
|
|
93
|
+
let settingsChanged;
|
|
94
|
+
if (method === 'set-memory-enabled') {
|
|
95
|
+
settingsChanged = api.store.memoryEnabled() !== args.enabled;
|
|
96
|
+
api.store.setMemoryEnabled(args.enabled);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
if (Object.keys(args).some(key => key !== 'enabled'))
|
|
100
|
+
return failure('invalid_input');
|
|
101
|
+
const before = api.store.consolidation.status().enabled;
|
|
102
|
+
settingsChanged = api.store.consolidation.configure({ enabled: args.enabled }).enabled !== before;
|
|
103
|
+
}
|
|
104
|
+
if (settingsChanged) {
|
|
105
|
+
notifyWatch(settings);
|
|
106
|
+
host.emit('project-memory/consolidation-settings-changed');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return { ok: true, value: { memoryEnabled: api.store.memoryEnabled(), consolidation: api.store.consolidation.status(),
|
|
110
|
+
readOnly, version: settings.version } };
|
|
111
|
+
}
|
|
112
|
+
const sessionId = args.sessionId;
|
|
113
|
+
if (typeof sessionId !== 'string' || sessionId.length > 256)
|
|
114
|
+
return failure('unavailable');
|
|
115
|
+
const allowed = () => globalAllowed() &&
|
|
116
|
+
host.get('remoteAccess')?.allows({ kind: 'session', id: sessionId }) !== false;
|
|
117
|
+
if (!allowed())
|
|
118
|
+
return failure('unavailable');
|
|
119
|
+
const agent = host.agents.get(sessionId) ??
|
|
120
|
+
(await host.get('sessionController')?.resolveAgent(sessionId))?.agent;
|
|
121
|
+
if (!agent ||
|
|
122
|
+
agent.session.header.origin === 'subagent' ||
|
|
123
|
+
!allowed() ||
|
|
124
|
+
host.agents.get(sessionId) !== agent)
|
|
125
|
+
return failure('unavailable');
|
|
126
|
+
const context = () => {
|
|
127
|
+
const project = api.domainOf(agent.session);
|
|
128
|
+
return {
|
|
129
|
+
root: project?.root ?? null,
|
|
130
|
+
cwd: project?.cwd ?? host.workingDirectory.get(agent.session),
|
|
131
|
+
projectKey: project?.id ?? null,
|
|
132
|
+
readOnly: host.get('sandboxPolicy')?.resolve({ session: agent.session }).mode === 'read-only',
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
const matchesContext = (expected, live) => expected === undefined || (!!expected && expected.root === live.root &&
|
|
136
|
+
expected.cwd === live.cwd && expected.projectKey === live.projectKey);
|
|
137
|
+
const stillAllowed = () => !signal.aborted && allowed() && host.agents.get(sessionId) === agent;
|
|
138
|
+
const stamp = (live, scope) => {
|
|
139
|
+
if (!api.store.uiChangeStamp)
|
|
140
|
+
return '';
|
|
141
|
+
const domains = [];
|
|
142
|
+
if (scope !== 'project')
|
|
143
|
+
domains.push('profile:personal');
|
|
144
|
+
if (scope !== 'profile' && live.projectKey)
|
|
145
|
+
domains.push(live.projectKey);
|
|
146
|
+
return JSON.stringify([api.store.uiChangeStamp(domains), scope ? args.args?.locale :
|
|
147
|
+
watches.get(agent.session)?.version, live, args.page && [args.page.offset, args.page.limit]]);
|
|
148
|
+
};
|
|
149
|
+
const unchanged = (key, current) => {
|
|
150
|
+
const lease = leases.get(agent.session)?.get(key);
|
|
151
|
+
return current && lease && lease.token === args.lease && lease.stamp === current;
|
|
152
|
+
};
|
|
153
|
+
const grant = (key, current) => {
|
|
154
|
+
let entries = leases.get(agent.session);
|
|
155
|
+
if (!entries)
|
|
156
|
+
leases.set(agent.session, entries = new Map());
|
|
157
|
+
const old = entries.get(key);
|
|
158
|
+
if (old?.stamp === current)
|
|
159
|
+
return old.token;
|
|
160
|
+
const token = randomUUID();
|
|
161
|
+
entries.set(key, { token, stamp: current });
|
|
162
|
+
return token;
|
|
163
|
+
};
|
|
164
|
+
const boundContext = args.expectedContext === undefined ? undefined : context();
|
|
165
|
+
if (signal.aborted || (boundContext && !matchesContext(args.expectedContext, boundContext)))
|
|
166
|
+
return failure('unavailable');
|
|
167
|
+
if (method === 'context') {
|
|
168
|
+
const live = boundContext ?? context();
|
|
169
|
+
return { ok: true, value: { ...live, ...(args.includePending && live.projectKey && {
|
|
170
|
+
hasPending: api.store.inbox(live.projectKey, sessionId).length > 0,
|
|
171
|
+
}) } };
|
|
172
|
+
}
|
|
173
|
+
if (method === 'turn-receipts') {
|
|
174
|
+
if (typeof args.answerSeq !== 'number' || !Number.isSafeInteger(args.answerSeq) || args.answerSeq < 0)
|
|
175
|
+
return failure('invalid_input');
|
|
176
|
+
if (signal.aborted)
|
|
177
|
+
return failure('unavailable');
|
|
178
|
+
return { ok: true, value: api.turnReceipts(agent, args.answerSeq) };
|
|
179
|
+
}
|
|
180
|
+
if (method === 'consolidation-suggestions' || method === 'decide-consolidation') {
|
|
181
|
+
const project = boundContext ?? context();
|
|
182
|
+
if (args.scope !== 'project' || !project.root || project.root !== args.root)
|
|
183
|
+
return failure('unavailable');
|
|
184
|
+
if (method === 'consolidation-suggestions')
|
|
185
|
+
return { ok: true, value: { suggestions: api.listConsolidation(agent) } };
|
|
186
|
+
if (project.readOnly)
|
|
187
|
+
return failure('read_only', '当前会话处于只读模式');
|
|
188
|
+
if (!isRef(args.left) || !isRef(args.right) || (args.keep !== null && !isRef(args.keep)))
|
|
189
|
+
return failure('invalid_input');
|
|
190
|
+
api.decideConsolidation(agent, args.left, args.right, args.keep);
|
|
191
|
+
host.emit('project-memory/consolidation-updated');
|
|
192
|
+
return { ok: true, value: {} };
|
|
193
|
+
}
|
|
194
|
+
if (method === 'manage') {
|
|
195
|
+
if (!args.op ||
|
|
196
|
+
!['list', 'search', 'read', 'source', 'revise', 'usage', 'forget', 'undo', 'pin', 'unpin', 'clear-quote'].includes(args.op) ||
|
|
197
|
+
!args.args ||
|
|
198
|
+
typeof args.args !== 'object' ||
|
|
199
|
+
Array.isArray(args.args) ||
|
|
200
|
+
(args.scope !== undefined && args.scope !== 'profile' && args.scope !== 'project'))
|
|
201
|
+
return failure('invalid_input');
|
|
202
|
+
if (args.details !== undefined && (typeof args.details !== 'boolean' ||
|
|
203
|
+
(args.details && (!args.scope || !['list', 'search'].includes(args.op)))))
|
|
204
|
+
return failure('invalid_input');
|
|
205
|
+
if (args.page !== undefined && (!args.details || !args.page || !Number.isSafeInteger(args.page.offset) ||
|
|
206
|
+
args.page.offset < 0 || !Number.isSafeInteger(args.page.limit) || args.page.limit < 0 || args.page.limit > 50))
|
|
207
|
+
return failure('invalid_input');
|
|
208
|
+
const write = !['list', 'search', 'read', 'source'].includes(args.op);
|
|
209
|
+
const before = boundContext ?? context();
|
|
210
|
+
if (before.readOnly && write)
|
|
211
|
+
return failure('read_only', '当前会话处于只读模式');
|
|
212
|
+
const listLease = args.op === 'list' && args.page && args.scope ? 'list:' + args.scope : '';
|
|
213
|
+
const initial = listLease ? stamp(before, args.scope) : '';
|
|
214
|
+
if (unchanged(listLease, initial))
|
|
215
|
+
return { ok: true, value: { unchanged: true, lease: args.lease } };
|
|
216
|
+
const check = { reusable: false };
|
|
217
|
+
const result = await api.manage(agent, args.op, { ...args.args, scope: args.scope }, listLease ? check : undefined, args.page);
|
|
218
|
+
if (!stillAllowed())
|
|
219
|
+
return failure('unavailable');
|
|
220
|
+
const live = context();
|
|
221
|
+
if (!matchesContext(before, live))
|
|
222
|
+
return failure('unavailable');
|
|
223
|
+
const { readOnly } = live;
|
|
224
|
+
if (write)
|
|
225
|
+
wake(agent.id);
|
|
226
|
+
if (args.scope && 'rules' in result) {
|
|
227
|
+
const inScope = (item) => item.scope === args.scope;
|
|
228
|
+
const scoped = {
|
|
229
|
+
rules: result.rules.filter(inScope),
|
|
230
|
+
needs_review: result.needs_review.filter(inScope),
|
|
231
|
+
};
|
|
232
|
+
if (!args.details)
|
|
233
|
+
return { ok: true, value: { readOnly, result: scoped } };
|
|
234
|
+
// Pending cards belong to this session in the project's store. List already
|
|
235
|
+
// carries the view; search may also need replacement choices outside its hits.
|
|
236
|
+
let review;
|
|
237
|
+
if (args.scope === 'project' && live.projectKey) {
|
|
238
|
+
if (hasReviewCards(result))
|
|
239
|
+
review = 'choices' in result && Array.isArray(result.choices)
|
|
240
|
+
? { proposals: result.proposals, rules: result.choices } : result;
|
|
241
|
+
else if (api.store.inbox(live.projectKey, agent.id).length)
|
|
242
|
+
review = api.view(agent, 'project');
|
|
243
|
+
}
|
|
244
|
+
const proposals = review?.proposals.filter(card => card.state === 'pending' &&
|
|
245
|
+
(!('scope' in card) || card.scope === args.scope)) ?? [];
|
|
246
|
+
const reviewRules = review && proposals.some(card => !card.source.fileImport)
|
|
247
|
+
? review.rules.filter(rule => inScope(rule) && !('knowledge' in rule)).map(rule => {
|
|
248
|
+
const { id, rev, scope, topic, usage, when, action, paths } = rule;
|
|
249
|
+
return usage === 'on_demand' && topic ? { id, rev, scope, topic, usage }
|
|
250
|
+
: { id, rev, scope, topic, usage, when, action, paths };
|
|
251
|
+
}) : [];
|
|
252
|
+
const suggestions = args.op === 'list' && args.scope === 'project' && live.projectKey
|
|
253
|
+
? api.listConsolidation(agent) : [];
|
|
254
|
+
const lease = listLease && check.reusable && initial && initial === stamp(live, args.scope) ? grant(listLease, initial) : undefined;
|
|
255
|
+
const pagedTotal = 'total' in result && typeof result.total === 'number' ? result.total : undefined;
|
|
256
|
+
const total = pagedTotal ?? scoped.rules.length + scoped.needs_review.length;
|
|
257
|
+
const { offset, limit } = args.page ?? { offset: 0, limit: total };
|
|
258
|
+
const resultPage = args.page && pagedTotal === undefined ? { rules: scoped.rules.slice(offset, offset + limit),
|
|
259
|
+
needs_review: scoped.needs_review.slice(Math.max(0, offset - scoped.rules.length), Math.max(0, offset + limit - scoped.rules.length)) } : scoped;
|
|
260
|
+
return { ok: true, value: { lease, readOnly, result: resultPage, ...(args.page && { total }), proposals, reviewRules, suggestions,
|
|
261
|
+
memoryEnabled: api.store.memoryEnabled(), context: live } };
|
|
262
|
+
}
|
|
263
|
+
return { ok: true, value: { result, readOnly } };
|
|
264
|
+
}
|
|
265
|
+
if (method === 'view') {
|
|
266
|
+
let watch = watches.get(agent.session);
|
|
267
|
+
if (!watch) {
|
|
268
|
+
watch = createWatch();
|
|
269
|
+
watches.set(agent.session, watch);
|
|
270
|
+
}
|
|
271
|
+
const observed = [watch, settings];
|
|
272
|
+
await waitForChange(observed, args.version, signal);
|
|
273
|
+
if (!stillAllowed())
|
|
274
|
+
return failure('unavailable');
|
|
275
|
+
const live = context();
|
|
276
|
+
if (!matchesContext(args.expectedContext, live))
|
|
277
|
+
return failure('unavailable');
|
|
278
|
+
const version = watchVersion(observed);
|
|
279
|
+
const initial = stamp(live);
|
|
280
|
+
if (unchanged('chat', initial))
|
|
281
|
+
return { ok: true, value: { unchanged: true, version, lease: args.lease } };
|
|
282
|
+
const check = { reusable: false };
|
|
283
|
+
const { conversationCards = [], rules, saved } = api.view(agent, 'chat', check);
|
|
284
|
+
// Chat polls for receipts every turn. Values of on-demand global memories are
|
|
285
|
+
// returned through an explicit manager read, never through this polling channel.
|
|
286
|
+
const receipts = new Set(conversationCards.flatMap(card => card.entries.map(ref => ref.id + '@' + ref.rev)));
|
|
287
|
+
const visibleRules = rules
|
|
288
|
+
.filter(rule => rule.usage === 'proactive' || !rule.topic || receipts.has(rule.id + '@' + rule.rev))
|
|
289
|
+
.map(chatRule);
|
|
290
|
+
const notices = saved.map(row => ({
|
|
291
|
+
id: row.id, rev: row.rev, scope: row.scope, turnId: row.turnId, topic: row.topic,
|
|
292
|
+
usage: row.usage, hasPrevious: !!row.previous,
|
|
293
|
+
}));
|
|
294
|
+
const lease = check.reusable && initial && initial === stamp(live) ? grant('chat', initial) : undefined;
|
|
295
|
+
return { ok: true, value: { proposals: conversationCards, rules: visibleRules, saved: notices, context: live, version, lease,
|
|
296
|
+
memoryEnabled: api.store.memoryEnabled() } };
|
|
297
|
+
}
|
|
298
|
+
if (host.get('sandboxPolicy')?.resolve({ session: agent.session }).mode === 'read-only')
|
|
299
|
+
return failure('read_only', '当前会话处于只读模式');
|
|
300
|
+
if (args.scope !== undefined && args.scope !== 'project')
|
|
301
|
+
return failure('unavailable');
|
|
302
|
+
if (typeof args.id !== 'string' ||
|
|
303
|
+
typeof args.revision !== 'number' ||
|
|
304
|
+
typeof args.digest !== 'string' ||
|
|
305
|
+
!Array.isArray(args.selections))
|
|
306
|
+
return failure('invalid_input');
|
|
307
|
+
const result = api.review(agent, { id: args.id, revision: args.revision, digest: args.digest, selections: args.selections }, undefined, 'owner_card');
|
|
308
|
+
wake(agent.id);
|
|
309
|
+
return { ok: true, value: result };
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
const code = error && typeof error === 'object' && 'code' in error ? String(error.code) : 'review_failed';
|
|
313
|
+
return failure(code, error instanceof Error ? error.message : code);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
// The panel reads, reviews and manages. Saving a new statement by hand is the /project-memory remember command.
|
|
317
|
+
for (const method of ['get-settings', 'set-memory-enabled', 'set-consolidation',
|
|
318
|
+
'context', 'view', 'turn-receipts', 'review', 'manage', 'consolidation-suggestions', 'decide-consolidation']) {
|
|
319
|
+
connection.fetch.register({
|
|
320
|
+
path: '/api/' + endpoint + method,
|
|
321
|
+
methods: ['POST'],
|
|
322
|
+
requestBody: 'buffered',
|
|
323
|
+
async fetch(request) {
|
|
324
|
+
// The shared /api bridge authenticates the request, checks Origin, and
|
|
325
|
+
// bounds the body before dispatch. Check the exact interactive browser
|
|
326
|
+
// identity as well: authenticated API peers can also have an owner role.
|
|
327
|
+
const admission = connection.admit(request);
|
|
328
|
+
if (!admission.peer ||
|
|
329
|
+
admission.peer.id !== connection.browserPeer.id ||
|
|
330
|
+
admission.peer.principal.kind !== 'owner')
|
|
331
|
+
return new Response('unavailable', { status: 403 });
|
|
332
|
+
if (request.headers.get('content-type')?.split(';')[0] !== 'application/json')
|
|
333
|
+
return new Response('expected JSON', { status: 415 });
|
|
334
|
+
const envelope = await request.json().catch(() => null);
|
|
335
|
+
if (!envelope ||
|
|
336
|
+
envelope.type !== 'client-request' ||
|
|
337
|
+
envelope.method !== endpoint + method ||
|
|
338
|
+
typeof envelope.rpcId !== 'string')
|
|
339
|
+
return new Response('invalid request', { status: 400 });
|
|
340
|
+
const result = await dispatch(method, envelope.payload, request.signal);
|
|
341
|
+
return Response.json({ type: 'server-response', rpcId: envelope.rpcId, result }, { headers: { 'cache-control': 'no-store' } });
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// Passage embeddings are derived from current SQLite heads. The durable queue tracks changed
|
|
2
|
+
// revisions; a restarted worker reuses completed passages from any interrupted revision.
|
|
3
|
+
import { document } from "./search-index.js";
|
|
4
|
+
export { document } from "./search-index.js";
|
|
5
|
+
import { createHash } from 'node:crypto';
|
|
6
|
+
import { setImmediate as yieldToHost } from 'node:timers/promises';
|
|
7
|
+
import { encoderId, language, modelLanguages, queryLanguages, SentenceEncoder } from "./encoder.js";
|
|
8
|
+
export { language } from "./encoder.js";
|
|
9
|
+
export const newSearchTrace = () => ({ match: 'ranked', sqliteMs: 0, queueMs: 0, encoderMs: 0 });
|
|
10
|
+
export class VectorIndex {
|
|
11
|
+
store;
|
|
12
|
+
encoder;
|
|
13
|
+
poll;
|
|
14
|
+
reschedule = false;
|
|
15
|
+
indexing = false;
|
|
16
|
+
closed = false;
|
|
17
|
+
inferenceTail = Promise.resolve();
|
|
18
|
+
constructor(store, encoder = new SentenceEncoder()) {
|
|
19
|
+
this.store = store;
|
|
20
|
+
this.encoder = encoder;
|
|
21
|
+
}
|
|
22
|
+
get languages() {
|
|
23
|
+
return this.encoder.languages ?? modelLanguages;
|
|
24
|
+
}
|
|
25
|
+
start() {
|
|
26
|
+
if (!this.languages.length)
|
|
27
|
+
return;
|
|
28
|
+
this.store.onHeadsChanged = () => this.enqueue();
|
|
29
|
+
this.enqueue();
|
|
30
|
+
}
|
|
31
|
+
enqueue() {
|
|
32
|
+
if (this.closed)
|
|
33
|
+
return;
|
|
34
|
+
clearTimeout(this.poll);
|
|
35
|
+
if (this.indexing) {
|
|
36
|
+
this.reschedule = true;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.indexing = true;
|
|
40
|
+
setImmediate(() => void this.drain());
|
|
41
|
+
}
|
|
42
|
+
async drain() {
|
|
43
|
+
try {
|
|
44
|
+
while (!this.closed) {
|
|
45
|
+
const job = this.store.nextVectorJob(this.languages.length === 1 ? this.languages[0] : undefined);
|
|
46
|
+
if (!job)
|
|
47
|
+
break;
|
|
48
|
+
await yieldToHost();
|
|
49
|
+
if (this.closed)
|
|
50
|
+
return;
|
|
51
|
+
try {
|
|
52
|
+
const rule = this.store.read(job.domain, job.id, job.rev);
|
|
53
|
+
if (rule)
|
|
54
|
+
await this.indexRule({ rule, domain: job.domain });
|
|
55
|
+
else
|
|
56
|
+
this.store.finishVectorJob(job.domain, job.id, job.rev);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
if (!this.closed)
|
|
60
|
+
this.store.deferVectorJob(job.rid, Date.now() + 5000);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// A busy or temporarily unavailable DB is retried by the same durable queue.
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
this.indexing = false;
|
|
69
|
+
if (!this.closed) {
|
|
70
|
+
if (this.reschedule) {
|
|
71
|
+
this.reschedule = false;
|
|
72
|
+
this.enqueue();
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
// Also discover writes from another process which cannot notify this instance.
|
|
76
|
+
this.poll = setTimeout(() => this.enqueue(), 5000);
|
|
77
|
+
this.poll.unref();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
passages(rule, text, cached) {
|
|
83
|
+
const model = encoderId(language(text));
|
|
84
|
+
const segments = rule.action.split(/[,,;;。!?::\n]+/u).map(s => s.trim())
|
|
85
|
+
.filter(s => s.length >= 6 && s !== rule.action);
|
|
86
|
+
const parts = [...new Set([text, ...segments])].slice(0, 8);
|
|
87
|
+
return parts.map((part, i) => {
|
|
88
|
+
const key = model + '/passage-' + i;
|
|
89
|
+
const digest = createHash('sha256').update(part).digest('hex');
|
|
90
|
+
const entry = cached?.get(key);
|
|
91
|
+
return { text: part, key, digest, vector: entry?.digest === digest ? entry.vector : undefined };
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
// The only background producer submits one head at a time, yielding before the next head.
|
|
95
|
+
// Queries join ahead of all as-yet unsubmitted passages. Worker deadlines start at dispatch.
|
|
96
|
+
encode(lang, texts, trace) {
|
|
97
|
+
const queued = performance.now();
|
|
98
|
+
const result = this.inferenceTail.then(async () => {
|
|
99
|
+
if (this.closed)
|
|
100
|
+
throw Error('embedding_unavailable');
|
|
101
|
+
const started = performance.now();
|
|
102
|
+
if (trace)
|
|
103
|
+
trace.queueMs += started - queued;
|
|
104
|
+
try {
|
|
105
|
+
return await this.encoder.encode(lang, texts);
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
if (trace)
|
|
109
|
+
trace.encoderMs += performance.now() - started;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
this.inferenceTail = result.then(() => { }, () => { });
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
async indexRule(row) {
|
|
116
|
+
const text = document(row.rule);
|
|
117
|
+
const missing = this.passages(row.rule, text, this.store.headVectors(row.domain, row.rule.id, row.rule.rev)).filter(p => !p.vector);
|
|
118
|
+
if (!missing.length) {
|
|
119
|
+
this.store.finishVectorJob(row.domain, row.rule.id, row.rule.rev);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const vectors = await this.encode(language(text), missing.map(p => p.text));
|
|
123
|
+
if (this.closed || !this.store.read(row.domain, row.rule.id, row.rule.rev))
|
|
124
|
+
return;
|
|
125
|
+
if (vectors.length !== missing.length || !vectors.every(v => v instanceof Float32Array && v.length > 0 && v.length <= 8192 && v.every(Number.isFinite))) {
|
|
126
|
+
throw Error('embedding_unavailable');
|
|
127
|
+
}
|
|
128
|
+
for (const [i, passage] of missing.entries()) {
|
|
129
|
+
// The SQL insert also checks the current revision atomically against other processes.
|
|
130
|
+
this.store.cacheVector(row.domain, row.rule.id, row.rule.rev, passage.key, passage.digest, vectors[i]);
|
|
131
|
+
}
|
|
132
|
+
this.store.finishVectorJob(row.domain, row.rule.id, row.rule.rev);
|
|
133
|
+
}
|
|
134
|
+
async queryVector(query, lang, trace) {
|
|
135
|
+
const instruction = lang === 'zh'
|
|
136
|
+
? '为这个句子生成表示以用于检索相关文章:'
|
|
137
|
+
: 'Represent this sentence for searching relevant passages: ';
|
|
138
|
+
const [vector] = await this.encode(lang, [instruction + query], trace);
|
|
139
|
+
return vector;
|
|
140
|
+
}
|
|
141
|
+
// Compare existing document vectors without loading historical quotes or keeping a
|
|
142
|
+
// SQLite reader open during inference. Empty or unindexed domains cost no encoding.
|
|
143
|
+
async reviewTopics(domains, query) {
|
|
144
|
+
const hits = [];
|
|
145
|
+
for (const lang of queryLanguages(query)) {
|
|
146
|
+
if (!this.languages.includes(lang))
|
|
147
|
+
continue;
|
|
148
|
+
try {
|
|
149
|
+
hits.push(...await this.reviewLanguage(domains, query, lang));
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
// Another installed language and the lexical index can still offer candidates.
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return hits.sort((a, b) => b.score - a.score || a.id.localeCompare(b.id));
|
|
156
|
+
}
|
|
157
|
+
async reviewLanguage(domains, query, lang) {
|
|
158
|
+
const model = encoderId(lang) + '/passage-0';
|
|
159
|
+
const probe = this.store.reviewVectors(domains, model);
|
|
160
|
+
const empty = probe.next().done;
|
|
161
|
+
probe.return();
|
|
162
|
+
if (empty)
|
|
163
|
+
return [];
|
|
164
|
+
const q = await this.queryVector(query, lang);
|
|
165
|
+
const hits = [];
|
|
166
|
+
for (const { domain, id, rev, vector } of this.store.reviewVectors(domains, model)) {
|
|
167
|
+
if (vector.length !== q.length)
|
|
168
|
+
continue;
|
|
169
|
+
const score = vector.reduce((sum, value, i) => sum + value * q[i], 0);
|
|
170
|
+
// A review shortlist includes weaker paraphrases than a normal search result.
|
|
171
|
+
// The model must still identify one target and the write path verifies the quote.
|
|
172
|
+
if (score >= 0.4)
|
|
173
|
+
hits.push({ domain, id, rev, score });
|
|
174
|
+
}
|
|
175
|
+
return hits;
|
|
176
|
+
}
|
|
177
|
+
async scores(query, docs, trace, lang) {
|
|
178
|
+
const groups = new Map();
|
|
179
|
+
for (const doc of docs) {
|
|
180
|
+
if (language(doc.text) !== lang)
|
|
181
|
+
continue;
|
|
182
|
+
const group = groups.get(doc.domain);
|
|
183
|
+
if (group)
|
|
184
|
+
group.push(doc);
|
|
185
|
+
else
|
|
186
|
+
groups.set(doc.domain, [doc]);
|
|
187
|
+
}
|
|
188
|
+
const scores = new Map();
|
|
189
|
+
let q;
|
|
190
|
+
let missing = false;
|
|
191
|
+
for (const [domain, group] of groups) {
|
|
192
|
+
// Read complete candidate batches before yielding. Other sessions can write during
|
|
193
|
+
// inference, and a broad query never holds all passage vectors in memory.
|
|
194
|
+
for (let start = 0; start < group.length; start += 96) {
|
|
195
|
+
if (start)
|
|
196
|
+
await yieldToHost();
|
|
197
|
+
const batch = group.slice(start, start + 96);
|
|
198
|
+
const before = performance.now();
|
|
199
|
+
const stored = this.store.headVectorsMany(domain, batch.map(({ rule }) => ({ id: rule.id, rev: rule.rev })));
|
|
200
|
+
trace.sqliteMs += performance.now() - before;
|
|
201
|
+
for (const { rule, text } of batch) {
|
|
202
|
+
const cached = stored.get(rule.id);
|
|
203
|
+
if (!cached) {
|
|
204
|
+
missing = true;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
for (const { vector } of this.passages(rule, text, cached)) {
|
|
208
|
+
if (!vector) {
|
|
209
|
+
missing = true;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
q ??= await this.queryVector(query, lang, trace);
|
|
213
|
+
if (vector.length !== q.length)
|
|
214
|
+
continue;
|
|
215
|
+
let score = 0;
|
|
216
|
+
for (let i = 0; i < q.length; i++)
|
|
217
|
+
score += vector[i] * q[i];
|
|
218
|
+
scores.set(rule.id, Math.max(scores.get(rule.id) ?? -1, score));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
trace.coverage = missing ? q ? 'partial' : 'missing' : 'complete';
|
|
224
|
+
return scores;
|
|
225
|
+
}
|
|
226
|
+
close() {
|
|
227
|
+
this.closed = true;
|
|
228
|
+
this.store.onHeadsChanged = undefined;
|
|
229
|
+
clearTimeout(this.poll);
|
|
230
|
+
this.encoder.close();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# 本地记忆的实现
|
|
2
|
+
|
|
3
|
+
DSH 提供当前会话、工作目录、用户事件和模型请求。插件将记忆和来源坐标存入当前 profile,在组装请求时选择适用的约定。助手可以按需查找其他结论,用户可以在“设置 → 记忆”中核对一次请求实际收到了哪些内容。[宿主注册](../src/index.ts) · [请求审计](../src/audit.ts)
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
[查看完整大图](./images/bond-memory-principle-zh.svg) · [English diagram](./images/bond-memory-principle-en.svg) · [可编辑的 draw.io 源图](./images/bond-memory-principle.drawio)
|
|
8
|
+
|
|
9
|
+
## 数据和作用域
|
|
10
|
+
|
|
11
|
+
主库位于 profile 内的 `memory-bond/memory.sqlite`,受管备份位于 `memory-bond/backups/projects.sqlite`。全局记忆随 profile 使用。项目记忆按本机身份、profile 和 Git 公共目录识别,因此同一仓库的 worktree 共享记忆,分别克隆的仓库各自保存。路径、分支、命令目标等条件仍在当前工作树核验。非 Git 项目可以通过 `nonGitRoots` 指定绝对根目录。若多个根目录覆盖当前位置,取最具体的一项。[项目身份](../src/domain.ts) · [存储](../src/store.ts)
|
|
12
|
+
|
|
13
|
+
主会话按宿主授予的权限访问项目和全局记忆,子代理只能访问获准的项目范围。当前 profile 的记忆开关控制助手的写入、注入和查阅。已有记录的管理沿用相应会话的访问权限。“全部记忆”汇总有权访问的项目与全局记录,按项目去重,待确认卡和实际投递可以按会话核对。[作用域和权限](../src/service.ts) · [管理接口](../src/ui.ts)
|
|
14
|
+
|
|
15
|
+
## 一条记忆如何生效
|
|
16
|
+
|
|
17
|
+
1. 助手通过 `project_memory_propose` 提交作用域、主体、主题、结论、适用条件和用户引文。插件核对当前会话、轮次和用户事件,并把引文定位到具体片段。原生提问工具的手填回答也可以作为来源。用户同轮明确要求记忆并选定格式时,会同时核对指令和所选选项。
|
|
18
|
+
2. 前台复核使用当前会话配置的模型,将原话、提议和可见的候选结论一起比较,判断新增、重述、替换或跳过。显式更正按 ID 和版本定位。引用仓库指令时,还会核对相关文件和引文。主库保存在本机,复核所需的片段和候选结论会发往当前会话的模型提供方。[写入协议](../src/propose-contract.ts) · [模型复核](../src/proposal-review.ts) · [仓库指令](../src/guidance.ts)
|
|
19
|
+
3. 新记录获得稳定 ID,修订沿用该 ID 并增加版本号。提交事务会重新核对状态、来源和预期版本,避免覆盖已经发生的更改。重复陈述可以沿用现行版本。用户也可以通过命令手工保存、调整用途或撤回记录,手工操作有单独回执。[写入服务](../src/service.ts) · [版本事务](../src/store.ts)
|
|
20
|
+
|
|
21
|
+
`usage` 决定结论如何进入请求。主动约定(`proactive`)可进入运行时上下文,按需内容(`on_demand`)通过检索或读取展开。标为敏感的自动记忆只允许按需使用。按需主题与本轮提问匹配时,索引可显示提问中已出现的词及记忆版本。[索引选择](../src/index-policy.ts)
|
|
22
|
+
|
|
23
|
+
## 从存储到模型请求
|
|
24
|
+
|
|
25
|
+
| 入口 | 何时使用 | 模型可见内容 |
|
|
26
|
+
| --- | --- | --- |
|
|
27
|
+
| 运行时上下文 | DSH 组装请求时 | 适用的主动约定、条件、例外和版本。受行数及字节预算限制,优先考虑置顶组。 |
|
|
28
|
+
| `project_memory_search` | 助手检索历史约定或事实时 | 可见且适用的现行记录。可按作用域、主体或主题缩小范围,默认最多返回 6 条,`limit` 可取 1 至 40。 |
|
|
29
|
+
| `project_memory_read` | 已知 ID 或需要展开结论时 | 对应现行版本的正文、条件与例外。给定版本失效时会报告状态。 |
|
|
30
|
+
| `project_memory_source` | 用户想核对依据时 | 返回现行适用版本留存的引文和来源状态。原项目会话可访问时,插件可按用户事件和引文区间核验。工具读取全局来源时使用留存引文,全局记忆的设置页还能按版本核对保留的历史原话。 |
|
|
31
|
+
|
|
32
|
+
保存或恢复记录时,SQLite 在事务内更新 FTS5 索引并登记向量任务。可选中文和英文 BGE 编码器在本地独立运行,生成的向量绑定原文摘要、模型和记忆版本。混合检索合并关键词和可用向量的结果。编码器缺失或索引尚未完成时仍可用关键词检索,`coverage` 表示当次向量覆盖情况。混合语言查询可以与两个模型各自编码的段落比较。`alternateQuery` 可补充另一种问法。[检索](../src/retrieval.ts) · [向量任务](../src/vector-index.ts)
|
|
33
|
+
|
|
34
|
+
同一条约定在不同工作树可以有不同的核验结果。例如在 `release` 删除约定依赖的 Make 目标后,该工作树的 `/project-memory status` 会把这个版本列入 `needs_review`。`main` 保留目标时仍可使用同一版本。核验结果决定读取资格,一次请求究竟收到了什么要看回答下方的「本轮记忆回执」。[仓库条件核验](../src/policy.ts)
|
|
35
|
+
|
|
36
|
+
聊天回执按 `id@rev` 汇总实际请求,同一条在不同步骤出现时可展开核对。短线索进入请求时只记作线索,完整结论进入请求时才记作正文送达。回执还分别记录助手在回复中引用版本号、Bash 执行匹配命令的情况。命令匹配能证实执行发生,判断助手选择它的原因还需结合对话上下文。撤回后的条目退出检索和注入,先前收到正文的会话可收到失效提示。[投递审计](../src/audit.ts) · [使用记录](../src/store.ts)
|
|
37
|
+
|
|
38
|
+
## 后台任务与配置
|
|
39
|
+
|
|
40
|
+
| 配置或开关 | 默认值 | 作用 |
|
|
41
|
+
| --- | --- | --- |
|
|
42
|
+
| `maxRows`、`maxTokens` | 16 行、2048 字节 | 限制运行时记忆索引。实现按 UTF-8 字节计量,可在没有模型分词器时给出保守上限。 |
|
|
43
|
+
| `overflowHints` | 依据当前提问匹配 | 在剩余空间内最多附两条线索。`false` 关闭线索,`true` 也允许未匹配的主动约定补位。 |
|
|
44
|
+
| `promptLanguage` | 根据用户输入推断,缺省使用宿主进程的区域设置 | 可用 `en` 或 `zh` 固定模型提示语言。 |
|
|
45
|
+
| `turnReviewBudget` | 每个 profile 每个 UTC 日 20 批 | 在可写主会话正常结束或达到输出上限后,用该会话的模型复核尚未处理的用户片段和相关候选。`0` 关闭轮末补查。 |
|
|
46
|
+
| `historyBudget` | 0 | 每个项目每天自动处理历史候选的额度。它复用会话中已有的提议和用户引文,符合条件的生成待审卡。显式执行的历史复核另行触发。 |
|
|
47
|
+
| `historyDays` | 90 天 | 控制被替换或撤回的版本正文、按请求记录的明细等的保留期。设为 0 会立即使已退役版本的正文过期,并停止保留逐请求明细。 |
|
|
48
|
+
| 设置中的“跨会话整理” | 关闭 | 已完成项目轮次的可写主会话空闲时检查,持续空闲时约每小时再查一次。 |
|
|
49
|
+
|
|
50
|
+
跨会话整理从同一项目不同会话中寻找关键词或本地向量相近的记录。只有选出合格的一对才调用模型比较其摘要和条件。模型判断可能重复时,设置页列出两条现行记录,用户可以保留两条,或指定保留其中一条并撤回另一条。[轮末补查](../src/turn-review.ts) · [历史复核](../src/maintenance.ts) · [跨会话整理](../src/consolidation.ts)
|
|
51
|
+
|
|
52
|
+
清除引文会清理主库和受管备份中的相应证据,并记录擦除以约束后续恢复。原始 DSH 会话由宿主管理。恢复受管备份时,插件核对现行版本、擦除记录和记忆开关的变更记录。[备份与恢复](../src/maintenance-store.ts) · [数据与权限说明](../SECURITY.md)
|