@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
package/README.md CHANGED
@@ -64,7 +64,7 @@ Full walkthrough with expected output at every step: **[docs/quickstart.md](docs
64
64
  Two MCP paths, on purpose. A client on this machine and a remote connector are different trust situations, and each has its own mechanism. The write-up that joins them is [docs/mcp-clients.md — Two MCP paths](docs/mcp-clients.md#two-mcp-paths).
65
65
 
66
66
  - **Local client: the `npx` stdio adapter.** `@tpsdev-ai/flair-mcp` is a separate package and is not installed globally. `flair init --agent <id>` attempts to wire detected clients when wiring is enabled, using `npx -y @tpsdev-ai/flair-mcp@<version>` pinned to the CLI's version. The adapter sends requests to `FLAIR_URL`, signing with an Ed25519 key when one resolves and otherwise using configured administrator Basic credentials when available. Loopback HTTP is the right scheme on this machine (the default is `http://127.0.0.1:19926`). A remote `FLAIR_URL` should use HTTPS. This is the path for Claude Code, Cursor, Codex, Gemini, and every other local MCP client.
67
- - **Remote client: native `/mcp`.** A JSON-RPC endpoint inside the server, OAuth bearer, exposing the curated tools that the JSON-RPC `tools/list` method on `/mcp` returns. It is off by default: an unset `FLAIR_MCP_OAUTH` leaves `/mcp` unregistered; a truthy flag and a configured issuer make Flair attempt to mount it, while only the literal value `true` also enables the OAuth component. `true` is the value that turns on both Flair's route and the OAuth component; `1`, `yes`, and `on` leave the component off and every call 401s. OAuth client-metadata is fetched over HTTPS and refuses a private, loopback, or link-local host, and `flair mcp enable` refuses a local origin (localhost, loopback, RFC1918, IPv4 link-local, `.local`). Remote connectors need a publicly reachable HTTPS origin; `flair mcp enable` refuses local origins, but route registration itself does not enforce a public HTTPS issuer.
67
+ - **Remote client: native `/mcp`.** A JSON-RPC endpoint inside the server, OAuth bearer, exposing the curated tools that the JSON-RPC `tools/list` method on `/mcp` returns. It is off by default: an unset `FLAIR_MCP_OAUTH` leaves `/mcp` unregistered; a truthy flag and a configured issuer make Flair attempt to mount it, while only the literal value `true` also enables the OAuth component. `true` is the value that turns on both Flair's route and the OAuth component; `1`, `yes`, and `on` leave the component off and every call 401s. OAuth client-metadata is fetched over HTTPS and refuses a private, loopback, or link-local host. Remote connectors need a publicly reachable HTTPS origin; `flair mcp enable` accepts loopback or unspecified targets for the local restart but refuses local issuers, while route registration itself does not enforce a public HTTPS issuer.
68
68
  `@tpsdev-ai/flair-client` is likewise its own package: add it to a project when you want to call Flair from your own code ([JavaScript / TypeScript](#javascript--typescript)).
69
69
 
70
70
  ### Where the agent's key lives
@@ -166,14 +166,14 @@ Embeddings are generated in-process by [nomic-embed-text](https://huggingface.co
166
166
 
167
167
  Requests are signed as `agentId:timestamp:nonce:METHOD:/path` and verified against the agent's registered public key, with a 30-second replay window and nonce deduplication.
168
168
 
169
- See **[DESIGN.md](DESIGN.md)** for the invariants behind the three primitives — why they're shaped the way they are.
169
+ See **[DESIGN.md](https://github.com/tpsdev-ai/flair/blob/main/DESIGN.md)** for the invariants behind the three primitives — why they're shaped the way they are.
170
170
 
171
171
  ## Features
172
172
 
173
173
  | Feature | What it does |
174
174
  |---|---|
175
175
  | **Semantic memory** | Auto-embedded on write. Search by meaning, not keywords. |
176
- | **Tiered durability** | `permanent` (retained until explicitly deleted by its owner or an admin) / `persistent` / `standard` (default) / `ephemeral` (24h TTL). |
176
+ | **Tiered durability** | Four tiers; each states what it does and does not guarantee. permanent — routine maintenance never reaps or age-archives it (an expired validTo archives an eligible row; an acquired expiresAt never reaps it); it never decays; bootstrap considers the bootstrapping agent's own permanent memories before recent rows, subject to scope, expiry/closure and the token budget. persistent — routine maintenance never reaps or age-archives it (an expired validTo archives an eligible row; an acquired expiresAt never reaps it). standard — routine maintenance archives it once its validTo passes or, as a session note, after 30 days. ephemeral — routine maintenance reaps it once its TTL (24h by default) passes. No tier adds a flush, fsync, backup or replica acknowledgement: an explicit delete (owner or admin) or a store failure can end any of them. |
177
177
  | **Temporal validity** | `validFrom` / `validTo` bounds. Expired memories drop out of search and bootstrap automatically. |
178
178
  | **Trust-graded recall** | Opt-in per-result evidence: provenance, usage signal, freshness, supersession. Confidence bands (`strong`/`moderate`/`breadcrumb`) and first-class **abstention** when nothing clears the floor. |
179
179
  | **Relationship graph** | Entity-to-entity triples with temporal bounds, queryable alongside semantic memory. |
@@ -187,7 +187,7 @@ See **[DESIGN.md](DESIGN.md)** for the invariants behind the three primitives
187
187
  | **OAuth 2.1 server** | PKCE, dynamic client registration, standards-compliant token endpoint. Delegate auth to Flair without a separate IdP. [docs/auth.md](docs/auth.md) |
188
188
  | **XAA** | Bind agent identities to Google Workspace, Azure AD or Okta accounts. |
189
189
  | **Web admin** | Server-rendered UI for principals, connectors, IdPs and instance config. No separate dashboard service. |
190
- | **Benchmarks** | [`flair-bench`](packages/flair-bench/README.md) scores candidate embedding models against the same recall corpus Flair's CI gates on. Runs standalone — no Flair install, no server. |
190
+ | **Benchmarks** | [`flair-bench`](https://github.com/tpsdev-ai/flair/blob/main/packages/flair-bench/README.md) scores candidate embedding models against the same recall corpus Flair's CI gates on. Runs standalone — no Flair install, no server. |
191
191
 
192
192
  Trust-graded recall reaches the authenticated HTTP API and the built-in `/mcp` tools today — the latter being off by default, see [One install, one binary](#one-install-one-binary). CLI, `@tpsdev-ai/flair-client` and `flair-mcp` exposure is a follow-up. REM needs a configured generative backend (Ollama, OpenAI, Anthropic, …) — without one, `flair rem rapid` fails with `Reflection error: No generative backend configured`.
193
193
 
@@ -227,7 +227,7 @@ Flair works with any agent runtime. Pick the path that fits yours — **[full ca
227
227
  }
228
228
  ```
229
229
 
230
- Then add to your `CLAUDE.md`:
230
+ Then add to your `CLAUDE.md`: <!-- docs-freshness-allow: names a file in the reader's project -->
231
231
 
232
232
  At the start of every session, run mcp__flair__bootstrap before responding.
233
233
 
@@ -243,7 +243,7 @@ Per-CLI config snippets (Gemini CLI's `~/.gemini/settings.json`, Codex CLI's `~/
243
243
  openclaw plugins install @tpsdev-ai/openclaw-flair
244
244
  ```
245
245
 
246
- Auto-detects the agent identity, provides `memory_store` / `memory_search` / `memory_get`, and provides bootstrap context from `before_prompt_build` (requires host opt-in). See the [plugin README](packages/openclaw-flair/README.md).
246
+ Auto-detects the agent identity, provides `memory_store` / `memory_search` / `memory_get`, and provides bootstrap context from `before_prompt_build` (requires host opt-in). See the [plugin README](https://github.com/tpsdev-ai/flair/blob/main/packages/openclaw-flair/README.md).
247
247
 
248
248
  ### n8n
249
249
 
@@ -263,10 +263,10 @@ flair search --agent mybot "that important thing"
263
263
  flair soul set --agent mybot --key role --value "Security reviewer" --admin-pass-file ~/.flair/admin-pass
264
264
  flair bootstrap --agent mybot --max-tokens 4000 # cold-start: soul + relevant memories
265
265
  flair backup --admin-pass-file ~/.flair/admin-pass # logical JSON export
266
- flair restore ./backup.json --admin-pass-file ~/.flair/admin-pass
266
+ FLAIR_ADMIN_PASS="$(cat ~/.flair/admin-pass)" flair restore ./backup.json
267
267
  ```
268
268
 
269
- `--admin-pass-file` is preferred over `--admin-pass`: it keeps the secret out of `ps` and your shell history.
269
+ For commands that declare `--admin-pass-file`, prefer it over `--admin-pass` to keep the secret out of `ps` and your shell history.
270
270
 
271
271
  ### JavaScript / TypeScript
272
272
 
@@ -289,7 +289,7 @@ const ctx = await flair.bootstrap({ maxTokens: 4000 })
289
289
  await flair.soul.get('role')
290
290
  ```
291
291
 
292
- No Harper, no embeddings — just HTTP and auth. Full API in the [client README](packages/flair-client/README.md).
292
+ No Harper, no embeddings — just HTTP and auth. Full API in the [client README](https://github.com/tpsdev-ai/flair/blob/main/packages/flair-client/README.md).
293
293
 
294
294
  ### HTTP API (any language)
295
295
 
@@ -415,7 +415,7 @@ bun run build # compile TypeScript → dist/
415
415
  bun test # unit + integration tests
416
416
  ```
417
417
 
418
- Integration tests spin up a real Harper instance on a random port and tear it down afterwards — no mocks for the database layer. Every commit runs unit tests, integration tests, type check, dependency audit, Semgrep and CodeQL SAST, and a from-scratch Docker validation. See [CONTRIBUTING.md](CONTRIBUTING.md).
418
+ Integration tests spin up a real Harper instance on a random port and tear it down afterwards — no mocks for the database layer. CI for pull requests to main and pushes to main runs unit and integration tests, type checks, dependency audit, Semgrep and CodeQL SAST. See [CONTRIBUTING.md](https://github.com/tpsdev-ai/flair/blob/main/CONTRIBUTING.md).
419
419
 
420
420
  ## Status
421
421
 
package/SECURITY.md CHANGED
@@ -63,8 +63,8 @@ Reads are open **within an org**; writes are isolated per agent. Enforced at
63
63
  the database layer (Harper resource `search()` override via a single
64
64
  centralized read-scope rule), not application logic:
65
65
 
66
- - `GET /Memory/` — returns the authenticated agent's own memories (any
67
- visibility) plus every **non-private** memory in the org
66
+ - `GET /Memory/` — applies the owner/visibility base scope and omits retained
67
+ closed skill payloads that fail the non-admin reader's current-authority check
68
68
  - `POST /MemorySearch` — same read scope: own memories plus all non-private
69
69
  - `POST /Memory` — writes are attributed to the authenticated agent; an
70
70
  agent cannot write as another (write isolation)
@@ -79,11 +79,55 @@ so a write naming neither is stamped `private` and is owner-only. An explicit
79
79
  `visibility` on the write always overrides the rule, and the response to a
80
80
  create names the value the record actually landed on.
81
81
 
82
+ ### Record Ownership on Writes
83
+
84
+ For a verified non-admin agent's HTTP write to an owner-scoped table served by
85
+ a resource that extends that table (Memory, Relationship, Soul, Credential,
86
+ Integration, Asset, MemoryCandidate, MemoryGrant, MemoryUsage, Message,
87
+ OrgEvent, WorkspaceState, Presence):
88
+
89
+ - The middleware can return
90
+ `403 forbidden: cannot modify <Table> owned by another principal` before the
91
+ table guard runs on a request target of exactly `/<Table>/<id>` (two
92
+ non-empty path segments, no `.` in the decoded id), for which Harper resolves
93
+ the same record id. Other addressed forms are left to the guard, which uses
94
+ Harper's resolved id.
95
+ - If reached, the guard checks the body `id` on POST/PUT/PATCH first, then
96
+ stored ownership (the same owner refusal), using Harper's resolved record id.
97
+ An absent, null or matching body `id` passes the body-id check; a differing
98
+ string or number `id` gets `403 write_id_not_addressed`, and a present,
99
+ non-null `id` of any other type that is not the addressed key gets
100
+ `400 id_target_mismatch`. Each
101
+ object element of an array body is checked the same way. OrgEvent and Memory
102
+ bind an addressed POST's missing body `id` to the addressed id.
103
+ - For a collection PUT, PATCH or DELETE, if reached, the table guard returns
104
+ `403 forbidden: a non-admin write to <Table> must address one record by its id`;
105
+ existing DELETE middleware may refuse earlier.
106
+
107
+ A refusal by this guard leaves its target row unchanged and carries no record
108
+ content. A POST to a collection is delegated to each resource's own
109
+ POST handling — its create and attribution rules (for example, an OrgEvent
110
+ collection POST that names an existing event owned by another agent reaches
111
+ OrgEvent's ownership check and is refused, one that names the caller's own
112
+ existing event can update it when OrgEvent's other checks pass (a changed
113
+ `createdAt` is refused with 409), and a
114
+ Presence heartbeat writes the caller's own row). Routes served
115
+ by a custom resource rather than a table-backed one are outside this table
116
+ guard and apply their own rules; `/AgentReadPosition`, for example, enforces
117
+ its own ownership rule.
118
+ The guard exempts administrator and in-process calls. OrgEvent POST id
119
+ selection also applies to administrator and in-process calls.
120
+
121
+ Credential records are owner-scoped by `principalId`: non-admin callers read and
122
+ modify only their own records, and administrators and trusted internal callers
123
+ are unscoped. Anonymous HTTP access is refused.
124
+
82
125
  ### Cross-Agent Access (within an org)
83
126
 
84
- Within an org, an agent reads every non-private memory directly — no grant
85
- required. This is deliberate: the goal is relevance (surface what's useful to
86
- the org) over secrecy. A writer keeps something private by marking it
127
+ Within an org, non-private memories pass the base read-scope check without a
128
+ grant; non-admin by-id and collection reads of retained closed skills
129
+ additionally require readable current authority. This is deliberate: the goal
130
+ is relevance (surface what's useful to the org) over secrecy. A writer keeps something private by marking it
87
131
  `visibility: private`, which keeps it strictly owner-only. The access boundary
88
132
  that stays hard is the **federation edge** (cross-instance / cross-org), not
89
133
  within-org reads.
package/config.yaml CHANGED
@@ -15,6 +15,13 @@ authentication:
15
15
  github:
16
16
  clientId: ${OAUTH_GITHUB_CLIENT_ID}
17
17
  clientSecret: ${OAUTH_GITHUB_CLIENT_SECRET}
18
+ # WHOLE-TOKEN env reference, like the two above. Since @harperfast/oauth
19
+ # 2.7.0 a CONFIGURED provider (both credentials set) needs a redirectUri;
20
+ # 2.8.1 skips an UNCONFIGURED one before that check
21
+ # (HarperFast/oauth#259). Set it to this instance's public origin plus
22
+ # /oauth — the component appends '/github/callback'. With the credentials
23
+ # set, an unset or unresolved value here fails the plugin's load.
24
+ redirectUri: ${OAUTH_GITHUB_REDIRECT_URI}
18
25
  mcp:
19
26
  # WHOLE-TOKEN env reference — the same FLAIR_MCP_OAUTH flag flair's
20
27
  # in-process /mcp route gates on (resources/mcp-oauth-flag.ts). The on/off
@@ -23,20 +30,20 @@ authentication:
23
30
  # (flair#1152). Requires @harperfast/oauth >= 2.5.0 (resolved-version
24
31
  # assertion + behavioral gate: test/integration/mcp-oauth-boot-safety.test.ts).
25
32
  #
26
- # ASYMMETRY (load-bearing, measured on oauth 2.5.0): the two readers of
27
- # this flag accept DIFFERENT vocabularies. The component's
28
- # coerceConfigBoolean accepts ONLY "true"/"false" and DELETES any other
29
- # string (unresolved placeholder, "1", "yes", garbage) so its disabled
30
- # default applies. flair's mcpOAuthEnabled() accepts 1/true/yes/on.
33
+ # ASYMMETRY (load-bearing, measured on @harperfast/oauth 2.9.0): the two
34
+ # readers of this flag accept DIFFERENT vocabularies. The component's
35
+ # coerceConfigBoolean trims and lowercases, mapping "true"/"false" to a
36
+ # boolean, and normalizeBooleanField deletes strings it cannot coerce
37
+ # (unresolved placeholder, "1", "yes", garbage), so its disabled default
38
+ # applies (dist/lib/config.js). flair's mcpOAuthEnabled() accepts
39
+ # 1/true/yes/on.
31
40
  #
32
- # Failure modes (oauth 2.5.0):
41
+ # Failure modes (oauth 2.9.0):
33
42
  # unset -> placeholder deleted -> both sides OFF, clean boot
34
- # true -> BOTH sides ON — the one working enable value
35
- # (`flair mcp enable` stages exactly this)
43
+ # true -> both flag readers accept this value
36
44
  # false -> both sides OFF
37
- # 1 / yes / on -> flair /mcp handler ON, component AS OFF ->
38
- # fail-closed broken-on: every /mcp request 401s,
39
- # no AS is advertised. Use "true" instead.
45
+ # 1 / yes / on -> flair's reader is ON, the component deletes the
46
+ # value (AS stays OFF); /mcp is not mounted.
40
47
  # garbage (maybe) -> deleted -> component OFF; flair strict -> OFF.
41
48
  # Inert: no /mcp handler, no data path (flair's own
42
49
  # discovery documents still serve, by design).
@@ -62,4 +69,8 @@ authentication:
62
69
  allowedHosts:
63
70
  - claude.ai
64
71
  - claude.com
65
- signingKeyPem: ${FLAIR_MCP_SIGNING_KEY_PEM}
72
+ # Optional pin; the algorithm follows the PEM (RSA -> RS256, EC P-256 -> ES256).
73
+ # Without a pin, minting reuses a persisted key or generates and persists
74
+ # one if oauth.harper_oauth_mcp_keys is empty.
75
+ # To pin, add the line below and stage the variable:
76
+ # signingKeyPem: ${FLAIR_MCP_SIGNING_KEY_PEM}
@@ -31,14 +31,34 @@
31
31
  * from malformed responses — easier to express in TS.
32
32
  *
33
33
  * Usage:
34
- * flair bridge import mem0 --user <id> --api-key <key> --agent <flair-id>
34
+ * MEM0_API_KEY=<token> flair bridge import mem0 --user <id> --agent <flair-id>
35
+ * flair bridge import mem0 --user <id> --api-key-file <path> --agent <flair-id>
35
36
  * flair bridge import mem0 --user <id> --base-url https://mem0.example.com --agent <flair-id>
36
- * MEM0_API_KEY=<key> flair bridge import mem0 --user <id> --agent <flair-id>
37
37
  */
38
38
  import { BridgeRuntimeError } from "../types.js";
39
39
  function isPaginatedEnvelope(body) {
40
40
  return !Array.isArray(body) && typeof body === "object" && body !== null && Array.isArray(body.results);
41
41
  }
42
+ function mem0BaseUrl(value) {
43
+ if (value === undefined)
44
+ return "https://api.mem0.ai";
45
+ // An explicit value must never select the cloud default by accident.
46
+ if (typeof value !== "string" || !value || value !== value.trim()) {
47
+ throw new Error("--base-url must be a non-empty HTTP(S) URL");
48
+ }
49
+ let url;
50
+ try {
51
+ url = new URL(value);
52
+ }
53
+ catch {
54
+ throw new Error("--base-url must be a valid HTTP(S) URL");
55
+ }
56
+ if (!['http:', 'https:'].includes(url.protocol) || !url.hostname || url.username || url.password ||
57
+ url.href.includes('?') || url.href.includes('#')) {
58
+ throw new Error("--base-url must be an HTTP(S) URL without credentials, query, or fragment");
59
+ }
60
+ return url.href.replace(/\/+$/, "");
61
+ }
42
62
  async function* importMem0(opts, ctx) {
43
63
  const userId = typeof opts.user === "string" ? opts.user : "";
44
64
  if (!userId) {
@@ -48,7 +68,7 @@ async function* importMem0(opts, ctx) {
48
68
  field: "user",
49
69
  expected: "Mem0 user_id string",
50
70
  got: "missing",
51
- hint: "pass --user <id>; example: flair bridge import mem0 --user <id> --api-key <key> --agent <flair-id>",
71
+ hint: "pass --user <id>; example: MEM0_API_KEY=<token> flair bridge import mem0 --user <id> --agent <flair-id>",
52
72
  });
53
73
  }
54
74
  const apiKey = typeof opts.apiKey === "string" ? opts.apiKey : "";
@@ -59,18 +79,22 @@ async function* importMem0(opts, ctx) {
59
79
  field: "apiKey",
60
80
  expected: "Mem0 API token (cloud or self-hosted)",
61
81
  got: "missing",
62
- hint: "pass --api-key <token> or set MEM0_API_KEY in the environment",
82
+ hint: "pass --api-key-file <path> or set MEM0_API_KEY; example: MEM0_API_KEY=<token> flair bridge import mem0 --user <id> --agent <flair-id>",
83
+ });
84
+ }
85
+ let baseUrl;
86
+ try {
87
+ baseUrl = mem0BaseUrl(opts.baseUrl);
88
+ }
89
+ catch (err) {
90
+ throw new BridgeRuntimeError({
91
+ bridge: "mem0", op: "import", field: "baseUrl", expected: "valid HTTP(S) URL",
92
+ got: "invalid explicit --base-url", hint: err.message,
63
93
  });
64
94
  }
65
- const baseUrl = typeof opts.baseUrl === "string" && opts.baseUrl.length > 0
66
- ? opts.baseUrl.replace(/\/+$/, "")
67
- : "https://api.mem0.ai";
68
95
  const maxPages = typeof opts.maxPages === "number" ? opts.maxPages : 0;
69
96
  const pageSize = 100;
70
- ctx.log.info("starting mem0 import", {
71
- user_id: userId,
72
- base_url: baseUrl,
73
- });
97
+ ctx.log.info("starting mem0 import");
74
98
  let pageCount = 0;
75
99
  let totalKept = 0;
76
100
  let pageNum = 1;
@@ -80,24 +104,24 @@ async function* importMem0(opts, ctx) {
80
104
  ctx.log.info("stopping at max-pages limit", { pages: pageCount, kept: totalKept });
81
105
  break;
82
106
  }
83
- ctx.log.debug("fetching page", { url: cursor, page: pageCount + 1 });
107
+ ctx.log.debug("fetching page", { page: pageCount + 1 });
84
108
  let res;
85
109
  try {
86
110
  res = await ctx.fetch(cursor, {
111
+ redirect: "manual",
87
112
  headers: {
88
113
  Authorization: `Token ${apiKey}`,
89
114
  Accept: "application/json",
90
115
  },
91
116
  });
92
117
  }
93
- catch (err) {
118
+ catch {
94
119
  throw new BridgeRuntimeError({
95
120
  bridge: "mem0",
96
121
  op: "import",
97
- path: cursor,
98
122
  field: "fetch",
99
123
  expected: "HTTP 200",
100
- got: `network error: ${err?.message ?? err}`,
124
+ got: "network error",
101
125
  hint: "check the base URL is reachable and the network is up",
102
126
  });
103
127
  }
@@ -105,7 +129,6 @@ async function* importMem0(opts, ctx) {
105
129
  throw new BridgeRuntimeError({
106
130
  bridge: "mem0",
107
131
  op: "import",
108
- path: cursor,
109
132
  field: "apiKey",
110
133
  expected: "valid Mem0 API token",
111
134
  got: "HTTP 401 Unauthorized",
@@ -116,7 +139,6 @@ async function* importMem0(opts, ctx) {
116
139
  throw new BridgeRuntimeError({
117
140
  bridge: "mem0",
118
141
  op: "import",
119
- path: cursor,
120
142
  field: "apiKey",
121
143
  expected: "authorized token",
122
144
  got: "HTTP 403 Forbidden",
@@ -127,23 +149,20 @@ async function* importMem0(opts, ctx) {
127
149
  throw new BridgeRuntimeError({
128
150
  bridge: "mem0",
129
151
  op: "import",
130
- path: cursor,
131
152
  field: "user",
132
153
  expected: "existing user_id",
133
154
  got: "HTTP 404 Not Found",
134
- hint: `user_id "${userId}" was not found on this Mem0 instance`,
155
+ hint: "user_id was not found on this Mem0 instance",
135
156
  });
136
157
  }
137
158
  if (!res.ok) {
138
- const body = await res.text().catch(() => "(could not read body)");
139
159
  throw new BridgeRuntimeError({
140
160
  bridge: "mem0",
141
161
  op: "import",
142
- path: cursor,
143
162
  field: "response",
144
163
  expected: "HTTP 200",
145
- got: `HTTP ${res.status} ${res.statusText}`,
146
- hint: `unexpected response (${res.status}): ${body.slice(0, 200)}`,
164
+ got: `HTTP ${res.status}`,
165
+ hint: `unexpected response (HTTP ${res.status}); check the Mem0 API server logs`,
147
166
  });
148
167
  }
149
168
  let body;
@@ -153,7 +172,6 @@ async function* importMem0(opts, ctx) {
153
172
  throw new BridgeRuntimeError({
154
173
  bridge: "mem0",
155
174
  op: "import",
156
- path: cursor,
157
175
  field: "(response)",
158
176
  expected: "JSON body",
159
177
  got: "empty response",
@@ -168,11 +186,10 @@ async function* importMem0(opts, ctx) {
168
186
  throw new BridgeRuntimeError({
169
187
  bridge: "mem0",
170
188
  op: "import",
171
- path: cursor,
172
189
  field: "(response)",
173
190
  expected: "valid JSON: bare array OR { results: [...], next: string|null }",
174
191
  got: "parse error",
175
- hint: `could not parse response: ${err?.message ?? err}`,
192
+ hint: "could not parse Mem0 API response as JSON",
176
193
  });
177
194
  }
178
195
  let mems;
@@ -189,19 +206,37 @@ async function* importMem0(opts, ctx) {
189
206
  // v3 / DRF-style envelope — use server-provided next URL.
190
207
  mems = body.results;
191
208
  nextCursor = typeof body.next === "string" && body.next.length > 0 ? body.next : null;
209
+ if (nextCursor !== null) {
210
+ let nextUrl;
211
+ try {
212
+ nextUrl = new URL(nextCursor, baseUrl);
213
+ }
214
+ catch {
215
+ throw new BridgeRuntimeError({
216
+ bridge: "mem0", op: "import", field: "next", expected: "same-origin HTTP(S) pagination URL",
217
+ got: "invalid pagination URL", hint: "Mem0 API returned an invalid pagination URL",
218
+ });
219
+ }
220
+ if (nextUrl.origin !== new URL(baseUrl).origin || nextUrl.username || nextUrl.password) {
221
+ throw new BridgeRuntimeError({
222
+ bridge: "mem0", op: "import", field: "next", expected: "same-origin HTTP(S) pagination URL",
223
+ got: "unsafe pagination URL", hint: "Mem0 API returned an unsafe pagination URL",
224
+ });
225
+ }
226
+ nextCursor = nextUrl.href;
227
+ }
192
228
  }
193
229
  else {
194
230
  throw new BridgeRuntimeError({
195
231
  bridge: "mem0",
196
232
  op: "import",
197
- path: cursor,
198
233
  field: "(response)",
199
234
  expected: "bare array OR { results: [...], next: string|null }",
200
235
  got: typeof body,
201
236
  hint: `unexpected response shape — got ${typeof body}, expected an array or paginated envelope`,
202
237
  });
203
238
  }
204
- ctx.log.debug("received page", { count: mems.length, next: nextCursor });
239
+ ctx.log.debug("received page", { count: mems.length, hasNext: nextCursor !== null });
205
240
  for (const m of mems) {
206
241
  const content = typeof m?.memory === "string" ? m.memory : "";
207
242
  if (!content || content.trim() === "")
@@ -20,6 +20,7 @@ const FLAIR_RESERVED_FIELDS_SET = new Set([
20
20
  "retrievalCount",
21
21
  "lastRetrieved",
22
22
  "promotionStatus",
23
+ "promotionContentHash",
23
24
  "_safetyFlags",
24
25
  "createdBy",
25
26
  "updatedBy",
@@ -16,6 +16,7 @@
16
16
  import { randomUUID } from "node:crypto";
17
17
  import { BridgeRuntimeError } from "../types.js";
18
18
  import { importFromYaml } from "./execute.js";
19
+ import { endsWithContentSelectorSuffix } from "../../lib/memory-id-policy.js";
19
20
  const VALID_DURABILITY = new Set(["ephemeral", "standard", "persistent", "permanent"]);
20
21
  /**
21
22
  * Drive a YAML descriptor's `import` block all the way through to PUTs
@@ -51,6 +52,17 @@ export async function runImport(opts) {
51
52
  ? m.durability
52
53
  : "standard";
53
54
  const id = m.id ?? `${resolvedAgent}-${Date.now()}-${shortRand()}`;
55
+ if (endsWithContentSelectorSuffix(id)) {
56
+ throw new BridgeRuntimeError({
57
+ bridge: opts.bridgeName,
58
+ op: "import",
59
+ record: total,
60
+ field: "id",
61
+ expected: "a Memory id that does not end in .content",
62
+ got: id,
63
+ hint: `Memory ids must not end in ".content". Change the bridge's id mapping for ${id}.`,
64
+ });
65
+ }
54
66
  const body = {
55
67
  id,
56
68
  agentId: resolvedAgent,
@@ -1,15 +1,8 @@
1
1
  /**
2
2
  * Dynamic loader for Shape B code-plugin bridges.
3
- *
4
- * Given a discovered `npm-package` source, dynamic-import the package,
5
- * validate that it exports a `MemoryBridge`, and return the loaded module.
6
- * The import is done via `createRequire` relative to the package root so
7
- * scoped packages and deep nested deps resolve correctly.
8
- *
9
- * Validation is deliberately minimal: `name`, `version`, `kind`, and at
10
- * least one of `import` / `export` must be present and look right. The
11
- * spec §6 contract is "duck-type at runtime, strict error messages."
12
3
  */
4
+ import { readFile, realpath } from "node:fs/promises";
5
+ import { isAbsolute, relative, resolve, sep } from "node:path";
13
6
  import { pathToFileURL } from "node:url";
14
7
  import { BridgeRuntimeError } from "../types.js";
15
8
  const DEFAULT_IMPORTER = (spec) => import(spec);
@@ -25,15 +18,15 @@ export async function loadCodePlugin(discovered, opts = {}) {
25
18
  });
26
19
  }
27
20
  const importer = opts.importer ?? DEFAULT_IMPORTER;
28
- // Package root path — the entry point is resolved by Node's package.json
29
- // "main"/"exports" fields. Use a file:// URL so Node resolves it as a
30
- // filesystem path rather than a bare specifier.
31
- const spec = pathToFileURL(discovered.path + "/").href;
21
+ let spec = pathToFileURL(discovered.path).href;
32
22
  let mod;
33
23
  try {
24
+ spec = pathToFileURL(await resolveEntry(discovered)).href;
34
25
  mod = await importer(spec);
35
26
  }
36
27
  catch (err) {
28
+ if (err instanceof BridgeRuntimeError)
29
+ throw err;
37
30
  throw new BridgeRuntimeError({
38
31
  bridge: discovered.name,
39
32
  op: "import",
@@ -61,6 +54,42 @@ export async function loadCodePlugin(discovered, opts = {}) {
61
54
  validateBridge(discovered, candidate);
62
55
  return candidate;
63
56
  }
57
+ function importTarget(value) {
58
+ if (typeof value === "string")
59
+ return value;
60
+ if (!value || typeof value !== "object" || Array.isArray(value))
61
+ return undefined;
62
+ const conditions = value;
63
+ return importTarget(conditions.import) ?? importTarget(conditions.default);
64
+ }
65
+ async function resolveEntry(discovered) {
66
+ const root = await realpath(discovered.path);
67
+ const pkg = JSON.parse(await readFile(resolve(root, "package.json"), "utf8"));
68
+ const exported = importTarget(pkg.exports && typeof pkg.exports === "object" && Object.hasOwn(pkg.exports, ".")
69
+ ? pkg.exports["."]
70
+ : pkg.exports);
71
+ const field = exported !== undefined ? "exports" : typeof pkg.main === "string" ? "main" : "index.js";
72
+ const target = exported ?? (typeof pkg.main === "string" ? pkg.main : "index.js");
73
+ const entry = resolve(root, target);
74
+ const assertInside = (path) => {
75
+ const rel = relative(root, path);
76
+ if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
77
+ throw new BridgeRuntimeError({
78
+ bridge: discovered.name,
79
+ op: "import",
80
+ path: discovered.path,
81
+ field,
82
+ expected: "entry inside package directory",
83
+ got: target,
84
+ hint: `package.json ${field} resolves outside the package directory`,
85
+ });
86
+ }
87
+ };
88
+ assertInside(entry);
89
+ const resolved = await realpath(entry);
90
+ assertInside(resolved);
91
+ return resolved;
92
+ }
64
93
  function pickBridgeExport(mod) {
65
94
  if (!mod || typeof mod !== "object")
66
95
  return null;
@@ -12,6 +12,7 @@
12
12
  import { promises as fsp } from "node:fs";
13
13
  import yaml from "js-yaml";
14
14
  import { BridgeRuntimeError } from "../types.js";
15
+ import { protoSafeRecord } from "../../lib/proto-safe-record.js";
15
16
  const VALID_FORMATS = [
16
17
  "jsonl",
17
18
  "json",
@@ -58,13 +59,14 @@ function normalizeSourceTarget(bridge, path, fieldBase, raw) {
58
59
  fail(bridge, path, `${fieldBase}.map`, "object", obj.map, `${fieldBase}.map must be an object of BridgeMemory-field → mapping expression`);
59
60
  }
60
61
  const mapIn = obj.map;
61
- const map = {};
62
62
  for (const [k, v] of Object.entries(mapIn)) {
63
63
  if (typeof v !== "string") {
64
64
  fail(bridge, path, `${fieldBase}.map.${k}`, "string expression", v, `map entries must be strings; got ${typeof v} for ${k}`);
65
65
  }
66
- map[k] = v;
67
66
  }
67
+ // A null-prototype copy: an own `__proto__` map key survives as a key rather
68
+ // than being silently dropped by `[[Set]]` (flair#2235).
69
+ const map = protoSafeRecord(mapIn);
68
70
  const out = {
69
71
  path: obj.path,
70
72
  format: obj.format,
@@ -16,6 +16,7 @@ export const FLAIR_RESERVED_FIELDS = [
16
16
  "retrievalCount",
17
17
  "lastRetrieved",
18
18
  "promotionStatus",
19
+ "promotionContentHash",
19
20
  "_safetyFlags",
20
21
  "createdBy",
21
22
  "updatedBy",
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "0.59.0",
3
- "commit": "e6b92b12a835799d4c55b93619653fa01db79357",
4
- "builtAt": "2026-10-02T08:18:27.351Z",
2
+ "version": "0.63.0",
3
+ "commit": "2684290e86191bdaf14560a45c5d1d0ec6c7d3e4",
4
+ "builtAt": "2026-11-24T15:09:23.643Z",
5
5
  "builder": "tsc"
6
6
  }