@tpsdev-ai/flair 0.55.1 → 0.56.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 (76) hide show
  1. package/README.md +3 -3
  2. package/dist/bridges/builtins/markdown.js +2 -2
  3. package/dist/bridges/discover.js +2 -2
  4. package/dist/bridges/runtime/allow-list.js +2 -2
  5. package/dist/build-info.json +3 -3
  6. package/dist/cli.js +201 -95
  7. package/dist/commands/attention.js +2 -2
  8. package/dist/commands/backup.js +2 -2
  9. package/dist/commands/doctor.js +168 -37
  10. package/dist/commands/export.js +2 -2
  11. package/dist/commands/federation.js +229 -95
  12. package/dist/commands/hook.js +4 -4
  13. package/dist/commands/init.js +94 -70
  14. package/dist/commands/mcp.js +2 -2
  15. package/dist/commands/migrate-harness-memory.js +8 -8
  16. package/dist/commands/rem.js +31 -4
  17. package/dist/commands/service.js +25 -1
  18. package/dist/commands/session.js +2 -2
  19. package/dist/commands/uninstall.js +2 -2
  20. package/dist/commands/upgrade.js +88 -69
  21. package/dist/doctor-client.js +341 -161
  22. package/dist/engine-version.js +2 -2
  23. package/dist/federation/scheduler.js +5 -5
  24. package/dist/hook-install.js +359 -176
  25. package/dist/install/clients.js +908 -214
  26. package/dist/keystore.js +10 -2
  27. package/dist/lib/auth-resolve.js +5 -5
  28. package/dist/lib/config-critical-section.js +557 -0
  29. package/dist/lib/doctor-config-path.js +2 -2
  30. package/dist/lib/doctor-run.js +107 -27
  31. package/dist/lib/flair-paths.js +29 -0
  32. package/dist/lib/home.js +60 -0
  33. package/dist/lib/launchd-repair.js +109 -0
  34. package/dist/lib/mcp-enable.js +4 -4
  35. package/dist/lib/owned-pins.js +256 -94
  36. package/dist/lib/pin-write-guard.js +87 -0
  37. package/dist/lib/settings-bytes.js +85 -0
  38. package/dist/lib/socket-path-limit.js +120 -0
  39. package/dist/lib/uninstall-purge.js +2 -18
  40. package/dist/lib/upgrade-plain-tree.js +2 -2
  41. package/dist/lib/upgrade-status.js +164 -0
  42. package/dist/lib/wiring-spec.js +238 -0
  43. package/dist/mcp-client-assertion.js +3 -3
  44. package/dist/rem/promote-policy.js +102 -0
  45. package/dist/rem/runner.js +3 -3
  46. package/dist/rem/scheduler.js +5 -5
  47. package/dist/rem/snapshot.js +2 -2
  48. package/dist/resources/MemoryReflect.js +10 -0
  49. package/dist/resources/OAuth.js +62 -11
  50. package/dist/resources/Presence.js +135 -47
  51. package/dist/resources/admin-layout.js +7 -2
  52. package/dist/resources/auto-promote-lib.js +56 -0
  53. package/dist/resources/health.js +26 -0
  54. package/dist/resources/memory-reflect-lib.js +215 -6
  55. package/dist/resources/migrations/progress.js +17 -0
  56. package/dist/resources/migrations/runner.js +46 -27
  57. package/dist/resources/migrations/status.js +2 -1
  58. package/dist/src/keystore.js +10 -2
  59. package/dist/src/lib/home.js +60 -0
  60. package/dist/src/rem/promote-policy.js +102 -0
  61. package/dist/src/rem/scheduler.js +5 -5
  62. package/dist/version-check.js +2 -2
  63. package/dist/version-handshake.js +2 -2
  64. package/docs/api-reference.md +31 -6
  65. package/docs/auth.md +14 -2
  66. package/docs/deploying-on-fabric.md +5 -4
  67. package/docs/deployment.md +26 -37
  68. package/docs/embedding-in-a-harper-app.md +4 -2
  69. package/docs/entity-vocabulary.md +5 -5
  70. package/docs/federation.md +58 -19
  71. package/docs/hosted-on-fabric.md +7 -5
  72. package/docs/mcp-clients.md +29 -12
  73. package/docs/releasing.md +66 -22
  74. package/docs/spoke-bringup.md +41 -22
  75. package/docs/standalone-local.md +12 -16
  76. package/package.json +3 -1
@@ -1,25 +1,25 @@
1
1
  import { COMPONENT_ENV_FILENAME, PUBLIC_URL_KEY, describePublicUrlFinding, readEnvValue } from "../component-env.js";
2
2
  import { checkClaudeMdBootstrap, checkContinuityCaptureHooks, describeAgentGateFinding, effectiveFlairUrl, embeddingsSkipRemedy, fixClaudeMdBootstrap, fixCommandAgentHint, fixContinuityCaptureHooks, fixSessionStartHook, inspectSessionStartHook, partitionKeyIds, planAgentIterations, readClientMcpBlock, resolveFixAgentId, resolveWireFlairUrl, upgradeSessionStartHookCommand } from "../doctor-client.js";
3
3
  import { markStale, sortOldestVersionFirst } from "../fleet-presence.js";
4
- import { hookSettingsPath, repinSessionStartHook, resolveHookAgentId } from "../hook-install.js";
5
- import { detectClients, wireAntigravity, wireClaudeCode, wireCodex, wireCursor, wireGemini } from "../install/clients.js";
4
+ import { hookSettingsPath, resolveHookAgentId } from "../hook-install.js";
5
+ import { ALL_CLIENTS, decideCodexPinOnly, decideJsonPinOnly, detectClients, wireAntigravity, wireClaudeCode, wireCodex, wireCursor, wireGemini } from "../install/clients.js";
6
6
  import { checkGlobalBinOnPath, resolveNpmGlobalPrefix } from "../install/global-bin-path.js";
7
7
  import { buildEd25519Auth, defaultAdminPassPath, defaultKeysDir, resolveAdminUser, resolveKeyPath, resolveLocalAdminPass } from "../lib/auth-resolve.js";
8
8
  import { flairConfigYamlCandidates, readPortFromYamlFile, resolveFlairConfigYaml } from "../lib/doctor-config-path.js";
9
9
  import { collectFederationEnv, describeFederationDriverFinding, federationPeersConfigured, loadYamlDoc } from "../lib/doctor-federation-driver.js";
10
10
  import { plistCarriesInlineAdminPassword } from "../lib/launchd-management.js";
11
- import { DOCTOR_CHECK_IDS, catalogIssueDelta, renderCatalogDoctorLines, runDoctorChecks } from "../lib/doctor-run.js";
11
+ import { DOCTOR_CHECK_IDS, catalogIssueDelta, mcpRepinIcon, renderCatalogDoctorLines, runDoctorChecks } from "../lib/doctor-run.js";
12
12
  import { describeEmbedGpuDoctorFinding } from "../lib/embed-gpu-doctor.js";
13
13
  import { adminPassDesyncFinding, detectPersistedAdminUser } from "../lib/init-admin-pass.js";
14
14
  import { opsApiBindFinding } from "../lib/ops-api-bind.js";
15
15
  import { flairCliVersion, unpinnedSpecWarning } from "../lib/mcp-spec.js";
16
- import { staleSessionStartHookPins } from "../lib/owned-pins.js";
16
+ import { mcpClientPinFindings, refreshOwnedPins, repinSessionStartHookGuarded, sessionStartHookPinFindings } from "../lib/owned-pins.js";
17
17
  import * as render from "../render.js";
18
18
  import { checkVersion, formatVersionNudge, probeInstanceVersion, FLAIR_PKG_NAME } from "../version-check.js";
19
19
  import { resolveRegistryNotice } from "../lib/npm-registry.js";
20
20
  import { existsSync, readFileSync, statSync } from "node:fs";
21
- import { homedir } from "node:os";
22
21
  import { dirname, join } from "node:path";
22
+ import { resolveHome } from "../lib/home.js";
23
23
  let cli;
24
24
  /** Bind the cli-locals this module depends on. */
25
25
  export function bindCli(fns) {
@@ -500,7 +500,7 @@ export function register(program) {
500
500
  // component dirs whose real config is ~/agents/flair/config.yaml.
501
501
  const configLookup = {
502
502
  cwd: process.cwd(),
503
- homeDir: homedir(),
503
+ homeDir: resolveHome(),
504
504
  componentDir: flairPackageDir(),
505
505
  };
506
506
  const cfgPath = resolveFlairConfigYaml(configLookup);
@@ -769,7 +769,7 @@ export function register(program) {
769
769
  }
770
770
  else {
771
771
  // Check ~/harper/ (common alternative)
772
- const altDir = join(homedir(), "harper");
772
+ const altDir = join(resolveHome(), "harper");
773
773
  if (existsSync(altDir)) {
774
774
  console.log(` ${render.icons.warn} Data at ${render.wrap(render.c.dim, "~/harper/")} (not ${render.wrap(render.c.dim, "~/.flair/data")}) — old install location`);
775
775
  }
@@ -815,7 +815,7 @@ export function register(program) {
815
815
  // drift (catalog "detached" fail + repair "regenerate"/"adopt"/"refuse").
816
816
  const doctorCatalogIds = DOCTOR_CHECK_IDS.filter((id) => id !== "launchd-management");
817
817
  const doctorCtx = {
818
- homeDir: homedir(),
818
+ homeDir: resolveHome(),
819
819
  cwd: process.cwd(),
820
820
  detectedClientIds: detectedClients.map((c) => c.id),
821
821
  keysDir,
@@ -823,7 +823,17 @@ export function register(program) {
823
823
  agentFlag: typeof opts.agent === "string" ? opts.agent : undefined,
824
824
  };
825
825
  const catalogBefore = runDoctorChecks(doctorCtx, { catalogIds: doctorCatalogIds });
826
- if (detectedClients.length === 0) {
826
+ // flair#1834 PR-H: a hook file on disk IS the wiring — the same rule the
827
+ // hook arms below apply. A SessionStart hook wired in ~/.claude/settings.json
828
+ // (or ~/.codex/hooks.json) is a Flair client integration even when the MCP
829
+ // server is configured PROJECT-scoped (a project's .mcp.json) rather than in
830
+ // ~/.claude.json — and even when the harness binary is not on this shell's
831
+ // PATH. Without this the whole section was skipped outright ("No MCP client
832
+ // detected") and a HOLD on that wired hook was silently missed. Presence-only
833
+ // here (probe:false); the arms below run the bounded execution probe.
834
+ const anyWiredSessionStartHook = inspectSessionStartHook(resolveHome(), { settingsPath: hookSettingsPath(resolveHome(), "claude-code"), probe: false }).present ||
835
+ inspectSessionStartHook(resolveHome(), { settingsPath: hookSettingsPath(resolveHome(), "codex"), probe: false }).present;
836
+ if (detectedClients.length === 0 && !anyWiredSessionStartHook) {
827
837
  console.log(` ${render.icons.info} No MCP client detected — skipping client-integration checks`);
828
838
  }
829
839
  else {
@@ -848,7 +858,7 @@ export function register(program) {
848
858
  // more. Doctor now diagnoses only MCP clients the user wired (below).
849
859
  if (client.kind !== "mcp")
850
860
  continue;
851
- const block = readClientMcpBlock(client.id, homedir());
861
+ const block = readClientMcpBlock(client.id, resolveHome());
852
862
  if (client.id === "claude-code" && block.agentId)
853
863
  claudeCodeAgentId = block.agentId;
854
864
  if (client.id === "codex" && block.agentId)
@@ -959,6 +969,69 @@ export function register(program) {
959
969
  console.log(` ${render.icons.warn} ${finding?.message ?? `could not verify agent registration (${reg.detail})`}`);
960
970
  }
961
971
  }
972
+ // flair#1779: `doctor --fix` re-pins a BEHIND MCP-client block the same
973
+ // way it re-pins a behind SessionStart hook. It routes through the ONE
974
+ // guarded writer the upgrade refresh uses (refreshOwnedPins), restricted
975
+ // to the behind wired clients and preserving each block's OWN agent id
976
+ // and FLAIR_URL. ahead/unknown are HELD (already a pass/warn), so only
977
+ // `behind` is written; the catalog delta below counts the fix.
978
+ if (autoFix) {
979
+ const behindMcp = mcpClientPinFindings(resolveHome(), flairCliVersion())
980
+ .filter((f) => f.direction === "behind")
981
+ // flair#1834 A1: key off STRUCTURAL presence (entryExists), not
982
+ // `present` (= agent id set). A behind entry without an identity is
983
+ // still a pin we own and re-pin — the pin-only writer preserves
984
+ // whatever identity the entry carries.
985
+ .filter((f) => f.reading.entryExists);
986
+ if (behindMcp.length > 0) {
987
+ if (dryRun) {
988
+ // flair#1834 A2: derive each dry-run line from the SAME
989
+ // classification the real run uses, so there is never a "Would
990
+ // re-pin" for a target the real run would HOLD or skip.
991
+ for (const f of behindMcp) {
992
+ const id = f.reading.target.id;
993
+ const label = ALL_CLIENTS.find((c) => c.id === id)?.label ?? id;
994
+ let dec;
995
+ try {
996
+ const raw = readFileSync(f.reading.target.path, "utf-8");
997
+ dec = id === "codex" ? decideCodexPinOnly(raw, label) : decideJsonPinOnly(raw, label, f.reading.target.path);
998
+ }
999
+ catch (err) {
1000
+ console.log(` ${render.icons.warn} ${label}: could not read ${f.reading.target.path} (${err instanceof Error ? err.message : String(err)}) — would not re-pin`);
1001
+ continue;
1002
+ }
1003
+ if (dec.result.kind === "repinned") {
1004
+ // flair#1834 A2 round 2: `oldPin` is already the full pinned spec
1005
+ // (`@tpsdev-ai/flair-mcp@<ver>`); do NOT re-prefix the package.
1006
+ // Match the real run's format: `(<oldPin> -> <newPin>)`.
1007
+ console.log(` ${render.wrap(render.c.dim, "Would re-pin the MCP server block in")} ${f.reading.target.path} (${dec.result.oldPin} -> ${dec.result.newPin})`);
1008
+ }
1009
+ else if (dec.result.kind === "hold") {
1010
+ // Match the real run's HOLD format, which names the client so a
1011
+ // multi-client dry-run says which hold is whose.
1012
+ console.log(` ${render.icons.warn} HOLD ${label}: ${dec.result.line ?? "refusing to rewrite this entry"}`);
1013
+ }
1014
+ else {
1015
+ console.log(` ${render.icons.warn} ${dec.result.line ?? `${label}: ${dec.result.kind} — would not re-pin`}`);
1016
+ }
1017
+ }
1018
+ }
1019
+ else {
1020
+ const overrides = behindMcp.map((f) => {
1021
+ const id = f.reading.target.id;
1022
+ return { kind: "mcp-client", id };
1023
+ });
1024
+ const results = refreshOwnedPins({ homeDir: resolveHome(), targets: overrides });
1025
+ for (const r of results) {
1026
+ if (r.target.kind !== "mcp-client")
1027
+ continue;
1028
+ // flair#1834 round 3: an attempted-but-skipped fix (e.g. a behind
1029
+ // Codex pin until A2 lands) is not a success — never ✓.
1030
+ console.log(` ${render.icons[mcpRepinIcon(r.action, r.ok)]} ${r.message}`);
1031
+ }
1032
+ }
1033
+ }
1034
+ }
962
1035
  // flair#989: the harness-specific checks below (CLAUDE.md, SessionStart
963
1036
  // hook, continuity, Codex hook) run only for a harness the user actually
964
1037
  // WIRED — its MCP block is present. A harness merely DETECTED on the box
@@ -966,8 +1039,8 @@ export function register(program) {
966
1039
  // positive this fix removes. Read the block fresh so a `--fix` that just
967
1040
  // wired the client during the loop above is reflected here.
968
1041
  const claudeCodeDetected = detectedClients.some((c) => c.id === "claude-code");
969
- const claudeCodeConfigured = claudeCodeDetected && readClientMcpBlock("claude-code", homedir()).present;
970
- const codexConfigured = detectedClients.some((c) => c.id === "codex") && readClientMcpBlock("codex", homedir()).present;
1042
+ const claudeCodeConfigured = claudeCodeDetected && readClientMcpBlock("claude-code", resolveHome()).present;
1043
+ const codexConfigured = detectedClients.some((c) => c.id === "codex") && readClientMcpBlock("codex", resolveHome()).present;
971
1044
  // Claude-Code-specific: CLAUDE.md + SessionStart hook + continuity.
972
1045
  // Codex has a SessionStart hook too (checked below); CLAUDE.md and
973
1046
  // continuity stay Claude Code only.
@@ -978,12 +1051,12 @@ export function register(program) {
978
1051
  // opt-in that renders "not enabled" as info and never a failure, so it
979
1052
  // stays gated on mere detection (flair#1324/#1257).
980
1053
  if (claudeCodeConfigured) {
981
- const claudeMd = checkClaudeMdBootstrap(process.cwd(), homedir());
1054
+ const claudeMd = checkClaudeMdBootstrap(process.cwd(), resolveHome());
982
1055
  if (claudeMd.present) {
983
1056
  console.log(` ${render.icons.ok} CLAUDE.md: bootstrap instruction present (${render.wrap(render.c.dim, claudeMd.path)})`);
984
1057
  }
985
1058
  else {
986
- console.log(` ${render.icons.error} CLAUDE.md: bootstrap instruction not found (checked ${render.wrap(render.c.dim, join(process.cwd(), "CLAUDE.md"))} and ${render.wrap(render.c.dim, join(homedir(), ".claude", "CLAUDE.md"))})`);
1059
+ console.log(` ${render.icons.error} CLAUDE.md: bootstrap instruction not found (checked ${render.wrap(render.c.dim, join(process.cwd(), "CLAUDE.md"))} and ${render.wrap(render.c.dim, join(resolveHome(), ".claude", "CLAUDE.md"))})`);
987
1060
  if (autoFix) {
988
1061
  if (dryRun) {
989
1062
  console.log(` ${render.wrap(render.c.dim, "Would append bootstrap instruction to")} ${join(process.cwd(), "CLAUDE.md")}`);
@@ -1003,6 +1076,19 @@ export function register(program) {
1003
1076
  console.log(` ${render.wrap(render.c.dim, "Fix:")} flair doctor --fix ${render.wrap(render.c.dim, "(adds the mcp__flair__bootstrap line to ./CLAUDE.md)")}`);
1004
1077
  }
1005
1078
  }
1079
+ } // end CLAUDE.md (claudeCodeConfigured)
1080
+ // flair#1834 PR-H: a hook file on disk IS the wiring — the same rule as
1081
+ // the Codex hook below. A realistic setup keeps the SessionStart hook in
1082
+ // ~/.claude/settings.json while the flair MCP server is configured
1083
+ // PROJECT-scoped (a project's .mcp.json) rather than in ~/.claude.json.
1084
+ // claudeCodeConfigured is then false and the hook never ran — a silently
1085
+ // skipped HOLD, the exact state PR-H exists to prevent. Inspect the
1086
+ // Claude Code hook whenever one is PRESENT on disk; a
1087
+ // `claudeCodeConfigured` box with NO hook still falls through to the
1088
+ // "not found / add" report below.
1089
+ const claudeHook = inspectSessionStartHook(resolveHome(), { settingsPath: hookSettingsPath(resolveHome(), "claude-code") });
1090
+ if (claudeCodeConfigured || claudeHook.present) {
1091
+ const hook = claudeHook;
1006
1092
  // flair#1007: presence was never the problem — the failing entry was
1007
1093
  // perfectly well-formed. inspectSessionStartHook() additionally RUNS
1008
1094
  // the registered command (bounded, side-effect-free via
@@ -1010,21 +1096,35 @@ export function register(program) {
1010
1096
  // works", and reports the shell-level silencing separately so an
1011
1097
  // already-installed loud hook can be upgraded rather than only
1012
1098
  // diagnosed.
1013
- const hook = inspectSessionStartHook(homedir());
1014
1099
  if (hook.present) {
1015
1100
  // flair#1485: pin ≠ installed CLI version is a failure, never a
1016
1101
  // ✓ "still runs". Check freshness first so a stale pin cannot
1017
1102
  // hide behind the execution probe. Catalog owns the issue count.
1018
- const claudeStale = staleSessionStartHookPins(homedir()).find((r) => r.target.id === "claude-code");
1019
- if (claudeStale) {
1020
- console.log(` ${render.icons.error} SessionStart hook: pinned to flair-mcp@${claudeStale.pin} (installed CLI is ${flairCliVersion()}) — the hook still launches the OLD adapter on every session`);
1103
+ const claudeStale = sessionStartHookPinFindings(resolveHome()).find((f) => f.reading.target.id === "claude-code");
1104
+ if (claudeStale && claudeStale.direction === "unknown") {
1105
+ // flair#1778: a pin we cannot compare is its OWN finding — a warn,
1106
+ // never the stale "old adapter" error, and NOT re-pinned (the
1107
+ // refresh holds an unreadable pin). Needs no --fix.
1108
+ console.log(` ${render.icons.warn} SessionStart hook: pin is not a version I can compare: ${claudeStale.reading.pin} — not re-pinned; re-run flair init or edit the hook if this is unintended`);
1109
+ }
1110
+ else if (claudeStale && claudeStale.direction === "ahead") {
1111
+ // flair#1778 follow-up: a pin AHEAD of the running CLI is not stale
1112
+ // — re-pinning would LOWER it and the refresh HOLDS it. Report a
1113
+ // held pass: no ✗, no issue count (the catalog agrees), no --fix.
1114
+ console.log(` ${render.icons.ok} SessionStart hook: pinned to flair-mcp@${claudeStale.reading.pin}, ahead of the installed CLI ${flairCliVersion()} — held`);
1115
+ }
1116
+ else if (claudeStale) {
1117
+ console.log(` ${render.icons.error} SessionStart hook: pinned to flair-mcp@${claudeStale.reading.pin} (installed CLI is ${flairCliVersion()}) — the hook still launches the OLD adapter on every session`);
1021
1118
  if (autoFix) {
1022
1119
  if (dryRun) {
1023
1120
  console.log(` ${render.wrap(render.c.dim, "Would re-pin the SessionStart hook in")} ${hook.path}`);
1024
1121
  }
1025
1122
  else {
1026
- const repin = repinSessionStartHook(homedir(), "claude-code");
1027
- console.log(` ${repin.ok ? render.icons.ok : render.icons.warn} ${repin.message}`);
1123
+ const repin = repinSessionStartHookGuarded(resolveHome(), "claude-code");
1124
+ // flair#1834 A1 round 3 + PR-H: the SAME icon rule as the MCP
1125
+ // re-pin line — a hold (or a failed write) renders ⚠, never a
1126
+ // false ✓ for an attempted-but-held fix.
1127
+ console.log(` ${render.icons[mcpRepinIcon(repin.action, repin.ok)]} ${repin.message}`);
1028
1128
  }
1029
1129
  }
1030
1130
  else {
@@ -1087,7 +1187,7 @@ export function register(program) {
1087
1187
  console.log(` Skipped.`);
1088
1188
  }
1089
1189
  else {
1090
- const upgrade = upgradeSessionStartHookCommand(homedir());
1190
+ const upgrade = upgradeSessionStartHookCommand(resolveHome());
1091
1191
  console.log(` ${upgrade.ok ? render.icons.ok : render.icons.warn} ${upgrade.message}`);
1092
1192
  }
1093
1193
  }
@@ -1114,7 +1214,7 @@ export function register(program) {
1114
1214
  }
1115
1215
  else {
1116
1216
  const fixAgentId = claudeCodeAgentId || opts.agent || process.env.FLAIR_AGENT_ID;
1117
- const fixRes = fixSessionStartHook(homedir(), fixAgentId);
1217
+ const fixRes = fixSessionStartHook(resolveHome(), fixAgentId);
1118
1218
  console.log(` ${fixRes.ok ? render.icons.ok : render.icons.warn} ${fixRes.message}`);
1119
1219
  }
1120
1220
  }
@@ -1123,7 +1223,7 @@ export function register(program) {
1123
1223
  console.log(` ${render.wrap(render.c.dim, "Fix:")} flair doctor --fix ${render.wrap(render.c.dim, "(adds the flair-session-start SessionStart hook)")}`);
1124
1224
  }
1125
1225
  }
1126
- } // end CLAUDE.md + SessionStart hook (claudeCodeConfigured)
1226
+ } // end SessionStart hook (claudeCodeConfigured || hook.present)
1127
1227
  // Continuity capture is a standalone Claude Code opt-in — shown whenever
1128
1228
  // Claude Code is DETECTED, independent of MCP wiring (flair#1324/#1257).
1129
1229
  if (claudeCodeDetected) {
@@ -1139,7 +1239,7 @@ export function register(program) {
1139
1239
  // --continuity` only). A partial or stale pair IS evidence of a prior
1140
1240
  // opt-in, so repairing it to the complete current form remains a
1141
1241
  // legitimate --fix.
1142
- const continuity = checkContinuityCaptureHooks(homedir());
1242
+ const continuity = checkContinuityCaptureHooks(resolveHome());
1143
1243
  if (continuity.state === "installed") {
1144
1244
  console.log(` ${render.icons.ok} Continuity capture hooks: PostToolUse + Stop wired in ${render.wrap(render.c.dim, continuity.path)}`);
1145
1245
  }
@@ -1167,7 +1267,7 @@ export function register(program) {
1167
1267
  // different instance.
1168
1268
  const existingCommand = continuity.postToolUse.command || continuity.stop.command || "";
1169
1269
  const existingUrl = existingCommand.match(/FLAIR_URL=(\S+)/)?.[1];
1170
- const fixRes = fixContinuityCaptureHooks(homedir(), fixAgentId, existingUrl);
1270
+ const fixRes = fixContinuityCaptureHooks(resolveHome(), fixAgentId, existingUrl);
1171
1271
  console.log(` ${fixRes.ok ? render.icons.ok : render.icons.warn} ${fixRes.message}`);
1172
1272
  if (fixRes.ok && fixRes.changed)
1173
1273
  fixed++;
@@ -1184,19 +1284,39 @@ export function register(program) {
1184
1284
  // command Claude Code uses, written to ~/.codex/hooks.json. Continuity
1185
1285
  // and CLAUDE.md stay Claude-Code-only; Codex's session-start mechanism
1186
1286
  // is the hook file.
1187
- if (codexConfigured) {
1188
- const hook = inspectSessionStartHook(homedir(), { settingsPath: hookSettingsPath(homedir(), "codex") });
1287
+ // flair#1834 PR-H: a hook file on disk IS the wiring. Inspect Codex's
1288
+ // SessionStart hook whenever one is PRESENT on disk, not only when Codex
1289
+ // is otherwise detected/configured on this box (a `codex` binary on PATH
1290
+ // or a wired ~/.codex/config.toml). Gating the whole block on Codex's MCP
1291
+ // configuration silently skipped a wired ~/.codex/hooks.json when Codex
1292
+ // was not installed — exactly the quiet skip PR-H exists to prevent (a
1293
+ // HOLD must be printed). A `codexConfigured` box with NO hook still falls
1294
+ // through to the "not found / add" report below.
1295
+ const codexHook = inspectSessionStartHook(resolveHome(), { settingsPath: hookSettingsPath(resolveHome(), "codex") });
1296
+ if (codexConfigured || codexHook.present) {
1297
+ const hook = codexHook;
1189
1298
  if (hook.present) {
1190
- const codexStale = staleSessionStartHookPins(homedir()).find((r) => r.target.id === "codex");
1191
- if (codexStale) {
1192
- console.log(` ${render.icons.error} SessionStart hook (codex): pinned to flair-mcp@${codexStale.pin} (installed CLI is ${flairCliVersion()}) — the hook still launches the OLD adapter on every session`);
1299
+ const codexStale = sessionStartHookPinFindings(resolveHome()).find((f) => f.reading.target.id === "codex");
1300
+ if (codexStale && codexStale.direction === "unknown") {
1301
+ // flair#1778: same direction rule as Claude Code above.
1302
+ console.log(` ${render.icons.warn} SessionStart hook (codex): pin is not a version I can compare: ${codexStale.reading.pin} — not re-pinned; re-run flair init or edit the hook if this is unintended`);
1303
+ }
1304
+ else if (codexStale && codexStale.direction === "ahead") {
1305
+ // flair#1778 follow-up: same direction rule as Claude Code above.
1306
+ console.log(` ${render.icons.ok} SessionStart hook (codex): pinned to flair-mcp@${codexStale.reading.pin}, ahead of the installed CLI ${flairCliVersion()} — held`);
1307
+ }
1308
+ else if (codexStale) {
1309
+ console.log(` ${render.icons.error} SessionStart hook (codex): pinned to flair-mcp@${codexStale.reading.pin} (installed CLI is ${flairCliVersion()}) — the hook still launches the OLD adapter on every session`);
1193
1310
  if (autoFix) {
1194
1311
  if (dryRun) {
1195
1312
  console.log(` ${render.wrap(render.c.dim, "Would re-pin the SessionStart hook in")} ${hook.path}`);
1196
1313
  }
1197
1314
  else {
1198
- const repin = repinSessionStartHook(homedir(), "codex");
1199
- console.log(` ${repin.ok ? render.icons.ok : render.icons.warn} ${repin.message}`);
1315
+ const repin = repinSessionStartHookGuarded(resolveHome(), "codex");
1316
+ // flair#1834 A1 round 3 + PR-H: the SAME icon rule as the MCP
1317
+ // re-pin line — a hold (or a failed write) renders ⚠, never a
1318
+ // false ✓ for an attempted-but-held fix.
1319
+ console.log(` ${render.icons[mcpRepinIcon(repin.action, repin.ok)]} ${repin.message}`);
1200
1320
  }
1201
1321
  }
1202
1322
  else {
@@ -1239,7 +1359,7 @@ export function register(program) {
1239
1359
  console.log(` Skipped.`);
1240
1360
  }
1241
1361
  else {
1242
- const upgrade = upgradeSessionStartHookCommand(homedir(), hook.path);
1362
+ const upgrade = upgradeSessionStartHookCommand(resolveHome(), hook.path);
1243
1363
  console.log(` ${upgrade.ok ? render.icons.ok : render.icons.warn} ${upgrade.message}`);
1244
1364
  }
1245
1365
  }
@@ -1265,8 +1385,8 @@ export function register(program) {
1265
1385
  console.log(` Skipped.`);
1266
1386
  }
1267
1387
  else {
1268
- const fixAgentId = resolveHookAgentId({ agent: opts.agent }, homedir(), "codex");
1269
- const fixRes = fixSessionStartHook(homedir(), fixAgentId, hook.path);
1388
+ const fixAgentId = resolveHookAgentId({ agent: opts.agent }, resolveHome(), "codex");
1389
+ const fixRes = fixSessionStartHook(resolveHome(), fixAgentId, hook.path);
1270
1390
  console.log(` ${fixRes.ok ? render.icons.ok : render.icons.warn} ${fixRes.message}`);
1271
1391
  }
1272
1392
  }
@@ -1470,6 +1590,17 @@ export function register(program) {
1470
1590
  try {
1471
1591
  const presRes = await fetch(`${baseUrl}/Presence`, { headers, signal: AbortSignal.timeout(5000) });
1472
1592
  if (!presRes.ok) {
1593
+ // flair#1880: GET /Presence requires a verified reader by default, so
1594
+ // a keyless (unsigned) read now gets 401. Say so plainly instead of a
1595
+ // bare HTTP code — there is no agent to sign as here, so the fix is
1596
+ // either to pass one (--agent) or to opt the instance into a public
1597
+ // roster. Never silent: the flip must not blind our own tooling.
1598
+ if (presRes.status === 401 && !canSign) {
1599
+ console.log(`${indent}${render.icons.info} Presence roster requires a verified reader (HTTP 401). ` +
1600
+ `Pass --agent <id> (with a matching key in ~/.flair/keys) to read it, or set ` +
1601
+ `PRESENCE_PUBLIC_ROSTER=true on the instance to publish a public roster.`);
1602
+ return;
1603
+ }
1473
1604
  console.log(`${indent}${render.icons.warn} Could not fetch presence roster (HTTP ${presRes.status})`);
1474
1605
  return;
1475
1606
  }
@@ -1689,7 +1820,7 @@ export function register(program) {
1689
1820
  statusCommand: "flair federation sync status",
1690
1821
  darwinTarget: `${guiDomain}/${fedSched.LAUNCHD_LABEL}`,
1691
1822
  linuxServiceUnit: fedSched.SYSTEMD_SERVICE_UNIT,
1692
- stderrLogPath: join(homedir(), ".flair", "logs", "federation-sync.stderr.log"),
1823
+ stderrLogPath: join(resolveHome(), ".flair", "logs", "federation-sync.stderr.log"),
1693
1824
  },
1694
1825
  {
1695
1826
  kind: "rem",
@@ -1699,7 +1830,7 @@ export function register(program) {
1699
1830
  statusCommand: "flair rem nightly status",
1700
1831
  darwinTarget: `${guiDomain}/${remSched.LAUNCHD_LABEL}`,
1701
1832
  linuxServiceUnit: remSched.SYSTEMD_SERVICE_UNIT,
1702
- stderrLogPath: join(homedir(), ".flair", "logs", "rem-nightly.stderr.log"),
1833
+ stderrLogPath: join(resolveHome(), ".flair", "logs", "rem-nightly.stderr.log"),
1703
1834
  },
1704
1835
  ];
1705
1836
  for (const d of drivers) {
@@ -1,8 +1,8 @@
1
1
  import { defaultKeysDir, resolveAdminUser } from "../lib/auth-resolve.js";
2
2
  import * as render from "../render.js";
3
3
  import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
- import { homedir } from "node:os";
5
4
  import { join, resolve } from "node:path";
5
+ import { resolveHome } from "../lib/home.js";
6
6
  let cli;
7
7
  /** Bind the cli-locals this module depends on. */
8
8
  export function bindCli(fns) {
@@ -88,7 +88,7 @@ export function register(program) {
88
88
  grants,
89
89
  ...(privateKey ? { privateKey } : {}),
90
90
  };
91
- const rawOutputPath = opts.output ?? join(homedir(), ".flair", "exports", `${agentId}-${Date.now()}.json`);
91
+ const rawOutputPath = opts.output ?? join(resolveHome(), ".flair", "exports", `${agentId}-${Date.now()}.json`);
92
92
  // Canonicalize to prevent path traversal (e.g. ../../etc/passwd)
93
93
  const outputPath = resolve(rawOutputPath);
94
94
  mkdirSync(join(outputPath, ".."), { recursive: true });