@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
@@ -43,7 +43,36 @@
43
43
  * so the executor only writes when the planner says it is proven.
44
44
  */
45
45
  import { resolve } from "node:path";
46
+ import { verifyLaunchdManagement } from "./launchd-management.js";
47
+ import { healthIndicatesListener } from "./daemon-liveness.js";
46
48
  import { preserveHttpPortValue, preserveSecurePort } from "./http-bind.js";
49
+ import { renderDomainUnavailableMessage, } from "./launchd-domain-preflight.js";
50
+ // ─── launchd preflight gate (flair#2040) ──────────────────────────────────
51
+ /**
52
+ * The `doctor --fix` refusal when this instance's launchd job cannot be loaded
53
+ * from this session — a PURE gate the executor runs BEFORE it stops, unloads or
54
+ * writes anything (flair#2040).
55
+ *
56
+ * Returns null when the preflight allows an attempt (`available`, or
57
+ * `not-applicable` off macOS), so the executor proceeds. Returns a `refused`
58
+ * result — doctor reports an ISSUE, never "fixed", and exits non-zero — when
59
+ * the GUI domain is `unavailable` or `unknown` (fail closed: a probe we could
60
+ * not interpret must not license stopping a healthy instance), or when the
61
+ * job's label is `disabled` in that domain (launchd would refuse the load).
62
+ *
63
+ * The refusal carries actor + state + remedy in its `detail` (a refusal is a
64
+ * verdict, not a failure, so there is no structured remedy), and says that
65
+ * nothing was touched.
66
+ */
67
+ export function domainPreflightRefusal(loadability, uid) {
68
+ if (loadability.state === "available" || loadability.state === "not-applicable")
69
+ return null;
70
+ return {
71
+ kind: "refused",
72
+ reason: loadability.state === "disabled" ? "launchd-job-disabled" : "launchd-domain-unavailable",
73
+ detail: renderDomainUnavailableMessage(loadability, uid),
74
+ };
75
+ }
47
76
  /**
48
77
  * Classify the plist at `plistPath` against `dataDir`.
49
78
  *
@@ -104,6 +133,19 @@ export function planLaunchdRepair(input) {
104
133
  if (observation.state === "managed") {
105
134
  return { kind: "no-op", reason: "already-managed", detail: observation.detail };
106
135
  }
136
+ // flair#2040: launchd runs the job, but the process serving this instance
137
+ // could not be identified. Regenerating would boot out a job that may be the
138
+ // one serving; adopting has no direct process to stop. Unknown evidence
139
+ // licenses neither: refuse, touching nothing.
140
+ if (observation.state === "unverified") {
141
+ return {
142
+ kind: "refuse",
143
+ reason: "unverifiable",
144
+ detail: `cannot repair launchd management: ${observation.detail}. Nothing was touched. ` +
145
+ "Restart Flair ('flair restart') so it rewrites its hdb.pid, or make lsof available, then re-run 'flair doctor'.",
146
+ plistPath,
147
+ };
148
+ }
107
149
  // Config authority (flair#914): no readable harper-config.yaml means no safe
108
150
  // ROOTPATH/ports, so the repair cannot proceed without inventing them.
109
151
  if (!configReadable) {
@@ -427,3 +469,56 @@ export async function decideAdoptStopWithWait(state, opts) {
427
469
  }
428
470
  return { health: poll.value, decision, timedOut: poll.timedOut, waitedMs: poll.waitedMs, observations: poll.observations };
429
471
  }
472
+ /**
473
+ * Still starting: launchd runs the job (it reported a pid) and nothing answers
474
+ * HTTP on the port yet (`refused`, or a probe that could not tell:
475
+ * `unreachable`) — whatever the management state says, because a pid file can
476
+ * name launchd's pid before the port is bound. Every other observation is
477
+ * final: launchd reports no pid (detached), or something answers the port
478
+ * (then the strict verifier and the health result decide, at once).
479
+ */
480
+ export function launchdJobStillStarting(o) {
481
+ return typeof o.management.launchdPid === "number" && !healthIndicatesListener(o.health);
482
+ }
483
+ /**
484
+ * Poll `observe` while the job is still starting (launchdJobStillStarting), up
485
+ * to `deadlineMs`, and return the final observation. It decides nothing: the
486
+ * caller judges what this returns with judgeLaunchdJobServing (health `ok` and
487
+ * the strict verifier UNCHANGED), so a job that never serves still fails — at
488
+ * the deadline, with the wait named.
489
+ */
490
+ export async function awaitLaunchdJobServing(opts) {
491
+ const poll = await pollUntil({
492
+ observe: opts.observe,
493
+ until: (o) => !launchdJobStillStarting(o),
494
+ deadlineMs: opts.deadlineMs,
495
+ intervalMs: opts.intervalMs,
496
+ now: opts.now,
497
+ sleep: opts.sleep,
498
+ });
499
+ const detail = poll.timedOut
500
+ ? `${poll.value.management.detail} (waited ${poll.waitedMs}ms for the launchd job to start serving; its port still did not answer: ${poll.value.health.kind})`
501
+ : poll.value.management.detail;
502
+ return { observation: poll.value, detail, timedOut: poll.timedOut, waitedMs: poll.waitedMs, observations: poll.observations };
503
+ }
504
+ /**
505
+ * The success test for the job just loaded (flair#2040): Flair's /Health
506
+ * answers `ok` on the instance's port AND the strict verifier passes on the
507
+ * same observation (launchd's pid is the identified serving pid). A matching
508
+ * pid with a port that does not serve Flair is NOT repaired — a pid file can be
509
+ * written before the port is bound, and one that never binds is not serving.
510
+ */
511
+ export function judgeLaunchdJobServing(w) {
512
+ const verdict = verifyLaunchdManagement(w.observation.management);
513
+ if (!verdict.verified)
514
+ return { verified: false, detail: w.detail };
515
+ if (w.observation.health.kind !== "ok") {
516
+ const waited = w.timedOut ? ` after waiting ${w.waitedMs}ms for it to start serving` : "";
517
+ return {
518
+ verified: false,
519
+ detail: `${verdict.detail}, but Flair's /Health on its port did not answer ok${waited} ` +
520
+ `(last health probe: ${w.observation.health.kind}), so the job is NOT serving this instance`,
521
+ };
522
+ }
523
+ return verdict;
524
+ }