@unblocklabs/unblock-memory 0.12.3 → 0.14.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 (138) hide show
  1. package/README.md +19 -18
  2. package/defaults.json +162 -0
  3. package/dist/src/analysis.js +1 -1
  4. package/dist/src/cluster-review.d.ts +2 -0
  5. package/dist/src/cluster-review.js +9 -8
  6. package/dist/src/config.d.ts +9 -6
  7. package/dist/src/config.js +59 -45
  8. package/dist/src/curation.d.ts +1 -1
  9. package/dist/src/decision-client.d.ts +45 -0
  10. package/dist/src/decision-client.js +87 -0
  11. package/dist/src/{typesafe.d.ts → decision-ranking.d.ts} +15 -18
  12. package/dist/src/decision-ranking.js +155 -0
  13. package/dist/src/{typesafe-review.d.ts → decision-review.d.ts} +13 -9
  14. package/dist/src/decision-review.js +193 -0
  15. package/dist/src/defaults.d.ts +8 -0
  16. package/dist/src/defaults.js +128 -0
  17. package/dist/src/diagnostics.d.ts +5 -5
  18. package/dist/src/emotion-baselines.d.ts +28 -3
  19. package/dist/src/emotion-baselines.js +312 -115
  20. package/dist/src/evidence-review.d.ts +22 -8
  21. package/dist/src/evidence-review.js +11 -8
  22. package/dist/src/extraction-chunk.d.ts +3 -0
  23. package/dist/src/extraction-chunk.js +25 -6
  24. package/dist/src/extraction-config.js +4 -2
  25. package/dist/src/extraction-model.d.ts +25 -17
  26. package/dist/src/extraction-model.js +232 -104
  27. package/dist/src/extraction-runtime.d.ts +3 -1
  28. package/dist/src/extraction-runtime.js +48 -20
  29. package/dist/src/extraction-source.d.ts +1 -1
  30. package/dist/src/extraction-source.js +21 -12
  31. package/dist/src/extraction-store.d.ts +29 -3
  32. package/dist/src/extraction-store.js +149 -25
  33. package/dist/src/extraction-worker.d.ts +3 -3
  34. package/dist/src/extraction-worker.js +250 -95
  35. package/dist/src/inside-out-runtime.js +43 -30
  36. package/dist/src/inside-out-sources.js +2 -1
  37. package/dist/src/inside-out-store.d.ts +2 -2
  38. package/dist/src/inside-out-store.js +111 -69
  39. package/dist/src/inside-out.d.ts +10 -9
  40. package/dist/src/inside-out.js +194 -106
  41. package/dist/src/manager.d.ts +22 -9
  42. package/dist/src/manager.js +279 -172
  43. package/dist/src/memory-database.js +3 -2
  44. package/dist/src/memory-passage.d.ts +2 -2
  45. package/dist/src/memory-passage.js +3 -2
  46. package/dist/src/memory-search.d.ts +4 -2
  47. package/dist/src/memory-search.js +5 -5
  48. package/dist/src/memory-whisperer.d.ts +1 -1
  49. package/dist/src/memory-whisperer.js +195 -129
  50. package/dist/src/my-turn.d.ts +1 -1
  51. package/dist/src/my-turn.js +90 -70
  52. package/dist/src/people-background.d.ts +5 -1
  53. package/dist/src/people-background.js +31 -7
  54. package/dist/src/people-dossier-review.d.ts +20 -8
  55. package/dist/src/people-dossier-review.js +15 -11
  56. package/dist/src/people-hooks.js +127 -22
  57. package/dist/src/people-learning-cron.d.ts +1 -1
  58. package/dist/src/people-learning-cron.js +107 -57
  59. package/dist/src/people-learning-inventory.d.ts +1 -0
  60. package/dist/src/people-learning-inventory.js +283 -172
  61. package/dist/src/people-learning-prompt.js +1 -1
  62. package/dist/src/people-learning-runtime.d.ts +1 -1
  63. package/dist/src/people-learning-runtime.js +360 -203
  64. package/dist/src/people-learning-store.d.ts +27 -4
  65. package/dist/src/people-learning-store.js +312 -96
  66. package/dist/src/people-primer-tool.js +13 -10
  67. package/dist/src/people-primer.d.ts +3 -1
  68. package/dist/src/people-primer.js +66 -48
  69. package/dist/src/people-store.d.ts +18 -21
  70. package/dist/src/people-store.js +188 -64
  71. package/dist/src/people-tools.js +138 -93
  72. package/dist/src/plugin.js +19 -18
  73. package/dist/src/quality-audit.d.ts +2 -0
  74. package/dist/src/quality-audit.js +11 -9
  75. package/dist/src/quality-triage.js +4 -3
  76. package/dist/src/query-generator.js +5 -2
  77. package/dist/src/response-audit.d.ts +1 -1
  78. package/dist/src/response-audit.js +78 -44
  79. package/dist/src/response-config.js +3 -1
  80. package/dist/src/response-episodes.d.ts +1 -1
  81. package/dist/src/response-episodes.js +15 -19
  82. package/dist/src/response-identity.js +2 -1
  83. package/dist/src/response-judge.d.ts +151 -145
  84. package/dist/src/response-judge.js +535 -204
  85. package/dist/src/response-memory.js +2 -1
  86. package/dist/src/response-outcome.js +9 -8
  87. package/dist/src/response-reviews.d.ts +29 -1
  88. package/dist/src/response-reviews.js +113 -15
  89. package/dist/src/response-runtime.js +10 -9
  90. package/dist/src/response-stages.d.ts +50 -53
  91. package/dist/src/response-stages.js +10 -4
  92. package/dist/src/response-store.d.ts +7 -6
  93. package/dist/src/response-store.js +335 -212
  94. package/dist/src/review-tools.d.ts +8 -2
  95. package/dist/src/review-tools.js +22 -21
  96. package/dist/src/runtime.d.ts +7 -4
  97. package/dist/src/runtime.js +625 -98
  98. package/dist/src/safety-config.js +3 -2
  99. package/dist/src/safety-whisperer.d.ts +2 -2
  100. package/dist/src/safety-whisperer.js +90 -73
  101. package/dist/src/session-sync.d.ts +3 -1
  102. package/dist/src/session-sync.js +202 -96
  103. package/dist/src/skill-whisperer.d.ts +2 -2
  104. package/dist/src/skill-whisperer.js +55 -32
  105. package/dist/src/slack-directory.js +3 -2
  106. package/dist/src/training-gate.d.ts +9 -22
  107. package/dist/src/training-gate.js +34 -36
  108. package/dist/src/training-input.js +4 -3
  109. package/dist/src/training-judge.d.ts +9 -16
  110. package/dist/src/training-judge.js +6 -5
  111. package/dist/src/training-models.d.ts +1 -1
  112. package/dist/src/training-models.js +9 -7
  113. package/dist/src/training-queries.d.ts +14 -9
  114. package/dist/src/training-queries.js +374 -231
  115. package/dist/src/training-retrieval.d.ts +17 -27
  116. package/dist/src/training-retrieval.js +186 -139
  117. package/dist/src/training-runtime.d.ts +3 -0
  118. package/dist/src/training-runtime.js +76 -18
  119. package/dist/src/training-store.d.ts +18 -3
  120. package/dist/src/training-store.js +141 -52
  121. package/dist/src/training.js +9 -11
  122. package/dist/src/whisperer-context.d.ts +13 -0
  123. package/dist/src/whisperer-context.js +22 -1
  124. package/docs/configuration.md +83 -64
  125. package/docs/extraction.md +26 -35
  126. package/docs/memory-training.md +7 -6
  127. package/docs/people-learning.md +2 -2
  128. package/docs/peoplesql.md +6 -6
  129. package/docs/response-audit.md +10 -8
  130. package/docs/retrieval.md +43 -47
  131. package/openclaw.plugin.json +76 -75
  132. package/package.json +5 -2
  133. package/skills/memory-curator/SKILL.md +1 -1
  134. package/skills/people-whisperer/SKILL.md +1 -1
  135. package/dist/src/typesafe-client.d.ts +0 -30
  136. package/dist/src/typesafe-client.js +0 -92
  137. package/dist/src/typesafe-review.js +0 -154
  138. package/dist/src/typesafe.js +0 -147
@@ -1,3 +1,4 @@
1
+ import { DEFAULTS } from "./defaults.js";
1
2
  import { isDeepStrictEqual } from "node:util";
2
3
  import { listAgentIds } from "openclaw/plugin-sdk/agent-runtime";
3
4
  import { record, nonBlank } from "./guards.js";
@@ -14,83 +15,132 @@ function containsDeclaration(actual, expected) {
14
15
  return fields && source ? Object.entries(fields).every(([key, value]) => containsDeclaration(source[key], value))
15
16
  : isDeepStrictEqual(actual, expected);
16
17
  }
18
+ function parseDeclarationKey(value) {
19
+ if (typeof value !== "string" || !value.startsWith(PREFIX))
20
+ return undefined;
21
+ const rest = value.slice(PREFIX.length);
22
+ const split = rest.lastIndexOf(":");
23
+ if (split <= 0)
24
+ return undefined;
25
+ const agentId = rest.slice(0, split), kind = rest.slice(split + 1);
26
+ if (kind !== "nightly" && kind !== "weekly")
27
+ return undefined;
28
+ return { agentId, kind };
29
+ }
30
+ function matchesLearningJob(job, agentId, kind, key, legacyJobIds) {
31
+ if (job.agentId !== agentId)
32
+ return false;
33
+ if (job.declarationKey === key || job.name === key || job.name === legacyNames[kind])
34
+ return true;
35
+ if (!legacyJobIds?.includes(String(job.id)))
36
+ return false;
37
+ const payload = record(job.payload);
38
+ return payload?.kind === "agentTurn" &&
39
+ String(payload.message).includes(`people-${kind === "nightly" ? "nightly-dreaming" : "weekly-validation"}.md`);
40
+ }
17
41
  export const LEARNING_TOOLS = ["read", "memory_people_learning", "memory_people_inspect", "memory_people_update",
18
42
  "memory_people_prime", "memory_search", "memory_get"];
19
43
  /** Service-owned cron, not bundled-only scheduleSessionTurn.
20
44
  * Stable declarations make a lost add response/reload safe. Legacy history stays on disabled originals.
21
45
  */
22
- export async function reconcilePeopleLearning(cron, cfg, config, active = () => true) {
46
+ export async function reconcilePeopleLearning(cron, cfg, config, active = () => true, onRecognize) {
47
+ const all = await cron.list({ includeDisabled: true });
48
+ if (!Array.isArray(all))
49
+ throw new Error("Unsupported service cron.list response");
23
50
  const jobs = [];
24
- {
25
- const all = await cron.list({ includeDisabled: true });
26
- if (!Array.isArray(all))
27
- throw new Error("Unsupported service cron.list response");
28
- for (const item of all) {
29
- const job = record(item);
30
- if (!job || !nonBlank(job.id))
31
- throw new Error("Invalid cron job inventory");
32
- jobs.push(job);
51
+ const recognized = new Map();
52
+ for (const item of all) {
53
+ const job = record(item);
54
+ if (!job || !nonBlank(job.id))
55
+ throw new Error("Invalid cron job inventory");
56
+ jobs.push(job);
57
+ const parsed = parseDeclarationKey(job.declarationKey);
58
+ if (parsed && job.agentId === parsed.agentId) {
59
+ const id = String(job.id);
60
+ recognized.set(`${parsed.agentId}:${id}`, { id, agentId: parsed.agentId, kind: parsed.kind });
33
61
  }
34
62
  }
35
- const result = [], owned = new Set();
63
+ const planned = [];
36
64
  for (const agentId of listAgentIds(cfg)) {
37
65
  const options = learningForAgent(config, agentId);
38
66
  for (const kind of ["nightly", "weekly"]) {
39
67
  const key = `${PREFIX}${agentId}:${kind}`;
40
- const matches = jobs.filter(job => job.agentId === agentId && (job.declarationKey === key ||
41
- job.name === key || job.name === legacyNames[kind] ||
42
- (options.legacyJobIds?.includes(String(job.id)) && record(job.payload)?.kind === "agentTurn" &&
43
- String(record(job.payload)?.message).includes(`people-${kind === "nightly" ? "nightly-dreaming" : "weekly-validation"}.md`))));
44
- const primary = matches.find(job => job.declarationKey === key);
45
- const legacy = matches.filter(job => job.declarationKey !== key);
46
- const migrationPaused = config.agents?.[agentId]?.enabled !== true &&
47
- (primary ? String(primary.description).includes("[migration-paused]") : legacy.length > 0 && legacy.every(job => job.enabled === false));
48
- const enabled = options.enabled && options[kind] && !migrationPaused;
49
- if (!primary && !legacy.length && !enabled)
50
- continue;
51
- const desired = {
52
- declarationKey: key, agentId, name: key,
53
- description: "Plugin-owned private People Whisperer review; opt out in people.learning." + (migrationPaused ? " [migration-paused]" : ""),
54
- enabled, schedule: { kind: "cron", expr: options[`${kind}Schedule`],
55
- tz: options.timezone ?? resolveTimezone(cfg.agents?.defaults?.userTimezone), staggerMs: 0 },
56
- sessionTarget: "isolated", wakeMode: "now", deleteAfterRun: false,
57
- payload: { kind: "agentTurn", message: peopleLearningPrompt(kind, agentId), timeoutSeconds: kind === "nightly" ? 2700 : 3600,
58
- toolsAllow: LEARNING_TOOLS },
59
- delivery: { mode: "none" }, failureAlert: false,
60
- };
61
- if (!active())
62
- return result;
63
- let id;
64
- if (primary) {
65
- id = String(primary.id);
68
+ const matches = jobs.filter(job => matchesLearningJob(job, agentId, kind, key, options.legacyJobIds));
69
+ for (const match of matches) {
70
+ const id = String(match.id);
71
+ recognized.set(`${agentId}:${id}`, { id, agentId, kind });
66
72
  }
67
- else {
68
- // declarationKey is creation-only in the installed SDK. Never "migrate"
69
- // it through update, which silently ignores that field. Create disabled
70
- // before pausing the originals so a lost reply cannot leave two runners.
71
- const added = record(await cron.add({ ...desired, enabled: false }));
72
- const addedId = nonBlank(added?.id) ?? nonBlank(record(added?.job)?.id);
73
- if (!addedId)
74
- throw new Error("Cron creation unconfirmed; retry reconciliation with the same declaration key");
75
- id = addedId;
76
- }
77
- owned.add(id);
78
- result.push({ id, agentId, kind });
79
- // Keep duplicate IDs and histories recoverable, but prevent a second run.
80
- for (const duplicate of matches)
81
- if (duplicate.id !== id && duplicate.enabled !== false && active()) {
82
- await cron.update(String(duplicate.id), { enabled: false });
83
- }
84
- const { declarationKey: _key, ...patch } = desired;
85
- if (active() && (!primary || !containsDeclaration(primary, patch)))
86
- await cron.update(id, patch);
73
+ planned.push({ agentId, kind, options, key, matches });
74
+ }
75
+ }
76
+ // Surface durably declared AND exact agent-scoped legacy matches immediately
77
+ // before any scheduler mutation so partial-reconcile or cron.add failures
78
+ // never leave active cron runs unrecognized by private-session hooks.
79
+ if (recognized.size && active())
80
+ onRecognize?.([...recognized.values()], false);
81
+ const result = [], owned = new Set();
82
+ for (const { agentId, kind, options, key, matches } of planned) {
83
+ const primary = matches.find(job => job.declarationKey === key);
84
+ const legacy = matches.filter(job => job.declarationKey !== key);
85
+ const migrationPaused = config.agents?.[agentId]?.enabled !== true &&
86
+ (primary ? String(primary.description).includes("[migration-paused]") : legacy.length > 0 && legacy.every(job => job.enabled === false));
87
+ const enabled = options.enabled && options[kind] && !migrationPaused;
88
+ if (!primary && !legacy.length && !enabled)
89
+ continue;
90
+ const desired = {
91
+ declarationKey: key, agentId, name: key,
92
+ description: "Plugin-owned private People Whisperer review; opt out in people.learning." + (migrationPaused ? " [migration-paused]" : ""),
93
+ enabled, schedule: {
94
+ kind: "cron", expr: options[`${kind}Schedule`],
95
+ tz: options.timezone ?? resolveTimezone(cfg.agents?.defaults?.userTimezone), staggerMs: 0,
96
+ },
97
+ sessionTarget: "isolated", wakeMode: "now", deleteAfterRun: false,
98
+ payload: {
99
+ kind: "agentTurn", message: peopleLearningPrompt(kind, agentId), timeoutSeconds: kind === "nightly" ? DEFAULTS.people.learningNightlyTimeoutSec : DEFAULTS.people.learningWeeklyTimeoutSec,
100
+ toolsAllow: LEARNING_TOOLS,
101
+ },
102
+ delivery: { mode: "none" }, failureAlert: false,
103
+ };
104
+ if (!active())
105
+ return result;
106
+ let id;
107
+ if (primary) {
108
+ id = String(primary.id);
109
+ }
110
+ else {
111
+ // declarationKey is creation-only in the installed SDK. Never "migrate"
112
+ // it through update, which silently ignores that field. Create disabled
113
+ // before pausing the originals so a lost reply cannot leave two runners.
114
+ const added = record(await cron.add({ ...desired, enabled: false }));
115
+ const addedId = nonBlank(added?.id) ?? nonBlank(record(added?.job)?.id);
116
+ if (!addedId)
117
+ throw new Error("Cron creation unconfirmed; retry reconciliation with the same declaration key");
118
+ id = addedId;
119
+ const created = { id, agentId, kind };
120
+ recognized.set(`${agentId}:${id}`, created);
121
+ if (active())
122
+ onRecognize?.([created], false);
87
123
  }
124
+ owned.add(id);
125
+ const entry = { id, agentId, kind };
126
+ recognized.set(`${agentId}:${id}`, entry);
127
+ result.push(entry);
128
+ // Keep duplicate IDs and histories recoverable, but prevent a second run.
129
+ for (const duplicate of matches)
130
+ if (duplicate.id !== id && duplicate.enabled !== false && active()) {
131
+ await cron.update(String(duplicate.id), { enabled: false });
132
+ }
133
+ const { declarationKey: _key, ...patch } = desired;
134
+ if (active() && (!primary || !containsDeclaration(primary, patch)))
135
+ await cron.update(id, patch);
88
136
  }
89
137
  // Only this exact namespace is owned. Never sweep other agents' maintenance jobs.
90
138
  for (const job of jobs)
91
139
  if (String(job.declarationKey ?? "").startsWith(PREFIX) && !owned.has(String(job.id)) && job.enabled !== false && active()) {
92
140
  await cron.update(String(job.id), { enabled: false });
93
141
  }
142
+ if (active())
143
+ onRecognize?.([...recognized.values()], true);
94
144
  return result;
95
145
  }
96
146
  export function learningSession(sessionKey, jobs) {
@@ -44,6 +44,7 @@ export type ReviewManifest = {
44
44
  inventoryPending?: boolean;
45
45
  };
46
46
  export declare function dossierAssertions(personId: string, dossier: PersonDossier): ReviewAssertion[];
47
+ /** Atomically publishes a flushed 0o600 private JSON artifact; never accepts a truncated partial file. */
47
48
  export declare function privateJson(root: string, name: string, value: unknown): string;
48
49
  export declare function inventoryPeople(options: {
49
50
  agentId: string;