@shadowforge0/aquifer-memory 1.5.12 → 1.6.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/.env.example +23 -0
- package/README.md +78 -73
- package/README_CN.md +659 -0
- package/README_TW.md +680 -0
- package/aquifer.config.example.json +34 -0
- package/consumers/claude-code.js +11 -11
- package/consumers/cli.js +353 -52
- package/consumers/codex-handoff.js +152 -0
- package/consumers/codex.js +1549 -0
- package/consumers/default/daily-entries.js +23 -4
- package/consumers/default/index.js +2 -2
- package/consumers/default/prompts/summary.js +6 -6
- package/consumers/mcp.js +96 -5
- package/consumers/openclaw-ext/index.js +0 -1
- package/consumers/openclaw-plugin.js +1 -1
- package/consumers/shared/config.js +8 -0
- package/consumers/shared/factory.js +1 -0
- package/consumers/shared/ingest.js +1 -1
- package/consumers/shared/normalize.js +14 -3
- package/consumers/shared/recall-format.js +27 -0
- package/consumers/shared/summary-parser.js +151 -0
- package/core/aquifer.js +372 -18
- package/core/finalization-review.js +319 -0
- package/core/mcp-manifest.js +52 -2
- package/core/memory-bootstrap.js +188 -0
- package/core/memory-consolidation.js +1236 -0
- package/core/memory-promotion.js +544 -0
- package/core/memory-recall.js +247 -0
- package/core/memory-records.js +581 -0
- package/core/memory-safety-gate.js +224 -0
- package/core/session-finalization.js +350 -0
- package/core/storage.js +385 -2
- package/docs/getting-started.md +99 -0
- package/docs/postprocess-contract.md +2 -2
- package/docs/setup.md +51 -2
- package/package.json +25 -11
- package/pipeline/normalize/adapters/codex.js +106 -0
- package/pipeline/normalize/detect.js +3 -2
- package/schema/001-base.sql +3 -0
- package/schema/007-v1-foundation.sql +273 -0
- package/schema/008-session-finalizations.sql +50 -0
- package/schema/009-v1-assertion-plane.sql +193 -0
- package/schema/010-v1-finalization-review.sql +160 -0
- package/schema/011-v1-compaction-claim.sql +46 -0
- package/schema/012-v1-compaction-lease.sql +39 -0
- package/schema/013-v1-compaction-lineage.sql +193 -0
- package/scripts/codex-recovery.js +532 -0
- package/consumers/miranda/context-inject.js +0 -120
- package/consumers/miranda/daily-entries.js +0 -224
- package/consumers/miranda/index.js +0 -364
- package/consumers/miranda/instance.js +0 -55
- package/consumers/miranda/llm.js +0 -99
- package/consumers/miranda/profile.json +0 -145
- package/consumers/miranda/prompts/summary.js +0 -303
- package/consumers/miranda/recall-format.js +0 -76
- package/consumers/miranda/render-daily-md.js +0 -186
- package/consumers/miranda/workspace-files.js +0 -91
- package/scripts/drop-entity-state-history.sql +0 -17
- package/scripts/drop-insights.sql +0 -12
- package/scripts/install-openclaw.sh +0 -59
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { finalizeTranscriptView } = require('./codex');
|
|
4
|
+
const { buildFinalizationReview } = require('../core/finalization-review');
|
|
5
|
+
|
|
6
|
+
function normalizeText(value) {
|
|
7
|
+
return String(value || '').trim().replace(/\s+/g, ' ');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function normalizeList(value) {
|
|
11
|
+
return Array.isArray(value) ? value.filter(Boolean) : [];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function comparableText(value) {
|
|
15
|
+
return normalizeText(value).replace(/[。.!?!?]+$/g, '').toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function addUniqueByText(out, item, text) {
|
|
19
|
+
const key = comparableText(text);
|
|
20
|
+
if (!key) return;
|
|
21
|
+
if (out.some(existing => comparableText(existing.item || existing.decision || existing.conclusion || existing.note || existing.summary) === key)) return;
|
|
22
|
+
out.push(item);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function normalizeDecision(item) {
|
|
26
|
+
if (typeof item === 'string') {
|
|
27
|
+
const decision = normalizeText(item);
|
|
28
|
+
return decision ? { decision } : null;
|
|
29
|
+
}
|
|
30
|
+
const decision = normalizeText(item && (item.decision || item.summary || item.text));
|
|
31
|
+
if (!decision) return null;
|
|
32
|
+
const reason = normalizeText(item && item.reason);
|
|
33
|
+
return reason ? { decision, reason } : { decision };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function normalizeOpenLoop(item) {
|
|
37
|
+
if (typeof item === 'string') {
|
|
38
|
+
const text = normalizeText(item);
|
|
39
|
+
return text ? { item: text, owner: 'unknown' } : null;
|
|
40
|
+
}
|
|
41
|
+
const text = normalizeText(item && (item.item || item.summary || item.text));
|
|
42
|
+
if (!text || ['none', 'n/a', 'na', 'done', '無'].includes(text.toLowerCase())) return null;
|
|
43
|
+
return {
|
|
44
|
+
item: text,
|
|
45
|
+
owner: normalizeText(item && item.owner) || 'unknown',
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function buildHandoffMetadata(payload = {}) {
|
|
50
|
+
const title = normalizeText(payload.title);
|
|
51
|
+
const overview = normalizeText(payload.overview);
|
|
52
|
+
const lastStep = normalizeText(payload.lastStep || payload.last_step);
|
|
53
|
+
const next = normalizeText(payload.next);
|
|
54
|
+
const handoffText = normalizeText(payload.handoffText || payload.handoff_text);
|
|
55
|
+
const decisions = [];
|
|
56
|
+
const openLoops = [];
|
|
57
|
+
|
|
58
|
+
for (const item of normalizeList(payload.decisions)) {
|
|
59
|
+
const decision = normalizeDecision(item);
|
|
60
|
+
if (decision) addUniqueByText(decisions, decision, decision.decision);
|
|
61
|
+
}
|
|
62
|
+
for (const item of normalizeList(payload.decided)) {
|
|
63
|
+
const decision = normalizeDecision(item);
|
|
64
|
+
if (decision) addUniqueByText(decisions, decision, decision.decision);
|
|
65
|
+
}
|
|
66
|
+
if (next && next !== '無') {
|
|
67
|
+
addUniqueByText(openLoops, { item: next, owner: 'unknown', source: 'handoff_next' }, next);
|
|
68
|
+
}
|
|
69
|
+
for (const item of normalizeList(payload.openLoops || payload.open_loops)) {
|
|
70
|
+
const loop = normalizeOpenLoop(item);
|
|
71
|
+
if (loop) addUniqueByText(openLoops, loop, loop.item);
|
|
72
|
+
}
|
|
73
|
+
for (const item of normalizeList(payload.todoNew || payload.todo_new)) {
|
|
74
|
+
const loop = normalizeOpenLoop({ item, owner: 'unknown' });
|
|
75
|
+
if (loop) addUniqueByText(openLoops, { ...loop, source: 'todo_new' }, loop.item);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
source: 'codex_handoff',
|
|
80
|
+
handoff: {
|
|
81
|
+
title,
|
|
82
|
+
overview,
|
|
83
|
+
status: normalizeText(payload.status),
|
|
84
|
+
stopReason: normalizeText(payload.stopReason || payload.stop_reason),
|
|
85
|
+
lastStep,
|
|
86
|
+
next,
|
|
87
|
+
handoffText,
|
|
88
|
+
topics: normalizeList(payload.topics),
|
|
89
|
+
decisions,
|
|
90
|
+
openLoops,
|
|
91
|
+
focus: normalizeList(payload.focus).map(normalizeText).filter(Boolean),
|
|
92
|
+
todoNew: normalizeList(payload.todoNew || payload.todo_new).map(normalizeText).filter(Boolean),
|
|
93
|
+
todoDone: normalizeList(payload.todoDone || payload.todo_done).map(normalizeText).filter(Boolean),
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function finalizeHandoff(aquifer, payload = {}, opts = {}) {
|
|
99
|
+
const view = opts.view || payload.view;
|
|
100
|
+
if (!view || view.status !== 'ok') {
|
|
101
|
+
throw new Error(`Codex handoff finalization requires an ok normalized transcript view; got ${view && view.status ? view.status : 'missing'}`);
|
|
102
|
+
}
|
|
103
|
+
const summary = opts.summary || payload.summary || {
|
|
104
|
+
summaryText: opts.summaryText || payload.summaryText,
|
|
105
|
+
structuredSummary: opts.structuredSummary || payload.structuredSummary,
|
|
106
|
+
};
|
|
107
|
+
const metadata = {
|
|
108
|
+
...buildHandoffMetadata(payload),
|
|
109
|
+
...(opts.metadata || {}),
|
|
110
|
+
};
|
|
111
|
+
const result = await finalizeTranscriptView(aquifer, view, summary, {
|
|
112
|
+
...opts,
|
|
113
|
+
mode: 'handoff',
|
|
114
|
+
metadataSource: 'codex_handoff',
|
|
115
|
+
metadata,
|
|
116
|
+
authority: opts.authority || 'manual',
|
|
117
|
+
});
|
|
118
|
+
const coreResult = result.finalization || {};
|
|
119
|
+
const finalSummary = coreResult.summary || {
|
|
120
|
+
summaryText: summary.summaryText,
|
|
121
|
+
structuredSummary: summary.structuredSummary || {},
|
|
122
|
+
};
|
|
123
|
+
const memoryResult = coreResult.memoryResult || result.memoryResult || {};
|
|
124
|
+
const memoryResults = coreResult.memoryResults || result.memoryResults || [];
|
|
125
|
+
const reviewText = coreResult.humanReviewText || result.humanReviewText || buildFinalizationReview({
|
|
126
|
+
summary: finalSummary,
|
|
127
|
+
memoryResult,
|
|
128
|
+
memoryResults,
|
|
129
|
+
title: payload.title,
|
|
130
|
+
overview: payload.overview,
|
|
131
|
+
next: payload.next,
|
|
132
|
+
sessionId: view.sessionId,
|
|
133
|
+
transcriptHash: view.transcriptHash,
|
|
134
|
+
finalization: coreResult.finalization || result.finalization,
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
...result,
|
|
138
|
+
finalization: coreResult.finalization || result.finalization,
|
|
139
|
+
memoryResult,
|
|
140
|
+
memoryResults,
|
|
141
|
+
summary: finalSummary || result.summary || null,
|
|
142
|
+
reviewText,
|
|
143
|
+
humanReviewText: reviewText,
|
|
144
|
+
sessionStartText: coreResult.sessionStartText || result.sessionStartText || '',
|
|
145
|
+
structuredSummary: finalSummary.structuredSummary || {},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
module.exports = {
|
|
150
|
+
buildHandoffMetadata,
|
|
151
|
+
finalizeHandoff,
|
|
152
|
+
};
|