harnessed 4.15.1 → 4.15.2

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
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { existsSync, mkdirSync, renameSync, writeFileSync, readFileSync, readdirSync, statSync } from 'fs';
3
3
  import { homedir } from 'os';
4
- import { join, dirname, resolve, sep, relative } from 'path';
4
+ import { join, dirname, resolve, sep, win32, relative } from 'path';
5
5
  import { Type } from '@sinclair/typebox';
6
6
  import { readFile, readdir, unlink, writeFile, stat, rm, cp, mkdir, rename, access, appendFile } from 'fs/promises';
7
7
  import { Value } from '@sinclair/typebox/value';
@@ -38,7 +38,7 @@ var init_package = __esm({
38
38
  "package.json"() {
39
39
  package_default = {
40
40
  name: "harnessed",
41
- version: "4.15.1",
41
+ version: "4.15.2",
42
42
  description: "AI coding harness package manager + composition orchestrator",
43
43
  type: "module",
44
44
  license: "Apache-2.0",
@@ -4411,6 +4411,16 @@ var init_breakLoop = __esm({
4411
4411
  LOOP_THRESHOLD = 3;
4412
4412
  }
4413
4413
  });
4414
+ function realProbe(p6) {
4415
+ try {
4416
+ if (typeof spawnSync !== "function") return null;
4417
+ const r = spawnSync(p6, ["-c", "echo harnessed-bash-ok"], { encoding: "utf8", timeout: 5e3 });
4418
+ if (!r || r.error) return null;
4419
+ return r.status === 0;
4420
+ } catch {
4421
+ return null;
4422
+ }
4423
+ }
4414
4424
  function realWhere(name) {
4415
4425
  try {
4416
4426
  if (typeof spawnSync !== "function") return [];
@@ -4433,7 +4443,8 @@ function defaultDeps() {
4433
4443
  platform: process.platform,
4434
4444
  env: process.env,
4435
4445
  where: realWhere,
4436
- exists: realExists
4446
+ exists: realExists,
4447
+ probe: realProbe
4437
4448
  };
4438
4449
  }
4439
4450
  function resolveBash(deps) {
@@ -4452,45 +4463,65 @@ function compute(d) {
4452
4463
  const pathLines = d.where("bash");
4453
4464
  const first = pathLines[0];
4454
4465
  const wslOnPath = first && WSL_STUB_RE.test(first) ? first : void 0;
4455
- if (first && !WSL_STUB_RE.test(first)) {
4466
+ const usable = (p6) => !WSL_STUB_RE.test(p6) && d.probe(p6) !== false;
4467
+ if (first && usable(first)) {
4456
4468
  return { path: first, source: "path" };
4457
4469
  }
4458
4470
  const gitFirst = d.where("git")[0];
4459
4471
  if (gitFirst && /git\.exe$/i.test(gitFirst)) {
4460
- const root = dirname(dirname(gitFirst));
4461
- for (const cand of [join(root, "bin", "bash.exe"), join(root, "usr", "bin", "bash.exe")]) {
4462
- if (d.exists(cand)) return { path: cand, source: "git-derived", wslOnPath };
4472
+ const root = dirname8(dirname8(gitFirst));
4473
+ for (const cand of [join17(root, "bin", "bash.exe"), join17(root, "usr", "bin", "bash.exe")]) {
4474
+ if (d.exists(cand) && usable(cand)) return { path: cand, source: "git-derived", wslOnPath };
4463
4475
  }
4464
4476
  }
4465
4477
  const bases = [
4466
4478
  d.env.ProgramFiles,
4467
4479
  d.env.ProgramW6432,
4468
4480
  d.env["ProgramFiles(x86)"],
4469
- d.env.LOCALAPPDATA ? join(d.env.LOCALAPPDATA, "Programs") : void 0
4481
+ d.env.LOCALAPPDATA ? join17(d.env.LOCALAPPDATA, "Programs") : void 0
4470
4482
  ];
4471
4483
  for (const base of bases) {
4472
4484
  if (!base) continue;
4473
4485
  for (const cand of [
4474
- join(base, "Git", "bin", "bash.exe"),
4475
- join(base, "Git", "usr", "bin", "bash.exe")
4486
+ join17(base, "Git", "bin", "bash.exe"),
4487
+ join17(base, "Git", "usr", "bin", "bash.exe")
4476
4488
  ]) {
4477
- if (d.exists(cand)) return { path: cand, source: "standard-location", wslOnPath };
4489
+ if (d.exists(cand) && usable(cand))
4490
+ return { path: cand, source: "standard-location", wslOnPath };
4478
4491
  }
4479
4492
  }
4480
- const laterNonWsl = pathLines.find((l) => !WSL_STUB_RE.test(l));
4481
- if (laterNonWsl) return { path: laterNonWsl, source: "path", wslOnPath };
4493
+ const laterUsable = pathLines.slice(1).find((l) => usable(l));
4494
+ if (laterUsable) return { path: laterUsable, source: "path", wslOnPath };
4482
4495
  if (pathLines.length > 0) {
4483
- return { path: null, source: "path", reason: "wsl-only", wslOnPath: first };
4496
+ return { path: null, source: "path", reason: "wsl-only", wslOnPath: wslOnPath ?? first };
4484
4497
  }
4485
4498
  return { path: "bash", source: "path-fallback" };
4486
4499
  }
4487
- var WSL_STUB_RE, cache2;
4500
+ var dirname8, join17, WSL_STUB_RE, cache2;
4488
4501
  var init_resolveBash = __esm({
4489
4502
  "src/installers/lib/resolveBash.ts"() {
4490
- WSL_STUB_RE = /[\\/]windows[\\/](system32|sysnative|syswow64)[\\/]bash\.exe$/i;
4503
+ ({ dirname: dirname8, join: join17 } = win32);
4504
+ WSL_STUB_RE = /[\\/](windows[\\/](system32|sysnative|syswow64)|microsoft[\\/]windowsapps)[\\/]bash\.exe$/i;
4491
4505
  cache2 = null;
4492
4506
  }
4493
4507
  });
4508
+
4509
+ // src/installers/lib/verifyMessage.ts
4510
+ function sanitizeOutputTail(raw, cap = 160) {
4511
+ const firstNonEmpty = raw.split(/\r?\n/).find((l) => l.trim().length > 0) ?? "";
4512
+ const printable = firstNonEmpty.replace(/[^\x20-\x7E]/g, "").trim();
4513
+ return printable.length > 0 ? printable.slice(0, cap) : "(unreadable output)";
4514
+ }
4515
+ function formatVerifyFail(cmd, exitCode, expected, stdout2, stderr) {
4516
+ const cmdPart = cmd.length > 80 ? `${cmd.slice(0, 80)}\u2026` : cmd;
4517
+ const rawTail = stderr.trim() || stdout2.trim();
4518
+ const tail = rawTail.length > 0 ? sanitizeOutputTail(rawTail) : "(no output)";
4519
+ return `verify failed (exit ${exitCode} \u2260 expected ${expected}): \`${cmdPart}\` \u2014 ${tail}`;
4520
+ }
4521
+ var init_verifyMessage = __esm({
4522
+ "src/installers/lib/verifyMessage.ts"() {
4523
+ }
4524
+ });
4494
4525
  function checkNodeVersion() {
4495
4526
  const v = process.versions.node;
4496
4527
  const major = Number.parseInt(v.split(".")[0] ?? "0", 10);
@@ -4547,12 +4578,17 @@ function checkJq() {
4547
4578
  };
4548
4579
  }
4549
4580
  const fix = process.platform === "win32" ? "winget install jqlang.jq (or: scoop install jq)" : process.platform === "darwin" ? "brew install jq" : "apt-get install jq (or: dnf install jq)";
4550
- return { name: "jq present", status: "fail", message: "jq not found in PATH", fix };
4581
+ const installCmd = process.platform === "win32" ? "winget install jqlang.jq" : process.platform === "darwin" ? "brew install jq" : "apt-get install -y jq";
4582
+ return {
4583
+ name: "jq present",
4584
+ status: "warn",
4585
+ message: "jq not found in PATH (optional \u2014 needed by `harnessed audit-log --filter` and the ralph-loop plugin on Windows)",
4586
+ fix,
4587
+ install_commands: [installCmd]
4588
+ };
4551
4589
  }
4552
4590
  function sanitizeToolOutput(raw, cap = 60) {
4553
- const first = raw.split(/\r?\n/)[0] ?? "";
4554
- const printable = first.replace(/[^\x20-\x7E]/g, "").trim();
4555
- return printable.length > 0 ? printable.slice(0, cap) : "(unreadable output)";
4591
+ return sanitizeOutputTail(raw, cap);
4556
4592
  }
4557
4593
  function checkWinBash() {
4558
4594
  if (process.platform !== "win32") {
@@ -4593,6 +4629,7 @@ var init_check_builtin = __esm({
4593
4629
  "src/cli/lib/check-builtin.ts"() {
4594
4630
  init_platform();
4595
4631
  init_resolveBash();
4632
+ init_verifyMessage();
4596
4633
  }
4597
4634
  });
4598
4635
 
@@ -5637,6 +5674,11 @@ function expandTildeForWindows(cmd) {
5637
5674
  const home = homedir().replace(/\\/g, "/");
5638
5675
  return cmd.replace(/(^|[\s"'`(])~\//g, `$1${home}/`);
5639
5676
  }
5677
+ function needsPosixShell(cmd) {
5678
+ if (POSIX_SYNTAX_RE.test(cmd)) return true;
5679
+ const firstToken = cmd.trim().split(/\s+/)[0]?.toLowerCase() ?? "";
5680
+ return POSIX_FIRST_TOKENS.has(firstToken);
5681
+ }
5640
5682
  async function spawnCmd(ctx, cmd, args, timeoutMs, opts) {
5641
5683
  const violation = checkCmdString(cmd);
5642
5684
  if (violation) {
@@ -5666,7 +5708,7 @@ async function spawnCmd(ctx, cmd, args, timeoutMs, opts) {
5666
5708
  let triedBash = false;
5667
5709
  const stdio = ["ignore", "pipe", "pipe"];
5668
5710
  if (process.platform === "win32") {
5669
- if (opts?.posixShell) {
5711
+ if (opts?.posixShell && needsPosixShell(joinedCmd)) {
5670
5712
  const bash = resolveBash();
5671
5713
  if (bash.path === null) {
5672
5714
  return {
@@ -5716,8 +5758,9 @@ async function spawnCmd(ctx, cmd, args, timeoutMs, opts) {
5716
5758
  path: "/spec/install/cmd",
5717
5759
  // v4.15.1 — fall back to stdout when stderr is empty (WSL stubs and
5718
5760
  // some CLIs write their error text to stdout; a bare trailing colon
5719
- // read as "no reason" in user dogfood).
5720
- message: `spawn timed out after ${effectiveTimeoutMs}ms (cmd: ${cmd}); partial output: ${(stderr || stdout2).slice(0, 200) || "(no output)"}`,
5761
+ // read as "no reason" in user dogfood). v4.15.2 — sanitized (CP936
5762
+ // mojibake was embedded verbatim in the ctx7 dogfood error).
5763
+ message: `spawn timed out after ${effectiveTimeoutMs}ms (cmd: ${cmd}); partial output: ${(stderr || stdout2).trim() ? sanitizeOutputTail(stderr || stdout2, 200) : "(no output)"}`,
5721
5764
  line: null,
5722
5765
  column: null,
5723
5766
  keyword: "spawn-timeout"
@@ -5746,12 +5789,38 @@ async function spawnCmd(ctx, cmd, args, timeoutMs, opts) {
5746
5789
  });
5747
5790
  });
5748
5791
  }
5749
- var DEFAULT_VERIFY_TIMEOUT_MS, DEFAULT_INSTALL_TIMEOUT_MS;
5792
+ var POSIX_SYNTAX_RE, POSIX_FIRST_TOKENS, DEFAULT_VERIFY_TIMEOUT_MS, DEFAULT_INSTALL_TIMEOUT_MS;
5750
5793
  var init_spawn = __esm({
5751
5794
  "src/installers/lib/spawn.ts"() {
5752
5795
  init_security();
5753
5796
  init_nativeTest();
5754
5797
  init_resolveBash();
5798
+ init_verifyMessage();
5799
+ POSIX_SYNTAX_RE = /[|;<>`$~[\]{}()*?!]|&&/;
5800
+ POSIX_FIRST_TOKENS = /* @__PURE__ */ new Set([
5801
+ "test",
5802
+ "grep",
5803
+ "rm",
5804
+ "cp",
5805
+ "mv",
5806
+ "mkdir",
5807
+ "ls",
5808
+ "cat",
5809
+ "cd",
5810
+ "sh",
5811
+ "bash",
5812
+ "command",
5813
+ "find",
5814
+ "sed",
5815
+ "awk",
5816
+ "touch",
5817
+ "ln",
5818
+ "chmod",
5819
+ "head",
5820
+ "tail",
5821
+ "which",
5822
+ "echo"
5823
+ ]);
5755
5824
  DEFAULT_VERIFY_TIMEOUT_MS = 15e3;
5756
5825
  DEFAULT_INSTALL_TIMEOUT_MS = 3e5;
5757
5826
  }
@@ -6107,17 +6176,6 @@ ${newEntry}
6107
6176
  };
6108
6177
  }
6109
6178
  });
6110
-
6111
- // src/installers/lib/verifyMessage.ts
6112
- function formatVerifyFail(cmd, exitCode, expected, stdout2, stderr) {
6113
- const cmdPart = cmd.length > 80 ? `${cmd.slice(0, 80)}\u2026` : cmd;
6114
- const tail = stderr.trim().slice(0, 160) || stdout2.trim().slice(0, 160) || "(no output)";
6115
- return `verify failed (exit ${exitCode} \u2260 expected ${expected}): \`${cmdPart}\` \u2014 ${tail}`;
6116
- }
6117
- var init_verifyMessage = __esm({
6118
- "src/installers/lib/verifyMessage.ts"() {
6119
- }
6120
- });
6121
6179
  function gitRevParseHead(cwd, timeoutMs = 1e4) {
6122
6180
  return new Promise((resolve17) => {
6123
6181
  const isWin = process.platform === "win32";
@@ -9642,7 +9700,8 @@ async function reclassifyForceUpdateFailures(firstPass, forcePass, probe) {
9642
9700
  const failed = [];
9643
9701
  const keptExisting = [];
9644
9702
  for (const entry of forcePass.failed) {
9645
- const name = (entry.match(/^([^:]+):/)?.[1] ?? entry).trim();
9703
+ const m = entry.match(/^([^:]+):\s*(.*)$/s);
9704
+ const name = (m?.[1] ?? entry).trim();
9646
9705
  if (priorlyInstalled.has(name)) {
9647
9706
  let present = false;
9648
9707
  try {
@@ -9651,7 +9710,7 @@ async function reclassifyForceUpdateFailures(firstPass, forcePass, probe) {
9651
9710
  present = false;
9652
9711
  }
9653
9712
  if (present) {
9654
- keptExisting.push(name);
9713
+ keptExisting.push({ name, reason: m?.[2]?.trim() ?? "" });
9655
9714
  continue;
9656
9715
  }
9657
9716
  }
@@ -9781,12 +9840,14 @@ function printGrouped(b, prefix = "") {
9781
9840
  for (const s of b.skipped)
9782
9841
  push(groupOf(s.name), { status: "skipped", name: s.name, note: s.reason });
9783
9842
  for (const n of b.alreadyInstalled) push(groupOf(n), { status: "already-installed", name: n });
9784
- for (const n of b.keptExisting ?? [])
9785
- push(groupOf(n), {
9843
+ for (const k of b.keptExisting ?? []) {
9844
+ const why = k.reason ? `refresh failed: ${k.reason.slice(0, 90)}` : "refresh failed";
9845
+ push(groupOf(k.name), {
9786
9846
  status: "kept-existing",
9787
- name: n,
9788
- note: "refresh failed, prior version retained"
9847
+ name: k.name,
9848
+ note: `${why} \u2014 prior version retained`
9789
9849
  });
9850
+ }
9790
9851
  for (const g of GROUP_ORDER) {
9791
9852
  const entries = buckets[g];
9792
9853
  if (!entries || entries.length === 0) continue;