harnessed 5.0.2 → 5.0.4

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.2",
40
+ version: "5.0.4",
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();
@@ -12731,6 +12736,23 @@ function extractGitCloneTarget(cmd, context) {
12731
12736
  if (dest.startsWith("/") || /^[A-Z]:[\\/]/i.test(dest)) return dest;
12732
12737
  return null;
12733
12738
  }
12739
+ function extractSingleSkillSelection(cmd) {
12740
+ const selections = [
12741
+ ...cmd.matchAll(
12742
+ /(?:^|\s)(?:--skill|-s)\s+['"]?([a-zA-Z0-9][a-zA-Z0-9._-]*)['"]?(?=\s+-|\s*$)/g
12743
+ )
12744
+ ];
12745
+ const selectionFlags = [...cmd.matchAll(/(?:^|\s)(?:--skill|-s)(?:\s|=)/g)];
12746
+ return selections.length === 1 && selectionFlags.length === 1 ? selections[0]?.[1] : void 0;
12747
+ }
12748
+ function npxActiveTargetNames(cmd, manifestName, installsSkills) {
12749
+ const selectedSkill = extractSingleSkillSelection(cmd);
12750
+ if (selectedSkill) return [selectedSkill];
12751
+ const indicators = INSTALLED_INDICATORS[manifestName];
12752
+ if (indicators?.length) return [...indicators];
12753
+ if (installsSkills?.length === 1 && installsSkills[0]) return [installsSkills[0]];
12754
+ return [extractSkillName(cmd, manifestName)];
12755
+ }
12734
12756
  function skillProbeDirs(context) {
12735
12757
  if (context)
12736
12758
  return [
@@ -12757,23 +12779,12 @@ async function indicatorPresent(name, context) {
12757
12779
  }
12758
12780
  return false;
12759
12781
  }
12760
- async function detectSkillPresence(cmd, name, context) {
12761
- if (await indicatorPresent(name, context)) return true;
12762
- const skillName = extractSkillName(cmd, name);
12763
- for (const skillsDir of skillProbeDirs(context)) {
12764
- try {
12765
- await access(join(skillsDir, skillName, "SKILL.md"));
12766
- return true;
12767
- } catch {
12768
- }
12769
- }
12770
- return false;
12771
- }
12772
12782
  async function detectNative(ctx) {
12773
12783
  const method = ctx.manifest.spec.install.method;
12774
12784
  const cmd = ctx.manifest.spec.install.cmd;
12775
12785
  const name = ctx.manifest.metadata.name;
12776
- if (await indicatorPresent(name, ctx.hostContext)) return true;
12786
+ if (method !== "npx-skill-installer" && await indicatorPresent(name, ctx.hostContext))
12787
+ return true;
12777
12788
  if (method === "mcp-stdio-add" || method === "mcp-http-add") {
12778
12789
  try {
12779
12790
  if (await (ctx.hostContext ? isMcpServerRegistered(name, ctx.hostContext) : isMcpServerRegistered(name)))
@@ -12791,13 +12802,18 @@ async function detectNative(ctx) {
12791
12802
  }
12792
12803
  }
12793
12804
  if (method === "npx-skill-installer") {
12794
- const skillName = extractSkillName(cmd, name);
12795
- for (const skillsDir of skillProbeDirs(ctx.hostContext)) {
12796
- const skillMd = join(skillsDir, skillName, "SKILL.md");
12797
- try {
12798
- await access(skillMd);
12799
- return true;
12800
- } catch {
12805
+ if (!extractSingleSkillSelection(cmd) && INSTALLED_INDICATORS[name]?.length) {
12806
+ if (await indicatorPresent(name, ctx.hostContext)) return true;
12807
+ } else {
12808
+ const targetNames = npxActiveTargetNames(cmd, name, ctx.manifest.spec.install.installs_skills);
12809
+ for (const skillsDir of skillProbeDirs(ctx.hostContext)) {
12810
+ for (const targetName of targetNames) {
12811
+ try {
12812
+ await access(join(skillsDir, targetName, "SKILL.md"));
12813
+ return true;
12814
+ } catch {
12815
+ }
12816
+ }
12801
12817
  }
12802
12818
  }
12803
12819
  }
@@ -14800,6 +14816,30 @@ function unprovenSkillTarget(ctx) {
14800
14816
  }
14801
14817
  };
14802
14818
  }
14819
+ async function activeSkillPresent(skillsDirs, names) {
14820
+ for (const skillsDir of skillsDirs) {
14821
+ for (const name of names) {
14822
+ if (await access(join(skillsDir, name, "SKILL.md")).then(
14823
+ () => true,
14824
+ () => false
14825
+ ))
14826
+ return true;
14827
+ }
14828
+ }
14829
+ return false;
14830
+ }
14831
+ async function activeTargetDirectoryExists(skillsDirs, names) {
14832
+ for (const skillsDir of skillsDirs) {
14833
+ for (const name of names) {
14834
+ if (await lstat(join(skillsDir, name)).then(
14835
+ () => true,
14836
+ (error) => error.code !== "ENOENT"
14837
+ ))
14838
+ return true;
14839
+ }
14840
+ }
14841
+ return false;
14842
+ }
14803
14843
  var HARD_CRASH_EXITS, HARD_CRASH_RETRY_DELAY_MS, installNpxSkillInstaller;
14804
14844
  var init_npxSkillInstaller2 = __esm({
14805
14845
  "src/installers/npxSkillInstaller.ts"() {
@@ -14854,13 +14894,32 @@ var init_npxSkillInstaller2 = __esm({
14854
14894
  };
14855
14895
  }
14856
14896
  const skillSegment = extractSkillName(install.cmd, ctx.manifest.metadata.name);
14857
- let existingTarget = false;
14897
+ const selections = [
14898
+ ...install.cmd.matchAll(
14899
+ /(?:^|\s)(?:--skill|-s)\s+['"]?([a-zA-Z0-9][a-zA-Z0-9._-]*)['"]?(?=\s+-|\s*$)/g
14900
+ )
14901
+ ];
14902
+ const selectionFlags = [...install.cmd.matchAll(/(?:^|\s)(?:--skill|-s)(?:\s|=)/g)];
14903
+ const selectedSkill = selections.length === 1 && selectionFlags.length === 1 ? selections[0]?.[1] : void 0;
14904
+ const activeTargetNames = npxActiveTargetNames(
14905
+ install.cmd,
14906
+ ctx.manifest.metadata.name,
14907
+ install.installs_skills
14908
+ );
14909
+ const activeSkillsDirs = ctx.hostContext ? [
14910
+ ...new Set(
14911
+ ctx.hostContext.hostId === "codex" ? [ctx.hostContext.platform.skillsDir, join(ctx.hostContext.nativeHome, "skills")] : [join(ctx.hostContext.nativeHome, "skills")]
14912
+ )
14913
+ ] : [getSkillsDir()];
14914
+ const primaryActiveSkillsDir = activeSkillsDirs[0] ?? getSkillsDir();
14915
+ let anyExistingTarget = false;
14858
14916
  if (ctx.hostContext) {
14859
14917
  const names = [.../* @__PURE__ */ new Set([skillSegment, ...install.installs_skills ?? []])];
14860
14918
  if (names.some((name2) => !/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(name2)))
14861
14919
  return unprovenSkillTarget(ctx);
14862
14920
  const roots = [
14863
14921
  .../* @__PURE__ */ new Set([
14922
+ ...activeSkillsDirs,
14864
14923
  ctx.hostContext.platform.skillsDir,
14865
14924
  join(ctx.hostContext.nativeHome, "skills"),
14866
14925
  join(ctx.hostContext.userHome, ".agents", "skills")
@@ -14871,21 +14930,18 @@ var init_npxSkillInstaller2 = __esm({
14871
14930
  if (await lstat(join(root, name2)).then(
14872
14931
  () => true,
14873
14932
  (error) => error.code !== "ENOENT"
14874
- ))
14875
- existingTarget = true;
14933
+ )) {
14934
+ anyExistingTarget = true;
14935
+ }
14876
14936
  }
14877
14937
  }
14878
- const selections = [
14879
- ...install.cmd.matchAll(
14880
- /(?:^|\s)(?:--skill|-s)\s+['"]?([a-zA-Z0-9][a-zA-Z0-9._-]*)['"]?(?=\s+-|\s*$)/g
14881
- )
14882
- ];
14883
- const selectionFlags = [...install.cmd.matchAll(/(?:^|\s)(?:--skill|-s)(?:\s|=)/g)];
14884
- const singleSkill = selections.length === 1 && selectionFlags.length === 1 && !/[;&|<>`$\r\n]/.test(install.cmd);
14885
- if (ctx.opts.updateInstalled && (!singleSkill || existingTarget || await isAlreadyInstalled(ctx, { honorUpdateFlag: false })))
14938
+ const singleSkill = selectedSkill !== void 0 && !/[;&|<>`$\r\n]/.test(install.cmd);
14939
+ if (ctx.opts.updateInstalled && (!singleSkill || anyExistingTarget || await isAlreadyInstalled(ctx, { honorUpdateFlag: false })))
14886
14940
  return unprovenSkillTarget(ctx);
14887
14941
  }
14888
- if (await isAlreadyInstalled(ctx)) {
14942
+ const activeTargetExists = await activeSkillPresent(activeSkillsDirs, activeTargetNames);
14943
+ const alreadyInstalled = ctx.hostContext ? !ctx.opts.dryRun && activeTargetExists : await isAlreadyInstalled(ctx);
14944
+ if (alreadyInstalled) {
14889
14945
  const verifyFailure2 = await verifyInstalled(ctx, { neutralCwd: true });
14890
14946
  if (verifyFailure2) return verifyFailure2;
14891
14947
  await recordObservedInstall(
@@ -14897,7 +14953,8 @@ var init_npxSkillInstaller2 = __esm({
14897
14953
  );
14898
14954
  return { ok: true, alreadyInstalled: true, backupId: "noop-idempotent" };
14899
14955
  }
14900
- if (existingTarget) return unprovenSkillTarget(ctx);
14956
+ if (ctx.hostContext && !activeTargetExists && await activeTargetDirectoryExists(activeSkillsDirs, activeTargetNames))
14957
+ return unprovenSkillTarget(ctx);
14901
14958
  const AGENT_BY_PLATFORM = {
14902
14959
  claude: "claude-code",
14903
14960
  codex: "codex"
@@ -14907,7 +14964,7 @@ var init_npxSkillInstaller2 = __esm({
14907
14964
  const hasExplicitAgent = /(?:^|\s)(?:--agent|-a)\s/.test(install.cmd);
14908
14965
  const effectiveCmd = agentId && !hasExplicitAgent ? `${install.cmd} --agent ${agentId}` : install.cmd;
14909
14966
  const name = ctx.manifest.metadata.name;
14910
- const skillDir = join(ctx.hostContext?.platform.skillsDir ?? getSkillsDir(), skillSegment);
14967
+ const skillDir = join(primaryActiveSkillsDir, skillSegment);
14911
14968
  const skillMdPath = join(skillDir, "SKILL.md");
14912
14969
  const plan = {
14913
14970
  files: [
@@ -14959,11 +15016,7 @@ var init_npxSkillInstaller2 = __esm({
14959
15016
  packSnapshot,
14960
15017
  ...ctx.hostContext ? [ctx.hostContext.platform.skillsDir] : []
14961
15018
  );
14962
- const present = await detectSkillPresence(
14963
- install.cmd,
14964
- name,
14965
- ...ctx.hostContext ? [ctx.hostContext] : []
14966
- );
15019
+ const present = await activeSkillPresent(activeSkillsDirs, activeTargetNames);
14967
15020
  if (!present) {
14968
15021
  return {
14969
15022
  ok: false,
@@ -15944,32 +15997,60 @@ var l4_rescue_exports = {};
15944
15997
  __export(l4_rescue_exports, {
15945
15998
  runL4Rescue: () => runL4Rescue
15946
15999
  });
15947
- async function runL4Rescue(manifestPaths, skipped, hostContext = captureHostInstallContext()) {
16000
+ async function runL4Rescue(manifestPaths, input, hostContext = captureHostInstallContext(), options = {}) {
16001
+ const legacyInput = Array.isArray(input);
15948
16002
  const out = { installed: [], skipped: [], failed: [] };
15949
- const targets = skipped.filter((s) => s.reason === "level-flag-missing");
15950
- if (targets.length === 0) return out;
16003
+ const normalized2 = legacyInput ? { skipped: input, failed: [] } : input;
16004
+ const candidates = /* @__PURE__ */ new Map();
16005
+ for (const entry of normalized2.skipped) {
16006
+ if (entry.reason === "level-flag-missing") {
16007
+ candidates.set(entry.name, { name: entry.name, updateInstalled: false });
16008
+ }
16009
+ }
16010
+ for (const failure of normalized2.failed) {
16011
+ const name = failure.split(": ", 1)[0] ?? failure;
16012
+ if (normalized2.failureKeywords?.[name] === "verify-failed" && normalized2.componentTypes?.[name] === "cli-binary") {
16013
+ candidates.set(name, { name, updateInstalled: true });
16014
+ }
16015
+ }
16016
+ if (candidates.size === 0) return out;
15951
16017
  const byName = /* @__PURE__ */ new Map();
15952
16018
  for (const path of manifestPaths) {
15953
16019
  try {
15954
16020
  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
- );
16021
+ if (v.ok) {
16022
+ byName.set(v.manifest.metadata.name, {
16023
+ path: path.replaceAll("\\", "/"),
16024
+ rawInstallType: v.manifest.spec.install_type,
16025
+ plan: resolveComponentPlan(v.manifest, hostContext, "install")
16026
+ });
16027
+ }
15960
16028
  } catch {
15961
16029
  }
15962
16030
  }
16031
+ const targets = [...candidates.values()].filter((target) => {
16032
+ if (!target.updateInstalled) return true;
16033
+ const resolved = byName.get(target.name);
16034
+ if (!resolved?.path.includes("/manifests/tools/")) return false;
16035
+ const spec = resolved.plan.manifest.spec;
16036
+ 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);
16037
+ });
16038
+ if (!legacyInput) {
16039
+ out.repairCandidates = targets.filter((target) => target.updateInstalled).map((target) => target.name);
16040
+ out.pending = targets.map((target) => target.name);
16041
+ }
16042
+ if (targets.length === 0 || options.interactive === false) return out;
15963
16043
  console.log(
15964
16044
  `
15965
16045
  ${targets.length} component(s) need a system-wide (L4) install \u2014 harnessed can run them now:`
15966
16046
  );
15967
16047
  for (const t2 of targets) {
15968
- const plan = byName.get(t2.name);
15969
- if (!plan) {
16048
+ const resolved = byName.get(t2.name);
16049
+ if (!resolved) {
15970
16050
  out.failed.push({ name: t2.name, reason: "manifest not found for L4 rescue" });
15971
16051
  continue;
15972
16052
  }
16053
+ const { plan } = resolved;
15973
16054
  if (plan.status === "unsupported") {
15974
16055
  out.skipped.push(t2.name);
15975
16056
  console.log(` skipped ${t2.name} (${plan.reason})`);
@@ -15996,7 +16077,7 @@ ${targets.length} component(s) need a system-wide (L4) install \u2014 harnessed
15996
16077
  // consent already given via the confirm above
15997
16078
  fullDiff: false,
15998
16079
  color: "auto",
15999
- updateInstalled: false,
16080
+ updateInstalled: t2.updateInstalled,
16000
16081
  quiet: true
16001
16082
  };
16002
16083
  const r = await runInstall(manifest, opts, plan.context);
@@ -20158,6 +20239,28 @@ async function makeIdempotentProbe(manifestPaths, context = captureHostInstallCo
20158
20239
  const selected = byName.get(name);
20159
20240
  if (!selected) return false;
20160
20241
  const { manifest, hostContext } = selected;
20242
+ if (manifest.spec.install.method === "npx-skill-installer") {
20243
+ const install = manifest.spec.install;
20244
+ const targets = npxActiveTargetNames(
20245
+ install.cmd,
20246
+ manifest.metadata.name,
20247
+ install.installs_skills
20248
+ );
20249
+ const roots = hostContext.hostId === "claude" ? [join(hostContext.nativeHome, "skills")] : [hostContext.platform.skillsDir, join(hostContext.nativeHome, "skills")];
20250
+ let activeSkillReadable = false;
20251
+ for (const root of roots) {
20252
+ for (const target of targets) {
20253
+ try {
20254
+ await readFile(join(root, target, "SKILL.md"), "utf8");
20255
+ activeSkillReadable = true;
20256
+ break;
20257
+ } catch {
20258
+ }
20259
+ }
20260
+ if (activeSkillReadable) break;
20261
+ }
20262
+ if (!activeSkillReadable) return false;
20263
+ }
20161
20264
  const opts = {
20162
20265
  apply: false,
20163
20266
  dryRun: false,
@@ -20424,6 +20527,26 @@ installing ${manifestPaths.length} upstream components (MCP serialized, rest par
20424
20527
  onProgress: progress.onProgress
20425
20528
  });
20426
20529
  progress.done();
20530
+ if (forceFirstPass && b.failed.length > 0) {
20531
+ const probe = await makeIdempotentProbe(manifestPaths, setupContext);
20532
+ const failed = [];
20533
+ for (const entry of b.failed) {
20534
+ const match = entry.match(/^([^:]+):\s*(.*)$/s);
20535
+ const name = (match?.[1] ?? entry).trim();
20536
+ let retained = false;
20537
+ if (b.failureKeywords?.[name] === "update-unsupported") {
20538
+ try {
20539
+ retained = await probe(name);
20540
+ } catch {
20541
+ }
20542
+ }
20543
+ if (retained) {
20544
+ b.keptExisting ??= [];
20545
+ b.keptExisting.push({ name, reason: match?.[2]?.trim() ?? "" });
20546
+ } else failed.push(entry);
20547
+ }
20548
+ b.failed = failed;
20549
+ }
20427
20550
  const stepBMs = (b.elapsedMs / 1e3).toFixed(1);
20428
20551
  console.log(
20429
20552
  t("setup.step_b_complete", {
@@ -20630,31 +20753,53 @@ Force-update pass complete: ${b2.installed.length} installed / ${b2.keptExisting
20630
20753
  }
20631
20754
  await enableAgentTeamsInSettings(setupContext);
20632
20755
  await enableUserLangInSettings(raw.userLang, setupContext);
20633
- if (!dryRun && raw.nonInteractive !== true && b.skipped.some((s) => s.reason === "level-flag-missing")) {
20756
+ let pendingNonInteractiveL4Repair = false;
20757
+ const hasL4RepairCandidate = b.skipped.some((s) => s.reason === "level-flag-missing") || b.failed.some((failure) => {
20758
+ const name = failure.split(": ", 1)[0] ?? failure;
20759
+ return b.failureKeywords?.[name] === "verify-failed" && b.componentTypes[name] === "cli-binary";
20760
+ });
20761
+ if (!dryRun && hasL4RepairCandidate) {
20634
20762
  const isTty = process.stdin.isTTY === true && process.stdout.isTTY === true;
20635
- if (isTty) {
20636
- const { runL4Rescue: runL4Rescue2 } = await Promise.resolve().then(() => (init_l4_rescue(), l4_rescue_exports));
20637
- const rescue = await runL4Rescue2(manifestPaths, b.skipped, setupContext);
20763
+ const interactive = isTty && raw.nonInteractive !== true;
20764
+ const { runL4Rescue: runL4Rescue2 } = await Promise.resolve().then(() => (init_l4_rescue(), l4_rescue_exports));
20765
+ const rescue = await runL4Rescue2(
20766
+ manifestPaths,
20767
+ {
20768
+ skipped: b.skipped,
20769
+ failed: b.failed,
20770
+ failureKeywords: b.failureKeywords,
20771
+ componentTypes: b.componentTypes
20772
+ },
20773
+ setupContext,
20774
+ { interactive }
20775
+ );
20776
+ pendingNonInteractiveL4Repair = !interactive && (rescue.pending?.length ?? 0) > 0;
20777
+ if (interactive) {
20778
+ const repairCandidates = new Set(rescue.repairCandidates ?? []);
20779
+ const resolved = /* @__PURE__ */ new Set([
20780
+ ...rescue.installed,
20781
+ ...rescue.failed.map((failure) => failure.name)
20782
+ ]);
20783
+ b.failed = b.failed.filter((failure) => {
20784
+ const name = failure.split(": ", 1)[0] ?? failure;
20785
+ return !resolved.has(name);
20786
+ });
20638
20787
  b.installed.push(...rescue.installed);
20639
20788
  for (const failure of rescue.failed) {
20640
20789
  const detail = `${failure.name}: ${failure.reason}`;
20641
20790
  b.failed.push(detail);
20642
20791
  console.error(` [L4 rescue] ${detail}`);
20643
20792
  }
20644
- const resolved = /* @__PURE__ */ new Set([
20645
- ...rescue.installed,
20646
- ...rescue.failed.map((failure) => failure.name)
20647
- ]);
20648
20793
  b.skipped = b.skipped.filter(
20649
- (skip) => skip.reason !== "level-flag-missing" || !resolved.has(skip.name)
20794
+ (skip) => skip.reason !== "level-flag-missing" || !resolved.has(skip.name) && !repairCandidates.has(skip.name)
20650
20795
  );
20651
20796
  }
20652
20797
  }
20653
- if (raw.system !== true && b.skipped.some(
20798
+ if (raw.system !== true && (pendingNonInteractiveL4Repair || b.skipped.some(
20654
20799
  (skip) => skip.reason === "level-flag-missing" || skip.reason.startsWith("L4 system-scope")
20655
- )) {
20800
+ ))) {
20656
20801
  console.warn(
20657
- "\nL4 system-wide installs remain skipped. To explicitly authorize them, run: harnessed setup --system --non-interactive"
20802
+ "\nL4 system-wide installs remain skipped or need repair. Run: harnessed setup --system --non-interactive --update-installed"
20658
20803
  );
20659
20804
  }
20660
20805
  let optionalFailed = 0;