harnessed 4.32.4 → 4.32.6

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/README.md CHANGED
@@ -501,7 +501,7 @@ planning-with-files /plan (cross-cutting tool) → write artifacts to .planning/
501
501
  | `harnessed run <name>` | Run a workflow via in-process SDK spawn (CI/headless mode). Slash commands use CC-native spawn instead. |
502
502
  | `harnessed resume` | Resume from the most recent checkpoint after a session interruption |
503
503
  | `harnessed status` | Current phase + lock holder |
504
- | `harnessed doctor` | Health check (Node / MCP / jq / Win bash / routing / token budget / skill integrity / GateGuard conflict / update-available, etc.) |
504
+ | `harnessed doctor` | Health check (Node / MCP / jq / Win bash / routing / token budget / skill integrity / GateGuard conflict / update-available / stale hooks, etc.). The **stale hooks** check flags orphaned harnessed `Stop`/`UserPromptSubmit` entries in `~/.claude/settings.json` that point at a deleted `bin/*.mjs` — the cause of a `MODULE_NOT_FOUND` error on every prompt after a raw `npm uninstall -g harnessed`. Fix: run `harnessed uninstall` (it strips them) **before** removing the package. |
505
505
  | `harnessed update [--check\|--upstreams\|--migration-report]` | Self-update, channel-aware: binary installs replace themselves in place from GitHub releases (sha256-verified, previous version kept for rollback); npm installs run `npm i -g harnessed@latest`. `--check` reports the latest version; `--upstreams` re-runs the base manifests; `--migration-report` is a read-only stale-state inventory |
506
506
  | `harnessed release-preflight` | Read-only release-readiness gate (CHANGELOG `[Unreleased]` / version / git-clean / tag-absent); exits 1 if not ready. The Ship-stage gate. |
507
507
  | `harnessed retro --done` | Reset the retro-reminder phase counter after running `/retro` (clears the per-turn RETRO-DUE nudge). |
@@ -11,7 +11,8 @@
11
11
  // compares its stdout to the TS builder.
12
12
  //
13
13
  // Phase 15 repo-aware: resolves the active repo's slot from
14
- // workflows.json[repoKey(cwd)] (legacy current-workflow.json as a fallback).
14
+ // workflows.json[repoKey(cwd)]. No legacy current-workflow.json fallback
15
+ // (removed 4.32.6 — it leaked cross-repo; see readWorkflow).
15
16
  // Root: HARNESSED_ROOT_OVERRIDE if set, else <homedir>/.claude/harnessed.
16
17
  import { createHash } from 'node:crypto'
17
18
  import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
@@ -105,8 +106,8 @@ function shouldEmitPc(root, repoRoot, sid, pc) {
105
106
  }
106
107
  }
107
108
 
108
- // Phase 35 — try the session-scoped slot first, then the bare repoKey slot, then
109
- // the legacy singleton (dual-write anchor). `keys` is ordered most→least specific.
109
+ // Phase 35 — try the session-scoped slot first, then the bare repoKey slot.
110
+ // `keys` is ordered most→least specific. No legacy-singleton fallback (see below).
110
111
  // 4.22.0 — also surfaces the intent sidecar (same key order) for the freestyle nag.
111
112
  function readWorkflow(root, keys) {
112
113
  let wf = null
@@ -141,13 +142,13 @@ function readWorkflow(root, keys) {
141
142
  }
142
143
  }
143
144
  } catch {}
144
- if (!wf) {
145
- try {
146
- const legacyPath = join(root, 'current-workflow.json')
147
- wf = JSON.parse(readFileSync(legacyPath, 'utf8'))
148
- ledgerAgeMs = ageOf(legacyPath)
149
- } catch {}
150
- }
145
+ // NO legacy `current-workflow.json` fallback here (removed 4.32.6): the
146
+ // pre-Phase-15 global singleton carries no repo identity, so an unconditional
147
+ // fallback leaked one repo's workflow-state into EVERY repo lacking a slot —
148
+ // an independent new project would get a phantom <workflow-state> every turn.
149
+ // Migration of a genuine pre-Phase-15 root is owned by readStoreRaw
150
+ // (workflowStore.ts), which only reads the singleton when workflows.json is
151
+ // wholly absent; the hot-path hook only ever reads the per-repo store.
151
152
  return { wf, intent, ledgerAgeMs }
152
153
  }
153
154
 
package/dist/cli.mjs CHANGED
@@ -38,7 +38,7 @@ var init_package = __esm({
38
38
  "package.json"() {
39
39
  package_default = {
40
40
  name: "harnessed",
41
- version: "4.32.4",
41
+ version: "4.32.6",
42
42
  description: "AI coding harness package manager + composition orchestrator",
43
43
  type: "module",
44
44
  license: "Apache-2.0",
@@ -1858,6 +1858,7 @@ var init_en = __esm({
1858
1858
  "uninstall.unified.commands": " Commands: {{count}} harnessed-generated slash command file(s) in ~/.claude/commands/",
1859
1859
  "uninstall.unified.skills": " Skills: {{count}} workflow skill directory(ies) in ~/.claude/skills/",
1860
1860
  "uninstall.unified.settings": " Settings: harnessed env vars (CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS, HARNESSED_USER_LANG) from ~/.claude/settings.json",
1861
+ "uninstall.unified.hooks": " Hooks: {{count}} harnessed Stop/UserPromptSubmit hook(s) in ~/.claude/settings.json",
1861
1862
  "uninstall.unified.state_dir": " State directory: ~/.claude/harnessed/ (includes backups, audit log, state, lock)",
1862
1863
  "uninstall.unified.upstream_note": "\nUpstream components (npm packages, MCP servers, CC plugins, git-cloned repos, npx skills) are NOT affected.",
1863
1864
  "uninstall.unified.dry_run_hint": "\n(dry-run \u2014 re-run without --dry-run to actually remove)",
@@ -1866,6 +1867,7 @@ var init_en = __esm({
1866
1867
  "uninstall.unified.removed_commands": " removed {{count}} command file(s)",
1867
1868
  "uninstall.unified.removed_skills": " removed {{count}} skill directory(ies)",
1868
1869
  "uninstall.unified.removed_settings": " removed harnessed env vars from ~/.claude/settings.json",
1870
+ "uninstall.unified.removed_hooks": " removed {{count}} harnessed hook(s) from ~/.claude/settings.json",
1869
1871
  "uninstall.unified.removed_state_dir": " removed ~/.claude/harnessed/",
1870
1872
  "uninstall.unified.partial_failure": "\n{{count}} item(s) could not be removed (permission denied or already gone):",
1871
1873
  "uninstall.unified.complete": "uninstall complete \u2014 harnessed's own files have been removed",
@@ -3181,7 +3183,7 @@ function nameToYamlHintPath(name) {
3181
3183
  function shouldOverwriteFile(content) {
3182
3184
  return HARNESSED_MARKER_RX.test(content) || V3_4_3_SIGNATURE_SUB_RX.test(content) || V3_4_3_SIGNATURE_MASTER_RX.test(content);
3183
3185
  }
3184
- async function writeAllCommands(slashNames, commandsDir, rolePrompts, capabilities, installedPlugins, installedUserSkills, writer, fileExists2 = existsSync, readFileSync19 = (p7) => readFileSync(p7, "utf8")) {
3186
+ async function writeAllCommands(slashNames, commandsDir, rolePrompts, capabilities, installedPlugins, installedUserSkills, writer, fileExists2 = existsSync, readFileSync20 = (p7) => readFileSync(p7, "utf8")) {
3185
3187
  const results = [];
3186
3188
  const aggregatedWarnings = /* @__PURE__ */ new Set();
3187
3189
  for (const name of slashNames) {
@@ -3200,7 +3202,7 @@ async function writeAllCommands(slashNames, commandsDir, rolePrompts, capabiliti
3200
3202
  if (fileExists2(path)) {
3201
3203
  let existing = "";
3202
3204
  try {
3203
- existing = readFileSync19(path);
3205
+ existing = readFileSync20(path);
3204
3206
  } catch {
3205
3207
  existing = "";
3206
3208
  }
@@ -6929,6 +6931,127 @@ var init_check_install_channels = __esm({
6929
6931
  }
6930
6932
  });
6931
6933
 
6934
+ // src/installers/lib/harnessedHookTeardown.ts
6935
+ function harnessedHookIdentity(raw) {
6936
+ for (const id of IDS) {
6937
+ if (new RegExp(`harnessed-${id}\\.mjs(?:["']|\\s|$)`).test(raw)) return id;
6938
+ if (new RegExp(`harnessed(?:\\.exe)?["']?\\s+${id}(?:\\s|$)`).test(raw)) return id;
6939
+ }
6940
+ return null;
6941
+ }
6942
+ function harnessedHookScriptPath(raw) {
6943
+ const mjs = raw.match(/["']?([^"'\s]*harnessed-(?:inject-state|stop-hook)\.mjs)["']?/);
6944
+ if (mjs?.[1]) return mjs[1];
6945
+ const quotedBin = raw.match(/["']([^"']*harnessed(?:\.exe)?)["']\s+(?:inject-state|stop-hook)\b/);
6946
+ if (quotedBin?.[1]) return quotedBin[1];
6947
+ const bareBin = raw.match(/(?:^|\s)(harnessed(?:\.exe)?)\s+(?:inject-state|stop-hook)\b/);
6948
+ if (bareBin?.[1]) return bareBin[1];
6949
+ return null;
6950
+ }
6951
+ function entryCommands(entry) {
6952
+ const cmds = [];
6953
+ if (typeof entry.command === "string") cmds.push(entry.command);
6954
+ if (Array.isArray(entry.hooks)) {
6955
+ for (const h of entry.hooks) if (h && typeof h.command === "string") cmds.push(h.command);
6956
+ }
6957
+ return cmds;
6958
+ }
6959
+ function entryIsHarnessed(entry) {
6960
+ return entryCommands(entry).some((c) => harnessedHookIdentity(c) !== null);
6961
+ }
6962
+ function stripHarnessedHooks(hooks) {
6963
+ let removed = 0;
6964
+ for (const ev of Object.keys(hooks)) {
6965
+ const arr = hooks[ev];
6966
+ if (!Array.isArray(arr)) continue;
6967
+ const kept = arr.filter((entry) => {
6968
+ const owned = entryIsHarnessed(entry);
6969
+ if (owned) removed++;
6970
+ return !owned;
6971
+ });
6972
+ if (kept.length === 0) delete hooks[ev];
6973
+ else hooks[ev] = kept;
6974
+ }
6975
+ return { removed };
6976
+ }
6977
+ function countHarnessedHooks(hooks) {
6978
+ let n = 0;
6979
+ for (const arr of Object.values(hooks)) {
6980
+ if (!Array.isArray(arr)) continue;
6981
+ for (const entry of arr) if (entryIsHarnessed(entry)) n++;
6982
+ }
6983
+ return n;
6984
+ }
6985
+ function harnessedStaleHookPaths(hooks, exists) {
6986
+ const out = [];
6987
+ for (const [event, arr] of Object.entries(hooks)) {
6988
+ if (!Array.isArray(arr)) continue;
6989
+ for (const entry of arr) {
6990
+ for (const cmd of entryCommands(entry)) {
6991
+ if (harnessedHookIdentity(cmd) === null) continue;
6992
+ const path = harnessedHookScriptPath(cmd);
6993
+ if (path && ABSOLUTE_RE.test(path) && !exists(path)) out.push({ event, path });
6994
+ }
6995
+ }
6996
+ }
6997
+ return out;
6998
+ }
6999
+ var IDS, ABSOLUTE_RE;
7000
+ var init_harnessedHookTeardown = __esm({
7001
+ "src/installers/lib/harnessedHookTeardown.ts"() {
7002
+ IDS = ["inject-state", "stop-hook"];
7003
+ ABSOLUTE_RE = /^([A-Za-z]:[\\/]|[\\/])/;
7004
+ }
7005
+ });
7006
+
7007
+ // src/cli/lib/check-stale-hooks.ts
7008
+ var check_stale_hooks_exports = {};
7009
+ __export(check_stale_hooks_exports, {
7010
+ checkStaleHooks: () => checkStaleHooks
7011
+ });
7012
+ function checkStaleHooks(deps) {
7013
+ const settingsPath = deps?.settingsPath ?? getSettingsPath();
7014
+ const readText = deps?.readText ?? ((p7) => {
7015
+ try {
7016
+ return readFileSync(p7, "utf8");
7017
+ } catch {
7018
+ return null;
7019
+ }
7020
+ });
7021
+ const exists = deps?.exists ?? existsSync;
7022
+ const raw = readText(settingsPath);
7023
+ if (raw === null) return { name: NAME, status: "pass", message: "no settings.json" };
7024
+ let data;
7025
+ try {
7026
+ data = JSON.parse(raw);
7027
+ } catch {
7028
+ return { name: NAME, status: "pass", message: "settings.json unreadable \u2014 skipped" };
7029
+ }
7030
+ const hooks = data.hooks;
7031
+ if (!hooks || typeof hooks !== "object") {
7032
+ return { name: NAME, status: "pass", message: "no hooks registered" };
7033
+ }
7034
+ const stale = harnessedStaleHookPaths(hooks, exists);
7035
+ if (stale.length === 0) {
7036
+ return { name: NAME, status: "pass", message: "no orphaned harnessed hooks" };
7037
+ }
7038
+ const list = stale.map((s) => `${s.event} \u2192 ${s.path}`).join("; ");
7039
+ return {
7040
+ name: NAME,
7041
+ status: "warn",
7042
+ message: `${stale.length} harnessed hook(s) point at a deleted script \u2014 Claude Code errors MODULE_NOT_FOUND every prompt (${list})`,
7043
+ fix: `run 'harnessed uninstall' to strip them, or delete the matching Stop/UserPromptSubmit entries from ${settingsPath}`
7044
+ };
7045
+ }
7046
+ var NAME;
7047
+ var init_check_stale_hooks = __esm({
7048
+ "src/cli/lib/check-stale-hooks.ts"() {
7049
+ init_harnessedHookTeardown();
7050
+ init_platform();
7051
+ NAME = "stale hooks";
7052
+ }
7053
+ });
7054
+
6932
7055
  // src/cli/lib/doctor-registry.ts
6933
7056
  var CHECKS;
6934
7057
  var init_doctor_registry = __esm({
@@ -6972,7 +7095,11 @@ var init_doctor_registry = __esm({
6972
7095
  async () => (await Promise.resolve().then(() => (init_check_update(), check_update_exports))).checkUpdate(),
6973
7096
  // 4.32.4 — dual install-channel conflict (warn-only): npm-global + standalone
6974
7097
  // binary both present → ambiguous PATH resolution + stale-update trap.
6975
- async () => (await Promise.resolve().then(() => (init_check_install_channels(), check_install_channels_exports))).checkInstallChannels()
7098
+ async () => (await Promise.resolve().then(() => (init_check_install_channels(), check_install_channels_exports))).checkInstallChannels(),
7099
+ // issue #8 — orphaned harnessed Stop/UserPromptSubmit hooks (warn-only): a hook
7100
+ // pointing at a deleted bin/*.mjs makes Claude Code error MODULE_NOT_FOUND every
7101
+ // prompt; `harnessed uninstall` now strips them.
7102
+ async () => (await Promise.resolve().then(() => (init_check_stale_hooks(), check_stale_hooks_exports))).checkStaleHooks()
6976
7103
  ];
6977
7104
  }
6978
7105
  });
@@ -7436,7 +7563,7 @@ var init_err = __esm({
7436
7563
  });
7437
7564
  function isRelativeFileToken(token) {
7438
7565
  if (!/[\\/]/.test(token)) return false;
7439
- if (ABSOLUTE_RE.test(token)) return false;
7566
+ if (ABSOLUTE_RE2.test(token)) return false;
7440
7567
  if (/[*?$`]/.test(token)) return false;
7441
7568
  return true;
7442
7569
  }
@@ -7480,7 +7607,7 @@ function hookScriptMarker(raw) {
7480
7607
  }
7481
7608
  return null;
7482
7609
  }
7483
- function entryCommands(entry) {
7610
+ function entryCommands2(entry) {
7484
7611
  const cmds = [];
7485
7612
  if (typeof entry.command === "string") cmds.push(entry.command);
7486
7613
  if (Array.isArray(entry.hooks)) {
@@ -7491,7 +7618,7 @@ function entryCommands(entry) {
7491
7618
  return cmds;
7492
7619
  }
7493
7620
  function entryMatchesRegistration(entry, raw, resolved, marker) {
7494
- const cmds = entryCommands(entry);
7621
+ const cmds = entryCommands2(entry);
7495
7622
  if (cmds.length === 0) return false;
7496
7623
  if (marker) return cmds.some((c) => c.includes(marker));
7497
7624
  return cmds.some((c) => c === raw || c === resolved);
@@ -7524,11 +7651,11 @@ function detectCcHookInstalled(settingsRaw, ev, raw, matcher, deps) {
7524
7651
  const matching = arr.filter((e) => entryMatchesRegistration(e, raw, resolved, marker));
7525
7652
  return matching.length === 1 && isDesiredHookEntry(matching[0] ?? {}, matcher, resolved);
7526
7653
  }
7527
- var COMPILED_HOOK_IDENTITIES, ABSOLUTE_RE;
7654
+ var COMPILED_HOOK_IDENTITIES, ABSOLUTE_RE2;
7528
7655
  var init_hookEntry = __esm({
7529
7656
  "src/installers/lib/hookEntry.ts"() {
7530
7657
  COMPILED_HOOK_IDENTITIES = ["inject-state", "stop-hook"];
7531
- ABSOLUTE_RE = /^([A-Za-z]:[\\/]|[\\/])/;
7658
+ ABSOLUTE_RE2 = /^([A-Za-z]:[\\/]|[\\/])/;
7532
7659
  }
7533
7660
  });
7534
7661
 
@@ -13392,6 +13519,7 @@ function registerStopHook(program2) {
13392
13519
 
13393
13520
  // src/cli/uninstall.ts
13394
13521
  init_i18n();
13522
+ init_harnessedHookTeardown();
13395
13523
  init_harnessedRoot();
13396
13524
  init_platform();
13397
13525
  init_path_guard();
@@ -13690,33 +13818,42 @@ async function checkSettingsEnv(settingsPath) {
13690
13818
  const raw = await readFile(settingsPath, "utf8");
13691
13819
  const data = JSON.parse(raw);
13692
13820
  const env = data.env ?? {};
13821
+ const hooks = data.hooks;
13693
13822
  return {
13694
13823
  hasAgentTeams: "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS" in env,
13695
- hasUserLang: "HARNESSED_USER_LANG" in env
13824
+ hasUserLang: "HARNESSED_USER_LANG" in env,
13825
+ // issue #8 — count orphaned harnessed-owned Stop/UserPromptSubmit hooks.
13826
+ staleHooks: hooks && typeof hooks === "object" ? countHarnessedHooks(hooks) : 0
13696
13827
  };
13697
13828
  } catch {
13698
- return { hasAgentTeams: false, hasUserLang: false };
13829
+ return { hasAgentTeams: false, hasUserLang: false, staleHooks: 0 };
13699
13830
  }
13700
13831
  }
13701
- async function removeSettingsEnv(settingsPath) {
13832
+ async function removeSettingsFootprint(settingsPath) {
13702
13833
  const raw = await readFile(settingsPath, "utf8");
13703
13834
  const data = JSON.parse(raw);
13704
13835
  const env = data.env ?? {};
13705
- let changed = false;
13836
+ let envRemoved = false;
13706
13837
  if ("CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS" in env) {
13707
13838
  delete env.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS;
13708
- changed = true;
13839
+ envRemoved = true;
13709
13840
  }
13710
13841
  if ("HARNESSED_USER_LANG" in env) {
13711
13842
  delete env.HARNESSED_USER_LANG;
13712
- changed = true;
13843
+ envRemoved = true;
13844
+ }
13845
+ let hooksRemoved = 0;
13846
+ const hooks = data.hooks;
13847
+ if (hooks && typeof hooks === "object") {
13848
+ hooksRemoved = stripHarnessedHooks(hooks).removed;
13849
+ if (Object.keys(hooks).length === 0) delete data.hooks;
13713
13850
  }
13714
- if (!changed) return false;
13851
+ if (!envRemoved && hooksRemoved === 0) return { envRemoved: false, hooksRemoved: 0 };
13715
13852
  if (Object.keys(env).length === 0) delete data.env;
13716
13853
  else data.env = env;
13717
13854
  await writeFile(settingsPath, `${JSON.stringify(data, null, 2)}
13718
13855
  `, "utf8");
13719
- return true;
13856
+ return { envRemoved, hooksRemoved };
13720
13857
  }
13721
13858
  function printCliRemovalHint() {
13722
13859
  console.log(t("uninstall.unified.cli_hint_header"));
@@ -13749,6 +13886,7 @@ async function runUnifiedUninstall(home, dryRun) {
13749
13886
  const commandFiles = await discoverCommandFiles(commandsDir);
13750
13887
  const settingsEnv = await checkSettingsEnv(settingsPath);
13751
13888
  const hasSettingsChanges = settingsEnv.hasAgentTeams || settingsEnv.hasUserLang;
13889
+ const staleHooks = settingsEnv.staleHooks;
13752
13890
  const skillDirs = [];
13753
13891
  for (const name of workflowNames) {
13754
13892
  const dir = join(skillsDir, name);
@@ -13758,7 +13896,7 @@ async function runUnifiedUninstall(home, dryRun) {
13758
13896
  } catch {
13759
13897
  }
13760
13898
  }
13761
- const discoverable = commandFiles.length + skillDirs.length + (hasSettingsChanges ? 1 : 0);
13899
+ const discoverable = commandFiles.length + skillDirs.length + (hasSettingsChanges ? 1 : 0) + (staleHooks > 0 ? 1 : 0);
13762
13900
  if (discoverable === 0) {
13763
13901
  console.log(t("uninstall.unified.nothing"));
13764
13902
  printCliRemovalHint();
@@ -13769,6 +13907,7 @@ async function runUnifiedUninstall(home, dryRun) {
13769
13907
  console.log(t("uninstall.unified.commands", { count: commandFiles.length }));
13770
13908
  if (skillDirs.length > 0) console.log(t("uninstall.unified.skills", { count: skillDirs.length }));
13771
13909
  if (hasSettingsChanges) console.log(t("uninstall.unified.settings"));
13910
+ if (staleHooks > 0) console.log(t("uninstall.unified.hooks", { count: staleHooks }));
13772
13911
  console.log(t("uninstall.unified.state_dir"));
13773
13912
  console.log(t("uninstall.unified.upstream_note"));
13774
13913
  if (dryRun) {
@@ -13805,9 +13944,12 @@ async function runUnifiedUninstall(home, dryRun) {
13805
13944
  }
13806
13945
  }
13807
13946
  let removedSettings = false;
13808
- if (hasSettingsChanges) {
13947
+ let removedHooks = 0;
13948
+ if (hasSettingsChanges || staleHooks > 0) {
13809
13949
  try {
13810
- removedSettings = await removeSettingsEnv(settingsPath);
13950
+ const r = await removeSettingsFootprint(settingsPath);
13951
+ removedSettings = r.envRemoved;
13952
+ removedHooks = r.hooksRemoved;
13811
13953
  } catch (e) {
13812
13954
  failures.push(`${settingsPath}: ${e.message}`);
13813
13955
  }
@@ -13830,6 +13972,7 @@ async function runUnifiedUninstall(home, dryRun) {
13830
13972
  if (removedSkills > 0)
13831
13973
  console.log(t("uninstall.unified.removed_skills", { count: removedSkills }));
13832
13974
  if (removedSettings) console.log(t("uninstall.unified.removed_settings"));
13975
+ if (removedHooks > 0) console.log(t("uninstall.unified.removed_hooks", { count: removedHooks }));
13833
13976
  if (removedStateDir) console.log(t("uninstall.unified.removed_state_dir"));
13834
13977
  if (failures.length > 0) {
13835
13978
  console.error(t("uninstall.unified.partial_failure", { count: failures.length }));