harnessed 4.32.5 → 4.32.7

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.
@@ -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.5",
41
+ version: "4.32.7",
42
42
  description: "AI coding harness package manager + composition orchestrator",
43
43
  type: "module",
44
44
  license: "Apache-2.0",
@@ -6930,45 +6930,152 @@ var init_check_install_channels = __esm({
6930
6930
  init_assetsRoot();
6931
6931
  }
6932
6932
  });
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;
6933
+ function isRelativeFileToken(token) {
6934
+ if (!/[\\/]/.test(token)) return false;
6935
+ if (ABSOLUTE_RE.test(token)) return false;
6936
+ if (/[*?$`]/.test(token)) return false;
6937
+ return true;
6938
+ }
6939
+ function stripQuotes(token) {
6940
+ const m = token.match(/^"(.*)"$/);
6941
+ if (m?.[1] !== void 0) return { bare: m[1], quoted: true };
6942
+ return { bare: token, quoted: false };
6943
+ }
6944
+ function resolveHookCommand(raw, deps) {
6945
+ const marker = deps.compiledExecPath ? hookScriptMarker(raw) : null;
6946
+ if (deps.compiledExecPath && marker && COMPILED_HOOK_IDENTITIES.includes(marker)) {
6947
+ const exe = deps.compiledExecPath();
6948
+ if (exe) return `"${exe.replace(/\\/g, "/")}" ${marker}`;
6939
6949
  }
6940
- return null;
6950
+ let root = null;
6951
+ const tokens = raw.split(/\s+/).filter((t2) => t2.length > 0);
6952
+ const out = tokens.map((token) => {
6953
+ const { bare: bare2 } = stripQuotes(token);
6954
+ if (!isRelativeFileToken(bare2)) return token;
6955
+ root = root ?? deps.assetsRoot();
6956
+ const abs = join(root, bare2);
6957
+ if (!deps.exists(abs)) return token;
6958
+ return `"${abs.replace(/\\/g, "/")}"`;
6959
+ });
6960
+ return out.join(" ");
6941
6961
  }
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];
6962
+ function hookScriptMarker(raw) {
6963
+ for (const token of raw.split(/\s+/)) {
6964
+ const { bare: bare2 } = stripQuotes(token);
6965
+ if (isRelativeFileToken(bare2)) {
6966
+ const seg = bare2.split(/[\\/]/);
6967
+ const base = seg[seg.length - 1] ?? null;
6968
+ const id = COMPILED_HOOK_IDENTITIES.find((k) => base?.includes(k));
6969
+ if (id) return id;
6970
+ return base;
6971
+ }
6972
+ }
6973
+ for (const token of raw.split(/\s+/)) {
6974
+ const { bare: bare2 } = stripQuotes(token);
6975
+ if (COMPILED_HOOK_IDENTITIES.includes(bare2)) return bare2;
6976
+ }
6949
6977
  return null;
6950
6978
  }
6951
6979
  function entryCommands(entry) {
6980
+ if (!entry || typeof entry !== "object") return [];
6952
6981
  const cmds = [];
6953
6982
  if (typeof entry.command === "string") cmds.push(entry.command);
6954
6983
  if (Array.isArray(entry.hooks)) {
6955
- for (const h of entry.hooks) if (h && typeof h.command === "string") cmds.push(h.command);
6984
+ for (const h of entry.hooks) {
6985
+ if (h && typeof h.command === "string") cmds.push(h.command);
6986
+ }
6956
6987
  }
6957
6988
  return cmds;
6958
6989
  }
6959
- function entryIsHarnessed(entry) {
6960
- return entryCommands(entry).some((c) => harnessedHookIdentity(c) !== null);
6990
+ function entryMatchesRegistration(entry, raw, resolved, marker) {
6991
+ const cmds = entryCommands(entry);
6992
+ if (cmds.length === 0) return false;
6993
+ if (marker) return cmds.some((c) => c.includes(marker));
6994
+ return cmds.some((c) => c === raw || c === resolved);
6995
+ }
6996
+ function desiredHookEntry(matcher, resolvedCmd) {
6997
+ return {
6998
+ ...matcher !== void 0 ? { matcher } : {},
6999
+ hooks: [{ type: "command", command: resolvedCmd }]
7000
+ };
7001
+ }
7002
+ function isDesiredHookEntry(entry, matcher, resolvedCmd) {
7003
+ if (typeof entry.command === "string") return false;
7004
+ if (entry.matcher !== matcher) return false;
7005
+ if (!Array.isArray(entry.hooks) || entry.hooks.length !== 1) return false;
7006
+ const h = entry.hooks[0];
7007
+ return !!h && h.type === "command" && h.command === resolvedCmd;
7008
+ }
7009
+ function detectCcHookInstalled(settingsRaw, ev, raw, matcher, deps) {
7010
+ if (settingsRaw === null) return false;
7011
+ let parsed;
7012
+ try {
7013
+ parsed = JSON.parse(settingsRaw);
7014
+ } catch {
7015
+ return false;
7016
+ }
7017
+ const arr = parsed.hooks?.[ev];
7018
+ if (!Array.isArray(arr)) return false;
7019
+ const resolved = resolveHookCommand(raw, deps);
7020
+ const marker = hookScriptMarker(raw);
7021
+ const matching = arr.filter((e) => entryMatchesRegistration(e, raw, resolved, marker));
7022
+ return matching.length === 1 && isDesiredHookEntry(matching[0] ?? {}, matcher, resolved);
7023
+ }
7024
+ var COMPILED_HOOK_IDENTITIES, ABSOLUTE_RE;
7025
+ var init_hookEntry = __esm({
7026
+ "src/installers/lib/hookEntry.ts"() {
7027
+ COMPILED_HOOK_IDENTITIES = ["inject-state", "stop-hook"];
7028
+ ABSOLUTE_RE = /^([A-Za-z]:[\\/]|[\\/])/;
7029
+ }
7030
+ });
7031
+
7032
+ // src/installers/lib/harnessedHookTeardown.ts
7033
+ function harnessedHookIdentity(raw) {
7034
+ for (const id of COMPILED_HOOK_IDENTITIES) {
7035
+ if (new RegExp(`${LEFT}harnessed-${id}\\.mjs(?:["']|\\s|$)`).test(raw)) return id;
7036
+ if (new RegExp(`${LEFT}harnessed(?:\\.exe)?["']?\\s+${id}(?:\\s|$)`).test(raw)) return id;
7037
+ }
7038
+ return null;
7039
+ }
7040
+ function harnessedHookScriptPath(raw) {
7041
+ const qMjs = raw.match(new RegExp(`"([^"]*harnessed-(?:${ID_ALT})\\.mjs)"`)) ?? raw.match(new RegExp(`'([^']*harnessed-(?:${ID_ALT})\\.mjs)'`));
7042
+ if (qMjs?.[1]) return qMjs[1];
7043
+ const uMjs = raw.match(new RegExp(`(?:^|\\s)([^\\s"']*harnessed-(?:${ID_ALT})\\.mjs)`));
7044
+ if (uMjs?.[1]) return uMjs[1];
7045
+ const qBin = raw.match(new RegExp(`"([^"]*harnessed(?:\\.exe)?)"\\s+(?:${ID_ALT})\\b`)) ?? raw.match(new RegExp(`'([^']*harnessed(?:\\.exe)?)'\\s+(?:${ID_ALT})\\b`));
7046
+ if (qBin?.[1]) return qBin[1];
7047
+ const bBin = raw.match(new RegExp(`(?:^|\\s)(harnessed(?:\\.exe)?)\\s+(?:${ID_ALT})\\b`));
7048
+ if (bBin?.[1]) return bBin[1];
7049
+ return null;
7050
+ }
7051
+ function isHarnessedCmd(cmd) {
7052
+ return harnessedHookIdentity(cmd) !== null;
6961
7053
  }
6962
7054
  function stripHarnessedHooks(hooks) {
6963
7055
  let removed = 0;
6964
7056
  for (const ev of Object.keys(hooks)) {
6965
7057
  const arr = hooks[ev];
6966
7058
  if (!Array.isArray(arr)) continue;
6967
- const kept = arr.filter((entry) => {
6968
- const owned = entryIsHarnessed(entry);
6969
- if (owned) removed++;
6970
- return !owned;
6971
- });
7059
+ const kept = [];
7060
+ for (const entry of arr) {
7061
+ if (!entry || typeof entry !== "object") {
7062
+ kept.push(entry);
7063
+ continue;
7064
+ }
7065
+ if (typeof entry.command === "string" && isHarnessedCmd(entry.command)) {
7066
+ removed++;
7067
+ continue;
7068
+ }
7069
+ if (Array.isArray(entry.hooks)) {
7070
+ const before = entry.hooks.length;
7071
+ entry.hooks = entry.hooks.filter(
7072
+ (h) => !(h && typeof h.command === "string" && isHarnessedCmd(h.command))
7073
+ );
7074
+ removed += before - entry.hooks.length;
7075
+ if (entry.hooks.length === 0 && typeof entry.command !== "string") continue;
7076
+ }
7077
+ kept.push(entry);
7078
+ }
6972
7079
  if (kept.length === 0) delete hooks[ev];
6973
7080
  else hooks[ev] = kept;
6974
7081
  }
@@ -6978,7 +7085,7 @@ function countHarnessedHooks(hooks) {
6978
7085
  let n = 0;
6979
7086
  for (const arr of Object.values(hooks)) {
6980
7087
  if (!Array.isArray(arr)) continue;
6981
- for (const entry of arr) if (entryIsHarnessed(entry)) n++;
7088
+ for (const entry of arr) n += entryCommands(entry).filter(isHarnessedCmd).length;
6982
7089
  }
6983
7090
  return n;
6984
7091
  }
@@ -6990,17 +7097,24 @@ function harnessedStaleHookPaths(hooks, exists) {
6990
7097
  for (const cmd of entryCommands(entry)) {
6991
7098
  if (harnessedHookIdentity(cmd) === null) continue;
6992
7099
  const path = harnessedHookScriptPath(cmd);
6993
- if (path && ABSOLUTE_RE.test(path) && !exists(path)) out.push({ event, path });
7100
+ if (!path) continue;
7101
+ if (ABSOLUTE_RE2.test(path)) {
7102
+ if (!exists(path)) out.push({ event, path });
7103
+ } else if (/\.mjs$/.test(path)) {
7104
+ out.push({ event, path });
7105
+ }
6994
7106
  }
6995
7107
  }
6996
7108
  }
6997
7109
  return out;
6998
7110
  }
6999
- var IDS, ABSOLUTE_RE;
7111
+ var ID_ALT, LEFT, ABSOLUTE_RE2;
7000
7112
  var init_harnessedHookTeardown = __esm({
7001
7113
  "src/installers/lib/harnessedHookTeardown.ts"() {
7002
- IDS = ["inject-state", "stop-hook"];
7003
- ABSOLUTE_RE = /^([A-Za-z]:[\\/]|[\\/])/;
7114
+ init_hookEntry();
7115
+ ID_ALT = COMPILED_HOOK_IDENTITIES.join("|");
7116
+ LEFT = `(?:^|[\\s"'=/\\\\])`;
7117
+ ABSOLUTE_RE2 = /^([A-Za-z]:[\\/]|[\\/])/;
7004
7118
  }
7005
7119
  });
7006
7120
 
@@ -7031,7 +7145,12 @@ function checkStaleHooks(deps) {
7031
7145
  if (!hooks || typeof hooks !== "object") {
7032
7146
  return { name: NAME, status: "pass", message: "no hooks registered" };
7033
7147
  }
7034
- const stale = harnessedStaleHookPaths(hooks, exists);
7148
+ let stale;
7149
+ try {
7150
+ stale = harnessedStaleHookPaths(hooks, exists);
7151
+ } catch {
7152
+ return { name: NAME, status: "pass", message: "hooks unreadable \u2014 skipped" };
7153
+ }
7035
7154
  if (stale.length === 0) {
7036
7155
  return { name: NAME, status: "pass", message: "no orphaned harnessed hooks" };
7037
7156
  }
@@ -7039,7 +7158,7 @@ function checkStaleHooks(deps) {
7039
7158
  return {
7040
7159
  name: NAME,
7041
7160
  status: "warn",
7042
- message: `${stale.length} harnessed hook(s) point at a deleted script \u2014 Claude Code errors MODULE_NOT_FOUND every prompt (${list})`,
7161
+ message: `${stale.length} harnessed hook(s) point at a missing/unresolvable script \u2014 Claude Code errors MODULE_NOT_FOUND every prompt (${list})`,
7043
7162
  fix: `run 'harnessed uninstall' to strip them, or delete the matching Stop/UserPromptSubmit entries from ${settingsPath}`
7044
7163
  };
7045
7164
  }
@@ -7561,103 +7680,6 @@ var init_err = __esm({
7561
7680
  "src/installers/lib/err.ts"() {
7562
7681
  }
7563
7682
  });
7564
- function isRelativeFileToken(token) {
7565
- if (!/[\\/]/.test(token)) return false;
7566
- if (ABSOLUTE_RE2.test(token)) return false;
7567
- if (/[*?$`]/.test(token)) return false;
7568
- return true;
7569
- }
7570
- function stripQuotes(token) {
7571
- const m = token.match(/^"(.*)"$/);
7572
- if (m?.[1] !== void 0) return { bare: m[1], quoted: true };
7573
- return { bare: token, quoted: false };
7574
- }
7575
- function resolveHookCommand(raw, deps) {
7576
- const marker = deps.compiledExecPath ? hookScriptMarker(raw) : null;
7577
- if (deps.compiledExecPath && marker && COMPILED_HOOK_IDENTITIES.includes(marker)) {
7578
- const exe = deps.compiledExecPath();
7579
- if (exe) return `"${exe.replace(/\\/g, "/")}" ${marker}`;
7580
- }
7581
- let root = null;
7582
- const tokens = raw.split(/\s+/).filter((t2) => t2.length > 0);
7583
- const out = tokens.map((token) => {
7584
- const { bare: bare2 } = stripQuotes(token);
7585
- if (!isRelativeFileToken(bare2)) return token;
7586
- root = root ?? deps.assetsRoot();
7587
- const abs = join(root, bare2);
7588
- if (!deps.exists(abs)) return token;
7589
- return `"${abs.replace(/\\/g, "/")}"`;
7590
- });
7591
- return out.join(" ");
7592
- }
7593
- function hookScriptMarker(raw) {
7594
- for (const token of raw.split(/\s+/)) {
7595
- const { bare: bare2 } = stripQuotes(token);
7596
- if (isRelativeFileToken(bare2)) {
7597
- const seg = bare2.split(/[\\/]/);
7598
- const base = seg[seg.length - 1] ?? null;
7599
- const id = COMPILED_HOOK_IDENTITIES.find((k) => base?.includes(k));
7600
- if (id) return id;
7601
- return base;
7602
- }
7603
- }
7604
- for (const token of raw.split(/\s+/)) {
7605
- const { bare: bare2 } = stripQuotes(token);
7606
- if (COMPILED_HOOK_IDENTITIES.includes(bare2)) return bare2;
7607
- }
7608
- return null;
7609
- }
7610
- function entryCommands2(entry) {
7611
- const cmds = [];
7612
- if (typeof entry.command === "string") cmds.push(entry.command);
7613
- if (Array.isArray(entry.hooks)) {
7614
- for (const h of entry.hooks) {
7615
- if (h && typeof h.command === "string") cmds.push(h.command);
7616
- }
7617
- }
7618
- return cmds;
7619
- }
7620
- function entryMatchesRegistration(entry, raw, resolved, marker) {
7621
- const cmds = entryCommands2(entry);
7622
- if (cmds.length === 0) return false;
7623
- if (marker) return cmds.some((c) => c.includes(marker));
7624
- return cmds.some((c) => c === raw || c === resolved);
7625
- }
7626
- function desiredHookEntry(matcher, resolvedCmd) {
7627
- return {
7628
- ...matcher !== void 0 ? { matcher } : {},
7629
- hooks: [{ type: "command", command: resolvedCmd }]
7630
- };
7631
- }
7632
- function isDesiredHookEntry(entry, matcher, resolvedCmd) {
7633
- if (typeof entry.command === "string") return false;
7634
- if (entry.matcher !== matcher) return false;
7635
- if (!Array.isArray(entry.hooks) || entry.hooks.length !== 1) return false;
7636
- const h = entry.hooks[0];
7637
- return !!h && h.type === "command" && h.command === resolvedCmd;
7638
- }
7639
- function detectCcHookInstalled(settingsRaw, ev, raw, matcher, deps) {
7640
- if (settingsRaw === null) return false;
7641
- let parsed;
7642
- try {
7643
- parsed = JSON.parse(settingsRaw);
7644
- } catch {
7645
- return false;
7646
- }
7647
- const arr = parsed.hooks?.[ev];
7648
- if (!Array.isArray(arr)) return false;
7649
- const resolved = resolveHookCommand(raw, deps);
7650
- const marker = hookScriptMarker(raw);
7651
- const matching = arr.filter((e) => entryMatchesRegistration(e, raw, resolved, marker));
7652
- return matching.length === 1 && isDesiredHookEntry(matching[0] ?? {}, matcher, resolved);
7653
- }
7654
- var COMPILED_HOOK_IDENTITIES, ABSOLUTE_RE2;
7655
- var init_hookEntry = __esm({
7656
- "src/installers/lib/hookEntry.ts"() {
7657
- COMPILED_HOOK_IDENTITIES = ["inject-state", "stop-hook"];
7658
- ABSOLUTE_RE2 = /^([A-Za-z]:[\\/]|[\\/])/;
7659
- }
7660
- });
7661
7683
 
7662
7684
  // src/installers/lib/preflight.ts
7663
7685
  function preflight(ctx) {