harnessed 4.19.0 → 4.20.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.
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.19.0",
41
+ version: "4.20.0",
42
42
  description: "AI coding harness package manager + composition orchestrator",
43
43
  type: "module",
44
44
  license: "Apache-2.0",
@@ -106,7 +106,8 @@ var init_package = __esm({
106
106
  bench: "vitest bench --run",
107
107
  lint: "biome check .",
108
108
  "lint:fix": "biome check --write .",
109
- format: "biome format --write ."
109
+ format: "biome format --write .",
110
+ "build:binary": "bun scripts/build-binary.mjs"
110
111
  },
111
112
  dependencies: {
112
113
  "@anthropic-ai/claude-agent-sdk": "0.3.142",
@@ -1857,9 +1858,19 @@ function safeIntlLocale() {
1857
1858
  return void 0;
1858
1859
  }
1859
1860
  }
1861
+ function wireMessagesDir(provider) {
1862
+ wiredMessagesDirProvider = provider;
1863
+ }
1860
1864
  function messagesDir() {
1861
1865
  const here = dirname(fileURLToPath(import.meta.url));
1862
- const candidates = [resolve(here, "..", "..", "messages"), resolve(here, "..", "messages")];
1866
+ const candidates = [];
1867
+ if (wiredMessagesDirProvider) {
1868
+ try {
1869
+ candidates.push(wiredMessagesDirProvider());
1870
+ } catch {
1871
+ }
1872
+ }
1873
+ candidates.push(resolve(here, "..", "..", "messages"), resolve(here, "..", "messages"));
1863
1874
  for (const c of candidates) {
1864
1875
  try {
1865
1876
  readFileSync(join(c, "en.json"), "utf8");
@@ -1903,13 +1914,14 @@ function t(key, params) {
1903
1914
  return v === void 0 ? `{{${name}}}` : String(v);
1904
1915
  });
1905
1916
  }
1906
- var SUPPORTED, currentLocale, cache;
1917
+ var SUPPORTED, currentLocale, cache, wiredMessagesDirProvider;
1907
1918
  var init_i18n = __esm({
1908
1919
  "src/i18n/index.ts"() {
1909
1920
  init_en();
1910
1921
  SUPPORTED = /* @__PURE__ */ new Set(["en", "zh-Hans"]);
1911
1922
  currentLocale = null;
1912
1923
  cache = {};
1924
+ wiredMessagesDirProvider = null;
1913
1925
  }
1914
1926
  });
1915
1927
  function getBackupRoot() {
@@ -3852,6 +3864,7 @@ var init_packagePath = __esm({
3852
3864
  // src/cli/lib/assetsRoot.ts
3853
3865
  var assetsRoot_exports = {};
3854
3866
  __export(assetsRoot_exports, {
3867
+ compiledAssetsDir: () => compiledAssetsDir,
3855
3868
  computeAssetsRoot: () => computeAssetsRoot,
3856
3869
  getAssetsRoot: () => getAssetsRoot,
3857
3870
  isCompiledModuleUrl: () => isCompiledModuleUrl
@@ -3877,6 +3890,9 @@ function computeAssetsRoot(d) {
3877
3890
  }
3878
3891
  return { root: d.packageRoot, source: "package", compiledAssetsMissing: false };
3879
3892
  }
3893
+ function compiledAssetsDir(version) {
3894
+ return join(detectPlatform().stateRoot, "assets", version);
3895
+ }
3880
3896
  function realDeps() {
3881
3897
  return {
3882
3898
  env: process.env,
@@ -5654,6 +5670,90 @@ var init_err = __esm({
5654
5670
  "src/installers/lib/err.ts"() {
5655
5671
  }
5656
5672
  });
5673
+ function isRelativeFileToken(token) {
5674
+ if (!/[\\/]/.test(token)) return false;
5675
+ if (ABSOLUTE_RE.test(token)) return false;
5676
+ if (/[*?$`]/.test(token)) return false;
5677
+ return true;
5678
+ }
5679
+ function stripQuotes(token) {
5680
+ const m = token.match(/^"(.*)"$/);
5681
+ if (m?.[1] !== void 0) return { bare: m[1], quoted: true };
5682
+ return { bare: token, quoted: false };
5683
+ }
5684
+ function resolveHookCommand(raw, deps) {
5685
+ let root = null;
5686
+ const tokens = raw.split(/\s+/).filter((t2) => t2.length > 0);
5687
+ const out = tokens.map((token) => {
5688
+ const { bare: bare2 } = stripQuotes(token);
5689
+ if (!isRelativeFileToken(bare2)) return token;
5690
+ root = root ?? deps.assetsRoot();
5691
+ const abs = join(root, bare2);
5692
+ if (!deps.exists(abs)) return token;
5693
+ return abs.includes(" ") ? `"${abs}"` : abs;
5694
+ });
5695
+ return out.join(" ");
5696
+ }
5697
+ function hookScriptMarker(raw) {
5698
+ for (const token of raw.split(/\s+/)) {
5699
+ const { bare: bare2 } = stripQuotes(token);
5700
+ if (isRelativeFileToken(bare2)) {
5701
+ const seg = bare2.split(/[\\/]/);
5702
+ return seg[seg.length - 1] ?? null;
5703
+ }
5704
+ }
5705
+ return null;
5706
+ }
5707
+ function entryCommands(entry) {
5708
+ const cmds = [];
5709
+ if (typeof entry.command === "string") cmds.push(entry.command);
5710
+ if (Array.isArray(entry.hooks)) {
5711
+ for (const h of entry.hooks) {
5712
+ if (h && typeof h.command === "string") cmds.push(h.command);
5713
+ }
5714
+ }
5715
+ return cmds;
5716
+ }
5717
+ function entryMatchesRegistration(entry, raw, resolved, marker) {
5718
+ const cmds = entryCommands(entry);
5719
+ if (cmds.length === 0) return false;
5720
+ if (marker) return cmds.some((c) => c.includes(marker));
5721
+ return cmds.some((c) => c === raw || c === resolved);
5722
+ }
5723
+ function desiredHookEntry(matcher, resolvedCmd) {
5724
+ return {
5725
+ ...matcher !== void 0 ? { matcher } : {},
5726
+ hooks: [{ type: "command", command: resolvedCmd }]
5727
+ };
5728
+ }
5729
+ function isDesiredHookEntry(entry, matcher, resolvedCmd) {
5730
+ if (typeof entry.command === "string") return false;
5731
+ if (entry.matcher !== matcher) return false;
5732
+ if (!Array.isArray(entry.hooks) || entry.hooks.length !== 1) return false;
5733
+ const h = entry.hooks[0];
5734
+ return !!h && h.type === "command" && h.command === resolvedCmd;
5735
+ }
5736
+ function detectCcHookInstalled(settingsRaw, ev, raw, matcher, deps) {
5737
+ if (settingsRaw === null) return false;
5738
+ let parsed;
5739
+ try {
5740
+ parsed = JSON.parse(settingsRaw);
5741
+ } catch {
5742
+ return false;
5743
+ }
5744
+ const arr = parsed.hooks?.[ev];
5745
+ if (!Array.isArray(arr)) return false;
5746
+ const resolved = resolveHookCommand(raw, deps);
5747
+ const marker = hookScriptMarker(raw);
5748
+ const matching = arr.filter((e) => entryMatchesRegistration(e, raw, resolved, marker));
5749
+ return matching.length === 1 && isDesiredHookEntry(matching[0] ?? {}, matcher, resolved);
5750
+ }
5751
+ var ABSOLUTE_RE;
5752
+ var init_hookEntry = __esm({
5753
+ "src/installers/lib/hookEntry.ts"() {
5754
+ ABSOLUTE_RE = /^([A-Za-z]:[\\/]|[\\/])/;
5755
+ }
5756
+ });
5657
5757
 
5658
5758
  // src/installers/lib/preflight.ts
5659
5759
  function preflight(ctx) {
@@ -5757,10 +5857,12 @@ var init_state2 = __esm({
5757
5857
  var installCcHookAdd;
5758
5858
  var init_ccHookAdd2 = __esm({
5759
5859
  "src/installers/ccHookAdd.ts"() {
5860
+ init_assetsRoot();
5760
5861
  init_backup();
5761
5862
  init_confirm();
5762
5863
  init_diff();
5763
5864
  init_err();
5865
+ init_hookEntry();
5764
5866
  init_platform();
5765
5867
  init_preflight();
5766
5868
  init_state2();
@@ -5811,11 +5913,16 @@ var init_ccHookAdd2 = __esm({
5811
5913
  const ev = install.hook_event;
5812
5914
  const matcher = install.hook_matcher;
5813
5915
  const cmd = install.hook_command;
5814
- settings.hooks[ev] = settings.hooks[ev] ?? [];
5815
- if (settings.hooks[ev].some((h) => h.command === cmd && h.matcher === matcher)) {
5916
+ const cmdDeps = { assetsRoot: getAssetsRoot, exists: existsSync };
5917
+ const resolvedCmd = resolveHookCommand(cmd, cmdDeps);
5918
+ const marker = hookScriptMarker(cmd);
5919
+ const arr = settings.hooks[ev] ?? [];
5920
+ const ours = arr.filter((e) => entryMatchesRegistration(e, cmd, resolvedCmd, marker));
5921
+ if (ours.length === 1 && isDesiredHookEntry(ours[0] ?? {}, matcher, resolvedCmd)) {
5816
5922
  return { ok: true, backupId: "idempotent-skip", appliedFiles: [] };
5817
5923
  }
5818
- settings.hooks[ev].push({ matcher, command: cmd });
5924
+ const others = arr.filter((e) => !entryMatchesRegistration(e, cmd, resolvedCmd, marker));
5925
+ settings.hooks[ev] = [...others, desiredHookEntry(matcher, resolvedCmd)];
5819
5926
  const newText = `${JSON.stringify(settings, null, 2)}
5820
5927
  `;
5821
5928
  const plan = {
@@ -5847,7 +5954,7 @@ var init_ccHookAdd2 = __esm({
5847
5954
  )
5848
5955
  };
5849
5956
  }
5850
- if (!verify.hooks?.[ev]?.some((h) => h.command === cmd)) {
5957
+ if (!verify.hooks?.[ev]?.some((e) => isDesiredHookEntry(e, matcher, resolvedCmd))) {
5851
5958
  return {
5852
5959
  ok: false,
5853
5960
  phase: "verify",
@@ -5855,7 +5962,7 @@ var init_ccHookAdd2 = __esm({
5855
5962
  error: err(
5856
5963
  ctx,
5857
5964
  "/spec/install/hook_command",
5858
- `hook '${cmd.slice(0, 80)}' missing in hooks.${ev}[] after write`,
5965
+ `hook '${resolvedCmd.slice(0, 80)}' missing in hooks.${ev}[] after write`,
5859
5966
  "verify-failed"
5860
5967
  )
5861
5968
  };
@@ -6236,6 +6343,25 @@ async function isAlreadyInstalled(ctx, opts = {}) {
6236
6343
  const honorUpdateFlag = opts.honorUpdateFlag !== false;
6237
6344
  if (honorUpdateFlag && ctx.opts.updateInstalled === true) return false;
6238
6345
  if (ctx.opts.dryRun) return false;
6346
+ const installCfg = ctx.manifest.spec.install;
6347
+ if (installCfg.method === "cc-hook-add") {
6348
+ let raw;
6349
+ try {
6350
+ raw = await readFile(getSettingsPath(), "utf8");
6351
+ } catch {
6352
+ raw = null;
6353
+ }
6354
+ return detectCcHookInstalled(
6355
+ raw,
6356
+ installCfg.hook_event,
6357
+ installCfg.hook_command,
6358
+ installCfg.hook_matcher,
6359
+ {
6360
+ assetsRoot: getAssetsRoot,
6361
+ exists: existsSync
6362
+ }
6363
+ );
6364
+ }
6239
6365
  const native = await detectNative(ctx);
6240
6366
  if (native) return true;
6241
6367
  const idempotentCmd = ctx.manifest.spec.install.idempotent_check;
@@ -6249,7 +6375,9 @@ async function isAlreadyInstalled(ctx, opts = {}) {
6249
6375
  var IDEMPOTENT_CHECK_TIMEOUT_MS, INSTALLED_INDICATORS;
6250
6376
  var init_idempotent = __esm({
6251
6377
  "src/installers/lib/idempotent.ts"() {
6378
+ init_assetsRoot();
6252
6379
  init_binaryProbe();
6380
+ init_hookEntry();
6253
6381
  init_platform();
6254
6382
  init_readClaudeConfig();
6255
6383
  init_spawn();
@@ -8959,6 +9087,9 @@ function registerLearn(program2) {
8959
9087
  });
8960
9088
  }
8961
9089
 
9090
+ // src/cli.ts
9091
+ init_assetsRoot();
9092
+
8962
9093
  // src/cli/lib/here.ts
8963
9094
  init_nextStep();
8964
9095
  init_i18n();
@@ -10547,6 +10678,8 @@ init_path_guard();
10547
10678
  init_validate();
10548
10679
 
10549
10680
  // src/uninstallers/ccHookAdd.ts
10681
+ init_assetsRoot();
10682
+ init_hookEntry();
10550
10683
  init_platform();
10551
10684
 
10552
10685
  // src/uninstallers/lib/runOrPreview.ts
@@ -10582,13 +10715,14 @@ var uninstallCcHookAdd = async (ctx) => {
10582
10715
  }
10583
10716
  const ev = install.hook_event;
10584
10717
  const cmd = install.hook_command;
10585
- const matcher = install.hook_matcher;
10586
10718
  if (!settings.hooks?.[ev]) {
10587
10719
  return { ok: true, removedPaths: [] };
10588
10720
  }
10721
+ const resolved = resolveHookCommand(cmd, { assetsRoot: getAssetsRoot, exists: existsSync });
10722
+ const marker = hookScriptMarker(cmd);
10589
10723
  const before = settings.hooks[ev].length;
10590
10724
  settings.hooks[ev] = settings.hooks[ev].filter(
10591
- (h) => !(h.command === cmd && h.matcher === matcher)
10725
+ (h) => !entryMatchesRegistration(h, cmd, resolved, marker)
10592
10726
  );
10593
10727
  if (settings.hooks[ev].length === 0) delete settings.hooks[ev];
10594
10728
  if (Object.keys(settings.hooks).length === 0) delete settings.hooks;
@@ -11137,6 +11271,7 @@ function registerWorkflows(program2) {
11137
11271
  // src/cli.ts
11138
11272
  init_i18n();
11139
11273
  init_harnessedRoot();
11274
+ wireMessagesDir(() => join(getAssetsRoot(), "messages"));
11140
11275
  migrateLegacyHarnessedRoot();
11141
11276
  var argv = process.argv;
11142
11277
  for (let i = 2; i < argv.length; i++) {