@acidicsoil/portable-capabilities 0.1.3 → 0.1.5

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 {
@@ -13842,8 +13842,8 @@ function block({
13842
13842
  return;
13843
13843
  }
13844
13844
  if (!o2) return;
13845
- const i3 = a3 === "return" ? 0 : -1, m = a3 === "return" ? -1 : 0;
13846
- l.moveCursor(r2, i3, m, () => {
13845
+ const i3 = a3 === "return" ? 0 : -1, m2 = a3 === "return" ? -1 : 0;
13846
+ l.moveCursor(r2, i3, m2, () => {
13847
13847
  l.clearLine(r2, 1, () => {
13848
13848
  e.once("keypress", n4);
13849
13849
  });
@@ -13861,9 +13861,9 @@ function wrapTextWithPrefix(e, r2, o2, t2 = o2, s = o2, n4) {
13861
13861
  hard: true,
13862
13862
  trim: false
13863
13863
  }).split(`
13864
- `).map((c4, i3, m) => {
13864
+ `).map((c4, i3, m2) => {
13865
13865
  const d = n4 ? n4(c4, i3) : c4;
13866
- return i3 === 0 ? `${t2}${d}` : i3 === m.length - 1 ? `${s}${d}` : `${o2}${d}`;
13866
+ return i3 === 0 ? `${t2}${d}` : i3 === m2.length - 1 ? `${s}${d}` : `${o2}${d}`;
13867
13867
  }).join(`
13868
13868
  `);
13869
13869
  }
@@ -14060,6 +14060,56 @@ var r = class extends V {
14060
14060
  });
14061
14061
  }
14062
14062
  };
14063
+ var a2 = class extends V {
14064
+ options;
14065
+ cursor = 0;
14066
+ get _value() {
14067
+ return this.options[this.cursor]?.value;
14068
+ }
14069
+ get _enabledOptions() {
14070
+ return this.options.filter((e) => e.disabled !== true);
14071
+ }
14072
+ toggleAll() {
14073
+ const e = this._enabledOptions, i3 = this.value !== void 0 && this.value.length === e.length;
14074
+ this.value = i3 ? [] : e.map((t2) => t2.value);
14075
+ }
14076
+ toggleInvert() {
14077
+ const e = this.value;
14078
+ if (!e)
14079
+ return;
14080
+ const i3 = this._enabledOptions.filter((t2) => !e.includes(t2.value));
14081
+ this.value = i3.map((t2) => t2.value);
14082
+ }
14083
+ toggleValue() {
14084
+ this.value === void 0 && (this.value = []);
14085
+ const e = this.value.includes(this._value);
14086
+ this.value = e ? this.value.filter((i3) => i3 !== this._value) : [...this.value, this._value];
14087
+ }
14088
+ constructor(e) {
14089
+ super(e, false), this.options = e.options, this.value = [...e.initialValues ?? []];
14090
+ const i3 = Math.max(
14091
+ this.options.findIndex(({ value: t2 }) => t2 === e.cursorAt),
14092
+ 0
14093
+ );
14094
+ this.cursor = this.options[i3]?.disabled ? findCursor(i3, 1, this.options) : i3, this.on("key", (t2, l2) => {
14095
+ l2.name === "a" && this.toggleAll(), l2.name === "i" && this.toggleInvert();
14096
+ }), this.on("cursor", (t2) => {
14097
+ switch (t2) {
14098
+ case "left":
14099
+ case "up":
14100
+ this.cursor = findCursor(this.cursor, -1, this.options);
14101
+ break;
14102
+ case "down":
14103
+ case "right":
14104
+ this.cursor = findCursor(this.cursor, 1, this.options);
14105
+ break;
14106
+ case "space":
14107
+ this.toggleValue();
14108
+ break;
14109
+ }
14110
+ });
14111
+ }
14112
+ };
14063
14113
  var n$1 = class n2 extends V {
14064
14114
  options;
14065
14115
  cursor = 0;
@@ -14185,13 +14235,13 @@ var I = (l2, e, w, p, b, C = false) => {
14185
14235
  let r2 = e, O = 0;
14186
14236
  if (C)
14187
14237
  for (let i3 = p - 1; i3 >= w; i3--) {
14188
- const m = l2[i3];
14189
- if (m && (r2 -= m.length), O++, r2 <= b) break;
14238
+ const m2 = l2[i3];
14239
+ if (m2 && (r2 -= m2.length), O++, r2 <= b) break;
14190
14240
  }
14191
14241
  else
14192
14242
  for (let i3 = w; i3 < p; i3++) {
14193
- const m = l2[i3];
14194
- if (m && (r2 -= m.length), O++, r2 <= b) break;
14243
+ const m2 = l2[i3];
14244
+ if (m2 && (r2 -= m2.length), O++, r2 <= b) break;
14195
14245
  }
14196
14246
  return { lineCount: r2, removals: O };
14197
14247
  };
@@ -14204,7 +14254,7 @@ var limitOptions = ({
14204
14254
  columnPadding: C = 0,
14205
14255
  rowPadding: r2 = 4
14206
14256
  }) => {
14207
- 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);
14257
+ 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);
14208
14258
  let f = 0;
14209
14259
  l2 >= a3 - 3 && (f = Math.max(
14210
14260
  Math.min(l2 - a3 + 3, e.length - a3),
@@ -14292,11 +14342,118 @@ var MULTISELECT_INSTRUCTIONS = [
14292
14342
  `${styleText2("dim", "Space:")} select`,
14293
14343
  `${styleText2("dim", "Enter:")} confirm`
14294
14344
  ];
14345
+ var m = (i3, u4) => i3.split(`
14346
+ `).map((d) => u4(d)).join(`
14347
+ `);
14348
+ var multiselect = (i3) => {
14349
+ const u4 = (t2, a3) => {
14350
+ const r2 = t2.label ?? String(t2.value);
14351
+ 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))}`;
14352
+ }, d = i3.required ?? true, v = i3.showInstructions ?? true;
14353
+ return new a2({
14354
+ options: i3.options,
14355
+ signal: i3.signal,
14356
+ input: i3.input,
14357
+ output: i3.output,
14358
+ initialValues: i3.initialValues,
14359
+ required: d,
14360
+ cursorAt: i3.cursorAt,
14361
+ validate(t2) {
14362
+ if (d && (t2 === void 0 || t2.length === 0))
14363
+ return `Please select at least one option.
14364
+ ${styleText2(
14365
+ "reset",
14366
+ styleText2(
14367
+ "dim",
14368
+ `Press ${styleText2(["gray", "bgWhite", "inverse"], " space ")} to select, ${styleText2(
14369
+ "gray",
14370
+ styleText2("bgWhite", styleText2("inverse", " enter "))
14371
+ )} to submit`
14372
+ )
14373
+ )}`;
14374
+ },
14375
+ render() {
14376
+ const t2 = i3.withGuide ?? settings.withGuide, a3 = wrapTextWithPrefix(
14377
+ i3.output,
14378
+ i3.message,
14379
+ t2 ? `${symbolBar(this.state)} ` : "",
14380
+ `${symbol(this.state)} `
14381
+ ), r2 = `${t2 ? `${styleText2("gray", S_BAR)}
14382
+ ` : ""}${a3}
14383
+ `, o2 = this.value ?? [], p = (n4, l2) => {
14384
+ if (n4.disabled)
14385
+ return u4(n4, "disabled");
14386
+ const s = o2.includes(n4.value);
14387
+ return l2 && s ? u4(n4, "active-selected") : s ? u4(n4, "selected") : u4(n4, l2 ? "active" : "inactive");
14388
+ };
14389
+ switch (this.state) {
14390
+ case "submit": {
14391
+ const n4 = this.options.filter(({ value: s }) => o2.includes(s)).map((s) => u4(s, "submitted")).join(styleText2("dim", ", ")) || styleText2("dim", "none"), l2 = wrapTextWithPrefix(
14392
+ i3.output,
14393
+ n4,
14394
+ t2 ? `${styleText2("gray", S_BAR)} ` : ""
14395
+ );
14396
+ return `${r2}${l2}`;
14397
+ }
14398
+ case "cancel": {
14399
+ const n4 = this.options.filter(({ value: s }) => o2.includes(s)).map((s) => u4(s, "cancelled")).join(styleText2("dim", ", "));
14400
+ if (n4.trim() === "")
14401
+ return `${r2}${styleText2("gray", S_BAR)}`;
14402
+ const l2 = wrapTextWithPrefix(
14403
+ i3.output,
14404
+ n4,
14405
+ t2 ? `${styleText2("gray", S_BAR)} ` : ""
14406
+ );
14407
+ return `${r2}${l2}${t2 ? `
14408
+ ${styleText2("gray", S_BAR)}` : ""}`;
14409
+ }
14410
+ case "error": {
14411
+ const n4 = t2 ? `${styleText2("yellow", S_BAR)} ` : "", l2 = this.error.split(`
14412
+ `).map(
14413
+ ($2, C) => C === 0 ? `${t2 ? `${styleText2("yellow", S_BAR_END)} ` : ""}${styleText2("yellow", $2)}` : ` ${$2}`
14414
+ ).join(`
14415
+ `), s = r2.split(`
14416
+ `).length, h3 = l2.split(`
14417
+ `).length + 1;
14418
+ return `${r2}${n4}${limitOptions({
14419
+ output: i3.output,
14420
+ options: this.options,
14421
+ cursor: this.cursor,
14422
+ maxItems: i3.maxItems,
14423
+ columnPadding: n4.length,
14424
+ rowPadding: s + h3,
14425
+ style: p
14426
+ }).join(`
14427
+ ${n4}`)}
14428
+ ${l2}
14429
+ `;
14430
+ }
14431
+ default: {
14432
+ const n4 = t2 ? `${styleText2("cyan", S_BAR)} ` : "", l2 = r2.split(`
14433
+ `).length, s = v ? formatInstructionFooter(MULTISELECT_INSTRUCTIONS, t2) : t2 ? [styleText2("cyan", S_BAR_END)] : [], h3 = s.join(`
14434
+ `), $2 = s.length + 1;
14435
+ return `${r2}${n4}${limitOptions({
14436
+ output: i3.output,
14437
+ options: this.options,
14438
+ cursor: this.cursor,
14439
+ maxItems: i3.maxItems,
14440
+ columnPadding: n4.length,
14441
+ rowPadding: l2 + $2,
14442
+ style: p
14443
+ }).join(`
14444
+ ${n4}`)}
14445
+ ${h3}
14446
+ `;
14447
+ }
14448
+ }
14449
+ }
14450
+ }).prompt();
14451
+ };
14295
14452
  var log = {
14296
14453
  message: (s = [], {
14297
14454
  symbol: e = styleText2("gray", S_BAR),
14298
14455
  secondarySymbol: r2 = styleText2("gray", S_BAR),
14299
- output: m = process.stdout,
14456
+ output: m2 = process.stdout,
14300
14457
  spacing: l2 = 1,
14301
14458
  withGuide: c4
14302
14459
  } = {}) => {
@@ -14311,7 +14468,7 @@ var log = {
14311
14468
  for (const p of y)
14312
14469
  p.length > 0 ? t2.push(`${u4}${p}`) : t2.push(o2 ? r2 : "");
14313
14470
  }
14314
- m.write(`${t2.join(`
14471
+ m2.write(`${t2.join(`
14315
14472
  `)}
14316
14473
  `);
14317
14474
  },
@@ -14362,7 +14519,7 @@ var spinner = ({
14362
14519
  errorMessage: O,
14363
14520
  frames: E = unicode ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"],
14364
14521
  delay: F = unicode ? 80 : 120,
14365
- signal: m,
14522
+ signal: m2,
14366
14523
  ...I2
14367
14524
  } = {}) => {
14368
14525
  const u4 = isCI();
@@ -14371,9 +14528,9 @@ var spinner = ({
14371
14528
  const r2 = e > 1 ? O ?? settings.messages.error : G ?? settings.messages.cancel;
14372
14529
  S = e === 1, d && (a3(r2, e), S && typeof h3 == "function" && h3());
14373
14530
  }, f = () => g(2), i3 = () => g(1), A = () => {
14374
- 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);
14531
+ 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);
14375
14532
  }, H = () => {
14376
- 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);
14533
+ 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);
14377
14534
  }, y = () => {
14378
14535
  if (p === void 0) return;
14379
14536
  u4 && n4.write(`
@@ -14447,11 +14604,11 @@ var c3 = (t2, o2) => t2.includes(`
14447
14604
  `).map((d) => o2(d)).join(`
14448
14605
  `) : o2(t2);
14449
14606
  var select2 = (t2) => {
14450
- const o2 = (n4, m) => {
14607
+ const o2 = (n4, m2) => {
14451
14608
  if (n4 === void 0)
14452
14609
  return "";
14453
14610
  const s = n4.label ?? String(n4.value);
14454
- switch (m) {
14611
+ switch (m2) {
14455
14612
  case "disabled":
14456
14613
  return `${styleText2("gray", S_RADIO_INACTIVE)} ${c3(s, (i3) => styleText2("gray", i3))}${n4.hint ? ` ${styleText2("dim", `(${n4.hint ?? "disabled"})`)}` : ""}`;
14457
14614
  case "selected":
@@ -14471,11 +14628,11 @@ var select2 = (t2) => {
14471
14628
  output: t2.output,
14472
14629
  initialValue: t2.initialValue,
14473
14630
  render() {
14474
- const n4 = t2.withGuide ?? settings.withGuide, m = `${symbol(this.state)} `, s = `${symbolBar(this.state)} `, i3 = wrapTextWithPrefix(
14631
+ const n4 = t2.withGuide ?? settings.withGuide, m2 = `${symbol(this.state)} `, s = `${symbolBar(this.state)} `, i3 = wrapTextWithPrefix(
14475
14632
  t2.output,
14476
14633
  t2.message,
14477
14634
  s,
14478
- m
14635
+ m2
14479
14636
  ), u4 = `${n4 ? `${styleText2("gray", S_BAR)}
14480
14637
  ` : ""}${i3}
14481
14638
  `;
@@ -14562,7 +14719,9 @@ ${r2}
14562
14719
  }).prompt();
14563
14720
 
14564
14721
  // packages/cli/src/wizard.ts
14565
- import { resolve as resolve8 } from "node:path";
14722
+ import { mkdtemp as mkdtemp2, rm as rm3 } from "node:fs/promises";
14723
+ import { tmpdir } from "node:os";
14724
+ import { join as join6, resolve as resolve8 } from "node:path";
14566
14725
  var supportedRuntimes = [
14567
14726
  "oh-my-pi",
14568
14727
  "opencode",
@@ -14582,13 +14741,14 @@ function unwrap(value) {
14582
14741
  }
14583
14742
  async function runInstallWizard() {
14584
14743
  intro("Portable Capabilities setup");
14744
+ let temporaryRoot = "";
14585
14745
  try {
14586
- const source = String(
14746
+ const manifest = String(
14587
14747
  unwrap(
14588
14748
  await text({
14589
- message: "Generated capability bundle directory",
14590
- placeholder: "/absolute/path/to/generated-bundle",
14591
- validate: (value) => value?.trim() ? void 0 : "Source directory is required"
14749
+ message: "Canonical system manifest",
14750
+ placeholder: "/absolute/path/to/system.yaml",
14751
+ validate: (value) => value?.trim() ? void 0 : "System manifest is required"
14592
14752
  })
14593
14753
  )
14594
14754
  );
@@ -14607,13 +14767,19 @@ async function runInstallWizard() {
14607
14767
  options: supportedRuntimes.map((value) => ({ value, label: value }))
14608
14768
  })
14609
14769
  );
14610
- const capabilityInput = String(
14611
- unwrap(
14612
- await text({
14613
- message: "Capability IDs",
14614
- placeholder: "Leave blank to install all capabilities"
14615
- })
14616
- )
14770
+ const spinner2 = spinner();
14771
+ spinner2.start("Reading available capabilities");
14772
+ const system = await resolveSystem(resolve8(manifest));
14773
+ const availableCapabilities = system.roles.map((role) => role.id);
14774
+ spinner2.stop(
14775
+ `Found ${availableCapabilities.length} capability${availableCapabilities.length === 1 ? "" : "ies"}`
14776
+ );
14777
+ const capabilityIds = unwrap(
14778
+ await multiselect({
14779
+ message: "Choose capabilities to install",
14780
+ options: availableCapabilities.map((value) => ({ value, label: value })),
14781
+ required: true
14782
+ })
14617
14783
  );
14618
14784
  const dryRun = unwrap(
14619
14785
  await confirm({
@@ -14621,16 +14787,22 @@ async function runInstallWizard() {
14621
14787
  initialValue: false
14622
14788
  })
14623
14789
  );
14624
- const capabilityIds = capabilityInput.split(",").map((value) => value.trim()).filter(Boolean);
14625
- const spinner2 = spinner();
14790
+ temporaryRoot = await mkdtemp2(join6(tmpdir(), "portable-capabilities-wizard-"));
14791
+ const bundleRoot = join6(temporaryRoot, `${runtime}-bundle`);
14792
+ spinner2.start("Building runtime bundle");
14793
+ const build = await buildProduction(system, {
14794
+ targets: [runtime],
14795
+ roles: capabilityIds
14796
+ });
14797
+ await writeFileSetAtomically(bundleRoot, build.files);
14798
+ spinner2.stop("Runtime bundle built");
14626
14799
  spinner2.start(dryRun ? "Planning installation" : "Installing capabilities");
14627
14800
  const result2 = await installPackage({
14628
- sourceRoot: resolve8(source),
14801
+ sourceRoot: bundleRoot,
14629
14802
  targetRoot: resolve8(target),
14630
14803
  runtimeId: runtime,
14631
14804
  packageVersion: cliVersion,
14632
- ...capabilityIds.length ? { capabilityIds } : {},
14633
- allCapabilities: capabilityIds.length === 0,
14805
+ capabilityIds,
14634
14806
  dryRun
14635
14807
  });
14636
14808
  spinner2.stop(result2.ok ? "Installation complete" : "Installation failed");
@@ -14644,6 +14816,8 @@ async function runInstallWizard() {
14644
14816
  outro(dryRun ? "Preview complete." : "Project is ready.");
14645
14817
  } catch (error) {
14646
14818
  if (error.message !== "cancelled") throw error;
14819
+ } finally {
14820
+ if (temporaryRoot) await rm3(temporaryRoot, { recursive: true, force: true });
14647
14821
  }
14648
14822
  }
14649
14823