@mono-agent/agent-app 0.19.1 → 0.20.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/README.md +304 -32
- package/dist/acp-bridge.d.ts.map +1 -1
- package/dist/acp-bridge.js +113 -54
- package/dist/acp-bridge.js.map +1 -1
- package/dist/acp-session-store.d.ts +12 -0
- package/dist/acp-session-store.d.ts.map +1 -0
- package/dist/acp-session-store.js +74 -0
- package/dist/acp-session-store.js.map +1 -0
- package/dist/agent-artifact-paths.d.ts +8 -0
- package/dist/agent-artifact-paths.d.ts.map +1 -0
- package/dist/agent-artifact-paths.js +11 -0
- package/dist/agent-artifact-paths.js.map +1 -0
- package/dist/agent-root-coordinator.d.ts +101 -0
- package/dist/agent-root-coordinator.d.ts.map +1 -0
- package/dist/agent-root-coordinator.js +470 -0
- package/dist/agent-root-coordinator.js.map +1 -0
- package/dist/app-controller-channels.d.ts +11 -1
- package/dist/app-controller-channels.d.ts.map +1 -1
- package/dist/app-controller-channels.js +145 -20
- package/dist/app-controller-channels.js.map +1 -1
- package/dist/app-controller-continuation.d.ts +2 -0
- package/dist/app-controller-continuation.d.ts.map +1 -1
- package/dist/app-controller-continuation.js.map +1 -1
- package/dist/app-controller-lifecycle.d.ts +5 -0
- package/dist/app-controller-lifecycle.d.ts.map +1 -1
- package/dist/app-controller-lifecycle.js +24 -5
- package/dist/app-controller-lifecycle.js.map +1 -1
- package/dist/app-controller-maintenance.d.ts +2 -0
- package/dist/app-controller-maintenance.d.ts.map +1 -1
- package/dist/app-controller-maintenance.js +32 -2
- package/dist/app-controller-maintenance.js.map +1 -1
- package/dist/app-controller-process-jobs.d.ts +46 -0
- package/dist/app-controller-process-jobs.d.ts.map +1 -0
- package/dist/app-controller-process-jobs.js +281 -0
- package/dist/app-controller-process-jobs.js.map +1 -0
- package/dist/app-controller-responder.d.ts +15 -0
- package/dist/app-controller-responder.d.ts.map +1 -1
- package/dist/app-controller-responder.js +146 -12
- package/dist/app-controller-responder.js.map +1 -1
- package/dist/app-controller-traceability.d.ts +6 -0
- package/dist/app-controller-traceability.d.ts.map +1 -1
- package/dist/app-controller-traceability.js +10 -0
- package/dist/app-controller-traceability.js.map +1 -1
- package/dist/app-controller-utils.d.ts +8 -0
- package/dist/app-controller-utils.d.ts.map +1 -1
- package/dist/app-controller-utils.js +24 -1
- package/dist/app-controller-utils.js.map +1 -1
- package/dist/app-controller.d.ts +40 -1
- package/dist/app-controller.d.ts.map +1 -1
- package/dist/app-controller.js +124 -39
- package/dist/app-controller.js.map +1 -1
- package/dist/background-log-maintenance.d.ts +85 -2
- package/dist/background-log-maintenance.d.ts.map +1 -1
- package/dist/background-log-maintenance.js +407 -136
- package/dist/background-log-maintenance.js.map +1 -1
- package/dist/background-runtime.d.ts.map +1 -1
- package/dist/background-runtime.js +22 -41
- package/dist/background-runtime.js.map +1 -1
- package/dist/background.d.ts +18 -26
- package/dist/background.d.ts.map +1 -1
- package/dist/background.js +83 -138
- package/dist/background.js.map +1 -1
- package/dist/channel-drivers/cron.d.ts +12 -1
- package/dist/channel-drivers/cron.d.ts.map +1 -1
- package/dist/channel-drivers/cron.js +121 -18
- package/dist/channel-drivers/cron.js.map +1 -1
- package/dist/channel-drivers/native-notify.d.ts +3 -0
- package/dist/channel-drivers/native-notify.d.ts.map +1 -1
- package/dist/channel-drivers/native-notify.js +2 -1
- package/dist/channel-drivers/native-notify.js.map +1 -1
- package/dist/channel-drivers/slack.d.ts.map +1 -1
- package/dist/channel-drivers/slack.js +41 -4
- package/dist/channel-drivers/slack.js.map +1 -1
- package/dist/channel-drivers/telegram.d.ts.map +1 -1
- package/dist/channel-drivers/telegram.js +46 -3
- package/dist/channel-drivers/telegram.js.map +1 -1
- package/dist/channel-drivers/tui.d.ts +13 -2
- package/dist/channel-drivers/tui.d.ts.map +1 -1
- package/dist/channel-drivers/tui.js +112 -3
- package/dist/channel-drivers/tui.js.map +1 -1
- package/dist/channels.d.ts +1 -1
- package/dist/channels.d.ts.map +1 -1
- package/dist/channels.js +4 -2
- package/dist/channels.js.map +1 -1
- package/dist/cli-args.d.ts +15 -1
- package/dist/cli-args.d.ts.map +1 -1
- package/dist/cli-args.js +82 -12
- package/dist/cli-args.js.map +1 -1
- package/dist/cli-background-command.d.ts +9 -2
- package/dist/cli-background-command.d.ts.map +1 -1
- package/dist/cli-background-command.js +174 -66
- package/dist/cli-background-command.js.map +1 -1
- package/dist/cli-commands.d.ts.map +1 -1
- package/dist/cli-commands.js +50 -12
- package/dist/cli-commands.js.map +1 -1
- package/dist/cli-help.d.ts.map +1 -1
- package/dist/cli-help.js +21 -1
- package/dist/cli-help.js.map +1 -1
- package/dist/config-reference.d.ts.map +1 -1
- package/dist/config-reference.js +99 -2
- package/dist/config-reference.js.map +1 -1
- package/dist/configured-agent.d.ts +44 -3
- package/dist/configured-agent.d.ts.map +1 -1
- package/dist/configured-agent.js +805 -156
- package/dist/configured-agent.js.map +1 -1
- package/dist/conversation-state-roots.d.ts +59 -0
- package/dist/conversation-state-roots.d.ts.map +1 -0
- package/dist/conversation-state-roots.js +248 -0
- package/dist/conversation-state-roots.js.map +1 -0
- package/dist/cron-control-store.d.ts +91 -0
- package/dist/cron-control-store.d.ts.map +1 -0
- package/dist/cron-control-store.js +1251 -0
- package/dist/cron-control-store.js.map +1 -0
- package/dist/cron-operator-service.d.ts +54 -0
- package/dist/cron-operator-service.d.ts.map +1 -0
- package/dist/cron-operator-service.js +352 -0
- package/dist/cron-operator-service.js.map +1 -0
- package/dist/doctor-session-history.d.ts +9 -0
- package/dist/doctor-session-history.d.ts.map +1 -0
- package/dist/doctor-session-history.js +313 -0
- package/dist/doctor-session-history.js.map +1 -0
- package/dist/doctor.d.ts +2 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +320 -9
- package/dist/doctor.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/interaction-bridge.d.ts +1 -0
- package/dist/interaction-bridge.d.ts.map +1 -1
- package/dist/interaction-bridge.js +54 -6
- package/dist/interaction-bridge.js.map +1 -1
- package/dist/jobs-command.d.ts +17 -0
- package/dist/jobs-command.d.ts.map +1 -0
- package/dist/jobs-command.js +207 -0
- package/dist/jobs-command.js.map +1 -0
- package/dist/launchd-lifecycle-lock.d.ts +36 -0
- package/dist/launchd-lifecycle-lock.d.ts.map +1 -0
- package/dist/launchd-lifecycle-lock.js +124 -0
- package/dist/launchd-lifecycle-lock.js.map +1 -0
- package/dist/launchd-log-monitor-status.d.ts +7 -0
- package/dist/launchd-log-monitor-status.d.ts.map +1 -0
- package/dist/launchd-log-monitor-status.js +224 -0
- package/dist/launchd-log-monitor-status.js.map +1 -0
- package/dist/launchd-logs.d.ts +9 -1
- package/dist/launchd-logs.d.ts.map +1 -1
- package/dist/launchd-logs.js +69 -16
- package/dist/launchd-logs.js.map +1 -1
- package/dist/launchd-maintenance-command.d.ts +10 -0
- package/dist/launchd-maintenance-command.d.ts.map +1 -0
- package/dist/launchd-maintenance-command.js +2 -0
- package/dist/launchd-maintenance-command.js.map +1 -0
- package/dist/launchd-maintenance-entry.d.ts +30 -0
- package/dist/launchd-maintenance-entry.d.ts.map +1 -0
- package/dist/launchd-maintenance-entry.js +206 -0
- package/dist/launchd-maintenance-entry.js.map +1 -0
- package/dist/launchd-maintenance-gate.d.ts +28 -0
- package/dist/launchd-maintenance-gate.d.ts.map +1 -0
- package/dist/launchd-maintenance-gate.js +80 -0
- package/dist/launchd-maintenance-gate.js.map +1 -0
- package/dist/launchd-private-files.d.ts +3 -0
- package/dist/launchd-private-files.d.ts.map +1 -0
- package/dist/launchd-private-files.js +58 -0
- package/dist/launchd-private-files.js.map +1 -0
- package/dist/launchd.d.ts +56 -2
- package/dist/launchd.d.ts.map +1 -1
- package/dist/launchd.js +210 -5
- package/dist/launchd.js.map +1 -1
- package/dist/local-configuration.d.ts.map +1 -1
- package/dist/local-configuration.js +33 -7
- package/dist/local-configuration.js.map +1 -1
- package/dist/managed-launchd-maintenance-environment.d.ts +3 -0
- package/dist/managed-launchd-maintenance-environment.d.ts.map +1 -0
- package/dist/managed-launchd-maintenance-environment.js +12 -0
- package/dist/managed-launchd-maintenance-environment.js.map +1 -0
- package/dist/managed-runtime-launch-proof.d.ts +11 -0
- package/dist/managed-runtime-launch-proof.d.ts.map +1 -0
- package/dist/managed-runtime-launch-proof.js +59 -0
- package/dist/managed-runtime-launch-proof.js.map +1 -0
- package/dist/managed-runtime-maintenance-entry.d.ts +10 -0
- package/dist/managed-runtime-maintenance-entry.d.ts.map +1 -0
- package/dist/managed-runtime-maintenance-entry.js +244 -0
- package/dist/managed-runtime-maintenance-entry.js.map +1 -0
- package/dist/managed-web-logs.d.ts +29 -11
- package/dist/managed-web-logs.d.ts.map +1 -1
- package/dist/managed-web-logs.js +244 -121
- package/dist/managed-web-logs.js.map +1 -1
- package/dist/managed-web-maintenance-environment.d.ts +6 -0
- package/dist/managed-web-maintenance-environment.d.ts.map +1 -0
- package/dist/managed-web-maintenance-environment.js +19 -0
- package/dist/managed-web-maintenance-environment.js.map +1 -0
- package/dist/mcp-apps.d.ts +37 -0
- package/dist/mcp-apps.d.ts.map +1 -0
- package/dist/mcp-apps.js +1753 -0
- package/dist/mcp-apps.js.map +1 -0
- package/dist/memory-command.d.ts +12 -0
- package/dist/memory-command.d.ts.map +1 -1
- package/dist/memory-command.js +510 -1
- package/dist/memory-command.js.map +1 -1
- package/dist/modules/known-tools.d.ts +1 -1
- package/dist/modules/known-tools.d.ts.map +1 -1
- package/dist/modules/known-tools.js +2 -0
- package/dist/modules/known-tools.js.map +1 -1
- package/dist/posted-reply-history.d.ts.map +1 -1
- package/dist/posted-reply-history.js +12 -0
- package/dist/posted-reply-history.js.map +1 -1
- package/dist/proactive-notify.d.ts +4 -1
- package/dist/proactive-notify.d.ts.map +1 -1
- package/dist/proactive-notify.js +43 -5
- package/dist/proactive-notify.js.map +1 -1
- package/dist/process-jobs-config.d.ts +82 -0
- package/dist/process-jobs-config.d.ts.map +1 -0
- package/dist/process-jobs-config.js +423 -0
- package/dist/process-jobs-config.js.map +1 -0
- package/dist/process-jobs-context.d.ts +24 -0
- package/dist/process-jobs-context.d.ts.map +1 -0
- package/dist/process-jobs-context.js +135 -0
- package/dist/process-jobs-context.js.map +1 -0
- package/dist/process-jobs-root-registry.d.ts +115 -0
- package/dist/process-jobs-root-registry.d.ts.map +1 -0
- package/dist/process-jobs-root-registry.js +978 -0
- package/dist/process-jobs-root-registry.js.map +1 -0
- package/dist/process-jobs-runtime.d.ts +35 -0
- package/dist/process-jobs-runtime.d.ts.map +1 -0
- package/dist/process-jobs-runtime.js +177 -0
- package/dist/process-jobs-runtime.js.map +1 -0
- package/dist/process-jobs-service.d.ts +70 -0
- package/dist/process-jobs-service.d.ts.map +1 -0
- package/dist/process-jobs-service.js +1989 -0
- package/dist/process-jobs-service.js.map +1 -0
- package/dist/process-jobs-store.d.ts +151 -0
- package/dist/process-jobs-store.d.ts.map +1 -0
- package/dist/process-jobs-store.js +1290 -0
- package/dist/process-jobs-store.js.map +1 -0
- package/dist/reply-artifacts.d.ts +65 -0
- package/dist/reply-artifacts.d.ts.map +1 -0
- package/dist/reply-artifacts.js +1147 -0
- package/dist/reply-artifacts.js.map +1 -0
- package/dist/reply-part-budget.d.ts +16 -0
- package/dist/reply-part-budget.d.ts.map +1 -0
- package/dist/reply-part-budget.js +57 -0
- package/dist/reply-part-budget.js.map +1 -0
- package/dist/request-model-override.d.ts +19 -0
- package/dist/request-model-override.d.ts.map +1 -1
- package/dist/request-model-override.js +54 -1
- package/dist/request-model-override.js.map +1 -1
- package/dist/request-scoped-mcp.d.ts +31 -0
- package/dist/request-scoped-mcp.d.ts.map +1 -0
- package/dist/request-scoped-mcp.js +197 -0
- package/dist/request-scoped-mcp.js.map +1 -0
- package/dist/run-history.d.ts.map +1 -1
- package/dist/run-history.js +50 -254
- package/dist/run-history.js.map +1 -1
- package/dist/runtime-option-extensions.d.ts +21 -0
- package/dist/runtime-option-extensions.d.ts.map +1 -1
- package/dist/runtime-option-extensions.js +53 -0
- package/dist/runtime-option-extensions.js.map +1 -1
- package/dist/secure-file-replace.d.ts +3 -0
- package/dist/secure-file-replace.d.ts.map +1 -1
- package/dist/secure-file-replace.js +31 -7
- package/dist/secure-file-replace.js.map +1 -1
- package/dist/session-history.d.ts +146 -0
- package/dist/session-history.d.ts.map +1 -0
- package/dist/session-history.js +347 -0
- package/dist/session-history.js.map +1 -0
- package/dist/sessions.d.ts +45 -2
- package/dist/sessions.d.ts.map +1 -1
- package/dist/sessions.js +849 -30
- package/dist/sessions.js.map +1 -1
- package/dist/web-command.d.ts +12 -11
- package/dist/web-command.d.ts.map +1 -1
- package/dist/web-command.js +554 -80
- package/dist/web-command.js.map +1 -1
- package/dist/web-log-maintenance-command.d.ts +7 -0
- package/dist/web-log-maintenance-command.d.ts.map +1 -0
- package/dist/web-log-maintenance-command.js +21 -0
- package/dist/web-log-maintenance-command.js.map +1 -0
- package/dist/web-log-maintenance-status.d.ts +26 -0
- package/dist/web-log-maintenance-status.d.ts.map +1 -0
- package/dist/web-log-maintenance-status.js +171 -0
- package/dist/web-log-maintenance-status.js.map +1 -0
- package/dist/web-log-maintenance.d.ts +32 -0
- package/dist/web-log-maintenance.d.ts.map +1 -0
- package/dist/web-log-maintenance.js +163 -0
- package/dist/web-log-maintenance.js.map +1 -0
- package/dist/web-maintenance-paths.d.ts +12 -0
- package/dist/web-maintenance-paths.d.ts.map +1 -0
- package/dist/web-maintenance-paths.js +24 -0
- package/dist/web-maintenance-paths.js.map +1 -0
- package/dist/wizard/prompts.d.ts.map +1 -1
- package/dist/wizard/prompts.js +1 -0
- package/dist/wizard/prompts.js.map +1 -1
- package/dist/wizard/run.js +1 -1
- package/dist/wizard/run.js.map +1 -1
- package/package.json +15 -15
- package/schema/mono-agent.config.schema.json +102 -1
- package/skills/mono-agent-composer/references/config-blueprint.md +26 -2
- package/skills/mono-agent-composer/references/discovery-questions.md +2 -2
- package/skills/mono-agent-composer/references/feature-coverage.md +6 -4
- package/skills/mono-agent-composer/references/package-map.md +19 -3
- package/skills/mono-agent-composer/references/playbooks.md +3 -3
- package/skills/mono-agent-composer/references/validation.md +4 -2
package/dist/memory-command.js
CHANGED
|
@@ -67,6 +67,14 @@ export async function runMemoryCommand(input) {
|
|
|
67
67
|
writeMemoryForgetFailure(input.json, input.positionals[1] ?? "unknown", "forget_usage");
|
|
68
68
|
return 2;
|
|
69
69
|
}
|
|
70
|
+
if (input.positionals[0] === "export") {
|
|
71
|
+
writeMemoryBundleFailure(input.json, "export", "export_usage");
|
|
72
|
+
return 2;
|
|
73
|
+
}
|
|
74
|
+
if (input.positionals[0] === "import") {
|
|
75
|
+
writeMemoryBundleFailure(input.json, memoryImportOperationLabel(input.positionals[1]), "import_usage");
|
|
76
|
+
return 2;
|
|
77
|
+
}
|
|
70
78
|
process.stderr.write(ui.errorLine(usageError));
|
|
71
79
|
return 2;
|
|
72
80
|
}
|
|
@@ -90,6 +98,10 @@ export async function runMemoryCommand(input) {
|
|
|
90
98
|
writeMemoryForgetFailure(input.json, rest[0] ?? "unknown", "forget_requires_bujo");
|
|
91
99
|
return 1;
|
|
92
100
|
}
|
|
101
|
+
if (subcommand === "export" || subcommand === "import") {
|
|
102
|
+
writeMemoryBundleFailure(input.json, subcommand === "export" ? "export" : memoryImportOperationLabel(rest[0]), subcommand === "export" ? "export_requires_bujo" : "import_requires_bujo");
|
|
103
|
+
return 1;
|
|
104
|
+
}
|
|
93
105
|
writeNoMemory(context.configPath, input.json);
|
|
94
106
|
return 0;
|
|
95
107
|
}
|
|
@@ -134,9 +146,13 @@ export async function runMemoryCommand(input) {
|
|
|
134
146
|
return await runReplayAdoption(context, input.json);
|
|
135
147
|
case "forget":
|
|
136
148
|
return await runMemoryForget(context, rest, input);
|
|
149
|
+
case "export":
|
|
150
|
+
return await runMemoryBundleExport(context, input);
|
|
151
|
+
case "import":
|
|
152
|
+
return await runMemoryBundleImport(context, rest, input);
|
|
137
153
|
default:
|
|
138
154
|
process.stderr.write(ui.errorLine(`Unknown memory subcommand \`${subcommand}\`.`));
|
|
139
|
-
process.stderr.write(ui.hint("Expected stats, today, show <date>, search <query>, top, audit, inspect [id], retry [id], resolve <id> <reason>, rebuild, rollback, adopt-replay, or
|
|
155
|
+
process.stderr.write(ui.hint("Expected stats, today, show <date>, search <query>, top, audit, inspect [id], retry [id], resolve <id> <reason>, rebuild, rollback, adopt-replay, forget prepare|apply|restore, export, or import prepare|apply|restore."));
|
|
140
156
|
return 2;
|
|
141
157
|
}
|
|
142
158
|
}
|
|
@@ -203,10 +219,503 @@ function memoryCommandUsageError(input) {
|
|
|
203
219
|
? undefined
|
|
204
220
|
: "Usage: mono-agent memory forget restore --backup <dir>.";
|
|
205
221
|
}
|
|
222
|
+
case "export":
|
|
223
|
+
if (rest.length !== 0 || input.bundlePath === undefined || input.planPath !== undefined
|
|
224
|
+
|| input.backupPath !== undefined || input.onConflict !== undefined
|
|
225
|
+
|| input.entityConflict !== undefined || input.acceptDerivedAssociationDrift === true) {
|
|
226
|
+
return "Usage: mono-agent memory export --bundle <dir> [--include-extras] [--allow-pending].";
|
|
227
|
+
}
|
|
228
|
+
return undefined;
|
|
229
|
+
case "import": {
|
|
230
|
+
const operation = rest[0];
|
|
231
|
+
if (rest.length !== 1 || (operation !== "prepare" && operation !== "apply" && operation !== "restore")) {
|
|
232
|
+
return "Usage: mono-agent memory import prepare|apply|restore with the required operation flags.";
|
|
233
|
+
}
|
|
234
|
+
if (input.includeExtras === true || input.allowPending === true) {
|
|
235
|
+
return "--include-extras and --allow-pending are only supported for `mono-agent memory export`.";
|
|
236
|
+
}
|
|
237
|
+
if (operation === "prepare") {
|
|
238
|
+
return input.bundlePath !== undefined && input.planPath !== undefined && input.backupPath === undefined
|
|
239
|
+
? undefined
|
|
240
|
+
: "Usage: mono-agent memory import prepare --bundle <dir> --plan <file> "
|
|
241
|
+
+ "[--on-conflict fail|skip] [--entity-conflict target|source] [--accept-derived-association-drift].";
|
|
242
|
+
}
|
|
243
|
+
if (operation === "apply") {
|
|
244
|
+
return input.planPath !== undefined && input.bundlePath === undefined && input.backupPath === undefined
|
|
245
|
+
&& input.onConflict === undefined && input.entityConflict === undefined
|
|
246
|
+
&& input.acceptDerivedAssociationDrift !== true
|
|
247
|
+
? undefined
|
|
248
|
+
: "Usage: mono-agent memory import apply --plan <file>.";
|
|
249
|
+
}
|
|
250
|
+
return input.backupPath !== undefined && input.bundlePath === undefined && input.planPath === undefined
|
|
251
|
+
&& input.onConflict === undefined && input.entityConflict === undefined
|
|
252
|
+
&& input.acceptDerivedAssociationDrift !== true
|
|
253
|
+
? undefined
|
|
254
|
+
: "Usage: mono-agent memory import restore --backup <dir>.";
|
|
255
|
+
}
|
|
206
256
|
default:
|
|
207
257
|
return undefined;
|
|
208
258
|
}
|
|
209
259
|
}
|
|
260
|
+
const MEMORY_BUNDLE_CLI_SCHEMA_VERSION = 1;
|
|
261
|
+
const MAX_IMPORT_PLAN_BYTES = 64 * 1024;
|
|
262
|
+
const MAX_MEMORY_BUNDLE_CAUSE_DEPTH = 8;
|
|
263
|
+
/**
|
|
264
|
+
* Frozen operator-facing messages. Package errors are never interpolated:
|
|
265
|
+
* they can carry memory text, memory ids, entity names, and absolute paths.
|
|
266
|
+
*/
|
|
267
|
+
const MEMORY_BUNDLE_FAILURE_MESSAGES = Object.freeze({
|
|
268
|
+
export_requires_bujo: "Memory export requires a configured built-in BuJo store with embeddings.",
|
|
269
|
+
export_usage: "Memory export arguments are invalid.",
|
|
270
|
+
export_config_invalid: "Memory export requires a valid private configuration.",
|
|
271
|
+
export_destination_invalid: "The bundle destination must be a new directory outside the memory root.",
|
|
272
|
+
export_pending_work: "The memory store has unreplayed durable work; let it drain or re-run with --allow-pending.",
|
|
273
|
+
export_source_changed: "The memory store kept changing during export; retry with the agent idle.",
|
|
274
|
+
export_source_invalid: "The canonical memory source is invalid; repair it before exporting.",
|
|
275
|
+
export_failed: "Memory export failed; no bundle was published.",
|
|
276
|
+
import_requires_bujo: "Memory import requires a configured built-in BuJo store with embeddings.",
|
|
277
|
+
import_usage: "Memory import arguments are invalid.",
|
|
278
|
+
import_config_invalid: "Memory import requires a valid private configuration.",
|
|
279
|
+
import_bundle_invalid: "The bundle failed verification; the memory store was not changed.",
|
|
280
|
+
import_derived_drift: "Importing these entities would remove derived associations from existing memories; re-run with --accept-derived-association-drift to proceed.",
|
|
281
|
+
import_conflict: "Incoming memory ids already exist with different content; re-run with --on-conflict skip to keep this store's versions.",
|
|
282
|
+
import_prepare_failed: "Import-plan preparation failed without changing the memory store.",
|
|
283
|
+
import_pending_work: "The memory store has unreplayed durable work; let it drain, stop the agent, and prepare a fresh plan.",
|
|
284
|
+
import_stale_plan: "The import plan no longer matches this memory store or bundle; prepare a fresh plan.",
|
|
285
|
+
import_apply_failed: "Import application failed before a recoverable backup was available.",
|
|
286
|
+
import_apply_failed_recovered: "Import application failed and the complete pre-import backup was restored.",
|
|
287
|
+
import_apply_recovery_failed: "Import application failed and automatic recovery could not be verified; keep the agent stopped and restore the reported backup manually.",
|
|
288
|
+
import_restore_failed: "Backup restore was refused or failed; the current memory store was not intentionally overwritten.",
|
|
289
|
+
});
|
|
290
|
+
class MemoryBundleOperationError extends Error {
|
|
291
|
+
code;
|
|
292
|
+
recovered;
|
|
293
|
+
backupPath;
|
|
294
|
+
constructor(code, recovered = false, backupPath) {
|
|
295
|
+
super(code);
|
|
296
|
+
this.code = code;
|
|
297
|
+
this.recovered = recovered;
|
|
298
|
+
this.backupPath = backupPath;
|
|
299
|
+
this.name = "MemoryBundleOperationError";
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/** Shared precondition: the built-in BuJo backend with a usable embedding provider. */
|
|
303
|
+
function bundleMemorySettings(context) {
|
|
304
|
+
const memory = context.config.memory;
|
|
305
|
+
if (memory === undefined || (memory.backend ?? "bujo") === "supermemory"
|
|
306
|
+
|| memory.mode !== "bujo" || memory.embeddings === undefined) {
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
return memory;
|
|
310
|
+
}
|
|
311
|
+
async function runMemoryBundleExport(context, input) {
|
|
312
|
+
const memory = bundleMemorySettings(context);
|
|
313
|
+
if (memory === undefined) {
|
|
314
|
+
writeMemoryBundleFailure(input.json, "export", "export_requires_bujo");
|
|
315
|
+
return 1;
|
|
316
|
+
}
|
|
317
|
+
let bujo;
|
|
318
|
+
try {
|
|
319
|
+
bujo = await loadBujoModule();
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
writeMemoryBundleFailure(input.json, "export", "export_failed");
|
|
323
|
+
return 1;
|
|
324
|
+
}
|
|
325
|
+
const { MemoryBundleExportError } = bujo;
|
|
326
|
+
try {
|
|
327
|
+
const root = resolve(context.cwd, memory.path);
|
|
328
|
+
const bundlePath = await canonicalProspectivePath(resolve(context.cwd, input.bundlePath));
|
|
329
|
+
const result = await bujo.exportMemoryBundle({
|
|
330
|
+
root,
|
|
331
|
+
bundlePath,
|
|
332
|
+
scope: input.includeExtras === true ? "canonical+extras" : "canonical",
|
|
333
|
+
...(input.allowPending === true ? { allowPending: true } : {}),
|
|
334
|
+
...(memory.embeddings?.model === undefined
|
|
335
|
+
? {}
|
|
336
|
+
: { embeddingModel: `${memory.embeddings.provider}:${memory.embeddings.model}` }),
|
|
337
|
+
dimension: memory.embeddings?.dim ?? 768,
|
|
338
|
+
});
|
|
339
|
+
const published = {
|
|
340
|
+
schemaVersion: MEMORY_BUNDLE_CLI_SCHEMA_VERSION,
|
|
341
|
+
operation: "memory-export",
|
|
342
|
+
status: "exported",
|
|
343
|
+
bundlePath: result.bundlePath,
|
|
344
|
+
scope: result.scope,
|
|
345
|
+
sourceFingerprint: result.sourceFingerprint,
|
|
346
|
+
treeFingerprint: result.treeFingerprint,
|
|
347
|
+
counts: result.counts,
|
|
348
|
+
...(result.pendingWork ? { pendingWork: true } : {}),
|
|
349
|
+
};
|
|
350
|
+
write(input.json, published, () => renderMemoryBundleExport(published));
|
|
351
|
+
return 0;
|
|
352
|
+
}
|
|
353
|
+
catch (error) {
|
|
354
|
+
writeMemoryBundleFailure(input.json, "export", classifyMemoryBundleExportFailure(MemoryBundleExportError, error));
|
|
355
|
+
return 1;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
async function runMemoryBundleImport(context, rest, input) {
|
|
359
|
+
const operation = rest[0];
|
|
360
|
+
const label = memoryImportOperationLabel(operation);
|
|
361
|
+
const memory = bundleMemorySettings(context);
|
|
362
|
+
if (memory === undefined) {
|
|
363
|
+
writeMemoryBundleFailure(input.json, label, "import_requires_bujo");
|
|
364
|
+
return 1;
|
|
365
|
+
}
|
|
366
|
+
try {
|
|
367
|
+
const bujo = await loadBujoModule();
|
|
368
|
+
// Canonicalize once through the import operation's recovery-aware resolver.
|
|
369
|
+
// Every containment check, fingerprint, and package call below must bind to
|
|
370
|
+
// this same root identity (not a lexical Darwin system alias).
|
|
371
|
+
const root = bujo.resolveMemoryBundleImportRoot(resolve(context.cwd, memory.path));
|
|
372
|
+
if (operation === "prepare") {
|
|
373
|
+
const result = await prepareMemoryImportPlan(context, root, input, bujo);
|
|
374
|
+
write(input.json, result, () => renderMemoryBundleImport(result));
|
|
375
|
+
return 0;
|
|
376
|
+
}
|
|
377
|
+
if (operation === "apply") {
|
|
378
|
+
const result = await applyMemoryImportPlan(context, root, input.planPath, bujo);
|
|
379
|
+
write(input.json, result, () => renderMemoryBundleImport(result));
|
|
380
|
+
return 0;
|
|
381
|
+
}
|
|
382
|
+
const result = await restoreMemoryImportBackup(context, root, input.backupPath, bujo);
|
|
383
|
+
write(input.json, result, () => renderMemoryBundleImport(result));
|
|
384
|
+
return 0;
|
|
385
|
+
}
|
|
386
|
+
catch (error) {
|
|
387
|
+
const failure = error instanceof MemoryBundleOperationError
|
|
388
|
+
? error
|
|
389
|
+
: new MemoryBundleOperationError(operation === "prepare"
|
|
390
|
+
? "import_prepare_failed"
|
|
391
|
+
: operation === "restore"
|
|
392
|
+
? "import_restore_failed"
|
|
393
|
+
: "import_apply_failed");
|
|
394
|
+
writeMemoryBundleFailure(input.json, label, failure.code, failure.recovered, failure.backupPath);
|
|
395
|
+
return 1;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
async function prepareMemoryImportPlan(context, root, input, bujo) {
|
|
399
|
+
const planPath = await canonicalProspectivePath(resolve(context.cwd, input.planPath));
|
|
400
|
+
if (isSameOrUnderDirectory(root, planPath)) {
|
|
401
|
+
throw new MemoryBundleOperationError("import_prepare_failed");
|
|
402
|
+
}
|
|
403
|
+
const bundlePath = resolve(context.cwd, input.bundlePath);
|
|
404
|
+
let preview;
|
|
405
|
+
try {
|
|
406
|
+
preview = bujo.prepareMemoryBundleImport({
|
|
407
|
+
root,
|
|
408
|
+
bundlePath,
|
|
409
|
+
onConflict: input.onConflict ?? "fail",
|
|
410
|
+
entityConflict: input.entityConflict ?? "target",
|
|
411
|
+
acceptDerivedAssociationDrift: input.acceptDerivedAssociationDrift === true,
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
catch (error) {
|
|
415
|
+
throw new MemoryBundleOperationError(classifyImportPrepareFailure(bujo.MemoryBundleImportError, error));
|
|
416
|
+
}
|
|
417
|
+
const payload = {
|
|
418
|
+
schemaVersion: MEMORY_BUNDLE_CLI_SCHEMA_VERSION,
|
|
419
|
+
operation: "import",
|
|
420
|
+
rootFingerprint: preview.rootFingerprint,
|
|
421
|
+
destinationSourceFingerprint: preview.destinationSourceFingerprint,
|
|
422
|
+
bundlePath: preview.bundlePath,
|
|
423
|
+
bundleDigest: preview.bundleDigest,
|
|
424
|
+
mergeDigest: preview.mergeDigest,
|
|
425
|
+
mergedSourceFingerprint: preview.mergedSourceFingerprint,
|
|
426
|
+
onConflict: preview.onConflict,
|
|
427
|
+
entityConflict: preview.entityConflict,
|
|
428
|
+
acceptDerivedAssociationDrift: input.acceptDerivedAssociationDrift === true,
|
|
429
|
+
createdAt: new Date().toISOString(),
|
|
430
|
+
};
|
|
431
|
+
const plan = {
|
|
432
|
+
...payload,
|
|
433
|
+
planDigest: createHash("sha256").update(JSON.stringify(payload)).digest("hex"),
|
|
434
|
+
};
|
|
435
|
+
await writePrivateJsonExclusive(planPath, plan);
|
|
436
|
+
return {
|
|
437
|
+
schemaVersion: MEMORY_BUNDLE_CLI_SCHEMA_VERSION,
|
|
438
|
+
operation: "memory-import-prepare",
|
|
439
|
+
status: "prepared",
|
|
440
|
+
planPath,
|
|
441
|
+
planDigest: plan.planDigest,
|
|
442
|
+
counts: preview.counts,
|
|
443
|
+
// Counts only: entity ids and memory ids never enter the operator plan.
|
|
444
|
+
derivedAssociationsAdded: preview.derivedAssociationsAdded.length,
|
|
445
|
+
derivedAssociationsRemoved: preview.derivedAssociationsRemoved.length,
|
|
446
|
+
...(preview.bundlePendingWork ? { bundlePendingWork: true } : {}),
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
async function applyMemoryImportPlan(context, root, rawPlanPath, bujo) {
|
|
450
|
+
const planPath = resolve(context.cwd, rawPlanPath);
|
|
451
|
+
if (isSameOrUnderDirectory(root, await canonicalProspectivePath(planPath))) {
|
|
452
|
+
throw new MemoryBundleOperationError("import_apply_failed");
|
|
453
|
+
}
|
|
454
|
+
const plan = await readMemoryImportPlan(planPath);
|
|
455
|
+
if (plan.rootFingerprint !== memoryRootFingerprint(root)) {
|
|
456
|
+
throw new MemoryBundleOperationError("import_stale_plan");
|
|
457
|
+
}
|
|
458
|
+
// Preserve the user-facing same-config diagnostic; the package transaction
|
|
459
|
+
// independently enforces the authoritative shared-root writer lease.
|
|
460
|
+
await assertNoLiveConfiguredAgent(context.configPath, await memoryRegistryDirs(context));
|
|
461
|
+
const settings = previewRecallSettings(context.config);
|
|
462
|
+
if (settings === undefined || "supermemory" in settings || settings.embeddings === undefined) {
|
|
463
|
+
throw new MemoryBundleOperationError("import_config_invalid");
|
|
464
|
+
}
|
|
465
|
+
const { createMemoryEmbeddingProvider } = await loadMemoryRecallModule();
|
|
466
|
+
const embeddings = await createMemoryEmbeddingProvider(settings.embeddings);
|
|
467
|
+
try {
|
|
468
|
+
const result = await bujo.applyMemoryBundleImport({
|
|
469
|
+
root,
|
|
470
|
+
bundlePath: plan.bundlePath,
|
|
471
|
+
expectedRootFingerprint: plan.rootFingerprint,
|
|
472
|
+
expectedSourceFingerprint: plan.destinationSourceFingerprint,
|
|
473
|
+
expectedBundleDigest: plan.bundleDigest,
|
|
474
|
+
expectedMergeDigest: plan.mergeDigest,
|
|
475
|
+
expectedMergedSourceFingerprint: plan.mergedSourceFingerprint,
|
|
476
|
+
planDigest: plan.planDigest,
|
|
477
|
+
onConflict: plan.onConflict,
|
|
478
|
+
entityConflict: plan.entityConflict,
|
|
479
|
+
acceptDerivedAssociationDrift: plan.acceptDerivedAssociationDrift,
|
|
480
|
+
embeddings,
|
|
481
|
+
dimension: settings.embeddings.dim ?? 768,
|
|
482
|
+
});
|
|
483
|
+
return {
|
|
484
|
+
schemaVersion: MEMORY_BUNDLE_CLI_SCHEMA_VERSION,
|
|
485
|
+
operation: "memory-import-apply",
|
|
486
|
+
status: "applied",
|
|
487
|
+
imported: result.imported,
|
|
488
|
+
skipped: result.skipped,
|
|
489
|
+
identical: result.identical,
|
|
490
|
+
sourceFingerprint: result.sourceFingerprint,
|
|
491
|
+
backupPath: result.backupPath,
|
|
492
|
+
planDigest: plan.planDigest,
|
|
493
|
+
rollbackRetained: false,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
catch (error) {
|
|
497
|
+
throw new MemoryBundleOperationError(...classifyImportApplyFailure(bujo, error));
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
async function restoreMemoryImportBackup(context, root, rawBackupPath, bujo) {
|
|
501
|
+
const backupPath = resolve(context.cwd, rawBackupPath);
|
|
502
|
+
await assertNoLiveConfiguredAgent(context.configPath, await memoryRegistryDirs(context));
|
|
503
|
+
try {
|
|
504
|
+
const result = await bujo.restoreMemoryBundleImport({
|
|
505
|
+
root,
|
|
506
|
+
backupPath,
|
|
507
|
+
expectedRootFingerprint: memoryRootFingerprint(root),
|
|
508
|
+
});
|
|
509
|
+
return {
|
|
510
|
+
schemaVersion: MEMORY_BUNDLE_CLI_SCHEMA_VERSION,
|
|
511
|
+
operation: "memory-import-restore",
|
|
512
|
+
status: "restored",
|
|
513
|
+
sourceFingerprint: result.sourceFingerprint,
|
|
514
|
+
backupPath: result.backupPath,
|
|
515
|
+
planDigest: result.planDigest,
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
catch {
|
|
519
|
+
throw new MemoryBundleOperationError("import_restore_failed");
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
export function classifyMemoryBundleExportFailure(MemoryBundleExportError, error) {
|
|
523
|
+
if (!(error instanceof MemoryBundleExportError))
|
|
524
|
+
return "export_failed";
|
|
525
|
+
return classifyMemoryBundleExportCode(error.code);
|
|
526
|
+
}
|
|
527
|
+
function classifyMemoryBundleExportCode(code) {
|
|
528
|
+
switch (code) {
|
|
529
|
+
case "export_destination_invalid":
|
|
530
|
+
case "export_pending_work":
|
|
531
|
+
case "export_source_changed":
|
|
532
|
+
case "export_source_invalid":
|
|
533
|
+
case "export_failed":
|
|
534
|
+
return code;
|
|
535
|
+
default:
|
|
536
|
+
return unexpectedMemoryBundleExportCode(code);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
function unexpectedMemoryBundleExportCode(_code) {
|
|
540
|
+
return "export_failed";
|
|
541
|
+
}
|
|
542
|
+
export function classifyImportPrepareFailure(MemoryBundleImportError, error) {
|
|
543
|
+
if (!(error instanceof MemoryBundleImportError))
|
|
544
|
+
return "import_prepare_failed";
|
|
545
|
+
const code = error.code;
|
|
546
|
+
switch (code) {
|
|
547
|
+
case "import_derived_drift":
|
|
548
|
+
return "import_derived_drift";
|
|
549
|
+
case "import_bundle_invalid":
|
|
550
|
+
case "import_bundle_incompatible":
|
|
551
|
+
return "import_bundle_invalid";
|
|
552
|
+
case "import_prepare_failed":
|
|
553
|
+
return hasExplicitCauseCode(error, "id_conflict") ? "import_conflict" : "import_prepare_failed";
|
|
554
|
+
case "import_pending_work":
|
|
555
|
+
case "import_stale_plan":
|
|
556
|
+
case "import_apply_failed":
|
|
557
|
+
case "import_apply_failed_recovered":
|
|
558
|
+
case "import_apply_recovery_failed":
|
|
559
|
+
case "import_restore_failed":
|
|
560
|
+
return "import_prepare_failed";
|
|
561
|
+
default:
|
|
562
|
+
return unexpectedImportPrepareCode(code);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
function unexpectedImportPrepareCode(_code) {
|
|
566
|
+
return "import_prepare_failed";
|
|
567
|
+
}
|
|
568
|
+
export function classifyImportApplyFailure(bujo, error) {
|
|
569
|
+
if (error instanceof bujo.MemoryBundleImportError) {
|
|
570
|
+
const code = error.code;
|
|
571
|
+
switch (code) {
|
|
572
|
+
case "import_apply_failed_recovered":
|
|
573
|
+
return ["import_apply_failed_recovered", true, error.backupPath];
|
|
574
|
+
case "import_apply_recovery_failed":
|
|
575
|
+
return ["import_apply_recovery_failed", false, error.backupPath];
|
|
576
|
+
case "import_stale_plan":
|
|
577
|
+
return ["import_stale_plan", false, undefined];
|
|
578
|
+
case "import_derived_drift":
|
|
579
|
+
return ["import_derived_drift", false, undefined];
|
|
580
|
+
case "import_bundle_invalid":
|
|
581
|
+
case "import_bundle_incompatible":
|
|
582
|
+
return ["import_bundle_invalid", false, undefined];
|
|
583
|
+
case "import_pending_work":
|
|
584
|
+
return ["import_pending_work", false, undefined];
|
|
585
|
+
case "import_apply_failed":
|
|
586
|
+
case "import_prepare_failed":
|
|
587
|
+
case "import_restore_failed":
|
|
588
|
+
return ["import_apply_failed", false, undefined];
|
|
589
|
+
default:
|
|
590
|
+
return unexpectedImportApplyCode(code);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
return ["import_apply_failed", false, undefined];
|
|
594
|
+
}
|
|
595
|
+
function unexpectedImportApplyCode(_code) {
|
|
596
|
+
return ["import_apply_failed", false, undefined];
|
|
597
|
+
}
|
|
598
|
+
function hasExplicitCauseCode(error, expectedCode) {
|
|
599
|
+
const seen = new Set();
|
|
600
|
+
let current = readErrorProperty(error, "cause");
|
|
601
|
+
for (let depth = 0; depth < MAX_MEMORY_BUNDLE_CAUSE_DEPTH; depth += 1) {
|
|
602
|
+
if (!current.ok || !isIntrinsicError(current.value) || seen.has(current.value))
|
|
603
|
+
return false;
|
|
604
|
+
const candidate = current.value;
|
|
605
|
+
seen.add(candidate);
|
|
606
|
+
const code = readOwnErrorCode(candidate);
|
|
607
|
+
if (code.ok && code.value === expectedCode)
|
|
608
|
+
return true;
|
|
609
|
+
current = readErrorProperty(candidate, "cause");
|
|
610
|
+
}
|
|
611
|
+
return false;
|
|
612
|
+
}
|
|
613
|
+
function readOwnErrorCode(error) {
|
|
614
|
+
try {
|
|
615
|
+
if (!Object.prototype.hasOwnProperty.call(error, "code"))
|
|
616
|
+
return { ok: true, value: undefined };
|
|
617
|
+
}
|
|
618
|
+
catch {
|
|
619
|
+
return { ok: false };
|
|
620
|
+
}
|
|
621
|
+
return readErrorProperty(error, "code");
|
|
622
|
+
}
|
|
623
|
+
async function readMemoryImportPlan(path) {
|
|
624
|
+
const value = await readPrivateJson(path, MAX_IMPORT_PLAN_BYTES);
|
|
625
|
+
if (!isObject(value)
|
|
626
|
+
|| !hasExactKeys(value, [
|
|
627
|
+
"acceptDerivedAssociationDrift",
|
|
628
|
+
"bundleDigest",
|
|
629
|
+
"bundlePath",
|
|
630
|
+
"createdAt",
|
|
631
|
+
"destinationSourceFingerprint",
|
|
632
|
+
"entityConflict",
|
|
633
|
+
"mergeDigest",
|
|
634
|
+
"mergedSourceFingerprint",
|
|
635
|
+
"onConflict",
|
|
636
|
+
"operation",
|
|
637
|
+
"planDigest",
|
|
638
|
+
"rootFingerprint",
|
|
639
|
+
"schemaVersion",
|
|
640
|
+
])
|
|
641
|
+
|| value.schemaVersion !== MEMORY_BUNDLE_CLI_SCHEMA_VERSION
|
|
642
|
+
|| value.operation !== "import"
|
|
643
|
+
|| !isSha256(value.rootFingerprint)
|
|
644
|
+
|| !isSha256(value.destinationSourceFingerprint)
|
|
645
|
+
|| typeof value.bundlePath !== "string"
|
|
646
|
+
|| !isSha256(value.bundleDigest)
|
|
647
|
+
|| !isSha256(value.mergeDigest)
|
|
648
|
+
|| !isSha256(value.mergedSourceFingerprint)
|
|
649
|
+
|| (value.onConflict !== "fail" && value.onConflict !== "skip")
|
|
650
|
+
|| (value.entityConflict !== "target" && value.entityConflict !== "source")
|
|
651
|
+
|| typeof value.acceptDerivedAssociationDrift !== "boolean"
|
|
652
|
+
|| typeof value.createdAt !== "string" || !isCanonicalIso(value.createdAt)
|
|
653
|
+
|| !isSha256(value.planDigest)) {
|
|
654
|
+
throw new MemoryBundleOperationError("import_stale_plan");
|
|
655
|
+
}
|
|
656
|
+
const plan = value;
|
|
657
|
+
const { planDigest, ...payload } = plan;
|
|
658
|
+
if (createHash("sha256").update(JSON.stringify(payload)).digest("hex") !== planDigest) {
|
|
659
|
+
throw new MemoryBundleOperationError("import_stale_plan");
|
|
660
|
+
}
|
|
661
|
+
return plan;
|
|
662
|
+
}
|
|
663
|
+
function memoryImportOperationLabel(operation) {
|
|
664
|
+
return operation === "prepare" || operation === "apply" || operation === "restore"
|
|
665
|
+
? `import-${operation}`
|
|
666
|
+
: "import-unknown";
|
|
667
|
+
}
|
|
668
|
+
export function writeMemoryBundleFailure(json, operation, code, recovered = false, backupPath) {
|
|
669
|
+
const safeOperation = operation === "export"
|
|
670
|
+
|| operation === "import-prepare"
|
|
671
|
+
|| operation === "import-apply"
|
|
672
|
+
|| operation === "import-restore"
|
|
673
|
+
|| operation === "import-unknown"
|
|
674
|
+
? operation
|
|
675
|
+
: "import-unknown";
|
|
676
|
+
const result = {
|
|
677
|
+
schemaVersion: MEMORY_BUNDLE_CLI_SCHEMA_VERSION,
|
|
678
|
+
operation: `memory-${safeOperation}`,
|
|
679
|
+
status: "failed",
|
|
680
|
+
code,
|
|
681
|
+
message: MEMORY_BUNDLE_FAILURE_MESSAGES[code],
|
|
682
|
+
...(recovered ? { recovered: true } : {}),
|
|
683
|
+
...(backupPath === undefined ? {} : { backupPath }),
|
|
684
|
+
};
|
|
685
|
+
if (json) {
|
|
686
|
+
write(true, result, () => "");
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
process.stderr.write(ui.errorLine(`[${code}] ${result.message}`));
|
|
690
|
+
}
|
|
691
|
+
function renderMemoryBundleExport(result) {
|
|
692
|
+
return `${ui.banner("mono-agent memory", "export")}\n${ui.keyValue([
|
|
693
|
+
["bundle", result.bundlePath],
|
|
694
|
+
["scope", result.scope],
|
|
695
|
+
["memories", String(result.counts.memories)],
|
|
696
|
+
["daily files", String(result.counts.dailyFiles)],
|
|
697
|
+
["entities", String(result.counts.graphEntities)],
|
|
698
|
+
["source fingerprint", result.sourceFingerprint],
|
|
699
|
+
...(result.pendingWork === true ? [["pending work", "yes"]] : []),
|
|
700
|
+
])}\n`;
|
|
701
|
+
}
|
|
702
|
+
function renderMemoryBundleImport(result) {
|
|
703
|
+
return `${ui.banner("mono-agent memory", result.operation)}\n${ui.keyValue([
|
|
704
|
+
["status", result.status],
|
|
705
|
+
...(result.counts === undefined ? [] : [["new memories", String(result.counts.newMemories)]]),
|
|
706
|
+
...(result.counts === undefined ? [] : [["conflicts", String(result.counts.conflictingMemories)]]),
|
|
707
|
+
...(result.derivedAssociationsAdded === undefined
|
|
708
|
+
? []
|
|
709
|
+
: [["derived associations +/-",
|
|
710
|
+
`${result.derivedAssociationsAdded}/${result.derivedAssociationsRemoved ?? 0}`]]),
|
|
711
|
+
...(result.imported === undefined ? [] : [["imported", String(result.imported)]]),
|
|
712
|
+
...(result.skipped === undefined ? [] : [["skipped", String(result.skipped)]]),
|
|
713
|
+
...(result.identical === undefined ? [] : [["identical", String(result.identical)]]),
|
|
714
|
+
...(result.planPath === undefined ? [] : [["plan", result.planPath]]),
|
|
715
|
+
...(result.backupPath === undefined ? [] : [["backup", result.backupPath]]),
|
|
716
|
+
...(result.sourceFingerprint === undefined ? [] : [["source fingerprint", result.sourceFingerprint]]),
|
|
717
|
+
])}\n`;
|
|
718
|
+
}
|
|
210
719
|
async function runReplayAdoption(context, json) {
|
|
211
720
|
const memory = context.config.memory;
|
|
212
721
|
if (memory === undefined || (memory.backend ?? "bujo") === "supermemory"
|