@tpsdev-ai/flair 0.58.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 (268) hide show
  1. package/README.md +7 -6
  2. package/SECURITY.md +36 -0
  3. package/config.yaml +15 -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 +1030 -343
  10. package/dist/commands/agent.js +384 -45
  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 +601 -163
  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 +146 -53
  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 +81 -8
  59. package/dist/lib/doctor-run.js +140 -35
  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 +120 -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 +27 -2
  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 +1775 -338
  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 +103 -7
  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 +348 -8
  105. package/dist/resources/AgentKeyRegister.js +214 -0
  106. package/dist/resources/AgentKeyRegistration.js +28 -0
  107. package/dist/resources/AgentSeed.js +19 -4
  108. package/dist/resources/AutoPromoteCandidates.js +7 -1
  109. package/dist/resources/Credential.js +177 -2
  110. package/dist/resources/Federation.js +752 -132
  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 +227 -64
  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/OrgSkillAssignment.js +209 -0
  129. package/dist/resources/Presence.js +144 -49
  130. package/dist/resources/PromoteMemoryCandidate.js +18 -7
  131. package/dist/resources/Relationship.js +23 -0
  132. package/dist/resources/SemanticSearch.js +63 -32
  133. package/dist/resources/Soul.js +189 -76
  134. package/dist/resources/TeamDirectory.js +35 -0
  135. package/dist/resources/WorkspaceState.js +21 -1
  136. package/dist/resources/XAA.js +212 -65
  137. package/dist/resources/agent-auth.js +40 -15
  138. package/dist/resources/agent-status-guard.js +63 -0
  139. package/dist/resources/auth-middleware.js +402 -162
  140. package/dist/resources/ed25519-auth.js +1 -1
  141. package/dist/resources/embedding-space-guard.js +366 -72
  142. package/dist/resources/engine-version-stamp-boot.js +53 -0
  143. package/dist/resources/federation-classify.js +94 -0
  144. package/dist/resources/federation-crypto.js +5 -5
  145. package/dist/resources/federation-retry-lib.js +135 -0
  146. package/dist/resources/flair-agent-role-boot.js +26 -0
  147. package/dist/resources/grant-visibility.js +135 -0
  148. package/dist/resources/harper-routing.js +83 -0
  149. package/dist/resources/health.js +130 -20
  150. package/dist/resources/host-source-citation.js +49 -0
  151. package/dist/resources/host-source-visibility.js +7 -6
  152. package/dist/resources/instance-create-lock.js +17 -0
  153. package/dist/resources/instance-identity.js +23 -0
  154. package/dist/resources/instruction-version-record.js +343 -0
  155. package/dist/resources/key-lock.js +31 -0
  156. package/dist/resources/mcp-handler.js +36 -8
  157. package/dist/resources/mcp-oauth-env-guard.js +36 -0
  158. package/dist/resources/mcp-oauth.js +26 -12
  159. package/dist/resources/mcp-tool-arguments.js +4 -6
  160. package/dist/resources/mcp-tools.js +150 -23
  161. package/dist/resources/memory-bootstrap-lib.js +5 -15
  162. package/dist/resources/memory-declared-attributes.js +3 -1
  163. package/dist/resources/memory-deletion-history.js +55 -0
  164. package/dist/resources/memory-durability.js +54 -0
  165. package/dist/resources/memory-embed-hash.js +88 -0
  166. package/dist/resources/memory-embedding-value.js +8 -0
  167. package/dist/resources/memory-host-source.js +27 -5
  168. package/dist/resources/memory-id-guard.js +75 -0
  169. package/dist/resources/memory-redaction.js +236 -0
  170. package/dist/resources/memory-supplied-vector.js +72 -0
  171. package/dist/resources/memory-write-lock.js +310 -0
  172. package/dist/resources/memory-write-response.js +139 -0
  173. package/dist/resources/migrations/data-dir.js +74 -16
  174. package/dist/resources/migrations/dir-safety.js +1 -1
  175. package/dist/resources/migrations/embedding-stamp.js +193 -79
  176. package/dist/resources/migrations/export.js +1 -0
  177. package/dist/resources/migrations/graph-heal.js +18 -25
  178. package/dist/resources/migrations/lock.js +7 -1
  179. package/dist/resources/migrations/snapshot.js +1 -0
  180. package/dist/resources/migrations/source-fields.js +5 -5
  181. package/dist/resources/migrations/synthetic-test-migration.js +14 -11
  182. package/dist/resources/migrations/visibility-backfill.js +29 -29
  183. package/dist/resources/multi-worker-guard.js +121 -0
  184. package/dist/resources/oauth-discovery.js +1 -0
  185. package/dist/resources/oauth-wellknown.js +8 -4
  186. package/dist/resources/object-body-guard.js +33 -0
  187. package/dist/resources/org-event-created-at.js +133 -0
  188. package/dist/resources/originator-instance.js +39 -7
  189. package/dist/resources/owner-delete-recheck.js +78 -0
  190. package/dist/resources/owner-field-guard.js +39 -5
  191. package/dist/resources/owner-scoped-write-policy.js +212 -0
  192. package/dist/resources/owner-scoped-writes.js +58 -0
  193. package/dist/resources/presence-receipt.js +236 -0
  194. package/dist/resources/promotion-stamp.js +47 -12
  195. package/dist/resources/record-owner-guard.js +74 -26
  196. package/dist/resources/record-types.js +17 -1
  197. package/dist/resources/relay-ops.js +78 -6
  198. package/dist/resources/replay-store.js +145 -21
  199. package/dist/resources/request-target.js +136 -0
  200. package/dist/resources/request-transaction.js +35 -0
  201. package/dist/resources/search-readiness.js +4 -1
  202. package/dist/resources/seed-ids.js +9 -0
  203. package/dist/resources/seed-reservation.js +117 -0
  204. package/dist/resources/semantic-retrieval-core.js +20 -9
  205. package/dist/resources/skill-manifest.js +190 -0
  206. package/dist/resources/skill-provenance.js +15 -10
  207. package/dist/resources/skill-subject.js +53 -0
  208. package/dist/resources/skill-version-write.js +432 -0
  209. package/dist/resources/skill-write-fault.js +17 -0
  210. package/dist/resources/skill-write-policy.js +67 -0
  211. package/dist/resources/skill-write.js +67 -7
  212. package/dist/resources/table-helpers.js +10 -7
  213. package/dist/resources/team-directory.js +248 -0
  214. package/dist/resources/tool-descriptors/index.js +69 -8
  215. package/dist/resources/txn-pause-point.js +118 -0
  216. package/dist/resources/usage-recording.js +171 -63
  217. package/dist/resources/write-back.js +218 -0
  218. package/dist/src/engine-version-contract.js +1 -0
  219. package/dist/src/keystore.js +72 -0
  220. package/dist/src/lib/agent-home-fields.js +132 -0
  221. package/dist/src/lib/agent-id-rule.js +46 -0
  222. package/dist/src/lib/agent-key-register.js +80 -0
  223. package/dist/src/lib/atomic-write.js +256 -0
  224. package/dist/src/lib/credential-status-rule.js +78 -0
  225. package/dist/src/lib/expired-by-agent.js +37 -0
  226. package/dist/src/lib/flair-agent-role.js +120 -0
  227. package/dist/src/lib/idp-mapping-rule.js +81 -0
  228. package/dist/src/lib/instance-identity-row.js +20 -0
  229. package/dist/src/lib/mcp-oauth-env-core.js +133 -0
  230. package/dist/src/lib/memory-attributes.js +2 -0
  231. package/dist/src/lib/memory-id-policy.js +46 -0
  232. package/dist/src/lib/principal-status.js +29 -0
  233. package/dist/src/lib/proto-safe-record.js +42 -0
  234. package/dist/src/lib/reembed-server-support.js +66 -0
  235. package/dist/src/lib/scheduler-platform.js +10 -6
  236. package/dist/src/lib/systemd-agent-id.js +38 -0
  237. package/docs/access-control.md +768 -0
  238. package/docs/api-reference.md +52 -13
  239. package/docs/auth.md +10 -12
  240. package/docs/bridges.md +11 -0
  241. package/docs/claude-code.md +34 -4
  242. package/docs/deepseek-harness.md +1 -1
  243. package/docs/deploying-on-fabric.md +70 -0
  244. package/docs/deployment.md +2 -0
  245. package/docs/embedding-in-a-harper-app.md +1 -1
  246. package/docs/federation.md +33 -2
  247. package/docs/hosted-on-fabric.md +43 -36
  248. package/docs/integrations.md +6 -6
  249. package/docs/mcp-clients.md +10 -5
  250. package/docs/n8n.md +17 -11
  251. package/docs/notes/mcp-agent-auth-consumer.md +12 -4
  252. package/docs/notes/mcp-oauth-model2.md +34 -5
  253. package/docs/quickstart-fabric.md +2 -2
  254. package/docs/quickstart.md +9 -1
  255. package/docs/releasing.md +34 -28
  256. package/docs/rem.md +8 -0
  257. package/docs/secrets-and-keys.md +19 -2
  258. package/docs/standalone-local.md +1 -0
  259. package/docs/supply-chain-policy.md +13 -3
  260. package/docs/upgrade.md +32 -6
  261. package/package.json +12 -6
  262. package/schemas/agent-key-registration.graphql +22 -0
  263. package/schemas/agent.graphql +3 -0
  264. package/schemas/federation.graphql +38 -1
  265. package/schemas/memory.graphql +115 -5
  266. package/schemas/oauth.graphql +27 -4
  267. package/schemas/schema.graphql +2 -0
  268. package/templates/launchd/start-flair-with-admin-pass.sh +89 -16
@@ -52,7 +52,7 @@ the schema section so the catalog is complete.
52
52
  | **Public** | none | Discovery, health, OAuth well-known. `GET /Presence` is public only when the instance opts in to a public roster (`PRESENCE_PUBLIC_ROSTER=true`) — by default it needs a verified reader. See [Presence for API consumers](#presence-for-api-consumers). |
53
53
  | **Ed25519 agent** | `TPS-Ed25519` header | Default agent path. Writes as self only. Reads follow the resource's read-scope (below). |
54
54
  | **Admin Basic** | Harper `HDB_ADMIN_PASSWORD` / `FLAIR_ADMIN_PASSWORD` | Whole-instance operator. Bypasses agent scoping, including `private` memory. Used by the web admin and `n8n-nodes-flair`. |
55
- | **Operator / internal** | Admin Basic, or a deliberate `internalContext()` call inside the process | Soul mutations and `AgentSeed`. Agent Ed25519 keys — including admin-agent keys — cannot author Soul. |
55
+ | **Operator / internal** | Admin Basic, or a deliberate `internalContext()` call inside the process | Soul mutations, `OrgSkillAssignment` writes and `AgentSeed`. Agent Ed25519 keys — including admin-agent keys — cannot author Soul. |
56
56
  | **Federation body-sig** | Ed25519 over the request body + timestamp/nonce; pairing uses a one-time token | `/FederationPair`, `/FederationSync`. Harper role gate is open; the handler is the auth boundary. |
57
57
  | **OAuth bearer** | Access token from Flair's AS or `@harperfast/oauth` | `/mcp` only, and only when `FLAIR_MCP_OAUTH=true` plus a public issuer. Off by default (path 404s). |
58
58
 
@@ -91,7 +91,7 @@ From `RECORD_TYPES` in `resources/record-types.ts`:
91
91
  |-------|---------|--------|
92
92
  | **open-within-org** | Own rows (any visibility) plus every other agent's non-private rows | Memory |
93
93
  | **owner-only** | Only the owning agent (plus admin / internal) | Relationship, WorkspaceState, Asset, MemoryCandidate |
94
- | **none** | Any verified agent reads every row; no visibility field | Soul, OrgEvent |
94
+ | **none** | Any verified agent reads every row; no visibility field | Soul, OrgEvent, OrgSkillAssignment |
95
95
 
96
96
  These three scopes are **not** in `RECORD_TYPES`. Each is hand-implemented on its
97
97
  own resource:
@@ -136,6 +136,7 @@ is `GET /Name/<id>` unless noted.
136
136
  | POST | `/Agent` | Admin Basic | Create principal. Also `POST /AgentSeed` (operator/internal only — not an admin-agent key). |
137
137
  | PUT / PATCH | `/Agent/<id>` | Ed25519 | An agent updates **only its own** record. |
138
138
  | DELETE | `/Agent/<id>` | Admin Basic | Deprovision. |
139
+ | POST | `/AgentKeyRegister` | Basic admin / Ed25519 agent with the admin annotation | Register an agent key. Under Flair's per-agent registration lock, reads a fresh local, non-deactivated row with `publicKey: "pending"` and, at the confirmation read, requires the committed row to equal the fresh-read snapshot and still be `pending` before commit. The lock serializes registrations for that agent within one Harper process; raw operations-API writes and other processes do not take it. A change committed after the confirmation read and before commit is not seen, and a change restored before the confirmation read is not observed; a commit-time pending check is a follow-up. Unsupported schemes that reach the handler receive 401 before Flair's `resolveAgentAuth`, body validation and table reads. Harper handles some Authorization values upstream: a Bearer refresh token receives Harper's 404 before any resource runs. Refuses 409 `agent_key_not_pending` (a non-`pending` row points to key rotation), 403 `agent_not_local` / `agent_inactive`, 404 `agent_not_found`, 400 `registration_request_invalid`, 409 `registration_conflict`, 503 `registration_unavailable`. Writes an `AgentKeyRegistration` audit row and an `agent_key_registered` OrgEvent. The audit `keyFingerprint` and the event `detail` carry the key fingerprint, not the key; the audit `agentId` and the event `refId` carry the target agent's id, which the event `summary` names in text. |
139
140
  | GET | `/Presence` | Verified reader | Roster. Requires a valid `TPS-Ed25519` agent signature or the admin credential; an anonymous request gets 401. An instance may opt in to a public roster with `PRESENCE_PUBLIC_ROSTER=true`, in which case an unverified reader gets the allowlisted roster with `currentTask`, `flairVersion`, and `harperVersion` as null. Thresholds: [Presence for API consumers](#presence-for-api-consumers). |
140
141
  | POST | `/Presence` | Ed25519 | Heartbeat. Agent writes only its own row (403 cross-agent). Stamps `flairVersion` / `harperVersion` on the row. |
141
142
  | PUT / DELETE | `/Presence/<id>` | Ed25519 | Own row only. Collection PUT is not a public bypass. |
@@ -143,9 +144,15 @@ is `GET /Name/<id>` unless noted.
143
144
  | POST / PUT / PATCH / DELETE | `/Soul` | **Operator / internal** | Not Ed25519. Learned Memory text cannot be copied in as Soul. See [docs/auth.md](auth.md#soul-authorship). |
144
145
  | POST | `/FeedSouls` | Ed25519 | Soul change feed (verified). |
145
146
 
146
- `Credential` (GET/POST verified; extra credentials for a principal) and
147
+ `Credential` (GET/POST verified; extra credentials for a principal; through
148
+ this resource only an administrator or the server creates a `kind: "idp"`
149
+ credential, changes its kind or identity fields, or reactivates it, and its
150
+ owner may relabel, revoke or delete it, see
151
+ [Who writes a mapping](access-control.md#who-writes-a-mapping)) and
147
152
  `Integration` (legacy 0.x platform rows; verified, prefer Credential) sit on
148
- the same identity plane.
153
+ the same identity plane. `AgentKeyRegistration`
154
+ (agent-key-registration.graphql) is the admin-read-only audit log of committed
155
+ registrations; its key field is the fingerprint, not the key.
149
156
 
150
157
  ### Memory, search, bootstrap
151
158
 
@@ -153,12 +160,13 @@ the same identity plane.
153
160
  |--------|------|------|--------------|
154
161
  | GET | `/Memory`, `/Memory/<id>` | Ed25519 | open-within-org. By-id deny = 404. |
155
162
  | POST / PUT / PATCH | `/Memory` | Ed25519 | Own `agentId` only. Auto-embed on write. Visibility defaults from durability (`permanent`/`persistent` → `shared`, `standard`/`ephemeral` → `private`). Identified client older than 0.18.0 → **426** `stale_flair_client` (missing version is served). |
163
+ | PATCH | `/Memory/<id>`, body `{"embedding": null, "embeddingModel": null}` | Ed25519 | Owner or admin. Re-embeds the stored row, writing `embedding`, `embeddingModel` and `updatedAt`, and answers `{ id, updatedAt }` (what `flair reembed` sends; it reads `embeddingModel` from the stored row afterwards). |
156
164
  | DELETE | `/Memory/<id>` | Ed25519 | Owner or admin. `permanent` owner-delete is allowed. |
157
- | POST | `/SemanticSearch` | Ed25519 | Hybrid semantic + lexical. Same read-scope as Memory. Default scoring is `raw`. |
165
+ | POST | `/SemanticSearch` | Ed25519 | Hybrid semantic + lexical. Same read-scope as Memory. Default scoring is `raw`. Results carry `provenance` (like the by-id and list reads); `includeTrust` and `abstain` stay opt-in. |
158
166
  | POST | `/BootstrapMemories` | Ed25519 | Cold-start context (soul + predicted memories + optional org events). |
159
167
  | POST | `/RecordUsage` | Ed25519 | Cross-agent usage signal (`Memory.usageCount`). No ownership requirement; counts only memories in the caller's read scope (`resolveReadScope`: own at any visibility, others' non-private), admin callers included even though admin Memory reads are unfiltered; an out-of-scope id is handled like a missing one. No existence oracle in the response. Prefer this over writing `/MemoryUsage` directly. |
160
168
  | GET | `/MemoryUsage` | Ed25519 | Non-admin reads: own ledger rows only, about memories the caller can currently read; any other row reads as not found. Admin and internal reads are unchanged. PUT/DELETE are admin/internal — agents must not delete their row to re-count. |
161
- | GET / write | `/MemoryGrant` | Ed25519 | Read: owner or grantee. Write/delete: owner only (you share your own memories). |
169
+ | GET / write | `/MemoryGrant` | Ed25519 | Non-admin reads: owner or grantee. Write/delete: owner only (you share your own memories). A `write` grant lets the grantee write a successor of the owner's memory or skill (`supersedes`). A write grant does not include changing a record's visibility; visibility is set by the owner or an admin. For that grant-authorized write, the successor carries the predecessor's visibility, and a write naming a different one is refused with 403 `grant_cannot_change_visibility` unless an earlier validation refuses it first (an ordinary, non-skill ephemeral write naming `shared` gets 400 `invalid_visibility_for_durability`; an ephemeral skill write gets 400 `skill_durability`, and a `session` skill write gets 400 `invalid_durability` on Memory POST/PUT (durability validation runs first) and 400 `skill_durability` on FeedMemories). After staging the close, the writer re-reads the predecessor's committed row; a visibility that no longer reads the same refuses the write with 409 `predecessor_visibility_changed`, and a change committed after that final re-read is not seen. An ordinary successor and its close share the write's transaction. An ordinary close refusal aborts the whole write: a storage Response returns the fixed 500 `write_response_withheld`; grant revocation returns 409 `granted_close_revoked`; a predecessor change that keeps visibility the same returns 409 `stored_row_changed`. No refusal writes anything. An ordinary successor is the grantee's own row, so the grantee may later change its visibility as its owner; a skill successor keeps its lineage owner. |
162
170
  | GET / write | `/Asset` | Ed25519 | Owner-only blobs linked by `memoryId`. No MCP and no federation in this slice. |
163
171
  | GET / write | `/MemoryCandidate` | Ed25519 | Owner-only REM drafts. Never auto-promoted except the narrow ADK path. |
164
172
  | POST | `/PromoteMemoryCandidate` | Ed25519 | Promote/reject with required rationale. |
@@ -170,7 +178,10 @@ the same identity plane.
170
178
  | POST | `/MemoryConsolidate` | Ed25519 | Dedup / consolidate. |
171
179
  | POST | `/MemoryReflect` | Ed25519 | REM distill → MemoryCandidate. |
172
180
  | POST | `/MemoryDedupStats` | Admin Basic | Dedup diagnostics. Fleet-wide sweep; `allowCreate` is `allowAdmin`. |
181
+ | POST | `/MemoryPurge` | **Operator / internal** | Not Ed25519, admin-agent keys included. Physical removal of Memory rows by id; a skill-tagged row expands to its whole skill lineage. `removedIds` lists the rows a read after the commit finds gone; a target not stored before the delete fails the call (404). A target still stored after the commit keeps its pointer row. Unconfirmed history cleanup returns 500 `memory_purge_history_cleanup_unconfirmed` before pointer-cleanup failure (500 `memory_purge_pointer_cleanup_failed`) or a still-stored target (409 `memory_purge_unconfirmed`). Does not change `DELETE /Memory/<id>`. An accepted DELETE of a non-reserved skill closes its head; the reserved `using-flair` seed is physically deleted. |
173
182
  | POST | `/SkillScan` | Ed25519 | Skill-tag scan on Memory writes. |
183
+ | GET | `/OrgSkillAssignment`, `/OrgSkillAssignment/<id>` | Ed25519 | Any verified agent. Org-scope skill assignments; see the `skills` paragraph in [docs/mcp-clients.md](mcp-clients.md). Not federated. |
184
+ | POST / PUT / PATCH / DELETE | `/OrgSkillAssignment/` (POST), `/OrgSkillAssignment/<id>` (PUT / PATCH / DELETE) | **Operator / internal** | Not Ed25519, admin-agent keys included. Each accepted write appends an `OrgSkillAssignmentHistory` row. |
174
185
 
175
186
  Skill-tagged Memory rows embed from `trigger` (the recall signal), not
176
187
  `content`. MCP tools: `skill_store`, `skill_search`, `skill_get`.
@@ -215,7 +226,7 @@ The remedy is `flair upgrade` (the adapter), not a server upgrade alone.
215
226
  | GET / POST / PUT | `/Relationship` | Ed25519 / Admin Basic | Owner-only for non-admin agents; administrators can read across owners. POST creates; a create that is otherwise admitted, valid and within the rate limit is 409 when its id already exists. PUT upserts. For a verified non-admin agent both stamp the owner from the caller (a body naming another agent is 403); an administrator keeps the owner it supplies. A write that passes validation gets provenance built server-side. |
216
227
  | GET / POST / PUT | `/WorkspaceState` | Ed25519 | Owner-only. POST stamps `agentId`; PUT rejects a mismatch. |
217
228
  | GET | `/WorkspaceLatest` | Ed25519 | Latest workspace row for the caller. |
218
- | GET / POST / PUT | `/OrgEvent` | Ed25519 | Any verified agent reads every event. Writes stamp `authorId`. |
229
+ | GET / POST / PUT / PATCH | `/OrgEvent` | Ed25519 / Admin Basic | Any verified agent reads every event. `authorId` for a non-admin agent: POST sets it from the caller, whatever the body says; PUT requires the body to name the caller (403 otherwise, including when it is absent); PATCH leaves the stored value unless the body names one, and refuses a change (403). An administrator (an admin agent key or credentialed Basic admin) may supply `authorId` on any verb; POST defaults it to the administrator's own id. The server assigns an OrgEvent's `createdAt` on create. After the earlier checks, a `createdAt` check reads the stored row under each event's id. A stored row's `createdAt` is authoritative whatever its value (an empty string included): an update that omits it keeps it, and one that names a different value is refused with 409 `created_at_immutable`. An event that reaches the check and is not an object, or whose id is not a non-empty string or a non-empty array of strings, is refused with 400 `invalid_event_id` before any write, as is an administrator's PATCH to the collection (for a non-admin's collection PUT, PATCH or DELETE, if reached, the table guard returns the 403 collection refusal; existing DELETE middleware may refuse earlier). Before validation, an addressed POST binds a missing or `null` body id to the addressed id, and a string or number body id when its text matches the address; any other id type is left unchanged by this step. At the root collection, POST generates an id when the body's id is missing, `null` or empty. At POST id validation, at the root collection or an addressed path whose body id was not bound, a remaining id that is not a non-empty string or a non-empty array of strings receives 400 `invalid_event_id`. |
219
230
  | GET / POST | `/OrgEventCatchup` | Ed25519 | Catch-up feed for the caller. `since` is optional (defaults to the per-agent watermark). GET pages; POST acks `{ position }` (advance-on-ack). |
220
231
  | GET / POST | `/AgentReadPosition` | Ed25519 | Owner-only watermark (`stream`, default `org-event`). Foundation for light-comms catch-up. |
221
232
  | POST | `/OrgEventMaintenance` | Ed25519 / admin | Expire / sweep org events. |
@@ -262,8 +273,13 @@ operator audit trail.
262
273
  | GET / write | `/IdpConfig` | Admin Basic | XAA IdP registration (`flair idp add`). |
263
274
  | GET | `/MCPClientMetadata` | Public / handler-gated | CIMD documents for allowed hosts. |
264
275
 
265
- `OAuthAuthCode`, `OAuthToken`, and `IdJagReplay` are internal tables (no
266
- `@export`). They hold codes, hashed tokens, and used `jti` values.
276
+ `OAuthAuthCode`, `OAuthToken`, `IdJagReplay`, and `OAuthSingleUse` are internal
277
+ tables (no `@export`). They hold codes, hashed tokens, used `jti` values, and
278
+ the hashed keys of codes presented for redemption and refresh tokens presented
279
+ for rotation. A single-use row records that a redemption was claimed. The
280
+ handler attempts the later `used` or revocation write before issuing tokens.
281
+ If that write fails, no token pair is issued; the claim remains, so the code
282
+ or token cannot be redeemed again.
267
283
 
268
284
  OAuth rate limits and env vars: [docs/auth.md](auth.md#rate-limiting).
269
285
 
@@ -332,7 +348,7 @@ client-writable even if a client sends them. Full comments live in
332
348
 
333
349
  `GET /Presence` requires a **verified reader** by default. A verified reader is a request carrying a valid `TPS-Ed25519` agent signature from an agent registered on this instance, or the admin credential. An anonymous — or otherwise unverified — request gets **401**, not a redacted roster. The roster is org-visible data (who is working, on what class of activity, and how recently) and is not published by default.
334
350
 
335
- An instance that runs a public status page opts back in with the presence config key `PRESENCE_PUBLIC_ROSTER=true` (the same env-var channel as the thresholds below); it is **off by default** and is documented as *publishes your roster to the internet*. With it on the behaviour is exactly as it was before: an anonymous caller gets the field-allowlisted roster (id, display name, role, runtime, activity fields, `presenceStatus`, `lastHeartbeatAt`), and three fields are redacted to `null` unless the request carries a valid `TPS-Ed25519` agent signature: `currentTask`, `flairVersion`, and `harperVersion`. Anonymous callers, unsigned loopback, Basic admin, and in-process calls without that signature are unverified readers of the content gate. The nulls are intentional. Version strings are withheld so a public roster cannot fingerprint the instance (the same split as public `/Health` versus Ed25519 `/HealthDetail`). A null `flairVersion` on an unverified read does not mean the peer lacks a version, and it does not mean the peer cannot accept a directed handoff.
351
+ An instance that runs a public status page opts back in with the presence config key `PRESENCE_PUBLIC_ROSTER=true` (the same env-var channel as the thresholds below); it is **off by default** and is documented as *publishes your roster to the internet*. With it on, an anonymous caller gets the field-allowlisted roster (id, display name, role, runtime, activity fields, `presenceStatus`, `lastHeartbeatAt`), and three fields are redacted to `null` for an HTTP caller unless the request carries a valid `TPS-Ed25519` agent signature: `currentTask`, `flairVersion`, and `harperVersion`. Over HTTP, anonymous callers, unsigned loopback and Basic admin are unverified readers of the content gate. A trusted in-process read delegated on behalf of a registered agent can also receive the three fields without a signature. The nulls are intentional. Public `/Health` exposes the server version and build identity. A null `flairVersion` on an unverified read does not mean the peer lacks a version, and it does not mean the peer cannot accept a directed handoff.
336
352
 
337
353
  A verified reader still sees `null` for a version the row never stored. Heartbeats stamp the running server's versions; a row written before that stamp, and not heartbeated since, has no value to return. `harperVersion` is also null when this process could not resolve Harper's package version. That null means unknown, not redacted.
338
354
 
@@ -386,6 +402,14 @@ A peer can therefore show `presenceStatus: "offline"`, `activity: "idle"`, `last
386
402
 
387
403
  > The host pointer (`hostSource`) is **not** a Memory attribute — it lives in its own `MemoryHostSource` table (below). There is no `hostSource` / `hostSourceVisibility` field on `Memory`.
388
404
 
405
+ #### Durability tiers (#2217)
406
+
407
+ - 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.
408
+ - persistent — routine maintenance never reaps or age-archives it (an expired validTo archives an eligible row; an acquired expiresAt never reaps it).
409
+ - standard — routine maintenance archives it once its validTo passes or, as a session note, after 30 days.
410
+ - ephemeral — routine maintenance reaps it once its TTL (24h by default) passes.
411
+ - 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.
412
+
389
413
  #### Memory host pointer (`MemoryHostSource`, #1940 A1'-A5)
390
414
 
391
415
  The pointer is a host-object pointer — versioned JSON `{ v: 1, host, kind, id, url? }` — that records which host object the writer claims as the memory’s source. **Supported writes store host pointers only in `MemoryHostSource`. For non-admin `Memory.get`, `Memory.search`, and `SemanticSearch` results, the gated projection removes inline pointer fields and renders a pointer only from a bound `MemoryHostSource` row.**
@@ -410,13 +434,13 @@ The **binding** (A1-iv item 1): The named application create paths stamp a local
410
434
  - **A4** — the server stamps `receivedAt` inside `provenance`; it is server-stamped and never client-writable. `createdAt` stays the writer's claimed time, so `asOf`/valid-time queries use the writer's claim.
411
435
  - **A5** — the pointer is NOT inside `provenance`; `provenance` stays never-client-writable.
412
436
 
413
- **Read** — the pointer reaches a reader ONLY through a gated join into Memory results (search, by-ID, semantic search; semantic results carry the joined pointer to a permitted reader — test `(s5)`), which has three outcomes: the pointer, `"withheld"`, or nothing. A pointer is visible only to the record's author unless the write opted it into the record's scope, and it is never wider than its record: the effective visibility is the narrower of the record's write-time visibility (`scopeAtWrite`) and its current visibility (`narrower(scopeAtWrite, record.visibility)`). The join takes the narrower of the stored pointer scope and the Memory row's current visibility, so a later widening of the record does not widen the pointer. A reader who may read the record but not the pointer: On the three named non-admin reads, a bound pointer outside the reader's pointer scope renders as `"withheld"`; an unbound or archived pointer renders nothing. Wherever a URL is rendered, only scheme, host and path appear; query and fragment are stripped. Redaction is applied on the server, in the read projection — no client or MCP layer can un-redact. `Memory.get()`, `Memory.search()` and `SemanticSearch` render pointers through the pointer helper. Other Memory projections, bootstrap included, do not render pointers in this slice. The readers fetch pointers for the whole result set in ONE batched query.
437
+ **Read** — the pointer reaches a reader ONLY through a gated join into Memory results (search, by-ID, semantic search, bootstrap; semantic results carry the joined pointer to a permitted reader — test `(s5)`), which has three outcomes: the pointer, `"withheld"`, or nothing. A pointer is visible only to the record's author unless the write opted it into the record's scope, and it is never wider than its record: the effective visibility is the narrower of the record's write-time visibility (`scopeAtWrite`) and its current visibility (`narrower(scopeAtWrite, record.visibility)`). The join takes the narrower of the stored pointer scope and the Memory row's current visibility, so a later widening of the record does not widen the pointer. A reader who may read the record but not the pointer: on a non-admin read, a bound pointer outside the reader's pointer scope renders as `"withheld"` on the structured reads (get / search / semantic search) and as the prose marker `[via withheld]` in bootstrap; an unbound or archived pointer renders nothing. Wherever a URL is rendered, only scheme, host and path appear; query and fragment are stripped. Redaction is applied on the server, in the read projection — no client or MCP layer can un-redact. `Memory.get()`, `Memory.search()`, `SemanticSearch` and bootstrap render pointers through the pointer helper; for a non-admin agent caller, bootstrap cites a visible pointer in PROSE as `[via <host>/<kind> <id8> (unverified)]`, where the first 8 id characters are display-only and the full URL never appears. Each reader fetches pointers in ONE batched query per result set, never one per row.
414
438
 
415
439
  **Direct access** — Direct resource reads permit admin agents and trusted in-process callers; non-admin agents cannot read this table directly. The author reads their own pointer only through the gated join. The table has **NO REST write verbs**: `POST`/`PUT`/`PATCH`/`DELETE` to the resource are refused for EVERY caller, non-admin and admin alike, with nothing written (`r4-http`), so no REST caller can plant a pointer. A superuser Harper operation against the table (an admin `export`, `backup`, `reseed`, or a hygiene/forensics read of orphaned or author-only pointers) is the named operator path and is not gated by the resource (`r4-http` proves only the resource refusal). This admin exception names `MemoryHostSource` explicitly.
416
440
 
417
441
  **Federation** — `MemoryHostSource` is excluded from the sync's table set by mechanism (it is absent from the federation table policy), and an inbound row carrying a pointer field is refused. The outbound reader projects declared Memory attributes. The inbound merge removes undeclared attributes except the named bookkeeping fields (`f1-out`, `f1-in`). `Memory.delete` and maintenance expiry or age-based archival delete the pointer with their Memory operation. `MemoryArchive` basement/restore retains the pointer row; the join suppresses it while the Memory is archived. `Memory.delete` joins a request transaction when present; maintenance uses an owned transaction per item. An orphan sweep re-checks inside the transaction before deleting; a cleanup failure makes the maintenance run report a failure, not "complete". Orphaned pointers are absent from ordinary Memory joins but remain directly readable by administrators.
418
442
 
419
- A `hostSource`, like a client-supplied `createdAt`, is a writer claim attributed to the authenticated agent on agent writes; it is a **claimed external source**. Flair does not verify the host object and does not cryptographically sign the pointer body (the Ed25519 request signature covers method and URL, not the body).
443
+ hostSource is the writer's unverified claim about an external source, stored with the writer's authenticated agent id; Flair does not verify it. The Ed25519 request signature covers method and URL, not the body.
420
444
 
421
445
  ### Soul
422
446
 
@@ -428,7 +452,7 @@ A `hostSource`, like a client-supplied `createdAt`, is a writer claim attributed
428
452
  | `priority` | String | `critical` \| `high` \| `standard` \| `low` |
429
453
  | `metadata` | String | JSON (skill governance, etc.) |
430
454
  | `provenance` | String | Operator/internal author + `sourceClass` |
431
- | `durability` | String | Default `permanent` |
455
+ | `durability` | String | POST defaults to `permanent`; PUT supplies no default |
432
456
  | `createdAt` / `updatedAt` | String | |
433
457
  | `originatorInstanceId` | String | Server-stamped write-time instance id; not client-writable through a resource write |
434
458
 
@@ -463,6 +487,7 @@ ed25519 / idp) and **Integration** (legacy platform connection).
463
487
  | **Instance** | yes | One row per Flair instance (`id`, `publicKey`, `role` hub/spoke, `fabricEndpoint`, `status`) |
464
488
  | **PairingToken** | yes | One-time token (`expiresAt`, `consumedBy`) |
465
489
  | **Peer** | yes | Pinned peer (`publicKey`, `endpoint`, `status`, `lastSyncAt` / `lastMergeAt`, `lastSyncCursor`, `relayOnly`) |
490
+ | **FederationRetry** | yes | Sender-owned federation retry bookkeeping, shaped for one row per (peer, table, record) refused for a reason a later re-offer could clear (`state`, `attempts`, `firstRefusedAt`, `lastReason`, `resolution`, `bound`). No production sender path creates rows yet; admin-written rows are readable. `@sealed`: a write naming an undeclared field is refused. Admin-only on every operation; excluded from federation policy and the receive mapping. |
466
491
  | **ReplayNonce** | no | `schemas/replay.graphql`. Anti-replay record shared by agent auth (`a:<agentId>:<nonce>`) and federation body signatures (`f:<nonce>`). Local to the instance (`replicate: false`); rows expire after 120 s |
467
492
  | **SyncLog** | no | Per-sync audit (`peerId`, `direction`, counts, `skippedReasons`, `status`) |
468
493
 
@@ -476,15 +501,29 @@ ed25519 / idp) and **Integration** (legacy platform connection).
476
501
  | **MemoryHitStat** | memory.graphql | no | Search-hit ledger (`retrievalCount`, `lastRetrieved`); overlaid onto Memory reads |
477
502
  | **MemoryCandidate** | memory.graphql | yes | REM draft (`claim`, `status`, `scopeTag`, visibility ruling) |
478
503
  | **Asset** | memory.graphql | yes | Blob (`contentType`, `data`) owned by `agentId`, linked by `memoryId` |
504
+ | **OrgSkillAssignment** | memory.graphql | yes | Org-scope skill assignment (`skillName`, `skillRef`, `priority`, server-stamped `writer` / `sourceClass`) |
505
+ | **OrgSkillAssignmentHistory** | memory.graphql | no | One row per accepted OrgSkillAssignment resource write (`assignmentId`, `op`, `actor`, `sourceClass`, `previousHash`) |
506
+ | **MemoryDeletionHistory** | memory.graphql | no | History of confirmed physical deletions of permanent/persistent Memory rows through `Memory.delete` (including CLI hygiene and agent remove), appended in the delete transaction. Non-durable deletes, including maintenance expiry, append no history (`memoryId`, `memoryInstanceToken`, `durability`, `actor`, `sourceClass`, `at`); read by `flair integrity check` for history-backed attributions. `replicate: true` is declared explicitly to state the database default (a table replicates unless it opts out) |
507
+ | **InstructionVersion** | memory.graphql | yes (read only) | Append-only history for single-row Soul resource writes and skill writes through Memory post/put/delete and FeedMemories (excluding `_reindex` and reserved-seed deletes). Soul collection deletes and InstructionVersion REST writes are refused. The operator's reserved seed row keeps its fixed id and is versioned in place. Skill writers share a subject-type lock, select rows where `archived !== true` and `validTo` is not a nonempty string, and refuse stale create/update targets or predecessors and ambiguous heads. Reads authorize `soul` subjects under Soul's verified-agent rule. Ordinary skill readers require readable stored visibility and current authority: matching subjects, a live skill Memory row owned by the head's owner, or a delete head with null `memoryId`; authority references require nonempty owners and explicit private/shared visibility. Admin/internal keep unfiltered skill reads; unknown subject types deny. `Memory.skillSubjectId` is nullable and server-owned. |
479
508
  | **WorkspaceState** | workspace.graphql | yes | Current work (`ref`, `provider`, `phase`, `entities`) |
480
509
  | **OrgEvent** | event.graphql | yes | Org-visible event (`authorId`, `kind`, `summary`, `entities`) |
481
510
  | **AgentReadPosition** | agent.graphql | no | Per-agent watermark (`agentId`, `stream`, `position`). HTTP via `/AgentReadPosition`, not raw-table REST. |
511
+ | **AgentKeyRegistration** | agent-key-registration.graphql | yes (admin read only) | Audit log of committed `POST /AgentKeyRegister` calls (`actorId`, `operator`, `agentId`, `instanceId`, `keyFingerprint`, `createdAt`). The Flair resource route refuses every write; the registration operation is its only application writer. The operations API is a separate raw-table trust root. `replicate: true` is declared explicitly to state the database default (a table replicates unless it opts out). |
482
512
  | **Message** | message.graphql | yes | Signed envelope (`from`, `to`, `threadId`, `seq`, `state`, `signature`) |
483
513
  | **OAuthClient** | oauth.graphql | yes | Registered OAuth clients |
484
514
  | **OAuthAuthCode** | oauth.graphql | no | Single-use codes + PKCE |
485
515
  | **OAuthToken** | oauth.graphql | no | Hashed access/refresh tokens |
486
516
  | **IdpConfig** | oauth.graphql | yes | XAA IdP (`issuer`, `jwksUri`, `requiredDomain`) |
487
517
  | **IdJagReplay** | oauth.graphql | no | Used ID-JAG `jti` values |
518
+ | **OAuthSingleUse** | oauth.graphql | no | A claim to redeem an authorization code or rotate a refresh token, keyed by its SHA-256 |
519
+
520
+ `flair integrity check` reports missing checkpointed durable Memory IDs or replacements with changed or missing previously nonempty tokens without matching new deletion history. A row created and lost entirely between scans is not observed. The scan reads deletion history at or after the checkpoint's watermark minus a margin; an absent or unknown watermark reads the whole table.
521
+
522
+ `flair integrity prune-history` prunes deletion history older than the oldest named checkpoint watermark minus a margin. It is a dry run unless `--apply` is given, prunes at most `--max` rows in a run, and refuses — naming the reason — when a checkpoint is missing or a watermark is unreadable. Pruning against only some of the checkpoints that read an instance can remove history an unnamed checkpoint still needs, which causes false alerts there.
523
+
524
+ `InstructionVersion` rows are appended by Flair's in-process write path. The administrator operations API (`upsert` / `delete` under admin auth) can also write version rows, and that path is not audited by this table — a documented, deferred exception.
525
+
526
+ Raw operations-API Memory deletes create no deletion history. A scan alerts when a checkpointed durable incarnation is missing or replaced without new matching history.
488
527
 
489
528
  ---
490
529
 
package/docs/auth.md CHANGED
@@ -12,19 +12,13 @@ Different surfaces authenticate differently. The model in one place:
12
12
  | **CLI / SDK clients** (`flair`, `flair-client`) | Ed25519 agent keys; administrator Basic on supported paths | Ordinary signed agents: own writes; own and org-wide non-private reads | Administrator agent roles and Basic credentials have broader authority. |
13
13
  | **MCP server** (`@tpsdev-ai/flair-mcp`) | Ed25519 agent key; configured administrator Basic fallback | Ordinary signed agents: own writes; own and org-wide non-private reads | The key is auto-resolved from `~/.flair/keys/<agent>.key`; Basic is used when no key resolves and administrator credentials are configured. |
14
14
  | **OpenClaw / pi / Hermes plugins** | Ed25519 agent keys; Pi can use configured administrator Basic fallback | Ordinary signed agents: own writes; own and org-wide non-private reads | OpenClaw identity comes from host context; Pi requires `FLAIR_AGENT_ID`; Hermes defaults to `hermes`. |
15
- | **`n8n-nodes-flair`** | **Harper admin-password Basic auth** | ⚠️ **Whole instance, read + write, including `private`** | The admin credential bypasses agent scoping entirely — every workflow gets read/write on the *entire* memory store, including other agents' `private`-marked memories, not just the org-wide non-private pool an Ed25519 identity would see. |
15
+ | **`n8n-nodes-flair`** | **Ed25519 with Agent Private Key selected**; deprecated administrator Basic | Ordinary signed agents: own writes; own and org-wide non-private reads | The deprecated **Admin Password** authenticates as the Harper administrator (whole instance, including `private`) when Agent Private Key is empty. |
16
16
 
17
17
  **The default, secure path is Ed25519 per-agent** (see below): each agent holds its own key and signs every request. For ordinary signed agents, this enforces write ownership: they can write only their own records and read their own plus other agents' non-private records. Administrator credentials and administrator agent roles have broader authority, including access to private records. The hard access boundary is the **federation edge** (a separate Flair instance / org), not reads within an instance. See [SECURITY.md](../SECURITY.md) for the full model. Use Ed25519 per-agent everywhere you can regardless — it's still what makes writes and identity trustworthy.
18
18
 
19
- ### Known limitation — n8n uses admin-password Basic auth
19
+ ### n8n: agent-key signing, with the admin password deprecated
20
20
 
21
- The `n8n-nodes-flair` community node authenticates with the Harper **admin password** (Basic auth), which bypasses agent scoping entirely — not just the org-wide non-private reads an Ed25519 identity already gets. Concretely, an n8n workflow using the admin credential can write memories under *any* agent's identity (no per-agent write isolation) and can read *every* memory including ones marked `visibility: private` (which stay owner-only under normal Ed25519 auth). This is acceptable only when **all** of the following hold:
22
-
23
- - The n8n instance is single-tenant and operator-controlled.
24
- - Workflow inputs are trusted (your own CRM, your own webhook source).
25
- - Write-forgery and full read access (including `private` memories) are acceptable for the use case.
26
-
27
- If any of those don't hold, use Flair's CLI / SDK clients (which support per-agent Ed25519 today) and wait for the n8n credential to gain Ed25519 per-agent auth (planned). Full guidance in [docs/n8n.md](n8n.md#security).
21
+ With **Agent Private Key** selected, `n8n-nodes-flair` signs as the credential's Agent ID. Ordinary agents write their own memories and read their own plus other agents' non-private memories. The deprecated **Admin Password** path uses Harper administrator Basic authentication only with an empty Agent Private Key, and warns on each node execution. See [n8n setup](n8n.md#3-create-the-credential).
28
22
 
29
23
  ## Ed25519 Agent Auth (Default)
30
24
 
@@ -66,6 +60,8 @@ The native `/mcp` OAuth surface (see below) doesn't need any client-side wiring
66
60
 
67
61
  Flair includes a built-in OAuth 2.1 authorization server for client integrations (e.g., Claude connecting to Flair as an MCP server).
68
62
 
63
+ The native `/mcp` endpoint is guarded by the `@harperfast/oauth` authorization server instead; who can connect through it, and how to revoke that access, is in [access-control.md](access-control.md).
64
+
69
65
  ### Dynamic Client Registration
70
66
 
71
67
  **Registration is off by default.** `POST /OAuthRegister` answers `403
@@ -232,6 +228,8 @@ For organizations using an Identity Provider (IdP), XAA lets the IdP control who
232
228
  3. Client sends the ID token to Flair's token endpoint using the `jwt-bearer` grant type
233
229
  4. Flair validates the JWT signature, checks issuer/domain, maps to a Principal, and issues a scoped access token
234
230
 
231
+ A `jti` claim, when present, must be a nonempty string, and the assertion must then carry an `exp` no more than 24 hours (plus 30 seconds of clock skew) ahead. Flair records the `jti` before it issues tokens, and refuses the assertion if it is presented to this Harper instance again.
232
+
235
233
  ```
236
234
  POST /OAuthToken
237
235
  Content-Type: application/x-www-form-urlencoded
@@ -320,9 +318,9 @@ Ed25519 keys, including admin-agent keys, and MCP/OAuth delegation cannot create
320
318
  update, patch or delete Soul. A missing context does not grant Soul authority.
321
319
  This distinguishes credential classes; an administrator password is still a
322
320
  privileged secret, not proof that a human typed the request. Keep it out of
323
- agent-runtime environments. The n8n adapter currently uses admin Basic credentials
324
- and therefore retains operator-level access; it needs separate runtime credentials
325
- to receive the runtime restriction. Existing verified Soul reads are unchanged.
321
+ agent-runtime environments. The n8n adapter uses agent signing when Agent Private
322
+ Key is selected; its deprecated Admin Password path uses administrator Basic
323
+ authentication. Existing verified Soul reads are unchanged.
326
324
 
327
325
  For an explicit operator edit:
328
326
 
package/docs/bridges.md CHANGED
@@ -47,6 +47,12 @@ interface BridgeMemory {
47
47
  }
48
48
  ```
49
49
 
50
+ - 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.
51
+ - persistent — routine maintenance never reaps or age-archives it (an expired validTo archives an eligible row; an acquired expiresAt never reaps it).
52
+ - standard — routine maintenance archives it once its validTo passes or, as a session note, after 30 days.
53
+ - ephemeral — routine maintenance reaps it once its TTL (24h by default) passes.
54
+ - 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.
55
+
50
56
  **Required on import:** `content` and (`agentId` or the `--agent` flag).
51
57
 
52
58
  **Flair-owned, never set by a bridge:** `contentHash`, `embedding`, `embeddingModel`, `retrievalCount`, `lastRetrieved`, `promotionStatus`, `_safetyFlags`, any `*By` audit field. These are computed on ingest; if a bridge emits them they're ignored.
@@ -73,6 +79,9 @@ Common runtime options for `import`:
73
79
  | `--port <port>` | Harper HTTP port |
74
80
  | `--url <url>` | Flair base URL (overrides `--port`) |
75
81
  | `--key <path>` | Ed25519 private key path (default: resolved from agent) |
82
+ | `--user <id>` | Foreign-system user id for bridges that import one user (e.g. mem0); YAML imports do not use it |
83
+ | `--base-url <url>` | HTTP(S) base URL of the foreign API for API bridges (e.g. a self-hosted mem0); an explicit empty or invalid mem0 URL is refused |
84
+ | `--api-key-file <path>` | For API bridges that declare an `apiKey` option, read the key from a file with no group/world permissions (`chmod 600` recommended). YAML imports refuse this flag. For mem0, `MEM0_API_KEY` is the alternative; the key is never a flag value. |
76
85
 
77
86
  ## Your first import (worked example: agentic-stack)
78
87
 
@@ -198,6 +207,8 @@ export const bridge: MemoryBridge = {
198
207
  };
199
208
  ```
200
209
 
210
+ **`opts`** contains the option values passed to the plugin as own properties. For `import` it is a null-prototype record, so inherited methods such as `opts.hasOwnProperty` are not available: test for a key with `Object.hasOwn(opts, key)`, which works for `export` too.
211
+
201
212
  **`BridgeContext`** gives you:
202
213
 
203
214
  - `ctx.fetch` — instrumented, rate-limited HTTP. **Always use this instead of the global `fetch`** — it's how the runtime applies per-bridge throttling and audit logging.
@@ -74,9 +74,11 @@ Copy this into your project's `CLAUDE.md` (or `.claude/settings.md`, `AGENTS.md`
74
74
 
75
75
  ### Durability levels
76
76
 
77
- - persistent — survives indefinitely. Use for lessons, decisions, preferences.
78
- - standard — default. Good for session context, observations.
79
- - ephemeral — auto-expires after 24h. Use for temporary notes.
77
+ - 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.
78
+ - persistent — routine maintenance never reaps or age-archives it (an expired validTo archives an eligible row; an acquired expiresAt never reaps it).
79
+ - standard — routine maintenance archives it once its validTo passes or, as a session note, after 30 days.
80
+ - ephemeral — routine maintenance reaps it once its TTL (24h by default) passes.
81
+ - 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.
80
82
 
81
83
  > **End of CLAUDE.md snippet.**
82
84
 
@@ -86,13 +88,15 @@ This is a prompt-driven CLI setup: Claude must choose to run these commands. For
86
88
 
87
89
  ## Hooks
88
90
 
89
- `@tpsdev-ai/flair-mcp` ships four Claude Code hooks. Each is a separate binary and each is optional. Each exits 0 on every failure it handles, but a hook can still delay the session start, the prompt or the compaction it runs for; the time budgets and limits of prompt recall and of the PreCompact hook are described below.
91
+ `@tpsdev-ai/flair-mcp` ships six Claude Code hooks. Each is a separate binary and each is optional. Each exits 0 on every failure it handles, but a hook can still delay the session start, the prompt or the compaction it runs for; the time budgets and limits of prompt recall and of the PreCompact hook are described below.
90
92
 
91
93
  | Hook | Claude Code event | What it does | Install |
92
94
  |---|---|---|---|
93
95
  | `flair-session-start` | `SessionStart` | Loads bootstrap context (soul plus relevant memories) when a session opens. | `flair hook install` ([details](mcp-clients.md#auto-recall-on-session-start-optional-hook)) |
94
96
  | `flair-continuity-capture` | `PostToolUse` and `Stop` | Journals the agent's working state into the ephemeral memory tier, so the next session start can point at it with a one-line resume hint. | `flair hook install --continuity` |
95
97
  | `flair-prompt-recall` | `UserPromptSubmit` | Searches memory with each prompt and adds the relevant memories as context before the model answers. | By hand, below |
98
+ | `flair-action-recall` | `PreToolUse` | Matches the pending Bash command against the agent's own triggered lessons and adds the matching ones as context on the next model request. | `flair hook install --action-recall` |
99
+ | `flair-capture` | `PostToolUseFailure`, `PostToolUse` and `Stop` | Stages candidates locally; a background flush attempts writes. | `flair hook install --capture` |
96
100
  | `flair-precompact` | `PreCompact` | Saves a bounded continuity record just before a compaction, for `flair-session-start` to show first afterwards. | By hand, [below](#continuity-across-compaction-flair-precompact-optional) |
97
101
 
98
102
  ### Per-prompt recall (`flair-prompt-recall`)
@@ -144,6 +148,32 @@ The same `npx -y -p @tpsdev-ai/flair-mcp@<version> flair-prompt-recall` invocati
144
148
 
145
149
  The environment wins over the config file, where the keys are top-level entries; a value that is missing or out of range falls through to the next source. Until the config file has been read, the hook's deadline uses the environment's budget or the default; a budget set in the config file applies from then on, still measured from the start. The hook reads `FLAIR_AGENT_ID`, `FLAIR_URL` and `FLAIR_KEY_PATH` like the other hooks. It never uses `FLAIR_ADMIN_USER` or `FLAIR_ADMIN_PASSWORD`: without an agent key the request goes out unsigned, Flair refuses it, and the prompt gets the one "unavailable" line.
146
150
 
151
+ ### Action recall (`flair-action-recall`)
152
+
153
+ `flair hook install --action-recall` copies the version-matched hook and its runtime modules to `~/.flair/hooks/action-recall/<version>-<content hash>/` and probes that installed command. This Flair-owned directory survives npm cache eviction; uninstall removes it. Status probes a detected entry; absence is informational. If absent, run `npx -y -p @tpsdev-ai/flair-mcp@<CLI version> node --version` first, then `flair hook install --action-recall`. An incompatible SessionStart entry or held pin refuses installation.
154
+
155
+ **How it decides.** A lesson opts in through its JSON `metadata` field:
156
+
157
+ ```json
158
+ { "flairActionRecall": { "v": 1, "triggers": [ { "verb": "git", "subcommands": ["push"], "flags": ["--force"], "paths": [] } ] } }
159
+ ```
160
+
161
+ Write a new lesson with `client.memory.write(content, { type: "lesson", metadata: { flairActionRecall: { v: 1, triggers } } })`. For an existing lesson, `client.memory.update(id, content, { metadata: { flairActionRecall: { v: 1, triggers } } })` preserves other metadata keys.
162
+
163
+ `verb` is a literal executable basename; `subcommands` are an exact contiguous argv prefix after it; `flags` are required members; `paths` are optional operand-glob alternatives matched against the command's operands, normalized against the payload `cwd`. A trigger with none of the three is rejected. At most 4 triggers per lesson, 3 subcommands, 8 flags and 2 path globs per trigger, each string at most 128 bytes. Set `triggers: []` through `client.memory.update` to disable recall at the next refresh.
164
+
165
+ The hot path reads a per-session cache of the agent's own lessons under `~/.flair/action-recall/`, refreshed at session start through a signed, non-admin read. The cache expires five minutes after refresh starts, shortened by each lesson's valid expiry or end-of-validity timestamp. Between refreshes, a deletion, edit or supersession can stay visible until expiry.
166
+
167
+ **What it never does.** It emits only `hookSpecificOutput.additionalContext` — never a permission decision, a question, replacement input or blocking output. It never executes or echoes the submitted command. Caught read and input errors produce no context. Missing, corrupt, wrong-mode, oversized or stale caches do not match. The reader checks path components for symlinks before opening and uses `O_NOFOLLOW` on the final component. A command it cannot read as one simple argv command (expansions, substitutions, assignments, redirects, comments, pipelines, lists, heredocs, compound commands) is silently not matched. At most three lessons are shown, each quoted line bounded, the whole output at most 4 KiB; excerpts are redacted before they are cached and quoted when shown. The hook does not read or use credentials, signs nothing and makes no network call.
168
+
169
+ ### Learning capture (`flair-capture`)
170
+
171
+ `flair hook install --capture` copies the version-matched hook and its runtime modules to `~/.flair/hooks/capture/<version>-<content hash>/` and probes that installed command. It wires three Claude Code events: `PostToolUseFailure` (matching `Bash`), `PostToolUse` (matching `Write|Edit|NotebookEdit|Bash`) and `Stop`.
172
+
173
+ The hook may stage a possible matching follow-up to a failed `Bash` call, or a cue-matching sentence from the turn's final text, in a bounded local spool under `~/.flair/capture/`. Network writes run in a detached flush. The foreground stdin deadline is 2 seconds; the default append-lock wait for Stop, PostToolUse and flush snapshot/rewrite operations is 200 ms. A failed-tool append waits up to 2 seconds for the lock and refuses if it remains busy. The installed command suppresses stdout, keeps stderr for lock-contention and pending-write warnings, and exits 0. The flush bounds its asynchronous setup and each write with one deadline; the 10 ms p95 hot-path budget in `scripts/capture-latency.mjs` is a manual measurement, not a CI gate.
174
+
175
+ Install probes the copied command; status probes artifact paths named in settings, without a directory restriction, and reports `partial` when only some of the three events are wired. Absence is informational: installing the hooks is the opt-in. If absent, run `npx -y -p @tpsdev-ai/flair-mcp@<CLI version> node --version` first, then `flair hook install --capture`.
176
+
147
177
  ## Multiple Projects
148
178
 
149
179
  Create a separate agent per project:
@@ -105,6 +105,6 @@ Field names verified against DSH `master` 2026-08-20; [their table](https://gith
105
105
 
106
106
  **Tools never appear.** DSH logs initial connection and discovery failures; by default a failed startup registers no tools rather than failing the plugin. Check `flair status` on the Flair side, and check the DSH logs for the `flair` server's connect errors. A duplicate `serverName: flair` across live instances fails the later instance at load.
107
107
 
108
- **`auth_error` on every call.** Identity/key mismatch — and remember that an exported `FLAIR_KEY_PATH` never reaches the server (caveat 1). Re-run `flair agent add <id>` (idempotent) or set `FLAIR_KEY_PATH` in `config.env`.
108
+ **`auth_error` on every call.** Read the reported cause. An exported `FLAIR_KEY_PATH` never reaches the server (caveat 1). For `unknown_agent`, no Agent row exists: run `flair agent add <id>`. For `invalid_signature`, the signature did not verify against the stored public key. Check the signing key and the signed request first. For a confirmed key mismatch, `agent add` refuses a well-formed existing row. Run `flair agent rotate-key <id>` on the Flair host; that writes the new private key on the Flair host. Copy that file to the harness host and set `FLAIR_KEY_PATH` in `config.env` to it, then restart. Other auth errors follow the cause they name.
109
109
 
110
110
  For everything else: [troubleshooting.md](troubleshooting.md).
@@ -331,6 +331,76 @@ flair upgrade --target https://<cluster>.<org>.harperfabric.com --check
331
331
 
332
332
  Full path: [upgrade.md](upgrade.md#upgrading-a-fabric-deployed-instance).
333
333
 
334
+ ### Memory ids: operator-run checkpoint and post-operation check
335
+
336
+ `flair fleet verify` probes health and version. Deploy's replication-error check compares
337
+ component-tree metadata. Neither checks Memory rows. Checkpoint the instance's Memory ids
338
+ before the operation, then verify after:
339
+
340
+ ```bash
341
+ flair memory checkpoint --target https://<cluster>.<org>.harperfabric.com \
342
+ --fabric-user admin --fabric-password-file ~/.tps/secrets/flair-fabric-hdb
343
+
344
+ # ... the planned cluster operation ...
345
+
346
+ flair memory verify --target https://<cluster>.<org>.harperfabric.com \
347
+ --fabric-user admin --fabric-password-file ~/.tps/secrets/flair-fabric-hdb
348
+ ```
349
+
350
+ The checkpoint command reads Memory ids and durability tiers through the admin operations
351
+ API (primary-key pages, never through recall) and writes IDs and aggregate tier counts to
352
+ `~/.flair/memory-id-checkpoint.json` (mode `0600`); it reads no Memory content.
353
+ `--checkpoint <path>` picks another file.
354
+
355
+ The verify command re-reads the same operations origin and compares:
356
+
357
+ - **verified** (exit 0) — checkpointed ids present and no tier-count drop; new ids are fine;
358
+ - **integrity failure** (exit 2) — a checkpointed id is gone, or a durability tier count
359
+ dropped; the report names the count of missing ids and up to ten ids;
360
+ - **unknown** (exit 3) — the comparison could not be completed: for example, an unreadable
361
+ checkpoint, a different operations origin, a failed read, or a count change.
362
+
363
+ An absent checkpoint exits 1 without a verification outcome.
364
+
365
+ `flair deploy` also takes `--memory-checkpoint <path>`: after the deploy it runs the same
366
+ verify and adds a `Memory id/tier check:` line to the report; an integrity failure does not
367
+ fail the deploy. Without the flag it says `not checked`.
368
+
369
+ ### Memory ids: comparing nodes
370
+
371
+ `flair memory checkpoint` writes one instance's observed Memory ids and per-tier counts to a file; `flair memory verify` compares a later read of those ids and counts with that file. To see whether two or more
372
+ physical nodes have the same observed Memory ids, name each node's operations API origin explicitly:
373
+
374
+ ```bash
375
+ flair memory compare-nodes \
376
+ --node <node-a-ops-origin> --node <node-b-ops-origin> \
377
+ --fabric-user admin --fabric-password-file ~/.tps/secrets/flair-fabric-hdb
378
+ ```
379
+
380
+ Each `--node` is the address that node's operations API is read at (the address `flair memory
381
+ checkpoint` reaches through `--ops-target`). Physical peers are never inferred from Flair's
382
+ federation peers: a node is compared only when `--node` names it. Each node is read with the same
383
+ paged operations-API read the checkpoint uses, plus stored timestamps. Count checks cannot detect
384
+ equal-count concurrent updates or replacements; an id absent on every named node is invisible
385
+ without a reference set. Timestamps use parseable `updatedAt`, else `createdAt`, which can be
386
+ caller-supplied. Node clocks can differ; timestamp comparisons do not establish actual write order.
387
+ A missing id uses the maximum timestamp among usable peers holding it. Per node the report gives:
388
+
389
+ - **in-sync** — observed ids equal the union of the other usable readings;
390
+ - **lagging** — missing ids only, each timestamp greater than this node's maximum timestamp;
391
+ - **divergent** — an extra id, or a missing id timestamp at or below this node's maximum;
392
+ - **unknown** — failed read, unusable timestamp, no usable peer, or no local timestamp for missing ids.
393
+
394
+ The overall result is healthy only when every node is in-sync. A lagging node is reported as such
395
+ and is never healthy; any unknown makes the overall result unknown. The report lists the missing
396
+ and extra ids against other usable readings (a count, then the ids up to ten). Failed reads report
397
+ counts, ids and timestamps as `UNAVAILABLE`; differences without a usable peer are `UNAVAILABLE`.
398
+ `--json` prints the same result as JSON.
399
+
400
+ Exit codes: `0` healthy, `2` divergent, `3` unknown, `4` lagging. Fewer than two `--node` values, a
401
+ repeated node, or an invalid HTTP(S) URL exits `1`. Paths, queries and fragments are removed from
402
+ node URLs before comparison.
403
+
334
404
  ---
335
405
 
336
406
  ## See also
@@ -234,6 +234,8 @@ flair restore ~/flair-backup-20260405.json
234
234
 
235
235
  Always backup before upgrades.
236
236
 
237
+ Concurrent deletes can cause `flair backup` to refuse publication on a count mismatch; pause writers and maintenance, then retry.
238
+
237
239
  ---
238
240
 
239
241
  ## Uninstall
@@ -227,7 +227,7 @@ Give every agent its own. A per-agent context costs nothing — no client to con
227
227
 
228
228
  ### In a cluster
229
229
 
230
- Harper replicates every table in a replicated database unless the table opts out with `@table(replicate: false)`. None of Flair's do. So:
230
+ Harper replicates tables in a replicated database unless a table opts out with `@table(replicate: false)`. Flair's replay stores are instance-wide across workers: `ReplayNonce` records agent-auth and federation nonces and opts out of replication, while `IdJagReplay` records used XAA assertion `jti` values and `OAuthSingleUse` records claims to redeem authorization codes or rotate refresh tokens. A single-use row records that a redemption was claimed. The handler attempts the later `used` or revocation write before issuing tokens. If that write fails, no token pair is issued; the claim remains, so the code or token cannot be redeemed again. `IdJagReplay` and `OAuthSingleUse` have no replication opt-out, so they replicate when the `flair` database does. Other Flair tables without a replication opt-out do too. So:
231
231
 
232
232
  - **The registry replicates.** An agent registered on node A is visible on node B with no coordination. (Replication comes from the *database* being replicated — not from `@export`, which only controls REST exposure. `Memory` carries no `@export` and still replicates.)
233
233
  - **Authority is local.** The context is constructed per call, in whichever process handles it. No node asks another who a caller is.
@@ -235,9 +235,9 @@ If neither the env var nor the passphrase file can be accessed, federation ident
235
235
 
236
236
  ### Pairing tokens
237
237
 
238
- New peers must present a valid, unexpired, unused pairing token. This prevents unauthorized instances from joining the federation. Tokens are generated by the hub admin and are single-use.
238
+ New peers must present a valid, unexpired, unused pairing token. This prevents unauthorized instances from joining the federation. Tokens are generated by the hub admin and are single-use on one node.
239
239
 
240
- Re-pairing an existing peer (same instance ID, same public key) does not require a token.
240
+ An otherwise valid re-pair of a non-revoked peer (same instance ID, signed with the peer's pinned public key) requires no token; a supplied token must pass validation before the transactional Peer re-read and is consumed only if the pairing commits. Before writing, the re-pair rechecks the pinned key and revoke status inside its owned transaction: a different key is refused (409); otherwise a revoked peer is refused (403 `peer_revoked`), with no peer row written and no token consumed. A peer row absent at that re-read is paired as a first-time pair with a valid token; without a token the request is refused (401). On the token path, the re-read covers changes committed before the transaction's first read (its token read), not changes committed after it. A pair request whose first read finds no peer row (a first-time pair) stages its peer row in the owned transaction that consumes its token, then re-reads the committed peer row before that transaction commits. If that confirm read finds a row for the instance in committed state although the first read returned none, the pair is refused (409 `peer_row_appeared`): the request writes no peer row and the token stays unconsumed. The confirm reports a row present when it runs, not when that row was committed; it also detects a row committed after the token read, if that row is still present. A row committed after the confirm read and before the commit is not seen by it.
241
241
 
242
242
  ### Originator enforcement
243
243
 
@@ -277,6 +277,37 @@ Records with `updatedAt` more than 5 minutes in the future are rejected. This pr
277
277
 
278
278
  Federation uses record-level last-write-wins (LWW) with ISO timestamp comparison. When two instances modify the same record, the one with the later `updatedAt` wins. Field-level LWW is planned for a future version.
279
279
 
280
+ ### A pending agent key is never completed by federation
281
+
282
+ `POST /AgentKeyRegister` checks a fresh row is non-deactivated, local and `pending` and
283
+ confirms it before commit (see [registration limits](api-reference.md#identity--agent-presence-soul)); the administrator
284
+ operations API can also write the column directly (the documented admin
285
+ trust-root path). Federation cannot complete it. A record that reaches the merge
286
+ plan with `publicKey` different from stored `pending` is skipped whole as
287
+ `agent_pending_key_not_federated`, unless the status rule refused it first as
288
+ `agent_status_not_federated`. Earlier validation keeps its own reason, such as
289
+ `future_timestamp` (see [docs/api-reference.md](api-reference.md#federation)).
290
+
291
+ Peer non-convergence is the consequence for a copy B already holds. Registration
292
+ writes only A's local tables; when B already holds a pending copy and A's
293
+ registered-key row later reaches B through a sync, the skip rule leaves that copy
294
+ exactly `pending`. Sync alone therefore does not converge that copy. Whether B's
295
+ own `POST /AgentKeyRegister` can complete it depends on how B's copy was created:
296
+ B stamps sync provenance on a row it receives through a sync, and a copy that
297
+ carries sync provenance (or whose `originatorInstanceId` names another instance)
298
+ is refused there as `agent_not_local`. A pending copy created locally on B, with
299
+ neither marker, is a local agent: B's own registration can complete it. For a
300
+ sync-originated or foreign-home copy, the two instances do not converge on one
301
+ key: syncing A's registered-key row cannot complete B's pending copy, and that
302
+ key needs direct action on B. The remedy is on B, for
303
+ a sync-originated or foreign-home copy: B's administrator writes the agent's
304
+ public key (the one registered on A) onto B's copy through B's operations API,
305
+ an `update` of `flair.Agent` with `{id, publicKey, updatedAt}`. That is the raw
306
+ write `flair agent rotate-key` makes, but `rotate-key` generates a new keypair,
307
+ so B's copy would then hold a different key from A's. A B row that is absent
308
+ can receive A's registered-key row: the pending-key guard applies only to a row B
309
+ already holds with `publicKey: "pending"`.
310
+
280
311
  ## Troubleshooting
281
312
 
282
313
  ### Listen port drift