harnessed 5.0.1 → 5.0.3

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
@@ -37,7 +37,7 @@ var init_package = __esm({
37
37
  "package.json"() {
38
38
  package_default = {
39
39
  name: "harnessed",
40
- version: "5.0.1",
40
+ version: "5.0.3",
41
41
  description: "AI coding harness package manager + composition orchestrator",
42
42
  type: "module",
43
43
  license: "Apache-2.0",
@@ -5914,13 +5914,18 @@ function sanitizeOutputTail(raw, cap = 160) {
5914
5914
  function sanitizeOutputTailEnd(raw, cap = 300) {
5915
5915
  const lines = raw.split(/\r?\n/).map((l) => l.replace(/[^\x20-\x7E]/g, "").trim()).filter((l) => l.length > 0);
5916
5916
  if (lines.length === 0) return "(unreadable output)";
5917
- let out = "";
5917
+ const exception = lines.find((line) => /^(?:Error|[A-Za-z]+Error)(?:\s*\[[^\]]+\])?:/.test(line));
5918
+ const tailCap = exception ? Math.max(0, cap - exception.length - 3) : cap;
5919
+ let tail = "";
5918
5920
  for (let i = lines.length - 1; i >= 0; i--) {
5919
- const cand = out ? `${lines[i]} | ${out}` : lines[i];
5920
- if (cand.length > cap) break;
5921
- out = cand;
5921
+ if (lines[i] === exception) continue;
5922
+ const cand = tail ? `${lines[i]} | ${tail}` : lines[i];
5923
+ if (cand.length > tailCap) break;
5924
+ tail = cand;
5922
5925
  }
5923
- return out || `${lines[lines.length - 1].slice(0, cap)}\u2026`;
5926
+ if (exception)
5927
+ return tail.length > 0 ? `${exception.slice(0, cap)} | ${tail}` : exception.slice(0, cap);
5928
+ return tail || `${lines[lines.length - 1].slice(0, cap)}\u2026`;
5924
5929
  }
5925
5930
  function formatSpawnFail(label, exitCode, stdout2, stderr) {
5926
5931
  const rawTail = stderr.trim() || stdout2.trim();
@@ -15944,32 +15949,60 @@ var l4_rescue_exports = {};
15944
15949
  __export(l4_rescue_exports, {
15945
15950
  runL4Rescue: () => runL4Rescue
15946
15951
  });
15947
- async function runL4Rescue(manifestPaths, skipped, hostContext = captureHostInstallContext()) {
15952
+ async function runL4Rescue(manifestPaths, input, hostContext = captureHostInstallContext(), options = {}) {
15953
+ const legacyInput = Array.isArray(input);
15948
15954
  const out = { installed: [], skipped: [], failed: [] };
15949
- const targets = skipped.filter((s) => s.reason === "level-flag-missing");
15950
- if (targets.length === 0) return out;
15955
+ const normalized2 = legacyInput ? { skipped: input, failed: [] } : input;
15956
+ const candidates = /* @__PURE__ */ new Map();
15957
+ for (const entry of normalized2.skipped) {
15958
+ if (entry.reason === "level-flag-missing") {
15959
+ candidates.set(entry.name, { name: entry.name, updateInstalled: false });
15960
+ }
15961
+ }
15962
+ for (const failure of normalized2.failed) {
15963
+ const name = failure.split(": ", 1)[0] ?? failure;
15964
+ if (normalized2.failureKeywords?.[name] === "verify-failed" && normalized2.componentTypes?.[name] === "cli-binary") {
15965
+ candidates.set(name, { name, updateInstalled: true });
15966
+ }
15967
+ }
15968
+ if (candidates.size === 0) return out;
15951
15969
  const byName = /* @__PURE__ */ new Map();
15952
15970
  for (const path of manifestPaths) {
15953
15971
  try {
15954
15972
  const v = validateManifestFile(await readFile(path, "utf8"), path);
15955
- if (v.ok)
15956
- byName.set(
15957
- v.manifest.metadata.name,
15958
- resolveComponentPlan(v.manifest, hostContext, "install")
15959
- );
15973
+ if (v.ok) {
15974
+ byName.set(v.manifest.metadata.name, {
15975
+ path: path.replaceAll("\\", "/"),
15976
+ rawInstallType: v.manifest.spec.install_type,
15977
+ plan: resolveComponentPlan(v.manifest, hostContext, "install")
15978
+ });
15979
+ }
15960
15980
  } catch {
15961
15981
  }
15962
15982
  }
15983
+ const targets = [...candidates.values()].filter((target) => {
15984
+ if (!target.updateInstalled) return true;
15985
+ const resolved = byName.get(target.name);
15986
+ if (!resolved?.path.includes("/manifests/tools/")) return false;
15987
+ const spec = resolved.plan.manifest.spec;
15988
+ return resolved.rawInstallType === "npm" && resolved.plan.status === "supported" && spec.type === "cli-npm" && spec.component_type === "cli-binary" && spec.install_type === "npm" && spec.install.method === "npm-cli" && /\bnpm\s+install\s+-g\b/.test(spec.install.cmd);
15989
+ });
15990
+ if (!legacyInput) {
15991
+ out.repairCandidates = targets.filter((target) => target.updateInstalled).map((target) => target.name);
15992
+ out.pending = targets.map((target) => target.name);
15993
+ }
15994
+ if (targets.length === 0 || options.interactive === false) return out;
15963
15995
  console.log(
15964
15996
  `
15965
15997
  ${targets.length} component(s) need a system-wide (L4) install \u2014 harnessed can run them now:`
15966
15998
  );
15967
15999
  for (const t2 of targets) {
15968
- const plan = byName.get(t2.name);
15969
- if (!plan) {
16000
+ const resolved = byName.get(t2.name);
16001
+ if (!resolved) {
15970
16002
  out.failed.push({ name: t2.name, reason: "manifest not found for L4 rescue" });
15971
16003
  continue;
15972
16004
  }
16005
+ const { plan } = resolved;
15973
16006
  if (plan.status === "unsupported") {
15974
16007
  out.skipped.push(t2.name);
15975
16008
  console.log(` skipped ${t2.name} (${plan.reason})`);
@@ -15996,7 +16029,7 @@ ${targets.length} component(s) need a system-wide (L4) install \u2014 harnessed
15996
16029
  // consent already given via the confirm above
15997
16030
  fullDiff: false,
15998
16031
  color: "auto",
15999
- updateInstalled: false,
16032
+ updateInstalled: t2.updateInstalled,
16000
16033
  quiet: true
16001
16034
  };
16002
16035
  const r = await runInstall(manifest, opts, plan.context);
@@ -20022,6 +20055,7 @@ async function runStepBInstall(manifestPaths, runOpts = {}) {
20022
20055
  };
20023
20056
  const start = Date.now();
20024
20057
  const componentTypes = {};
20058
+ const failureKeywords = {};
20025
20059
  const total = manifestPaths.length;
20026
20060
  let done = 0;
20027
20061
  const emit = (entry) => {
@@ -20068,6 +20102,7 @@ async function runStepBInstall(manifestPaths, runOpts = {}) {
20068
20102
  if (r.ok && "alreadyInstalled" in r && r.alreadyInstalled)
20069
20103
  return emit({ status: "already-installed", name });
20070
20104
  if (r.ok) return emit({ status: "installed", name });
20105
+ if (r.error.keyword) failureKeywords[name] = r.error.keyword;
20071
20106
  return emit({ status: "failed", name, reason: r.error.message });
20072
20107
  } catch (e) {
20073
20108
  return emit({ status: "failed", name, reason: String(e) });
@@ -20102,6 +20137,7 @@ async function runStepBInstall(manifestPaths, runOpts = {}) {
20102
20137
  alreadyInstalled,
20103
20138
  skipped,
20104
20139
  failed,
20140
+ failureKeywords,
20105
20141
  elapsedMs: Date.now() - start,
20106
20142
  componentTypes
20107
20143
  };
@@ -20114,6 +20150,10 @@ async function reclassifyForceUpdateFailures(firstPass, forcePass, probe) {
20114
20150
  const m = entry.match(/^([^:]+):\s*(.*)$/s);
20115
20151
  const name = (m?.[1] ?? entry).trim();
20116
20152
  if (priorlyInstalled.has(name)) {
20153
+ if (forcePass.failureKeywords?.[name] === "update-unsupported") {
20154
+ keptExisting.push({ name, reason: m?.[2]?.trim() ?? "" });
20155
+ continue;
20156
+ }
20117
20157
  let present = false;
20118
20158
  try {
20119
20159
  present = await probe(name);
@@ -20623,31 +20663,53 @@ Force-update pass complete: ${b2.installed.length} installed / ${b2.keptExisting
20623
20663
  }
20624
20664
  await enableAgentTeamsInSettings(setupContext);
20625
20665
  await enableUserLangInSettings(raw.userLang, setupContext);
20626
- if (!dryRun && raw.nonInteractive !== true && b.skipped.some((s) => s.reason === "level-flag-missing")) {
20666
+ let pendingNonInteractiveL4Repair = false;
20667
+ const hasL4RepairCandidate = b.skipped.some((s) => s.reason === "level-flag-missing") || b.failed.some((failure) => {
20668
+ const name = failure.split(": ", 1)[0] ?? failure;
20669
+ return b.failureKeywords?.[name] === "verify-failed" && b.componentTypes[name] === "cli-binary";
20670
+ });
20671
+ if (!dryRun && hasL4RepairCandidate) {
20627
20672
  const isTty = process.stdin.isTTY === true && process.stdout.isTTY === true;
20628
- if (isTty) {
20629
- const { runL4Rescue: runL4Rescue2 } = await Promise.resolve().then(() => (init_l4_rescue(), l4_rescue_exports));
20630
- const rescue = await runL4Rescue2(manifestPaths, b.skipped, setupContext);
20673
+ const interactive = isTty && raw.nonInteractive !== true;
20674
+ const { runL4Rescue: runL4Rescue2 } = await Promise.resolve().then(() => (init_l4_rescue(), l4_rescue_exports));
20675
+ const rescue = await runL4Rescue2(
20676
+ manifestPaths,
20677
+ {
20678
+ skipped: b.skipped,
20679
+ failed: b.failed,
20680
+ failureKeywords: b.failureKeywords,
20681
+ componentTypes: b.componentTypes
20682
+ },
20683
+ setupContext,
20684
+ { interactive }
20685
+ );
20686
+ pendingNonInteractiveL4Repair = !interactive && (rescue.pending?.length ?? 0) > 0;
20687
+ if (interactive) {
20688
+ const repairCandidates = new Set(rescue.repairCandidates ?? []);
20689
+ const resolved = /* @__PURE__ */ new Set([
20690
+ ...rescue.installed,
20691
+ ...rescue.failed.map((failure) => failure.name)
20692
+ ]);
20693
+ b.failed = b.failed.filter((failure) => {
20694
+ const name = failure.split(": ", 1)[0] ?? failure;
20695
+ return !resolved.has(name);
20696
+ });
20631
20697
  b.installed.push(...rescue.installed);
20632
20698
  for (const failure of rescue.failed) {
20633
20699
  const detail = `${failure.name}: ${failure.reason}`;
20634
20700
  b.failed.push(detail);
20635
20701
  console.error(` [L4 rescue] ${detail}`);
20636
20702
  }
20637
- const resolved = /* @__PURE__ */ new Set([
20638
- ...rescue.installed,
20639
- ...rescue.failed.map((failure) => failure.name)
20640
- ]);
20641
20703
  b.skipped = b.skipped.filter(
20642
- (skip) => skip.reason !== "level-flag-missing" || !resolved.has(skip.name)
20704
+ (skip) => skip.reason !== "level-flag-missing" || !resolved.has(skip.name) && !repairCandidates.has(skip.name)
20643
20705
  );
20644
20706
  }
20645
20707
  }
20646
- if (raw.system !== true && b.skipped.some(
20708
+ if (raw.system !== true && (pendingNonInteractiveL4Repair || b.skipped.some(
20647
20709
  (skip) => skip.reason === "level-flag-missing" || skip.reason.startsWith("L4 system-scope")
20648
- )) {
20710
+ ))) {
20649
20711
  console.warn(
20650
- "\nL4 system-wide installs remain skipped. To explicitly authorize them, run: harnessed setup --system --non-interactive"
20712
+ "\nL4 system-wide installs remain skipped or need repair. Run: harnessed setup --system --non-interactive --update-installed"
20651
20713
  );
20652
20714
  }
20653
20715
  let optionalFailed = 0;