harnessed 5.0.3 → 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.3",
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",
@@ -12736,6 +12736,23 @@ function extractGitCloneTarget(cmd, context) {
12736
12736
  if (dest.startsWith("/") || /^[A-Z]:[\\/]/i.test(dest)) return dest;
12737
12737
  return null;
12738
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
+ }
12739
12756
  function skillProbeDirs(context) {
12740
12757
  if (context)
12741
12758
  return [
@@ -12762,23 +12779,12 @@ async function indicatorPresent(name, context) {
12762
12779
  }
12763
12780
  return false;
12764
12781
  }
12765
- async function detectSkillPresence(cmd, name, context) {
12766
- if (await indicatorPresent(name, context)) return true;
12767
- const skillName = extractSkillName(cmd, name);
12768
- for (const skillsDir of skillProbeDirs(context)) {
12769
- try {
12770
- await access(join(skillsDir, skillName, "SKILL.md"));
12771
- return true;
12772
- } catch {
12773
- }
12774
- }
12775
- return false;
12776
- }
12777
12782
  async function detectNative(ctx) {
12778
12783
  const method = ctx.manifest.spec.install.method;
12779
12784
  const cmd = ctx.manifest.spec.install.cmd;
12780
12785
  const name = ctx.manifest.metadata.name;
12781
- if (await indicatorPresent(name, ctx.hostContext)) return true;
12786
+ if (method !== "npx-skill-installer" && await indicatorPresent(name, ctx.hostContext))
12787
+ return true;
12782
12788
  if (method === "mcp-stdio-add" || method === "mcp-http-add") {
12783
12789
  try {
12784
12790
  if (await (ctx.hostContext ? isMcpServerRegistered(name, ctx.hostContext) : isMcpServerRegistered(name)))
@@ -12796,13 +12802,18 @@ async function detectNative(ctx) {
12796
12802
  }
12797
12803
  }
12798
12804
  if (method === "npx-skill-installer") {
12799
- const skillName = extractSkillName(cmd, name);
12800
- for (const skillsDir of skillProbeDirs(ctx.hostContext)) {
12801
- const skillMd = join(skillsDir, skillName, "SKILL.md");
12802
- try {
12803
- await access(skillMd);
12804
- return true;
12805
- } 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
+ }
12806
12817
  }
12807
12818
  }
12808
12819
  }
@@ -14805,6 +14816,30 @@ function unprovenSkillTarget(ctx) {
14805
14816
  }
14806
14817
  };
14807
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
+ }
14808
14843
  var HARD_CRASH_EXITS, HARD_CRASH_RETRY_DELAY_MS, installNpxSkillInstaller;
14809
14844
  var init_npxSkillInstaller2 = __esm({
14810
14845
  "src/installers/npxSkillInstaller.ts"() {
@@ -14859,13 +14894,32 @@ var init_npxSkillInstaller2 = __esm({
14859
14894
  };
14860
14895
  }
14861
14896
  const skillSegment = extractSkillName(install.cmd, ctx.manifest.metadata.name);
14862
- 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;
14863
14916
  if (ctx.hostContext) {
14864
14917
  const names = [.../* @__PURE__ */ new Set([skillSegment, ...install.installs_skills ?? []])];
14865
14918
  if (names.some((name2) => !/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(name2)))
14866
14919
  return unprovenSkillTarget(ctx);
14867
14920
  const roots = [
14868
14921
  .../* @__PURE__ */ new Set([
14922
+ ...activeSkillsDirs,
14869
14923
  ctx.hostContext.platform.skillsDir,
14870
14924
  join(ctx.hostContext.nativeHome, "skills"),
14871
14925
  join(ctx.hostContext.userHome, ".agents", "skills")
@@ -14876,21 +14930,18 @@ var init_npxSkillInstaller2 = __esm({
14876
14930
  if (await lstat(join(root, name2)).then(
14877
14931
  () => true,
14878
14932
  (error) => error.code !== "ENOENT"
14879
- ))
14880
- existingTarget = true;
14933
+ )) {
14934
+ anyExistingTarget = true;
14935
+ }
14881
14936
  }
14882
14937
  }
14883
- const selections = [
14884
- ...install.cmd.matchAll(
14885
- /(?:^|\s)(?:--skill|-s)\s+['"]?([a-zA-Z0-9][a-zA-Z0-9._-]*)['"]?(?=\s+-|\s*$)/g
14886
- )
14887
- ];
14888
- const selectionFlags = [...install.cmd.matchAll(/(?:^|\s)(?:--skill|-s)(?:\s|=)/g)];
14889
- const singleSkill = selections.length === 1 && selectionFlags.length === 1 && !/[;&|<>`$\r\n]/.test(install.cmd);
14890
- 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 })))
14891
14940
  return unprovenSkillTarget(ctx);
14892
14941
  }
14893
- 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) {
14894
14945
  const verifyFailure2 = await verifyInstalled(ctx, { neutralCwd: true });
14895
14946
  if (verifyFailure2) return verifyFailure2;
14896
14947
  await recordObservedInstall(
@@ -14902,7 +14953,8 @@ var init_npxSkillInstaller2 = __esm({
14902
14953
  );
14903
14954
  return { ok: true, alreadyInstalled: true, backupId: "noop-idempotent" };
14904
14955
  }
14905
- if (existingTarget) return unprovenSkillTarget(ctx);
14956
+ if (ctx.hostContext && !activeTargetExists && await activeTargetDirectoryExists(activeSkillsDirs, activeTargetNames))
14957
+ return unprovenSkillTarget(ctx);
14906
14958
  const AGENT_BY_PLATFORM = {
14907
14959
  claude: "claude-code",
14908
14960
  codex: "codex"
@@ -14912,7 +14964,7 @@ var init_npxSkillInstaller2 = __esm({
14912
14964
  const hasExplicitAgent = /(?:^|\s)(?:--agent|-a)\s/.test(install.cmd);
14913
14965
  const effectiveCmd = agentId && !hasExplicitAgent ? `${install.cmd} --agent ${agentId}` : install.cmd;
14914
14966
  const name = ctx.manifest.metadata.name;
14915
- const skillDir = join(ctx.hostContext?.platform.skillsDir ?? getSkillsDir(), skillSegment);
14967
+ const skillDir = join(primaryActiveSkillsDir, skillSegment);
14916
14968
  const skillMdPath = join(skillDir, "SKILL.md");
14917
14969
  const plan = {
14918
14970
  files: [
@@ -14964,11 +15016,7 @@ var init_npxSkillInstaller2 = __esm({
14964
15016
  packSnapshot,
14965
15017
  ...ctx.hostContext ? [ctx.hostContext.platform.skillsDir] : []
14966
15018
  );
14967
- const present = await detectSkillPresence(
14968
- install.cmd,
14969
- name,
14970
- ...ctx.hostContext ? [ctx.hostContext] : []
14971
- );
15019
+ const present = await activeSkillPresent(activeSkillsDirs, activeTargetNames);
14972
15020
  if (!present) {
14973
15021
  return {
14974
15022
  ok: false,
@@ -20191,6 +20239,28 @@ async function makeIdempotentProbe(manifestPaths, context = captureHostInstallCo
20191
20239
  const selected = byName.get(name);
20192
20240
  if (!selected) return false;
20193
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
+ }
20194
20264
  const opts = {
20195
20265
  apply: false,
20196
20266
  dryRun: false,
@@ -20457,6 +20527,26 @@ installing ${manifestPaths.length} upstream components (MCP serialized, rest par
20457
20527
  onProgress: progress.onProgress
20458
20528
  });
20459
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
+ }
20460
20550
  const stepBMs = (b.elapsedMs / 1e3).toFixed(1);
20461
20551
  console.log(
20462
20552
  t("setup.step_b_complete", {