@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,8 +1,13 @@
1
1
  import nacl from "tweetnacl";
2
- import { existsSync, mkdirSync, writeFileSync, readFileSync, chmodSync } from "node:fs";
2
+ import { existsSync, mkdirSync, writeFileSync, readFileSync, chmodSync, unlinkSync, realpathSync } from "node:fs";
3
3
  import { join } from "node:path";
4
4
  import * as render from "../render.js";
5
- import { resolveAdminPassFromSources, defaultKeysDir, resolveLocalAdminPass, resolveAdminUser, resolveKeyPath, authFetch, } from "../lib/auth-resolve.js";
5
+ import { addAdminPassOptions, credentialsInHeader, defaultKeysDir, describeHttpFailure, resolveLocalAdminPass, resolveAdminUser, resolveKeyPath, authFetch, authFetchWithSentCredentials, } from "../lib/auth-resolve.js";
6
+ import { encodeRecordId } from "../lib/record-id-path.js";
7
+ import { resolveLocalDeleteInstance } from "../lib/local-delete-instance.js";
8
+ import { invalidAgentIdMessage, isValidAgentId } from "../lib/agent-id-rule.js";
9
+ import { agentHomeEndpoint, resolveTargetInstanceId, runAgentHomeStamp, stampLeftoverLines, } from "../lib/agent-home.js";
10
+ import { confirmedPurgeIds } from "../lib/memory-purge-response.js";
6
11
  let cli;
7
12
  /** Bind shared CLI helpers. cli.ts calls this immediately before register(program). */
8
13
  export function bindCli(fns) {
@@ -12,12 +17,48 @@ const api = (method, path, body, options) => cli.api(method, path, body, options
12
17
  const b64url = (bytes) => cli.b64url(bytes);
13
18
  const privKeyPath = (agentId, keysDir) => cli.privKeyPath(agentId, keysDir);
14
19
  const pubKeyPath = (agentId, keysDir) => cli.pubKeyPath(agentId, keysDir);
20
+ /**
21
+ * flair#2479 — check each key's canonical target before unlinking.
22
+ * Return successful unlinks; invalid ids require manual cleanup.
23
+ */
24
+ export function removeAgentKeyFiles(agentId, keysDir) {
25
+ if (!isValidAgentId(agentId))
26
+ return { removed: [], manual: true };
27
+ let root;
28
+ try {
29
+ root = realpathSync(keysDir);
30
+ }
31
+ catch {
32
+ return { removed: [], manual: false }; // directory resolution failed
33
+ }
34
+ const removed = [];
35
+ for (const name of [`${agentId}.key`, `${agentId}.pub`, `${agentId}.key.bak`]) {
36
+ let real;
37
+ try {
38
+ real = realpathSync(join(keysDir, name));
39
+ }
40
+ catch {
41
+ continue; // candidate resolution failed
42
+ }
43
+ if (real !== join(root, name))
44
+ continue; // unexpected canonical target; skip
45
+ try {
46
+ unlinkSync(real);
47
+ removed.push(real);
48
+ }
49
+ catch { /* best effort */ }
50
+ }
51
+ return { removed, manual: false };
52
+ }
15
53
  const shouldShowInlineSecretWarning = (optValue, fromEnv, secretFlagNames, flagName) => cli.shouldShowInlineSecretWarning(optValue, fromEnv, secretFlagNames, flagName);
16
54
  const resolveHttpPort = (opts, mode) => cli.resolveHttpPort(opts, mode);
17
55
  const resolveOpsPort = (opts) => cli.resolveOpsPort(opts);
56
+ const resolveAgentHomeTarget = (opts) => cli.resolveAgentHomeTarget(opts);
18
57
  const resolveEffectiveOpsUrl = (opts) => cli.resolveEffectiveOpsUrl(opts);
19
- const seedAgentViaOpsApi = (opsPortOrUrl, agentId, pubKeyB64url, adminUser, adminPass) => cli.seedAgentViaOpsApi(opsPortOrUrl, agentId, pubKeyB64url, adminUser, adminPass);
58
+ const seedAgentWithLocalHome = (opsPortOrUrl, agentId, pubKeyB64url, adminUser, adminPass) => cli.seedAgentWithLocalHome(opsPortOrUrl, agentId, pubKeyB64url, adminUser, adminPass);
20
59
  const agentRecordIsAdmin = (record) => cli.agentRecordIsAdmin(record);
60
+ const INLINE_ADMIN_PASS_WARNING = "warning: --admin-pass passed inline. Use FLAIR_ADMIN_PASS without typing its value into a recorded " +
61
+ "shell line (for example, read it from the admin-pass file).";
21
62
  /** Operations API URL, same shape as `seedAgentViaOpsApi` (trailing slash). */
22
63
  function opsApiUrl(opsPortOrUrl) {
23
64
  return typeof opsPortOrUrl === "number"
@@ -165,19 +206,25 @@ async function readStoredAgent(opsPortOrUrl, id, adminUser, adminPass) {
165
206
  export function register(program) {
166
207
  // ─── flair agent ─────────────────────────────────────────────────────────────
167
208
  const agent = program.command("agent").description("Manage Flair agents");
168
- agent
209
+ addAdminPassOptions(agent
169
210
  .command("add <id>")
170
211
  .description("Register a new agent. Refuses an id whose Agent record already exists")
171
212
  .option("--name <name>", "Display name (defaults to id)")
172
- .option("--port <port>", "Harper HTTP port")
173
- .option("--admin-pass <pass>", "Admin password for registration")
174
- .option("--admin-pass-file <path>", "Read the admin password from a file (chmod 600 enforced). Preferred over inline --admin-pass — keeps the secret out of ps and shell history; works for remote targets too (an explicit flag is operator intent).")
213
+ .option("--port <port>", "Harper HTTP port"), "Admin password for registration", {
214
+ adminPassFileHelp: "Read the admin password from a file (owner-only permissions enforced). Preferred over inline --admin-pass — keeps the secret out of ps and shell history; works for remote targets too (an explicit flag is operator intent).",
215
+ })
175
216
  .option("--admin-user <name>", "Admin username for Basic auth (env: FLAIR_ADMIN_USER; default: admin)")
176
217
  .option("--keys-dir <dir>", "Directory for Ed25519 keys")
177
218
  .option("--ops-port <port>", "Harper operations API port")
178
- .option("--target <url>", "Remote Flair REST URL; derives the ops API URL (port-1) to seed the Agent there (env: FLAIR_TARGET)")
219
+ .option("--target <url>", "Remote Flair REST URL; derives ops URL (HTTPS no port/:443 → Fabric ops :9925; HTTP no port/:80 → :19925; other ports 2–65535 → port-1; port 1 refused; env: FLAIR_TARGET)")
179
220
  .option("--ops-target <url>", "Explicit ops API URL to seed the Agent on (env: FLAIR_OPS_TARGET; bypasses port derivation)")
180
221
  .action(async (id, opts) => {
222
+ // flair#2359 — the ONE agent-ID rule, before any key file is written or
223
+ // any insert is attempted. Refuse a non-matching id by name.
224
+ if (!isValidAgentId(id)) {
225
+ console.error(`Error: ${invalidAgentIdMessage(id)}`);
226
+ process.exit(1);
227
+ }
181
228
  const httpPort = resolveHttpPort(opts);
182
229
  const opsPort = resolveOpsPort(opts);
183
230
  const keysDir = opts.keysDir ?? defaultKeysDir();
@@ -189,29 +236,13 @@ export function register(program) {
189
236
  // `flair import`: explicit --ops-target > derive from --target > localhost.
190
237
  const seedOpsTarget = resolveEffectiveOpsUrl({ target: opts.target, opsTarget: opts.opsTarget }) ?? opsPort;
191
238
  const isRemoteTarget = typeof seedOpsTarget === "string";
192
- // flair#1259 / #1910 — --admin-pass-file and --admin-pass resolve through
193
- // the ONE resolver (resolveAdminPassFromSources), the file read in-process
194
- // via readAdminPassFileSecure so the secret never appears in ps or shell
195
- // history. Combining the file and the flag is a usage error (the flag used
196
- // to silently win). This does NOT weaken the #1085 remote guard below: an
197
- // explicit flag naming a file IS operator intent toward this target,
198
- // exactly like an explicit inline --admin-pass — what the guard blocks is
199
- // the AMBIENT env/local-file fallbacks silently traveling to a third-party
200
- // host.
201
- let explicitPass;
202
- try {
203
- explicitPass =
204
- resolveAdminPassFromSources({
205
- adminPassFile: opts.adminPassFile,
206
- adminPass: opts.adminPass,
207
- envPass: undefined,
208
- }) || undefined;
209
- }
210
- catch (err) {
211
- console.error(`Error: ${err.message}`);
212
- process.exit(1);
213
- }
214
- opts.adminPass = explicitPass;
239
+ // flair#1259 / #1910 — the pair is resolved by addAdminPassOptions' preAction
240
+ // hook, before this action runs. This does NOT weaken the #1085 remote guard
241
+ // below: an explicit flag naming a file IS operator intent toward this
242
+ // target, exactly like an explicit inline --admin-pass — what the guard
243
+ // blocks is the AMBIENT env/local-file fallbacks silently traveling to a
244
+ // third-party host.
245
+ //
215
246
  // #590 — local convenience fallback: FLAIR_ADMIN_PASS env, then the secure
216
247
  // ~/.flair/admin-pass file `flair init` already writes (mode 0600). Never
217
248
  // applied for a remote target — see resolveLocalAdminPass.
@@ -264,7 +295,7 @@ export function register(program) {
264
295
  pubKeyB64url = b64url(kp.publicKey);
265
296
  console.log(`Keypair written: ${privPath}`);
266
297
  }
267
- await seedAgentViaOpsApi(seedOpsTarget, id, pubKeyB64url, adminUser, adminPass);
298
+ await seedAgentWithLocalHome(seedOpsTarget, id, pubKeyB64url, adminUser, adminPass);
268
299
  const stored = await readStoredAgent(seedOpsTarget, id, adminUser, adminPass);
269
300
  if (!stored || stored.publicKey !== pubKeyB64url) {
270
301
  console.error(agentKeyNotStoredMessage(id, stored));
@@ -283,10 +314,7 @@ export function register(program) {
283
314
  console.log(` Note: an OAuth /mcp connector maps its own IdP subject to an Agent (distinct from '${id}' by default).\n` +
284
315
  ` To point a connector at '${id}': flair mcp enable --principal ${id} --idp-subject <your-idp-login>`);
285
316
  });
286
- agent
287
- .command("list")
288
- .description("List all agents")
289
- .option("--admin-pass <pass>", "Admin password (or set FLAIR_ADMIN_PASS env)")
317
+ addAdminPassOptions(agent.command("list").description("List all agents"), "Admin password (or set FLAIR_ADMIN_PASS env)")
290
318
  .option("--admin-user <name>", "Admin username for Basic auth (env: FLAIR_ADMIN_USER; default: admin)")
291
319
  .option("--agent <id>", "Agent ID to authenticate as via Ed25519 (or FLAIR_AGENT_ID env) when no admin pass")
292
320
  .option("--keys-dir <dir>", "Directory holding the agent's Ed25519 key")
@@ -294,11 +322,8 @@ export function register(program) {
294
322
  .option("--json", "Emit raw JSON array (also: pipe + FLAIR_OUTPUT=json)")
295
323
  .action(async (opts) => {
296
324
  const port = resolveHttpPort(opts);
297
- // fromEnv is true ONLY when the resolved value came from env (no inline override).
298
- const adminPassFromEnv = !opts.adminPass && (!!process.env.FLAIR_ADMIN_PASS || !!process.env.HDB_ADMIN_PASSWORD);
299
- if (shouldShowInlineSecretWarning(opts.adminPass, adminPassFromEnv, new Set(["--admin-pass"]), "--admin-pass")) {
300
- console.error("warning: --admin-pass passed inline. Consider --admin-pass-from <file> or FLAIR_ADMIN_PASS env " +
301
- "to keep secrets out of shell history.");
325
+ if (shouldShowInlineSecretWarning(opts.inlineAdminPass, false, new Set(["--admin-pass"]), "--admin-pass")) {
326
+ console.error(INLINE_ADMIN_PASS_WARNING);
302
327
  }
303
328
  const adminPass = opts.adminPass ?? process.env.FLAIR_ADMIN_PASS ?? process.env.HDB_ADMIN_PASSWORD ?? "";
304
329
  const mode = render.resolveOutputMode(opts);
@@ -319,7 +344,8 @@ export function register(program) {
319
344
  });
320
345
  if (!res.ok) {
321
346
  const text = await res.text().catch(() => "");
322
- console.error(`${render.icons.error} ${res.status} ${text}`);
347
+ const sent = credentialsInHeader(`Basic ${auth}`);
348
+ console.error(`${render.icons.error} ${describeHttpFailure(res.status, text, sent.values, sent.withhold)}`);
323
349
  process.exit(1);
324
350
  }
325
351
  agents = await res.json();
@@ -334,13 +360,14 @@ export function register(program) {
334
360
  const agentId = opts.agent ?? process.env.FLAIR_AGENT_ID;
335
361
  const keysDir = opts.keysDir ?? process.env.FLAIR_KEY_DIR ?? defaultKeysDir();
336
362
  let res;
363
+ let sent = { values: [], withhold: false };
337
364
  if (agentId) {
338
365
  const keyPath = resolveKeyPath(agentId) ?? join(keysDir, `${agentId}.key`);
339
366
  if (!existsSync(keyPath)) {
340
367
  console.error(`${render.icons.error} no key for agent '${agentId}' (looked in ${keysDir}). Pass --admin-pass, --keys-dir, or a registered --agent.`);
341
368
  process.exit(1);
342
369
  }
343
- res = await authFetch(baseUrl, agentId, keyPath, "GET", "/Agent");
370
+ ({ res, sent } = await authFetchWithSentCredentials(baseUrl, agentId, keyPath, "GET", "/Agent"));
344
371
  }
345
372
  else {
346
373
  // No agent identity available either. Try anonymously, but if it 403s
@@ -356,7 +383,7 @@ export function register(program) {
356
383
  console.error(` or ${render.wrap(render.c.cyan, "--admin-pass")} / FLAIR_ADMIN_PASS for the admin view.`);
357
384
  }
358
385
  else {
359
- console.error(`${render.icons.error} ${res.status} ${text}`);
386
+ console.error(`${render.icons.error} ${describeHttpFailure(res.status, text, sent.values, sent.withhold)}`);
360
387
  }
361
388
  process.exit(1);
362
389
  }
@@ -385,7 +412,7 @@ export function register(program) {
385
412
  .description("Show agent details")
386
413
  .option("--json", "Emit raw JSON response (also: pipe + FLAIR_OUTPUT=json)")
387
414
  .action(async (id, opts) => {
388
- const out = await api("GET", `/Agent/${id}`);
415
+ const out = await api("GET", `/Agent/${encodeRecordId(id)}`);
389
416
  const mode = render.resolveOutputMode(opts);
390
417
  if (mode === "json") {
391
418
  console.log(render.asJSON(out));
@@ -419,22 +446,18 @@ export function register(program) {
419
446
  console.log(render.kv("updated", `${render.relativeTime(out.updatedAt)} ${render.wrap(render.c.dim, `(${out.updatedAt})`)}`));
420
447
  }
421
448
  });
422
- agent
449
+ addAdminPassOptions(agent
423
450
  .command("rotate-key <id>")
424
451
  .description("Rotate an agent's Ed25519 keypair")
425
452
  .option("--port <port>", "Harper HTTP port")
426
- .option("--ops-port <port>", "Harper operations API port")
427
- .option("--admin-pass <pass>", "Admin password (or set FLAIR_ADMIN_PASS env)")
453
+ .option("--ops-port <port>", "Harper operations API port"), "Admin password (or set FLAIR_ADMIN_PASS env)")
428
454
  .option("--admin-user <name>", "Admin username for Basic auth (env: FLAIR_ADMIN_USER; default: admin)")
429
455
  .option("--keys-dir <dir>", "Directory for Ed25519 keys")
430
456
  .action(async (id, opts) => {
431
457
  const httpPort = resolveHttpPort(opts);
432
458
  const opsPort = resolveOpsPort(opts);
433
- // fromEnv is true ONLY when the resolved value came from env (no inline override).
434
- const adminPassFromEnv = !opts.adminPass && !!process.env.FLAIR_ADMIN_PASS;
435
- if (shouldShowInlineSecretWarning(opts.adminPass, adminPassFromEnv, new Set(["--admin-pass"]), "--admin-pass")) {
436
- console.error("warning: --admin-pass passed inline. Consider --admin-pass-from <file> or FLAIR_ADMIN_PASS env " +
437
- "to keep secrets out of shell history.");
459
+ if (shouldShowInlineSecretWarning(opts.inlineAdminPass, false, new Set(["--admin-pass"]), "--admin-pass")) {
460
+ console.error(INLINE_ADMIN_PASS_WARNING);
438
461
  }
439
462
  const adminPass = opts.adminPass ?? process.env.FLAIR_ADMIN_PASS ?? "";
440
463
  const adminUser = resolveAdminUser(opts.adminUser);
@@ -491,7 +514,7 @@ export function register(program) {
491
514
  // Verify new key works
492
515
  console.log(`Verifying new Ed25519 auth...`);
493
516
  const httpUrl = `http://127.0.0.1:${httpPort}`;
494
- const verifyRes = await authFetch(httpUrl, id, currentPrivPath, "GET", `/Agent/${id}`);
517
+ const verifyRes = await authFetch(httpUrl, id, currentPrivPath, "GET", `/Agent/${encodeRecordId(id)}`);
495
518
  if (!verifyRes.ok) {
496
519
  console.error(`⚠️ Auth verification failed (${verifyRes.status}). Old key is backed up at: ${backupPrivPath}`);
497
520
  process.exit(1);
@@ -503,18 +526,16 @@ export function register(program) {
503
526
  console.log(` Old key backup: ${backupPrivPath}`);
504
527
  });
505
528
  // ─── flair agent remove ──────────────────────────────────────────────────────
506
- agent
529
+ addAdminPassOptions(agent
507
530
  .command("remove <id>")
508
531
  .description("Remove an agent and all its data from Flair")
509
532
  .option("--keep-keys", "Do not delete key files from disk")
510
533
  .option("--port <port>", "Harper HTTP port")
511
- .option("--ops-port <port>", "Harper operations API port")
512
- .option("--admin-pass <pass>", "Admin password (or set FLAIR_ADMIN_PASS env)")
534
+ .option("--ops-port <port>", "Harper operations API port"), "Admin password (or set FLAIR_ADMIN_PASS env)")
513
535
  .option("--admin-user <name>", "Admin username for Basic auth (env: FLAIR_ADMIN_USER; default: admin)")
514
536
  .option("--keys-dir <dir>", "Directory for Ed25519 keys")
515
537
  .option("--force", "Skip interactive confirmation (required when stdin is not a TTY)")
516
538
  .action(async (id, opts) => {
517
- const opsPort = resolveOpsPort(opts);
518
539
  const adminPass = opts.adminPass ?? process.env.FLAIR_ADMIN_PASS ?? "";
519
540
  const adminUser = resolveAdminUser(opts.adminUser);
520
541
  const keysDir = opts.keysDir ?? defaultKeysDir();
@@ -523,9 +544,11 @@ export function register(program) {
523
544
  process.exit(1);
524
545
  }
525
546
  const auth = `Basic ${Buffer.from(`${adminUser}:${adminPass}`).toString("base64")}`;
547
+ const instance = await resolveLocalDeleteInstance(opts, resolveOpsPort, auth);
526
548
  async function opsPost(body) {
527
- return fetch(`http://127.0.0.1:${opsPort}/`, {
549
+ return fetch(instance.opsUrl, {
528
550
  method: "POST",
551
+ redirect: "error",
529
552
  headers: { "Content-Type": "application/json", Authorization: auth },
530
553
  body: JSON.stringify(body),
531
554
  signal: AbortSignal.timeout(10_000),
@@ -535,9 +558,41 @@ export function register(program) {
535
558
  const agentRes = await opsPost({ operation: "search_by_value", database: "flair", table: "Agent", search_attribute: "id", search_value: id, get_attributes: ["id", "name"] });
536
559
  const agentData = agentRes.ok ? await agentRes.json().catch(() => null) : null;
537
560
  const agentName = agentData?.[0]?.name ?? id;
538
- const memRes = await opsPost({ operation: "search_by_value", database: "flair", table: "Memory", search_attribute: "agentId", search_value: id, get_attributes: ["id"] });
539
- const memories = memRes.ok ? await memRes.json().catch(() => []) : [];
540
- const memoryCount = Array.isArray(memories) ? memories.length : 0;
561
+ async function scanOwnedIds(table) {
562
+ const res = await opsPost({
563
+ operation: "search_by_conditions", database: "flair", table, operator: "and",
564
+ conditions: [{ search_attribute: "agentId", search_type: "equals", search_value: id }],
565
+ get_attributes: ["id", "agentId"],
566
+ });
567
+ if (!res.ok)
568
+ throw new Error(`operations API returned ${res.status}`);
569
+ const rows = await res.json();
570
+ if (!Array.isArray(rows) || !rows.every((row) => typeof row?.id === "string" && row.id.length > 0)) {
571
+ throw new Error("returned an unexpected response");
572
+ }
573
+ for (const row of rows) {
574
+ if (row.agentId !== id) {
575
+ const error = new Error(`${table} row '${row.id}' does not belong to agent '${id}'`);
576
+ error.name = "AgentRemoveOwnerMismatchError";
577
+ throw error;
578
+ }
579
+ }
580
+ return rows.map((row) => row.id);
581
+ }
582
+ async function initialScan(table) {
583
+ try {
584
+ return await scanOwnedIds(table);
585
+ }
586
+ catch (error) {
587
+ const failure = new Error(`The ${table} scan for agent '${id}' failed: ${error instanceof Error ? error.message : String(error)}; nothing was removed.`, { cause: error });
588
+ if (error instanceof Error)
589
+ failure.name = error.name;
590
+ throw failure;
591
+ }
592
+ }
593
+ const memoryIds = await initialScan("Memory");
594
+ const memoryCount = memoryIds.length;
595
+ const soulIds = await initialScan("Soul");
541
596
  // Confirmation
542
597
  const isInteractive = process.stdin.isTTY;
543
598
  if (!opts.force) {
@@ -568,25 +623,48 @@ export function register(program) {
568
623
  else {
569
624
  console.log(`Removing agent '${agentName}' (${id}) with ${memoryCount} memories...`);
570
625
  }
571
- // Delete all memories
626
+ // Delete the scanned memories through the server's physical-removal
627
+ // path. A skill-tagged row expands to its whole lineage there, so
628
+ // superseded version rows go too. An accepted DELETE of a non-reserved
629
+ // skill closes its head; the reserved `using-flair` seed is physically
630
+ // deleted. A response that does not list every scanned id as
631
+ // removed stops the command before the Agent record is deleted.
572
632
  if (memoryCount > 0) {
573
633
  console.log(`Deleting ${memoryCount} memories...`);
574
- for (const mem of (Array.isArray(memories) ? memories : [])) {
575
- if (!mem?.id)
576
- continue;
577
- await opsPost({ operation: "delete", database: "flair", table: "Memory", ids: [mem.id] }).catch(() => { });
634
+ const purge = await api("POST", "/MemoryPurge", { ids: memoryIds }, {
635
+ baseUrl: instance.baseUrl,
636
+ explicitAdminPass: adminPass, adminUser, agentId: null,
637
+ });
638
+ confirmedPurgeIds(purge, memoryIds);
639
+ }
640
+ if (soulIds.length > 0) {
641
+ console.log(`Deleting ${soulIds.length} soul entries...`);
642
+ for (const soulId of soulIds) {
643
+ try {
644
+ const soulDel = await opsPost({ operation: "delete", database: "flair", table: "Soul", ids: [soulId] });
645
+ if (!soulDel.ok) {
646
+ const text = await soulDel.text().catch(() => "");
647
+ throw new Error(`operations API returned ${soulDel.status}: ${text}`);
648
+ }
649
+ }
650
+ catch (error) {
651
+ throw new Error(`Failed to delete Soul '${soulId}': ${error instanceof Error ? error.message : String(error)}`, { cause: error });
652
+ }
578
653
  }
579
654
  }
580
- // Delete all souls
581
- const soulRes = await opsPost({ operation: "search_by_value", database: "flair", table: "Soul", search_attribute: "agentId", search_value: id, get_attributes: ["id"] });
582
- const souls = soulRes.ok ? await soulRes.json().catch(() => []) : [];
583
- if (Array.isArray(souls) && souls.length > 0) {
584
- console.log(`Deleting ${souls.length} soul entries...`);
585
- for (const soul of souls) {
586
- if (!soul?.id)
587
- continue;
588
- await opsPost({ operation: "delete", database: "flair", table: "Soul", ids: [soul.id] }).catch(() => { });
589
- }
655
+ let remainingIds;
656
+ try {
657
+ remainingIds = await scanOwnedIds("Soul");
658
+ }
659
+ catch (error) {
660
+ const failure = new Error(`The Soul deletion for agent '${id}' could not be confirmed: ${error instanceof Error ? error.message : String(error)}; ` +
661
+ `these scanned Soul rows may remain and the Agent record was not deleted: ${soulIds.join(", ") || "(none scanned)"}.`, { cause: error });
662
+ if (error instanceof Error)
663
+ failure.name = error.name;
664
+ throw failure;
665
+ }
666
+ if (remainingIds.length > 0) {
667
+ throw new Error(`The Soul deletion for agent '${id}' was not confirmed; these Soul rows remain and the Agent record was not deleted: ${remainingIds.join(", ")}.`);
590
668
  }
591
669
  // Delete agent record
592
670
  const delRes = await opsPost({ operation: "delete", database: "flair", table: "Agent", ids: [id] });
@@ -596,23 +674,88 @@ export function register(program) {
596
674
  }
597
675
  // Delete key files (unless --keep-keys)
598
676
  if (!opts.keepKeys) {
599
- const privPath = privKeyPath(id, keysDir);
600
- const pubPath = pubKeyPath(id, keysDir);
601
- const backupPath = privPath + ".bak";
602
- for (const p of [privPath, pubPath, backupPath]) {
603
- if (existsSync(p)) {
604
- try {
605
- const { unlinkSync: ul } = await import("node:fs");
606
- ul(p);
607
- }
608
- catch { /* best effort */ }
609
- }
610
- }
611
- console.log("Key files deleted.");
677
+ const keys = removeAgentKeyFiles(id, keysDir);
678
+ console.log(keys.manual
679
+ ? `Key files for '${id}' are not deleted by this command (the id is outside the agent-ID rule); clean them up manually.`
680
+ : `Removed ${keys.removed.length} key file(s).`);
612
681
  }
613
682
  else {
614
683
  console.log("Key files preserved (--keep-keys).");
615
684
  }
616
685
  console.log(`\n✅ Agent '${id}' removed successfully`);
617
686
  });
687
+ addAdminPassOptions(agent
688
+ .command("stamp-home")
689
+ .description("Back-fill the home instance (originatorInstanceId) on home-less Agent rows with no federation-sync provenance")
690
+ .option("--port <port>", "Harper HTTP port")
691
+ .option("--ops-port <port>", "Harper operations API port"), "Admin password (or set FLAIR_ADMIN_PASS)", { adminPassFileHelp: "Read the admin password from a file (owner-only permissions enforced)" })
692
+ .option("--admin-user <name>", "Admin username for Basic auth (env: FLAIR_ADMIN_USER; default: admin)")
693
+ .option("--apply", "Write the home; without it the command is a dry run and writes nothing")
694
+ .action(async (opts) => {
695
+ let target;
696
+ try {
697
+ // flair#2474 — pair the ops port (the roster read) with the HTTP port (the
698
+ // guarded PATCH). A target the configured pair contradicts, or one with a
699
+ // single port named and no complete configured pair, is refused by name
700
+ // (see resolveAgentHomeTarget).
701
+ target = resolveAgentHomeTarget(opts);
702
+ }
703
+ catch (err) {
704
+ console.error(`Error: ${err.message}`);
705
+ process.exit(1);
706
+ }
707
+ const opsPort = target.opsPort;
708
+ const adminUser = resolveAdminUser(opts.adminUser);
709
+ let adminPass;
710
+ try {
711
+ adminPass = resolveLocalAdminPass(opts.adminPass);
712
+ }
713
+ catch (err) {
714
+ console.error(`Error: ${err.message}`);
715
+ process.exit(1);
716
+ }
717
+ if (!adminPass) {
718
+ console.error("Error: --admin-pass or FLAIR_ADMIN_PASS required (or ensure ~/.flair/admin-pass exists, created by `flair init`)");
719
+ process.exit(1);
720
+ }
721
+ const opsUrl = `http://127.0.0.1:${opsPort}/`;
722
+ const httpUrl = `http://127.0.0.1:${target.httpPort}/`;
723
+ const auth = `Basic ${Buffer.from(`${adminUser}:${adminPass}`).toString("base64")}`;
724
+ const localInstanceId = await resolveTargetInstanceId(agentHomeEndpoint(opsUrl, adminUser, adminPass));
725
+ const result = await runAgentHomeStamp({
726
+ opsUrl,
727
+ httpUrl,
728
+ authHeader: auth,
729
+ localInstanceId,
730
+ apply: Boolean(opts.apply),
731
+ });
732
+ if (result.reason === "roster-unreadable") {
733
+ console.error("Error: could not read the stored Agent roster; nothing was changed.");
734
+ process.exit(1);
735
+ }
736
+ const plan = result.plan;
737
+ if (plan.homeLess.length === 0) {
738
+ console.log(`${render.icons.ok} Every stored agent row names a home instance.`);
739
+ return;
740
+ }
741
+ console.log(`${plan.homeLess.length} agent row(s) have no home instance` +
742
+ (localInstanceId ? ` (this instance is ${localInstanceId})` : ""));
743
+ for (const id of plan.homeLess) {
744
+ const inSync = plan.sync.includes(id);
745
+ console.log(` ${inSync ? "list only (sync-originated):" : "stamp:"} ${id}`);
746
+ }
747
+ if (result.reason === "no-canonical-id") {
748
+ console.error("Error: could not confirm a single canonical Instance row to stamp as the home; nothing was written.");
749
+ process.exitCode = 1;
750
+ return;
751
+ }
752
+ if (!opts.apply) {
753
+ console.log(`Dry run — nothing written. Re-run with --apply to stamp ${plan.stampable.length} row(s); ` +
754
+ `${plan.sync.length} sync-originated row(s) are never stamped.`);
755
+ return;
756
+ }
757
+ for (const line of stampLeftoverLines(result))
758
+ console.log(line);
759
+ console.log(`${render.icons.ok} Stamped the home instance on ${result.stamped.length} row(s).`);
760
+ });
618
761
  }
@@ -1,4 +1,4 @@
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
3
  let cli;
4
4
  /** Bind the cli-locals this module depends on. */
@@ -67,12 +67,13 @@ export function register(program) {
67
67
  payload.days = n;
68
68
  }
69
69
  const baseUrl = resolveBaseUrl(opts);
70
+ const url = requestUrl(baseUrl, "/AttentionQuery");
70
71
  const headers = { "content-type": "application/json" };
71
72
  const keyPath = opts.key || resolveKeyPath(agentId);
72
73
  if (keyPath) {
73
- headers["authorization"] = buildEd25519Auth(agentId, "POST", "/AttentionQuery", keyPath);
74
+ headers["authorization"] = buildEd25519Auth(agentId, "POST", requestTarget(url), keyPath);
74
75
  }
75
- const res = await fetch(`${baseUrl}/AttentionQuery`, {
76
+ const res = await fetch(url, {
76
77
  method: "POST",
77
78
  headers,
78
79
  body: JSON.stringify(payload),