@tpsdev-ai/flair 0.57.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.
- package/README.md +4 -4
- package/SECURITY.md +4 -1
- package/dist/build-info.json +3 -3
- package/dist/cli.js +1685 -279
- package/dist/commands/doctor.js +162 -4
- package/dist/commands/federation.js +2 -1
- package/dist/commands/hook.js +10 -2
- package/dist/commands/init.js +150 -44
- package/dist/commands/memory.js +24 -2
- package/dist/commands/quality.js +26 -18
- package/dist/commands/service.js +137 -22
- package/dist/commands/status.js +114 -3
- package/dist/commands/upgrade.js +204 -84
- package/dist/doctor-client.js +50 -4
- package/dist/federation/scheduler.js +253 -4
- package/dist/install/clients.js +89 -23
- package/dist/install/global-bin-path.js +26 -6
- package/dist/lib/atomic-write.js +256 -0
- package/dist/lib/daemon-liveness.js +61 -0
- package/dist/lib/doctor-run.js +5 -0
- package/dist/lib/embed-gpu-doctor.js +49 -26
- package/dist/lib/federation-memory-attributes.js +15 -0
- package/dist/lib/init-admin-pass.js +4 -2
- package/dist/lib/init-listener-environ.js +38 -0
- package/dist/lib/init-occupied-listener.js +165 -0
- package/dist/lib/launchd-domain-preflight.js +448 -0
- package/dist/lib/launchd-management.js +176 -6
- package/dist/lib/launchd-repair.js +95 -0
- package/dist/lib/memory-attributes.js +77 -0
- package/dist/lib/node-alias-path.js +95 -0
- package/dist/lib/npm-registry.js +119 -6
- package/dist/lib/owned-pins.js +20 -6
- package/dist/lib/service-repoint-apply.js +267 -0
- package/dist/lib/service-repoint.js +575 -0
- package/dist/lib/toml-string-array.js +104 -0
- package/dist/lib/tree-divergence.js +716 -0
- package/dist/lib/upgrade-plain-tree.js +18 -8
- package/dist/lib/upgrade-prior-liveness.js +69 -0
- package/dist/lib/upgrade-rollback.js +116 -0
- package/dist/rem/runner.js +11 -0
- package/dist/resources/Agent.js +27 -14
- package/dist/resources/AgentSeed.js +35 -1
- package/dist/resources/Federation.js +70 -52
- package/dist/resources/Memory.js +567 -72
- package/dist/resources/MemoryArchive.js +9 -0
- package/dist/resources/MemoryBootstrap.js +4 -0
- package/dist/resources/MemoryFeed.js +204 -3
- package/dist/resources/MemoryHostSource.js +90 -0
- package/dist/resources/MemoryMaintenance.js +121 -32
- package/dist/resources/MemoryReflect.js +4 -1
- package/dist/resources/MemoryReindex.js +7 -4
- package/dist/resources/MemoryUsage.js +53 -3
- package/dist/resources/Presence.js +18 -10
- package/dist/resources/RecordUsage.js +30 -40
- package/dist/resources/Relationship.js +167 -78
- package/dist/resources/SemanticSearch.js +19 -6
- package/dist/resources/Soul.js +31 -19
- package/dist/resources/XAA.js +7 -3
- package/dist/resources/agent-auth.js +16 -10
- package/dist/resources/auth-middleware.js +135 -48
- package/dist/resources/auto-promote-lib.js +4 -4
- package/dist/resources/bm25-index-service.js +246 -32
- package/dist/resources/bm25-status.js +132 -0
- package/dist/resources/ed25519-auth.js +11 -54
- package/dist/resources/embed-gpu.js +262 -47
- package/dist/resources/embeddings-boot.js +52 -17
- package/dist/resources/federation-classify.js +12 -0
- package/dist/resources/federation-crypto.js +65 -19
- package/dist/resources/health.js +57 -14
- package/dist/resources/host-pointer/registry.js +35 -0
- package/dist/resources/host-pointer-adapter.js +15 -0
- package/dist/resources/host-source-visibility.js +167 -0
- package/dist/resources/host-source.js +151 -0
- package/dist/resources/instance-identity.js +3 -2
- package/dist/resources/mcp-handler.js +147 -51
- package/dist/resources/mcp-tools.js +25 -21
- package/dist/resources/memory-consolidate-lib.js +3 -1
- package/dist/resources/memory-declared-attributes.js +103 -0
- package/dist/resources/memory-feed-lib.js +5 -1
- package/dist/resources/memory-host-source.js +163 -0
- package/dist/resources/migrations/synthetic-test-migration.js +4 -1
- package/dist/resources/migrations/visibility-backfill.js +4 -1
- package/dist/resources/originator-instance.js +235 -0
- package/dist/resources/promotion-stamp.js +2 -0
- package/dist/resources/provenance.js +111 -11
- package/dist/resources/record-owner-guard.js +19 -0
- package/dist/resources/record-type-kit.js +9 -12
- package/dist/resources/record-types.js +6 -6
- package/dist/resources/relay-ops.js +28 -3
- package/dist/resources/replay-store.js +289 -0
- package/dist/resources/request-transaction.js +78 -0
- package/dist/resources/search-readiness.js +19 -21
- package/dist/resources/semantic-retrieval-core.js +5 -1
- package/dist/resources/table-patch-policy.js +109 -0
- package/dist/resources/table-patches.js +17 -0
- package/dist/resources/table-post-policy.js +138 -0
- package/dist/resources/table-posts.js +22 -0
- package/dist/resources/table-subscription-policy.js +135 -0
- package/dist/resources/table-subscriptions.js +19 -0
- package/dist/resources/tool-descriptors/index.js +15 -15
- package/dist/resources/trust-block.js +10 -3
- package/dist/resources/usage-recording.js +169 -41
- package/dist/src/lib/memory-attributes.js +77 -0
- package/docs/api-reference.md +79 -15
- package/docs/claude-code.md +132 -0
- package/docs/deployment.md +1 -1
- package/docs/federation.md +1 -1
- package/docs/integrations.md +5 -5
- package/docs/mcp-clients.md +11 -21
- package/docs/notes/mcp-oauth-model2.md +15 -1
- package/docs/quickstart.md +5 -0
- package/docs/releasing.md +134 -2
- package/docs/supply-chain-policy.md +10 -5
- package/docs/troubleshooting.md +11 -0
- package/docs/upgrade.md +187 -61
- package/package.json +9 -5
- package/schemas/agent.graphql +9 -6
- package/schemas/federation.graphql +2 -11
- package/schemas/memory.graphql +106 -17
- package/schemas/replay.graphql +18 -0
- package/templates/launchd/start-flair-with-admin-pass.sh +22 -0
- package/dist/resources/federation-nonce-store.js +0 -195
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
* extracted program/working-directory paths ever reach a message, and the
|
|
46
46
|
* extractor below reads exactly those keys rather than returning the document.
|
|
47
47
|
*/
|
|
48
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
48
|
+
import { accessSync, constants, existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
49
49
|
import { unescapeXml } from "./xml-escape.js";
|
|
50
50
|
/**
|
|
51
51
|
* Ceiling on the `launchctl list` spawn. A status query answers instantly when
|
|
@@ -158,6 +158,133 @@ export function diagnoseLaunchdPlistPaths(plistPath, deps = {}) {
|
|
|
158
158
|
}
|
|
159
159
|
return null;
|
|
160
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Validate a plist's CONTENT before it is written or loaded (flair#2040) —
|
|
163
|
+
* the check that must pass before any command stops the running instance to
|
|
164
|
+
* put this plist in its place.
|
|
165
|
+
*
|
|
166
|
+
* `diagnoseLaunchdPlistPaths` reads a plist that is already on disk and words
|
|
167
|
+
* its finding as drift ("no longer exists"). This reads the document the caller
|
|
168
|
+
* is ABOUT to install and answers a stricter question: can launchd run it?
|
|
169
|
+
*
|
|
170
|
+
* - every absolute ProgramArguments entry exists;
|
|
171
|
+
* - ProgramArguments[0] — what launchd execs — is executable;
|
|
172
|
+
* - for the pass-file shape (`<launcher> <admin-pass-file> <node> <harper>`),
|
|
173
|
+
* the node binary the launcher execs is executable;
|
|
174
|
+
* - WorkingDirectory is an existing directory;
|
|
175
|
+
* - ROOTPATH (the data directory) is an existing directory.
|
|
176
|
+
*
|
|
177
|
+
* Returns one line naming the offending key and path, or null. Never returns
|
|
178
|
+
* plist content — only the extracted paths (the plist may name the pass file).
|
|
179
|
+
*/
|
|
180
|
+
export function checkLaunchdPlistBeforeLoad(content, deps = {}) {
|
|
181
|
+
const exists = deps.exists ?? existsSync;
|
|
182
|
+
const isExecutable = deps.isExecutable ?? ((p) => {
|
|
183
|
+
try {
|
|
184
|
+
accessSync(p, constants.X_OK);
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
const isDirectory = deps.isDirectory ?? ((p) => {
|
|
192
|
+
try {
|
|
193
|
+
return statSync(p).isDirectory();
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
const refs = readPlistProgramRefs("<content>", () => content);
|
|
200
|
+
if (!refs || refs.programArguments.length === 0)
|
|
201
|
+
return "the plist has no ProgramArguments";
|
|
202
|
+
for (const arg of refs.programArguments) {
|
|
203
|
+
if (arg.startsWith("/") && !exists(arg))
|
|
204
|
+
return `ProgramArguments names ${arg}, which does not exist`;
|
|
205
|
+
}
|
|
206
|
+
const program = refs.programArguments[0];
|
|
207
|
+
if (!program.startsWith("/"))
|
|
208
|
+
return `ProgramArguments[0] (${program}) is not an absolute path`;
|
|
209
|
+
if (!isExecutable(program))
|
|
210
|
+
return `ProgramArguments[0] (${program}) is not executable, so launchd cannot exec it`;
|
|
211
|
+
if (refs.programArguments.length >= 4 && refs.programArguments[0].endsWith(".sh")) {
|
|
212
|
+
const node = refs.programArguments[2];
|
|
213
|
+
if (node.startsWith("/") && !isExecutable(node))
|
|
214
|
+
return `the node binary the launcher execs (${node}) is not executable`;
|
|
215
|
+
}
|
|
216
|
+
const wd = refs.workingDirectory;
|
|
217
|
+
if (wd === null)
|
|
218
|
+
return "the plist has no WorkingDirectory";
|
|
219
|
+
if (!isDirectory(wd))
|
|
220
|
+
return `WorkingDirectory ${wd} is not an existing directory`;
|
|
221
|
+
const root = content.match(/<key>ROOTPATH<\/key>\s*<string>([^<]*)<\/string>/);
|
|
222
|
+
if (!root)
|
|
223
|
+
return "the plist has no ROOTPATH";
|
|
224
|
+
const rootPath = unescapeXml(root[1]);
|
|
225
|
+
if (!isDirectory(rootPath))
|
|
226
|
+
return `ROOTPATH ${rootPath} (the data directory) is not an existing directory`;
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
function realpathOr(p, realpath) {
|
|
230
|
+
try {
|
|
231
|
+
return realpath(p);
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
return p;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
export function classifyServiceNodePin(input, deps = {}) {
|
|
238
|
+
const exists = deps.exists ?? existsSync;
|
|
239
|
+
const realpath = deps.realpath ?? ((p) => realpathSync(p));
|
|
240
|
+
const { unitNodeBin, unitTree, currentNodeBin, cliTree, unitDescription } = input;
|
|
241
|
+
if (!unitNodeBin || !unitTree)
|
|
242
|
+
return null;
|
|
243
|
+
if (!exists(unitNodeBin))
|
|
244
|
+
return null; // the missing path is diagnoseLaunchdPlistPaths's
|
|
245
|
+
if (realpathOr(unitNodeBin, realpath) === realpathOr(currentNodeBin, realpath))
|
|
246
|
+
return null;
|
|
247
|
+
if (realpathOr(unitTree, realpath) === realpathOr(cliTree, realpath)) {
|
|
248
|
+
return {
|
|
249
|
+
kind: "pinned",
|
|
250
|
+
unitNodeBin,
|
|
251
|
+
currentNodeBin,
|
|
252
|
+
// `flair init` never rewrites a pin (it reports `pinned-node` and writes
|
|
253
|
+
// nothing), so the only way to move it is by hand — said as such.
|
|
254
|
+
message: `${unitDescription} pins node ${unitNodeBin} while this CLI runs ${currentNodeBin}, and it serves this ` +
|
|
255
|
+
`CLI's own install tree (${unitTree}). That is treated as a deliberate runtime pin and left as it is; ` +
|
|
256
|
+
"`flair init` does not change it. To move the service to this CLI's runtime, change that node path to " +
|
|
257
|
+
`${currentNodeBin} in the unit by hand, then run: flair restart`,
|
|
258
|
+
remedy: [],
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
kind: "erroneous",
|
|
263
|
+
unitNodeBin,
|
|
264
|
+
currentNodeBin,
|
|
265
|
+
message: `${unitDescription} runs node ${unitNodeBin} from the install tree ${unitTree}, but this CLI runs node ` +
|
|
266
|
+
`${currentNodeBin} from ${cliTree}. Both were baked at an earlier runtime, so the service keeps serving ` +
|
|
267
|
+
"the old tree while the CLI runs from the current one.",
|
|
268
|
+
remedy: ["flair init", "flair restart"],
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* `classifyServiceNodePin` for a launchd plist: reads the node argument and the
|
|
273
|
+
* WorkingDirectory out of the plist and classifies them against this CLI.
|
|
274
|
+
*/
|
|
275
|
+
export function diagnoseLaunchdNodePath(plistPath, currentNodeBin, cliTree, deps = {}) {
|
|
276
|
+
const refs = readPlistProgramRefs(plistPath, deps.read);
|
|
277
|
+
if (!refs)
|
|
278
|
+
return null;
|
|
279
|
+
const unitNodeBin = refs.programArguments.find((a) => a.startsWith("/") && /(^|[/\\])node$/.test(a)) ?? null;
|
|
280
|
+
return classifyServiceNodePin({
|
|
281
|
+
unitDescription: `the launchd plist at ${plistPath}`,
|
|
282
|
+
unitNodeBin,
|
|
283
|
+
unitTree: refs.workingDirectory,
|
|
284
|
+
currentNodeBin,
|
|
285
|
+
cliTree,
|
|
286
|
+
}, deps);
|
|
287
|
+
}
|
|
161
288
|
/**
|
|
162
289
|
* Parse `launchctl list <label>` output.
|
|
163
290
|
*
|
|
@@ -214,6 +341,25 @@ export function pickInstancePid(input) {
|
|
|
214
341
|
export function isDetached(m) {
|
|
215
342
|
return m.state === "detached";
|
|
216
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* The STRICT verifier every success claim goes through (flair#2040): a
|
|
346
|
+
* launchd check mark from `flair start` or `flair init`, and `doctor --fix`'s
|
|
347
|
+
* "repaired". Verified ONLY when launchd reported a pid, a serving pid was
|
|
348
|
+
* IDENTIFIED, and they are the same number. An unknown serving pid is never
|
|
349
|
+
* verified — unknown evidence must not license a success claim.
|
|
350
|
+
*
|
|
351
|
+
* `assessLaunchdManagement` is the observer (status, warnings); this decides
|
|
352
|
+
* what may be claimed.
|
|
353
|
+
*/
|
|
354
|
+
export function verifyLaunchdManagement(m) {
|
|
355
|
+
if (m.state === "managed" &&
|
|
356
|
+
typeof m.launchdPid === "number" &&
|
|
357
|
+
typeof m.servingPid === "number" &&
|
|
358
|
+
m.launchdPid === m.servingPid) {
|
|
359
|
+
return { verified: true, pid: m.launchdPid, detail: m.detail };
|
|
360
|
+
}
|
|
361
|
+
return { verified: false, detail: m.detail, remedy: m.remedy };
|
|
362
|
+
}
|
|
217
363
|
/**
|
|
218
364
|
* Is this instance under launchd right now?
|
|
219
365
|
*
|
|
@@ -232,10 +378,11 @@ export function isDetached(m) {
|
|
|
232
378
|
* - launchd reports a PID that is not the instance's PID ⇒ **detached**, and
|
|
233
379
|
* this is the exact shape the incident produced: launchd holds a job that
|
|
234
380
|
* is failing, while a directly-spawned process answers on the port.
|
|
235
|
-
* - launchd reports a PID and we cannot
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
381
|
+
* - launchd reports a PID and we cannot identify the instance's own ⇒
|
|
382
|
+
* **unverified** (flair#2040). Warning on it would alarm healthy installs,
|
|
383
|
+
* which is its own defect; calling it managed would be a claim without
|
|
384
|
+
* proof. It is neither: no warning, and no success claim
|
|
385
|
+
* (verifyLaunchdManagement refuses it).
|
|
239
386
|
*
|
|
240
387
|
* A parent-process check is NOT used, and that is worth stating because it is
|
|
241
388
|
* the obvious first idea: the direct-start fallback spawns `detached: true` and
|
|
@@ -292,9 +439,32 @@ export function assessLaunchdManagement(input) {
|
|
|
292
439
|
detail: `this instance is served by process ${instancePid}, but launchd's job ${label} is process ${job.pid} — ` +
|
|
293
440
|
`the running instance is not the one launchd manages.${because}`,
|
|
294
441
|
remedy,
|
|
442
|
+
launchdPid: job.pid,
|
|
443
|
+
servingPid: instancePid,
|
|
295
444
|
};
|
|
296
445
|
}
|
|
297
|
-
|
|
446
|
+
if (instancePid === null) {
|
|
447
|
+
// flair#2040: launchd runs SOMETHING, but nothing identifies the process
|
|
448
|
+
// serving this instance. Not detached (no evidence of that, and a warning
|
|
449
|
+
// on a healthy install trains operators to skip warnings) — and not
|
|
450
|
+
// managed either: an unknown serving pid is not proof.
|
|
451
|
+
return {
|
|
452
|
+
state: "unverified",
|
|
453
|
+
label,
|
|
454
|
+
detail: `launchd job ${label} is running as process ${job.pid}, but the process serving this instance could not be ` +
|
|
455
|
+
"identified (no live hdb.pid, and no listener found on its port), so launchd management is NOT verified",
|
|
456
|
+
remedy: ["flair restart"],
|
|
457
|
+
launchdPid: job.pid,
|
|
458
|
+
servingPid: null,
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
return {
|
|
462
|
+
state: "managed",
|
|
463
|
+
label,
|
|
464
|
+
detail: `launchd job ${label} is running as process ${job.pid}`,
|
|
465
|
+
launchdPid: job.pid,
|
|
466
|
+
servingPid: instancePid,
|
|
467
|
+
};
|
|
298
468
|
}
|
|
299
469
|
/**
|
|
300
470
|
* The lines to print for a degraded (detached) outcome.
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** Shared Memory field contract for resource writers and federation readers.
|
|
2
|
+
* Kept under src so the CLI build can include it within its rootDir; the
|
|
3
|
+
* server build also emits this dependency under dist/src/lib.
|
|
4
|
+
* Pure data: importing this contract never loads Harper.
|
|
5
|
+
*/
|
|
6
|
+
/** Every DECLARED attribute of `type Memory` in schemas/memory.graphql, in
|
|
7
|
+
* schema order. Keep in sync with the schema (the drift test enforces it). */
|
|
8
|
+
export const DECLARED_MEMORY_ATTRIBUTES = Object.freeze([
|
|
9
|
+
"id",
|
|
10
|
+
"agentId",
|
|
11
|
+
"content",
|
|
12
|
+
"contentHash",
|
|
13
|
+
"trigger",
|
|
14
|
+
"visibility",
|
|
15
|
+
"embedding",
|
|
16
|
+
"embeddingModel",
|
|
17
|
+
"tags",
|
|
18
|
+
"durability",
|
|
19
|
+
"source",
|
|
20
|
+
"type",
|
|
21
|
+
"createdAt",
|
|
22
|
+
"updatedAt",
|
|
23
|
+
"instanceToken",
|
|
24
|
+
"expiresAt",
|
|
25
|
+
"retrievalCount",
|
|
26
|
+
"lastRetrieved",
|
|
27
|
+
"usageCount",
|
|
28
|
+
"promotionStatus",
|
|
29
|
+
"promotedAt",
|
|
30
|
+
"promotedBy",
|
|
31
|
+
"archived",
|
|
32
|
+
"archivedAt",
|
|
33
|
+
"archivedBy",
|
|
34
|
+
"parentId",
|
|
35
|
+
"derivedFrom",
|
|
36
|
+
"sessionId",
|
|
37
|
+
"lastReflected",
|
|
38
|
+
"supersedes",
|
|
39
|
+
"subject",
|
|
40
|
+
"summary",
|
|
41
|
+
"validFrom",
|
|
42
|
+
"validTo",
|
|
43
|
+
"_safetyFlags",
|
|
44
|
+
"provenance",
|
|
45
|
+
"originatorInstanceId",
|
|
46
|
+
"metadata",
|
|
47
|
+
"entities",
|
|
48
|
+
]);
|
|
49
|
+
/** Pre-existing UNDECLARED attributes the codebase deliberately stores on a
|
|
50
|
+
* Memory row and must keep (the guard's job is the POINTER, not these).
|
|
51
|
+
* This is an EXPLICIT, NAMED list measured against a live store (A1'' item 1)
|
|
52
|
+
* — never derived from the schema, because the schema is not the source of
|
|
53
|
+
* truth for what is on disk:
|
|
54
|
+
* - `meta` — the continuity-journal payload {seq, processUUID, sessionId,
|
|
55
|
+
* hook} written by the capture path (PUT /Memory/<id>,
|
|
56
|
+
* flair#1257 slice 3); Kern's slice-2 ruling settled that it
|
|
57
|
+
* round-trips as an undeclared field, and
|
|
58
|
+
* test/integration/continuity-rem-promotion-1257.test.ts pins
|
|
59
|
+
* that. It is not a flat String, so declaring it would change
|
|
60
|
+
* the stored shape.
|
|
61
|
+
* - `kind` — carried on a couple of older rows.
|
|
62
|
+
* - `_originatorInstanceId`, `_syncedFrom`, `_syncedAt` — federation
|
|
63
|
+
* bookkeeping stamped by the RECEIVER at merge time
|
|
64
|
+
* (resources/Federation.ts's mergeRecord) on every synced row.
|
|
65
|
+
* Any OTHER undeclared key (in particular any pointer input) is stripped. */
|
|
66
|
+
export const UNDECLARED_ALLOWED = Object.freeze([
|
|
67
|
+
"meta",
|
|
68
|
+
"kind",
|
|
69
|
+
"_originatorInstanceId",
|
|
70
|
+
"_syncedFrom",
|
|
71
|
+
"_syncedAt",
|
|
72
|
+
]);
|
|
73
|
+
/** Every field retained by Memory writers and the inbound federation guard. */
|
|
74
|
+
export const MEMORY_ATTRIBUTES = Object.freeze([
|
|
75
|
+
...DECLARED_MEMORY_ATTRIBUTES,
|
|
76
|
+
...UNDECLARED_ALLOWED,
|
|
77
|
+
]);
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* node-alias-path.ts — the node binary path to write into a generated service
|
|
3
|
+
* unit or shim (flair#2034 §2).
|
|
4
|
+
*
|
|
5
|
+
* A version manager exposes each installed runtime under a path that carries
|
|
6
|
+
* its exact version (`…/installs/node/24.19.0/bin/node`). Some also expose a
|
|
7
|
+
* FLOATING alias that resolves to one of them. This module writes such an alias
|
|
8
|
+
* instead of the exact path when, and only when, the alias resolves (realpath)
|
|
9
|
+
* to the very binary we would otherwise write. When no alias resolves to the
|
|
10
|
+
* same binary, the exact path is written unchanged: a path that points at a
|
|
11
|
+
* DIFFERENT runtime would be worse than the bug.
|
|
12
|
+
*
|
|
13
|
+
* Where an alias exists, and where it does not:
|
|
14
|
+
*
|
|
15
|
+
* - mise: `$MISE_DATA_DIR | ~/.local/share/mise` + `/installs/node/<major>/bin/node`.
|
|
16
|
+
* mise keeps `installs/node/<major>` as a symlink to the newest installed
|
|
17
|
+
* runtime of that major, so it resolves to the same binary and is written.
|
|
18
|
+
* - Volta: `$VOLTA_HOME | ~/.volta` + `/bin/node`. Considered, but a standard
|
|
19
|
+
* Volta install makes that path a link to `volta-shim`, whose realpath is
|
|
20
|
+
* not a node binary, so the equality check rejects it and the exact path is
|
|
21
|
+
* written. It is chosen only on a setup where it really is the same binary.
|
|
22
|
+
* - nvm, fnm, asdf: no alias path of this kind (nvm's default alias is a text
|
|
23
|
+
* file; asdf's `shims/node` is a script), so the exact path is written.
|
|
24
|
+
*
|
|
25
|
+
* WHAT A FLOATING ALIAS DOES LATER. The alias is a moving pointer, by design:
|
|
26
|
+
* when mise retargets `installs/node/24` to a newer 24.x, a unit holding the
|
|
27
|
+
* alias runs THAT runtime from then on, without flair being re-run. That keeps
|
|
28
|
+
* the unit's node path from dangling after a patch/minor bump, but it is a
|
|
29
|
+
* different runtime than the one that was in use when the unit was written.
|
|
30
|
+
*
|
|
31
|
+
* WHAT IT DOES NOT DO. Only the node binary floats. The install tree a unit
|
|
32
|
+
* serves (its working directory, the Harper entry, the launcher, the flair
|
|
33
|
+
* script a shim runs) lives under the exact runtime's global prefix
|
|
34
|
+
* (`…/installs/node/24.19.0/lib/node_modules/@tpsdev-ai/flair`), and is written
|
|
35
|
+
* as that exact path. After a Node bump, `npm i -g @tpsdev-ai/flair` under the
|
|
36
|
+
* new runtime installs a NEW tree; the unit keeps serving the old one until it
|
|
37
|
+
* is re-pointed (`flair init && flair restart`).
|
|
38
|
+
*/
|
|
39
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
40
|
+
import { join } from "node:path";
|
|
41
|
+
import { resolveHome } from "./home.js";
|
|
42
|
+
/** `24.19.0` / `v24.19.0` → `24.19.0`; null when no version is present. */
|
|
43
|
+
export function parseNodeVersion(nodePath) {
|
|
44
|
+
const m = /(?:^|[/\\])v?(\d+\.\d+\.\d+)(?:[/\\]|$)/.exec(nodePath);
|
|
45
|
+
return m ? m[1] : null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The floating aliases a version manager might expose for `nodeBin`'s runtime.
|
|
49
|
+
* Pure: derived from the path + env only, no filesystem access. Callers filter
|
|
50
|
+
* by existence + realpath equality.
|
|
51
|
+
*/
|
|
52
|
+
export function aliasCandidates(nodeBin, hooks = {}) {
|
|
53
|
+
const home = hooks.home ?? resolveHome();
|
|
54
|
+
const env = hooks.env ?? process.env;
|
|
55
|
+
const version = parseNodeVersion(nodeBin);
|
|
56
|
+
const out = [];
|
|
57
|
+
if (!version || !home)
|
|
58
|
+
return out;
|
|
59
|
+
const major = version.split(".")[0];
|
|
60
|
+
const miseData = env.MISE_DATA_DIR ?? join(home, ".local", "share", "mise");
|
|
61
|
+
out.push({ manager: "mise", path: join(miseData, "installs", "node", major, "bin", "node") });
|
|
62
|
+
const voltaHome = env.VOLTA_HOME ?? join(home, ".volta");
|
|
63
|
+
out.push({ manager: "volta", path: join(voltaHome, "bin", "node") });
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The node path to WRITE into a generated unit: a floating alias whose realpath
|
|
68
|
+
* is the same binary as `nodeBin`, when one exists; otherwise `nodeBin`
|
|
69
|
+
* unchanged. mise's major alias is preferred over Volta's when both match.
|
|
70
|
+
*/
|
|
71
|
+
export function preferVersionManagerAlias(nodeBin, hooks = {}) {
|
|
72
|
+
const exists = hooks.exists ?? existsSync;
|
|
73
|
+
const realpath = hooks.realpath ?? ((p) => realpathSync(p));
|
|
74
|
+
let target;
|
|
75
|
+
try {
|
|
76
|
+
target = realpath(nodeBin);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return nodeBin; // the resolved binary is not readable — write it as given
|
|
80
|
+
}
|
|
81
|
+
for (const c of aliasCandidates(nodeBin, hooks)) {
|
|
82
|
+
try {
|
|
83
|
+
if (c.path === nodeBin)
|
|
84
|
+
continue;
|
|
85
|
+
if (!exists(c.path))
|
|
86
|
+
continue;
|
|
87
|
+
if (realpath(c.path) === target)
|
|
88
|
+
return c.path;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
/* an unreadable candidate is not a match */
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return nodeBin;
|
|
95
|
+
}
|
package/dist/lib/npm-registry.js
CHANGED
|
@@ -482,15 +482,59 @@ function runNpmViewJson(spec, field, registryUrl, timeoutMs) {
|
|
|
482
482
|
const message = String(stderr || err.message || "npm view failed").trim();
|
|
483
483
|
return resolve({ ok: false, message });
|
|
484
484
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
}
|
|
488
|
-
catch {
|
|
489
|
-
resolve({ ok: false, message: "npm view returned non-JSON output" });
|
|
490
|
-
}
|
|
485
|
+
const parsed = parseNpmViewStdout(String(stdout));
|
|
486
|
+
resolve(parsed);
|
|
491
487
|
});
|
|
492
488
|
});
|
|
493
489
|
}
|
|
490
|
+
/** Parse trimmed stdout as JSON; distinguish empty output from invalid JSON. */
|
|
491
|
+
export function parseNpmViewStdout(stdout) {
|
|
492
|
+
const text = stdout.trim();
|
|
493
|
+
if (text === "")
|
|
494
|
+
return { ok: false, message: "npm view returned empty output" };
|
|
495
|
+
try {
|
|
496
|
+
return { ok: true, data: JSON.parse(text), message: "" };
|
|
497
|
+
}
|
|
498
|
+
catch {
|
|
499
|
+
return { ok: false, message: "npm view returned malformed JSON" };
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
/** Remove characters in U+0000-U+001F and U+007F-U+009F. */
|
|
503
|
+
export function stripControlChars(value) {
|
|
504
|
+
return value.replace(/[\u0000-\u001F\u007F\u0080-\u009F]/g, "");
|
|
505
|
+
}
|
|
506
|
+
/** Accept a non-array object whose name and version equal the requested values. */
|
|
507
|
+
export function isExactVersionDocument(data, packageName, version) {
|
|
508
|
+
if (!data || typeof data !== "object" || Array.isArray(data))
|
|
509
|
+
return false;
|
|
510
|
+
const doc = data;
|
|
511
|
+
if (doc.version !== version)
|
|
512
|
+
return false;
|
|
513
|
+
if (doc.name !== packageName)
|
|
514
|
+
return false;
|
|
515
|
+
return true;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Empty-output errors and blank strings yield active; nonblank strings yield
|
|
519
|
+
* deprecated. Other errors and non-string values yield unavailable.
|
|
520
|
+
* Deprecation messages have control characters removed and a fallback if empty.
|
|
521
|
+
*/
|
|
522
|
+
export function deprecationFromNpmView(parsed) {
|
|
523
|
+
if (!parsed.ok) {
|
|
524
|
+
if (parsed.message === "npm view returned empty output")
|
|
525
|
+
return { kind: "active" };
|
|
526
|
+
return { kind: "unavailable", message: parsed.message };
|
|
527
|
+
}
|
|
528
|
+
// Non-string JSON values yield unavailable, including null.
|
|
529
|
+
if (typeof parsed.data !== "string") {
|
|
530
|
+
return { kind: "unavailable", message: "npm view deprecated field was not a string" };
|
|
531
|
+
}
|
|
532
|
+
const raw = parsed.data;
|
|
533
|
+
const cleaned = stripControlChars(raw).trim();
|
|
534
|
+
if (!raw.trim())
|
|
535
|
+
return { kind: "active" };
|
|
536
|
+
return { kind: "deprecated", message: cleaned || "npm marked this version deprecated" };
|
|
537
|
+
}
|
|
494
538
|
/** True when this registry should be queried through npm rather than fetch(). */
|
|
495
539
|
async function useNpmTransport(registry, deps) {
|
|
496
540
|
if (registry.url === DEFAULT_NPM_REGISTRY)
|
|
@@ -576,3 +620,72 @@ export async function fetchDeclaredDependencies(packageName, version, deps = {})
|
|
|
576
620
|
: null;
|
|
577
621
|
return { kind: "ok", dependencies, registry };
|
|
578
622
|
}
|
|
623
|
+
/**
|
|
624
|
+
* Query deprecation for a strict semver version using the resolved registry.
|
|
625
|
+
* HTTP responses must pass isExactVersionDocument; npm output goes through
|
|
626
|
+
* deprecationFromNpmView. Absent HTTP fields and blank strings yield active;
|
|
627
|
+
* nonblank strings yield deprecated. Non-string fields yield unavailable.
|
|
628
|
+
* Registry resolution errors return refused; invalid versions return invalid.
|
|
629
|
+
* decideDeprecatedRollback refuses only a reported deprecated result.
|
|
630
|
+
*/
|
|
631
|
+
export async function fetchVersionDeprecation(packageName, version, deps = {}) {
|
|
632
|
+
if (!isStrictSemver(version))
|
|
633
|
+
return { kind: "invalid", value: version };
|
|
634
|
+
let registry;
|
|
635
|
+
try {
|
|
636
|
+
registry = await resolveNpmRegistryDetailed(packageName, deps);
|
|
637
|
+
}
|
|
638
|
+
catch (err) {
|
|
639
|
+
if (err instanceof RegistryRefusalError)
|
|
640
|
+
return { kind: "refused", message: err.message };
|
|
641
|
+
return { kind: "refused", message: err instanceof Error ? err.message : String(err) };
|
|
642
|
+
}
|
|
643
|
+
deps.onRegistry?.(registry);
|
|
644
|
+
const timeoutMs = deps.timeoutMs ?? 5000;
|
|
645
|
+
if (await useNpmTransport(registry, deps)) {
|
|
646
|
+
const view = deps.npmViewJson ?? runNpmViewJson;
|
|
647
|
+
const out = await view(`${packageName}@${version}`, "deprecated", registry.url, timeoutMs);
|
|
648
|
+
const field = deprecationFromNpmView(out);
|
|
649
|
+
if (field.kind === "unavailable")
|
|
650
|
+
return { kind: "unavailable", message: field.message, registry };
|
|
651
|
+
if (field.kind === "deprecated")
|
|
652
|
+
return { kind: "deprecated", message: field.message, registry };
|
|
653
|
+
return { kind: "active", registry };
|
|
654
|
+
}
|
|
655
|
+
const out = await fetchRegistryJson(`${registry.url}/${packageName}/${version}`, timeoutMs, deps.fetchImpl);
|
|
656
|
+
if (!out.ok)
|
|
657
|
+
return { kind: "unavailable", message: out.message, registry };
|
|
658
|
+
if (!isExactVersionDocument(out.data, packageName, version)) {
|
|
659
|
+
return {
|
|
660
|
+
kind: "unavailable",
|
|
661
|
+
message: `registry response was not a version document for ${packageName}@${version}`,
|
|
662
|
+
registry,
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
const deprecated = out.data.deprecated;
|
|
666
|
+
if (!Object.prototype.hasOwnProperty.call(out.data, "deprecated")) {
|
|
667
|
+
return { kind: "active", registry };
|
|
668
|
+
}
|
|
669
|
+
if (typeof deprecated === "string" && !deprecated.trim())
|
|
670
|
+
return { kind: "active", registry };
|
|
671
|
+
if (deprecated === null) {
|
|
672
|
+
return {
|
|
673
|
+
kind: "unavailable",
|
|
674
|
+
message: `registry deprecated field for ${packageName}@${version} was null`,
|
|
675
|
+
registry,
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
if (typeof deprecated !== "string") {
|
|
679
|
+
return {
|
|
680
|
+
kind: "unavailable",
|
|
681
|
+
message: `registry deprecated field for ${packageName}@${version} was not a string`,
|
|
682
|
+
registry,
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
const cleaned = stripControlChars(deprecated).trim();
|
|
686
|
+
return {
|
|
687
|
+
kind: "deprecated",
|
|
688
|
+
message: cleaned || "npm marked this version deprecated",
|
|
689
|
+
registry,
|
|
690
|
+
};
|
|
691
|
+
}
|