@tpsdev-ai/flair 0.54.2 → 0.55.1
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 +86 -1
- 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 +62 -7
- package/dist/commands/upgrade.js +6 -0
- package/dist/doctor-client.js +118 -32
- package/dist/hook-install.js +170 -16
- package/dist/lib/doctor-run.js +49 -3
- package/dist/lib/embed-gpu-doctor.js +63 -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/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/lib/upgrade-plain-tree.js +293 -48
- 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/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/dist/src/lib/harper-port-value.js +43 -0
- package/docs/api-reference.md +35 -2
- package/docs/deployment.md +39 -6
- package/docs/federation.md +18 -7
- package/docs/mcp-clients.md +19 -6
- package/docs/releasing.md +79 -13
- package/docs/rem.md +1 -1
- package/docs/secrets-and-keys.md +1 -0
- package/docs/standalone-local.md +8 -5
- package/docs/troubleshooting.md +17 -0
- package/package.json +1 -1
package/dist/doctor-client.js
CHANGED
|
@@ -106,25 +106,35 @@ const HOOK_VALUE_SAFE_RE = /^[A-Za-z0-9._:/-]+$/;
|
|
|
106
106
|
export function isHookCommandValueSafe(value) {
|
|
107
107
|
return typeof value === "string" && HOOK_VALUE_SAFE_RE.test(value);
|
|
108
108
|
}
|
|
109
|
-
|
|
110
|
-
* Build the exact `command` string to register as a SessionStart hook.
|
|
111
|
-
* Throws (rather than emitting a quoted approximation) when a value cannot be
|
|
112
|
-
* represented safely — see HOOK_VALUE_SAFE_RE.
|
|
113
|
-
*/
|
|
114
|
-
export function buildSessionStartHookCommand(agentId, flairUrl) {
|
|
109
|
+
export function buildSessionStartHookCommand(agentId, flairUrl, opts) {
|
|
115
110
|
if (!isHookCommandValueSafe(agentId)) {
|
|
116
111
|
throw new Error(`agent id '${agentId}' contains characters that cannot be safely written into a shell hook command (allowed: letters, digits, . _ : / -)`);
|
|
117
112
|
}
|
|
118
113
|
if (flairUrl != null && flairUrl !== "" && !isHookCommandValueSafe(flairUrl)) {
|
|
119
114
|
throw new Error(`Flair URL '${flairUrl}' contains characters that cannot be safely written into a shell hook command (allowed: letters, digits, . _ : / -)`);
|
|
120
115
|
}
|
|
121
|
-
const
|
|
116
|
+
const harness = opts?.harness ?? "claude-code";
|
|
117
|
+
const envParts = harness === "codex" ? [`FLAIR_HOOK_HARNESS=${harness}`] : [];
|
|
118
|
+
envParts.push(`FLAIR_AGENT_ID=${agentId}`);
|
|
119
|
+
if (flairUrl)
|
|
120
|
+
envParts.push(`FLAIR_URL=${flairUrl}`);
|
|
121
|
+
const env = envParts.join(" ");
|
|
122
122
|
// Same pin as user-local MCP client configs (mcpServerSpec / flair#907).
|
|
123
123
|
// Public plugin mcp.json stays unpinned (flair#1308) — that is a scraped
|
|
124
124
|
// listing, not a machine we just wired.
|
|
125
125
|
const invocation = `${env} npx -y -p ${mcpServerSpec()} ${SESSION_START_HOOK_MARKER}`;
|
|
126
|
+
// Codex: keep `|| true` so a missing binary cannot brick session start
|
|
127
|
+
// (#1007) but do not swallow stderr — an auth_error must be visible (#1734).
|
|
128
|
+
if (harness === "codex") {
|
|
129
|
+
return `sh -c 'out=$(${invocation}) && printf %s "$out" || true'`;
|
|
130
|
+
}
|
|
126
131
|
return `sh -c 'out=$(${invocation} 2>/dev/null) && printf %s "$out" || true'`;
|
|
127
132
|
}
|
|
133
|
+
/** Infer harness from the settings path `flair hook install` / doctor write. */
|
|
134
|
+
export function hookHarnessFromSettingsPath(settingsPath) {
|
|
135
|
+
const normalized = settingsPath.replace(/\\/g, "/");
|
|
136
|
+
return normalized.includes("/.codex/hooks.json") ? "codex" : "claude-code";
|
|
137
|
+
}
|
|
128
138
|
/**
|
|
129
139
|
* The `npx -y -p` invocation that runs `flair-session-start` — pinned
|
|
130
140
|
* (`@tpsdev-ai/flair-mcp@<ver>`) or the pre-#1143 unpinned form. Used by
|
|
@@ -137,17 +147,20 @@ export function isSessionStartHookInvocation(command) {
|
|
|
137
147
|
return typeof command === "string" && SESSION_START_HOOK_INVOCATION_RE.test(command);
|
|
138
148
|
}
|
|
139
149
|
/**
|
|
140
|
-
* Does this command absorb a failure
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* command that genuinely achieves both is not nagged about.
|
|
150
|
+
* Does this command absorb a failure so the harness session still starts?
|
|
151
|
+
* flair#1734: "silenced" means `|| true` (won't brick the session), not
|
|
152
|
+
* "stderr discarded". Codex's installer keeps stderr visible on purpose.
|
|
144
153
|
*/
|
|
145
154
|
export function hookCommandIsSilenced(command) {
|
|
146
155
|
if (typeof command !== "string")
|
|
147
156
|
return false;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
157
|
+
return /\|\|\s*(?:true|:)(?:\s|'|$)/.test(command) || /;\s*(?:true|:)\s*'?\s*$/.test(command);
|
|
158
|
+
}
|
|
159
|
+
/** Does the command discard stderr? Codex's installer must not (flair#1734). */
|
|
160
|
+
export function hookCommandDiscardsStderr(command) {
|
|
161
|
+
if (typeof command !== "string")
|
|
162
|
+
return false;
|
|
163
|
+
return command.includes("2>/dev/null") || command.includes("2>&-");
|
|
151
164
|
}
|
|
152
165
|
/**
|
|
153
166
|
* The EXACT unwrapped shape Flair wrote before #1007. Recognising it precisely
|
|
@@ -775,14 +788,53 @@ export function checkSessionStartHook(homeDir, settingsPath) {
|
|
|
775
788
|
return { present: false, path };
|
|
776
789
|
}
|
|
777
790
|
}
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
791
|
+
const FLAIR_AT_SPEC_RE = /@tpsdev-ai\/(flair-mcp|flair-client)@([0-9A-Za-z][^\s"'\],]*)/g;
|
|
792
|
+
const FLAIR_JSON_DEP_RE = /"@tpsdev-ai\/(flair-mcp|flair-client)"\s*:\s*"([^"]+)"/g;
|
|
793
|
+
/** Strip npm range / workspace prefixes so `^0.17.0` compares as `0.17.0`. */
|
|
794
|
+
export function normalizeDeclaredPinVersion(raw) {
|
|
795
|
+
if (typeof raw !== "string")
|
|
796
|
+
return null;
|
|
797
|
+
let v = raw.trim();
|
|
798
|
+
if (!v)
|
|
799
|
+
return null;
|
|
800
|
+
v = v.replace(/^(workspace|npm):/, "");
|
|
801
|
+
v = v.replace(/^[\^~>=<\s]+/, "");
|
|
802
|
+
v = v.replace(/^v/, "");
|
|
803
|
+
// Require X.Y.Z so `latest` / tags / bare names are not pins.
|
|
804
|
+
const m = v.match(/^(\d+\.\d+\.\d+[^\s"'\],]*)/);
|
|
805
|
+
return m ? m[1] : null;
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Every `@tpsdev-ai/flair-mcp` / `@tpsdev-ai/flair-client` pin in a wiring
|
|
809
|
+
* string or package.json. Covers `pkg@<ver>` specs (MCP args, hook commands)
|
|
810
|
+
* and `"pkg": "<ver>"` dependency fields. Bare / unpinned / `latest` specs
|
|
811
|
+
* contribute nothing.
|
|
812
|
+
*
|
|
813
|
+
* flair#1383: doctor must read the actual installed pins, not infer age
|
|
814
|
+
* from "pin !== CLI version".
|
|
815
|
+
*/
|
|
816
|
+
export function extractFlairPackagePins(text) {
|
|
817
|
+
if (typeof text !== "string")
|
|
818
|
+
return [];
|
|
819
|
+
const out = [];
|
|
820
|
+
const seen = new Set();
|
|
821
|
+
const add = (pkg, rawVer) => {
|
|
822
|
+
const version = normalizeDeclaredPinVersion(rawVer);
|
|
823
|
+
if (!version)
|
|
824
|
+
return;
|
|
825
|
+
const name = pkg;
|
|
826
|
+
const key = `${name}@${version}`;
|
|
827
|
+
if (seen.has(key))
|
|
828
|
+
return;
|
|
829
|
+
seen.add(key);
|
|
830
|
+
out.push({ package: name, version });
|
|
831
|
+
};
|
|
832
|
+
for (const m of text.matchAll(FLAIR_AT_SPEC_RE))
|
|
833
|
+
add(m[1], m[2]);
|
|
834
|
+
for (const m of text.matchAll(FLAIR_JSON_DEP_RE))
|
|
835
|
+
add(m[1], m[2]);
|
|
836
|
+
return out;
|
|
837
|
+
}
|
|
786
838
|
/**
|
|
787
839
|
* Extract a pinned `@tpsdev-ai/flair-mcp` version from any wiring string — a
|
|
788
840
|
* client MCP `args` array, a Codex TOML args line, or a SessionStart hook
|
|
@@ -794,12 +846,7 @@ export function checkSessionStartHook(homeDir, settingsPath) {
|
|
|
794
846
|
* establishes that flair-mcp is wired but contributes no version.
|
|
795
847
|
*/
|
|
796
848
|
export function extractFlairMcpPin(text) {
|
|
797
|
-
|
|
798
|
-
return null;
|
|
799
|
-
// `@tpsdev-ai/flair-mcp@<version>`; the version token runs until the first
|
|
800
|
-
// character that can't appear in a spec embedded in JSON args / TOML.
|
|
801
|
-
const m = text.match(/@tpsdev-ai\/flair-mcp@([0-9A-Za-z][^\s"'\],]*)/);
|
|
802
|
-
return m ? m[1] : null;
|
|
849
|
+
return extractFlairPackagePins(text).find((p) => p.package === "flair-mcp")?.version ?? null;
|
|
803
850
|
}
|
|
804
851
|
export function detectWiredFlairMcp(homeDir) {
|
|
805
852
|
let wired = false;
|
|
@@ -914,7 +961,7 @@ export function fixSessionStartHook(homeDir, agentId, settingsPath) {
|
|
|
914
961
|
hooks: [
|
|
915
962
|
{
|
|
916
963
|
type: "command",
|
|
917
|
-
command: buildSessionStartHookCommand(agentId),
|
|
964
|
+
command: buildSessionStartHookCommand(agentId, undefined, { harness: hookHarnessFromSettingsPath(path) }),
|
|
918
965
|
},
|
|
919
966
|
],
|
|
920
967
|
});
|
|
@@ -969,6 +1016,43 @@ const defaultProbeRunner = (command, timeoutMs) => {
|
|
|
969
1016
|
spawnError: res.error && !timedOut ? res.error.message : null,
|
|
970
1017
|
};
|
|
971
1018
|
};
|
|
1019
|
+
/**
|
|
1020
|
+
* Delivery probe (flair#1734): run the registered command so we can classify
|
|
1021
|
+
* SessionStart additionalContext. Must NOT set FLAIR_HOOK_PROBE — that path
|
|
1022
|
+
* prints inert `{}` and would make every status look undelivered.
|
|
1023
|
+
*/
|
|
1024
|
+
export function probeSessionStartHookDelivery(command, opts = {}) {
|
|
1025
|
+
const timeoutMs = opts.timeoutMs ?? 8_000;
|
|
1026
|
+
const runner = opts.runner ?? ((cmd, ms) => {
|
|
1027
|
+
const res = spawnSync("/bin/sh", ["-c", cmd], {
|
|
1028
|
+
input: "{}",
|
|
1029
|
+
encoding: "utf-8",
|
|
1030
|
+
timeout: ms,
|
|
1031
|
+
env: {
|
|
1032
|
+
...process.env,
|
|
1033
|
+
FLAIR_HOOK_PROBE: "0",
|
|
1034
|
+
FLAIR_HOOK_DELIVERY_PROBE: "1",
|
|
1035
|
+
FLAIR_HOOK_TIMEOUT_MS: "4000",
|
|
1036
|
+
FLAIR_PRESENCE_TIMEOUT_MS: "1",
|
|
1037
|
+
},
|
|
1038
|
+
});
|
|
1039
|
+
const timedOut = res.signal === "SIGTERM" && res.status === null;
|
|
1040
|
+
return {
|
|
1041
|
+
exitCode: res.status,
|
|
1042
|
+
stdout: res.stdout ?? "",
|
|
1043
|
+
stderr: res.stderr ?? "",
|
|
1044
|
+
timedOut,
|
|
1045
|
+
spawnError: res.error && !timedOut ? res.error.message : null,
|
|
1046
|
+
};
|
|
1047
|
+
});
|
|
1048
|
+
try {
|
|
1049
|
+
return runner(command, timeoutMs);
|
|
1050
|
+
}
|
|
1051
|
+
catch (err) {
|
|
1052
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
1053
|
+
return { exitCode: null, stdout: "", stderr: "", timedOut: false, spawnError: reason };
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
972
1056
|
/**
|
|
973
1057
|
* Run a registered hook command once, bounded, with probe-mode env set.
|
|
974
1058
|
* Only ever called for commands isFlairHookCommand() recognises — doctor does
|
|
@@ -1090,7 +1174,9 @@ export function upgradeSessionStartHookCommand(homeDir, settingsPath) {
|
|
|
1090
1174
|
message: `the SessionStart hook in ${path} is not the command Flair wrote — leaving it untouched`,
|
|
1091
1175
|
};
|
|
1092
1176
|
}
|
|
1093
|
-
const next = buildSessionStartHookCommand(legacy.agentId, legacy.flairUrl
|
|
1177
|
+
const next = buildSessionStartHookCommand(legacy.agentId, legacy.flairUrl, {
|
|
1178
|
+
harness: hookHarnessFromSettingsPath(path),
|
|
1179
|
+
});
|
|
1094
1180
|
if (next === hook.command)
|
|
1095
1181
|
return { ok: true, path, changed: false, message: `SessionStart hook in ${path} is already current` };
|
|
1096
1182
|
hook.command = next;
|
|
@@ -1137,8 +1223,8 @@ function sessionStartHookHint(agentId, path) {
|
|
|
1137
1223
|
{
|
|
1138
1224
|
type: "command",
|
|
1139
1225
|
command: isHookCommandValueSafe(agentId)
|
|
1140
|
-
? buildSessionStartHookCommand(agentId)
|
|
1141
|
-
: buildSessionStartHookCommand("me"),
|
|
1226
|
+
? buildSessionStartHookCommand(agentId, undefined, { harness: hookHarnessFromSettingsPath(path) })
|
|
1227
|
+
: buildSessionStartHookCommand("me", undefined, { harness: hookHarnessFromSettingsPath(path) }),
|
|
1142
1228
|
},
|
|
1143
1229
|
],
|
|
1144
1230
|
},
|
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,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* embed-gpu-doctor.ts — the flair doctor line for an unconfirmed Metal offload
|
|
3
|
+
* (flair#1437 PLAN ACCEPTED condition 1; severity split added by flair#1761).
|
|
4
|
+
*
|
|
5
|
+
* /Health already carries `embedding.fallback` when offload was requested
|
|
6
|
+
* and the GPU log heuristic did not confirm Metal. Operators read
|
|
7
|
+
* `flair doctor`, not Health. This is the single decision: given the public
|
|
8
|
+
* Health embedding field, what (if anything) doctor prints, and whether it
|
|
9
|
+
* weighs on doctor's exit code.
|
|
10
|
+
*
|
|
11
|
+
* flair#1761: the finding is NOT one severity. The fallback sentence is a log
|
|
12
|
+
* heuristic, not an observation (it can err in both directions), and since
|
|
13
|
+
* 0.55.0 the derived Metal default requests offload on every darwin-arm64
|
|
14
|
+
* host without the operator asking. So the severity is read off `source`:
|
|
15
|
+
*
|
|
16
|
+
* source === "detected" → the default chose for the operator; advisory
|
|
17
|
+
* WARNING, does not count as an issue.
|
|
18
|
+
* source === "env" → the operator explicitly set
|
|
19
|
+
* FLAIR_EMBED_GPU_LAYERS; blocking ERROR.
|
|
20
|
+
* missing / unrecognized → FAIL CLOSED: blocking ERROR, exactly as before.
|
|
21
|
+
* An unknown state is never softened to advisory.
|
|
22
|
+
*/
|
|
23
|
+
export const EMBED_GPU_DOCTOR_MARKER = "requested GPU offload; Metal did not engage";
|
|
24
|
+
/** Advisory wording (flair#1761). We cannot observe engagement, only that it
|
|
25
|
+
* was NOT confirmed — the old "did not engage" over-claimed. */
|
|
26
|
+
export const EMBED_GPU_DETECTED_MESSAGE = "Automatic Metal acceleration was requested, but engagement could not be verified.";
|
|
27
|
+
/**
|
|
28
|
+
* Doctor finding, or null when there is nothing to say.
|
|
29
|
+
* Only the Health `fallback` sentence is a finding — a stated CPU default
|
|
30
|
+
* or a confirmed Metal run is not an issue. The severity depends on
|
|
31
|
+
* `source` (flair#1761): an operator-requested offload that was not
|
|
32
|
+
* confirmed still fails loud, but the derived Metal default is advisory and
|
|
33
|
+
* an unrecognized source fails closed.
|
|
34
|
+
*/
|
|
35
|
+
export function describeEmbedGpuDoctorFinding(embedding) {
|
|
36
|
+
if (embedding == null || typeof embedding !== "object" || Array.isArray(embedding)) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const fallback = embedding.fallback;
|
|
40
|
+
if (typeof fallback !== "string" || !fallback.includes(EMBED_GPU_DOCTOR_MARKER)) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const source = embedding.source;
|
|
44
|
+
if (source === "detected") {
|
|
45
|
+
// The Metal default requested offload for the operator; nothing was
|
|
46
|
+
// chosen. Working embeddings on CPU is a standing, benign condition —
|
|
47
|
+
// keep it visible as a persistent warning, never a blocking finding.
|
|
48
|
+
return {
|
|
49
|
+
isIssue: false,
|
|
50
|
+
icon: "warn",
|
|
51
|
+
message: EMBED_GPU_DETECTED_MESSAGE,
|
|
52
|
+
fixHint: "Pin CPU with FLAIR_EMBED_GPU_LAYERS=0.",
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// A source the operator set ("env"), or one we do not recognize at all
|
|
56
|
+
// (missing/unknown) — fail closed and keep the existing fail-loud finding.
|
|
57
|
+
return {
|
|
58
|
+
isIssue: true,
|
|
59
|
+
icon: "error",
|
|
60
|
+
message: fallback,
|
|
61
|
+
fixHint: "Pin CPU with FLAIR_EMBED_GPU_LAYERS=0, or restore @node-llama-cpp/mac-arm64-metal and flair restart.",
|
|
62
|
+
};
|
|
63
|
+
}
|