@acidicsoil/portable-capabilities 0.1.3 → 0.1.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.
@@ -1823,8 +1823,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
1823
1823
  } else if (fn instanceof RegExp) {
1824
1824
  const regex = fn;
1825
1825
  fn = (val, def) => {
1826
- const m = regex.exec(val);
1827
- return m ? m[0] : def;
1826
+ const m2 = regex.exec(val);
1827
+ return m2 ? m2[0] : def;
1828
1828
  };
1829
1829
  option.default(defaultValue).argParser(fn);
1830
1830
  } else {
@@ -13956,8 +13956,8 @@ function block({
13956
13956
  return;
13957
13957
  }
13958
13958
  if (!o2) return;
13959
- const i3 = a3 === "return" ? 0 : -1, m = a3 === "return" ? -1 : 0;
13960
- l.moveCursor(r2, i3, m, () => {
13959
+ const i3 = a3 === "return" ? 0 : -1, m2 = a3 === "return" ? -1 : 0;
13960
+ l.moveCursor(r2, i3, m2, () => {
13961
13961
  l.clearLine(r2, 1, () => {
13962
13962
  e.once("keypress", n4);
13963
13963
  });
@@ -13975,9 +13975,9 @@ function wrapTextWithPrefix(e, r2, o2, t2 = o2, s = o2, n4) {
13975
13975
  hard: true,
13976
13976
  trim: false
13977
13977
  }).split(`
13978
- `).map((c4, i3, m) => {
13978
+ `).map((c4, i3, m2) => {
13979
13979
  const d = n4 ? n4(c4, i3) : c4;
13980
- return i3 === 0 ? `${t2}${d}` : i3 === m.length - 1 ? `${s}${d}` : `${o2}${d}`;
13980
+ return i3 === 0 ? `${t2}${d}` : i3 === m2.length - 1 ? `${s}${d}` : `${o2}${d}`;
13981
13981
  }).join(`
13982
13982
  `);
13983
13983
  }
@@ -14174,6 +14174,56 @@ var r = class extends V {
14174
14174
  });
14175
14175
  }
14176
14176
  };
14177
+ var a2 = class extends V {
14178
+ options;
14179
+ cursor = 0;
14180
+ get _value() {
14181
+ return this.options[this.cursor]?.value;
14182
+ }
14183
+ get _enabledOptions() {
14184
+ return this.options.filter((e) => e.disabled !== true);
14185
+ }
14186
+ toggleAll() {
14187
+ const e = this._enabledOptions, i3 = this.value !== void 0 && this.value.length === e.length;
14188
+ this.value = i3 ? [] : e.map((t2) => t2.value);
14189
+ }
14190
+ toggleInvert() {
14191
+ const e = this.value;
14192
+ if (!e)
14193
+ return;
14194
+ const i3 = this._enabledOptions.filter((t2) => !e.includes(t2.value));
14195
+ this.value = i3.map((t2) => t2.value);
14196
+ }
14197
+ toggleValue() {
14198
+ this.value === void 0 && (this.value = []);
14199
+ const e = this.value.includes(this._value);
14200
+ this.value = e ? this.value.filter((i3) => i3 !== this._value) : [...this.value, this._value];
14201
+ }
14202
+ constructor(e) {
14203
+ super(e, false), this.options = e.options, this.value = [...e.initialValues ?? []];
14204
+ const i3 = Math.max(
14205
+ this.options.findIndex(({ value: t2 }) => t2 === e.cursorAt),
14206
+ 0
14207
+ );
14208
+ this.cursor = this.options[i3]?.disabled ? findCursor(i3, 1, this.options) : i3, this.on("key", (t2, l2) => {
14209
+ l2.name === "a" && this.toggleAll(), l2.name === "i" && this.toggleInvert();
14210
+ }), this.on("cursor", (t2) => {
14211
+ switch (t2) {
14212
+ case "left":
14213
+ case "up":
14214
+ this.cursor = findCursor(this.cursor, -1, this.options);
14215
+ break;
14216
+ case "down":
14217
+ case "right":
14218
+ this.cursor = findCursor(this.cursor, 1, this.options);
14219
+ break;
14220
+ case "space":
14221
+ this.toggleValue();
14222
+ break;
14223
+ }
14224
+ });
14225
+ }
14226
+ };
14177
14227
  var n$1 = class n2 extends V {
14178
14228
  options;
14179
14229
  cursor = 0;
@@ -14299,13 +14349,13 @@ var I = (l2, e, w, p, b, C = false) => {
14299
14349
  let r2 = e, O = 0;
14300
14350
  if (C)
14301
14351
  for (let i3 = p - 1; i3 >= w; i3--) {
14302
- const m = l2[i3];
14303
- if (m && (r2 -= m.length), O++, r2 <= b) break;
14352
+ const m2 = l2[i3];
14353
+ if (m2 && (r2 -= m2.length), O++, r2 <= b) break;
14304
14354
  }
14305
14355
  else
14306
14356
  for (let i3 = w; i3 < p; i3++) {
14307
- const m = l2[i3];
14308
- if (m && (r2 -= m.length), O++, r2 <= b) break;
14357
+ const m2 = l2[i3];
14358
+ if (m2 && (r2 -= m2.length), O++, r2 <= b) break;
14309
14359
  }
14310
14360
  return { lineCount: r2, removals: O };
14311
14361
  };
@@ -14318,7 +14368,7 @@ var limitOptions = ({
14318
14368
  columnPadding: C = 0,
14319
14369
  rowPadding: r2 = 4
14320
14370
  }) => {
14321
- const i3 = getColumns(p) - C, m = getRows(p), M = styleText2("dim", "..."), v = Math.max(m - r2, 0), a3 = Math.max(Math.min(b, v), 5);
14371
+ const i3 = getColumns(p) - C, m2 = getRows(p), M = styleText2("dim", "..."), v = Math.max(m2 - r2, 0), a3 = Math.max(Math.min(b, v), 5);
14322
14372
  let f = 0;
14323
14373
  l2 >= a3 - 3 && (f = Math.max(
14324
14374
  Math.min(l2 - a3 + 3, e.length - a3),
@@ -14406,11 +14456,118 @@ var MULTISELECT_INSTRUCTIONS = [
14406
14456
  `${styleText2("dim", "Space:")} select`,
14407
14457
  `${styleText2("dim", "Enter:")} confirm`
14408
14458
  ];
14459
+ var m = (i3, u4) => i3.split(`
14460
+ `).map((d) => u4(d)).join(`
14461
+ `);
14462
+ var multiselect = (i3) => {
14463
+ const u4 = (t2, a3) => {
14464
+ const r2 = t2.label ?? String(t2.value);
14465
+ return a3 === "disabled" ? `${styleText2("gray", S_CHECKBOX_INACTIVE)} ${m(r2, (o2) => styleText2(["strikethrough", "gray"], o2))}${t2.hint ? ` ${styleText2("dim", `(${t2.hint ?? "disabled"})`)}` : ""}` : a3 === "active" ? `${styleText2("cyan", S_CHECKBOX_ACTIVE)} ${r2}${t2.hint ? ` ${styleText2("dim", `(${t2.hint})`)}` : ""}` : a3 === "selected" ? `${styleText2("green", S_CHECKBOX_SELECTED)} ${m(r2, (o2) => styleText2("dim", o2))}${t2.hint ? ` ${styleText2("dim", `(${t2.hint})`)}` : ""}` : a3 === "cancelled" ? `${m(r2, (o2) => styleText2(["strikethrough", "dim"], o2))}` : a3 === "active-selected" ? `${styleText2("green", S_CHECKBOX_SELECTED)} ${r2}${t2.hint ? ` ${styleText2("dim", `(${t2.hint})`)}` : ""}` : a3 === "submitted" ? `${m(r2, (o2) => styleText2("dim", o2))}` : `${styleText2("dim", S_CHECKBOX_INACTIVE)} ${m(r2, (o2) => styleText2("dim", o2))}`;
14466
+ }, d = i3.required ?? true, v = i3.showInstructions ?? true;
14467
+ return new a2({
14468
+ options: i3.options,
14469
+ signal: i3.signal,
14470
+ input: i3.input,
14471
+ output: i3.output,
14472
+ initialValues: i3.initialValues,
14473
+ required: d,
14474
+ cursorAt: i3.cursorAt,
14475
+ validate(t2) {
14476
+ if (d && (t2 === void 0 || t2.length === 0))
14477
+ return `Please select at least one option.
14478
+ ${styleText2(
14479
+ "reset",
14480
+ styleText2(
14481
+ "dim",
14482
+ `Press ${styleText2(["gray", "bgWhite", "inverse"], " space ")} to select, ${styleText2(
14483
+ "gray",
14484
+ styleText2("bgWhite", styleText2("inverse", " enter "))
14485
+ )} to submit`
14486
+ )
14487
+ )}`;
14488
+ },
14489
+ render() {
14490
+ const t2 = i3.withGuide ?? settings.withGuide, a3 = wrapTextWithPrefix(
14491
+ i3.output,
14492
+ i3.message,
14493
+ t2 ? `${symbolBar(this.state)} ` : "",
14494
+ `${symbol(this.state)} `
14495
+ ), r2 = `${t2 ? `${styleText2("gray", S_BAR)}
14496
+ ` : ""}${a3}
14497
+ `, o2 = this.value ?? [], p = (n4, l2) => {
14498
+ if (n4.disabled)
14499
+ return u4(n4, "disabled");
14500
+ const s = o2.includes(n4.value);
14501
+ return l2 && s ? u4(n4, "active-selected") : s ? u4(n4, "selected") : u4(n4, l2 ? "active" : "inactive");
14502
+ };
14503
+ switch (this.state) {
14504
+ case "submit": {
14505
+ const n4 = this.options.filter(({ value: s }) => o2.includes(s)).map((s) => u4(s, "submitted")).join(styleText2("dim", ", ")) || styleText2("dim", "none"), l2 = wrapTextWithPrefix(
14506
+ i3.output,
14507
+ n4,
14508
+ t2 ? `${styleText2("gray", S_BAR)} ` : ""
14509
+ );
14510
+ return `${r2}${l2}`;
14511
+ }
14512
+ case "cancel": {
14513
+ const n4 = this.options.filter(({ value: s }) => o2.includes(s)).map((s) => u4(s, "cancelled")).join(styleText2("dim", ", "));
14514
+ if (n4.trim() === "")
14515
+ return `${r2}${styleText2("gray", S_BAR)}`;
14516
+ const l2 = wrapTextWithPrefix(
14517
+ i3.output,
14518
+ n4,
14519
+ t2 ? `${styleText2("gray", S_BAR)} ` : ""
14520
+ );
14521
+ return `${r2}${l2}${t2 ? `
14522
+ ${styleText2("gray", S_BAR)}` : ""}`;
14523
+ }
14524
+ case "error": {
14525
+ const n4 = t2 ? `${styleText2("yellow", S_BAR)} ` : "", l2 = this.error.split(`
14526
+ `).map(
14527
+ ($2, C) => C === 0 ? `${t2 ? `${styleText2("yellow", S_BAR_END)} ` : ""}${styleText2("yellow", $2)}` : ` ${$2}`
14528
+ ).join(`
14529
+ `), s = r2.split(`
14530
+ `).length, h3 = l2.split(`
14531
+ `).length + 1;
14532
+ return `${r2}${n4}${limitOptions({
14533
+ output: i3.output,
14534
+ options: this.options,
14535
+ cursor: this.cursor,
14536
+ maxItems: i3.maxItems,
14537
+ columnPadding: n4.length,
14538
+ rowPadding: s + h3,
14539
+ style: p
14540
+ }).join(`
14541
+ ${n4}`)}
14542
+ ${l2}
14543
+ `;
14544
+ }
14545
+ default: {
14546
+ const n4 = t2 ? `${styleText2("cyan", S_BAR)} ` : "", l2 = r2.split(`
14547
+ `).length, s = v ? formatInstructionFooter(MULTISELECT_INSTRUCTIONS, t2) : t2 ? [styleText2("cyan", S_BAR_END)] : [], h3 = s.join(`
14548
+ `), $2 = s.length + 1;
14549
+ return `${r2}${n4}${limitOptions({
14550
+ output: i3.output,
14551
+ options: this.options,
14552
+ cursor: this.cursor,
14553
+ maxItems: i3.maxItems,
14554
+ columnPadding: n4.length,
14555
+ rowPadding: l2 + $2,
14556
+ style: p
14557
+ }).join(`
14558
+ ${n4}`)}
14559
+ ${h3}
14560
+ `;
14561
+ }
14562
+ }
14563
+ }
14564
+ }).prompt();
14565
+ };
14409
14566
  var log = {
14410
14567
  message: (s = [], {
14411
14568
  symbol: e = styleText2("gray", S_BAR),
14412
14569
  secondarySymbol: r2 = styleText2("gray", S_BAR),
14413
- output: m = process.stdout,
14570
+ output: m2 = process.stdout,
14414
14571
  spacing: l2 = 1,
14415
14572
  withGuide: c4
14416
14573
  } = {}) => {
@@ -14425,7 +14582,7 @@ var log = {
14425
14582
  for (const p of y)
14426
14583
  p.length > 0 ? t2.push(`${u4}${p}`) : t2.push(o2 ? r2 : "");
14427
14584
  }
14428
- m.write(`${t2.join(`
14585
+ m2.write(`${t2.join(`
14429
14586
  `)}
14430
14587
  `);
14431
14588
  },
@@ -14476,7 +14633,7 @@ var spinner = ({
14476
14633
  errorMessage: O,
14477
14634
  frames: E = unicode ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"],
14478
14635
  delay: F = unicode ? 80 : 120,
14479
- signal: m,
14636
+ signal: m2,
14480
14637
  ...I2
14481
14638
  } = {}) => {
14482
14639
  const u4 = isCI();
@@ -14485,9 +14642,9 @@ var spinner = ({
14485
14642
  const r2 = e > 1 ? O ?? settings.messages.error : G ?? settings.messages.cancel;
14486
14643
  S = e === 1, d && (a3(r2, e), S && typeof h3 == "function" && h3());
14487
14644
  }, f = () => g(2), i3 = () => g(1), A = () => {
14488
- process.on("uncaughtExceptionMonitor", f), process.on("unhandledRejection", f), process.on("SIGINT", i3), process.on("SIGTERM", i3), process.on("exit", g), m && m.addEventListener("abort", i3);
14645
+ process.on("uncaughtExceptionMonitor", f), process.on("unhandledRejection", f), process.on("SIGINT", i3), process.on("SIGTERM", i3), process.on("exit", g), m2 && m2.addEventListener("abort", i3);
14489
14646
  }, H = () => {
14490
- process.removeListener("uncaughtExceptionMonitor", f), process.removeListener("unhandledRejection", f), process.removeListener("SIGINT", i3), process.removeListener("SIGTERM", i3), process.removeListener("exit", g), m && m.removeEventListener("abort", i3);
14647
+ process.removeListener("uncaughtExceptionMonitor", f), process.removeListener("unhandledRejection", f), process.removeListener("SIGINT", i3), process.removeListener("SIGTERM", i3), process.removeListener("exit", g), m2 && m2.removeEventListener("abort", i3);
14491
14648
  }, y = () => {
14492
14649
  if (p === void 0) return;
14493
14650
  u4 && n4.write(`
@@ -14561,11 +14718,11 @@ var c3 = (t2, o2) => t2.includes(`
14561
14718
  `).map((d) => o2(d)).join(`
14562
14719
  `) : o2(t2);
14563
14720
  var select2 = (t2) => {
14564
- const o2 = (n4, m) => {
14721
+ const o2 = (n4, m2) => {
14565
14722
  if (n4 === void 0)
14566
14723
  return "";
14567
14724
  const s = n4.label ?? String(n4.value);
14568
- switch (m) {
14725
+ switch (m2) {
14569
14726
  case "disabled":
14570
14727
  return `${styleText2("gray", S_RADIO_INACTIVE)} ${c3(s, (i3) => styleText2("gray", i3))}${n4.hint ? ` ${styleText2("dim", `(${n4.hint ?? "disabled"})`)}` : ""}`;
14571
14728
  case "selected":
@@ -14585,11 +14742,11 @@ var select2 = (t2) => {
14585
14742
  output: t2.output,
14586
14743
  initialValue: t2.initialValue,
14587
14744
  render() {
14588
- const n4 = t2.withGuide ?? settings.withGuide, m = `${symbol(this.state)} `, s = `${symbolBar(this.state)} `, i3 = wrapTextWithPrefix(
14745
+ const n4 = t2.withGuide ?? settings.withGuide, m2 = `${symbol(this.state)} `, s = `${symbolBar(this.state)} `, i3 = wrapTextWithPrefix(
14589
14746
  t2.output,
14590
14747
  t2.message,
14591
14748
  s,
14592
- m
14749
+ m2
14593
14750
  ), u4 = `${n4 ? `${styleText2("gray", S_BAR)}
14594
14751
  ` : ""}${i3}
14595
14752
  `;
@@ -14676,7 +14833,9 @@ ${r2}
14676
14833
  }).prompt();
14677
14834
 
14678
14835
  // packages/cli/src/wizard.ts
14679
- import { resolve as resolve8 } from "node:path";
14836
+ import { mkdtemp as mkdtemp2, rm as rm3 } from "node:fs/promises";
14837
+ import { tmpdir } from "node:os";
14838
+ import { join as join6, resolve as resolve8 } from "node:path";
14680
14839
  var supportedRuntimes = [
14681
14840
  "oh-my-pi",
14682
14841
  "opencode",
@@ -14696,13 +14855,14 @@ function unwrap(value) {
14696
14855
  }
14697
14856
  async function runInstallWizard() {
14698
14857
  intro("Portable Capabilities setup");
14858
+ let temporaryRoot = "";
14699
14859
  try {
14700
- const source = String(
14860
+ const manifest = String(
14701
14861
  unwrap(
14702
14862
  await text({
14703
- message: "Generated capability bundle directory",
14704
- placeholder: "/absolute/path/to/generated-bundle",
14705
- validate: (value) => value?.trim() ? void 0 : "Source directory is required"
14863
+ message: "Canonical system manifest",
14864
+ placeholder: "/absolute/path/to/system.yaml",
14865
+ validate: (value) => value?.trim() ? void 0 : "System manifest is required"
14706
14866
  })
14707
14867
  )
14708
14868
  );
@@ -14721,13 +14881,19 @@ async function runInstallWizard() {
14721
14881
  options: supportedRuntimes.map((value) => ({ value, label: value }))
14722
14882
  })
14723
14883
  );
14724
- const capabilityInput = String(
14725
- unwrap(
14726
- await text({
14727
- message: "Capability IDs",
14728
- placeholder: "Leave blank to install all capabilities"
14729
- })
14730
- )
14884
+ const spinner2 = spinner();
14885
+ spinner2.start("Reading available capabilities");
14886
+ const system = await resolveSystem(resolve8(manifest));
14887
+ const availableCapabilities = system.roles.map((role) => role.id);
14888
+ spinner2.stop(
14889
+ `Found ${availableCapabilities.length} capability${availableCapabilities.length === 1 ? "" : "ies"}`
14890
+ );
14891
+ const capabilityIds = unwrap(
14892
+ await multiselect({
14893
+ message: "Choose capabilities to install",
14894
+ options: availableCapabilities.map((value) => ({ value, label: value })),
14895
+ required: true
14896
+ })
14731
14897
  );
14732
14898
  const dryRun = unwrap(
14733
14899
  await confirm({
@@ -14735,16 +14901,22 @@ async function runInstallWizard() {
14735
14901
  initialValue: false
14736
14902
  })
14737
14903
  );
14738
- const capabilityIds = capabilityInput.split(",").map((value) => value.trim()).filter(Boolean);
14739
- const spinner2 = spinner();
14904
+ temporaryRoot = await mkdtemp2(join6(tmpdir(), "portable-capabilities-wizard-"));
14905
+ const bundleRoot = join6(temporaryRoot, `${runtime}-bundle`);
14906
+ spinner2.start("Building runtime bundle");
14907
+ const build = await buildProduction(system, {
14908
+ targets: [runtime],
14909
+ roles: capabilityIds
14910
+ });
14911
+ await writeFileSetAtomically(bundleRoot, build.files);
14912
+ spinner2.stop("Runtime bundle built");
14740
14913
  spinner2.start(dryRun ? "Planning installation" : "Installing capabilities");
14741
14914
  const result2 = await installPackage({
14742
- sourceRoot: resolve8(source),
14915
+ sourceRoot: bundleRoot,
14743
14916
  targetRoot: resolve8(target),
14744
14917
  runtimeId: runtime,
14745
14918
  packageVersion: cliVersion,
14746
- ...capabilityIds.length ? { capabilityIds } : {},
14747
- allCapabilities: capabilityIds.length === 0,
14919
+ capabilityIds,
14748
14920
  dryRun
14749
14921
  });
14750
14922
  spinner2.stop(result2.ok ? "Installation complete" : "Installation failed");
@@ -14758,6 +14930,8 @@ async function runInstallWizard() {
14758
14930
  outro(dryRun ? "Preview complete." : "Project is ready.");
14759
14931
  } catch (error) {
14760
14932
  if (error.message !== "cancelled") throw error;
14933
+ } finally {
14934
+ if (temporaryRoot) await rm3(temporaryRoot, { recursive: true, force: true });
14761
14935
  }
14762
14936
  }
14763
14937