@tpsdev-ai/flair 0.59.0 → 0.62.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 (259) hide show
  1. package/README.md +4 -4
  2. package/SECURITY.md +36 -0
  3. package/config.yaml +12 -1
  4. package/dist/bridges/builtins/mem0.js +63 -28
  5. package/dist/bridges/runtime/import-runner.js +12 -0
  6. package/dist/bridges/runtime/load-plugin.js +42 -13
  7. package/dist/bridges/runtime/yaml-loader.js +4 -2
  8. package/dist/build-info.json +3 -3
  9. package/dist/cli.js +991 -248
  10. package/dist/commands/agent.js +224 -43
  11. package/dist/commands/attention.js +4 -3
  12. package/dist/commands/backup.js +202 -34
  13. package/dist/commands/bridge.js +172 -119
  14. package/dist/commands/deploy.js +37 -4
  15. package/dist/commands/doctor.js +592 -146
  16. package/dist/commands/export.js +54 -19
  17. package/dist/commands/federation.js +141 -21
  18. package/dist/commands/hook.js +155 -2
  19. package/dist/commands/idp.js +14 -1
  20. package/dist/commands/import.js +7 -3
  21. package/dist/commands/init.js +462 -193
  22. package/dist/commands/integrity.js +388 -0
  23. package/dist/commands/keys.js +247 -58
  24. package/dist/commands/mcp.js +97 -35
  25. package/dist/commands/memory.js +171 -21
  26. package/dist/commands/migrate-harness-memory.js +3 -2
  27. package/dist/commands/orgevent.js +46 -37
  28. package/dist/commands/presence.js +4 -3
  29. package/dist/commands/principal.js +426 -48
  30. package/dist/commands/quality.js +10 -1
  31. package/dist/commands/reembed.js +141 -17
  32. package/dist/commands/relationship.js +2 -1
  33. package/dist/commands/rem.js +56 -18
  34. package/dist/commands/restore.js +101 -61
  35. package/dist/commands/search.js +6 -4
  36. package/dist/commands/service.js +151 -38
  37. package/dist/commands/soul.js +4 -3
  38. package/dist/commands/status.js +43 -5
  39. package/dist/commands/test.js +3 -2
  40. package/dist/commands/upgrade.js +24 -1
  41. package/dist/commands/workspace.js +6 -3
  42. package/dist/component-env.js +31 -41
  43. package/dist/deploy.js +77 -1
  44. package/dist/doctor-client.js +529 -92
  45. package/dist/engine-version-contract.js +1 -0
  46. package/dist/engine-version.js +23 -3
  47. package/dist/federation-verify.js +4 -3
  48. package/dist/hook-install.js +670 -6
  49. package/dist/keystore.js +72 -0
  50. package/dist/lib/action-recall-runtime.js +328 -0
  51. package/dist/lib/agent-home-fields.js +132 -0
  52. package/dist/lib/agent-home.js +427 -0
  53. package/dist/lib/agent-id-rule.js +46 -0
  54. package/dist/lib/agent-roster.js +33 -0
  55. package/dist/lib/auth-resolve.js +49 -16
  56. package/dist/lib/capture-runtime.js +124 -0
  57. package/dist/lib/credential-status-rule.js +78 -0
  58. package/dist/lib/daemon-liveness.js +41 -10
  59. package/dist/lib/doctor-run.js +75 -37
  60. package/dist/lib/durability-copy.js +10 -0
  61. package/dist/lib/embedding-space-doctor.js +75 -0
  62. package/dist/lib/flair-agent-role.js +4 -0
  63. package/dist/lib/hub-url.js +12 -0
  64. package/dist/lib/init-admin-pass.js +88 -12
  65. package/dist/lib/init-listener-environ.js +1 -2
  66. package/dist/lib/init-occupied-listener.js +15 -111
  67. package/dist/lib/init-spawn-attribution.js +73 -0
  68. package/dist/lib/init-tcp-probe.js +33 -0
  69. package/dist/lib/instance-identity-row.js +20 -0
  70. package/dist/lib/launchd-management.js +24 -0
  71. package/dist/lib/listener-table.js +268 -0
  72. package/dist/lib/local-delete-instance.js +27 -0
  73. package/dist/lib/local-instance-pair.js +256 -0
  74. package/dist/lib/mcp-enable.js +1168 -326
  75. package/dist/lib/mcp-oauth-env-core.js +133 -0
  76. package/dist/lib/mcp-oauth-env.js +125 -0
  77. package/dist/lib/mcp-spec.js +17 -1
  78. package/dist/lib/memory-attributes.js +2 -0
  79. package/dist/lib/memory-id-policy.js +46 -0
  80. package/dist/lib/memory-integrity.js +309 -0
  81. package/dist/lib/memory-purge-response.js +20 -0
  82. package/dist/lib/ops-table-count.js +25 -0
  83. package/dist/lib/owned-pins.js +67 -10
  84. package/dist/lib/peer-status.js +27 -0
  85. package/dist/lib/principal-status.js +29 -0
  86. package/dist/lib/process-start-time.js +76 -12
  87. package/dist/lib/proto-safe-record.js +42 -0
  88. package/dist/lib/record-id-path.js +25 -0
  89. package/dist/lib/reembed-server-support.js +66 -0
  90. package/dist/lib/restore-verify.js +104 -0
  91. package/dist/lib/scheduler-platform.js +10 -6
  92. package/dist/lib/secret-keys.js +25 -0
  93. package/dist/lib/secrets-push.js +50 -22
  94. package/dist/lib/skill-seed-pending.js +24 -0
  95. package/dist/lib/skill-seed.js +365 -0
  96. package/dist/lib/stop-start-recovery.js +54 -0
  97. package/dist/lib/using-flair-skill.js +87 -0
  98. package/dist/mcp-client-assertion.js +112 -4
  99. package/dist/memory-id-checkpoint.js +326 -0
  100. package/dist/memory-node-compare.js +207 -0
  101. package/dist/packages/flair-mcp/src/secret-redaction.js +113 -0
  102. package/dist/rem/restore.js +6 -5
  103. package/dist/rem/runner.js +103 -44
  104. package/dist/resources/Agent.js +321 -1
  105. package/dist/resources/AgentKeyRegister.js +214 -0
  106. package/dist/resources/AgentKeyRegistration.js +28 -0
  107. package/dist/resources/AgentSeed.js +10 -4
  108. package/dist/resources/AutoPromoteCandidates.js +7 -1
  109. package/dist/resources/Credential.js +177 -2
  110. package/dist/resources/Federation.js +751 -143
  111. package/dist/resources/FederationRetry.js +140 -0
  112. package/dist/resources/InstructionVersion.js +220 -0
  113. package/dist/resources/Integration.js +300 -25
  114. package/dist/resources/Memory.js +2113 -604
  115. package/dist/resources/MemoryArchive.js +75 -42
  116. package/dist/resources/MemoryBootstrap.js +110 -39
  117. package/dist/resources/MemoryCandidate.js +21 -1
  118. package/dist/resources/MemoryDedupStats.js +30 -1
  119. package/dist/resources/MemoryFeed.js +327 -45
  120. package/dist/resources/MemoryGrant.js +21 -1
  121. package/dist/resources/MemoryMaintenance.js +129 -25
  122. package/dist/resources/MemoryPurge.js +232 -0
  123. package/dist/resources/MemoryReflect.js +7 -2
  124. package/dist/resources/MemoryReindex.js +24 -8
  125. package/dist/resources/Message.js +5 -3
  126. package/dist/resources/OAuth.js +186 -9
  127. package/dist/resources/OrgEvent.js +126 -3
  128. package/dist/resources/Presence.js +144 -49
  129. package/dist/resources/PromoteMemoryCandidate.js +18 -7
  130. package/dist/resources/Relationship.js +23 -0
  131. package/dist/resources/SemanticSearch.js +63 -32
  132. package/dist/resources/Soul.js +189 -76
  133. package/dist/resources/TeamDirectory.js +35 -0
  134. package/dist/resources/WorkspaceState.js +21 -1
  135. package/dist/resources/XAA.js +181 -63
  136. package/dist/resources/agent-auth.js +40 -15
  137. package/dist/resources/auth-middleware.js +400 -161
  138. package/dist/resources/ed25519-auth.js +1 -1
  139. package/dist/resources/embedding-space-guard.js +366 -72
  140. package/dist/resources/engine-version-stamp-boot.js +53 -0
  141. package/dist/resources/federation-classify.js +72 -0
  142. package/dist/resources/federation-crypto.js +5 -5
  143. package/dist/resources/federation-retry-lib.js +135 -0
  144. package/dist/resources/grant-visibility.js +135 -0
  145. package/dist/resources/harper-routing.js +83 -0
  146. package/dist/resources/health.js +120 -18
  147. package/dist/resources/host-source-citation.js +49 -0
  148. package/dist/resources/host-source-visibility.js +7 -6
  149. package/dist/resources/instance-create-lock.js +17 -0
  150. package/dist/resources/instance-identity.js +23 -0
  151. package/dist/resources/instruction-version-record.js +343 -0
  152. package/dist/resources/key-lock.js +3 -3
  153. package/dist/resources/mcp-handler.js +36 -8
  154. package/dist/resources/mcp-oauth-env-guard.js +36 -0
  155. package/dist/resources/mcp-oauth.js +23 -6
  156. package/dist/resources/mcp-tool-arguments.js +4 -6
  157. package/dist/resources/mcp-tools.js +128 -19
  158. package/dist/resources/memory-bootstrap-lib.js +5 -15
  159. package/dist/resources/memory-declared-attributes.js +3 -1
  160. package/dist/resources/memory-deletion-history.js +55 -0
  161. package/dist/resources/memory-durability.js +54 -0
  162. package/dist/resources/memory-embed-hash.js +88 -0
  163. package/dist/resources/memory-embedding-value.js +8 -0
  164. package/dist/resources/memory-host-source.js +27 -5
  165. package/dist/resources/memory-id-guard.js +75 -0
  166. package/dist/resources/memory-redaction.js +236 -0
  167. package/dist/resources/memory-supplied-vector.js +72 -0
  168. package/dist/resources/memory-write-lock.js +310 -0
  169. package/dist/resources/memory-write-response.js +139 -0
  170. package/dist/resources/migrations/data-dir.js +74 -16
  171. package/dist/resources/migrations/dir-safety.js +1 -1
  172. package/dist/resources/migrations/embedding-stamp.js +193 -79
  173. package/dist/resources/migrations/export.js +1 -0
  174. package/dist/resources/migrations/graph-heal.js +18 -25
  175. package/dist/resources/migrations/lock.js +7 -1
  176. package/dist/resources/migrations/snapshot.js +1 -0
  177. package/dist/resources/migrations/source-fields.js +5 -5
  178. package/dist/resources/migrations/synthetic-test-migration.js +14 -11
  179. package/dist/resources/migrations/visibility-backfill.js +29 -29
  180. package/dist/resources/object-body-guard.js +33 -0
  181. package/dist/resources/org-event-created-at.js +133 -0
  182. package/dist/resources/originator-instance.js +39 -7
  183. package/dist/resources/owner-delete-recheck.js +78 -0
  184. package/dist/resources/owner-field-guard.js +39 -5
  185. package/dist/resources/owner-scoped-write-policy.js +212 -0
  186. package/dist/resources/owner-scoped-writes.js +58 -0
  187. package/dist/resources/presence-receipt.js +236 -0
  188. package/dist/resources/promotion-stamp.js +47 -12
  189. package/dist/resources/record-owner-guard.js +74 -26
  190. package/dist/resources/record-types.js +1 -1
  191. package/dist/resources/relay-ops.js +78 -6
  192. package/dist/resources/replay-store.js +96 -19
  193. package/dist/resources/request-target.js +136 -0
  194. package/dist/resources/request-transaction.js +35 -0
  195. package/dist/resources/search-readiness.js +4 -1
  196. package/dist/resources/seed-ids.js +9 -0
  197. package/dist/resources/seed-reservation.js +117 -0
  198. package/dist/resources/semantic-retrieval-core.js +20 -9
  199. package/dist/resources/skill-manifest.js +20 -11
  200. package/dist/resources/skill-subject.js +53 -0
  201. package/dist/resources/skill-version-write.js +432 -0
  202. package/dist/resources/skill-write-fault.js +17 -0
  203. package/dist/resources/skill-write-policy.js +67 -0
  204. package/dist/resources/skill-write.js +67 -7
  205. package/dist/resources/table-helpers.js +10 -7
  206. package/dist/resources/team-directory.js +248 -0
  207. package/dist/resources/tool-descriptors/index.js +69 -8
  208. package/dist/resources/txn-pause-point.js +118 -0
  209. package/dist/resources/usage-recording.js +171 -63
  210. package/dist/resources/write-back.js +218 -0
  211. package/dist/src/engine-version-contract.js +1 -0
  212. package/dist/src/keystore.js +72 -0
  213. package/dist/src/lib/agent-home-fields.js +132 -0
  214. package/dist/src/lib/agent-id-rule.js +46 -0
  215. package/dist/src/lib/agent-key-register.js +80 -0
  216. package/dist/src/lib/atomic-write.js +256 -0
  217. package/dist/src/lib/credential-status-rule.js +78 -0
  218. package/dist/src/lib/expired-by-agent.js +37 -0
  219. package/dist/src/lib/flair-agent-role.js +4 -0
  220. package/dist/src/lib/idp-mapping-rule.js +81 -0
  221. package/dist/src/lib/instance-identity-row.js +20 -0
  222. package/dist/src/lib/mcp-oauth-env-core.js +133 -0
  223. package/dist/src/lib/memory-attributes.js +2 -0
  224. package/dist/src/lib/memory-id-policy.js +46 -0
  225. package/dist/src/lib/principal-status.js +29 -0
  226. package/dist/src/lib/proto-safe-record.js +42 -0
  227. package/dist/src/lib/reembed-server-support.js +66 -0
  228. package/dist/src/lib/scheduler-platform.js +10 -6
  229. package/dist/src/lib/systemd-agent-id.js +38 -0
  230. package/docs/access-control.md +146 -45
  231. package/docs/api-reference.md +46 -11
  232. package/docs/auth.md +6 -12
  233. package/docs/bridges.md +11 -0
  234. package/docs/claude-code.md +34 -4
  235. package/docs/deploying-on-fabric.md +70 -0
  236. package/docs/deployment.md +2 -0
  237. package/docs/embedding-in-a-harper-app.md +1 -1
  238. package/docs/federation.md +33 -2
  239. package/docs/hosted-on-fabric.md +43 -36
  240. package/docs/integrations.md +5 -5
  241. package/docs/mcp-clients.md +5 -2
  242. package/docs/n8n.md +17 -11
  243. package/docs/notes/mcp-agent-auth-consumer.md +12 -4
  244. package/docs/notes/mcp-oauth-model2.md +34 -5
  245. package/docs/quickstart-fabric.md +2 -2
  246. package/docs/quickstart.md +9 -1
  247. package/docs/releasing.md +12 -6
  248. package/docs/rem.md +8 -0
  249. package/docs/secrets-and-keys.md +19 -2
  250. package/docs/standalone-local.md +1 -0
  251. package/docs/supply-chain-policy.md +13 -3
  252. package/docs/upgrade.md +32 -6
  253. package/package.json +10 -5
  254. package/schemas/agent-key-registration.graphql +22 -0
  255. package/schemas/agent.graphql +3 -0
  256. package/schemas/federation.graphql +38 -1
  257. package/schemas/memory.graphql +84 -5
  258. package/schemas/oauth.graphql +19 -0
  259. package/schemas/schema.graphql +2 -0
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
@@ -173,7 +173,7 @@ See **[DESIGN.md](DESIGN.md)** for the invariants behind the three primitives
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. |
@@ -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
 
package/SECURITY.md CHANGED
@@ -79,6 +79,42 @@ 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 a differing string or number body `id` on POST/PUT/PATCH
96
+ first (`403 write_id_not_addressed`), then stored ownership (the same owner
97
+ refusal), using Harper's resolved record id. An absent or matching body `id`
98
+ passes the body-id check. OrgEvent and Memory bind an addressed POST's
99
+ missing body `id` to the addressed id.
100
+ - For a collection PUT, PATCH or DELETE, if reached, the table guard returns
101
+ `403 forbidden: a non-admin write to <Table> must address one record by its id`;
102
+ existing DELETE middleware may refuse earlier.
103
+
104
+ A refusal by this guard leaves its target row unchanged and carries no record
105
+ content. A POST to a collection is delegated to each resource's own
106
+ POST handling — its create and attribution rules (for example, an OrgEvent
107
+ collection POST that names an existing event owned by another agent reaches
108
+ OrgEvent's ownership check and is refused, one that names the caller's own
109
+ existing event can update it when OrgEvent's other checks pass (a changed
110
+ `createdAt` is refused with 409), and a
111
+ Presence heartbeat writes the caller's own row). Routes served
112
+ by a custom resource rather than a table-backed one are outside this table
113
+ guard and apply their own rules; `/AgentReadPosition`, for example, enforces
114
+ its own ownership rule.
115
+ The guard exempts administrator and in-process calls. OrgEvent POST id
116
+ selection also applies to administrator and in-process calls.
117
+
82
118
  ### Cross-Agent Access (within an org)
83
119
 
84
120
  Within an org, an agent reads every non-private memory directly — no grant
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
@@ -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() === "")
@@ -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,
@@ -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.62.0",
3
+ "commit": "2461721a17f346ef922f9665a14e940e257415d1",
4
+ "builtAt": "2026-10-17T20:48:39.747Z",
5
5
  "builder": "tsc"
6
6
  }