hippo-memory 3.4.0 → 3.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 (135) hide show
  1. package/README.md +29 -26
  2. package/dist/api/callers.d.ts +4 -1
  3. package/dist/api/context/context-plan.js +3 -0
  4. package/dist/api/context/context-pools.js +2 -0
  5. package/dist/api/context/context.d.ts +1 -1
  6. package/dist/api/context/context.js +13 -9
  7. package/dist/api/ledger-db.d.ts +4 -2
  8. package/dist/api/ledger-db.js +11 -1
  9. package/dist/api/objects/object-kinds.d.ts +1 -4
  10. package/dist/api/objects/object-kinds.js +1 -5
  11. package/dist/api/pilot-arm.js +4 -1
  12. package/dist/api/recall/finish.js +3 -2
  13. package/dist/api/recall/recall.js +3 -1
  14. package/dist/api/recall/request.d.ts +1 -1
  15. package/dist/api/recall/request.js +3 -1
  16. package/dist/api/session-end.d.ts +3 -2
  17. package/dist/api/session-end.js +8 -4
  18. package/dist/api/sharing.d.ts +4 -3
  19. package/dist/api/sharing.js +2 -2
  20. package/dist/api/sleep/auto-sleep.d.ts +3 -2
  21. package/dist/api/sleep/auto-sleep.js +16 -3
  22. package/dist/api/sleep/one-sleep.d.ts +23 -0
  23. package/dist/api/sleep/one-sleep.js +53 -0
  24. package/dist/api/sleep/sleep.d.ts +5 -0
  25. package/dist/api/sleep/sleep.js +2 -1
  26. package/dist/api/tokens.d.ts +1 -1
  27. package/dist/api/tokens.js +3 -0
  28. package/dist/api/types.d.ts +2 -0
  29. package/dist/api/types.js +4 -0
  30. package/dist/base/config/config-keys.js +1 -0
  31. package/dist/base/config/config.d.ts +4 -0
  32. package/dist/base/config/config.js +1 -0
  33. package/dist/base/embeddings/local.d.ts +1 -1
  34. package/dist/base/embeddings/local.js +2 -3
  35. package/dist/base/errors/read-only.d.ts +3 -0
  36. package/dist/base/errors/read-only.js +4 -0
  37. package/dist/base/ports/store/capture.d.ts +2 -0
  38. package/dist/base/ports/store/consolidation.d.ts +15 -0
  39. package/dist/base/ports/store/consolidation.js +2 -0
  40. package/dist/base/ports/store/context-reads.d.ts +2 -0
  41. package/dist/base/ports/store/objects.d.ts +15 -4
  42. package/dist/base/ports/store/store-effects.d.ts +2 -0
  43. package/dist/base/ports/store.d.ts +1 -1
  44. package/dist/base/scope/read-admission.d.ts +2 -0
  45. package/dist/base/scope/read-admission.js +8 -2
  46. package/dist/base/util/env.d.ts +1 -0
  47. package/dist/base/util/env.js +3 -0
  48. package/dist/base/util/version.d.ts +1 -1
  49. package/dist/base/util/version.js +1 -1
  50. package/dist/cli.js +14 -1
  51. package/dist/db/connect.d.ts +4 -0
  52. package/dist/db/connect.js +79 -1
  53. package/dist/db/grant.js +1 -1
  54. package/dist/db/migrate.d.ts +3 -0
  55. package/dist/db/migrate.js +1 -1
  56. package/dist/db/migrations/index.d.ts +1 -1
  57. package/dist/db/migrations/index.js +3 -1
  58. package/dist/db/migrations/v63.d.ts +3 -0
  59. package/dist/db/migrations/v63.js +9 -0
  60. package/dist/db/store-runtime.d.ts +7 -0
  61. package/dist/db/store-runtime.js +4 -0
  62. package/dist/domain/consolidate/merge.js +6 -6
  63. package/dist/domain/consolidate/tombstones.d.ts +3 -4
  64. package/dist/domain/consolidate/tombstones.js +3 -3
  65. package/dist/domain/objects/decisions.d.ts +4 -7
  66. package/dist/domain/objects/decisions.js +1 -9
  67. package/dist/domain/objects/descriptor.d.ts +2 -0
  68. package/dist/domain/objects/lifecycle.js +8 -2
  69. package/dist/domain/sharing/share.d.ts +16 -4
  70. package/dist/domain/sharing/share.js +33 -17
  71. package/dist/entry/store-kit.js +2 -1
  72. package/dist/infra/local-embedder.js +14 -2
  73. package/dist/infra/spool-claims.d.ts +2 -2
  74. package/dist/infra/spool-claims.js +4 -3
  75. package/dist/infra/spool-import.js +1 -1
  76. package/dist/infra/spool-record.d.ts +3 -1
  77. package/dist/store/sqlite/capture/compaction-hooks.js +14 -6
  78. package/dist/store/sqlite/capture/spool-request-id.d.ts +3 -0
  79. package/dist/store/sqlite/capture/spool-request-id.js +12 -0
  80. package/dist/store/sqlite/consolidation/consolidation.js +2 -0
  81. package/dist/store/sqlite/consolidation/sleep-lock.d.ts +4 -0
  82. package/dist/store/sqlite/consolidation/sleep-lock.js +69 -0
  83. package/dist/store/sqlite/entries/entry-filter.js +1 -2
  84. package/dist/store/sqlite/entries/entry-row.js +5 -1
  85. package/dist/store/sqlite/entries/entry-writes.js +3 -10
  86. package/dist/store/sqlite/entries/raw-archive.d.ts +2 -1
  87. package/dist/store/sqlite/entries/raw-archive.js +12 -3
  88. package/dist/store/sqlite/index.d.ts +1 -1
  89. package/dist/store/sqlite/learning/prediction-baserate.js +4 -2
  90. package/dist/store/sqlite/recall/candidates.js +2 -7
  91. package/dist/store/sqlite/recall/search-rows.d.ts +3 -0
  92. package/dist/store/sqlite/recall/search-rows.js +27 -8
  93. package/dist/store/sqlite/records/object-rows.d.ts +2 -0
  94. package/dist/store/sqlite/records/object-rows.js +5 -1
  95. package/dist/store/sqlite/records/object-writes.d.ts +3 -0
  96. package/dist/store/sqlite/records/object-writes.js +43 -1
  97. package/dist/store/sqlite/review/conflicts.js +3 -4
  98. package/dist/store/sqlite/runtime/handles.js +3 -0
  99. package/dist/store/sqlite/runtime/rule-sql.d.ts +1 -0
  100. package/dist/store/sqlite/runtime/rule-sql.js +2 -0
  101. package/dist/surface/capture/session-worker.d.ts +3 -2
  102. package/dist/surface/capture/session-worker.js +36 -10
  103. package/dist/surface/cli/api-context.js +3 -1
  104. package/dist/surface/cli/cli-runtime.js +2 -1
  105. package/dist/surface/cli/client.d.ts +6 -5
  106. package/dist/surface/cli/client.js +50 -19
  107. package/dist/surface/cli/decisions.js +16 -17
  108. package/dist/surface/cli/hooks/session-end-worker.js +3 -2
  109. package/dist/surface/cli/install-steps.js +99 -13
  110. package/dist/surface/cli/memory-writes.js +3 -2
  111. package/dist/surface/cli/serve.js +4 -1
  112. package/dist/surface/cli/sleep-render.js +7 -0
  113. package/dist/surface/cli/sleep.d.ts +3 -2
  114. package/dist/surface/cli/sleep.js +10 -4
  115. package/dist/surface/cli/transfer.js +6 -3
  116. package/dist/surface/cli/verb-row.d.ts +2 -0
  117. package/dist/surface/cli/verbs/health.js +3 -0
  118. package/dist/surface/cli/verbs/memory.js +5 -0
  119. package/dist/surface/cli/verbs/objects.js +2 -0
  120. package/dist/surface/cli/verbs/sessions.js +11 -0
  121. package/dist/surface/hooks-install/codex-wrapper.js +52 -11
  122. package/dist/surface/hooks-install/rules/hook-blocks.js +9 -2
  123. package/dist/surface/mcp/admin-tools.js +5 -2
  124. package/dist/surface/mcp/request.js +6 -2
  125. package/dist/surface/mcp/tools.d.ts +2 -0
  126. package/dist/surface/mcp/tools.js +8 -0
  127. package/dist/surface/open-store.d.ts +2 -2
  128. package/dist/surface/open-store.js +2 -2
  129. package/dist/surface/server/routes/decisions.js +2 -2
  130. package/dist/surface/server/sleep-child.js +5 -4
  131. package/dist/surface/server/sleep-offload.js +36 -25
  132. package/extensions/openclaw-plugin/openclaw.plugin.json +1 -1
  133. package/extensions/openclaw-plugin/package.json +1 -1
  134. package/openclaw.plugin.json +1 -1
  135. package/package.json +1 -1
@@ -133,6 +133,7 @@ export const HEALTH_VERBS = {
133
133
  ],
134
134
  }),
135
135
  outcome: verb(() => import('../curate.js'), 'handleOutcome', {
136
+ readOnly: 'refuse',
136
137
  repairsCodexWrapper: true,
137
138
  scoped: true,
138
139
  flags: { switches: ['bad', 'good'], values: ['id'] },
@@ -155,6 +156,7 @@ export const HEALTH_VERBS = {
155
156
  ],
156
157
  }),
157
158
  resolve: verb(() => import('../conflicts.js'), 'handleResolve', {
159
+ readOnly: 'refuse',
158
160
  needs: ['conflicts'],
159
161
  destructive: true,
160
162
  flags: { switches: ['forget', 'reject-loser'], values: ['keep', 'reason'] },
@@ -246,6 +248,7 @@ export const HEALTH_VERBS = {
246
248
  ],
247
249
  }),
248
250
  'capture-error': verb(() => import('../hooks/capture-error.js'), 'handleCaptureError', {
251
+ readOnly: 'skip',
249
252
  needs: ['failureLog', 'lessonWrites'],
250
253
  flags: { values: ['format', 'runtime'] },
251
254
  usage: [
@@ -33,6 +33,7 @@ export const MEMORY_VERBS = {
33
33
  ],
34
34
  }),
35
35
  remember: verb(() => import('../remember.js'), 'handleRemember', {
36
+ readOnly: 'refuse',
36
37
  repairsCodexWrapper: true,
37
38
  flags: {
38
39
  switches: ['error', 'extract', 'force', 'global', 'inferred', 'observed', 'pin', 'verified'],
@@ -52,6 +53,7 @@ export const MEMORY_VERBS = {
52
53
  ],
53
54
  }),
54
55
  supersede: verb(() => import('../remember.js'), 'handleSupersede', {
56
+ readOnly: 'refuse',
55
57
  destructive: true,
56
58
  flags: { switches: ['pin'], values: ['layer'], lists: ['tag'] },
57
59
  usage: [
@@ -211,6 +213,7 @@ export const MEMORY_VERBS = {
211
213
  ],
212
214
  }),
213
215
  refine: verb(() => import('../maintenance.js'), 'handleRefine', {
216
+ readOnly: 'refuse',
214
217
  flags: { switches: ['all', 'dry-run', 'json'], values: ['model'], numbers: ['limit'] },
215
218
  usage: [
216
219
  `
@@ -275,6 +278,7 @@ export const MEMORY_VERBS = {
275
278
  ],
276
279
  }),
277
280
  sleep: verb(() => import('../sleep.js'), 'handleSleep', {
281
+ readOnly: 'skip',
278
282
  needs: ['graphReads', 'vectors'],
279
283
  repairsCodexWrapper: true,
280
284
  destructive: true,
@@ -293,6 +297,7 @@ export const MEMORY_VERBS = {
293
297
  ],
294
298
  }),
295
299
  'daily-runner': verb(() => import('../daily-runner.js'), 'handleDailyRunner', {
300
+ readOnly: 'skip',
296
301
  needs: ['reports'],
297
302
  flags: {},
298
303
  usage: [
@@ -31,6 +31,7 @@ export const OBJECT_VERBS = {
31
31
  ],
32
32
  }),
33
33
  decide: verb(() => import('../decisions.js'), 'handleDecide', {
34
+ readOnly: 'refuse',
34
35
  needs: ['objects'],
35
36
  flags: { values: ['context', 'status', 'supersedes'], numbers: ['limit'] },
36
37
  usage: [
@@ -170,6 +171,7 @@ export const OBJECT_VERBS = {
170
171
  ],
171
172
  }),
172
173
  invalidate: verb(() => import('../curate.js'), 'handleInvalidate', {
174
+ readOnly: 'refuse',
173
175
  destructive: true,
174
176
  flags: { switches: ['churn', 'dry-run'], values: ['id', 'reason'] },
175
177
  usage: [
@@ -155,6 +155,7 @@ export const SESSION_VERBS = {
155
155
  ],
156
156
  }),
157
157
  forget: verb(() => import('../curate.js'), 'handleForget', {
158
+ readOnly: 'refuse',
158
159
  destructive: true,
159
160
  scoped: true,
160
161
  flags: { switches: ['archive', 'dry-run'], values: ['reason'] },
@@ -192,6 +193,7 @@ export const SESSION_VERBS = {
192
193
  ],
193
194
  }),
194
195
  learn: verb(() => import('../learn.js'), 'handleLearn', {
196
+ readOnly: 'refuse',
195
197
  needs: ['lessonWrites', 'vectors', 'vectorWrites'],
196
198
  scoped: true,
197
199
  flags: { switches: ['git'], values: ['repos'], numbers: ['days'] },
@@ -204,6 +206,7 @@ export const SESSION_VERBS = {
204
206
  ],
205
207
  }),
206
208
  promote: verb(() => import('../transfer.js'), 'handlePromote', {
209
+ readOnly: 'refuse',
207
210
  scoped: true,
208
211
  flags: {},
209
212
  usage: [
@@ -212,6 +215,7 @@ export const SESSION_VERBS = {
212
215
  ],
213
216
  }),
214
217
  share: verb(() => import('../transfer.js'), 'handleShare', {
218
+ readOnly: 'refuse',
215
219
  needs: ['vectors', 'vectorWrites'],
216
220
  dryRun: {
217
221
  form: '--auto',
@@ -243,6 +247,7 @@ export const SESSION_VERBS = {
243
247
  ],
244
248
  }),
245
249
  import: verb(() => import('../memory-import.js'), 'handleImport', {
250
+ readOnly: 'refuse',
246
251
  flags: {
247
252
  switches: ['agents', 'dry-run', 'global'],
248
253
  values: ['chatgpt', 'claude', 'cursor', 'file', 'markdown', 'name', 'scope', 'vault'],
@@ -278,6 +283,7 @@ export const SESSION_VERBS = {
278
283
  ],
279
284
  }),
280
285
  capture: verb(() => import('../hooks/capture.js'), 'handleCapture', {
286
+ readOnly: 'skip',
281
287
  repairsCodexWrapper: true,
282
288
  flags: {
283
289
  switches: ['dry-run', 'global', 'last-session', 'stdin'],
@@ -332,6 +338,7 @@ export const SESSION_VERBS = {
332
338
  ],
333
339
  }),
334
340
  'session-end': verb(() => import('../hooks/session-end.js'), 'handleSessionEnd', {
341
+ readOnly: 'skip',
335
342
  // Its sleep step reads --dry-run, but the capture after it writes for real.
336
343
  dryRun: false,
337
344
  flags: {
@@ -355,6 +362,7 @@ export const SESSION_VERBS = {
355
362
  ],
356
363
  }),
357
364
  '__session-end-worker': verb(() => import('../hooks/session-end-worker.js'), 'handleSessionEndWorker', {
365
+ readOnly: 'skip',
358
366
  needs: ['sessions', 'reports'],
359
367
  dryRun: false,
360
368
  flags: {
@@ -363,6 +371,7 @@ export const SESSION_VERBS = {
363
371
  },
364
372
  }),
365
373
  'pre-compact': verb(() => import('../hooks/pre-compact.js'), 'handlePreCompact', {
374
+ readOnly: 'skip',
366
375
  flags: { values: ['format', 'log-file', 'runtime'] },
367
376
  usage: [
368
377
  `
@@ -382,6 +391,7 @@ export const SESSION_VERBS = {
382
391
  ],
383
392
  }),
384
393
  'post-compact': verb(() => import('../hooks/post-compact.js'), 'handlePostCompact', {
394
+ readOnly: 'skip',
385
395
  flags: { values: ['log-file'] },
386
396
  usage: [
387
397
  `
@@ -398,6 +408,7 @@ export const SESSION_VERBS = {
398
408
  ],
399
409
  }),
400
410
  '__codex-session-end-worker': verb(() => import('../hooks/codex-session-end-worker.js'), 'handleCodexSessionEndWorker', {
411
+ readOnly: 'skip',
401
412
  flags: { values: ['codex-home', 'history-path', 'log-file', 'start-offset', 'started-at'] },
402
413
  }),
403
414
  hook: verb(() => import('../hook.js'), 'handleHook', {
@@ -110,22 +110,40 @@ export function installedRealCodexPath() {
110
110
  }
111
111
  return metadata.realCodexPath;
112
112
  }
113
- export function detectRealCodexPath() {
114
- const metadata = readCodexWrapperMetadata();
115
- if (isCodexWrapperMetadataValid(metadata))
116
- return metadata.realCodexPath;
113
+ /** The launcher paths of each PATH folder, in PATH order, wrapper folder excluded, with their
114
+ * install plans. */
115
+ function pathLauncherFolders() {
117
116
  const { wrapperDir } = resolveCodexWrapperPaths();
118
- const entries = (envPath() ?? '')
117
+ const folders = (envPath() ?? '')
119
118
  .split(path.delimiter)
120
119
  .map((entry) => entry.trim())
121
120
  .filter(Boolean)
122
121
  .filter((entry) => !pathEquals(entry, wrapperDir));
123
- for (const entry of entries) {
124
- for (const name of CODEX_LAUNCHER_NAMES) {
125
- const candidate = path.join(entry, name);
126
- if (fs.existsSync(candidate))
127
- return candidate;
122
+ return folders.map((folder) => CODEX_LAUNCHER_NAMES.map((name) => {
123
+ const original = path.join(folder, name);
124
+ return { original, plan: resolveCodexInstallPlan(original) };
125
+ }));
126
+ }
127
+ /** Whether the plan's command path is empty or hippo's wrapper, so writing a wrapper there loses no
128
+ * launcher; a cmd shim for a vacated exe slot would otherwise overwrite a live codex.cmd. */
129
+ function commandPathIsFree(plan) {
130
+ return !fs.existsSync(plan.commandPath) || isHippoCodexWrapperFile(plan.commandPath);
131
+ }
132
+ export function detectRealCodexPath() {
133
+ const metadata = readCodexWrapperMetadata();
134
+ if (isCodexWrapperMetadataValid(metadata))
135
+ return metadata.realCodexPath;
136
+ // The first folder with a launcher wins, as the shell would resolve `codex`; within a folder a
137
+ // backup beside an empty slot means an install stopped after its rename, so the slot is the launcher.
138
+ for (const slots of pathLauncherFolders()) {
139
+ const vacated = slots.find(({ original, plan }) => fs.existsSync(plan.backupPath) && !fs.existsSync(original) && commandPathIsFree(plan));
140
+ if (vacated) {
141
+ log.info(`recovered an interrupted codex wrapper install from the backup ${vacated.plan.backupPath}`);
142
+ return vacated.original;
128
143
  }
144
+ const present = slots.find(({ original }) => fs.existsSync(original));
145
+ if (present)
146
+ return present.original;
129
147
  }
130
148
  return null;
131
149
  }
@@ -184,6 +202,9 @@ function makeWrapperDirs(paths) {
184
202
  }
185
203
  }
186
204
  function backUpRealLauncher(realCodexPath, backupPath) {
205
+ // The launcher is gone and its backup is not: an earlier install already made this rename.
206
+ if (!fs.existsSync(realCodexPath) && fs.existsSync(backupPath))
207
+ return;
187
208
  // A launcher that is not our wrapper is the current codex, so it replaces any older backup a
188
209
  // Codex update left.
189
210
  if (!isHippoCodexWrapperFile(realCodexPath)) {
@@ -216,10 +237,30 @@ function restoreCodexLauncher(metadata, metadataPath) {
216
237
  fs.renameSync(plan.backupPath, originalCodexPath);
217
238
  return true;
218
239
  }
240
+ /** With no metadata, a backup beside an empty or hippo-wrapped slot is an install that stopped
241
+ * part-way; a slot or command path holding a real launcher is never touched. */
242
+ function restoreLeftoverBackups() {
243
+ let changed = false;
244
+ for (const { original, plan } of pathLauncherFolders().flat()) {
245
+ if (!fs.existsSync(plan.backupPath))
246
+ continue;
247
+ if (fs.existsSync(original) && !isHippoCodexWrapperFile(original))
248
+ continue;
249
+ if (!commandPathIsFree(plan))
250
+ continue;
251
+ if (isHippoCodexWrapperFile(plan.commandPath))
252
+ fs.rmSync(plan.commandPath, { force: true });
253
+ fs.renameSync(plan.backupPath, original);
254
+ changed = true;
255
+ }
256
+ return changed;
257
+ }
219
258
  export function uninstallCodexWrapper() {
220
259
  const paths = resolveCodexWrapperPaths();
221
260
  const metadata = readCodexWrapperMetadata();
222
- let changed = metadata !== null && restoreCodexLauncher(metadata, paths.metadataPath);
261
+ let changed = metadata === null
262
+ ? restoreLeftoverBackups()
263
+ : restoreCodexLauncher(metadata, paths.metadataPath);
223
264
  cleanupLegacyCodexPathWrappers(paths);
224
265
  if (fs.existsSync(paths.metadataPath)) {
225
266
  fs.rmSync(paths.metadataPath, { force: true });
@@ -95,8 +95,8 @@ ends, so there is nothing to record or run by hand.
95
95
  content: agentsBlock('session', { footer: PI_FOOTER }),
96
96
  },
97
97
  };
98
- // sha256 of each trimmed block an earlier hippo wrote, so init refreshes only blocks nobody edited.
99
- // Add the old hash when a block changes.
98
+ // sha256 of every block text hippo has shipped, current ones included, so init refreshes only
99
+ // blocks nobody edited. scripts/checks/check-hook-block-hashes.mjs fails while a text is unlisted.
100
100
  const SHIPPED_HOOK_HASHES = new Map([
101
101
  ['c80e760208aed70f6094757736b9a2f496ba5c30d88bc2a7ae3e128b403dcc6b', 'claude-code'],
102
102
  ['75937be6b7fdc2b87bcb08b7fec56757808075db129d99eff3e9f769f80a7781', 'claude-code'],
@@ -121,6 +121,13 @@ const SHIPPED_HOOK_HASHES = new Map([
121
121
  ['8b8f5986d7f7ed15f06e68720d8913c3cab23d94366b411935ca2bbaa334553b', 'pi'],
122
122
  ['37767b355e18beac726b05b9e2b898dab8c6135fd7b98f3aa52edc734d5dd283', 'pi'],
123
123
  ['6e85a5cccb3cfeaa9a080713754936db730f96376f94cc9a9888a746149c7268', 'pi'],
124
+ ['9943e6f7e3e18cda82197f77f012841916223fd2e026c10196392f9090554dd8', 'claude-code'],
125
+ ['baa311df8f1cf35bc014f27e5e9cf8f9120bfa1594d5a48a4c31d6bf5922b5ae', 'codex'],
126
+ ['0fdf490b8120e538b0f2c2417b844d39da772415715d0572f31c5337162a4912', 'cursor'],
127
+ ['80d457096eabd14cc9a2178c06cb76b2440c02eec4eb117ef9fe57eaa03c3c20', 'openclaw'],
128
+ ['9af7ca33d8b9e96cec2dd519d5a52435ccd7bcb7590a9b1c4f8615da70ac48ce', 'opencode'],
129
+ ['ffb8b55d4ee75b876afabfa75df3836b6aa50cff117120562b71fa28888a5f7b', 'pi'],
130
+ ['349d81d433a8000a92fa99e97eebe88e31f752dec6456198c648bb0953129beb', 'openclaw'],
124
131
  ]);
125
132
  /**
126
133
  * The first hippo block in `text` and the agent whose current or shipped text it is; `owner` is
@@ -101,9 +101,12 @@ export async function runShareTool({ args, ctx, store }) {
101
101
  // The share reads the id in the caller's tenant only, so tenant A cannot copy tenant B's row to
102
102
  // the global store.
103
103
  const shared = await shareToGlobal({ ...apiCtx, store }, shareId, { force });
104
- if (!shared)
104
+ if (shared.kind === 'low-score')
105
105
  return 'Transfer score too low. Use force=true to override.';
106
- return `Shared [${shared.id}] to global store. Source: ${shared.source}`;
106
+ if (shared.kind === 'already-shared') {
107
+ return `Already shared: the global store holds this text as [${shared.existingId}].`;
108
+ }
109
+ return `Shared [${shared.entry.id}] to global store. Source: ${shared.entry.source}`;
107
110
  }
108
111
  export async function runPeersTool({ ctx }) {
109
112
  // Tenant-scope peer discovery to the caller, as hippo_share does.
@@ -9,7 +9,9 @@ import { RecallRequestError } from '../../api/recall/request.js';
9
9
  import { globalTargetOf } from '../../api/infra.js';
10
10
  import { recordTokens } from '../../api/tokens.js';
11
11
  import { mcpApiContext, } from './protocol.js';
12
- import { TOOLS, TOOLS_BY_NAME, ARGS_CHECKED_BY_API } from './tools.js';
12
+ import { TOOLS, TOOLS_BY_NAME, ARGS_CHECKED_BY_API, WRITE_TOOLS } from './tools.js';
13
+ import { READ_ONLY_REFUSAL } from '../../base/errors/read-only.js';
14
+ import { readOnlyOf } from '../../api/types.js';
13
15
  import { runRecallTool, runAssembleTool, runDrillTool, runContextTool } from './recall-tools.js';
14
16
  import { runRememberTool, runOutcomeTool, runLearnTool } from './memory-tools.js';
15
17
  import { runPredictBaserateTool, runStatusTool, runConflictsTool, runResolveTool, runShareTool, runPeersTool, } from './admin-tools.js';
@@ -130,7 +132,9 @@ async function callTool(id, params, ctx) {
130
132
  const run = toolRun(toolName, ctx);
131
133
  if (run === undefined)
132
134
  return errorReply(id, INTERNAL_ERROR, STORE_NOT_PORTED_MESSAGE);
133
- const refusal = sharedStoreRefusal(toolName, ctx);
135
+ const refusal = WRITE_TOOLS.has(toolName) && readOnlyOf(ctx)
136
+ ? READ_ONLY_REFUSAL
137
+ : sharedStoreRefusal(toolName, ctx);
134
138
  if (refusal !== undefined) {
135
139
  return resultReply(id, { content: [{ type: 'text', text: refusal }], isError: true });
136
140
  }
@@ -6,6 +6,8 @@ interface McpToolDefinition {
6
6
  }
7
7
  export declare const TOOLS: readonly McpToolDefinition[];
8
8
  export declare const TOOLS_BY_NAME: Map<string, McpToolDefinition>;
9
+ /** The tools that save, which answer the read-only refusal under HIPPO_READ_ONLY=1. */
10
+ export declare const WRITE_TOOLS: ReadonlySet<string>;
9
11
  export declare const ARGS_CHECKED_BY_API: Map<string, ReadonlySet<string>>;
10
12
  export {};
11
13
  //# sourceMappingURL=tools.d.ts.map
@@ -298,6 +298,14 @@ export const TOOLS = [
298
298
  },
299
299
  ];
300
300
  export const TOOLS_BY_NAME = new Map(TOOLS.map((t) => [t.name, t]));
301
+ /** The tools that save, which answer the read-only refusal under HIPPO_READ_ONLY=1. */
302
+ export const WRITE_TOOLS = new Set([
303
+ 'hippo_remember',
304
+ 'hippo_outcome',
305
+ 'hippo_learn',
306
+ 'hippo_resolve',
307
+ 'hippo_share',
308
+ ]);
301
309
  // api.retrieve rejects these itself, so MCP and HTTP callers get the same typed error code for the
302
310
  // same bad value.
303
311
  export const ARGS_CHECKED_BY_API = new Map([
@@ -1,6 +1,6 @@
1
1
  import type { StoreRules } from '../base/ports/infra.js';
2
2
  import type { HippoStore, StoreGroups } from '../base/ports/store-index.js';
3
- import { StoreRuntime, type ServerRuntimeOptions, type SqliteServerRuntime } from '../store/sqlite/index.js';
3
+ import { StoreRuntime, type ServerRuntimeOptions, type SqliteServerRuntime, type StoreRuntimeOptions } from '../store/sqlite/index.js';
4
4
  export { askingNearestFirst, inSqliteSession as inStoreSession, runSqliteBatch as runStoreBatch, runSqliteHookRequest as runStoreHookRequest, runSqliteRequest as runStoreRequest, saveVectorGraphFile, sqliteDashboardReads as defaultDashboardReads, sqliteDiagnosticsStore as defaultDiagnostics, sqliteImportFiles as defaultImportFiles, sqliteImportStores as defaultImportStores, sqliteReach as defaultReach, sqliteStore as defaultStore, tenantOfApiKey, withSharedStoreHandles, type RequestStores as StoreSession, type ResolveOptions, type ServerRuntimeOptions, type SqliteServerRuntime as ServerRuntime, type SqliteStoreOptions as StoreOptions, type StoreRuntime, } from '../store/sqlite/index.js';
5
5
  export { decodeVector, EMBEDDING_MODEL_META_KEY, encodeVector, OTHER_STORE_MARKER, rankVectorRows, type VectorMatch, type VectorRow, } from '../store/sqlite/index.js';
6
6
  /** The default store as ./store-kit publishes it, with only the rules an add-on picks: a runtime
@@ -8,7 +8,7 @@ export { decodeVector, EMBEDDING_MODEL_META_KEY, encodeVector, OTHER_STORE_MARKE
8
8
  export declare const publishedDefaultStore: (hippoRoot: string, rules?: StoreRules) => HippoStore & StoreGroups;
9
9
  /** Runs `fn` on a store runtime of its own, disposed with the work `fn` detached on it once `fn`
10
10
  * settles, or closed by its exit hook if the process exits first. */
11
- export declare function withStoreRuntime<T>(fn: (runtime: StoreRuntime) => Promise<T>): Promise<T>;
11
+ export declare function withStoreRuntime<T>(fn: (runtime: StoreRuntime) => Promise<T>, opts?: StoreRuntimeOptions): Promise<T>;
12
12
  /** hippo.db as a server serves it, with an exit hook that closes what the server opened if
13
13
  * close() never runs. */
14
14
  export declare function defaultServerRuntime(hippoRoot: string, opts?: ServerRuntimeOptions): SqliteServerRuntime;
@@ -7,8 +7,8 @@ export { decodeVector, EMBEDDING_MODEL_META_KEY, encodeVector, OTHER_STORE_MARKE
7
7
  export const publishedDefaultStore = sqliteStoreWith;
8
8
  /** Runs `fn` on a store runtime of its own, disposed with the work `fn` detached on it once `fn`
9
9
  * settles, or closed by its exit hook if the process exits first. */
10
- export async function withStoreRuntime(fn) {
11
- const runtime = new StoreRuntime();
10
+ export async function withStoreRuntime(fn, opts = {}) {
11
+ const runtime = new StoreRuntime(opts);
12
12
  const onExit = () => runtime.closeNow();
13
13
  process.once('exit', onExit);
14
14
  try {
@@ -6,8 +6,8 @@ import { isJsonNumber } from '../../../base/util/json.js';
6
6
  import { parseJsonBody, getString, requiredString, } from '../validation.js';
7
7
  import { MAX_SHORT_FIELD_LEN } from '../../../base/util/limits.js';
8
8
  const TEXT = { max: MAX_SHORT_FIELD_LEN };
9
- // The HTTP surface has no legacy --supersedes <memory-id> constraint, so it supersedes by table id
10
- // and never weakens a memory mirror.
9
+ // The HTTP surface supersedes by table id; the store weakens the replaced decision's memory in the
10
+ // same save.
11
11
  function supersededId(body) {
12
12
  const raw = body['supersedesDecisionId'];
13
13
  if (raw === undefined || raw === null)
@@ -4,6 +4,7 @@
4
4
  import { evalStoreRules } from '../../infra/eval-switches.js';
5
5
  import { sleepWholeStore } from '../../api/sleep/sleep.js';
6
6
  import { autoSleepConsolidate } from '../../api/sleep/auto-sleep.js';
7
+ import { sleepWasRefused } from '../../api/sleep/one-sleep.js';
7
8
  import { rootInfra } from '../../infra/ports.js';
8
9
  import { configReader } from '../../host/config-file.js';
9
10
  import { createHost } from '../../host/host.js';
@@ -31,9 +32,9 @@ function sleepJob({ hippoRoot, ...job }, session) {
31
32
  return sleepWholeStore({ tenantId: job.tenantId, actor: job.actor, store, reach, config, infra }, job.opts);
32
33
  }
33
34
  /** A sleep that changed the store saves its vector graph file, so a store whose server holds no
34
- * graph gets one. */
35
- async function saveGraphAfter(job) {
36
- if (job.kind !== 'sleep' || job.opts.dryRun)
35
+ * graph gets one; a refused sleep changed nothing. */
36
+ async function saveGraphAfter(job, result) {
37
+ if (job.kind !== 'sleep' || job.opts.dryRun || sleepWasRefused(result))
37
38
  return;
38
39
  const { maxVectors } = loadConfig(job.hippoRoot).vectorGraph;
39
40
  await saveVectorGraphFile(job.hippoRoot, { maxVectors, deadline: job.deadline - EXIT_MARGIN_MS });
@@ -70,7 +71,7 @@ process.once('message', (message) => {
70
71
  // After the reply, so the sleep's caller never waits on the build; the server's queue waits
71
72
  // for the exit.
72
73
  if (reply.ok)
73
- await saveGraphAfter(job);
74
+ await saveGraphAfter(job, reply.result);
74
75
  return code;
75
76
  })
76
77
  .catch((err) => {
@@ -23,11 +23,22 @@ export function isSleepReply(message) {
23
23
  'message' in message &&
24
24
  typeof message.message === 'string');
25
25
  }
26
- function failureOf(reply, code, signal) {
27
- if (!reply || reply.ok) {
28
- return new Error(`sleep process ended without an answer (code ${code}, signal ${signal})`);
26
+ // The failed-versus-deadline order lives in this precedence, not in the type.
27
+ function settle(end, event) {
28
+ if (end?.kind === 'answered')
29
+ return end;
30
+ switch (event.kind) {
31
+ case 'reply':
32
+ if (event.reply.ok)
33
+ return { kind: 'answered', result: event.reply.result };
34
+ return end ?? { kind: 'failed', reply: event.reply };
35
+ case 'malformed':
36
+ return end ?? { kind: 'malformed' };
37
+ case 'deadline':
38
+ return { kind: 'deadline' };
39
+ case 'close':
40
+ return end ?? { kind: 'closed' };
29
41
  }
30
- return replyError(reply);
31
42
  }
32
43
  function runInChild(job) {
33
44
  let ended = () => undefined;
@@ -45,22 +56,19 @@ function childAnswer(job, ended) {
45
56
  stdio: ['ignore', 'inherit', 'inherit', 'ipc'],
46
57
  windowsHide: true,
47
58
  });
48
- let reply;
49
- let timedOut = false;
50
- let malformed = false;
59
+ let end;
51
60
  // SIGKILL because the child is inside synchronous hippo.db work and cannot run a handler; the
52
61
  // OS drops its write lock.
53
62
  const timer = setTimeout(() => {
54
- timedOut = true;
63
+ end = settle(end, { kind: 'deadline' });
55
64
  child.kill('SIGKILL');
56
65
  }, deadlineMs);
57
66
  child.once('message', (message) => {
58
- if (isSleepReply(message))
59
- reply = message;
60
- else
61
- malformed = true;
62
- if (reply?.ok)
63
- resolve(reply.result);
67
+ end = settle(end, isSleepReply(message)
68
+ ? { kind: 'reply', reply: message }
69
+ : { kind: 'malformed' });
70
+ if (end.kind === 'answered')
71
+ resolve(end.result);
64
72
  });
65
73
  child.once('error', (err) => {
66
74
  clearTimeout(timer);
@@ -72,22 +80,25 @@ function childAnswer(job, ended) {
72
80
  child.once('close', (code, signal) => {
73
81
  clearTimeout(timer);
74
82
  ended();
75
- if (reply?.ok)
76
- return;
77
- reject(unansweredFailure(reply, code, signal, { timedOut, malformed, deadlineMs }));
83
+ end = settle(end, { kind: 'close' });
84
+ if (end.kind !== 'answered')
85
+ reject(unansweredFailure(end, deadlineMs, code, signal));
78
86
  });
79
87
  child.send({ ...job, deadline: Date.now() + deadlineMs });
80
88
  });
81
89
  }
82
- /** Why a child that closed without a good reply failed, the deadline first. */
83
- function unansweredFailure(reply, code, signal, { timedOut, malformed, deadlineMs }) {
84
- if (timedOut) {
85
- return new HttpError(504, `sleep did not finish within ${deadlineMs} ms and was stopped; the next sleep carries on from there`);
90
+ /** Why a child that closed without a good reply failed. */
91
+ function unansweredFailure(end, deadlineMs, code, signal) {
92
+ switch (end.kind) {
93
+ case 'deadline':
94
+ return new HttpError(504, `sleep did not finish within ${deadlineMs} ms and was stopped; the next sleep carries on from there`);
95
+ case 'malformed':
96
+ return new Error(`sleep process sent a reply that is not a sleep result (code ${code}, signal ${signal})`);
97
+ case 'failed':
98
+ return replyError(end.reply);
99
+ case 'closed':
100
+ return new Error(`sleep process ended without an answer (code ${code}, signal ${signal})`);
86
101
  }
87
- if (malformed) {
88
- return new Error(`sleep process sent a reply that is not a sleep result (code ${code}, signal ${signal})`);
89
- }
90
- return failureOf(reply, code, signal);
91
102
  }
92
103
  // One running and one waiting: each further sleep would only hold a request open behind work the
93
104
  // waiting one already covers.
@@ -2,7 +2,7 @@
2
2
  "id": "hippo-memory",
3
3
  "name": "Hippo Memory",
4
4
  "description": "Make your agent's memory work like a brain. Hippo is long-term memory for coding agents.",
5
- "version": "3.4.0",
5
+ "version": "3.6.0",
6
6
 
7
7
  "configSchema": {
8
8
  "type": "object",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hippo-memory",
3
- "version": "3.4.0",
3
+ "version": "3.6.0",
4
4
  "type": "module",
5
5
  "description": "Make your agent's memory work like a brain. Hippo is long-term memory for coding agents.",
6
6
  "main": "index.ts",
@@ -2,7 +2,7 @@
2
2
  "id": "hippo-memory",
3
3
  "name": "Hippo Memory",
4
4
  "description": "Make your agent's memory work like a brain. Hippo is long-term memory for coding agents.",
5
- "version": "3.4.0",
5
+ "version": "3.6.0",
6
6
  "configSchema": {
7
7
  "type": "object",
8
8
  "additionalProperties": false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hippo-memory",
3
- "version": "3.4.0",
3
+ "version": "3.6.0",
4
4
  "description": "Make your agent's memory work like a brain. Hippo is long-term memory for coding agents.",
5
5
  "mcpName": "io.github.kitfunso/hippo-memory",
6
6
  "type": "module",