@shadowforge0/aquifer-memory 1.9.0 → 1.9.1
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 +33 -4
- package/README_CN.md +9 -1
- package/README_TW.md +5 -2
- package/consumers/cli.js +55 -34
- package/consumers/codex-active-checkpoint.js +3 -1
- package/consumers/codex-current-memory.js +10 -6
- package/consumers/codex.js +5 -2
- package/consumers/default/daily-entries.js +2 -2
- package/consumers/default/index.js +40 -30
- package/consumers/default/prompts/summary.js +2 -2
- package/consumers/mcp.js +56 -49
- package/consumers/openclaw-ext/index.js +1 -1
- package/consumers/openclaw-ext/openclaw.plugin.json +1 -1
- package/consumers/openclaw-ext/package.json +1 -1
- package/consumers/openclaw-plugin.js +66 -23
- package/consumers/shared/compat-recall.js +101 -0
- package/consumers/shared/openclaw-product-tools.js +130 -0
- package/consumers/shared/recall-format.js +2 -2
- package/core/aquifer.js +385 -20
- package/core/backends/local.js +60 -1
- package/core/finalization-review.js +88 -42
- package/core/interface.js +629 -0
- package/core/mcp-manifest.js +11 -3
- package/core/memory-bootstrap.js +25 -27
- package/core/memory-consolidation.js +564 -42
- package/core/memory-explain.js +20 -51
- package/core/memory-promotion.js +392 -55
- package/core/memory-recall.js +26 -48
- package/core/memory-records.js +91 -103
- package/core/memory-type-policy.js +298 -0
- package/core/postgres-migrations.js +9 -0
- package/core/session-checkpoint-producer.js +3 -1
- package/core/session-checkpoints.js +1 -1
- package/core/session-finalization.js +2 -2
- package/docs/getting-started.md +16 -3
- package/docs/setup.md +61 -2
- package/package.json +2 -2
- package/schema/004-completion.sql +4 -4
- package/schema/010-v1-finalization-review.sql +72 -0
- package/schema/020-v1-assistant-shaping-memory.sql +30 -0
- package/scripts/backfill-canonical-key.js +1 -1
- package/scripts/diagnose-fts-zh.js +1 -1
- package/scripts/extract-insights-from-recent-sessions.js +4 -4
|
@@ -1,40 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
entity_note: '註記',
|
|
10
|
-
open_loop: '未完成',
|
|
11
|
-
conclusion: '判斷',
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const SESSION_START_TYPE_PRIORITY = {
|
|
15
|
-
state: 0,
|
|
16
|
-
open_loop: 1,
|
|
17
|
-
constraint: 2,
|
|
18
|
-
preference: 3,
|
|
19
|
-
decision: 4,
|
|
20
|
-
fact: 5,
|
|
21
|
-
conclusion: 6,
|
|
22
|
-
entity_note: 7,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const AUTHORITY_PRIORITY = {
|
|
26
|
-
user_explicit: 0,
|
|
27
|
-
executable_evidence: 1,
|
|
28
|
-
manual: 2,
|
|
29
|
-
system: 3,
|
|
30
|
-
verified_summary: 4,
|
|
31
|
-
llm_inference: 5,
|
|
32
|
-
raw_transcript: 6,
|
|
33
|
-
};
|
|
3
|
+
const {
|
|
4
|
+
assistantShapingMetadata,
|
|
5
|
+
authoritySortPriority,
|
|
6
|
+
memoryTypeBootstrapPriority,
|
|
7
|
+
memoryTypeLabel,
|
|
8
|
+
} = require('./memory-type-policy');
|
|
34
9
|
|
|
35
10
|
const MEMORY_KEYS = [
|
|
36
11
|
'summary',
|
|
37
12
|
'title',
|
|
13
|
+
'guidance',
|
|
14
|
+
'policy',
|
|
15
|
+
'boundary',
|
|
16
|
+
'rule',
|
|
38
17
|
'decision',
|
|
39
18
|
'item',
|
|
40
19
|
'conclusion',
|
|
@@ -49,13 +28,15 @@ const MEMORY_KEYS = [
|
|
|
49
28
|
];
|
|
50
29
|
|
|
51
30
|
const STRUCTURED_FIELDS = [
|
|
31
|
+
['assistant_shaping', 'assistant_shaping'],
|
|
32
|
+
['assistant_shaping_memories', 'assistant_shaping'],
|
|
33
|
+
['constraints', 'constraint'],
|
|
52
34
|
['states', 'state'],
|
|
53
35
|
['state', 'state'],
|
|
54
36
|
['decisions', 'decision'],
|
|
37
|
+
['preferences', 'preference'],
|
|
55
38
|
['important_facts', 'fact'],
|
|
56
39
|
['facts', 'fact'],
|
|
57
|
-
['preferences', 'preference'],
|
|
58
|
-
['constraints', 'constraint'],
|
|
59
40
|
['conclusions', 'conclusion'],
|
|
60
41
|
['entity_notes', 'entity_note'],
|
|
61
42
|
['open_loops', 'open_loop'],
|
|
@@ -105,7 +86,7 @@ function memoryTypeOf(value) {
|
|
|
105
86
|
}
|
|
106
87
|
|
|
107
88
|
function labelFor(type) {
|
|
108
|
-
return
|
|
89
|
+
return memoryTypeLabel(type);
|
|
109
90
|
}
|
|
110
91
|
|
|
111
92
|
function pushUnique(out, text) {
|
|
@@ -122,6 +103,43 @@ function asLine(type, text, suffix = '') {
|
|
|
122
103
|
return `${labelFor(type)}:${body}${suffix}`;
|
|
123
104
|
}
|
|
124
105
|
|
|
106
|
+
function shapingSuffix(type, value = {}) {
|
|
107
|
+
if (String(type || '').toLowerCase() !== 'assistant_shaping') return '';
|
|
108
|
+
const metadata = assistantShapingMetadata(value);
|
|
109
|
+
if (metadata.length === 0) return '';
|
|
110
|
+
return `(${metadata.map(([key, text]) => `${key}: ${text}`).join(',')})`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function reviewTypePriority(type) {
|
|
114
|
+
return memoryTypeBootstrapPriority(type);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function reviewAuthorityPriority(authority) {
|
|
118
|
+
return authoritySortPriority(authority);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function reviewAcceptedAt(value) {
|
|
122
|
+
return Date.parse(value || '') || 0;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function sortReviewEntries(entries = []) {
|
|
126
|
+
return entries.slice().sort((left, right) => {
|
|
127
|
+
const leftType = reviewTypePriority(left.type);
|
|
128
|
+
const rightType = reviewTypePriority(right.type);
|
|
129
|
+
if (leftType !== rightType) return leftType - rightType;
|
|
130
|
+
|
|
131
|
+
const leftAuthority = reviewAuthorityPriority(left.authority);
|
|
132
|
+
const rightAuthority = reviewAuthorityPriority(right.authority);
|
|
133
|
+
if (leftAuthority !== rightAuthority) return leftAuthority - rightAuthority;
|
|
134
|
+
|
|
135
|
+
const leftAcceptedAt = reviewAcceptedAt(left.acceptedAt);
|
|
136
|
+
const rightAcceptedAt = reviewAcceptedAt(right.acceptedAt);
|
|
137
|
+
if (leftAcceptedAt !== rightAcceptedAt) return rightAcceptedAt - leftAcceptedAt;
|
|
138
|
+
|
|
139
|
+
return (left.index ?? 0) - (right.index ?? 0);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
125
143
|
function truncate(text, max = 220) {
|
|
126
144
|
const normalized = sanitizeHumanText(text);
|
|
127
145
|
if (normalized.length <= max) return normalized;
|
|
@@ -129,6 +147,8 @@ function truncate(text, max = 220) {
|
|
|
129
147
|
}
|
|
130
148
|
|
|
131
149
|
function addStructuredItems(out, structuredSummary = {}, filter = null) {
|
|
150
|
+
const entries = [];
|
|
151
|
+
let index = 0;
|
|
132
152
|
for (const [field, type] of STRUCTURED_FIELDS) {
|
|
133
153
|
if (filter && !filter(type)) continue;
|
|
134
154
|
const items = Array.isArray(structuredSummary[field]) ? structuredSummary[field] : [];
|
|
@@ -138,19 +158,45 @@ function addStructuredItems(out, structuredSummary = {}, filter = null) {
|
|
|
138
158
|
const owner = type === 'open_loop' && item && typeof item === 'object' && normalizeText(item.owner)
|
|
139
159
|
? `(owner: ${normalizeText(item.owner)})`
|
|
140
160
|
: '';
|
|
141
|
-
|
|
161
|
+
entries.push({
|
|
162
|
+
type,
|
|
163
|
+
text,
|
|
164
|
+
suffix: owner || shapingSuffix(type, item),
|
|
165
|
+
authority: item && typeof item === 'object' ? (item.authority || item.payload?.authority) : null,
|
|
166
|
+
acceptedAt: item && typeof item === 'object'
|
|
167
|
+
? (item.acceptedAt || item.accepted_at || item.payload?.acceptedAt || item.payload?.accepted_at)
|
|
168
|
+
: null,
|
|
169
|
+
index: index++,
|
|
170
|
+
});
|
|
142
171
|
}
|
|
143
172
|
}
|
|
173
|
+
for (const entry of sortReviewEntries(entries)) {
|
|
174
|
+
pushUnique(out, asLine(entry.type, entry.text, entry.suffix));
|
|
175
|
+
}
|
|
144
176
|
}
|
|
145
177
|
|
|
146
178
|
function promotedMemoryLines(memoryResults = []) {
|
|
147
|
-
const
|
|
179
|
+
const entries = [];
|
|
180
|
+
let index = 0;
|
|
148
181
|
for (const result of memoryResults || []) {
|
|
149
182
|
if (!result || result.action !== 'promote') continue;
|
|
150
183
|
const memory = result.memory || result.record || result.candidate || {};
|
|
151
184
|
const type = memoryTypeOf(memory);
|
|
152
185
|
if (type === 'open_loop') continue;
|
|
153
|
-
|
|
186
|
+
const text = firstText(memory);
|
|
187
|
+
if (!text) continue;
|
|
188
|
+
entries.push({
|
|
189
|
+
type,
|
|
190
|
+
text,
|
|
191
|
+
suffix: shapingSuffix(type, memory),
|
|
192
|
+
authority: memory.authority,
|
|
193
|
+
acceptedAt: memory.acceptedAt || memory.accepted_at,
|
|
194
|
+
index: index++,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
const lines = [];
|
|
198
|
+
for (const entry of sortReviewEntries(entries)) {
|
|
199
|
+
pushUnique(lines, asLine(entry.type, entry.text, entry.suffix));
|
|
154
200
|
}
|
|
155
201
|
return lines;
|
|
156
202
|
}
|
|
@@ -285,12 +331,12 @@ function buildSessionStartContext(records = [], opts = {}) {
|
|
|
285
331
|
}
|
|
286
332
|
|
|
287
333
|
active.sort((a, b) => {
|
|
288
|
-
const aType =
|
|
289
|
-
const bType =
|
|
334
|
+
const aType = memoryTypeBootstrapPriority(memoryTypeOf(a.record));
|
|
335
|
+
const bType = memoryTypeBootstrapPriority(memoryTypeOf(b.record));
|
|
290
336
|
if (aType !== bType) return aType - bType;
|
|
291
337
|
|
|
292
|
-
const aAuth =
|
|
293
|
-
const bAuth =
|
|
338
|
+
const aAuth = authoritySortPriority(a.record.authority);
|
|
339
|
+
const bAuth = authoritySortPriority(b.record.authority);
|
|
294
340
|
if (aAuth !== bAuth) return aAuth - bAuth;
|
|
295
341
|
|
|
296
342
|
const aAccepted = Date.parse(a.record.acceptedAt || a.record.accepted_at || '') || 0;
|
|
@@ -302,7 +348,7 @@ function buildSessionStartContext(records = [], opts = {}) {
|
|
|
302
348
|
const lines = [];
|
|
303
349
|
for (const { record } of active.slice(0, limit)) {
|
|
304
350
|
const type = memoryTypeOf(record);
|
|
305
|
-
pushUnique(lines, asLine(type, firstText(record)));
|
|
351
|
+
pushUnique(lines, asLine(type, firstText(record), shapingSuffix(type, record)));
|
|
306
352
|
}
|
|
307
353
|
let selected = lines;
|
|
308
354
|
let text = `下一段只需要帶:\n${linesOrNone(selected)}\n`;
|