@tpsdev-ai/flair 0.59.0 → 0.63.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 (359) hide show
  1. package/README.md +10 -10
  2. package/SECURITY.md +49 -5
  3. package/config.yaml +23 -12
  4. package/dist/bridges/builtins/mem0.js +63 -28
  5. package/dist/bridges/runtime/execute.js +1 -0
  6. package/dist/bridges/runtime/import-runner.js +12 -0
  7. package/dist/bridges/runtime/load-plugin.js +42 -13
  8. package/dist/bridges/runtime/yaml-loader.js +4 -2
  9. package/dist/bridges/types.js +1 -0
  10. package/dist/build-info.json +3 -3
  11. package/dist/cli.js +1054 -367
  12. package/dist/commands/agent.js +233 -90
  13. package/dist/commands/attention.js +4 -3
  14. package/dist/commands/backup-approval.js +218 -0
  15. package/dist/commands/backup.js +211 -39
  16. package/dist/commands/bootstrap.js +3 -1
  17. package/dist/commands/bridge.js +172 -119
  18. package/dist/commands/deploy.js +71 -8
  19. package/dist/commands/doctor.js +711 -146
  20. package/dist/commands/export.js +57 -23
  21. package/dist/commands/federation.js +787 -82
  22. package/dist/commands/grant.js +5 -6
  23. package/dist/commands/help.js +25 -0
  24. package/dist/commands/hook.js +155 -2
  25. package/dist/commands/idp.js +27 -19
  26. package/dist/commands/import.js +136 -20
  27. package/dist/commands/init.js +469 -200
  28. package/dist/commands/integrity.js +387 -0
  29. package/dist/commands/keys.js +247 -58
  30. package/dist/commands/mcp.js +108 -52
  31. package/dist/commands/memory.js +203 -35
  32. package/dist/commands/migrate-harness-memory.js +3 -2
  33. package/dist/commands/orgevent.js +51 -47
  34. package/dist/commands/presence.js +4 -3
  35. package/dist/commands/principal.js +428 -62
  36. package/dist/commands/quality.js +13 -1
  37. package/dist/commands/reembed.js +141 -17
  38. package/dist/commands/relationship.js +2 -1
  39. package/dist/commands/rem.js +537 -80
  40. package/dist/commands/restore.js +413 -65
  41. package/dist/commands/search.js +6 -4
  42. package/dist/commands/service.js +235 -40
  43. package/dist/commands/soul.js +4 -9
  44. package/dist/commands/status.js +94 -38
  45. package/dist/commands/test.js +7 -3
  46. package/dist/commands/upgrade.js +77 -23
  47. package/dist/commands/workspace.js +13 -11
  48. package/dist/component-env.js +31 -41
  49. package/dist/deploy.js +136 -4
  50. package/dist/doctor-client.js +534 -92
  51. package/dist/engine-version-contract.js +1 -0
  52. package/dist/engine-version.js +23 -3
  53. package/dist/fabric-upgrade.js +12 -2
  54. package/dist/federation/presence-send.js +139 -0
  55. package/dist/federation-verify.js +273 -180
  56. package/dist/hook-install.js +670 -6
  57. package/dist/install/clients.js +171 -35
  58. package/dist/keystore.js +72 -0
  59. package/dist/lib/action-recall-runtime.js +328 -0
  60. package/dist/lib/agent-home-fields.js +132 -0
  61. package/dist/lib/agent-home.js +427 -0
  62. package/dist/lib/agent-id-rule.js +88 -0
  63. package/dist/lib/agent-roster.js +33 -0
  64. package/dist/lib/atomic-write.js +1 -1
  65. package/dist/lib/auth-resolve.js +1069 -60
  66. package/dist/lib/backup-approval-store.js +612 -0
  67. package/dist/lib/backup-artifact.js +343 -0
  68. package/dist/lib/capture-runtime.js +124 -0
  69. package/dist/lib/config-critical-section.js +212 -25
  70. package/dist/lib/connect-phase.js +33 -0
  71. package/dist/lib/credential-status-rule.js +78 -0
  72. package/dist/lib/daemon-liveness.js +43 -11
  73. package/dist/lib/doctor-run.js +75 -37
  74. package/dist/lib/durability-copy.js +10 -0
  75. package/dist/lib/embedding-space-doctor.js +75 -0
  76. package/dist/lib/federation-pair-access.js +4 -0
  77. package/dist/lib/federation-retry-queue.js +283 -0
  78. package/dist/lib/federation-retry-row.js +101 -0
  79. package/dist/lib/flair-agent-role.js +4 -0
  80. package/dist/lib/hub-url.js +12 -0
  81. package/dist/lib/init-admin-pass.js +88 -12
  82. package/dist/lib/init-listener-environ.js +1 -2
  83. package/dist/lib/init-occupied-listener.js +15 -111
  84. package/dist/lib/init-spawn-attribution.js +73 -0
  85. package/dist/lib/init-tcp-probe.js +33 -0
  86. package/dist/lib/instance-identity-row.js +20 -0
  87. package/dist/lib/instruction-event-contract.js +17 -0
  88. package/dist/lib/instruction-event-doctor.js +102 -0
  89. package/dist/lib/launchd-management.js +38 -3
  90. package/dist/lib/listener-table.js +268 -0
  91. package/dist/lib/local-delete-instance.js +27 -0
  92. package/dist/lib/local-instance-pair.js +256 -0
  93. package/dist/lib/mcp-enable.js +1182 -341
  94. package/dist/lib/mcp-oauth-env-core.js +133 -0
  95. package/dist/lib/mcp-oauth-env.js +125 -0
  96. package/dist/lib/mcp-spec.js +17 -1
  97. package/dist/lib/memory-attributes.js +4 -0
  98. package/dist/lib/memory-id-policy.js +46 -0
  99. package/dist/lib/memory-integrity.js +309 -0
  100. package/dist/lib/memory-provider-timeout.js +33 -0
  101. package/dist/lib/memory-purge-response.js +20 -0
  102. package/dist/lib/mqtt-config.js +132 -0
  103. package/dist/lib/mqtt-listener-doctor.js +104 -0
  104. package/dist/lib/open-live-row.js +20 -0
  105. package/dist/lib/ops-table-count.js +25 -0
  106. package/dist/lib/ops-url.js +52 -0
  107. package/dist/lib/owned-pins.js +67 -10
  108. package/dist/lib/peer-status.js +27 -0
  109. package/dist/lib/principal-status.js +29 -0
  110. package/dist/lib/process-start-time.js +76 -12
  111. package/dist/lib/promotion-content-hash.js +20 -0
  112. package/dist/lib/proto-safe-record.js +42 -0
  113. package/dist/lib/record-id-path.js +25 -0
  114. package/dist/lib/reembed-server-support.js +66 -0
  115. package/dist/lib/restore-archive.js +760 -0
  116. package/dist/lib/restore-verify.js +104 -0
  117. package/dist/lib/scheduler-platform.js +10 -6
  118. package/dist/lib/secret-keys.js +25 -0
  119. package/dist/lib/secrets-push.js +50 -22
  120. package/dist/lib/skill-assignment-preflight.js +159 -0
  121. package/dist/lib/skill-seed-pending.js +24 -0
  122. package/dist/lib/skill-seed.js +448 -0
  123. package/dist/lib/skill-tombstone-doctor.js +133 -0
  124. package/dist/lib/soul-scope-fields.js +26 -0
  125. package/dist/lib/stop-start-recovery.js +54 -0
  126. package/dist/lib/uninstall-purge.js +266 -11
  127. package/dist/lib/upgrade-prior-liveness.js +2 -1
  128. package/dist/lib/using-flair-skill.js +87 -0
  129. package/dist/mcp-client-assertion.js +114 -14
  130. package/dist/memory-id-checkpoint.js +347 -0
  131. package/dist/memory-node-compare.js +207 -0
  132. package/dist/mqtt-off-deploy.js +550 -0
  133. package/dist/packages/flair-mcp/src/secret-redaction.js +113 -0
  134. package/dist/rem/promote-policy.js +3 -3
  135. package/dist/rem/restore.js +303 -26
  136. package/dist/rem/runner.js +317 -96
  137. package/dist/rem/scheduler.js +21 -4
  138. package/dist/resources/A2AAdapter.js +131 -178
  139. package/dist/resources/AdminMemory.js +2 -0
  140. package/dist/resources/AdminMemoryCandidates.js +116 -0
  141. package/dist/resources/Agent.js +463 -33
  142. package/dist/resources/AgentCard.js +4 -0
  143. package/dist/resources/AgentKeyRegister.js +248 -0
  144. package/dist/resources/AgentKeyRegistration.js +28 -0
  145. package/dist/resources/AgentReadPosition.js +7 -0
  146. package/dist/resources/AgentSeed.js +238 -107
  147. package/dist/resources/AutoPromoteCandidates.js +413 -78
  148. package/dist/resources/Credential.js +183 -10
  149. package/dist/resources/Federation.js +915 -145
  150. package/dist/resources/FederationRetry.js +140 -0
  151. package/dist/resources/InstructionVersion.js +220 -0
  152. package/dist/resources/Integration.js +300 -25
  153. package/dist/resources/MCPClientMetadata.js +6 -3
  154. package/dist/resources/Memory.js +3300 -758
  155. package/dist/resources/MemoryArchive.js +171 -53
  156. package/dist/resources/MemoryBootstrap.js +122 -61
  157. package/dist/resources/MemoryCandidate.js +37 -3
  158. package/dist/resources/MemoryConsolidate.js +2 -2
  159. package/dist/resources/MemoryDedupStats.js +30 -1
  160. package/dist/resources/MemoryFeed.js +545 -50
  161. package/dist/resources/MemoryGrant.js +21 -1
  162. package/dist/resources/MemoryMaintenance.js +368 -46
  163. package/dist/resources/MemoryPurge.js +348 -0
  164. package/dist/resources/MemoryReflect.js +71 -12
  165. package/dist/resources/MemoryReindex.js +111 -17
  166. package/dist/resources/Message.js +16 -5
  167. package/dist/resources/OAuth.js +342 -48
  168. package/dist/resources/OAuthClient.js +1 -1
  169. package/dist/resources/OrgEvent.js +405 -19
  170. package/dist/resources/OrgEventCatchup.js +7 -0
  171. package/dist/resources/OrgEventMaintenance.js +48 -10
  172. package/dist/resources/PairingToken.js +1 -1
  173. package/dist/resources/Presence.js +166 -51
  174. package/dist/resources/PromoteMemoryCandidate.js +24 -7
  175. package/dist/resources/RecordUsage.js +2 -4
  176. package/dist/resources/Relationship.js +23 -0
  177. package/dist/resources/SemanticSearch.js +63 -32
  178. package/dist/resources/Soul.js +191 -76
  179. package/dist/resources/SoulFeed.js +2 -1
  180. package/dist/resources/TeamDirectory.js +35 -0
  181. package/dist/resources/WorkspaceLatest.js +4 -0
  182. package/dist/resources/WorkspaceState.js +21 -1
  183. package/dist/resources/XAA.js +207 -63
  184. package/dist/resources/a2a-stream.js +313 -0
  185. package/dist/resources/a2a-url.js +4 -5
  186. package/dist/resources/agent-admin.js +10 -1
  187. package/dist/resources/agent-auth.js +138 -83
  188. package/dist/resources/agent-read-position-lib.js +4 -1
  189. package/dist/resources/agent-status-guard.js +9 -7
  190. package/dist/resources/auth-middleware.js +534 -171
  191. package/dist/resources/authority-field-guard.js +9 -11
  192. package/dist/resources/auto-promote-lib.js +8 -5
  193. package/dist/resources/basic-auth-header.js +21 -0
  194. package/dist/resources/bm25-index-service.js +4 -5
  195. package/dist/resources/dedup-cluster.js +6 -1
  196. package/dist/resources/ed25519-auth.js +1 -1
  197. package/dist/resources/embedding-space-guard.js +366 -72
  198. package/dist/resources/embeddings-provider.js +25 -0
  199. package/dist/resources/engine-version-stamp-boot.js +53 -0
  200. package/dist/resources/federation-classify.js +161 -0
  201. package/dist/resources/federation-crypto.js +5 -5
  202. package/dist/resources/federation-retry-lib.js +60 -0
  203. package/dist/resources/grant-visibility.js +135 -0
  204. package/dist/resources/harper-routing.js +83 -0
  205. package/dist/resources/health.js +163 -22
  206. package/dist/resources/host-pointer/registry.js +29 -0
  207. package/dist/resources/host-pointer-adapter.js +1 -0
  208. package/dist/resources/host-source-citation.js +49 -0
  209. package/dist/resources/host-source-visibility.js +7 -6
  210. package/dist/resources/in-process.js +24 -22
  211. package/dist/resources/instance-create-lock.js +17 -0
  212. package/dist/resources/instance-identity.js +23 -0
  213. package/dist/resources/instruction-version-record.js +587 -0
  214. package/dist/resources/internal-authority.js +13 -0
  215. package/dist/resources/key-lock.js +3 -3
  216. package/dist/resources/mcp-handler.js +141 -19
  217. package/dist/resources/mcp-oauth-env-guard.js +36 -0
  218. package/dist/resources/mcp-oauth-flag.js +12 -14
  219. package/dist/resources/mcp-oauth.js +450 -56
  220. package/dist/resources/mcp-tool-arguments.js +4 -6
  221. package/dist/resources/mcp-tools.js +187 -40
  222. package/dist/resources/memory-bootstrap-lib.js +5 -15
  223. package/dist/resources/memory-declared-attributes.js +4 -1
  224. package/dist/resources/memory-deletion-history.js +55 -0
  225. package/dist/resources/memory-durability.js +54 -0
  226. package/dist/resources/memory-embed-hash.js +144 -0
  227. package/dist/resources/memory-embedding-value.js +8 -0
  228. package/dist/resources/memory-host-source.js +32 -7
  229. package/dist/resources/memory-id-guard.js +75 -0
  230. package/dist/resources/memory-redaction.js +236 -0
  231. package/dist/resources/memory-reflect-lib.js +1 -1
  232. package/dist/resources/memory-supplied-vector.js +72 -0
  233. package/dist/resources/memory-write-lock.js +489 -0
  234. package/dist/resources/memory-write-response.js +139 -0
  235. package/dist/resources/memory-write-transaction.js +243 -0
  236. package/dist/resources/migration-boot.js +17 -12
  237. package/dist/resources/migrations/boot-progress.js +25 -0
  238. package/dist/resources/migrations/data-dir.js +90 -19
  239. package/dist/resources/migrations/dir-safety.js +61 -3
  240. package/dist/resources/migrations/embedding-stamp.js +462 -82
  241. package/dist/resources/migrations/export.js +1 -0
  242. package/dist/resources/migrations/graph-heal.js +27 -27
  243. package/dist/resources/migrations/ledger.js +5 -2
  244. package/dist/resources/migrations/lock.js +870 -77
  245. package/dist/resources/migrations/progress.js +71 -10
  246. package/dist/resources/migrations/runner.js +212 -18
  247. package/dist/resources/migrations/snapshot.js +1 -0
  248. package/dist/resources/migrations/source-fields.js +5 -5
  249. package/dist/resources/migrations/state.js +36 -1
  250. package/dist/resources/migrations/status.js +2 -13
  251. package/dist/resources/migrations/synthetic-test-migration.js +81 -12
  252. package/dist/resources/migrations/types.js +26 -1
  253. package/dist/resources/migrations/visibility-backfill.js +113 -72
  254. package/dist/resources/oauth-discovery.js +0 -5
  255. package/dist/resources/object-body-guard.js +40 -0
  256. package/dist/resources/org-event-created-at.js +133 -0
  257. package/dist/resources/org-event-reserved.js +92 -0
  258. package/dist/resources/org-event-write-fault.js +19 -0
  259. package/dist/resources/originator-instance.js +39 -7
  260. package/dist/resources/owner-delete-recheck.js +78 -0
  261. package/dist/resources/owner-field-guard.js +39 -5
  262. package/dist/resources/owner-scoped-write-policy.js +256 -0
  263. package/dist/resources/owner-scoped-writes.js +89 -0
  264. package/dist/resources/path-id-rewrite.js +76 -0
  265. package/dist/resources/presence-internal.js +5 -5
  266. package/dist/resources/presence-receipt.js +236 -0
  267. package/dist/resources/promotion-binding.js +43 -0
  268. package/dist/resources/promotion-stamp.js +143 -17
  269. package/dist/resources/protocol-context.js +189 -0
  270. package/dist/resources/record-owner-guard.js +74 -26
  271. package/dist/resources/record-type-kit.js +2 -4
  272. package/dist/resources/record-types.js +1 -1
  273. package/dist/resources/relay-ops.js +78 -6
  274. package/dist/resources/replay-store.js +96 -19
  275. package/dist/resources/request-target.js +163 -0
  276. package/dist/resources/request-transaction.js +46 -1
  277. package/dist/resources/search-readiness.js +4 -1
  278. package/dist/resources/seed-ids.js +9 -0
  279. package/dist/resources/seed-reservation.js +116 -0
  280. package/dist/resources/semantic-retrieval-core.js +27 -15
  281. package/dist/resources/server-row-validation.js +71 -0
  282. package/dist/resources/skill-manifest.js +24 -14
  283. package/dist/resources/skill-subject.js +53 -0
  284. package/dist/resources/skill-version-write.js +789 -0
  285. package/dist/resources/skill-write-fault.js +20 -0
  286. package/dist/resources/skill-write-policy.js +68 -0
  287. package/dist/resources/skill-write.js +67 -7
  288. package/dist/resources/soul-write-policy.js +26 -7
  289. package/dist/resources/table-helpers.js +10 -7
  290. package/dist/resources/table-subscription-policy.js +518 -85
  291. package/dist/resources/table-subscriptions.js +20 -7
  292. package/dist/resources/team-directory.js +248 -0
  293. package/dist/resources/tool-descriptors/index.js +69 -8
  294. package/dist/resources/txn-pause-point.js +235 -0
  295. package/dist/resources/usage-recording.js +186 -70
  296. package/dist/resources/write-back.js +383 -0
  297. package/dist/resources/write-journal-context.js +5 -0
  298. package/dist/resources/write-journal.js +289 -0
  299. package/dist/src/engine-version-contract.js +1 -0
  300. package/dist/src/keystore.js +72 -0
  301. package/dist/src/lib/agent-home-fields.js +132 -0
  302. package/dist/src/lib/agent-id-rule.js +88 -0
  303. package/dist/src/lib/agent-key-register.js +80 -0
  304. package/dist/src/lib/atomic-write.js +256 -0
  305. package/dist/src/lib/credential-status-rule.js +78 -0
  306. package/dist/src/lib/expired-by-agent.js +37 -0
  307. package/dist/src/lib/federation-retry-row.js +101 -0
  308. package/dist/src/lib/flair-agent-role.js +4 -0
  309. package/dist/src/lib/idp-mapping-rule.js +81 -0
  310. package/dist/src/lib/instance-identity-row.js +20 -0
  311. package/dist/src/lib/instruction-event-contract.js +17 -0
  312. package/dist/src/lib/mcp-oauth-env-core.js +133 -0
  313. package/dist/src/lib/memory-attributes.js +4 -0
  314. package/dist/src/lib/memory-id-policy.js +46 -0
  315. package/dist/src/lib/open-live-row.js +20 -0
  316. package/dist/src/lib/principal-status.js +29 -0
  317. package/dist/src/lib/proto-safe-record.js +42 -0
  318. package/dist/src/lib/reembed-server-support.js +66 -0
  319. package/dist/src/lib/scheduler-platform.js +10 -6
  320. package/dist/src/lib/soul-scope-fields.js +26 -0
  321. package/dist/src/lib/systemd-agent-id.js +38 -0
  322. package/dist/src/rem/promote-policy.js +3 -3
  323. package/dist/src/rem/scheduler.js +21 -4
  324. package/docs/access-control.md +164 -54
  325. package/docs/api-reference.md +165 -32
  326. package/docs/auth.md +46 -30
  327. package/docs/bridges.md +11 -0
  328. package/docs/claude-code.md +37 -7
  329. package/docs/deploying-on-fabric.md +178 -0
  330. package/docs/deployment.md +19 -0
  331. package/docs/embedding-in-a-harper-app.md +17 -15
  332. package/docs/entity-vocabulary.md +3 -6
  333. package/docs/federation.md +61 -3
  334. package/docs/hosted-on-fabric.md +43 -36
  335. package/docs/integrations.md +14 -14
  336. package/docs/mcp-clients.md +12 -7
  337. package/docs/n8n.md +17 -11
  338. package/docs/notes/mcp-agent-auth-consumer.md +16 -13
  339. package/docs/notes/mcp-oauth-model2.md +40 -11
  340. package/docs/openclaw.md +1 -1
  341. package/docs/quickstart-fabric.md +4 -4
  342. package/docs/quickstart.md +12 -4
  343. package/docs/releasing.md +25 -19
  344. package/docs/rem.md +32 -3
  345. package/docs/secrets-and-keys.md +21 -4
  346. package/docs/standalone-local.md +30 -2
  347. package/docs/supply-chain-policy.md +34 -16
  348. package/docs/the-team.md +2 -2
  349. package/docs/upgrade.md +46 -6
  350. package/package.json +24 -12
  351. package/schemas/agent-key-registration.graphql +22 -0
  352. package/schemas/agent.graphql +6 -3
  353. package/schemas/federation.graphql +41 -1
  354. package/schemas/memory.graphql +91 -7
  355. package/schemas/oauth.graphql +19 -0
  356. package/schemas/schema.graphql +2 -0
  357. package/templates/bin/flair-rem-nightly.sh.tmpl +7 -1
  358. package/templates/launchd/start-flair-with-admin-pass.sh +188 -10
  359. package/dist/resources/soul-adk-guard.js +0 -68
@@ -1,6 +1,13 @@
1
- import { resolveAdminUser } from "../lib/auth-resolve.js";
1
+ import { addAdminPassOptions, isLocalBase, resolveAdminUser, sendJsonRequest } from "../lib/auth-resolve.js";
2
+ import { readBackupArtifact } from "../lib/backup-artifact.js";
3
+ import { loadApprovedArchive } from "../lib/backup-approval-store.js";
4
+ import { encodeRecordId } from "../lib/record-id-path.js";
5
+ import { comparePreservedFields } from "../lib/restore-verify.js";
6
+ import { refuseSkillAssignmentWrite, skillSourceIsFilesystemPath } from "../lib/skill-assignment-preflight.js";
7
+ import { suppliesSoulScopeFields } from "../lib/soul-scope-fields.js";
8
+ import { listAgentCandidates, requireLiveListing } from "../rem/restore.js";
2
9
  import * as render from "../render.js";
3
- import { existsSync, readFileSync } from "node:fs";
10
+ import { existsSync } from "node:fs";
4
11
  let cli;
5
12
  /** Bind the cli-locals this module depends on. */
6
13
  export function bindCli(fns) {
@@ -11,14 +18,13 @@ function resolveHttpPort(...args) {
11
18
  }
12
19
  export function register(program) {
13
20
  // ─── flair restore ────────────────────────────────────────────────────────────
14
- program
21
+ addAdminPassOptions(program
15
22
  .command("restore <path>")
16
23
  .description("Import a Flair backup archive")
17
24
  .option("--merge", "Add/update records without deleting existing (default)")
18
- .option("--replace", "Delete all existing data for backed-up agents first, then import")
25
+ .option("--replace", "Delete archived Soul and Memory IDs first, then import")
19
26
  .option("--port <port>", "Harper HTTP port")
20
- .option("--url <url>", "Flair base URL (overrides --port)")
21
- .option("--admin-pass <pass>", "Admin password (or set FLAIR_ADMIN_PASS env)")
27
+ .option("--url <url>", "Flair base URL (overrides --port)"), "Admin password (or set FLAIR_ADMIN_PASS env)")
22
28
  .option("--admin-user <name>", "Admin username for Basic auth (env: FLAIR_ADMIN_USER; default: admin)")
23
29
  .option("--dry-run", "Show what would be imported without making changes")
24
30
  .action(async (backupPath, opts) => {
@@ -35,14 +41,69 @@ export function register(program) {
35
41
  console.error(`Error: backup file not found: ${backupPath}`);
36
42
  process.exit(1);
37
43
  }
38
- const backup = JSON.parse(readFileSync(backupPath, "utf-8"));
39
- if (backup.version !== 1) {
40
- console.error(`Error: unsupported backup version: ${backup.version}`);
41
- process.exit(1);
44
+ // Preflight (flair#2664), before any request in every mode, dry run
45
+ // included: read the archive once, hash and parse that one buffer, and
46
+ // require the hash to equal the digest flair backup wrote to
47
+ // `<archive>.sha256`. The parse refuses ill-formed UTF-8 or JSON, a
48
+ // repeated key or row id, an unsupported version, and rows restore cannot
49
+ // write (src/lib/restore-archive.ts).
50
+ //
51
+ // An archive with no sidecar (flair#2664 slice 1c) is admitted only by an
52
+ // unrevoked approval in this host's approval store
53
+ // (src/lib/backup-approval-store.ts) for the digest of the bytes just
54
+ // read, and only when the stored copy still hashes to that digest; the
55
+ // rows restored are parsed from that rechecked copy. A sidecar-backed
56
+ // archive needs no approval here.
57
+ const artifact = readBackupArtifact(backupPath);
58
+ let archive;
59
+ let admitted;
60
+ if (artifact.ok === false && (artifact.code !== "digest-missing" || artifact.sha256 === undefined)) {
61
+ console.error(`Error: ${artifact.reason}`);
62
+ process.exitCode = 1;
63
+ return;
64
+ }
65
+ if (artifact.ok === false) {
66
+ const approved = loadApprovedArchive(artifact.sha256);
67
+ if (approved.ok === false) {
68
+ const reapprove = approved.code === "store-unsafe" || approved.code === "record-invalid"
69
+ ? ""
70
+ : ` Approve the archive again on this host with flair backup-approval legacy-admit ${backupPath}.`;
71
+ const reason = approved.code === "not-approved"
72
+ ? artifact.reason
73
+ : `archive digest sidecar ${backupPath}.sha256 not found, and ${approved.reason}; restore stopped before any write.${reapprove}`;
74
+ console.error(`Error: ${reason}`);
75
+ process.exitCode = 1;
76
+ return;
77
+ }
78
+ archive = approved.archive;
79
+ admitted = `${approved.sha256} (no digest sidecar; approved on this host by ${approved.record.approvedBy} ` +
80
+ `at ${approved.record.approvedAt}, ${approved.record.admission} admission)`;
81
+ }
82
+ else {
83
+ archive = artifact.archive;
84
+ admitted = `${artifact.sha256} (matches ${artifact.digestPath})`;
85
+ }
86
+ const { agents, memories, souls } = archive;
87
+ const collections = [
88
+ { name: "Agent", rows: agents },
89
+ { name: "Soul", rows: souls },
90
+ { name: "Memory", rows: memories },
91
+ ];
92
+ const failures = [];
93
+ function fail() {
94
+ for (const failure of failures)
95
+ console.error(`Error: ${failure}`);
96
+ process.exitCode = 1;
42
97
  }
43
- const { agents = [], memories = [], souls = [] } = backup;
44
98
  const auth = `Basic ${Buffer.from(`${adminUser}:${adminPass}`).toString("base64")}`;
99
+ // Every preflight read and every restore write targets baseUrl and refuses
100
+ // redirects, so a method-specific redirect is named instead of sent to a
101
+ // location the preflight did not check. The read raises ApiHttpError for a
102
+ // non-2xx reply, which is the shape the reused candidate-listing helper
103
+ // turns into its route guidance.
104
+ const preflightCall = (method, path, body) => sendJsonRequest(new URL(`${baseUrl}${path}`), method, body, auth, isLocalBase(baseUrl), { refuseRedirects: true, withholdResponseBodyDebug: true });
45
105
  console.log(`Restoring from: ${backupPath}`);
106
+ console.log(`Archive SHA-256: ${admitted}`);
46
107
  console.log(`Mode: ${mode}${dryRun ? " (dry run)" : ""}`);
47
108
  console.log(` Agents: ${agents.length}`);
48
109
  console.log(` Memories: ${memories.length}`);
@@ -51,77 +112,364 @@ export function register(program) {
51
112
  console.log("\n✅ Dry run complete — no changes made");
52
113
  return;
53
114
  }
54
- async function adminPut(path, body) {
55
- const res = await fetch(`${baseUrl}${path}`, {
56
- method: "PUT",
57
- headers: { "Content-Type": "application/json", Authorization: auth },
58
- body: JSON.stringify(body),
59
- signal: AbortSignal.timeout(10_000),
60
- });
61
- if (!res.ok) {
62
- const text = await res.text().catch(() => "");
63
- throw new Error(`PUT ${path} failed (${res.status}): ${text}`);
115
+ async function adminWrite(method, path, body) {
116
+ try {
117
+ const res = await fetch(`${baseUrl}${path}`, {
118
+ method,
119
+ headers: { "Content-Type": "application/json", Authorization: auth },
120
+ body: body === undefined ? undefined : JSON.stringify(body),
121
+ redirect: "manual",
122
+ signal: AbortSignal.timeout(10_000),
123
+ });
124
+ if (res.status >= 300 && res.status < 400) {
125
+ return { status: res.status, error: undefined, redirected: true };
126
+ }
127
+ // The refusal name is read from the body, never the outcome: a body
128
+ // that cannot be read keeps the status this write answered with.
129
+ let error;
130
+ try {
131
+ error = errorName(await res.text());
132
+ }
133
+ catch {
134
+ error = undefined;
135
+ }
136
+ return { status: res.status, error, redirected: false };
137
+ }
138
+ catch {
139
+ return { status: undefined, error: undefined, redirected: false };
64
140
  }
65
141
  }
66
- async function adminDelete(path) {
67
- const res = await fetch(`${baseUrl}${path}`, {
68
- method: "DELETE",
69
- headers: { Authorization: auth },
70
- signal: AbortSignal.timeout(10_000),
71
- });
72
- // 404 is fine — already gone
73
- if (!res.ok && res.status !== 404) {
74
- const text = await res.text().catch(() => "");
75
- throw new Error(`DELETE ${path} failed (${res.status}): ${text}`);
142
+ /** A redirect on a restore write, named rather than followed. */
143
+ const redirectFailure = (name, row, method, status) => `${label(name, row)}: ${method} was answered with HTTP ${status} redirect, which restore does not follow; `
144
+ + "no request was sent to the redirected location";
145
+ /** The `error` name in a refusal body, when it carries one. */
146
+ function errorName(text) {
147
+ try {
148
+ const error = JSON.parse(text)?.error;
149
+ return typeof error === "string" ? error : undefined;
150
+ }
151
+ catch {
152
+ return undefined;
76
153
  }
77
154
  }
78
- // Replace mode: delete existing data for these agents first
155
+ const label = (name, row) => `${name} ${row.id} (agent ${name === "Agent" ? row.id : row.agentId})`;
156
+ const diagnostic = (name, row, method, status) => `${label(name, row)}: ${method} failed (HTTP ${status ?? "unavailable"})`;
79
157
  if (mode === "replace") {
80
- console.log("\nDeleting existing data (replace mode)...");
81
- for (const memory of memories) {
82
- if (memory.id)
83
- await adminDelete(`/Memory/${memory.id}`).catch((e) => console.warn(` warn: ${e.message}`));
158
+ // A replace replay sends every archived Soul row back whole after
159
+ // deleting the archived ids. The server refuses a Soul write that
160
+ // supplies a non-empty `scopeTag` or `tags` array (flair#1540) or whose
161
+ // `value` equals a same-agent Memory content or MemoryCandidate claim
162
+ // (resources/soul-write-policy.ts), so a row either rule would refuse
163
+ // must stop the replay before the deletes, or the refused row may lose
164
+ // its live copy (flair#2931, #2941). Merge mode deletes nothing and is
165
+ // not checked here.
166
+ //
167
+ // The learned-content comparison runs against the state each Soul PUT
168
+ // will meet: the archived Memory ids are deleted first, and a failed
169
+ // Memory DELETE stops the run before any Soul delete, so those rows are
170
+ // gone when the Souls are written. They are written back after the Souls,
171
+ // so a live Memory row counts only when its id is not in the archive.
172
+ // Every live candidate counts: replace never deletes MemoryCandidate rows.
173
+ //
174
+ // A concurrent same-agent write between this preflight and the PUT is not
175
+ // covered.
176
+ const LEARNED_REFUSAL = "soul_value_is_learned_content";
177
+ const writtenSouls = souls;
178
+ const refusals = [];
179
+ const scopeRefused = new Set();
180
+ for (const row of writtenSouls) {
181
+ if (!suppliesSoulScopeFields(row))
182
+ continue;
183
+ scopeRefused.add(String(row.id));
184
+ refusals.push(`Error: Soul ${row.id}: the archived row supplies a non-empty scopeTag or tags array, `
185
+ + "which the Soul scope-field rule refuses; edit that row in the archive, then re-run; no rows were deleted");
84
186
  }
85
- for (const soul of souls) {
86
- if (soul.id)
87
- await adminDelete(`/Soul/${soul.id}`).catch((e) => console.warn(` warn: ${e.message}`));
187
+ // The copied predicate's filesystem classification reads this CLI
188
+ // process's tmpdir/TMPDIR/TMP/TEMP and working directory, while the
189
+ // server uses its own environment (resources/skill-provenance.ts), so a
190
+ // filesystem-path source can be durable to one and not the other.
191
+ // Non-dry-run replace refuses every such row before any delete; a
192
+ // non-path source keeps the environment-independent copied predicate.
193
+ const filesystemSourceRefused = new Set();
194
+ for (const row of writtenSouls) {
195
+ const id = String(row.id);
196
+ if (scopeRefused.has(id))
197
+ continue;
198
+ if (!skillSourceIsFilesystemPath(row))
199
+ continue;
200
+ filesystemSourceRefused.add(id);
201
+ refusals.push(`Error: Soul ${row.id}: its skill-assignment source is a filesystem path, whose durability `
202
+ + "the server decides from its own environment; restore without --replace, or edit that "
203
+ + "row's source in the archive, then re-run; no rows were deleted");
88
204
  }
89
- }
90
- // Restore agents
91
- console.log("\nRestoring agents...");
92
- let agentCount = 0;
93
- for (const agent of agents) {
94
- try {
95
- await adminPut(`/Agent/${agent.id}`, agent);
96
- agentCount++;
205
+ // The Soul PUT also refuses a skill-assignment row that the copied
206
+ // predicate refuses. The PUT sees no stored row (`existing` is
207
+ // undefined) only after a successful Soul DELETE; a failed DELETE is
208
+ // recorded and the PUT still runs, so the stored row may still exist.
209
+ const writeRuleRefused = new Set();
210
+ for (const row of writtenSouls) {
211
+ const id = String(row.id);
212
+ if (scopeRefused.has(id) || filesystemSourceRefused.has(id))
213
+ continue;
214
+ const skillDenied = refuseSkillAssignmentWrite(row);
215
+ if (!skillDenied)
216
+ continue;
217
+ writeRuleRefused.add(id);
218
+ let code = "skill-assignment";
219
+ try {
220
+ const body = (await skillDenied.json());
221
+ if (typeof body?.error === "string")
222
+ code = body.error;
223
+ }
224
+ catch {
225
+ /* keep the rule name */
226
+ }
227
+ refusals.push(`Error: Soul ${row.id}: the archived row would be refused by the Soul skill-assignment rule (${code}); `
228
+ + "edit that row in the archive, then re-run; no rows were deleted");
97
229
  }
98
- catch (err) {
99
- console.warn(` warn: agent ${agent.id}: ${err.message}`);
230
+ // Soul id -> value each Soul PUT will send, per owning agent.
231
+ const learnedCandidates = new Map();
232
+ for (const row of writtenSouls) {
233
+ const id = String(row.id);
234
+ if (scopeRefused.has(id) || filesystemSourceRefused.has(id) || writeRuleRefused.has(id))
235
+ continue;
236
+ if (typeof row.value !== "string" || row.value === "")
237
+ continue;
238
+ if (typeof row.agentId !== "string" || row.agentId === "")
239
+ continue;
240
+ let byValue = learnedCandidates.get(row.agentId);
241
+ if (byValue === undefined) {
242
+ byValue = new Map();
243
+ learnedCandidates.set(row.agentId, byValue);
244
+ }
245
+ const ids = byValue.get(row.value) ?? [];
246
+ ids.push(id);
247
+ byValue.set(row.value, ids);
100
248
  }
101
- }
102
- // Restore souls before memories: refuseLearnedSoulWrite matches Memory text.
103
- console.log("Restoring souls...");
104
- let soulCount = 0;
105
- for (const soul of souls) {
249
+ const learnedRefusal = (soulId, table, row) => {
250
+ const field = table === "Memory" ? "content" : "claim";
251
+ const subject = row?.id === undefined || row.id === null || row.id === ""
252
+ ? `a ${table} row without an id`
253
+ : `${table} ${row.id}`;
254
+ return `Error: Soul ${soulId}: its value equals the ${field} of the same agent's ${subject}, `
255
+ + `which the Soul learned-content rule refuses (${LEARNED_REFUSAL}); `
256
+ + `remove or edit that ${table} row or the archived Soul's value, then re-run; no rows were deleted`;
257
+ };
258
+ // A live Memory row whose id is in the archive is deleted before the
259
+ // Souls are written, so it does not count as a survivor.
260
+ const archivedMemoryIds = new Set(memories.filter((row) => row?.id !== undefined && row.id !== null && row.id !== "").map((row) => String(row.id)));
106
261
  try {
107
- await adminPut(`/Soul/${soul.id}`, soul);
108
- soulCount++;
262
+ for (const [agentId, byValue] of learnedCandidates) {
263
+ const liveMemories = requireLiveListing(await preflightCall("GET", `/Memory?agentId=${encodeURIComponent(agentId)}`), "Memory", agentId);
264
+ const survivorByContent = new Map();
265
+ for (const memory of liveMemories) {
266
+ if (!memory || typeof memory !== "object" || Array.isArray(memory)) {
267
+ throw new Error(`the Memory listing for agent ${agentId} carries a row that is not an object`);
268
+ }
269
+ if (memory.agentId !== agentId)
270
+ continue;
271
+ if (typeof memory.content !== "string")
272
+ continue;
273
+ const id = memory.id === undefined || memory.id === null || memory.id === "" ? undefined : String(memory.id);
274
+ if (id !== undefined && archivedMemoryIds.has(id))
275
+ continue;
276
+ if (!survivorByContent.has(memory.content))
277
+ survivorByContent.set(memory.content, memory);
278
+ }
279
+ const unmatched = new Map(byValue);
280
+ for (const [value, soulIds] of byValue) {
281
+ const match = survivorByContent.get(value);
282
+ if (match === undefined)
283
+ continue;
284
+ for (const soulId of soulIds)
285
+ refusals.push(learnedRefusal(soulId, "Memory", match));
286
+ unmatched.delete(value);
287
+ }
288
+ if (unmatched.size === 0)
289
+ continue;
290
+ // The admin candidate route lists ids only; each listed row is read
291
+ // until every unmatched value has matched, to compare its claim
292
+ // exactly.
293
+ const candidates = await listAgentCandidates(preflightCall, agentId);
294
+ for (const candidate of candidates) {
295
+ if (unmatched.size === 0)
296
+ break;
297
+ const row = await preflightCall("GET", `/MemoryCandidate/${encodeRecordId(candidate.id)}`);
298
+ if (!row || typeof row !== "object" || Array.isArray(row) || typeof row.claim !== "string") {
299
+ throw new Error(`MemoryCandidate ${candidate.id} could not be read as a row with a claim`);
300
+ }
301
+ if (row.agentId !== agentId)
302
+ continue;
303
+ const soulIds = unmatched.get(row.claim);
304
+ if (soulIds === undefined)
305
+ continue;
306
+ for (const soulId of soulIds)
307
+ refusals.push(learnedRefusal(soulId, "MemoryCandidate", candidate));
308
+ unmatched.delete(row.claim);
309
+ }
310
+ }
109
311
  }
110
312
  catch (err) {
111
- console.warn(` warn: soul ${soul.id}: ${err.message}`);
313
+ // A refusal already collected stays visible even when a later listing
314
+ // read fails: the operator should see each refusal collected so far,
315
+ // not only the error that stopped it (flair#2941).
316
+ for (const refusal of refusals)
317
+ console.error(refusal);
318
+ console.error(`Error: ${err?.message ?? String(err)}`);
319
+ console.error("Error: the replace stopped before any delete: a Soul write rule could not be checked against "
320
+ + "the live rows; check the target's Memory listing and MemoryCandidate listing responses, "
321
+ + "then re-run. No rows were deleted.");
322
+ process.exitCode = 1;
323
+ return;
324
+ }
325
+ if (refusals.length > 0) {
326
+ for (const refusal of refusals)
327
+ console.error(refusal);
328
+ process.exitCode = 1;
329
+ return;
330
+ }
331
+ console.log("\nDeleting existing data (replace mode)...");
332
+ // Memory rows go first: the learned-content check above assumes the
333
+ // archived Memory ids are gone before a Soul write. A Memory DELETE the
334
+ // server refuses leaves that row in place, so stop here rather than
335
+ // delete a Soul whose PUT the surviving row would refuse.
336
+ // Archived Memories whose DELETE succeeded or whose outcome is unknown:
337
+ // if a later DELETE fails, attempt their write-back, verify each successful
338
+ // PUT, and report any PUT or verification failure by id.
339
+ const memoriesToRestore = [];
340
+ for (const row of memories) {
341
+ const { status, redirected } = await adminWrite("DELETE", `/Memory/${encodeRecordId(row.id)}`);
342
+ if (redirected) {
343
+ failures.push(redirectFailure("Memory", row, "DELETE", status));
344
+ }
345
+ else if (status === undefined || (status !== 404 && (status < 200 || status >= 300))) {
346
+ failures.push(diagnostic("Memory", row, "DELETE", status));
347
+ if (status === undefined)
348
+ memoriesToRestore.push(row);
349
+ }
350
+ else if (status >= 200 && status < 300) {
351
+ memoriesToRestore.push(row);
352
+ }
353
+ }
354
+ if (failures.length > 0) {
355
+ console.error("Error: a Memory DELETE failed; no Soul row was deleted.");
356
+ // Attempt the archived Memory write-backs, verify each successful PUT,
357
+ // and report any PUT or verification failure by id.
358
+ for (const row of memoriesToRestore) {
359
+ const { status, redirected } = await adminWrite("PUT", `/Memory/${encodeRecordId(row.id)}`, row);
360
+ if (redirected || status === undefined || status < 200 || status >= 300) {
361
+ failures.push(`${label("Memory", row)}: could not be restored after a later DELETE failed (`
362
+ + `${redirected ? `PUT was answered with HTTP ${status} redirect, which restore does not follow` : `PUT HTTP ${status ?? "unavailable"}`})`);
363
+ continue;
364
+ }
365
+ let problem;
366
+ try {
367
+ const res = await fetch(`${baseUrl}/Memory/${encodeRecordId(row.id)}`, {
368
+ headers: { Authorization: auth },
369
+ redirect: "manual",
370
+ signal: AbortSignal.timeout(10_000),
371
+ });
372
+ if (res.status >= 300 && res.status < 400) {
373
+ problem = `GET verification was answered with HTTP ${res.status} redirect, which restore does not follow`;
374
+ }
375
+ else if (!res.ok) {
376
+ problem = `GET verification failed (HTTP ${res.status})`;
377
+ }
378
+ else {
379
+ const restored = await res.json();
380
+ const mismatched = comparePreservedFields("Memory", row, restored);
381
+ if (!restored || typeof restored !== "object" || Array.isArray(restored)) {
382
+ problem = "GET verification returned a row that is not an object";
383
+ }
384
+ else if (restored.id !== row.id) {
385
+ problem = "GET verification returned a different id";
386
+ }
387
+ else if (mismatched.length > 0) {
388
+ problem = `GET verification failed (field mismatch: ${mismatched.join(", ")})`;
389
+ }
390
+ }
391
+ }
392
+ catch {
393
+ problem = "GET verification failed";
394
+ }
395
+ if (problem !== undefined) {
396
+ failures.push(`${label("Memory", row)}: could not be restored after a later DELETE failed: ${problem}`);
397
+ }
398
+ }
399
+ fail();
400
+ return;
401
+ }
402
+ for (const row of souls) {
403
+ const { status, redirected } = await adminWrite("DELETE", `/Soul/${encodeRecordId(row.id)}`);
404
+ if (redirected) {
405
+ failures.push(redirectFailure("Soul", row, "DELETE", status));
406
+ }
407
+ else if (status === undefined || (status !== 404 && (status < 200 || status >= 300))) {
408
+ failures.push(diagnostic("Soul", row, "DELETE", status));
409
+ }
112
410
  }
113
411
  }
114
- console.log("Restoring memories...");
115
- let memoryCount = 0;
116
- for (const memory of memories) {
117
- try {
118
- await adminPut(`/Memory/${memory.id}`, memory);
119
- memoryCount++;
412
+ for (const { name, rows } of collections) {
413
+ console.log(`Restoring ${name} records...`);
414
+ for (const row of rows) {
415
+ const { status, error, redirected } = await adminWrite("PUT", `/${name}/${encodeRecordId(row.id)}`, row);
416
+ if (redirected) {
417
+ failures.push(redirectFailure(name, row, "PUT", status));
418
+ }
419
+ else if (status === undefined || status < 200 || status >= 300) {
420
+ // A failed Soul write appends the refusal name the server returned,
421
+ // so a learned-content 403 is named rather than read as an auth
422
+ // failure (flair#2931, #2941).
423
+ failures.push(`${diagnostic(name, row, "PUT", status)}${name === "Soul" && error ? `: ${error}` : ""}`);
424
+ }
120
425
  }
121
- catch (err) {
122
- console.warn(` warn: memory ${memory.id}: ${err.message}`);
426
+ }
427
+ for (const { name, rows } of collections) {
428
+ for (const row of rows) {
429
+ const path = `/${name}/${encodeRecordId(row.id)}`;
430
+ let status;
431
+ let restored;
432
+ let redirect;
433
+ try {
434
+ const res = await fetch(`${baseUrl}${path}`, {
435
+ headers: { Authorization: auth },
436
+ redirect: "manual",
437
+ signal: AbortSignal.timeout(10_000),
438
+ });
439
+ status = res.status;
440
+ if (res.status >= 300 && res.status < 400) {
441
+ redirect = res.status;
442
+ throw new Error();
443
+ }
444
+ if (!res.ok)
445
+ throw new Error();
446
+ restored = await res.json();
447
+ if (!restored || typeof restored !== "object" || Array.isArray(restored)
448
+ || restored.id !== row.id
449
+ || (name !== "Agent" && restored.agentId !== row.agentId)) {
450
+ throw new Error();
451
+ }
452
+ }
453
+ catch {
454
+ failures.push(redirect === undefined
455
+ ? `${diagnostic(name, row, "GET", status)}: verification failed`
456
+ : `${label(name, row)}: GET verification was answered with HTTP ${redirect} redirect, which restore does not follow`);
457
+ continue;
458
+ }
459
+ // Report mismatched field names without mismatched content values.
460
+ const mismatched = comparePreservedFields(name, row, restored);
461
+ if (mismatched.length > 0) {
462
+ failures.push(`${label(name, row)}: GET verification failed (field mismatch: ${mismatched.join(", ")})`);
463
+ }
123
464
  }
124
465
  }
466
+ if (failures.length) {
467
+ fail();
468
+ return;
469
+ }
470
+ const agentCount = agents.length;
471
+ const memoryCount = memories.length;
472
+ const soulCount = souls.length;
125
473
  console.log(`\n${render.icons.ok} ${render.wrap(render.c.green, "Restore complete")}`);
126
474
  console.log(render.kv("Agents restored", `${render.wrap(render.c.bold, String(agentCount))}${render.wrap(render.c.dim, `/${agents.length}`)}`));
127
475
  console.log(render.kv("Memories restored", `${render.wrap(render.c.bold, String(memoryCount))}${render.wrap(render.c.dim, `/${memories.length}`)}`));
@@ -1,5 +1,6 @@
1
- import { buildEd25519Auth, resolveKeyPath } from "../lib/auth-resolve.js";
1
+ import { buildEd25519Auth, requestTarget, requestUrl, resolveKeyPath } from "../lib/auth-resolve.js";
2
2
  import * as render from "../render.js";
3
+ import { DURABILITY_CAVEAT } from "../lib/durability-copy.js";
3
4
  let cli;
4
5
  /** Bind the cli-locals this module depends on. */
5
6
  export function bindCli(fns) {
@@ -100,7 +101,7 @@ export function register(program) {
100
101
  .option("--scoring <mode>", "Scoring mode: raw (default) uses cosine similarity/BM25 only; composite re-ranks by durability/recency/retrieval (measurably hurts precision as of flair#623 — opt-in only)", "raw")
101
102
  .option("--min-score <n>", "Drop results below this score (0..1)", "0")
102
103
  // Client-side filters (applied after server response)
103
- .option("--durability <level>", "Filter to permanent|persistent|standard|ephemeral (client-side)")
104
+ .option("--durability <level>", `Filter results by durability (permanent/persistent/standard/ephemeral; comma-separated; client-side). ${DURABILITY_CAVEAT}`)
104
105
  .option("--source <name>", "Filter by source/agentId (client-side)")
105
106
  // Output modes
106
107
  .option("--explain", "Show score breakdown (raw, composite, durability, age, usage) per hit — also added to --json output as _explain")
@@ -113,10 +114,11 @@ export function register(program) {
113
114
  process.exit(2);
114
115
  }
115
116
  const baseUrl = resolveBaseUrl(opts);
117
+ const url = requestUrl(baseUrl, "/SemanticSearch");
116
118
  const headers = { "content-type": "application/json" };
117
119
  const keyPath = opts.key || resolveKeyPath(agentId);
118
120
  if (keyPath) {
119
- headers["authorization"] = buildEd25519Auth(agentId, "POST", "/SemanticSearch", keyPath);
121
+ headers["authorization"] = buildEd25519Auth(agentId, "POST", requestTarget(url), keyPath);
120
122
  }
121
123
  // Build payload from CLI options. Server validates types.
122
124
  const payload = {
@@ -141,7 +143,7 @@ export function register(program) {
141
143
  const minScore = Number.parseFloat(opts.minScore ?? "0");
142
144
  if (Number.isFinite(minScore) && minScore > 0)
143
145
  payload.minScore = minScore;
144
- const res = await fetch(`${baseUrl}/SemanticSearch`, {
146
+ const res = await fetch(url, {
145
147
  method: "POST",
146
148
  headers,
147
149
  body: JSON.stringify(payload),