@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,4 +1,4 @@
1
- import { detectWiredFlairMcp, isNodeKeyId } from "../doctor-client.js";
1
+ import { detectWiredFlairMcp } from "../doctor-client.js";
2
2
  import { UPGRADE_SNAPSHOT_ROOT, fetchDeclaredHarperVersion, readInstalledHarperVersion } from "../engine-version.js";
3
3
  import { fabricUpgrade } from "../fabric-upgrade.js";
4
4
  import { renderFleetSweepTable, sweepFleet } from "../fleet-verify.js";
@@ -16,9 +16,10 @@ import { probeInstance } from "../probe.js";
16
16
  import * as render from "../render.js";
17
17
  import { FLAIR_PKG_NAME, primeVersionCheckCache } from "../version-check.js";
18
18
  import { chmodSync, existsSync, lstatSync, mkdirSync, readdirSync, realpathSync, rmSync, statSync } from "node:fs";
19
- import { homedir } from "node:os";
20
19
  import { join, resolve, sep } from "node:path";
21
20
  import { create as tarCreate } from "tar";
21
+ import { classifyInstalledVersion, formatUpgradeStatusLine } from "../lib/upgrade-status.js";
22
+ import { resolveHome } from "../lib/home.js";
22
23
  let cli;
23
24
  /** Bind the cli-locals this module depends on. */
24
25
  export function bindCli(fns) {
@@ -66,9 +67,6 @@ function probeOpenclawPluginVersion(...args) {
66
67
  function relativeTime(...args) {
67
68
  return cli.relativeTime(...args);
68
69
  }
69
- function resolveAgentIdOrEnv(...args) {
70
- return cli.resolveAgentIdOrEnv(...args);
71
- }
72
70
  function resolveFabricCredentials(...args) {
73
71
  return cli.resolveFabricCredentials(...args);
74
72
  }
@@ -841,6 +839,13 @@ export function register(program) {
841
839
  // resolved, so a redirected registry is visible to the operator before
842
840
  // anything is fetched or installed. One line per distinct registry.
843
841
  const noticeRegistry = createRegistryNoticePrinter();
842
+ // An explicit --flair-version pin is the operator's requested target (its
843
+ // downgrade semantics are slice 2, flair#1778 D7) — when set, the
844
+ // plain-tree lane keeps its existing explicit-target behaviour rather than
845
+ // the direction-aware "ahead" gate.
846
+ const flairVersionPin = typeof opts.flairVersion === "string" && opts.flairVersion.trim() !== ""
847
+ ? opts.flairVersion
848
+ : null;
844
849
  for (const { name, probe, kind, transitive } of packages) {
845
850
  if (transitive && !showAll)
846
851
  continue;
@@ -876,7 +881,7 @@ export function register(program) {
876
881
  // that, a requested tarball swap reports up to date and does nothing.
877
882
  const listing = resolvePlainTreeListingTarget({
878
883
  registryLatest,
879
- pin: typeof opts.flairVersion === "string" ? opts.flairVersion : null,
884
+ pin: flairVersionPin,
880
885
  });
881
886
  if (!listing)
882
887
  continue;
@@ -894,12 +899,6 @@ export function register(program) {
894
899
  console.error(` ⚠ ${name}: refusing non-semver install target ${JSON.stringify(latest)} — expected a version like 1.2.3.`);
895
900
  continue;
896
901
  }
897
- if (name === FLAIR_PKG_NAME) {
898
- try {
899
- primeVersionCheckCache(latest);
900
- }
901
- catch { /* best-effort */ }
902
- }
903
902
  const globalProbe = probe();
904
903
  let installed;
905
904
  let status;
@@ -909,17 +908,21 @@ export function register(program) {
909
908
  installed = treeLane.version;
910
909
  if (installed === null)
911
910
  status = "missing";
912
- else if (installed === latest)
913
- status = "current";
911
+ // An explicit --flair-version pin IS the requested target (slice 2
912
+ // owns its downgrade semantics) — do not gate it. Without a pin,
913
+ // classify by semver direction so an install ahead of registry
914
+ // latest is never mistaken for an upgrade (flair#1778).
915
+ else if (flairVersionPin !== null)
916
+ status = installed === latest ? "current" : "outdated";
914
917
  else
915
- status = "outdated";
918
+ status = classifyInstalledVersion(installed, latest);
916
919
  }
917
920
  else if (name === FLAIR_MCP_PACKAGE) {
918
921
  // flair-mcp is zero-install via npx (#1168) — a null global probe is
919
922
  // the NORMAL state, not "missing". Resolve it from its actual wiring
920
923
  // (the pin in a client MCP config / the SessionStart hook) so the
921
924
  // listing is truthful and the remedy actually works (flair#1208).
922
- const home = process.env.HOME ?? homedir();
925
+ const home = resolveHome();
923
926
  ({ installed, status } = resolveFlairMcpFinding(globalProbe, latest, detectWiredFlairMcp(home)));
924
927
  }
925
928
  else {
@@ -929,14 +932,26 @@ export function register(program) {
929
932
  // installed, don't surface a misleading "install with npm" advice.
930
933
  status = kind === "openclaw-plugin" ? "optional" : "missing";
931
934
  }
932
- else if (installed === latest) {
933
- status = "current";
934
- }
935
935
  else {
936
- status = "outdated";
936
+ // Direction-aware (flair#1778): an install ahead of latest is a
937
+ // distinct state, never rendered as an upgrade, never installed.
938
+ status = classifyInstalledVersion(installed, latest);
937
939
  }
938
940
  }
939
941
  findings.push({ name, installed, latest, status, kind });
942
+ // flair#1778 D5: prime the version-check cache with the EFFECTIVE
943
+ // target. When the install is AHEAD of latest nothing will be installed,
944
+ // so priming `latest` would make a later version check nudge a
945
+ // downgrade.
946
+ if (name === FLAIR_PKG_NAME) {
947
+ const effectiveTarget = status === "ahead" ? installed : latest;
948
+ if (effectiveTarget) {
949
+ try {
950
+ primeVersionCheckCache(effectiveTarget);
951
+ }
952
+ catch { /* best-effort */ }
953
+ }
954
+ }
940
955
  // Suppress the line for openclaw plugins that are optional-because-
941
956
  // openclaw-is-absent: on machines without openclaw the
942
957
  // "○ … not installed (openclaw not detected) → … (install via …)"
@@ -944,13 +959,11 @@ export function register(program) {
944
959
  // (current/outdated) or under --all.
945
960
  if (!shouldPrintUpgradeLine(status, showAll))
946
961
  continue;
947
- const icon = status === "current" ? "✅"
948
- : status === "outdated" ? "⬆️"
949
- : status === "optional" ? "○"
950
- : "❔";
951
- const installedLabel = installed ?? (status === "optional" ? "not installed (openclaw not detected)" : "not detected");
962
+ // ONE renderer (src/lib/upgrade-status.ts). An install AHEAD of latest
963
+ // prints with NO arrow and NO remedy (flair#1778); an unparseable
964
+ // installed version prints the raw string as "❔ unknown".
952
965
  const suffix = upgradeStatusSuffix(name, status);
953
- console.log(` ${icon} ${name}: ${installedLabel} → ${latest}${suffix}`);
966
+ console.log(formatUpgradeStatusLine({ name, installed, latest, status, suffix }));
954
967
  }
955
968
  catch { /* skip unavailable packages */ }
956
969
  }
@@ -985,25 +998,41 @@ export function register(program) {
985
998
  let treePlan = null;
986
999
  if (treeLane) {
987
1000
  const flairFindingForPlan = findings.find((f) => f.name === FLAIR_PKG_NAME);
988
- // flair#1758: unit discovery is captured HERE, into the plan, while apply
989
- // later renames the selected canonical tree (applyPlainTreeUpgrade). A
990
- // concurrent symlink retarget between discovery and apply can therefore
991
- // make the restart launch a DIFFERENT tree than the one that matched.
992
- // Resolving both sides fresh narrows the window; it is not transaction
993
- // locking.
994
- treePlan = planPlainTreeUpgrade({
995
- treeDir: treeLane.dir,
996
- fromVersion: treeLane.version,
997
- toVersion: flairFindingForPlan?.latest ?? treeLane.version ?? "unknown",
998
- systemdUnits: findSystemdUnitsForTree(treeLane.dir),
999
- });
1001
+ // flair#1778 D3: CONSTRUCT the plan only when flair is actually being
1002
+ // upgraded. Downstream restart/rollback/cleanup key on `treePlan`'s
1003
+ // presence, so a plan built for an install that is not changing would
1004
+ // stage a swap that never happens.
1000
1005
  if (flairFindingForPlan?.status === "outdated") {
1006
+ // flair#1758: unit discovery is captured HERE, into the plan, while
1007
+ // apply later renames the selected canonical tree
1008
+ // (applyPlainTreeUpgrade). A concurrent symlink retarget between
1009
+ // discovery and apply can therefore make the restart launch a
1010
+ // DIFFERENT tree than the one that matched. Resolving both sides fresh
1011
+ // narrows the window; it is not transaction locking.
1012
+ treePlan = planPlainTreeUpgrade({
1013
+ treeDir: treeLane.dir,
1014
+ fromVersion: treeLane.version,
1015
+ toVersion: flairFindingForPlan.latest,
1016
+ systemdUnits: findSystemdUnitsForTree(treeLane.dir),
1017
+ });
1001
1018
  console.log("");
1002
1019
  console.log(formatPlainTreePlan(treePlan));
1003
1020
  }
1004
1021
  }
1005
1022
  if (outdated.length === 0 && missing.length === 0) {
1006
- console.log("\n✅ Everything is up to date.");
1023
+ // An install AHEAD of latest is not an upgrade (flair#1778), and neither
1024
+ // is one whose installed version we could not PARSE: "unknown" is not
1025
+ // evidence of convergence, so "✅ Everything is up to date." would claim
1026
+ // more than we can see (flair#1778 slice-1 follow-up, N1). Prefer the
1027
+ // neutral summary whenever EITHER state is present, and for an
1028
+ // unparseable version name the package and the raw string that could not
1029
+ // be parsed — the operator gets to see what was unreadable.
1030
+ const anyAhead = findings.some((f) => f.status === "ahead");
1031
+ const unknownFindings = findings.filter((f) => f.status === "unknown");
1032
+ for (const f of unknownFindings) {
1033
+ console.log(`\n❔ ${f.name}: could not parse installed version ${JSON.stringify(f.installed)} — not reporting it as up to date.`);
1034
+ }
1035
+ console.log(anyAhead || unknownFindings.length > 0 ? "\nNo upgrades available." : "\n✅ Everything is up to date.");
1007
1036
  return;
1008
1037
  }
1009
1038
  // ONE pin-refresh implementation, two callers (flair#1324): the post-
@@ -1013,33 +1042,14 @@ export function register(program) {
1013
1042
  // `doctor --fix` round-trip. Only refreshes clients that are ALREADY
1014
1043
  // wired — never wires new ones. Best-effort: failures warn but never fail
1015
1044
  // the upgrade.
1016
- async function refreshWiredMcpClientPins(targetPort) {
1017
- const agentId = resolveAgentIdOrEnv({}) ?? (() => {
1018
- try {
1019
- const kd = defaultKeysDir();
1020
- const keyFiles = readdirSync(kd).filter((f) => f.endsWith(".key"));
1021
- // Node-scoped federation keys aren't agents (flair#1193) — never
1022
- // pin-refresh a connector as one.
1023
- const agentKeyFile = keyFiles.find((f) => !isNodeKeyId(f.replace(/\.key$/, ""), kd));
1024
- return agentKeyFile ? agentKeyFile.replace(/\.key$/, "") : null;
1025
- }
1026
- catch {
1027
- return null;
1028
- }
1029
- })();
1030
- // flair#1485: one catalogue (listOwnedPinTargets) for every file we
1031
- // pin — MCP client configs AND SessionStart hooks. A missing agent id
1032
- // skips MCP only; hook re-pin reads the agent from the existing command
1033
- // and must still run (the early return here used to leave hooks stale).
1034
- if (!agentId) {
1035
- console.log("\n (no agent id known — skip MCP client pin refresh; SessionStart hooks still re-pin)");
1036
- }
1037
- const homeDir = process.env.HOME || process.env.USERPROFILE || homedir();
1038
- const results = refreshOwnedPins({
1039
- homeDir,
1040
- agentId: agentId ?? null,
1041
- flairUrl: `http://127.0.0.1:${targetPort}`,
1042
- });
1045
+ async function refreshWiredMcpClientPins() {
1046
+ // flair#1834 A1: the refresh is PIN-ONLY. It no longer resolves a
1047
+ // host-wide agent id (the old first-`.key` fallback in this function) or a FLAIR_URL, because those were written into EVERY wired
1048
+ // client's env — rewriting each client's FLAIR_AGENT_ID to whichever key
1049
+ // happened to sort first. The writer preserves each entry's own identity
1050
+ // and changes only the pinned package argument.
1051
+ const homeDir = resolveHome();
1052
+ const results = refreshOwnedPins({ homeDir });
1043
1053
  const noteworthy = results.filter(ownedPinRefreshShouldReport);
1044
1054
  if (noteworthy.length === 0)
1045
1055
  return;
@@ -1060,7 +1070,16 @@ export function register(program) {
1060
1070
  if (missing.length > 0) {
1061
1071
  const npmMissing = missing.filter((f) => f.name !== FLAIR_MCP_PACKAGE);
1062
1072
  const mcpMissing = missing.some((f) => f.name === FLAIR_MCP_PACKAGE);
1063
- console.log(`\n❔ ${missing.length} package${missing.length > 1 ? "s" : ""} not detected — all detected packages are up to date.`);
1073
+ // flair#1778 follow-up: "all detected packages are up to date" is the
1074
+ // same false-convergence claim the no-upgrade summary above avoids, so
1075
+ // guard it with the same condition — when any detected package is
1076
+ // `ahead` or `unknown`, say only that there are no upgrades for the
1077
+ // rest, never that they are up to date.
1078
+ const anyAheadOrUnknown = findings.some((f) => f.status === "ahead" || f.status === "unknown");
1079
+ const tail = anyAheadOrUnknown
1080
+ ? "no upgrades available for the rest"
1081
+ : "all detected packages are up to date";
1082
+ console.log(`\n❔ ${missing.length} package${missing.length > 1 ? "s" : ""} not detected — ${tail}.`);
1064
1083
  if (npmMissing.length > 0) {
1065
1084
  console.log(` Install missing: npm install -g ${npmMissing.map((f) => f.name).join(" ")}`);
1066
1085
  }
@@ -1074,7 +1093,7 @@ export function register(program) {
1074
1093
  console.log(" Run: flair upgrade (refreshes the pin)");
1075
1094
  }
1076
1095
  else {
1077
- await refreshWiredMcpClientPins(resolveHttpPort({}));
1096
+ await refreshWiredMcpClientPins();
1078
1097
  }
1079
1098
  }
1080
1099
  return;
@@ -1314,7 +1333,7 @@ export function register(program) {
1314
1333
  // version. Runs BEFORE the restart so --no-restart and --no-verify paths
1315
1334
  // also get the refresh (flair#1167). Best-effort: failures warn but never
1316
1335
  // fail the upgrade.
1317
- await refreshWiredMcpClientPins(upgradePort);
1336
+ await refreshWiredMcpClientPins();
1318
1337
  // ── Restart + verify + rollback (flair#635) ─────────────────────────────
1319
1338
  // Decision (2026-07-08): restart is now the default post-upgrade step —
1320
1339
  // installing new code without restarting leaves the OLD process serving