@shadowforge0/aquifer-memory 1.8.1 → 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.
Files changed (57) hide show
  1. package/.env.example +1 -0
  2. package/README.md +82 -26
  3. package/README_CN.md +33 -23
  4. package/README_TW.md +25 -24
  5. package/aquifer.config.example.json +2 -1
  6. package/consumers/cli.js +587 -33
  7. package/consumers/codex-active-checkpoint.js +3 -1
  8. package/consumers/codex-current-memory.js +10 -6
  9. package/consumers/codex.js +6 -3
  10. package/consumers/default/daily-entries.js +2 -2
  11. package/consumers/default/index.js +40 -30
  12. package/consumers/default/prompts/summary.js +2 -2
  13. package/consumers/mcp.js +56 -46
  14. package/consumers/openclaw-ext/index.js +65 -7
  15. package/consumers/openclaw-ext/openclaw.plugin.json +1 -1
  16. package/consumers/openclaw-ext/package.json +1 -1
  17. package/consumers/openclaw-install.js +326 -0
  18. package/consumers/openclaw-plugin.js +105 -24
  19. package/consumers/shared/compat-recall.js +101 -0
  20. package/consumers/shared/config.js +2 -0
  21. package/consumers/shared/openclaw-product-tools.js +130 -0
  22. package/consumers/shared/recall-format.js +2 -2
  23. package/core/aquifer.js +553 -41
  24. package/core/backends/local.js +169 -1
  25. package/core/doctor.js +924 -0
  26. package/core/finalization-inspector.js +164 -0
  27. package/core/finalization-review.js +88 -42
  28. package/core/interface.js +629 -0
  29. package/core/mcp-manifest.js +11 -3
  30. package/core/memory-bootstrap.js +25 -27
  31. package/core/memory-consolidation.js +564 -42
  32. package/core/memory-explain.js +593 -0
  33. package/core/memory-promotion.js +392 -55
  34. package/core/memory-recall.js +75 -71
  35. package/core/memory-records.js +107 -108
  36. package/core/memory-review.js +891 -0
  37. package/core/memory-serving.js +61 -4
  38. package/core/memory-type-policy.js +298 -0
  39. package/core/operator-observability.js +249 -0
  40. package/core/postgres-migrations.js +22 -0
  41. package/core/session-checkpoint-producer.js +3 -1
  42. package/core/session-checkpoints.js +1 -1
  43. package/core/session-finalization.js +78 -3
  44. package/core/storage.js +124 -8
  45. package/docs/getting-started.md +50 -4
  46. package/docs/setup.md +163 -24
  47. package/package.json +5 -4
  48. package/schema/004-completion.sql +4 -4
  49. package/schema/010-v1-finalization-review.sql +72 -0
  50. package/schema/019-v1-memory-review-resolutions.sql +53 -0
  51. package/schema/020-v1-assistant-shaping-memory.sql +30 -0
  52. package/scripts/backfill-canonical-key.js +1 -1
  53. package/scripts/codex-checkpoint-commands.js +28 -0
  54. package/scripts/codex-checkpoint-runtime.js +109 -0
  55. package/scripts/codex-recovery.js +16 -4
  56. package/scripts/diagnose-fts-zh.js +1 -1
  57. package/scripts/extract-insights-from-recent-sessions.js +4 -4
@@ -1,25 +1,11 @@
1
1
  'use strict';
2
2
 
3
- const TYPE_PRIORITY = {
4
- constraint: 0,
5
- state: 1,
6
- open_loop: 2,
7
- decision: 3,
8
- preference: 4,
9
- fact: 5,
10
- conclusion: 6,
11
- entity_note: 7,
12
- };
13
-
14
- const AUTHORITY_PRIORITY = {
15
- user_explicit: 0,
16
- executable_evidence: 1,
17
- manual: 2,
18
- system: 3,
19
- verified_summary: 4,
20
- llm_inference: 5,
21
- raw_transcript: 6,
22
- };
3
+ const {
4
+ authoritySortPriority,
5
+ formatRuntimeMemoryLine,
6
+ memoryTypeBootstrapPriority,
7
+ memoryTypeRuntimeContract,
8
+ } = require('./memory-type-policy');
23
9
 
24
10
  function recordId(record) {
25
11
  return String(record.memoryId || record.memory_id || record.id || record.canonicalKey || record.canonical_key);
@@ -42,6 +28,11 @@ function parseTime(value) {
42
28
  return Number.isFinite(t) ? t : null;
43
29
  }
44
30
 
31
+ function numericValue(value) {
32
+ const parsed = Number(value);
33
+ return Number.isFinite(parsed) ? parsed : 0;
34
+ }
35
+
45
36
  function isWithinTime(record, asOf) {
46
37
  if (!asOf) return true;
47
38
  const at = Date.parse(asOf);
@@ -97,20 +88,28 @@ function resolveApplicableRecords(records = [], opts = {}) {
97
88
  }
98
89
 
99
90
  function sortForBootstrap(a, b, opts = {}) {
91
+ const aRuntimeContract = memoryTypeRuntimeContract(a.memoryType || a.memory_type);
92
+ const bRuntimeContract = memoryTypeRuntimeContract(b.memoryType || b.memory_type);
93
+ if (aRuntimeContract !== bRuntimeContract) return aRuntimeContract ? -1 : 1;
94
+
100
95
  const activeScopePath = opts.activeScopePath || (opts.activeScopeKey ? [opts.activeScopeKey] : ['global']);
101
96
  const position = new Map(activeScopePath.map((key, idx) => [key, idx]));
102
97
  const aScope = position.get(scopeKey(a)) ?? -1;
103
98
  const bScope = position.get(scopeKey(b)) ?? -1;
104
99
  if (bScope !== aScope) return bScope - aScope;
105
100
 
106
- const aType = TYPE_PRIORITY[a.memoryType || a.memory_type] ?? 99;
107
- const bType = TYPE_PRIORITY[b.memoryType || b.memory_type] ?? 99;
101
+ const aType = memoryTypeBootstrapPriority(a.memoryType || a.memory_type);
102
+ const bType = memoryTypeBootstrapPriority(b.memoryType || b.memory_type);
108
103
  if (aType !== bType) return aType - bType;
109
104
 
110
- const aAuth = AUTHORITY_PRIORITY[a.authority] ?? 99;
111
- const bAuth = AUTHORITY_PRIORITY[b.authority] ?? 99;
105
+ const aAuth = authoritySortPriority(a.authority);
106
+ const bAuth = authoritySortPriority(b.authority);
112
107
  if (aAuth !== bAuth) return aAuth - bAuth;
113
108
 
109
+ const aFeedback = numericValue(a.feedbackScore ?? a.feedback_score);
110
+ const bFeedback = numericValue(b.feedbackScore ?? b.feedback_score);
111
+ if (aFeedback !== bFeedback) return bFeedback - aFeedback;
112
+
114
113
  const aAccepted = Date.parse(a.acceptedAt || a.accepted_at || '') || 0;
115
114
  const bAccepted = Date.parse(b.acceptedAt || b.accepted_at || '') || 0;
116
115
  if (aAccepted !== bAccepted) return bAccepted - aAccepted;
@@ -119,9 +118,7 @@ function sortForBootstrap(a, b, opts = {}) {
119
118
  }
120
119
 
121
120
  function lineFor(record) {
122
- const type = record.memoryType || record.memory_type || 'memory';
123
- const text = record.summary || record.title || '';
124
- return `- ${type}: ${String(text).trim()}`;
121
+ return formatRuntimeMemoryLine(record);
125
122
  }
126
123
 
127
124
  function buildText(records, meta) {
@@ -184,6 +181,7 @@ function createMemoryBootstrap({ records }) {
184
181
  scopeId: opts.scopeId,
185
182
  scopeKeys: opts.activeScopePath || (opts.activeScopeKey ? [opts.activeScopeKey] : undefined),
186
183
  visibleInBootstrap: true,
184
+ includeFeedbackScore: true,
187
185
  asOf: opts.asOf,
188
186
  limit: Math.max(50, Math.min(200, requestedLimit * 4)),
189
187
  });