@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.
- package/dist/build-info.json +3 -3
- package/dist/cli.js +774 -176
- package/dist/commands/doctor.js +73 -2
- package/dist/commands/federation.js +131 -36
- package/dist/commands/hook.js +20 -10
- package/dist/commands/init.js +193 -67
- package/dist/commands/service.js +16 -12
- package/dist/commands/soul.js +10 -5
- package/dist/commands/status.js +80 -8
- package/dist/commands/upgrade.js +41 -5
- package/dist/doctor-client.js +118 -32
- package/dist/engine-version.js +12 -4
- package/dist/fabric-upgrade.js +30 -15
- package/dist/hook-install.js +170 -16
- package/dist/lib/doctor-run.js +49 -3
- package/dist/lib/embed-gpu-doctor.js +30 -0
- package/dist/lib/federation-pair-access.js +118 -0
- package/dist/lib/harper-port-value.js +43 -0
- package/dist/lib/http-bind.js +227 -0
- package/dist/lib/init-admin-pass.js +316 -0
- package/dist/lib/launchd-management.js +16 -0
- package/dist/lib/launchd-repair.js +122 -1
- package/dist/lib/npm-registry.js +578 -0
- package/dist/lib/owned-pins.js +54 -1
- package/dist/lib/process-start-time.js +82 -0
- package/dist/lib/scratch-owner.js +124 -10
- package/dist/lib/stale-client-pin.js +26 -0
- package/dist/rem/runner.js +10 -1
- package/dist/resources/AdminInstance.js +8 -2
- package/dist/resources/Memory.js +36 -1
- package/dist/resources/MemoryBootstrap.js +23 -32
- package/dist/resources/MemoryFeed.js +4 -1
- package/dist/resources/MemoryReflect.js +121 -93
- package/dist/resources/SkillScan.js +13 -11
- package/dist/resources/Soul.js +15 -1
- package/dist/resources/XAA.js +16 -1
- package/dist/resources/a2a-url.js +5 -2
- package/dist/resources/client-version-gate.js +144 -0
- package/dist/resources/embed-gpu.js +241 -0
- package/dist/resources/embeddings-boot.js +34 -42
- package/dist/resources/federation-peer-liveness.js +7 -1
- package/dist/resources/health.js +12 -3
- package/dist/resources/mcp-tools.js +8 -3
- package/dist/resources/memory-reflect-lib.js +66 -0
- package/dist/resources/memory-reflect-models.js +9 -0
- package/dist/resources/migrations/embedding-stamp.js +32 -4
- package/dist/resources/oauth-discovery.js +3 -1
- package/dist/resources/record-type-kit.js +59 -0
- package/dist/resources/scan/skill-markdown.js +166 -0
- package/dist/resources/scan/skill-scanner.js +89 -68
- package/dist/resources/skill-provenance.js +273 -0
- package/dist/resources/skill-write.js +26 -7
- package/{node_modules/@tpsdev-ai/flair-tool-descriptors/dist → dist/resources/tool-descriptors}/index.js +4 -0
- package/dist/src/lib/harper-port-value.js +43 -0
- package/dist/version-check.js +29 -8
- package/docs/api-reference.md +35 -2
- package/docs/deployment.md +1 -1
- package/docs/federation.md +18 -7
- package/docs/mcp-clients.md +19 -6
- package/docs/releasing.md +96 -24
- package/docs/rem.md +1 -1
- package/docs/secrets-and-keys.md +1 -0
- package/docs/standalone-local.md +1 -1
- package/docs/troubleshooting.md +17 -0
- package/package.json +4 -9
- package/node_modules/@tpsdev-ai/flair-tool-descriptors/LICENSE +0 -19
- package/node_modules/@tpsdev-ai/flair-tool-descriptors/README.md +0 -22
- package/node_modules/@tpsdev-ai/flair-tool-descriptors/dist/index.d.ts +0 -70
- package/node_modules/@tpsdev-ai/flair-tool-descriptors/package.json +0 -46
package/dist/hook-install.js
CHANGED
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
// reuses bootstrap's own maxTokens machinery.
|
|
55
55
|
import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
56
56
|
import { dirname, join } from "node:path";
|
|
57
|
-
import { SESSION_START_HOOK_MARKER, buildSessionStartHookCommand, buildContinuityCaptureHookCommand, checkContinuityCaptureHooks, computeContinuityHookInstall, computeContinuityHookRemoval, hookCommandIsSilenced, isHookCommandValueSafe, isSessionStartHookInvocation, readClientMcpBlock, } from "./doctor-client.js";
|
|
57
|
+
import { SESSION_START_HOOK_MARKER, buildSessionStartHookCommand, buildContinuityCaptureHookCommand, checkContinuityCaptureHooks, computeContinuityHookInstall, computeContinuityHookRemoval, hookCommandIsSilenced, hookCommandDiscardsStderr, isFlairHookCommand, isHookCommandValueSafe, isSessionStartHookInvocation, readClientMcpBlock, } from "./doctor-client.js";
|
|
58
58
|
import { mcpServerSpec } from "./lib/mcp-spec.js";
|
|
59
59
|
// ── harness registry ────────────────────────────────────────────────────────
|
|
60
60
|
/** SessionStart hook harnesses. A second harness is an additive registry
|
|
@@ -122,8 +122,12 @@ export function hookBackupPath(settingsPath) {
|
|
|
122
122
|
* so the invocation's failure behaviour is defined and tested in one place
|
|
123
123
|
* instead of drifting across three literals. Throws when agentId/flairUrl
|
|
124
124
|
* cannot be represented safely; installHook() checks first and reports. */
|
|
125
|
-
export function buildHookCommand(agentId, flairUrl) {
|
|
126
|
-
return buildSessionStartHookCommand(agentId, flairUrl);
|
|
125
|
+
export function buildHookCommand(agentId, flairUrl, harness = "claude-code") {
|
|
126
|
+
return buildSessionStartHookCommand(agentId, flairUrl, { harness });
|
|
127
|
+
}
|
|
128
|
+
const CODEX_REAPPROVAL = "Codex requires re-approval in /hooks before the change takes effect";
|
|
129
|
+
function withCodexReapproval(harness, message) {
|
|
130
|
+
return harness === "codex" ? `${message} — ${CODEX_REAPPROVAL}` : message;
|
|
127
131
|
}
|
|
128
132
|
/**
|
|
129
133
|
* Peel the installer `sh -c '...'` wrapper (and its `out=$(...)` capture)
|
|
@@ -133,7 +137,7 @@ export function buildHookCommand(agentId, flairUrl) {
|
|
|
133
137
|
function unwrapInstallerHookCommand(command) {
|
|
134
138
|
const shc = command.match(/^sh\s+-c\s+(['"])([\s\S]*)\1\s*$/);
|
|
135
139
|
const body = shc ? shc[2] : command;
|
|
136
|
-
// SessionStart installer: `out=$(<invocation> 2>/dev/null) && printf ...`
|
|
140
|
+
// SessionStart installer: `out=$(<invocation> [2>/dev/null]) && printf ...`
|
|
137
141
|
const captured = body.match(/^out=\$\((.*)\)\s*&&/);
|
|
138
142
|
return captured ? captured[1] : body;
|
|
139
143
|
}
|
|
@@ -237,8 +241,8 @@ function takeBackup(path) {
|
|
|
237
241
|
copyFileSync(path, dest);
|
|
238
242
|
return dest;
|
|
239
243
|
}
|
|
240
|
-
function computeInstallDelta(config, agentId, flairUrl) {
|
|
241
|
-
const command = buildHookCommand(agentId, flairUrl);
|
|
244
|
+
function computeInstallDelta(config, agentId, flairUrl, harness) {
|
|
245
|
+
const command = buildHookCommand(agentId, flairUrl, harness);
|
|
242
246
|
const after = makeHookGroup(command);
|
|
243
247
|
const existing = findHookEntry(config);
|
|
244
248
|
if (existing) {
|
|
@@ -308,11 +312,11 @@ export function installHook(opts) {
|
|
|
308
312
|
backupPath: null, delta: null,
|
|
309
313
|
};
|
|
310
314
|
}
|
|
311
|
-
const { action, before, after } = computeInstallDelta(read.parsed ?? {}, agentId, flairUrl);
|
|
315
|
+
const { action, before, after } = computeInstallDelta(read.parsed ?? {}, agentId, flairUrl, harness);
|
|
312
316
|
const delta = { action, path, harness, before, after };
|
|
313
317
|
const message = action === "noop"
|
|
314
|
-
? `already correct in ${path} — no changes`
|
|
315
|
-
: `would ${action} the SessionStart hook in ${path} (dry run — nothing written)
|
|
318
|
+
? withCodexReapproval(harness, `already correct in ${path} — no changes`)
|
|
319
|
+
: withCodexReapproval(harness, `would ${action} the SessionStart hook in ${path} (dry run — nothing written)`);
|
|
316
320
|
return { ok: true, path, harness, dryRun, message, backupPath: null, delta };
|
|
317
321
|
}
|
|
318
322
|
// Backup BEFORE the parse attempt (Sherlock condition 1) — only meaningful
|
|
@@ -340,16 +344,20 @@ export function installHook(opts) {
|
|
|
340
344
|
backupPath, delta: null,
|
|
341
345
|
};
|
|
342
346
|
}
|
|
343
|
-
const { action, before, after, newConfig } = computeInstallDelta(read.parsed ?? {}, agentId, flairUrl);
|
|
347
|
+
const { action, before, after, newConfig } = computeInstallDelta(read.parsed ?? {}, agentId, flairUrl, harness);
|
|
344
348
|
const delta = { action, path, harness, before, after };
|
|
345
349
|
if (action === "noop") {
|
|
346
|
-
return {
|
|
350
|
+
return {
|
|
351
|
+
ok: true, path, harness, dryRun,
|
|
352
|
+
message: withCodexReapproval(harness, `SessionStart hook already correct in ${path}`),
|
|
353
|
+
backupPath, delta,
|
|
354
|
+
};
|
|
347
355
|
}
|
|
348
356
|
mkdirSync(dirname(path), { recursive: true });
|
|
349
357
|
writeFileSync(path, JSON.stringify(newConfig, null, 2) + "\n");
|
|
350
358
|
return {
|
|
351
359
|
ok: true, path, harness, dryRun,
|
|
352
|
-
message: `${action === "add" ? "added" : "updated"} the SessionStart hook in ${path}
|
|
360
|
+
message: withCodexReapproval(harness, `${action === "add" ? "added" : "updated"} the SessionStart hook in ${path}`),
|
|
353
361
|
backupPath, delta,
|
|
354
362
|
};
|
|
355
363
|
}
|
|
@@ -400,7 +408,7 @@ export function repinSessionStartHook(homeDir, harness) {
|
|
|
400
408
|
}
|
|
401
409
|
let next;
|
|
402
410
|
try {
|
|
403
|
-
next = buildSessionStartHookCommand(env.agentId, env.flairUrl);
|
|
411
|
+
next = buildSessionStartHookCommand(env.agentId, env.flairUrl, { harness });
|
|
404
412
|
}
|
|
405
413
|
catch (err) {
|
|
406
414
|
const reason = err instanceof Error ? err.message : String(err);
|
|
@@ -481,27 +489,173 @@ export function uninstallHook(opts) {
|
|
|
481
489
|
writeFileSync(path, JSON.stringify(newConfig, null, 2) + "\n");
|
|
482
490
|
return { ok: true, path, harness, dryRun, message: `removed the Flair SessionStart hook from ${path}`, backupPath, delta };
|
|
483
491
|
}
|
|
492
|
+
/**
|
|
493
|
+
* Effect check: did the hook command produce SessionStart additionalContext?
|
|
494
|
+
* Exit 0, inert `{}`, and empty stdout are not that. Do not treat
|
|
495
|
+
* FLAIR_HOOK_PROBE's `{}` as success. This is not harness delivery.
|
|
496
|
+
*/
|
|
497
|
+
export function classifyHookDelivery(outcome) {
|
|
498
|
+
if (outcome.timedOut) {
|
|
499
|
+
return { delivered: false, reason: "not delivered: probe timed out" };
|
|
500
|
+
}
|
|
501
|
+
if (outcome.spawnError) {
|
|
502
|
+
return { delivered: false, reason: `not delivered: probe spawn failed (${outcome.spawnError})` };
|
|
503
|
+
}
|
|
504
|
+
if (outcome.exitCode !== 0) {
|
|
505
|
+
if (outcome.exitCode == null) {
|
|
506
|
+
return { delivered: false, reason: "not delivered: probe did not exit" };
|
|
507
|
+
}
|
|
508
|
+
return { delivered: false, reason: `not delivered: exited ${outcome.exitCode}` };
|
|
509
|
+
}
|
|
510
|
+
const trimmed = (outcome.stdout ?? "").trim();
|
|
511
|
+
if (!trimmed) {
|
|
512
|
+
return { delivered: false, reason: "not delivered: empty stdout" };
|
|
513
|
+
}
|
|
514
|
+
if (trimmed === "{}") {
|
|
515
|
+
return { delivered: false, reason: "not delivered: inert empty context" };
|
|
516
|
+
}
|
|
517
|
+
try {
|
|
518
|
+
const parsed = JSON.parse(trimmed);
|
|
519
|
+
const context = parsed?.hookSpecificOutput?.additionalContext;
|
|
520
|
+
if (typeof context === "string" && context.trim()) {
|
|
521
|
+
return { delivered: true, reason: "the hook command produced additionalContext" };
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
catch {
|
|
525
|
+
// fall through — JSON-looking but not the documented contract
|
|
526
|
+
}
|
|
527
|
+
return { delivered: false, reason: "not delivered: no SessionStart additionalContext" };
|
|
528
|
+
}
|
|
529
|
+
/** Operator headline. Never an unqualified "wired" when delivery is unverified. */
|
|
530
|
+
export function hookStatusHeadline(status) {
|
|
531
|
+
if (!status.wired || status.delivery === "absent")
|
|
532
|
+
return "not configured";
|
|
533
|
+
if (status.delivery === "verified")
|
|
534
|
+
return "configured; verified the hook command produced additionalContext";
|
|
535
|
+
return "configured; delivery NOT verified";
|
|
536
|
+
}
|
|
537
|
+
function readCodexConfigToml(homeDir) {
|
|
538
|
+
const configPath = join(homeDir, ".codex", "config.toml");
|
|
539
|
+
if (!existsSync(configPath))
|
|
540
|
+
return null;
|
|
541
|
+
try {
|
|
542
|
+
return readFileSync(configPath, "utf-8");
|
|
543
|
+
}
|
|
544
|
+
catch {
|
|
545
|
+
return null;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
function scanCodexFeaturesHooksEnabled(raw) {
|
|
549
|
+
const header = raw.match(/^\[features\]\s*$/m);
|
|
550
|
+
if (!header || header.index === undefined)
|
|
551
|
+
return undefined;
|
|
552
|
+
const rest = raw.slice(header.index);
|
|
553
|
+
for (const line of rest.split("\n").slice(1)) {
|
|
554
|
+
const trimmed = line.trim();
|
|
555
|
+
if (trimmed.startsWith("["))
|
|
556
|
+
break;
|
|
557
|
+
const match = trimmed.match(/^(?:hooks|codex_hooks)\s*=\s*(true|false)\b/);
|
|
558
|
+
if (match)
|
|
559
|
+
return match[1] === "true";
|
|
560
|
+
}
|
|
561
|
+
return undefined;
|
|
562
|
+
}
|
|
563
|
+
function readCodexHookRuntime(homeDir) {
|
|
564
|
+
const mcp = readClientMcpBlock("codex", homeDir);
|
|
565
|
+
const raw = readCodexConfigToml(homeDir);
|
|
566
|
+
if (raw == null) {
|
|
567
|
+
return { hooksEnabled: undefined, mcpAgentId: mcp.agentId, hasTrustedHash: false };
|
|
568
|
+
}
|
|
569
|
+
return {
|
|
570
|
+
hooksEnabled: scanCodexFeaturesHooksEnabled(raw),
|
|
571
|
+
mcpAgentId: mcp.agentId,
|
|
572
|
+
hasTrustedHash: /^\s*trusted_hash\s*=/m.test(raw),
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
function assessDelivery(homeDir, harness, wired, agentId, correctShape, command, deliveryProbe) {
|
|
576
|
+
if (!wired)
|
|
577
|
+
return { delivery: "absent", deliveryReasons: [] };
|
|
578
|
+
const blockers = [];
|
|
579
|
+
const notes = [];
|
|
580
|
+
if (harness === "codex") {
|
|
581
|
+
const runtime = readCodexHookRuntime(homeDir);
|
|
582
|
+
if (runtime.hooksEnabled === false) {
|
|
583
|
+
blockers.push("Codex features.hooks is disabled — the harness will not run this hook");
|
|
584
|
+
}
|
|
585
|
+
if (runtime.mcpAgentId && agentId && runtime.mcpAgentId !== agentId) {
|
|
586
|
+
blockers.push(`agent id drift: hook command is '${agentId}', MCP env is '${runtime.mcpAgentId}'`);
|
|
587
|
+
}
|
|
588
|
+
if (runtime.hasTrustedHash) {
|
|
589
|
+
notes.push("trusted_hash is recorded but Flair cannot verify it matches the current definition");
|
|
590
|
+
}
|
|
591
|
+
else if (runtime.hooksEnabled !== false) {
|
|
592
|
+
notes.push("Codex hook trust unread or untrusted — re-approval in /hooks required");
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
if (deliveryProbe && command) {
|
|
596
|
+
if (!isFlairHookCommand(command) || !correctShape) {
|
|
597
|
+
return {
|
|
598
|
+
delivery: "unverified",
|
|
599
|
+
deliveryReasons: [
|
|
600
|
+
...blockers,
|
|
601
|
+
"delivery not probed — command is not the Flair installer shape",
|
|
602
|
+
...notes,
|
|
603
|
+
],
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
const verdict = classifyHookDelivery(deliveryProbe(command));
|
|
607
|
+
if (verdict.delivered && blockers.length === 0) {
|
|
608
|
+
return { delivery: "verified", deliveryReasons: [verdict.reason, ...notes] };
|
|
609
|
+
}
|
|
610
|
+
return { delivery: "unverified", deliveryReasons: [...blockers, verdict.reason, ...notes] };
|
|
611
|
+
}
|
|
612
|
+
return {
|
|
613
|
+
delivery: "unverified",
|
|
614
|
+
deliveryReasons: [
|
|
615
|
+
...blockers,
|
|
616
|
+
"delivery not verified — no SessionStart additionalContext observed",
|
|
617
|
+
...notes,
|
|
618
|
+
],
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
/** On-failure line for `flair hook status`. Codex keeps stderr visible. */
|
|
622
|
+
export function hookStatusFailureLine(status) {
|
|
623
|
+
if (status.stderrDiscarded)
|
|
624
|
+
return "silent (exit 0, no output)";
|
|
625
|
+
if (status.silenced)
|
|
626
|
+
return "session continues (exit 0); stderr is visible";
|
|
627
|
+
return "prints an error on every session";
|
|
628
|
+
}
|
|
484
629
|
/** Read-only report: is the hook wired, does it look right, and which agent
|
|
485
630
|
* / Flair instance does it point at (recovered from the wired command). */
|
|
486
|
-
export function hookStatus(homeDir, harness) {
|
|
631
|
+
export function hookStatus(homeDir, harness, opts = {}) {
|
|
487
632
|
const path = hookSettingsPath(homeDir, harness);
|
|
488
633
|
const read = readSettingsFile(path);
|
|
489
634
|
if (read.parseError) {
|
|
490
|
-
return {
|
|
635
|
+
return {
|
|
636
|
+
harness, path, wired: false, correctShape: false, silenced: false, stderrDiscarded: false,
|
|
637
|
+
parseError: read.parseError, delivery: "absent", deliveryReasons: [],
|
|
638
|
+
};
|
|
491
639
|
}
|
|
492
640
|
const config = read.parsed ?? {};
|
|
493
641
|
const existing = findHookEntry(config);
|
|
494
642
|
if (!existing) {
|
|
495
|
-
return {
|
|
643
|
+
return {
|
|
644
|
+
harness, path, wired: false, correctShape: false, silenced: false, stderrDiscarded: false,
|
|
645
|
+
parseError: null, delivery: "absent", deliveryReasons: [],
|
|
646
|
+
};
|
|
496
647
|
}
|
|
497
648
|
const hookEntry = config.hooks.SessionStart[existing.groupIndex].hooks[existing.hookIndex];
|
|
498
649
|
const command = typeof hookEntry?.command === "string" ? hookEntry.command : "";
|
|
499
650
|
const correctShape = hookEntry?.type === "command" && isSessionStartHookInvocation(command);
|
|
500
651
|
const env = parseHookCommandEnv(command);
|
|
652
|
+
const assessed = assessDelivery(homeDir, harness, true, env.agentId, correctShape, command, opts.deliveryProbe);
|
|
501
653
|
return {
|
|
502
654
|
harness, path, wired: true, correctShape,
|
|
503
655
|
silenced: hookCommandIsSilenced(command),
|
|
656
|
+
stderrDiscarded: hookCommandDiscardsStderr(command),
|
|
504
657
|
agentId: env.agentId, flairUrl: env.flairUrl, command, parseError: null,
|
|
658
|
+
delivery: assessed.delivery, deliveryReasons: assessed.deliveryReasons,
|
|
505
659
|
};
|
|
506
660
|
}
|
|
507
661
|
// ── continuity capture hooks (flair#1257 slice 2) ──────────────────────────
|
package/dist/lib/doctor-run.js
CHANGED
|
@@ -19,12 +19,14 @@
|
|
|
19
19
|
* Skip (N/A) is not unrun. Linux has no launchd; a machine without Codex
|
|
20
20
|
* does not owe a Codex hook. Those checks execute and return `skip`.
|
|
21
21
|
*/
|
|
22
|
-
import { existsSync, readdirSync } from "node:fs";
|
|
22
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
23
|
+
import { join } from "node:path";
|
|
23
24
|
import { checkClaudeMdBootstrap, checkSessionStartHook, effectiveFlairUrl, hookCommandIsSilenced, isFlairHookCommand, partitionKeyIds, planAgentIterations, readClientMcpBlock, } from "../doctor-client.js";
|
|
24
25
|
import { hookInstallHint, hookSettingsPath, installHook, SUPPORTED_HARNESSES, } from "../hook-install.js";
|
|
25
|
-
import { staleHookRemedy, staleMcpClientPins, staleSessionStartHookPins } from "./owned-pins.js";
|
|
26
|
+
import { findUnsafeWiredPins, staleHookRemedy, staleMcpClientPins, staleSessionStartHookPins } from "./owned-pins.js";
|
|
26
27
|
import { flairCliVersion, isResolvedVersion } from "./mcp-spec.js";
|
|
27
|
-
import {
|
|
28
|
+
import { unsafeAdapterPinDetail } from "./stale-client-pin.js";
|
|
29
|
+
import { isDetached, plistCarriesInlineAdminPassword, renderDetachedWarning, } from "./launchd-management.js";
|
|
28
30
|
/**
|
|
29
31
|
* The catalog. This is the contract upgrade asserts against.
|
|
30
32
|
*
|
|
@@ -75,6 +77,19 @@ function runMcpBlock(ctx) {
|
|
|
75
77
|
// flair#1485 / Bugbot: a failed MCP pin refresh used to print nothing and
|
|
76
78
|
// leave the old @tpsdev-ai/flair-mcp pin in place. Presence is not
|
|
77
79
|
// currency — the same catalogue upgrade refreshes must fail here too.
|
|
80
|
+
// flair#1383: read the pins that are actually installed — flair-mcp
|
|
81
|
+
// and flair-client — in wired host configs and cwd package.json.
|
|
82
|
+
// Independent of "pin !== CLI version": a current MCP pin next to
|
|
83
|
+
// flair-client@0.17.0 still silently drops writes.
|
|
84
|
+
const unsafeWired = findUnsafeWiredPins(ctx.homeDir, ctx.cwd).filter((p) => p.source === "package.json"
|
|
85
|
+
|| (p.source === "mcp-client" && wired.includes(p.id)));
|
|
86
|
+
if (unsafeWired.length > 0) {
|
|
87
|
+
const first = unsafeWired[0];
|
|
88
|
+
return result(id, label, "fail", {
|
|
89
|
+
detail: unsafeAdapterPinDetail(first.surface, first.id, first.version, first.package),
|
|
90
|
+
remedy: "flair upgrade",
|
|
91
|
+
});
|
|
92
|
+
}
|
|
78
93
|
const expected = flairCliVersion();
|
|
79
94
|
if (isResolvedVersion(expected)) {
|
|
80
95
|
const stale = staleMcpClientPins(ctx.homeDir, expected)
|
|
@@ -180,6 +195,14 @@ function runSessionStartHook(ctx) {
|
|
|
180
195
|
// session. Compare against flairCliVersion() — not the MCP client pin —
|
|
181
196
|
// so two equally-stale pins cannot hide each other. Same owned-pin
|
|
182
197
|
// catalogue `flair upgrade` refreshes.
|
|
198
|
+
const unsafeHook = findUnsafeWiredPins(ctx.homeDir).filter((p) => p.source === "session-start-hook" && harnesses.includes(p.id));
|
|
199
|
+
if (unsafeHook.length > 0) {
|
|
200
|
+
const first = unsafeHook[0];
|
|
201
|
+
return result(id, label, "fail", {
|
|
202
|
+
detail: unsafeAdapterPinDetail(first.surface, first.id, first.version, first.package),
|
|
203
|
+
remedy: "flair upgrade",
|
|
204
|
+
});
|
|
205
|
+
}
|
|
183
206
|
const expected = flairCliVersion();
|
|
184
207
|
if (isResolvedVersion(expected)) {
|
|
185
208
|
const stale = staleSessionStartHookPins(ctx.homeDir, expected)
|
|
@@ -245,6 +268,29 @@ function runLaunchdManagement(ctx) {
|
|
|
245
268
|
if (m.state === "not-applicable" || m.state === "no-service") {
|
|
246
269
|
return result(id, label, "skip", { detail: m.detail, launchd: m });
|
|
247
270
|
}
|
|
271
|
+
// flair#1693: a registered plist that carries the admin password INLINE is a
|
|
272
|
+
// downgrade from the flair#1573 pass-file shape — the secret lives in a
|
|
273
|
+
// world-readable config file. The running job may be unaffected (launchd
|
|
274
|
+
// keeps the loaded definition), so `state === "managed"` is exactly the
|
|
275
|
+
// masked condition here: report the plist shape as a failure, not a pass.
|
|
276
|
+
if (m.label) {
|
|
277
|
+
const plistPath = join(ctx.homeDir, "Library", "LaunchAgents", `${m.label}.plist`);
|
|
278
|
+
try {
|
|
279
|
+
const raw = readFileSync(plistPath, "utf-8");
|
|
280
|
+
if (plistCarriesInlineAdminPassword(raw)) {
|
|
281
|
+
return result(id, label, "fail", {
|
|
282
|
+
detail: `the launchd plist ${plistPath} embeds HDB_ADMIN_PASSWORD inline instead of using the ` +
|
|
283
|
+
"pass-file launcher, so the admin password is stored in a config file",
|
|
284
|
+
remedy: "flair doctor --fix",
|
|
285
|
+
launchd: m,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
// Plist unreadable — the management verdict above already covers a
|
|
291
|
+
// plist that should exist; this check adds no failure of its own.
|
|
292
|
+
}
|
|
293
|
+
}
|
|
248
294
|
return result(id, label, "pass", { detail: m.detail, launchd: m });
|
|
249
295
|
}
|
|
250
296
|
/** Default implementations. An id in DOCTOR_CHECK_IDS missing from this
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* embed-gpu-doctor.ts — the flair doctor line for a failed Metal offload
|
|
3
|
+
* (flair#1437 PLAN ACCEPTED condition 1).
|
|
4
|
+
*
|
|
5
|
+
* /Health already carries `embedding.fallback` when offload was requested
|
|
6
|
+
* and Metal did not engage. Operators read `flair doctor`, not Health.
|
|
7
|
+
* This is the single decision: given the public Health embedding field,
|
|
8
|
+
* what (if anything) doctor prints. Harper-free; unit-tested.
|
|
9
|
+
*/
|
|
10
|
+
export const EMBED_GPU_DOCTOR_MARKER = "requested GPU offload; Metal did not engage";
|
|
11
|
+
/**
|
|
12
|
+
* Fail-loud doctor finding, or null when there is nothing to say.
|
|
13
|
+
* Only the Health `fallback` sentence is a finding — a stated CPU default
|
|
14
|
+
* or a confirmed Metal run is not an issue.
|
|
15
|
+
*/
|
|
16
|
+
export function describeEmbedGpuDoctorFinding(embedding) {
|
|
17
|
+
if (embedding == null || typeof embedding !== "object" || Array.isArray(embedding)) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const fallback = embedding.fallback;
|
|
21
|
+
if (typeof fallback !== "string" || !fallback.includes(EMBED_GPU_DOCTOR_MARKER)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
isIssue: true,
|
|
26
|
+
icon: "error",
|
|
27
|
+
message: fallback,
|
|
28
|
+
fixHint: "Pin CPU with FLAIR_EMBED_GPU_LAYERS=0, or restore @node-llama-cpp/mac-arm64-metal and flair restart.",
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spoke pair local-identity denial (flair#820).
|
|
3
|
+
*
|
|
4
|
+
* `flair federation pair` starts with a signed GET of /FederationInstance
|
|
5
|
+
* (CLI tooling — peers never call this path during the handshake). That
|
|
6
|
+
* resource is allowAdmin. When the invoking agent is not a runtime admin,
|
|
7
|
+
* Harper returns a raw `error:AccessViolation` JSON body and pair printed
|
|
8
|
+
* it unchanged — operators read a HUB auth failure and spent hours on
|
|
9
|
+
* hub theories. The failing call is LOCAL.
|
|
10
|
+
*
|
|
11
|
+
* Named error + operator sentence live here so the contract can be
|
|
12
|
+
* unit-tested without driving process.exit. Pair wraps only the identity
|
|
13
|
+
* GET; later failures (token, hub POST, local Peer write) keep their
|
|
14
|
+
* own messages unless the body is specifically a missing pairing role.
|
|
15
|
+
*/
|
|
16
|
+
export const FEDERATION_INSTANCE_PATH = "/FederationInstance";
|
|
17
|
+
export const FEDERATION_PAIR_LOCAL_ACCESS_ERROR_NAME = "FederationPairLocalAccessError";
|
|
18
|
+
export const FEDERATION_PAIR_HUB_ACCESS_ERROR_NAME = "FederationPairHubAccessError";
|
|
19
|
+
export const PAIR_INITIATOR_ROLE = "flair_pair_initiator";
|
|
20
|
+
export const PAIR_INITIATOR_FIX_COMMAND = "flair init --remote";
|
|
21
|
+
export const ADMIN_AGENTS_ENV = "FLAIR_ADMIN_AGENTS";
|
|
22
|
+
/** Real admin-grant surface: upserts `role: "admin"` + `admin: true`. */
|
|
23
|
+
export const PRINCIPAL_ADD_ADMIN_COMMAND = "flair principal add";
|
|
24
|
+
export class FederationPairLocalAccessError extends Error {
|
|
25
|
+
status = 403;
|
|
26
|
+
side;
|
|
27
|
+
path = FEDERATION_INSTANCE_PATH;
|
|
28
|
+
constructor(message, side = "LOCAL") {
|
|
29
|
+
super(message);
|
|
30
|
+
this.name = FEDERATION_PAIR_LOCAL_ACCESS_ERROR_NAME;
|
|
31
|
+
this.side = side;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export class FederationPairHubAccessError extends Error {
|
|
35
|
+
status;
|
|
36
|
+
side = "HUB";
|
|
37
|
+
constructor(message, status = 403) {
|
|
38
|
+
super(message);
|
|
39
|
+
this.name = FEDERATION_PAIR_HUB_ACCESS_ERROR_NAME;
|
|
40
|
+
this.status = status;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function errorText(err) {
|
|
44
|
+
if (err instanceof Error)
|
|
45
|
+
return err.message;
|
|
46
|
+
if (typeof err === "object" && err && "message" in err) {
|
|
47
|
+
return String(err.message ?? err);
|
|
48
|
+
}
|
|
49
|
+
return String(err);
|
|
50
|
+
}
|
|
51
|
+
function isNoCredentialsDenial(err) {
|
|
52
|
+
if (typeof err === "object" && err && "noCredentials" in err) {
|
|
53
|
+
return err.noCredentials === true;
|
|
54
|
+
}
|
|
55
|
+
return /no credentials sent/i.test(errorText(err));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* True only for Harper's AccessViolation body (missing admin on an
|
|
59
|
+
* authenticated call). Bare 403, no-credentials, and rejected-password
|
|
60
|
+
* bodies stay out so their honest text is not replaced.
|
|
61
|
+
*/
|
|
62
|
+
export function isFederationInstanceAccessViolation(err) {
|
|
63
|
+
if (!err || isNoCredentialsDenial(err))
|
|
64
|
+
return false;
|
|
65
|
+
return /AccessViolation/i.test(errorText(err));
|
|
66
|
+
}
|
|
67
|
+
export function principalAddAdminInvocation(agentId) {
|
|
68
|
+
return `${PRINCIPAL_ADD_ADMIN_COMMAND} ${agentId} --admin`;
|
|
69
|
+
}
|
|
70
|
+
export function describeFederationPairLocalAccessError(opts) {
|
|
71
|
+
const side = opts.side ?? "LOCAL";
|
|
72
|
+
const base = opts.url.replace(/\/$/, "");
|
|
73
|
+
const agent = opts.agentId?.trim() ?? "";
|
|
74
|
+
const identity = `pair: cannot read ${side} instance identity ` +
|
|
75
|
+
`(GET ${base}${FEDERATION_INSTANCE_PATH} → 403 AccessViolation). `;
|
|
76
|
+
const hubRole = `Hub pairing role: if pairing later fails because the hub is missing ` +
|
|
77
|
+
`${PAIR_INITIATOR_ROLE}, restore it with \`${PAIR_INITIATOR_FIX_COMMAND}\`.`;
|
|
78
|
+
if (!agent) {
|
|
79
|
+
return (identity +
|
|
80
|
+
`Missing role/grant: the calling agent is not a runtime admin ` +
|
|
81
|
+
`(${FEDERATION_INSTANCE_PATH} is allowAdmin). ` +
|
|
82
|
+
`Fix: add the agent to ${ADMIN_AGENTS_ENV} in the SERVER process env ` +
|
|
83
|
+
`(not just .env). Set FLAIR_AGENT_ID so the grant can name the principal. ` +
|
|
84
|
+
hubRole);
|
|
85
|
+
}
|
|
86
|
+
return (identity +
|
|
87
|
+
`Missing role/grant: agent '${agent}' is not a runtime admin ` +
|
|
88
|
+
`(${FEDERATION_INSTANCE_PATH} is allowAdmin). ` +
|
|
89
|
+
`Fix: add '${agent}' to ${ADMIN_AGENTS_ENV} in the SERVER process env ` +
|
|
90
|
+
`(not just .env), or grant the admin role with \`${principalAddAdminInvocation(agent)}\`. ` +
|
|
91
|
+
hubRole);
|
|
92
|
+
}
|
|
93
|
+
export function rewriteFederationPairLocalAccessError(err, opts) {
|
|
94
|
+
if (!isFederationInstanceAccessViolation(err))
|
|
95
|
+
return err;
|
|
96
|
+
return new FederationPairLocalAccessError(describeFederationPairLocalAccessError(opts), opts.side ?? "LOCAL");
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Hub POST /FederationPair is a pairing-role problem only when the body
|
|
100
|
+
* names `flair_pair_initiator` or a role-not-found. A bare 403 (proxy,
|
|
101
|
+
* wrong host, rejected bootstrap password) keeps its own text.
|
|
102
|
+
*/
|
|
103
|
+
export function isFederationPairHubAccessDenial(_status, body) {
|
|
104
|
+
return /role[- ]?not[- ]?found|flair_pair_initiator/i.test(body);
|
|
105
|
+
}
|
|
106
|
+
export function describeFederationPairHubAccessError(opts) {
|
|
107
|
+
const hub = opts.hubUrl.replace(/\/$/, "");
|
|
108
|
+
return (`pair: HUB rejected the pairing request ` +
|
|
109
|
+
`(POST ${hub}/FederationPair → ${opts.status}). ` +
|
|
110
|
+
`Missing role/grant: the hub may lack ${PAIR_INITIATOR_ROLE}. ` +
|
|
111
|
+
`Fix: re-run \`${PAIR_INITIATOR_FIX_COMMAND}\` on the hub to restore ` +
|
|
112
|
+
`the pairing role, mint a new token, then retry.`);
|
|
113
|
+
}
|
|
114
|
+
export function rewriteFederationPairHubAccessError(status, hubUrl, body) {
|
|
115
|
+
if (!isFederationPairHubAccessDenial(status, body))
|
|
116
|
+
return null;
|
|
117
|
+
return new FederationPairHubAccessError(describeFederationPairHubAccessError({ hubUrl, status }), status);
|
|
118
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* harper-port-value.ts — the ONE parser for a Harper port config value, shared
|
|
3
|
+
* by the CLI (`src/`) and the runtime resources (`resources/`).
|
|
4
|
+
*
|
|
5
|
+
* Moved out of `src/cli.ts` (where it lived as `harperPortValue`), not
|
|
6
|
+
* rewritten: every consumer that interpolates a port into a URL parses it here.
|
|
7
|
+
* A second, hand-rolled parser is the same defect as a second detector — two
|
|
8
|
+
* implementations that can drift, with the drift only visible on the value one
|
|
9
|
+
* of them mishandles.
|
|
10
|
+
*
|
|
11
|
+
* Harper accepts both a bare port (`9926`, all interfaces) and the
|
|
12
|
+
* host-qualified `host:port` form flair writes for the ops API
|
|
13
|
+
* (`127.0.0.1:9925` — see `opsNetworkPortValue`). Both name the same port; only
|
|
14
|
+
* the bind differs, and `detectOpsApiAllInterfacesBind` (lib/ops-api-bind.ts) is
|
|
15
|
+
* what reads the host half. Splits on the LAST colon so an IPv6 literal
|
|
16
|
+
* (`[::1]:9925`) keeps its port.
|
|
17
|
+
*
|
|
18
|
+
* What it checks: ONLY the digits after the last colon. The host half is NOT
|
|
19
|
+
* validated — any host text is accepted and ignored, so a qualified value means
|
|
20
|
+
* "the port is whatever trails the final colon". A value with no colon, an
|
|
21
|
+
* empty string, or a non-numeric tail yields null.
|
|
22
|
+
*
|
|
23
|
+
* Range: a port outside 1..65535 yields null so the caller falls back to its
|
|
24
|
+
* default. `new URL()` rejects a port above 65535, so returning one would hand
|
|
25
|
+
* a URL builder a value that throws instead of a usable loopback URL.
|
|
26
|
+
*/
|
|
27
|
+
const MAX_TCP_PORT = 65535;
|
|
28
|
+
export function harperPortValue(value) {
|
|
29
|
+
if (value === undefined || value === null)
|
|
30
|
+
return null;
|
|
31
|
+
if (typeof value === "number") {
|
|
32
|
+
return Number.isInteger(value) && value > 0 && value <= MAX_TCP_PORT ? value : null;
|
|
33
|
+
}
|
|
34
|
+
const str = String(value).trim();
|
|
35
|
+
if (str === "")
|
|
36
|
+
return null;
|
|
37
|
+
const lastColon = str.lastIndexOf(":");
|
|
38
|
+
const portPart = lastColon > 0 ? str.slice(lastColon + 1) : str;
|
|
39
|
+
if (!/^\d+$/.test(portPart))
|
|
40
|
+
return null;
|
|
41
|
+
const n = Number(portPart);
|
|
42
|
+
return n > 0 && n <= MAX_TCP_PORT ? n : null;
|
|
43
|
+
}
|