@tpsdev-ai/flair 0.54.1 → 0.55.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 (69) hide show
  1. package/dist/build-info.json +3 -3
  2. package/dist/cli.js +774 -176
  3. package/dist/commands/doctor.js +73 -2
  4. package/dist/commands/federation.js +131 -36
  5. package/dist/commands/hook.js +20 -10
  6. package/dist/commands/init.js +193 -67
  7. package/dist/commands/service.js +16 -12
  8. package/dist/commands/soul.js +10 -5
  9. package/dist/commands/status.js +80 -8
  10. package/dist/commands/upgrade.js +41 -5
  11. package/dist/doctor-client.js +118 -32
  12. package/dist/engine-version.js +12 -4
  13. package/dist/fabric-upgrade.js +30 -15
  14. package/dist/hook-install.js +170 -16
  15. package/dist/lib/doctor-run.js +49 -3
  16. package/dist/lib/embed-gpu-doctor.js +30 -0
  17. package/dist/lib/federation-pair-access.js +118 -0
  18. package/dist/lib/harper-port-value.js +43 -0
  19. package/dist/lib/http-bind.js +227 -0
  20. package/dist/lib/init-admin-pass.js +316 -0
  21. package/dist/lib/launchd-management.js +16 -0
  22. package/dist/lib/launchd-repair.js +122 -1
  23. package/dist/lib/npm-registry.js +578 -0
  24. package/dist/lib/owned-pins.js +54 -1
  25. package/dist/lib/process-start-time.js +82 -0
  26. package/dist/lib/scratch-owner.js +124 -10
  27. package/dist/lib/stale-client-pin.js +26 -0
  28. package/dist/rem/runner.js +10 -1
  29. package/dist/resources/AdminInstance.js +8 -2
  30. package/dist/resources/Memory.js +36 -1
  31. package/dist/resources/MemoryBootstrap.js +23 -32
  32. package/dist/resources/MemoryFeed.js +4 -1
  33. package/dist/resources/MemoryReflect.js +121 -93
  34. package/dist/resources/SkillScan.js +13 -11
  35. package/dist/resources/Soul.js +15 -1
  36. package/dist/resources/XAA.js +16 -1
  37. package/dist/resources/a2a-url.js +5 -2
  38. package/dist/resources/client-version-gate.js +144 -0
  39. package/dist/resources/embed-gpu.js +241 -0
  40. package/dist/resources/embeddings-boot.js +34 -42
  41. package/dist/resources/federation-peer-liveness.js +7 -1
  42. package/dist/resources/health.js +12 -3
  43. package/dist/resources/mcp-tools.js +8 -3
  44. package/dist/resources/memory-reflect-lib.js +66 -0
  45. package/dist/resources/memory-reflect-models.js +9 -0
  46. package/dist/resources/migrations/embedding-stamp.js +32 -4
  47. package/dist/resources/oauth-discovery.js +3 -1
  48. package/dist/resources/record-type-kit.js +59 -0
  49. package/dist/resources/scan/skill-markdown.js +166 -0
  50. package/dist/resources/scan/skill-scanner.js +89 -68
  51. package/dist/resources/skill-provenance.js +273 -0
  52. package/dist/resources/skill-write.js +26 -7
  53. package/{node_modules/@tpsdev-ai/flair-tool-descriptors/dist → dist/resources/tool-descriptors}/index.js +4 -0
  54. package/dist/src/lib/harper-port-value.js +43 -0
  55. package/dist/version-check.js +29 -8
  56. package/docs/api-reference.md +35 -2
  57. package/docs/deployment.md +1 -1
  58. package/docs/federation.md +18 -7
  59. package/docs/mcp-clients.md +19 -6
  60. package/docs/releasing.md +96 -24
  61. package/docs/rem.md +1 -1
  62. package/docs/secrets-and-keys.md +1 -0
  63. package/docs/standalone-local.md +1 -1
  64. package/docs/troubleshooting.md +17 -0
  65. package/package.json +4 -9
  66. package/node_modules/@tpsdev-ai/flair-tool-descriptors/LICENSE +0 -19
  67. package/node_modules/@tpsdev-ai/flair-tool-descriptors/README.md +0 -22
  68. package/node_modules/@tpsdev-ai/flair-tool-descriptors/dist/index.d.ts +0 -70
  69. package/node_modules/@tpsdev-ai/flair-tool-descriptors/package.json +0 -46
@@ -37,8 +37,13 @@
37
37
  * - config unreadable -> refuse.
38
38
  * - detached-and-running (ours) -> adopt (clean-stop -> regenerate -> load).
39
39
  * - detached-and-running (foreign) -> refuse (ownership guard).
40
+ * - no satisfiable admin-pass -> refuse (flair#1685; a pass-file plist
41
+ * whose launcher argv names a missing/unsafe file can never start). The
42
+ * plan carries the credential decision (`credential.writeAdminPassFile`)
43
+ * so the executor only writes when the planner says it is proven.
40
44
  */
41
45
  import { resolve } from "node:path";
46
+ import { preserveHttpPortValue, preserveSecurePort } from "./http-bind.js";
42
47
  /**
43
48
  * Classify the plist at `plistPath` against `dataDir`.
44
49
  *
@@ -62,6 +67,27 @@ export function classifyPlist(plistPath, dataDir, deps) {
62
67
  return "unattributable";
63
68
  return resolve(rootPath) === resolve(dataDir) ? "ours" : "foreign";
64
69
  }
70
+ /**
71
+ * Refuse an instance whose recorded bind values a repair cannot serialise,
72
+ * WITHOUT bouncing or writing anything. Returns the refusal detail, or null when
73
+ * the values are repairable.
74
+ *
75
+ * This must run during PLANNING. `buildRepairPlist` (the executor's writer) is
76
+ * the first caller of the preservation helpers and runs AFTER the adopt arm's
77
+ * clean-stop, so a throw there would leave the live instance DOWN with the
78
+ * circular remedy "flair doctor --fix" — the command that just bounced it.
79
+ */
80
+ export function validateRepairBindValues(values) {
81
+ try {
82
+ preserveHttpPortValue(values.httpPort);
83
+ preserveSecurePort(values.httpSecurePort);
84
+ preserveSecurePort(values.opsSecurePort);
85
+ return null;
86
+ }
87
+ catch (err) {
88
+ return err instanceof Error ? err.message : String(err);
89
+ }
90
+ }
65
91
  /**
66
92
  * Decide what `doctor --fix` may do about launchd management.
67
93
  *
@@ -71,7 +97,7 @@ export function classifyPlist(plistPath, dataDir, deps) {
71
97
  * refusal.
72
98
  */
73
99
  export function planLaunchdRepair(input) {
74
- const { observation, disposition, plistPath, directProcessRunning, configReadable } = input;
100
+ const { observation, disposition, plistPath, directProcessRunning, configReadable, adminPass, adminPassPath } = input;
75
101
  if (observation.state === "not-applicable") {
76
102
  return { kind: "no-op", reason: "not-applicable", detail: observation.detail };
77
103
  }
@@ -107,6 +133,24 @@ export function planLaunchdRepair(input) {
107
133
  plistPath,
108
134
  };
109
135
  }
136
+ // Bind values the executor could not serialise (ops-nv9d slice 2). Decided
137
+ // HERE, before any arm that stops the live instance, so an unsupported
138
+ // configuration refuses instead of bouncing first and refusing after.
139
+ if (input.configBindValues) {
140
+ const unsupported = validateRepairBindValues(input.configBindValues);
141
+ if (unsupported) {
142
+ return { kind: "refuse", reason: "unsupported-config", detail: unsupported, plistPath };
143
+ }
144
+ }
145
+ // Credential before plist (flair#1685). The plist this plan authorizes is
146
+ // ALWAYS pass-file mode, so its launcher cannot start unless
147
+ // `adminPassPath` exists and is safe. Never authorize a write the product
148
+ // has not itself made startable: reuse a valid file, materialize a proven
149
+ // env candidate, or refuse.
150
+ const credential = planCredential(adminPass, directProcessRunning, adminPassPath, plistPath);
151
+ if ("kind" in credential) {
152
+ return credential;
153
+ }
110
154
  // Detached-and-running (flair#1573 slice b2): a direct (non-launchd) process
111
155
  // is serving this instance. The plist is ours/absent/corrupt (the foreign and
112
156
  // unattributable cases were refused above), so the direct process is THIS
@@ -119,14 +163,91 @@ export function planLaunchdRepair(input) {
119
163
  detail: "the instance is running but not under launchd (direct-spawned) — adopting it into launchd " +
120
164
  "will clean-stop the live process (SIGTERM, wait for exit), regenerate the plist, and reload it. " +
121
165
  "This bounces the live instance.",
166
+ credential: credential,
122
167
  };
123
168
  }
124
169
  // Repairable: absent, corrupt, or ours, with no direct process in the way.
125
170
  return {
126
171
  kind: "regenerate",
127
172
  detail: "regenerating the launchd plist for this instance",
173
+ credential: credential,
128
174
  };
129
175
  }
176
+ /**
177
+ * Decide whether the pass-file launcher's argv is satisfiable, and how.
178
+ *
179
+ * - an existing valid file -> reuse it (never rewrite; flair#827)
180
+ * - an env candidate + live instance -> write it, after the executor proves
181
+ * it against the instance
182
+ * - an env candidate with no live instance, or nothing at all -> refuse
183
+ *
184
+ * A live instance is required to WRITE because the password is not recoverable
185
+ * from Harper (it stores a hash): the only safe source of the file's bytes is a
186
+ * credential that authenticates against THIS instance right now. Trusting an
187
+ * unverified env value would reintroduce the flair#827 desync this avoids.
188
+ */
189
+ function planCredential(adminPass, directProcessRunning, adminPassPath, plistPath) {
190
+ if (adminPass.kind === "existing-valid") {
191
+ return { writeAdminPassFile: false, source: "existing-file" };
192
+ }
193
+ if (adminPass.kind === "candidate") {
194
+ if (directProcessRunning)
195
+ return { writeAdminPassFile: true, source: "env" };
196
+ return {
197
+ kind: "refuse",
198
+ reason: "missing-credential",
199
+ detail: `refusing to repair the launchd plist at ${plistPath}: a credential is present in the environment, ` +
200
+ `but no running instance is available to prove it against, so ${adminPassPath} cannot be written ` +
201
+ "safely. Start the instance and re-run 'flair doctor --fix', or run 'flair init' to provision " +
202
+ `${adminPassPath}.`,
203
+ plistPath,
204
+ };
205
+ }
206
+ return {
207
+ kind: "refuse",
208
+ reason: "missing-credential",
209
+ detail: `refusing to repair the launchd plist at ${plistPath}: ${adminPass.detail}`,
210
+ plistPath,
211
+ };
212
+ }
213
+ /**
214
+ * Prove the adopted launchd job — not the old direct process — serves the
215
+ * instance (flair#1685). Port health ALONE is the green light that lied in
216
+ * #1684: the direct-spawned init instance answered 9926 the whole time the
217
+ * adopted job was failing to start. The proof is therefore about IDENTITY and
218
+ * CHANGE, not reachability:
219
+ *
220
+ * 1. the pre-adopt process must be dead (otherwise it is still answering);
221
+ * 2. the serving pid must have CHANGED from the pre-adopt pid;
222
+ * 3. the serving pid must be launchd's reported pid for the adopted label
223
+ * (the label's process owns the listener).
224
+ */
225
+ export function verifyAdoptServing(input) {
226
+ const { directPid, managedPid, servingPid, directPidAlive } = input;
227
+ if (directPid !== null && directPidAlive) {
228
+ return {
229
+ detail: `the pre-adopt process ${directPid} is still alive after the bounce, so whatever answers the port ` +
230
+ "may be that process, not the launchd job",
231
+ };
232
+ }
233
+ if (servingPid === null) {
234
+ return {
235
+ detail: "could not identify the process serving this instance after adoption (no hdb.pid and no port listener)",
236
+ };
237
+ }
238
+ if (directPid !== null && servingPid === directPid) {
239
+ return {
240
+ detail: `the serving process is still pid ${servingPid}, the pre-adopt process — adoption did not bounce the live instance`,
241
+ };
242
+ }
243
+ if (managedPid !== null && servingPid !== managedPid) {
244
+ return {
245
+ detail: `the instance is served by pid ${servingPid}, but launchd reports pid ${managedPid} for the adopted ` +
246
+ "job — the launchd job does not own the listener",
247
+ };
248
+ }
249
+ return null;
250
+ }
130
251
  // ─── the executor's pure helpers (slice b2) ───────────────────────────────
131
252
  /**
132
253
  * Map a throw from the executor arm to a named result (flair#1573 slice b2,