@tpsdev-ai/flair 0.57.0 → 0.59.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 (143) hide show
  1. package/README.md +7 -6
  2. package/SECURITY.md +4 -1
  3. package/config.yaml +3 -0
  4. package/dist/build-info.json +3 -3
  5. package/dist/cli.js +1726 -376
  6. package/dist/commands/agent.js +160 -2
  7. package/dist/commands/doctor.js +177 -27
  8. package/dist/commands/federation.js +2 -1
  9. package/dist/commands/hook.js +10 -2
  10. package/dist/commands/init.js +150 -44
  11. package/dist/commands/mcp.js +53 -22
  12. package/dist/commands/memory.js +24 -2
  13. package/dist/commands/quality.js +26 -18
  14. package/dist/commands/service.js +137 -22
  15. package/dist/commands/status.js +114 -3
  16. package/dist/commands/upgrade.js +204 -84
  17. package/dist/doctor-client.js +50 -4
  18. package/dist/federation/scheduler.js +253 -4
  19. package/dist/install/clients.js +89 -23
  20. package/dist/install/global-bin-path.js +26 -6
  21. package/dist/lib/atomic-write.js +256 -0
  22. package/dist/lib/daemon-liveness.js +103 -0
  23. package/dist/lib/doctor-run.js +72 -0
  24. package/dist/lib/embed-gpu-doctor.js +49 -26
  25. package/dist/lib/federation-memory-attributes.js +15 -0
  26. package/dist/lib/flair-agent-role.js +116 -0
  27. package/dist/lib/init-admin-pass.js +4 -2
  28. package/dist/lib/init-listener-environ.js +38 -0
  29. package/dist/lib/init-occupied-listener.js +165 -0
  30. package/dist/lib/launchd-domain-preflight.js +448 -0
  31. package/dist/lib/launchd-management.js +179 -8
  32. package/dist/lib/launchd-repair.js +95 -0
  33. package/dist/lib/mcp-enable.js +667 -72
  34. package/dist/lib/memory-attributes.js +77 -0
  35. package/dist/lib/node-alias-path.js +95 -0
  36. package/dist/lib/npm-registry.js +119 -6
  37. package/dist/lib/owned-pins.js +20 -6
  38. package/dist/lib/process-start-time.js +32 -0
  39. package/dist/lib/service-repoint-apply.js +267 -0
  40. package/dist/lib/service-repoint.js +575 -0
  41. package/dist/lib/toml-string-array.js +104 -0
  42. package/dist/lib/tree-divergence.js +716 -0
  43. package/dist/lib/upgrade-plain-tree.js +18 -8
  44. package/dist/lib/upgrade-prior-liveness.js +69 -0
  45. package/dist/lib/upgrade-rollback.js +116 -0
  46. package/dist/rem/runner.js +11 -0
  47. package/dist/resources/Agent.js +54 -21
  48. package/dist/resources/AgentSeed.js +44 -1
  49. package/dist/resources/Federation.js +84 -54
  50. package/dist/resources/Memory.js +567 -72
  51. package/dist/resources/MemoryArchive.js +9 -0
  52. package/dist/resources/MemoryBootstrap.js +125 -29
  53. package/dist/resources/MemoryFeed.js +204 -3
  54. package/dist/resources/MemoryHostSource.js +90 -0
  55. package/dist/resources/MemoryMaintenance.js +121 -32
  56. package/dist/resources/MemoryReflect.js +4 -1
  57. package/dist/resources/MemoryReindex.js +7 -4
  58. package/dist/resources/MemoryUsage.js +53 -3
  59. package/dist/resources/OrgSkillAssignment.js +209 -0
  60. package/dist/resources/Presence.js +18 -10
  61. package/dist/resources/RecordUsage.js +30 -40
  62. package/dist/resources/Relationship.js +167 -78
  63. package/dist/resources/SemanticSearch.js +19 -6
  64. package/dist/resources/Soul.js +31 -19
  65. package/dist/resources/XAA.js +47 -14
  66. package/dist/resources/agent-auth.js +16 -10
  67. package/dist/resources/agent-status-guard.js +63 -0
  68. package/dist/resources/auth-middleware.js +137 -49
  69. package/dist/resources/auto-promote-lib.js +4 -4
  70. package/dist/resources/bm25-index-service.js +246 -32
  71. package/dist/resources/bm25-status.js +132 -0
  72. package/dist/resources/ed25519-auth.js +11 -54
  73. package/dist/resources/embed-gpu.js +262 -47
  74. package/dist/resources/embeddings-boot.js +52 -17
  75. package/dist/resources/federation-classify.js +34 -0
  76. package/dist/resources/federation-crypto.js +65 -19
  77. package/dist/resources/flair-agent-role-boot.js +26 -0
  78. package/dist/resources/health.js +67 -16
  79. package/dist/resources/host-pointer/registry.js +35 -0
  80. package/dist/resources/host-pointer-adapter.js +15 -0
  81. package/dist/resources/host-source-visibility.js +167 -0
  82. package/dist/resources/host-source.js +151 -0
  83. package/dist/resources/instance-identity.js +3 -2
  84. package/dist/resources/key-lock.js +31 -0
  85. package/dist/resources/mcp-handler.js +147 -51
  86. package/dist/resources/mcp-oauth.js +3 -6
  87. package/dist/resources/mcp-tools.js +47 -25
  88. package/dist/resources/memory-consolidate-lib.js +3 -1
  89. package/dist/resources/memory-declared-attributes.js +103 -0
  90. package/dist/resources/memory-feed-lib.js +5 -1
  91. package/dist/resources/memory-host-source.js +163 -0
  92. package/dist/resources/migrations/synthetic-test-migration.js +4 -1
  93. package/dist/resources/migrations/visibility-backfill.js +4 -1
  94. package/dist/resources/multi-worker-guard.js +121 -0
  95. package/dist/resources/oauth-discovery.js +1 -0
  96. package/dist/resources/oauth-wellknown.js +8 -4
  97. package/dist/resources/originator-instance.js +235 -0
  98. package/dist/resources/promotion-stamp.js +2 -0
  99. package/dist/resources/provenance.js +111 -11
  100. package/dist/resources/record-owner-guard.js +19 -0
  101. package/dist/resources/record-type-kit.js +9 -12
  102. package/dist/resources/record-types.js +22 -6
  103. package/dist/resources/relay-ops.js +28 -3
  104. package/dist/resources/replay-store.js +336 -0
  105. package/dist/resources/request-transaction.js +78 -0
  106. package/dist/resources/search-readiness.js +19 -21
  107. package/dist/resources/semantic-retrieval-core.js +5 -1
  108. package/dist/resources/skill-manifest.js +181 -0
  109. package/dist/resources/skill-provenance.js +15 -10
  110. package/dist/resources/table-patch-policy.js +109 -0
  111. package/dist/resources/table-patches.js +17 -0
  112. package/dist/resources/table-post-policy.js +138 -0
  113. package/dist/resources/table-posts.js +22 -0
  114. package/dist/resources/table-subscription-policy.js +135 -0
  115. package/dist/resources/table-subscriptions.js +19 -0
  116. package/dist/resources/tool-descriptors/index.js +15 -15
  117. package/dist/resources/trust-block.js +10 -3
  118. package/dist/resources/usage-recording.js +169 -41
  119. package/dist/src/lib/flair-agent-role.js +116 -0
  120. package/dist/src/lib/memory-attributes.js +77 -0
  121. package/docs/access-control.md +667 -0
  122. package/docs/api-reference.md +85 -17
  123. package/docs/auth.md +4 -0
  124. package/docs/claude-code.md +132 -0
  125. package/docs/deepseek-harness.md +1 -1
  126. package/docs/deployment.md +1 -1
  127. package/docs/federation.md +1 -1
  128. package/docs/integrations.md +6 -6
  129. package/docs/mcp-clients.md +16 -24
  130. package/docs/notes/mcp-oauth-model2.md +15 -1
  131. package/docs/quickstart.md +5 -0
  132. package/docs/releasing.md +152 -20
  133. package/docs/supply-chain-policy.md +10 -5
  134. package/docs/troubleshooting.md +11 -0
  135. package/docs/upgrade.md +187 -61
  136. package/package.json +10 -5
  137. package/schemas/agent.graphql +9 -6
  138. package/schemas/federation.graphql +2 -11
  139. package/schemas/memory.graphql +137 -17
  140. package/schemas/oauth.graphql +8 -4
  141. package/schemas/replay.graphql +18 -0
  142. package/templates/launchd/start-flair-with-admin-pass.sh +95 -0
  143. package/dist/resources/federation-nonce-store.js +0 -195
package/docs/upgrade.md CHANGED
@@ -27,8 +27,12 @@ flair backup \
27
27
  # 2. Check what's outdated (doesn't install anything)
28
28
  flair upgrade --check
29
29
 
30
- # 3. Upgrade — installs, restarts, and verifies the new version is actually
31
- # serving, all in one step (see "Upgrade is a transaction" below)
30
+ # 3. Upgrade — installs, then restarts and verifies that the new version is
31
+ # serving (--no-restart skips both, --no-verify skips the verification).
32
+ # A failure does not always roll back: when a new flair package was
33
+ # installed and the pre-install /Health check was refused, a failed restart
34
+ # keeps the new package and exits successfully, printing the start error
35
+ # and `flair start`. See "Restart, verification and rollback" below
32
36
  flair upgrade
33
37
 
34
38
  # 4. Verify
@@ -36,6 +40,15 @@ flair status
36
40
  flair doctor
37
41
  ```
38
42
 
43
+ After a restart, `flair status` shows the BM25 index building in the
44
+ background (`building 312/817 docs (38%) · started 4s ago`) and then
45
+ `ready · 817 docs · built in 1.2s · 3m ago`. A text search issued while it
46
+ is building waits for that build. `disabled — <reason>` means the index is
47
+ not serving; the reason says why (after a failure, search is on the
48
+ per-query scan). With `FLAIR_BM25_INDEX=false` or vector-only retrieval the
49
+ index is not built at all. With `THREADS_COUNT` greater than 1 the line
50
+ names the worker it describes.
51
+
39
52
  `flair upgrade` checks and upgrades the npm-global packages (`@tpsdev-ai/flair`,
40
53
  `@tpsdev-ai/flair-mcp`) and, if present, the `openclaw-flair` plugin (via
41
54
  `openclaw plugins install --force --pin`, not `npm install -g` — it needs OpenClaw's
@@ -77,8 +90,16 @@ and:
77
90
  5. Restarts the systemd unit whose `WorkingDirectory` / `ExecStart` names the
78
91
  tree (`FLAIR_SYSTEMD_UNIT=flair.service` adds an explicit unit). If no unit
79
92
  is found, it falls back to `flair restart`
80
- 6. Verifies, then removes `.upgrade-prev`. On a failed restart or verify the
81
- previous tree is swapped back
93
+ 6. Verifies, then removes `.upgrade-prev` on success. A thrown restart error
94
+ keeps a swapped Flair package when the prior `/Health` connection was
95
+ refused (`keep`, successful exit). With a swap and a running or indeterminate
96
+ prior probe, a nonempty previous version selects rollback. No swap, or no
97
+ previous version after a running or indeterminate probe, selects `no-target`
98
+ (failure). Verification keeps an `ok` or `healthy-unverified` result;
99
+ other results select rollback with a
100
+ nonempty previous version, or `cannot-rollback` without one. A reported
101
+ deprecation blocks rollback, and a missing saved tree skips tree restoration.
102
+ See [Restart, verification and rollback](#restart-verification-and-rollback).
82
103
 
83
104
  ```bash
84
105
  flair upgrade --check --tree /opt/flair
@@ -90,48 +111,143 @@ flair upgrade --tree /opt/flair --flair-version 0.50.0
90
111
  without touching the tree. A git checkout or a path that *is* the npm-global
91
112
  install is refused rather than overwritten.
92
113
 
93
- ### Upgrade is a transaction
94
-
95
- As of flair#635, `flair upgrade` is install → restart → verify →
96
- rollback-on-failure, in one step — installing new code without restarting used
97
- to leave the OLD process serving while the version on disk lied about what was
98
- actually running:
99
-
100
- - **Restart happens automatically** after install. Pass `--no-restart` to
101
- stage the new packages without bouncing the process yet (the old
102
- opt-in `--restart` flag still parses but is now a no-op — restart is the
103
- default).
104
- - **The restart runs through the newly installed CLI** (flair#905), not the
105
- process that did the installing. Only version N's own code knows how version
106
- N starts — spawn arguments, required environment, config templates and the
107
- Harper dependency's own package name are all things a release may change, and
108
- the pre-swap process would get every one of them wrong the same silent way.
109
- The output names the CLI it handed the restart to. If that CLI can't be found
110
- or its version can't be confirmed, the upgrade says so and restarts in-process
111
- rather than refusing to start anything.
112
- - **Post-restart verification** (skip with `--no-verify`) confirms the
113
- restarted instance answers `/Health`, that an authenticated request
114
- round-trips, and that the reported running version matches what was just
115
- installed. It then runs the same enumerable doctor install-health checks
116
- (`flair doctor`'s client-integration catalog, plus launchd management)
117
- and prints `✅ verified: healthy` only when every check ran and none
118
- failed. A missing Codex SessionStart hook — which `flair init` before
119
- 0.50.0 never wrote — is one of those checks. Installing the hook is
120
- consent-bearing (it executes at every session start): an interactive
121
- upgrade prompts; a non-interactive upgrade states the gap and withholds
122
- ✅. Pass `--install-hooks` to consent without a prompt, then `flair
123
- doctor` exits 0.
124
- - **On a failed restart OR a failed verification**, `flair upgrade`
125
- automatically reinstalls the previously-running `@tpsdev-ai/flair` version,
126
- restarts again, and re-verifies — then exits nonzero with a clear report of
127
- what failed. Until flair#905 the rollback was wired to the *verification* leg
128
- only: an upgrade that installed new packages and then failed to start them
129
- exited 1 and left the operator on the new version with nothing running, which
130
- is the single outcome this transaction exists to prevent. If the
131
- rollback itself fails verification, it says so loudly and points at the
132
- concrete pre-upgrade snapshot path (see "Pre-upgrade snapshot" below)
133
- instead of retrying in a loop — see [Downgrade](#downgrade) for the
134
- restore procedure.
114
+ ### After a Node bump: the CLI and the instance in different install trees
115
+
116
+ A service unit bakes the node binary and install tree of the runtime it was
117
+ written under. After a Node version bump, `flair` on your PATH can come from the
118
+ new runtime's global tree while the instance keeps serving the old one.
119
+ `flair status`, `flair upgrade`, `flair doctor` and `flair restart` name this —
120
+ both trees, both versions, the unit — but only when it is **proven**: the
121
+ service manager must own the process that answered — the one process listening
122
+ on the instance's port, which must also be the PID the instance reported about
123
+ itself when it reported one. Two listeners, none, or a PID file that names
124
+ another process make the answer unknown; only when the port's listeners cannot
125
+ be read at all (`lsof` missing or failing) does a reported PID stand on its own.
126
+ On Linux, the unit is found from that process — its cgroup (`/proc/<pid>/cgroup`,
127
+ cgroup v2) names the systemd user unit it runs in — and systemd must report that
128
+ process as the unit's MainPID and the unit's file in `~/.config/systemd/user` as
129
+ its `FragmentPath`. Because the unit comes from the process, not from a tree path
130
+ in a unit file, it is still found after `flair init` re-pointed the file: the
131
+ state is then diverged with `flair restart` as the remedy. Otherwise the serving
132
+ tree is reported as unknown and nothing is advised from it.
133
+
134
+ The remedy is `flair init && flair restart`. `flair init` re-points the
135
+ instance's own unit — **only** its launcher, node, Harper entry and working
136
+ directory — and writes nothing unless the unit is provably this instance's and
137
+ exactly a shape flair supports:
138
+
139
+ | | Written only when | Refused (nothing written) |
140
+ |---|---|---|
141
+ | macOS plist (`~/Library/LaunchAgents/ai.tpsdev.flair.<hash>.plist`), read as XML structure | one Label (this data directory's) at the top level, ROOTPATH (this data directory) and HOME (yours) in `EnvironmentVariables`, no `Program` key, ProgramArguments = the launcher in its WorkingDirectory tree, this instance's admin-pass file, a `node`, a Harper entry in that tree | a plist that is not this instance's or not in that shape — another HOME, label or pass file, an extra argument, a key in the wrong dict — and an XML declaration naming an encoding other than UTF-8, an XML comment, CDATA, a character reference, a duplicate key, or an unsupported XML element |
142
+ | Linux systemd user unit (the one proven above) | one `WorkingDirectory=` (the served tree) and one `ExecStart=` of `<node> <harper.js> run .` or `<launcher> <admin-pass file> <node> <harper.js>`, optional `-` prefix | drop-ins (any location systemd reports, or `<unit>.d` beside the file), any other argument (operator arguments are never rewritten), quoting, `%` specifiers, `$` variables, line continuations, other `ExecStart=` prefixes, and a new path that would need quoting |
143
+ | Both, when moving to a different installed tree | the old tree is an npm-global install; its flair version and this CLI's are strict semver and this CLI's is not older (prereleases count: `0.57.0-beta.1` is older than `0.57.0`) | a plain tree or checkout (separately managed), an unreadable, non-semver or newer version (a downgrade cannot be ruled out) |
144
+
145
+ A unit that serves this CLI's tree with a different, existing node is treated
146
+ as a deliberate pin: `flair init` leaves it, and init and `flair doctor` report it
147
+ with the hand edit that would move it. A plist that already serves this CLI's
148
+ tree has a missing runtime path replaced without the version check in the table,
149
+ which applies only to a move between trees. The write is atomic and
150
+ lands only over the bytes it was planned from — the file is read as a regular
151
+ file (a symlink is refused, not followed) whose bytes are valid UTF-8 (anything
152
+ else is refused before planning), and its bytes are re-checked immediately
153
+ before the rename, so an edit saved in between refuses the write. On Linux,
154
+ `flair init` first records what systemd holds for the unit (it writes nothing
155
+ if it cannot, or if systemd no longer reports the serving process as the
156
+ unit's MainPID), then runs `systemctl --user daemon-reload` (which also loads any
157
+ other pending edits to your user units) and checks what systemd loaded. If the
158
+ reload fails or systemd does not hold the re-pointed unit, the previous bytes
159
+ are restored, systemd is reloaded and asked again. That check covers three
160
+ fields: when systemd's FragmentPath, drop-ins and WorkingDirectory are back at
161
+ the values recorded before the write, flair says exactly that and still calls
162
+ full agreement between the restored file and systemd unverified; otherwise it
163
+ reports systemd's state as unverified. Every refusal names the file, what did not match, and the
164
+ remedy — the paths to set by hand, an update of this CLI's tree, or a
165
+ reinstall; after a hand edit, `flair restart` brings the instance up under
166
+ the edited unit (macOS reloads the plist; on Linux, when the unit is proven to
167
+ run the instance, it reloads systemd, restarts through the unit and checks that
168
+ the unit's new main process runs from its WorkingDirectory). On Linux,
169
+ `flair restart` never stops a process that a systemd unit supervises — one
170
+ systemd reports as that unit's MainPID — and starts it again outside the unit:
171
+ when it is not the proven unit, it refuses and names the `systemctl` command to
172
+ use. It also refuses when flair cannot learn the MainPID of the unit the
173
+ process's cgroup names (systemd cannot be asked, or reports no main process),
174
+ naming the same command, and when the process's cgroup cannot be read at all
175
+ or contradicts itself (for example, a user slice and a user manager that name
176
+ different users, or one unit's cgroup nested in another's) — then no manager is
177
+ asked.
178
+ A process that only runs inside some service's cgroup without being its main
179
+ process (a child of a CI runner agent, a terminal multiplexer or an ssh session
180
+ service) was started directly, and `flair restart` restarts it directly.
181
+
182
+ The federation-sync shim (`~/.flair/bin/flair-federation-sync`) is re-pointed
183
+ the same way: only its exec line changes, the scheduler unit is never
184
+ rewritten, and the shim is refused when it is a symlink or not valid UTF-8,
185
+ changes between the read and the rename, runs any command other than what
186
+ `flair federation sync enable` writes (comment lines are not compared), or —
187
+ when it is moved to a different installed tree — when that tree's version (or
188
+ this CLI's) is not strict semver or is newer.
189
+ `flair federation sync enable` regenerates it.
190
+
191
+ ### Restart, verification and rollback
192
+
193
+ In the local upgrade path, `--no-restart` skips restart and post-restart
194
+ verification. With restart enabled, the pre-install `/Health` probe runs, also
195
+ under `--no-verify`. With `--no-restart`, it runs only when a pre-upgrade
196
+ snapshot is needed, to decide whether that snapshot restarts the old instance.
197
+
198
+ The probe labels a successful HTTP response `running`. A caught error is
199
+ `stopped` when every failure in it, including each `cause` and aggregated
200
+ error, is a connection refusal: a string code must be `ECONNREFUSED` or
201
+ `ConnectionRefused`, and an uncoded failure with no nested failures must
202
+ contain one of them in its text. Other responses and caught errors are
203
+ `indeterminate`.
204
+ The `stopped` label does not establish whether a process exists.
205
+
206
+ After a thrown restart error, `decideAfterRestartFailure` selects:
207
+
208
+ | Flair itself was swapped | Prior probe | Previous version | Decision |
209
+ | --- | --- | --- | --- |
210
+ | No | Any | Any | `no-target` |
211
+ | Yes | `stopped` | Any | `keep` |
212
+ | Yes | `running` or `indeterminate` | Nonempty | `rollback` |
213
+ | Yes | `running` or `indeterminate` | Missing or empty | `no-target` |
214
+
215
+ `keep` leaves the new package installed, prints the start error and
216
+ `flair start`, and exits successfully. `no-target` exits with failure.
217
+ `rollback` enters the shared rollback path below.
218
+
219
+ When post-restart verification runs, `decideAfterVerify` returns `ok` for
220
+ a successful probe; otherwise it returns `healthy-unverified` when the probe
221
+ reports healthy with a credentials failure. Other results select `rollback`
222
+ for a nonempty previous version and `cannot-rollback` otherwise; the latter exits
223
+ with failure. Prior liveness and the swap flag are not inputs to this decision.
224
+
225
+ The shared rollback path refuses a target reported deprecated by the registry
226
+ lookup and exits with failure. Failed or unusable lookups, including a null
227
+ `deprecated` field, allow the attempt. npm-global attempts to reinstall the
228
+ previous package version; plain-tree attempts to restore the saved tree when
229
+ it exists and skips restoration when it is absent. The tree restore first
230
+ attempts to move the live path to `.upgrade-failed` when it exists.
231
+
232
+ After that stage, an engine change requires a snapshot path and successful
233
+ snapshot restoration before restart. Before restoring, rollback stops the
234
+ instance and requires fresh daemon evidence that it is stopped. It then moves
235
+ the current data directory to a unique, timestamped sibling named
236
+ `<data-dir>.pre-rollback-<timestamp>-<suffix>` and prints that retained path.
237
+ Rollback never deletes this retained directory. If stopping, confirming the
238
+ stop, validating the snapshot, or moving the data aside fails, restoration is
239
+ refused without replacing the current data. To recover writes made after the
240
+ snapshot, stop Flair, set aside the restored data directory, move the retained
241
+ directory back, and start with the Harper engine version that wrote it.
242
+ Rollback then attempts restart and, if restart returns, verification; its
243
+ reported outcomes exit with failure.
244
+
245
+ If that restart throws, the npm-global and restored-tree diagnostics label
246
+ the rollback target known-broken for this attempt. The missing-tree diagnostic
247
+ uses a neutral headline. Plain-tree recovery text reports whether the previous
248
+ tree was restored and whether a live tree was set aside. Both lanes report
249
+ whether a data snapshot was restored. An npm version candidate printed by
250
+ this message is not guaranteed non-deprecated.
135
251
 
136
252
  ### Pre-upgrade snapshot (opt-in for same-engine, unconditional on engine change)
137
253
 
@@ -177,23 +293,23 @@ To capture one first: `flair snapshot create` (physical) or `flair backup` (logi
177
293
  - **Retention:** keeps the newest 3 snapshots, prunes older ones automatically after
178
294
  each successful snapshot — whether taken via `--snapshot` or `flair snapshot create`
179
295
  (below); both draw from the same `~/.flair/upgrade-snapshots/` pool.
180
- - **Consistency:** when a snapshot is taken (`--snapshot`, or `flair snapshot create`),
181
- Flair is briefly stopped, snapshotted, and immediately restarted on the same version
182
- before anything else happens — a plain file copy of a *running* Harper's data
183
- directory isn't guaranteed point-in-time consistent (Harper 5.x stores tables in
184
- RocksDB — an LSM engine whose WAL, MANIFEST, and SST files can be
185
- mid-write/mid-compaction), so the snapshot always happens against a quiesced
186
- directory. During an upgrade this means a short stop/start blip even with
187
- `--no-restart` — the snapshot's correctness doesn't depend on whether you want a
188
- restart *after* the upgrade, those are separate questions. (A native Harper backup
189
- operation, `get_backup`, was evaluated and rejected here — see the code comment
296
+ - **Consistency:** a snapshot uses a stopped, quiesced data directory — a plain
297
+ file copy of a *running* Harper's data directory isn't guaranteed point-in-time
298
+ consistent (Harper 5.x stores tables in RocksDB, whose WAL, MANIFEST, and SST
299
+ files can be mid-write/mid-compaction). `flair snapshot create` restarts Flair
300
+ afterward. During an upgrade, the old version is restarted after the snapshot
301
+ only if the pre-install `/Health` probe did not refuse the connection. A refused
302
+ connection leaves it stopped through the package swap. An instance that answered
303
+ or had indeterminate liveness has a short stop/start blip even with
304
+ `--no-restart`; that flag controls the restart *after* the upgrade. (A native
305
+ Harper backup operation, `get_backup`, was evaluated and rejected here — see the code comment
190
306
  above `createDataSnapshot` in `src/cli.ts` for why: it backs up one table/schema at a
191
307
  time over the running HTTP API, not the whole data directory, and would be strictly
192
308
  less complete than a plain file copy.)
193
309
  - **Failure is a hard stop when requested:** if you passed `--snapshot` and the
194
310
  snapshot itself fails (disk full, permissions, etc.), the upgrade aborts before any
195
- package changes — no packages are swapped, Flair is restarted on the version it was
196
- already running.
311
+ package changes. Flair is restarted on the old version only if the pre-install
312
+ `/Health` probe did not refuse the connection.
197
313
 
198
314
  #### `flair snapshot` — the standalone command
199
315
 
@@ -443,9 +559,19 @@ flair restart
443
559
  flair restore ~/flair-backup-<date>.json
444
560
  ```
445
561
 
446
- `flair upgrade` does this automatically on a failed post-restart verification — see
447
- "Upgrade is a transaction" above. This section is for doing it by hand, e.g. after
448
- `--no-verify`, or after problems surface later than the automatic check catches.
562
+ `flair upgrade` selects automatic rollback after post-restart verification only
563
+ when the result is neither `ok` nor `healthy-unverified` and a nonempty previous
564
+ version is available; otherwise a failed result is `cannot-rollback`. A thrown
565
+ restart error instead keeps a swapped Flair package after a refused pre-upgrade
566
+ `/Health` connection (`keep`, successful exit). No swap, or no previous version
567
+ after a running or indeterminate probe, selects `no-target`; a swap with that
568
+ probe and a nonempty previous version selects rollback. Reported deprecation
569
+ blocks rollback; a missing saved plain-tree directory skips tree restoration.
570
+ Engine-change data restoration requires a confirmed stop and retention of the
571
+ current directory. See [Restart, verification and rollback](#restart-verification-and-rollback)
572
+ for the decisions and retained-data recovery instructions. This section is for
573
+ manual recovery, e.g. after `--no-verify`, or after problems surface later than
574
+ the automatic check catches.
449
575
 
450
576
  ### Known issue — upgrading *from* an older version can still report a false rollback
451
577
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tpsdev-ai/flair",
3
- "version": "0.57.0",
3
+ "version": "0.59.0",
4
4
  "packageManager": "bun@1.3.10",
5
5
  "description": "Identity, memory, and soul for AI agents. Cryptographic identity (Ed25519), semantic memory with local embeddings, and persistent personality — all in a single process.",
6
6
  "type": "module",
@@ -76,9 +76,9 @@
76
76
  },
77
77
  "overrides": {
78
78
  "react-native-fs": "npm:empty-npm-package@1.0.0",
79
- "brace-expansion": "^5.0.9",
80
- "undici": "^8.9.0",
81
- "fast-uri": "^4.1.3",
79
+ "brace-expansion": "^5.0.12",
80
+ "undici": "~8.10.2",
81
+ "fast-uri": "^4.1.5",
82
82
  "hono": "^4.13.5",
83
83
  "js-yaml": "^4.3.2",
84
84
  "adm-zip": "^0.6.1",
@@ -90,7 +90,12 @@
90
90
  "mysql2": "^3.22.0",
91
91
  "mariadb": "~3.4.7",
92
92
  "qs": "^6.16.0",
93
- "fastify": "^5.12.1"
93
+ "fastify": "^5.12.5",
94
+ "lodash": "^4.18.0",
95
+ "ip-address": "^10.5.1",
96
+ "joi": "^17.13.7",
97
+ "moment": "^2.31.0",
98
+ "@grpc/grpc-js": "^1.14.5"
94
99
  },
95
100
  "devDependencies": {
96
101
  "@playwright/test": "1.59.1",
@@ -23,12 +23,15 @@ type Agent @table(database: "flair") @export {
23
23
  createdAt: String!
24
24
  updatedAt: String
25
25
  originatorInstanceId: String @indexed # federation-edge-hardening slice 1 — write-time instance identity,
26
- # stamped server-side in resources/Agent.ts's post()/put() from
27
- # resources/instance-identity.ts's localInstanceId(). Nullable (existing rows
28
- # read null = clean upgrade); preserved (never re-stamped) as the record flows
29
- # through federation sync merges. See schemas/memory.graphql's Memory.
30
- # originatorInstanceId for the full contract — same field, same idiom, this is
31
- # one of the 4 synced tables (Memory/Soul/Agent/Relationship).
26
+ # stamped server-side in resources/Agent.ts's post()/put() via
27
+ # resources/originator-instance.ts from resources/instance-identity.ts's
28
+ # localInstanceId(). On CREATE the local id is stamped (a request-body value is
29
+ # ignored); on UPDATE the STORED value stands (a body value neither replaces nor
30
+ # clears it). Nullable (existing rows read null = clean upgrade); preserved
31
+ # (never re-stamped) as the record flows through federation sync merges. See
32
+ # schemas/memory.graphql's Memory.originatorInstanceId for the full contract —
33
+ # same field, same idiom, this is one of the 4 synced tables
34
+ # (Memory/Soul/Agent/Relationship).
32
35
  }
33
36
 
34
37
  # Credential table — auth surfaces for Principals.
@@ -39,17 +39,8 @@ type Peer @table(database: "flair") @export {
39
39
  updatedAt: String
40
40
  }
41
41
 
42
- # Anti-replay nonce store (federation-edge-hardening slice 4).
43
- # Persists nonces recorded by verifyBodySignatureFresh (federation-crypto.ts)
44
- # so an instance restart doesn't wipe recently-seen nonces — closes the
45
- # ±30s freshness-window replay gap a restart would otherwise reopen. Nonces
46
- # are already globally unique (128-bit random, generated per request by
47
- # signBodyFresh), so the nonce string itself is the primary key — no scope
48
- # prefix needed. Internal bookkeeping only: never served, never replicated.
49
- type Nonce @table(database: "flair") {
50
- id: ID @primaryKey # the nonce string (base64url, 128-bit random)
51
- seenAt: Int! @indexed # ms-epoch when first recorded — eviction cutoff
52
- }
42
+ # Federation body-signature nonces are recorded in `ReplayNonce`
43
+ # (schemas/replay.graphql), shared with agent auth (flair#2061).
53
44
 
54
45
  # Sync log — audit trail for federation operations.
55
46
  type SyncLog @table(database: "flair") {
@@ -42,8 +42,22 @@ type Memory @table(database: "flair") {
42
42
  tags: [String] @indexed
43
43
  durability: String @indexed
44
44
  source: String
45
+ type: String # flair#1940 A1'' item 1: declared from MEASURED data, not derived from the schema. A live
46
+ # store (3,963 Memory rows) really carries `type` on 62% of rows — the client filters
47
+ # on it and MemoryMaintenance archives `type === "session"`. Declaring it here is what
48
+ # lets the declared-only whitelist (resources/memory-declared-attributes.ts) KEEP it on a
49
+ # full-row write instead of stripping it. Nullable/additive — existing rows keep their
50
+ # value, rows without it stay without it.
45
51
  createdAt: String! @indexed
46
52
  updatedAt: String
53
+ instanceToken: String @indexed # flair#1940 A1-iv: a server-stamped row INCARNATION token (UUID). The named
54
+ # application create paths stamp a local `instanceToken`; existing legacy rows may have
55
+ # none. Memory's REST write paths remove client-supplied `instanceToken` and
56
+ # `provenance`. The named update paths retain a stored token when their existing-row read
57
+ # succeeds. The host-pointer join binds on it: a pointer is returned only when
58
+ # memoryId, authorId === agentId, instanceToken and "not archived" all hold, so a
59
+ # deleted-and-recreated id (which gets a NEW token) can never re-bind a stale pointer.
60
+ # Nullable/additive: existing rows read back null (clean-upgrade-path gate).
47
61
  expiresAt: String @indexed
48
62
  retrievalCount: Int # Observable search-hit counter. Authoritative increments live on
49
63
  # MemoryHitStat (resources/hit-tracking.ts, flair#1528); GET/search
@@ -84,16 +98,28 @@ type Memory @table(database: "flair") {
84
98
  validFrom: String @indexed # ISO timestamp — when this fact became true
85
99
  validTo: String @indexed # ISO timestamp — when this fact stopped being true (null = still valid)
86
100
  _safetyFlags: [String] # content safety flags from scanContent()
87
- provenance: String # JSON blob (memory-provenance slice 1; claimed.client added by flair#718): { v, verified: { agentId, timestamp }, claimed?: { model, client } }
88
- # Nullable by design — existing rows read back provenance = null, unchanged behavior (clean-upgrade-path gate).
89
- # Same idiom as Soul.metadata below. Stamped server-side in resources/Memory.ts; never client-writable.
90
- originatorInstanceId: String @indexed # federation-edge-hardening slice 1: WRITE-TIME instance identity, stamped server-side in
91
- # resources/Memory.ts from resources/instance-identity.ts's localInstanceId() — never client-writable.
92
- # Nullable (existing rows read null = clean upgrade). Distinct from the legacy _originatorInstanceId
93
- # (Federation.ts's mergeRecord — stamped by the RECEIVER at merge time, forgeable/lossy); this field is
94
- # stamped by the ORIGINATING instance itself and preserved (never re-stamped) as the record flows through
95
- # sync merges. @indexed for the later sync push-query filter (per-record signature verification and the
96
- # classifier org-gate are separate, later slices — not built here).
101
+ provenance: String # JSON blob (memory-provenance slice 1; claimed.client added by flair#718): { v, verified: { agentId, timestamp, receivedAt }, claimed?: { model, client } }
102
+ # Server-STAMPED (receivedAt is the server's receipt time, never client-writable — flair#1940 A4).
103
+ # flair#1940 A1' — The Memory schema does not declare a pointer attribute.
104
+ # Supported Memory writes store accepted pointers in `MemoryHostSource`
105
+ # (below); the named non-admin reads use its gated join. Client and adapter
106
+ # transport is outside this slice. The three write-body inputs (hostSource,
107
+ # hostSourceScope, hostSourceVisibility) are consumed by Memory.post()/put()
108
+ # and are never persisted here.
109
+ originatorInstanceId: String @indexed # federation-edge-hardening slice 1: WRITE-TIME instance identity, stamped server-side on every
110
+ # application write via resources/originator-instance.ts from resources/instance-identity.ts's localInstanceId()
111
+ # (Memory/Soul/Agent/Relationship post()/put()/patch(), Memory's _reindex re-PUT, the FeedMemories ingest, AgentSeed
112
+ # and the MCP/IdP principal provisioning). On CREATE the local id is stamped and any request-body value is
113
+ # ignored; on UPDATE the STORED value stands (a body value neither replaces nor clears it, and an update that
114
+ # omits the field leaves it). Nullable (existing rows read null = clean upgrade).
115
+ # NOT client-writable through a resource write. Distinct from the legacy _originatorInstanceId (Federation.ts's
116
+ # mergeRecord — stamped by the RECEIVER at merge time, forgeable/lossy); this field is stamped by the ORIGINATING
117
+ # instance itself and preserved (never re-stamped) as the record flows through sync merges. Federation and Harper's
118
+ # administrator ops API are EXCEPTIONS to the rule, not the field's only raw writers: the SIGNED federation merge
119
+ # (FederationSync.post, which accepts a signed HTTP body from a known, non-revoked peer; a record's own signature,
120
+ # when present, is verified against the pinned key of the record's envelope originator) and the administrator ops
121
+ # API (:9925, admin auth). @indexed for the
122
+ # later sync push-query filter (per-record signature verification and the classifier org-gate are separate slices).
97
123
  metadata: String # JSON blob (flair#1332/#1202): ADK custom_metadata, store-and-return. CLIENT-WRITABLE
98
124
  # (unlike provenance above, which is server-stamped) and OPAQUE TO THE SERVER by
99
125
  # contract: stored verbatim, returned verbatim, never parsed server-side, never
@@ -141,14 +167,20 @@ type Relationship @table(database: "flair") {
141
167
  updatedAt: String
142
168
  originatorInstanceId: String @indexed # federation-edge-hardening slice 1 — see Memory.originatorInstanceId's doc above
143
169
  # for the full contract (write-time stamp, nullable, preserved across sync merges).
144
- # Stamped server-side in resources/Relationship.ts's put().
145
- provenance: String # JSON blob (relationship-write-path, folded K&S refinement): SAME shape as
146
- # Memory.provenance above — { v, verified: { agentId, timestamp }, claimed?: { model, client } }
147
- # — via the shared resources/provenance.ts buildProvenance(), never a
148
- # Relationship-specific format. Nullable by design — pre-existing rows read back
170
+ # Stamped server-side in resources/Relationship.ts's post() and put() via resources/originator-instance.ts
171
+ # (create stamps the local id; update keeps the stored value; never client-writable).
172
+ provenance: String # JSON blob (relationship-write-path, folded K&S refinement; re-stamped on
173
+ # the semantic PATCH path by flair#1960 r2): SAME shape as
174
+ # Memory.provenance above — { v, verified: { agentId, timestamp, receivedAt },
175
+ # claimed?: { createdAt, model, client } } — via the shared
176
+ # resources/provenance.ts buildProvenance(), never a
177
+ # Relationship-specific format. On a newly stamped local write, every
178
+ # field under `verified` is server-derived (the resolved auth verdict
179
+ # + one server clock read), never client-writable. Nullable by design — pre-existing rows read back
149
180
  # provenance = null, unchanged behavior (migration-equivalence gate, same
150
181
  # discipline as Memory.usageCount/flair#684). Stamped server-side in
151
- # resources/Relationship.ts's put(); never client-writable.
182
+ # resources/Relationship.ts's post() and put() (and re-stamped on a semantic patch());
183
+ # never client-writable.
152
184
  }
153
185
 
154
186
  type Soul @table(database: "flair") {
@@ -164,7 +196,8 @@ type Soul @table(database: "flair") {
164
196
  updatedAt: String
165
197
  originatorInstanceId: String @indexed # federation-edge-hardening slice 1 — see Memory.originatorInstanceId's doc above
166
198
  # for the full contract (write-time stamp, nullable, preserved across sync merges).
167
- # Stamped server-side in resources/Soul.ts's post()/put().
199
+ # Stamped server-side in resources/Soul.ts's post()/put() via resources/originator-instance.ts
200
+ # (create stamps the local id; update keeps the stored value; never client-writable).
168
201
  }
169
202
 
170
203
  type MemoryGrant @table(database: "flair") @export {
@@ -221,6 +254,62 @@ type MemoryHitStat @table(database: "flair") {
221
254
  lastRetrieved: String
222
255
  }
223
256
 
257
+ # MemoryHostSource — the host pointer, IN ITS OWN TABLE (flair#1940 slice 1 /
258
+ # A1', confirmed by Kern and Sherlock). The pointer is a host-object pointer —
259
+ # versioned JSON { v: 1, host, kind, id, url? } — The Memory schema does not
260
+ # declare a pointer attribute. Supported Memory writes store accepted pointers in
261
+ # `MemoryHostSource`; the named non-admin reads use its gated join. Client and
262
+ # adapter transport is outside this slice.
263
+ #
264
+ # Writes are NOT a REST surface for any caller: Memory.post()/put() write the row
265
+ # in the SAME transaction as the Memory row — a request's open transaction, or
266
+ # one created with transaction(ctx, cb) when an internal caller has no request
267
+ # context — so the row and its pointer commit together or not at all (real-
268
+ # Harper t1/t2: a failed pointer write leaves no row, and a failed PUT leaves
269
+ # the pre-existing row byte-identical). This resource refuses its OWN
270
+ # post()/put()/patch()/delete() for EVERY caller (r4-http), so no REST caller
271
+ # can plant a pointer; a superuser Harper operation against the table (an
272
+ # operator export, backup or reseed) is the operator path.
273
+ #
274
+ # Direct resource reads permit admin agents and trusted in-process callers;
275
+ # non-admin agents cannot read this table directly. The author
276
+ # reads their own pointer only through the gated join INTO Memory results (A1'
277
+ # item 4), never from this table directly. Bootstrap does not render pointers in
278
+ # this slice.
279
+ #
280
+ # NOT federated (A1' item 5/A1'' item 8): the table is absent from
281
+ # FEDERATION_TABLE_POLICY, so it is never in the sync's table set, an inbound row
282
+ # carrying a pointer field is REFUSED (resources/federation-classify.ts). The
283
+ # outbound reader projects declared Memory attributes. The inbound merge removes
284
+ # undeclared attributes except the named bookkeeping fields (f1-out/f1-in).
285
+ #
286
+ # Cascade (A1' item 6 / A1'' item 2): `Memory.delete` and maintenance expiry or
287
+ # age-based archival delete the pointer with their Memory operation. `MemoryArchive`
288
+ # basement/restore retains the pointer row; the join suppresses it while the Memory
289
+ # is archived. `Memory.delete` joins a request transaction when present; maintenance
290
+ # uses an owned transaction per item (c3). An orphan sweep re-checks inside the
291
+ # transaction before deleting; a cleanup failure makes the maintenance run report a
292
+ # failure, not "complete".
293
+ #
294
+ # hostSource is a writer claim attributed to the authenticated agent on agent
295
+ # writes — a claimed external source. Flair does not verify the host object and
296
+ # does not cryptographically sign the pointer body (the Ed25519 request
297
+ # signature covers method and URL, not the body).
298
+ # scopeAtWrite is the record's visibility AT WRITE (null → author-only). The join
299
+ # takes the narrower of the stored pointer scope and the Memory row's current
300
+ # visibility. A partial PUT carries the stored visibility it read at the start of
301
+ # the request (p2). receivedAt is server-stamped.
302
+ type MemoryHostSource @table(database: "flair") @export {
303
+ memoryId: ID @primaryKey # the Memory.id this pointer belongs to
304
+ hostSource: String! # canonical v1 JSON: { v:1, host, kind, id, url? }
305
+ scopeAtWrite: String # the record's visibility at write when the write opted in; null = author-only
306
+ authorId: String! @indexed # server-stamped from the authenticated principal, NEVER the body
307
+ memoryInstanceToken: String # the Memory row's server-stamped `instanceToken` at pointer-write time (A1-iv). The
308
+ # join returns this pointer only when it still equals the Memory row's token, so a
309
+ # deleted-and-recreated id (new token) never re-binds it.
310
+ receivedAt: String! # server receipt time
311
+ }
312
+
224
313
  # MemoryCandidate — staged distillations from the FLAIR-NIGHTLY-REM cycle.
225
314
  # Per docs/rem.md. Slice 1 of ops-2qq adds the schema +
226
315
  # `flair rem candidates` listing command. Future slices wire the nightly
@@ -294,3 +383,34 @@ type Asset @table(database: "flair") @export {
294
383
  createdAt: String! @indexed
295
384
  updatedAt: String # stamped on write; later sweep key (nullable/additive)
296
385
  }
386
+
387
+ # OrgSkillAssignment — an org-scope skill assignment (flair#2141 S1):
388
+ # `skillRef`, under `skillName` and `priority`, for the agents on this
389
+ # instance that receive org skills (resources/skill-manifest.ts). No @export:
390
+ # the REST surface is resources/OrgSkillAssignment.ts, whose writes need the
391
+ # operator or internal source and server-stamp `writer`, `sourceClass`,
392
+ # `createdAt` and `updatedAt`. Instance-local: absent from the federation table
393
+ # policy.
394
+ type OrgSkillAssignment @table(database: "flair") {
395
+ id: ID @primaryKey
396
+ skillName: String! @indexed
397
+ skillRef: String!
398
+ priority: String! # critical | high | standard | low
399
+ createdAt: String!
400
+ updatedAt: String
401
+ writer: String # the operator's principal id; null for an internal write
402
+ sourceClass: String! # operator | internal
403
+ }
404
+
405
+ # OrgSkillAssignmentHistory — one row per accepted write through
406
+ # resources/OrgSkillAssignment.ts, appended in the write's transaction.
407
+ # No @export and no resource class: there is no direct /OrgSkillAssignmentHistory route.
408
+ type OrgSkillAssignmentHistory @table(database: "flair") {
409
+ id: ID @primaryKey
410
+ assignmentId: String! @indexed
411
+ op: String! # create | update | delete
412
+ actor: String # the writer; null for an internal write
413
+ sourceClass: String! # operator | internal
414
+ previousHash: String # sha256 of the stored row before the write; null on create
415
+ at: String!
416
+ }
@@ -48,11 +48,15 @@ type IdpConfig @table(database: "flair") @export {
48
48
  updatedAt: String
49
49
  }
50
50
 
51
- # ID-JAG replay prevention — tracks used `jti` claims.
52
- type IdJagReplay @table(database: "flair") {
51
+ # ID-JAG replay prevention — one row per used `jti`, written once per instance
52
+ # under a per-key lock by resources/replay-store.ts (claimIdJagJti).
53
+ # expiration: 90000 — seconds a newly recorded row is kept. It MUST equal
54
+ # ID_JAG_REPLAY_RETENTION_S in resources/XAA.ts, which says why it outlives
55
+ # every accepted assertion whose jti was recorded;
56
+ # test/unit-isolated/xaa-jti-replay.test.ts pins both.
57
+ type IdJagReplay @table(database: "flair", expiration: 90000) {
53
58
  id: ID @primaryKey # the jti value
54
- expiresAt: String! @indexed # TTL for cleanup
55
- createdAt: String!
59
+ seenAt: Long! # ms-epoch when recorded
56
60
  }
57
61
 
58
62
  # Access + refresh tokens.