@shadowforge0/aquifer-memory 1.5.9 → 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.
Files changed (65) hide show
  1. package/.env.example +23 -0
  2. package/README.md +96 -73
  3. package/README_CN.md +659 -0
  4. package/README_TW.md +680 -0
  5. package/aquifer.config.example.json +34 -0
  6. package/consumers/claude-code.js +11 -11
  7. package/consumers/cli.js +374 -39
  8. package/consumers/codex-handoff.js +152 -0
  9. package/consumers/codex.js +1549 -0
  10. package/consumers/default/daily-entries.js +23 -4
  11. package/consumers/default/index.js +2 -2
  12. package/consumers/default/prompts/summary.js +6 -6
  13. package/consumers/mcp.js +131 -7
  14. package/consumers/openclaw-ext/index.js +0 -1
  15. package/consumers/openclaw-plugin.js +44 -4
  16. package/consumers/shared/config.js +28 -0
  17. package/consumers/shared/factory.js +2 -0
  18. package/consumers/shared/ingest.js +1 -1
  19. package/consumers/shared/normalize.js +14 -3
  20. package/consumers/shared/recall-format.js +53 -0
  21. package/consumers/shared/summary-parser.js +151 -0
  22. package/core/aquifer.js +384 -18
  23. package/core/finalization-review.js +319 -0
  24. package/core/insights.js +210 -58
  25. package/core/mcp-manifest.js +69 -2
  26. package/core/memory-bootstrap.js +188 -0
  27. package/core/memory-consolidation.js +1236 -0
  28. package/core/memory-promotion.js +544 -0
  29. package/core/memory-recall.js +247 -0
  30. package/core/memory-records.js +581 -0
  31. package/core/memory-safety-gate.js +224 -0
  32. package/core/session-finalization.js +350 -0
  33. package/core/storage.js +456 -2
  34. package/docs/getting-started.md +99 -0
  35. package/docs/postprocess-contract.md +2 -2
  36. package/docs/setup.md +51 -2
  37. package/package.json +31 -9
  38. package/pipeline/normalize/adapters/codex.js +106 -0
  39. package/pipeline/normalize/detect.js +3 -2
  40. package/schema/001-base.sql +3 -0
  41. package/schema/007-v1-foundation.sql +273 -0
  42. package/schema/008-session-finalizations.sql +50 -0
  43. package/schema/009-v1-assertion-plane.sql +193 -0
  44. package/schema/010-v1-finalization-review.sql +160 -0
  45. package/schema/011-v1-compaction-claim.sql +46 -0
  46. package/schema/012-v1-compaction-lease.sql +39 -0
  47. package/schema/013-v1-compaction-lineage.sql +193 -0
  48. package/scripts/backfill-canonical-key.js +250 -0
  49. package/scripts/codex-recovery.js +532 -0
  50. package/consumers/miranda/context-inject.js +0 -119
  51. package/consumers/miranda/daily-entries.js +0 -224
  52. package/consumers/miranda/index.js +0 -364
  53. package/consumers/miranda/instance.js +0 -55
  54. package/consumers/miranda/llm.js +0 -99
  55. package/consumers/miranda/profile.json +0 -145
  56. package/consumers/miranda/prompts/summary.js +0 -303
  57. package/consumers/miranda/recall-format.js +0 -76
  58. package/consumers/miranda/render-daily-md.js +0 -186
  59. package/consumers/miranda/workspace-files.js +0 -91
  60. package/scripts/drop-entity-state-history.sql +0 -17
  61. package/scripts/drop-insights.sql +0 -12
  62. package/scripts/install-openclaw.sh +0 -59
  63. package/scripts/queries.json +0 -45
  64. package/scripts/retro-recall-bench.js +0 -409
  65. package/scripts/sample-bench-queries.sql +0 -75
@@ -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
+ };