@tpsdev-ai/flair 0.49.0 → 0.51.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +15 -4
  2. package/dist/bridges/runtime/roundtrip.js +91 -2
  3. package/dist/build-info.json +3 -3
  4. package/dist/cli.js +565 -171
  5. package/dist/deploy.js +20 -3
  6. package/dist/doctor-client.js +62 -34
  7. package/dist/federation/scheduler.js +24 -3
  8. package/dist/hook-install.js +45 -13
  9. package/dist/install/clients.js +28 -17
  10. package/dist/lib/doctor-run.js +481 -0
  11. package/dist/lib/launchd-management.js +7 -26
  12. package/dist/lib/scheduler-platform.js +132 -10
  13. package/dist/lib/scratch-owner.js +49 -0
  14. package/dist/rem/scheduler.js +23 -5
  15. package/dist/resources/Federation.js +42 -20
  16. package/dist/resources/MemoryBootstrap.js +8 -4
  17. package/dist/resources/RecordUsage.js +13 -6
  18. package/dist/resources/SemanticSearch.js +8 -1
  19. package/dist/resources/federation-classify.js +90 -0
  20. package/dist/resources/health.js +51 -7
  21. package/dist/resources/mcp-tools.js +10 -6
  22. package/dist/resources/search-readiness.js +123 -0
  23. package/dist/resources/semantic-retrieval-core.js +48 -21
  24. package/dist/resources/sort-comparators.js +45 -0
  25. package/dist/resources/usage-ids.js +63 -0
  26. package/dist/src/lib/scheduler-platform.js +132 -10
  27. package/dist/src/rem/scheduler.js +23 -5
  28. package/docs/auth.md +5 -0
  29. package/docs/deepseek-harness.md +1 -1
  30. package/docs/federation.md +11 -0
  31. package/docs/hosted-on-fabric.md +2 -0
  32. package/docs/integrations.md +53 -1
  33. package/docs/mcp-clients.md +67 -15
  34. package/docs/quickstart-fabric.md +1 -1
  35. package/docs/supply-chain-policy.md +1 -1
  36. package/docs/troubleshooting.md +25 -0
  37. package/docs/upgrade.md +17 -1
  38. package/package.json +3 -3
  39. package/schemas/federation.graphql +1 -1
package/dist/deploy.js CHANGED
@@ -631,9 +631,26 @@ export function publishedEntryNames(packageRoot) {
631
631
  }
632
632
  // `files` entries are npm patterns; the ones flair uses are plain top-level
633
633
  // names, optionally trailing-slashed ("dist/"). Normalise to the entry name.
634
- const names = declared
635
- .map((f) => String(f).replace(/^\.\//, "").replace(/\/+$/, ""))
636
- .filter((f) => f !== "" && !f.includes("*") && !f.startsWith("!"));
634
+ //
635
+ // Honourable iff the entry is a plain top-level name. A blacklist of `*` and
636
+ // `!` lets `?`, `[]`, `{}` (and anything else minimatch understands) through
637
+ // as a literal that matches no real file — the same silent drop this fix
638
+ // exists to prevent (Sherlock on #1398). Whitelist: there is no
639
+ // differently-malformed form that slips through.
640
+ const names = [];
641
+ for (const raw of declared) {
642
+ const f = String(raw).replace(/^\.\//, "").replace(/\/+$/, "");
643
+ // Empty after normalize (`""`, `./`, `/`) is a listed entry we cannot
644
+ // honour as a plain top-level name. Skipping it left hasDeclaredFiles
645
+ // true and shipped only the always-includes — the same silent omit
646
+ // (Bugbot on #1398).
647
+ if (f === "." || f === ".." || !/^[a-zA-Z0-9._-]+$/.test(f)) {
648
+ throw new Error(`Cannot honour files entry ${JSON.stringify(String(raw))}: the deploy payload filter supports plain ` +
649
+ `top-level entries only. Either simplify the entry, or extend publishedEntryNames() ` +
650
+ `to match npm pack semantics.`);
651
+ }
652
+ names.push(f);
653
+ }
637
654
  return new Set([...names, ...always]);
638
655
  }
639
656
  /**
@@ -23,7 +23,7 @@ import { spawnSync } from "node:child_process";
23
23
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
24
24
  import { dirname, join } from "node:path";
25
25
  import { ALL_CLIENTS, clientConfigPath, piSettingsPath, resolvePiExtensionPath, scanPiSettings, } from "./install/clients.js";
26
- import { FLAIR_MCP_PACKAGE } from "./lib/mcp-spec.js";
26
+ import { FLAIR_MCP_PACKAGE, mcpServerSpec } from "./lib/mcp-spec.js";
27
27
  // The exact substring `flair init` writes into CLAUDE.md (src/cli.ts, the
28
28
  // `init` action) and that the doctor check + fix both key off of.
29
29
  export const CLAUDE_MD_BOOTSTRAP_MARKER = "mcp__flair__bootstrap";
@@ -42,9 +42,10 @@ export const SESSION_START_HOOK_MARKER = "flair-session-start";
42
42
  //
43
43
  // WHY THE INVOCATION IS WRAPPED
44
44
  // -----------------------------
45
- // The hook runs `npx -y -p @tpsdev-ai/flair-mcp flair-session-start`: it resolves
46
- // a package binary through whatever Node runtime the user's shell happens to
47
- // expose. Under a Node version manager, globally installed packages are
45
+ // The hook runs `npx -y -p @tpsdev-ai/flair-mcp@<version> flair-session-start`
46
+ // (same mcpServerSpec() pin as `flair init`'s user-local MCP client configs
47
+ // flair#1143). It resolves a package binary through whatever Node runtime the
48
+ // user's shell happens to expose. Under a Node version manager, globally installed packages are
48
49
  // per-runtime-version, so a routine and entirely unrelated runtime upgrade
49
50
  // orphans that binary. The command then stops resolving and the harness
50
51
  // reports a hook error on EVERY session, indefinitely, in wording that names
@@ -64,7 +65,7 @@ export const SESSION_START_HOOK_MARKER = "flair-session-start";
64
65
  // spawns with `shell: true` and never consults $SHELL (verified against the
65
66
  // 2.1.220 bundle; the settings schema's claim that `"shell": "bash"` uses your
66
67
  // $SHELL is not what the code does on POSIX). So a bare POSIX fragment would
67
- // in fact be enough for the one harness we support today.
68
+ // in fact be enough for the JSON-command harnesses we support today.
68
69
  //
69
70
  // It is still wrapped, because this string is not private to that harness:
70
71
  // SUPPORTED_HARNESSES (src/hook-install.ts) is a registry meant to grow, and
@@ -118,9 +119,23 @@ export function buildSessionStartHookCommand(agentId, flairUrl) {
118
119
  throw new Error(`Flair URL '${flairUrl}' contains characters that cannot be safely written into a shell hook command (allowed: letters, digits, . _ : / -)`);
119
120
  }
120
121
  const env = flairUrl ? `FLAIR_AGENT_ID=${agentId} FLAIR_URL=${flairUrl}` : `FLAIR_AGENT_ID=${agentId}`;
121
- const invocation = `${env} npx -y -p @tpsdev-ai/flair-mcp ${SESSION_START_HOOK_MARKER}`;
122
+ // Same pin as user-local MCP client configs (mcpServerSpec / flair#907).
123
+ // Public plugin mcp.json stays unpinned (flair#1308) — that is a scraped
124
+ // listing, not a machine we just wired.
125
+ const invocation = `${env} npx -y -p ${mcpServerSpec()} ${SESSION_START_HOOK_MARKER}`;
122
126
  return `sh -c 'out=$(${invocation} 2>/dev/null) && printf %s "$out" || true'`;
123
127
  }
128
+ /**
129
+ * The `npx -y -p` invocation that runs `flair-session-start` — pinned
130
+ * (`@tpsdev-ai/flair-mcp@<ver>`) or the pre-#1143 unpinned form. Used by
131
+ * `flair hook status` so a freshly-pinned hook is not reported as
132
+ * hand-edited, and an older unpinned hook is not reported as broken.
133
+ * Rejects the pre-#1166 form (no `-p`), which runs the MCP shim.
134
+ */
135
+ export const SESSION_START_HOOK_INVOCATION_RE = /npx -y -p @tpsdev-ai\/flair-mcp(?:@[^\s"']+)? flair-session-start/;
136
+ export function isSessionStartHookInvocation(command) {
137
+ return typeof command === "string" && SESSION_START_HOOK_INVOCATION_RE.test(command);
138
+ }
124
139
  /**
125
140
  * Does this command absorb a failure instead of surfacing it? Checked as two
126
141
  * independent PROPERTIES (stderr discarded, non-zero exit absorbed) rather
@@ -249,8 +264,8 @@ function continuityEventReport(config, event) {
249
264
  * pure fs read, no probe. A missing or unparseable settings.json reads as
250
265
  * "absent" (not enabled), matching checkSessionStartHook's tolerance.
251
266
  */
252
- export function checkContinuityCaptureHooks(homeDir) {
253
- const path = join(homeDir, ".claude", "settings.json");
267
+ export function checkContinuityCaptureHooks(homeDir, settingsPath) {
268
+ const path = settingsPath ?? join(homeDir, ".claude", "settings.json");
254
269
  let config = {};
255
270
  const raw = readTextFile(path);
256
271
  if (raw && raw.trim()) {
@@ -728,12 +743,14 @@ export function fixClaudeMdBootstrap(cwd) {
728
743
  }
729
744
  }
730
745
  /**
731
- * Pass when ~/.claude/settings.json exists, parses as JSON, and ANY hook
746
+ * Pass when the harness settings file exists, parses as JSON, and ANY hook
732
747
  * command anywhere under hooks.SessionStart[*].hooks[*].command contains the
733
748
  * flair-session-start marker (see docs/mcp-clients.md for the exact shape).
749
+ * `settingsPath` defaults to ~/.claude/settings.json; pass the Codex
750
+ * `~/.codex/hooks.json` path (or any other hookSettingsPath) for that harness.
734
751
  */
735
- export function checkSessionStartHook(homeDir) {
736
- const path = join(homeDir, ".claude", "settings.json");
752
+ export function checkSessionStartHook(homeDir, settingsPath) {
753
+ const path = settingsPath ?? join(homeDir, ".claude", "settings.json");
737
754
  const raw = readTextFile(path);
738
755
  if (!raw || !raw.trim())
739
756
  return { present: false, path };
@@ -772,10 +789,9 @@ export function checkSessionStartHook(homeDir) {
772
789
  * command. Returns the version when the spec is written
773
790
  * `@tpsdev-ai/flair-mcp@<ver>`; null for a bare/unpinned spec.
774
791
  *
775
- * The SessionStart hook is deliberately unpinned (`npx -y -p
776
- * @tpsdev-ai/flair-mcp`, buildSessionStartHookCommand above), so a hook
777
- * establishes that flair-mcp is wired but never carries a version — the pin
778
- * comes from the client MCP config.
792
+ * SessionStart hooks written since flair#1143 carry the same pin as a
793
+ * client MCP config (`mcpServerSpec()`). A pre-#1143 unpinned hook still
794
+ * establishes that flair-mcp is wired but contributes no version.
779
795
  */
780
796
  export function extractFlairMcpPin(text) {
781
797
  if (typeof text !== "string")
@@ -800,27 +816,39 @@ export function detectWiredFlairMcp(homeDir) {
800
816
  pinnedVersion = pin;
801
817
  }
802
818
  };
803
- // 1. The SessionStart hook (claude-code). Establishes wiring; unpinned by design.
804
- const hook = checkSessionStartHook(homeDir);
805
- if (hook.present && isFlairHookCommand(hook.command ?? ""))
806
- note(hook.command);
807
- // 2. Every known client's MCP config — a wired flair block carries the spec.
819
+ // 1. Every known client's MCP config a wired flair block carries the spec.
820
+ // Scanned first so a client pin wins (see module note above).
808
821
  for (const client of ALL_CLIENTS) {
809
822
  const configPath = withHome(homeDir, () => clientConfigPath(client.id));
810
823
  note(readTextFile(configPath));
811
824
  }
825
+ // 2. SessionStart hooks (claude-code settings.json + Codex hooks.json).
826
+ // Establish wiring; may carry a pin, but NEVER override a client pin
827
+ // already taken above — `note()` only sets pinnedVersion when it is still
828
+ // unset, so THIS ORDERING IS THE PRECEDENCE RULE, not decoration. The
829
+ // Codex path is additive (flair#1148); it must not reorder these two steps.
830
+ // Paths match hookSettingsPath in src/hook-install.ts — listed here to
831
+ // avoid a cycle (hook-install already imports this module).
832
+ for (const hookPath of [
833
+ join(homeDir, ".claude", "settings.json"),
834
+ join(homeDir, ".codex", "hooks.json"),
835
+ ]) {
836
+ const hook = checkSessionStartHook(homeDir, hookPath);
837
+ if (hook.present && isFlairHookCommand(hook.command ?? ""))
838
+ note(hook.command);
839
+ }
812
840
  return { wired, pinnedVersion };
813
841
  }
814
842
  /**
815
- * Merge-safe insert of a Flair SessionStart hook group into
816
- * ~/.claude/settings.json — creates the file/array if absent, preserves any
817
- * other existing hooks/keys (read-parse-merge-write, mirroring wireJsonMcp's
818
- * merge safety in src/install/clients.ts; never a blind overwrite). Dedupes:
819
- * a no-op (ok:true) if a matching hook is already present, so it's safe to
820
- * call twice.
843
+ * Merge-safe insert of a Flair SessionStart hook group into the harness
844
+ * settings file (default ~/.claude/settings.json) — creates the file/array
845
+ * if absent, preserves any other existing hooks/keys (read-parse-merge-write,
846
+ * mirroring wireJsonMcp's merge safety in src/install/clients.ts; never a
847
+ * blind overwrite). Dedupes: a no-op (ok:true) if a matching hook is already
848
+ * present, so it's safe to call twice.
821
849
  */
822
- export function fixSessionStartHook(homeDir, agentId) {
823
- const path = join(homeDir, ".claude", "settings.json");
850
+ export function fixSessionStartHook(homeDir, agentId, settingsPath) {
851
+ const path = settingsPath ?? join(homeDir, ".claude", "settings.json");
824
852
  if (!agentId) {
825
853
  return {
826
854
  ok: false,
@@ -953,7 +981,7 @@ export function classifyHookProbe(outcome) {
953
981
  * (or null via `{ probe: false }`) to keep a caller hermetic.
954
982
  */
955
983
  export function inspectSessionStartHook(homeDir, opts = {}) {
956
- const found = checkSessionStartHook(homeDir);
984
+ const found = checkSessionStartHook(homeDir, opts.settingsPath);
957
985
  if (!found.present || !found.command) {
958
986
  return { path: found.path, present: false, ours: false, silenced: false, upgradable: false, execution: null };
959
987
  }
@@ -995,8 +1023,8 @@ export function classifyHookReadiness(report) {
995
1023
  * decision to un-wire ambient memory, and `flair hook uninstall` is the
996
1024
  * command for that when the user does decide.
997
1025
  */
998
- export function upgradeSessionStartHookCommand(homeDir) {
999
- const path = join(homeDir, ".claude", "settings.json");
1026
+ export function upgradeSessionStartHookCommand(homeDir, settingsPath) {
1027
+ const path = settingsPath ?? join(homeDir, ".claude", "settings.json");
1000
1028
  try {
1001
1029
  const raw = readTextFile(path);
1002
1030
  if (!raw || !raw.trim())
@@ -1089,8 +1117,8 @@ function sessionStartHookHint(agentId, path) {
1089
1117
  * after the hook is present (whether from a prior call or already there)
1090
1118
  * reports ok:true, applied:false — safe to call on every `flair init`.
1091
1119
  */
1092
- export function applyOrReportSessionStartHook(homeDir, agentId, skip) {
1093
- const existing = checkSessionStartHook(homeDir);
1120
+ export function applyOrReportSessionStartHook(homeDir, agentId, skip, settingsPath) {
1121
+ const existing = checkSessionStartHook(homeDir, settingsPath);
1094
1122
  if (existing.present) {
1095
1123
  return { applied: false, ok: true, message: `SessionStart hook already wired in ${existing.path}` };
1096
1124
  }
@@ -1098,7 +1126,7 @@ export function applyOrReportSessionStartHook(homeDir, agentId, skip) {
1098
1126
  if (skip) {
1099
1127
  return { applied: false, ok: false, message: "SessionStart hook skipped (--skip-hook)", hint };
1100
1128
  }
1101
- const fix = fixSessionStartHook(homeDir, agentId);
1129
+ const fix = fixSessionStartHook(homeDir, agentId, settingsPath ?? existing.path);
1102
1130
  return { applied: fix.ok, ok: fix.ok, message: fix.message, hint: fix.ok ? undefined : hint };
1103
1131
  }
1104
1132
  // ── check 5: per-agent iteration for verified-read sections (flair#722) ────
@@ -62,7 +62,7 @@ import { resolve, dirname } from "node:path";
62
62
  import { homedir } from "node:os";
63
63
  import { fileURLToPath } from "node:url";
64
64
  import { escapeXml } from "../lib/xml-escape.js";
65
- import { detectPlatform as detectPlatformFor, spawnReport, readTemplate, renderTemplateWith, writeFileWithDir, interpretActiveResult, describeLoadFailure as describeLoadFailureFor, describeExitCode, resolveNodeBin, verifyFirstRun, STATUS_CHECK_TIMEOUT_MS, } from "../lib/scheduler-platform.js";
65
+ import { detectPlatform as detectPlatformFor, spawnReport, readTemplate, renderTemplateWith, writeFileWithDir, interpretActiveResult, describeLoadFailure as describeLoadFailureFor, describeExitCode, resolveNodeBin, resolveFlairBin, formatFlairBinWarning, verifyFirstRun, probeUserLingerEnabled, STATUS_CHECK_TIMEOUT_MS, } from "../lib/scheduler-platform.js";
66
66
  export const LAUNCHD_LABEL = "dev.flair.federation.sync";
67
67
  export const SYSTEMD_TIMER_UNIT = "flair-federation-sync.timer";
68
68
  export const SYSTEMD_SERVICE_UNIT = "flair-federation-sync.service";
@@ -165,7 +165,8 @@ function launchdDomain() {
165
165
  */
166
166
  export function enableScheduler(opts) {
167
167
  const plat = detectPlatform(opts.platformOverride);
168
- const flairBin = opts.flairBin ?? process.argv[1] ?? "flair";
168
+ const resolvedFlair = resolveFlairBin(opts.flairBin);
169
+ const flairBin = resolvedFlair.path;
169
170
  const nodeBin = resolveNodeBin(opts.nodeBin);
170
171
  const shimPath = opts.shimPathOverride ?? SHIM_PATH_DEFAULT;
171
172
  const templateRoot = opts.templateRootOverride ?? defaultTemplateRoot();
@@ -221,6 +222,7 @@ export function enableScheduler(opts) {
221
222
  return {
222
223
  platform: plat, shimPath, schedulerPath: plistPath, intervalSeconds: opts.intervalSeconds,
223
224
  loadCommand, loadResult, firstRunVerified: firstRun?.verified === true, firstRun,
225
+ flairBin, flairBinCanonical: resolvedFlair.canonical, flairBinPublic: resolvedFlair.publicBin,
224
226
  };
225
227
  }
226
228
  // Linux: systemd user units.
@@ -249,6 +251,7 @@ export function enableScheduler(opts) {
249
251
  return {
250
252
  platform: plat, shimPath, schedulerPath: timerPath, intervalSeconds: opts.intervalSeconds,
251
253
  loadCommand, loadResult, firstRunVerified: firstRun?.verified === true, firstRun,
254
+ flairBin, flairBinCanonical: resolvedFlair.canonical, flairBinPublic: resolvedFlair.publicBin,
252
255
  };
253
256
  }
254
257
  /** Removes the scheduler entry. Peer records and sync history are untouched. */
@@ -485,6 +488,15 @@ export function assessDriver(input) {
485
488
  * asked for — a sync run through the service manager — has been observed to
486
489
  * happen once.
487
490
  */
491
+ function appendFlairBinWarning(lines, r) {
492
+ if (r.flairBinCanonical !== false || !r.flairBin)
493
+ return;
494
+ const warning = formatFlairBinWarning(r.flairBin, r.flairBinPublic ?? null, "flair federation sync enable");
495
+ if (warning.length === 0)
496
+ return;
497
+ lines.push("");
498
+ lines.push(...warning);
499
+ }
488
500
  export function formatEnableReport(r, input) {
489
501
  const activationFailed = !!r.loadResult && r.loadResult.code !== 0;
490
502
  const credLine = input.adminPassFile
@@ -504,11 +516,18 @@ export function formatEnableReport(r, input) {
504
516
  lines.push(` Activation: ${r.loadCommand.join(" ")} → code ${lr.code}`);
505
517
  if (lr.stderr)
506
518
  lines.push(` stderr: ${lr.stderr.trim()}`);
507
- const remedy = describeLoadFailureFor(r.platform, lr, "flair federation sync enable");
519
+ const lingerEnabled = input.lingerEnabled !== undefined
520
+ ? input.lingerEnabled
521
+ : (r.platform === "linux" ? (input.probeLinger ?? probeUserLingerEnabled)() : undefined);
522
+ const remedy = describeLoadFailureFor(r.platform, lr, "flair federation sync enable", {
523
+ lingerEnabled,
524
+ env: input.env,
525
+ });
508
526
  lines.push("");
509
527
  lines.push(remedy ? ` ${remedy}` : ` Re-run the activation command above manually to see the full diagnostic.`);
510
528
  lines.push("");
511
529
  lines.push(` Nothing is scheduled until activation succeeds. Check anytime with: flair federation sync status`);
530
+ appendFlairBinWarning(lines, r);
512
531
  return { lines, ok: false };
513
532
  }
514
533
  if (!r.firstRunVerified) {
@@ -561,6 +580,7 @@ export function formatEnableReport(r, input) {
561
580
  }
562
581
  lines.push("");
563
582
  lines.push(` Check anytime with: flair federation sync status`);
583
+ appendFlairBinWarning(lines, r);
564
584
  return { lines, ok: false };
565
585
  }
566
586
  const lines = [
@@ -579,6 +599,7 @@ export function formatEnableReport(r, input) {
579
599
  lines.push(`Confirm anytime with \`flair federation status\`,`);
580
600
  lines.push(`which reports whether anything is actually driving sync.`);
581
601
  lines.push(`Disable with \`flair federation sync disable\`.`);
602
+ appendFlairBinWarning(lines, r);
582
603
  return { lines, ok: true };
583
604
  }
584
605
  /** Formats the `flair federation sync status` report. */
@@ -54,12 +54,13 @@
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, } from "./doctor-client.js";
57
+ import { SESSION_START_HOOK_MARKER, buildSessionStartHookCommand, buildContinuityCaptureHookCommand, checkContinuityCaptureHooks, computeContinuityHookInstall, computeContinuityHookRemoval, hookCommandIsSilenced, isHookCommandValueSafe, isSessionStartHookInvocation, readClientMcpBlock, } from "./doctor-client.js";
58
58
  // ── harness registry ────────────────────────────────────────────────────────
59
- /** v1 supports exactly one harness. The flag/type exist so a second harness
60
- * is an additive registry entry, not a rewrite (Kern's #719 verdict: "a
61
- * switch statement... is fine until we have 3+ harnesses"). */
62
- export const SUPPORTED_HARNESSES = ["claude-code"];
59
+ /** SessionStart hook harnesses. A second harness is an additive registry
60
+ * entry, not a rewrite (Kern's #719 verdict: "a switch statement... is
61
+ * fine until we have 3+ harnesses"). Codex writes the same JSON hook
62
+ * schema Claude Code uses, into `~/.codex/hooks.json` (flair#1148). */
63
+ export const SUPPORTED_HARNESSES = ["claude-code", "codex"];
63
64
  export function isSupportedHarness(value) {
64
65
  return SUPPORTED_HARNESSES.includes(value);
65
66
  }
@@ -70,8 +71,37 @@ export function hookSettingsPath(homeDir, harness) {
70
71
  switch (harness) {
71
72
  case "claude-code":
72
73
  return join(homeDir, ".claude", "settings.json");
74
+ case "codex":
75
+ return join(homeDir, ".codex", "hooks.json");
73
76
  }
74
77
  }
78
+ /** Continuity capture (PostToolUse + Stop) is Claude Code only. The matcher
79
+ * is Claude tool names; writing it into another harness looks enabled and
80
+ * never journals (flair#1148 Bugbot). SessionStart stays per-harness. */
81
+ export function harnessSupportsContinuity(harness) {
82
+ return harness === "claude-code";
83
+ }
84
+ /** Status/doctor hint for `flair hook install`. Claude Code stays the bare
85
+ * default; every other harness is named so the hint cannot silently write
86
+ * the wrong file (flair#1148 Bugbot). */
87
+ export function hookInstallHint(harness, extraFlags = "") {
88
+ const parts = ["flair hook install"];
89
+ if (extraFlags)
90
+ parts.push(extraFlags);
91
+ if (harness !== "claude-code")
92
+ parts.push(`--harness ${harness}`);
93
+ return parts.join(" ");
94
+ }
95
+ /** Agent id for a hook install: flag, env, this harness's MCP block, then
96
+ * Claude Code's block as a last resort (same agent is often shared). */
97
+ export function resolveHookAgentId(opts, homeDir, harness) {
98
+ return (opts.agent ||
99
+ opts.agentId ||
100
+ process.env.FLAIR_AGENT_ID ||
101
+ readClientMcpBlock(harness, homeDir).agentId ||
102
+ (harness !== "claude-code" ? readClientMcpBlock("claude-code", homeDir).agentId : undefined) ||
103
+ undefined);
104
+ }
75
105
  /** Backup path convention: a single sibling `<path>.bak`, overwritten on
76
106
  * every mutating run — recovery insurance for the mutation that's about to
77
107
  * happen, not a version history. Exported so tests assert against the same
@@ -131,7 +161,7 @@ export const HOOK_STATUS_UNPARSED = "(unknown — could not parse command)";
131
161
  * Recovered values are shown. The installer-no-URL omit (flair#1325) is
132
162
  * allowed ONLY when agentId was parsed — that is the real `flair init`
133
163
  * shape (`FLAIR_AGENT_ID` set, `FLAIR_URL` omitted). correctShape alone
134
- * is not enough: it is an npx-substring check and a wired correct-shape
164
+ * is not enough: it is an npx-invocation check and a wired correct-shape
135
165
  * command with no env assignments must still show the unknown lines,
136
166
  * not a silent all-clear. */
137
167
  export function hookStatusIdentityLines(status) {
@@ -392,7 +422,7 @@ export function hookStatus(homeDir, harness) {
392
422
  }
393
423
  const hookEntry = config.hooks.SessionStart[existing.groupIndex].hooks[existing.hookIndex];
394
424
  const command = typeof hookEntry?.command === "string" ? hookEntry.command : "";
395
- const correctShape = hookEntry?.type === "command" && command.includes(`npx -y -p @tpsdev-ai/flair-mcp ${SESSION_START_HOOK_MARKER}`);
425
+ const correctShape = hookEntry?.type === "command" && isSessionStartHookInvocation(command);
396
426
  const env = parseHookCommandEnv(command);
397
427
  return {
398
428
  harness, path, wired: true, correctShape,
@@ -425,6 +455,13 @@ export function installContinuityHooks(opts) {
425
455
  const { homeDir, harness, agentId, flairUrl } = opts;
426
456
  const dryRun = !!opts.dryRun;
427
457
  const path = hookSettingsPath(homeDir, harness);
458
+ if (!harnessSupportsContinuity(harness)) {
459
+ return {
460
+ ok: false, path, harness, dryRun,
461
+ message: `continuity capture is Claude Code only — ${harness} has no PostToolUse/Stop matcher Flair can journal (SessionStart is still ${hookInstallHint(harness)})`,
462
+ backupPath: null, actions: null,
463
+ };
464
+ }
428
465
  for (const [label, value] of [["agent id", agentId], ["Flair URL", flairUrl]]) {
429
466
  if (!isHookCommandValueSafe(value)) {
430
467
  return {
@@ -542,10 +579,5 @@ export function uninstallContinuityHooks(opts) {
542
579
  /** Read-only continuity status for `flair hook status` — the same report
543
580
  * doctor's check consumes, resolved through the harness's settings path. */
544
581
  export function continuityHookStatus(homeDir, harness) {
545
- // hookSettingsPath and checkContinuityCaptureHooks both resolve
546
- // ~/.claude/settings.json from homeDir; asserting through the harness
547
- // registry keeps a future second harness from silently reading the wrong
548
- // file.
549
- void hookSettingsPath(homeDir, harness);
550
- return checkContinuityCaptureHooks(homeDir);
582
+ return checkContinuityCaptureHooks(homeDir, hookSettingsPath(homeDir, harness));
551
583
  }
@@ -5,7 +5,9 @@
5
5
  // @tpsdev-ai/flair-mcp); pi is a native-extension host (kind:
6
6
  // "native-extension" — wired via pi's own settings.json `packages` key,
7
7
  // flair#1342). Each client has:
8
- // - detection: `bin` on PATH, optionally widened by a declared detect() override
8
+ // - detection: `bin` on PATH OR the client's known config path exists
9
+ // (flair#1417 — GUI-only Cursor, PATH-quirky installs). A declared
10
+ // detect() override remains the exception (pi).
9
11
  // - wire(env): { ok: boolean; message: string }
10
12
  //
11
13
  // Wiring contract (FIX 4 — onboarding dogfood round 1):
@@ -89,12 +91,13 @@ function binInPath(name) {
89
91
  * elsewhere — the same defect already fixed for `flair upgrade`'s presence
90
92
  * probes (see "Upgrade presence probes" in src/cli.ts).
91
93
  *
92
- * Nothing is lost by dropping it: an `npm install -g` links the package's bin
93
- * into the prefix's bin directory, which is on PATH by construction (it is where
94
- * `npm` itself is found from). A client whose binary is NOT on PATH is a client
95
- * the user cannot launch, and wiring an MCP config for it is at best a no-op.
96
- * `flair init --client <name>` still wires a client explicitly, bypassing
97
- * detection entirely, so an exotic install is never locked out.
94
+ * Nothing is lost by dropping the npm-list fallback: an `npm install -g` links
95
+ * the package's bin into the prefix's bin directory, which is on PATH by
96
+ * construction. Detection still asks PATH first. A second signal is the
97
+ * client's known config path (detectClients, flair#1417): a GUI install whose
98
+ * shell command is opt-in (Cursor) is still present when its config file
99
+ * exists. `flair init --client <name>` still wires a client explicitly,
100
+ * bypassing detection entirely, so an exotic install is never locked out.
98
101
  */
99
102
  function detectBin(bin) {
100
103
  try {
@@ -560,10 +563,12 @@ function antigravityConfigPath() {
560
563
  return join(resolveHome(), ".gemini", "config", "mcp_config.json");
561
564
  }
562
565
  /**
563
- * Single dispatcher for "where does this client's MCP config live" — used by
566
+ * Single dispatcher for "where does this client's config live" — used by
564
567
  * `flair doctor`'s client-integration checks (flair#588) to read the config
565
- * without duplicating the per-client path logic that already lives here.
566
- * Additive only: does not change existing wire/detect behavior.
568
+ * without duplicating the per-client path logic that already lives here,
569
+ * and by detectClients() as the config-path presence signal (flair#1417).
570
+ * Every current ClientId has a path; a future id must extend this switch
571
+ * or stay binary-only via a `detect` override — do not invent a path.
567
572
  */
568
573
  export function clientConfigPath(id) {
569
574
  switch (id) {
@@ -758,17 +763,23 @@ export function renderWiringSummary(results, opts = {}) {
758
763
  return lines;
759
764
  }
760
765
  /**
761
- * Detect every known client. One rule (`bin` on PATH) applied uniformly — a
762
- * client added to ALL_CLIENTS is detected by declaring its executable, with no
763
- * per-client branch here to forget to extend. A client may widen that with a
764
- * declared `detect` override (still a pure fs check pi adds its settings
765
- * file as a second signal, flair#1342); the override lives on the registry
766
- * entry, so this function stays branch-free.
766
+ * Detect every known client. One rule applied uniformly: `bin` on PATH OR
767
+ * the client's known config path exists (flair#1417). A client added to
768
+ * ALL_CLIENTS is detected by declaring its executable; clientConfigPath()
769
+ * already names every current id, so the config-path fallback is not a
770
+ * per-client branch to forget. A declared `detect` override remains the
771
+ * exception (still a pure fs check — pi, flair#1342). Detection never
772
+ * spawns a subprocess (flair#946).
773
+ *
774
+ * A future client with no config path helper stays binary-only until it
775
+ * grows one here or a `detect` override — do not invent a path.
767
776
  */
768
777
  export function detectClients() {
769
778
  return ALL_CLIENTS.map((client) => ({
770
779
  ...client,
771
- detected: client.detect ? client.detect() : detectBin(client.bin),
780
+ detected: client.detect
781
+ ? client.detect()
782
+ : detectBin(client.bin) || existsSync(clientConfigPath(client.id)),
772
783
  }));
773
784
  }
774
785
  export function wireClaudeCode(env) {