@tpsdev-ai/flair 0.56.0 → 0.58.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 (153) hide show
  1. package/README.md +19 -20
  2. package/SECURITY.md +4 -1
  3. package/dist/build-info.json +3 -3
  4. package/dist/cli.js +1800 -293
  5. package/dist/commands/agent.js +22 -15
  6. package/dist/commands/bridge.js +40 -3
  7. package/dist/commands/doctor.js +214 -4
  8. package/dist/commands/federation.js +265 -38
  9. package/dist/commands/hook.js +10 -2
  10. package/dist/commands/init.js +179 -48
  11. package/dist/commands/memory.js +24 -2
  12. package/dist/commands/quality.js +26 -18
  13. package/dist/commands/service.js +137 -22
  14. package/dist/commands/status.js +114 -3
  15. package/dist/commands/upgrade.js +204 -84
  16. package/dist/doctor-client.js +50 -4
  17. package/dist/federation/scheduler.js +253 -4
  18. package/dist/install/clients.js +89 -23
  19. package/dist/install/global-bin-path.js +26 -6
  20. package/dist/lib/atomic-write.js +256 -0
  21. package/dist/lib/auth-resolve.js +46 -0
  22. package/dist/lib/daemon-liveness.js +61 -0
  23. package/dist/lib/doctor-run.js +5 -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/init-admin-pass.js +4 -2
  27. package/dist/lib/init-listener-environ.js +38 -0
  28. package/dist/lib/init-occupied-listener.js +165 -0
  29. package/dist/lib/instance-identity-row.js +580 -0
  30. package/dist/lib/launchd-domain-preflight.js +448 -0
  31. package/dist/lib/launchd-management.js +176 -6
  32. package/dist/lib/launchd-repair.js +95 -0
  33. package/dist/lib/memory-attributes.js +77 -0
  34. package/dist/lib/node-alias-path.js +95 -0
  35. package/dist/lib/npm-registry.js +119 -6
  36. package/dist/lib/owned-pins.js +20 -6
  37. package/dist/lib/redact-token-id.js +197 -0
  38. package/dist/lib/service-repoint-apply.js +267 -0
  39. package/dist/lib/service-repoint.js +575 -0
  40. package/dist/lib/toml-string-array.js +104 -0
  41. package/dist/lib/tree-divergence.js +716 -0
  42. package/dist/lib/upgrade-plain-tree.js +18 -8
  43. package/dist/lib/upgrade-prior-liveness.js +69 -0
  44. package/dist/lib/upgrade-rollback.js +116 -0
  45. package/dist/rem/runner.js +11 -0
  46. package/dist/resources/Agent.js +27 -14
  47. package/dist/resources/AgentSeed.js +39 -2
  48. package/dist/resources/Asset.js +3 -11
  49. package/dist/resources/Credential.js +4 -10
  50. package/dist/resources/Federation.js +299 -127
  51. package/dist/resources/Integration.js +8 -32
  52. package/dist/resources/Memory.js +623 -86
  53. package/dist/resources/MemoryArchive.js +9 -0
  54. package/dist/resources/MemoryBootstrap.js +23 -12
  55. package/dist/resources/MemoryCandidate.js +3 -11
  56. package/dist/resources/MemoryDedupStats.js +1 -1
  57. package/dist/resources/MemoryFeed.js +214 -5
  58. package/dist/resources/MemoryGrant.js +19 -40
  59. package/dist/resources/MemoryHostSource.js +90 -0
  60. package/dist/resources/MemoryMaintenance.js +121 -32
  61. package/dist/resources/MemoryReflect.js +4 -1
  62. package/dist/resources/MemoryReindex.js +7 -4
  63. package/dist/resources/MemoryUsage.js +55 -18
  64. package/dist/resources/Presence.js +18 -10
  65. package/dist/resources/RecordUsage.js +30 -40
  66. package/dist/resources/Relationship.js +170 -89
  67. package/dist/resources/SemanticSearch.js +44 -19
  68. package/dist/resources/Soul.js +31 -19
  69. package/dist/resources/XAA.js +7 -3
  70. package/dist/resources/agent-auth.js +16 -10
  71. package/dist/resources/auth-middleware.js +164 -50
  72. package/dist/resources/auto-promote-lib.js +4 -4
  73. package/dist/resources/bm25-index-service.js +246 -32
  74. package/dist/resources/bm25-status.js +132 -0
  75. package/dist/resources/bm25.js +13 -14
  76. package/dist/resources/ed25519-auth.js +11 -54
  77. package/dist/resources/embed-gpu.js +262 -47
  78. package/dist/resources/embeddings-boot.js +52 -17
  79. package/dist/resources/federation-classify.js +12 -0
  80. package/dist/resources/federation-cleanup.js +289 -51
  81. package/dist/resources/federation-crypto.js +65 -19
  82. package/dist/resources/health.js +105 -22
  83. package/dist/resources/host-pointer/registry.js +35 -0
  84. package/dist/resources/host-pointer-adapter.js +15 -0
  85. package/dist/resources/host-source-visibility.js +167 -0
  86. package/dist/resources/host-source.js +151 -0
  87. package/dist/resources/in-process-api.js +2 -1
  88. package/dist/resources/instance-create-lock.js +363 -0
  89. package/dist/resources/instance-identity-rows.js +43 -0
  90. package/dist/resources/instance-identity.js +97 -12
  91. package/dist/resources/mcp-handler.js +155 -51
  92. package/dist/resources/mcp-tool-arguments.js +83 -0
  93. package/dist/resources/mcp-tools.js +28 -25
  94. package/dist/resources/memory-consolidate-lib.js +3 -1
  95. package/dist/resources/memory-declared-attributes.js +103 -0
  96. package/dist/resources/memory-feed-lib.js +5 -1
  97. package/dist/resources/memory-host-source.js +163 -0
  98. package/dist/resources/memory-visibility.js +10 -7
  99. package/dist/resources/migrations/synthetic-test-migration.js +4 -1
  100. package/dist/resources/migrations/visibility-backfill.js +4 -1
  101. package/dist/resources/originator-instance.js +235 -0
  102. package/dist/resources/promotion-stamp.js +2 -0
  103. package/dist/resources/provenance.js +111 -11
  104. package/dist/resources/rate-limit.js +6 -4
  105. package/dist/resources/record-owner-guard.js +19 -0
  106. package/dist/resources/record-type-kit.js +44 -23
  107. package/dist/resources/record-types.js +6 -6
  108. package/dist/resources/relay-ops.js +28 -3
  109. package/dist/resources/replay-store.js +289 -0
  110. package/dist/resources/request-transaction.js +78 -0
  111. package/dist/resources/search-readiness.js +26 -22
  112. package/dist/resources/semantic-retrieval-core.js +103 -4
  113. package/dist/resources/table-helpers.js +33 -0
  114. package/dist/resources/table-patch-policy.js +109 -0
  115. package/dist/resources/table-patches.js +17 -0
  116. package/dist/resources/table-post-policy.js +138 -0
  117. package/dist/resources/table-posts.js +22 -0
  118. package/dist/resources/table-subscription-policy.js +135 -0
  119. package/dist/resources/table-subscriptions.js +19 -0
  120. package/dist/resources/tool-descriptors/index.js +15 -15
  121. package/dist/resources/trust-block.js +10 -3
  122. package/dist/resources/usage-recording.js +169 -41
  123. package/dist/src/lib/instance-identity-row.js +580 -0
  124. package/dist/src/lib/memory-attributes.js +77 -0
  125. package/dist/src/lib/redact-token-id.js +197 -0
  126. package/docs/api-reference.md +80 -16
  127. package/docs/auth.md +5 -5
  128. package/docs/claude-code.md +137 -6
  129. package/docs/deploying-on-fabric.md +6 -3
  130. package/docs/deployment.md +1 -1
  131. package/docs/embedding-in-a-harper-app.md +3 -3
  132. package/docs/federation.md +17 -10
  133. package/docs/hosted-on-fabric.md +4 -3
  134. package/docs/integrations.md +28 -19
  135. package/docs/mcp-clients.md +26 -32
  136. package/docs/n8n.md +8 -8
  137. package/docs/notes/mcp-oauth-model2.md +27 -18
  138. package/docs/openclaw.md +29 -28
  139. package/docs/quickstart.md +5 -0
  140. package/docs/releasing.md +134 -2
  141. package/docs/spoke-bringup.md +14 -11
  142. package/docs/standalone-local.md +2 -2
  143. package/docs/supply-chain-policy.md +28 -10
  144. package/docs/system-requirements.md +1 -1
  145. package/docs/troubleshooting.md +11 -0
  146. package/docs/upgrade.md +189 -63
  147. package/package.json +9 -5
  148. package/schemas/agent.graphql +9 -6
  149. package/schemas/federation.graphql +2 -11
  150. package/schemas/memory.graphql +106 -17
  151. package/schemas/replay.graphql +18 -0
  152. package/templates/launchd/start-flair-with-admin-pass.sh +22 -0
  153. package/dist/resources/federation-nonce-store.js +0 -195
@@ -1,7 +1,9 @@
1
1
  import { DEFAULT_ADMIN_USER } from "../lib/auth-resolve.js";
2
2
  import { classifyDaemonState } from "../lib/daemon-liveness.js";
3
- import { diagnoseLaunchdPlistPaths, isDetached, renderDetachedWarning } from "../lib/launchd-management.js";
3
+ import { diagnoseLaunchdPlistPaths, isDetached, renderDetachedWarning, verifyLaunchdManagement } from "../lib/launchd-management.js";
4
+ import { LaunchdValidationRefusal, loadabilityAllowsAttempt, renderDirectRunNotice, renderStartLaunchdUnavailable, } from "../lib/launchd-domain-preflight.js";
4
5
  import { opsSocketPathRefusal } from "../lib/socket-path-limit.js";
6
+ import { formatServingTreeLine, formatTreeAssessmentLines } from "../lib/tree-divergence.js";
5
7
  import { spawn } from "node:child_process";
6
8
  import { existsSync } from "node:fs";
7
9
  import { join } from "node:path";
@@ -10,9 +12,34 @@ let cli;
10
12
  export function bindCli(fns) {
11
13
  cli = fns;
12
14
  }
15
+ function afterFailedLaunchdAttempt(...args) {
16
+ return cli.afterFailedLaunchdAttempt(...args);
17
+ }
13
18
  function buildDirectSpawnEnv(...args) {
14
19
  return cli.buildDirectSpawnEnv(...args);
15
20
  }
21
+ /**
22
+ * flair#2034 §2: after a restart, say which install tree now serves the
23
+ * instance — proven from the service manager that owns the serving process —
24
+ * and whether it is this CLI's. This is the verification step of the
25
+ * `flair init && flair restart` remedy. Report-only: the restart itself
26
+ * succeeded, so the exit code is not changed; `ok` is false only when a
27
+ * divergence is PROVEN to remain.
28
+ */
29
+ export function restartTreeReport(a) {
30
+ if (!a)
31
+ return { ok: true, lines: [] };
32
+ if (a.state === "diverged") {
33
+ return {
34
+ ok: false,
35
+ lines: [
36
+ "⚠️ Flair restarted, but the instance still serves a DIFFERENT install tree than this CLI.",
37
+ ...formatTreeAssessmentLines(a, { context: "restart" }),
38
+ ],
39
+ };
40
+ }
41
+ return { ok: true, lines: [` ${formatServingTreeLine(a)}`] };
42
+ }
16
43
  function closedDirectSpawnEnv(...args) {
17
44
  return cli.closedDirectSpawnEnv(...args);
18
45
  }
@@ -28,6 +55,9 @@ function flairPackageDir(...args) {
28
55
  function gatherDaemonEvidence(...args) {
29
56
  return cli.gatherDaemonEvidence(...args);
30
57
  }
58
+ function removeStaleSidecarIfConfirmedDead(...args) {
59
+ return cli.removeStaleSidecarIfConfirmedDead(...args);
60
+ }
31
61
  function guardEngineNotBackwards(...args) {
32
62
  return cli.guardEngineNotBackwards(...args);
33
63
  }
@@ -37,6 +67,12 @@ function harperBinNotFoundMessage(...args) {
37
67
  function harperSearchRoots(...args) {
38
68
  return cli.harperSearchRoots(...args);
39
69
  }
70
+ function launchdLabel(...args) {
71
+ return cli.launchdLabel(...args);
72
+ }
73
+ function observeLaunchdLoadability(...args) {
74
+ return cli.observeLaunchdLoadability(...args);
75
+ }
40
76
  function observeLaunchdManagement(...args) {
41
77
  return cli.observeLaunchdManagement(...args);
42
78
  }
@@ -133,6 +169,12 @@ export function register(program) {
133
169
  }
134
170
  }
135
171
  await waitForProcessExit(pid, STARTUP_TIMEOUT_MS);
172
+ // flair#2055: once the process is CONFIRMED gone, drop the identity
173
+ // sidecar — a leftover naming the stopped pid is what makes a later
174
+ // instance under another supervisor refuse. Gated on a fresh
175
+ // O_NOFOLLOW read that still names the pid it named before; unknown
176
+ // liveness removes nothing.
177
+ removeStaleSidecarIfConfirmedDead(dataDir);
136
178
  const after = await probeHealth(port);
137
179
  if (after.kind === "refused") {
138
180
  console.log(`✅ Flair stopped (${label}, pid ${pid})`);
@@ -143,6 +185,10 @@ export function register(program) {
143
185
  return;
144
186
  }
145
187
  case "NOT_RUNNING":
188
+ // A sidecar left naming a pid that is CONFIRMED gone is a leftover too
189
+ // (flair#2055); clearing it here keeps a repeat stop from carrying the
190
+ // refusal forward.
191
+ removeStaleSidecarIfConfirmedDead(dataDir);
146
192
  console.log("Flair is not running.");
147
193
  return;
148
194
  case "DISAGREEMENT":
@@ -223,33 +269,78 @@ export function register(program) {
223
269
  process.exit(1);
224
270
  }
225
271
  const platform = process.platform;
272
+ // Set when a launchd service is registered for this instance but this run
273
+ // could not start it under launchd — the direct start below then reports
274
+ // "running directly, NOT launchd-managed" instead of a plain success.
275
+ let launchdFellBack = false;
226
276
  if (platform === "darwin") {
227
277
  // resolveLaunchdLabel (flair#693) finds whichever label this data
228
278
  // dir is currently registered under (new instance-scoped, or a
229
279
  // pre-flair#693 legacy install) so the existsSync gate below is
230
280
  // accurate before we attempt anything.
231
- const { plistPath } = resolveLaunchdLabel(dataDir);
281
+ const { plistPath, isLegacy } = resolveLaunchdLabel(dataDir);
232
282
  if (existsSync(plistPath)) {
233
- try {
234
- // flair#1022, same pre-flight as startFlairProcess: launchctl exits 0
235
- // for a job it cannot exec, so a stale plist is only ever observable
236
- // as a startup timeout unless the paths are checked first.
237
- const stalePlist = diagnoseLaunchdPlistPaths(plistPath);
238
- if (stalePlist) {
239
- throw new Error(`${stalePlist.message} Fix it with: ${stalePlist.remedy.join(" && ")}`);
240
- }
241
- const { execSync } = await import("node:child_process");
242
- const { label, migrated } = ensureLaunchdServiceLoaded(dataDir, (cmd) => execSync(cmd, { stdio: "pipe" }));
243
- if (migrated)
244
- console.log(`Migrated launchd service off the legacy label (${LEGACY_LAUNCHD_LABEL}) → ${label} ✓`);
245
- await waitForHealth(port, DEFAULT_ADMIN_USER, process.env.HDB_ADMIN_PASSWORD ?? "", STARTUP_TIMEOUT_MS);
246
- readyOpsSocketPosture(dataDir); // flair#763: re-assert socket posture on the freshly-created socket
247
- stampEngineVersionIfRunning(dataDir); // flair#1047: stamp the store with the engine version
248
- console.log("✅ Flair started (launchd)");
249
- return;
283
+ // flair#2040: preflight BEFORE the load — is the GUI domain reachable
284
+ // from this session, and is the job enabled there? Read-only. When it
285
+ // is not, say why (actor, state) and start directly.
286
+ const jobLabel = launchdLabel(dataDir);
287
+ const loadability = observeLaunchdLoadability(jobLabel);
288
+ if (!loadabilityAllowsAttempt(loadability)) {
289
+ console.error(renderStartLaunchdUnavailable("flair start", loadability));
290
+ launchdFellBack = true;
250
291
  }
251
- catch (err) {
252
- console.error(`launchd start failed, falling back to direct start: ${err.message}`);
292
+ else {
293
+ try {
294
+ // flair#1022, same pre-flight as startFlairProcess: launchctl exits 0
295
+ // for a job it cannot exec, so a stale plist is only ever observable
296
+ // as a startup timeout unless the paths are checked first.
297
+ // flair#2040: a validation refusal — nothing loaded or unloaded.
298
+ const stalePlist = diagnoseLaunchdPlistPaths(plistPath);
299
+ if (stalePlist) {
300
+ throw new LaunchdValidationRefusal(`${stalePlist.message} Fix it with: ${stalePlist.remedy.join(" && ")}`);
301
+ }
302
+ const { execSync } = await import("node:child_process");
303
+ // Targeted at gui/<uid> — the domain the preflight probed (flair#2040).
304
+ const { label, migrated } = ensureLaunchdServiceLoaded(dataDir, (cmd) => execSync(cmd, { stdio: "pipe" }));
305
+ await waitForHealth(port, DEFAULT_ADMIN_USER, process.env.HDB_ADMIN_PASSWORD ?? "", STARTUP_TIMEOUT_MS);
306
+ readyOpsSocketPosture(dataDir); // flair#763: re-assert socket posture on the freshly-created socket
307
+ stampEngineVersionIfRunning(dataDir); // flair#1047: stamp the store with the engine version
308
+ // flair#2040: the launchd check mark only after VERIFYING that
309
+ // launchd's pid IS the identified serving pid — a healthy port is
310
+ // not proof that launchd started what answers it, and an
311
+ // unidentified serving process is not proof either.
312
+ const managed = observeLaunchdManagement(dataDir, port);
313
+ const verdict = verifyLaunchdManagement(managed);
314
+ if (verdict.verified) {
315
+ // The migration's check mark too only after the strict verifier
316
+ // passed: moving a plist is not launchd running this instance.
317
+ if (migrated)
318
+ console.log(`Migrated launchd service off the legacy label (${LEGACY_LAUNCHD_LABEL}) → ${label} ✓`);
319
+ console.log(`✅ Flair started (launchd-managed: ${verdict.detail})`);
320
+ return;
321
+ }
322
+ // Healthy, but not proven to be launchd's process: no launchd check
323
+ // mark, and no claim about what happens at the next reboot either.
324
+ console.error(`⚠️ Flair is running on port ${port}, but it is NOT verified as launchd-managed: ${managed.detail}`);
325
+ if (migrated)
326
+ console.error(` The launchd service was moved off the legacy label (${LEGACY_LAUNCHD_LABEL}) → ${label}.`);
327
+ if (managed.remedy?.length)
328
+ console.error(` Fix: ${managed.remedy.join(" && ")}`);
329
+ return;
330
+ }
331
+ catch (err) {
332
+ // flair#2040: start directly below only when no job for this
333
+ // instance could start underneath the direct process. A failed LOAD
334
+ // is unloaded again and verified gone; a VALIDATION refusal loaded
335
+ // and unloaded nothing, so nothing is booted out — a loaded job (a
336
+ // legacy one, say) refuses the direct start instead.
337
+ const after = afterFailedLaunchdAttempt("flair start", jobLabel, isLegacy ? [jobLabel, LEGACY_LAUNCHD_LABEL] : [jobLabel], err);
338
+ for (const line of after.lines)
339
+ console.error(line);
340
+ if (!after.directStart)
341
+ process.exit(1);
342
+ launchdFellBack = true;
343
+ }
253
344
  }
254
345
  }
255
346
  }
@@ -290,7 +381,16 @@ export function register(program) {
290
381
  await waitForHealth(port, DEFAULT_ADMIN_USER, adminPass, STARTUP_TIMEOUT_MS);
291
382
  readyOpsSocketPosture(dataDir); // flair#763: re-assert socket posture on the freshly-created socket
292
383
  stampEngineVersionIfRunning(dataDir); // flair#1047: stamp the store with the engine version
293
- console.log(`✅ Flair started on port ${port}`);
384
+ if (launchdFellBack) {
385
+ // flair#2040: a direct start that took launchd's place says so.
386
+ const [headline, ...rest] = renderDirectRunNotice(port, proc.pid ?? null);
387
+ console.log(headline);
388
+ for (const line of rest)
389
+ console.error(line);
390
+ }
391
+ else {
392
+ console.log(`✅ Flair started on port ${port}`);
393
+ }
294
394
  }
295
395
  catch {
296
396
  console.error("❌ Flair failed to start within timeout. Check logs in " + join(dataDir, "harper.log"));
@@ -333,7 +433,22 @@ export function register(program) {
333
433
  }
334
434
  return;
335
435
  }
436
+ let tree = null;
437
+ try {
438
+ tree = cli.assessInstallTree(dataDir, port, { local: true });
439
+ }
440
+ catch {
441
+ tree = null;
442
+ }
443
+ const report = restartTreeReport(tree);
444
+ if (!report.ok) {
445
+ for (const line of report.lines)
446
+ console.error(line);
447
+ return;
448
+ }
336
449
  console.log("✅ Flair restarted");
450
+ for (const line of report.lines)
451
+ console.log(line);
337
452
  }
338
453
  catch (err) {
339
454
  console.error(`❌ Flair failed to restart: ${err?.message ?? err}`);
@@ -2,6 +2,7 @@ import { resolveAdminUser } from "../lib/auth-resolve.js";
2
2
  import { opsApiBindFinding } from "../lib/ops-api-bind.js";
3
3
  import * as render from "../render.js";
4
4
  import { checkVersion, formatVersionNudge, FLAIR_PKG_NAME } from "../version-check.js";
5
+ import { formatServingTreeLine, formatTreeAssessmentLines, treeAssessmentJson, } from "../lib/tree-divergence.js";
5
6
  import { resolveRegistryNotice } from "../lib/npm-registry.js";
6
7
  let cli;
7
8
  /** Bind the cli-locals this module depends on. */
@@ -32,6 +33,63 @@ function readHarperConfig(...args) {
32
33
  function readPortFromConfig() {
33
34
  return cli.readPortFromConfig();
34
35
  }
36
+ function resolveHttpPort(...args) {
37
+ return cli.resolveHttpPort(...args);
38
+ }
39
+ /**
40
+ * flair#2034 §2: the version-and-tree advice `flair status` prints, decided in
41
+ * ONE place from one comparison, each hint at most once:
42
+ *
43
+ * - a PROVEN tree divergence prints the divergence block (both trees, both
44
+ * versions — "unknown" where one cannot be read — and the remedy) INSTEAD
45
+ * of the CLI's "is behind — run: flair upgrade" hint, which would upgrade
46
+ * the wrong tree;
47
+ * - otherwise the CLI-currency hint (this CLI vs the latest published) prints
48
+ * once, and — separately — the server-currency line when the running
49
+ * server's version differs from this CLI's. Its advice depends on what is
50
+ * proven: `flair restart` only when the instance serves this CLI's own
51
+ * tree; no local remedy when the serving tree is unknown.
52
+ *
53
+ * Pure: returns the lines; the caller prints them.
54
+ */
55
+ export function statusVersionAdvice(input) {
56
+ const out = [];
57
+ const t = input.tree;
58
+ // A separately managed tree (a plain tree, a checkout) is the steady state of
59
+ // such a deployment; it is named only when its version differs from this CLI's.
60
+ const nameSeparate = t?.state === "separate" && input.runningVersion !== input.cliVersion;
61
+ if (t && (t.state === "diverged" || nameSeparate)) {
62
+ const tone = t.state === "diverged" ? "yellow" : "plain";
63
+ for (const line of formatTreeAssessmentLines(t, { latest: input.latest, context: "status" }))
64
+ out.push({ tone, text: line });
65
+ if (t.state === "diverged")
66
+ return out;
67
+ }
68
+ if (input.versionNudge) {
69
+ out.push({ tone: input.versionNudge.severity === "red" ? "red" : "yellow", text: `⚠ ${input.versionNudge.message}` });
70
+ }
71
+ const rv = input.runningVersion;
72
+ if (rv === null) {
73
+ out.push({ tone: "dim", text: `server version: unknown (this CLI is flair ${input.cliVersion})` });
74
+ }
75
+ else if (rv !== input.cliVersion) {
76
+ if (t?.state === "same") {
77
+ out.push({
78
+ tone: "yellow",
79
+ text: `⚠ the server is running flair ${rv}; this CLI (the same install tree) is ${input.cliVersion} — run: flair restart`,
80
+ });
81
+ }
82
+ else if (!nameSeparate) {
83
+ out.push({
84
+ tone: "yellow",
85
+ text: `⚠ the server is running flair ${rv}; this CLI is ${input.cliVersion}. ` +
86
+ (t ? formatServingTreeLine(t) : "serving install tree: unknown") +
87
+ ", so this CLI cannot say which tree to update.",
88
+ });
89
+ }
90
+ }
91
+ return out;
92
+ }
35
93
  /**
36
94
  * Local install-health warnings that `flair doctor` also checks (flair#852).
37
95
  *
@@ -114,6 +172,13 @@ function oauthDetailLines(o) {
114
172
  // 19926: current default (DEFAULT_PORT)
115
173
  // 19925: ops-anvil VM secondary
116
174
  const LOCAL_FLAIR_PROBE_PORTS = [9926, 19926, 19925];
175
+ /** The BM25 line /HealthDetail already formatted. Null on an older server. */
176
+ export function formatBm25StatusLine(bm25) {
177
+ if (!bm25 || typeof bm25.summary !== "string")
178
+ return null;
179
+ const summary = bm25.summary.trim();
180
+ return summary.length > 0 ? summary : null;
181
+ }
117
182
  /**
118
183
  * The unreachable-path guidance for a localhost target, as printable lines.
119
184
  *
@@ -246,6 +311,33 @@ export function register(program) {
246
311
  // check, so a redirected mirror is never silent — including when the
247
312
  // version answer came from cache and no network request was made.
248
313
  const registryNotice = await resolveRegistryNotice(FLAIR_PKG_NAME);
314
+ // flair#2034 §2: which install tree serves the instance that answered —
315
+ // proven from the service manager that owns the answering process, or
316
+ // unknown. Only a local query of this data dir's instance can be proven.
317
+ const runningVersion = typeof healthData?.version === "string" && healthData.version !== "" ? healthData.version : null;
318
+ let treeAssessment = null;
319
+ if (healthy) {
320
+ try {
321
+ const port = resolveHttpPort(opts);
322
+ let urlPort = null;
323
+ try {
324
+ urlPort = Number(new URL(baseUrl).port) || null;
325
+ }
326
+ catch {
327
+ urlPort = null;
328
+ }
329
+ const local = isLocalhostUrl(baseUrl) && urlPort === port && !opts.target && !process.env.FLAIR_TARGET;
330
+ treeAssessment = cli.assessInstallTree(defaultDataDir(), port, {
331
+ local,
332
+ queryUrl: baseUrl,
333
+ respondingPid: typeof healthData?.pid === "number" ? healthData.pid : null,
334
+ runningVersion,
335
+ });
336
+ }
337
+ catch {
338
+ treeAssessment = null;
339
+ }
340
+ }
249
341
  if (opts.json) {
250
342
  const out = { healthy, url: baseUrl, flairVersion: __pkgVersion, ...healthData };
251
343
  if (localWarnings.length > 0) {
@@ -258,6 +350,9 @@ export function register(program) {
258
350
  out.discoveredPort = discoveredPort;
259
351
  if (versionCheckResult.latest)
260
352
  out.latestVersion = versionCheckResult.latest;
353
+ // flair#2034 §2: the same install-tree comparison the human output uses.
354
+ out.serverVersion = runningVersion;
355
+ out.installTree = treeAssessment ? treeAssessmentJson(treeAssessment) : null;
261
356
  if (registryNotice.line)
262
357
  out.registry = registryNotice.line;
263
358
  if (registryNotice.error)
@@ -360,9 +455,19 @@ export function register(program) {
360
455
  console.log(render.kv("Registry", registryNotice.line.replace(/^registry:\s*/, "")));
361
456
  if (registryNotice.error)
362
457
  console.log(` ${render.icons.warn} ${render.wrap(render.c.yellow, registryNotice.error)}`);
363
- if (versionNudge) {
364
- const color = versionNudge.severity === "red" ? render.c.red : render.c.yellow;
365
- console.log(`\n ${render.wrap(color, "⚠")} ${render.wrap(color, versionNudge.message)}`);
458
+ // flair#2034 §2: every version / install-tree hint, decided once.
459
+ const advice = statusVersionAdvice({
460
+ cliVersion: __pkgVersion,
461
+ runningVersion,
462
+ versionNudge,
463
+ latest: versionCheckResult.latest ?? null,
464
+ tree: treeAssessment,
465
+ });
466
+ if (advice.length > 0)
467
+ console.log("");
468
+ for (const a of advice) {
469
+ const color = a.tone === "red" ? render.c.red : a.tone === "yellow" ? render.c.yellow : a.tone === "dim" ? render.c.dim : null;
470
+ console.log(` ${color ? render.wrap(color, a.text) : a.text}`);
366
471
  }
367
472
  if (scopedWarnings.length > 0) {
368
473
  console.log(`\n${render.wrap(render.c.bold, "Warnings")} ${render.wrap(render.c.dim, `(${scopedWarnings.length})`)}`);
@@ -404,6 +509,9 @@ export function register(program) {
404
509
  if (healthData?.lastWrite)
405
510
  console.log(render.kv("Last write", render.relativeTime(healthData.lastWrite)));
406
511
  }
512
+ const bm25Line = formatBm25StatusLine(healthData?.bm25);
513
+ if (bm25Line)
514
+ console.log(render.kv("BM25 index", bm25Line));
407
515
  if (agents && agents.count > 0) {
408
516
  console.log(`\n${render.wrap(render.c.bold, "Agents")}`);
409
517
  const nameStr = agents.names?.length > 0 ? ` ${render.wrap(render.c.dim, "—")} ${agents.names.join(render.wrap(render.c.dim, ", "))}` : "";
@@ -847,6 +955,9 @@ export function register(program) {
847
955
  if (healthData?.lastWrite)
848
956
  console.log(`Last write: ${relativeTime(healthData.lastWrite)} (${healthData.lastWrite})`);
849
957
  }
958
+ const bm25DeepLine = formatBm25StatusLine(healthData?.bm25);
959
+ if (bm25DeepLine)
960
+ console.log(`BM25 index: ${bm25DeepLine}`);
850
961
  const agents = healthData?.agents;
851
962
  if (agents && agents.count > 0) {
852
963
  console.log("\n═══ Agents ═══════════════════════════════════════");