zion 2.4.0 → 2.5.1

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.
Files changed (2) hide show
  1. package/dist/cli.js +313 -160
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  // src/cli.tsx
4
4
  import os3 from "os";
5
- import path11 from "path";
5
+ import path14 from "path";
6
6
 
7
7
  // package.json
8
- var version = "2.4.0";
8
+ var version = "2.5.1";
9
9
 
10
10
  // src/lib/theme.ts
11
11
  import chalk, { supportsColor, supportsColorStderr } from "chalk";
@@ -277,7 +277,7 @@ var HelpPrinter = class {
277
277
  root(ctx) {
278
278
  const commands = this.registry.list().map((command) => [command.name, command.summary]);
279
279
  return render([
280
- header(ctx, this.fallback.summary),
280
+ header(ctx),
281
281
  section("Usage", [`${ctx.bin} ${paint.muted("[command] [options]")}`]),
282
282
  section("Commands", table(commands)),
283
283
  section("Options", table(GLOBAL_OPTIONS)),
@@ -334,7 +334,8 @@ var HelpCommand = class {
334
334
  };
335
335
  function header(ctx, summary, name) {
336
336
  const title = name ? `${badge("zion")} ${paint.bold(name)}` : badge("zion");
337
- return [indent(`${title} ${paint.muted(`v${ctx.version}`)}`), indent(paint.muted(summary))];
337
+ const lines = [indent(`${title} ${paint.muted(`v${ctx.version}`)}`)];
338
+ return summary ? [...lines, indent(paint.muted(summary))] : lines;
338
339
  }
339
340
  function section(title, lines) {
340
341
  return [indent(paint.bold(title.toUpperCase())), ...lines.map((line) => indent(indent(line)))];
@@ -484,7 +485,7 @@ function ConfirmPrompt({ message, defaultValue, onSubmit }) {
484
485
  import { useRef as useRef2, useState as useState2 } from "react";
485
486
  import { Text as Text2, useInput as useInput2 } from "ink";
486
487
  import { jsx as jsx3 } from "react/jsx-runtime";
487
- function MultiSelectPrompt({ message, options, initialValues, onSubmit }) {
488
+ function MultiSelectPrompt({ message, options, initialValues, required, onSubmit }) {
488
489
  const [index, setIndex] = useState2(0);
489
490
  const [chosen, setChosen] = useState2(
490
491
  () => new Set(options.flatMap((option, i) => initialValues.includes(option.value) ? [i] : []))
@@ -506,7 +507,7 @@ function MultiSelectPrompt({ message, options, initialValues, onSubmit }) {
506
507
  else if (input === " ") toggle(index);
507
508
  else if (input === "a") setChosen((current) => new Set(current.size === count ? [] : options.map((_, i) => i)));
508
509
  else if (key.return) {
509
- if (chosen.size === 0) {
510
+ if (required && chosen.size === 0) {
510
511
  setError("Choose at least one with space.");
511
512
  return;
512
513
  }
@@ -698,7 +699,7 @@ var InkPrompter = class extends BasePrompter {
698
699
  (value) => ({ title: message, lines: [options.find((option) => option.value === value)?.label ?? String(value)] })
699
700
  );
700
701
  }
701
- multiselect({ message, options, initialValues = [] }) {
702
+ multiselect({ message, options, initialValues = [], required = true }) {
702
703
  return this.ask(
703
704
  (submit) => /* @__PURE__ */ jsx8(
704
705
  MultiSelectPrompt,
@@ -706,13 +707,14 @@ var InkPrompter = class extends BasePrompter {
706
707
  message,
707
708
  options,
708
709
  initialValues,
710
+ required,
709
711
  onSubmit: (chosen) => submit(chosen.map((option) => option.value))
710
712
  }
711
713
  ),
712
714
  (values) => ({
713
715
  title: message,
714
716
  lines: [
715
- options.filter((option) => values.includes(option.value)).map((option) => option.label).join(", ")
717
+ options.filter((option) => values.includes(option.value)).map((option) => option.label).join(", ") || "None"
716
718
  ]
717
719
  })
718
720
  );
@@ -781,13 +783,19 @@ var PlainPrompter = class extends BasePrompter {
781
783
  this.step({ title: message, lines: [option.label] });
782
784
  return option.value;
783
785
  }
784
- async multiselect({ message, options, initialValues = [], nonInteractiveHint }) {
786
+ async multiselect({
787
+ message,
788
+ options,
789
+ initialValues = [],
790
+ required = true,
791
+ nonInteractiveHint
792
+ }) {
785
793
  this.assertCanPrompt();
786
794
  const chosen = options.filter((option) => initialValues.includes(option.value));
787
- if (nonInteractiveHint || chosen.length === 0) {
795
+ if (nonInteractiveHint || required && chosen.length === 0) {
788
796
  throw new UsageError(`${message} (no terminal to ask in)`, nonInteractiveHint);
789
797
  }
790
- this.step({ title: message, lines: [chosen.map((option) => option.label).join(", ")] });
798
+ this.step({ title: message, lines: [chosen.map((option) => option.label).join(", ") || "None"] });
791
799
  return chosen.map((option) => option.value);
792
800
  }
793
801
  async confirm({ message, defaultValue, nonInteractiveHint }) {
@@ -1228,8 +1236,8 @@ import fs2 from "fs/promises";
1228
1236
  import path3 from "path";
1229
1237
  var VERSION = 1;
1230
1238
  var JsonLockfile = class {
1231
- constructor(path12) {
1232
- this.path = path12;
1239
+ constructor(path15) {
1240
+ this.path = path15;
1233
1241
  }
1234
1242
  async read() {
1235
1243
  let text;
@@ -1394,12 +1402,12 @@ var HttpSkillsApi = class {
1394
1402
  return this.parseSkill(name, body);
1395
1403
  }
1396
1404
  /** Resolves to the parsed body, or undefined for a 404. */
1397
- async request(path12, signal) {
1405
+ async request(path15, signal) {
1398
1406
  const timeout = AbortSignal.timeout(TIMEOUT_MS);
1399
1407
  let body;
1400
1408
  let status;
1401
1409
  try {
1402
- const response = await this.fetchImpl(new URL(path12, this.base), {
1410
+ const response = await this.fetchImpl(new URL(path15, this.base), {
1403
1411
  headers: { accept: "application/json" },
1404
1412
  signal: signal ? AbortSignal.any([signal, timeout]) : timeout
1405
1413
  });
@@ -1429,13 +1437,13 @@ var HttpSkillsApi = class {
1429
1437
  commit,
1430
1438
  updatedAt,
1431
1439
  files: files.map((file) => {
1432
- const { path: path12, sha, executable, content } = file ?? {};
1433
- if (typeof path12 !== "string" || typeof sha !== "string" || typeof content !== "string") throw this.malformed();
1440
+ const { path: path15, sha, executable, content } = file ?? {};
1441
+ if (typeof path15 !== "string" || typeof sha !== "string" || typeof content !== "string") throw this.malformed();
1434
1442
  const bytes = Buffer.from(content, "base64");
1435
1443
  if (gitBlobSha(bytes) !== sha) {
1436
- throw new CliError(`${this.host} sent a damaged copy of ${name}/${path12}`, "try again in a moment");
1444
+ throw new CliError(`${this.host} sent a damaged copy of ${name}/${path15}`, "try again in a moment");
1437
1445
  }
1438
- return { path: path12, sha, executable: executable === true, content: bytes };
1446
+ return { path: path15, sha, executable: executable === true, content: bytes };
1439
1447
  })
1440
1448
  };
1441
1449
  }
@@ -1448,10 +1456,32 @@ var HttpSkillsApi = class {
1448
1456
  };
1449
1457
 
1450
1458
  // src/commands/skills/InstallFlow.ts
1451
- import path6 from "path";
1459
+ import path7 from "path";
1452
1460
 
1453
- // src/commands/skills/copies.ts
1461
+ // src/commands/skills/chooseTargets.ts
1454
1462
  import path5 from "path";
1463
+ async function chooseTargets(ui, { targets, files }, given, lock) {
1464
+ if (given.length > 0) {
1465
+ const chosen = targets.filter((target) => given.includes(target.id));
1466
+ ui.step({ title: "Install into", lines: [chosen.map((target) => tildify(target.dir)).join(", ")] });
1467
+ return chosen;
1468
+ }
1469
+ const used = new Set(Object.values(lock.skills).flatMap((skill) => skill.paths.map((dir) => path5.dirname(dir))));
1470
+ let suggested = targets.filter((target) => used.has(target.dir));
1471
+ if (suggested.length === 0) {
1472
+ const present = await Promise.all(targets.map((target) => files.exists(target.home)));
1473
+ suggested = targets.filter((_, i) => present[i]);
1474
+ }
1475
+ return ui.multiselect({
1476
+ message: "Install into",
1477
+ options: targets.map((target) => ({ value: target, label: tildify(target.dir), hint: target.hint })),
1478
+ initialValues: suggested,
1479
+ nonInteractiveHint: `pass --target (${targets.map((target) => target.id).join(", ")}), e.g. -t ${targets[0].id}`
1480
+ });
1481
+ }
1482
+
1483
+ // src/commands/skills/copies.ts
1484
+ import path6 from "path";
1455
1485
  function fileHashes(skill) {
1456
1486
  return Object.fromEntries(skill.files.map((file) => [file.path, file.sha]));
1457
1487
  }
@@ -1513,11 +1543,23 @@ function describeCopies(title, skills, copies) {
1513
1543
  return {
1514
1544
  title,
1515
1545
  lines: skills.map((skill) => {
1516
- const dirs = copies.filter((copy) => copy.skill === skill).map((copy) => tildify(path5.dirname(copy.dir)));
1546
+ const dirs = copies.filter((copy) => copy.skill === skill).map((copy) => tildify(path6.dirname(copy.dir)));
1517
1547
  return `${skill.name.padEnd(width)} ${paint.muted(dirs.length ? dirs.join(", ") : "nowhere")}`;
1518
1548
  })
1519
1549
  };
1520
1550
  }
1551
+ function describeChange(locked, latest) {
1552
+ const before = locked.files;
1553
+ const after = fileHashes(latest);
1554
+ const count = (files2) => files2.length;
1555
+ const changes = [
1556
+ [count(Object.keys(after).filter((file) => file in before && before[file] !== after[file])), "changed"],
1557
+ [count(Object.keys(after).filter((file) => !(file in before))), "added"],
1558
+ [count(Object.keys(before).filter((file) => !(file in after))), "removed"]
1559
+ ];
1560
+ const files = changes.filter(([n]) => n > 0).map(([n, what]) => `${n} ${what}`);
1561
+ return `${short(locked.commit)} \u2192 ${short(latest.commit)}${files.length ? ` \xB7 ${files.join(", ")}` : ""}`;
1562
+ }
1521
1563
  var short = (commit) => commit.slice(0, 7);
1522
1564
  function plural(count, noun) {
1523
1565
  return `${count} ${noun}${count === 1 ? "" : "s"}`;
@@ -1531,17 +1573,19 @@ var InstallFlow = class {
1531
1573
  async run(ui, options, ctx) {
1532
1574
  const { api, lockfile } = this.deps;
1533
1575
  const lock = await lockfile.read();
1534
- const available = await ui.task(
1535
- "Fetching the list of skills",
1536
- (signal) => api.list(signal),
1537
- (names2) => ({ title: `${plural(names2.length, "skill")} available` })
1538
- );
1539
- if (available.length === 0) throw new CliError(`${api.host} has no skills right now`, "try again later");
1540
- const names = await this.chooseSkills(ui, options, ctx, available, lock);
1541
- const targets = await this.chooseTargets(ui, options, ctx, lock);
1576
+ const names = await this.chooseSkills(ui, options, ctx, lock);
1577
+ const targets = await chooseTargets(ui, this.deps, options.targets, lock);
1542
1578
  const skills = await ui.task(
1543
1579
  `Downloading ${names.join(", ")}`,
1544
- (signal) => Promise.all(names.map((name) => api.get(name, signal))),
1580
+ (signal) => Promise.all(
1581
+ names.map(
1582
+ (name) => api.get(name, signal).catch((error) => {
1583
+ if (error instanceof SkillNotFoundError)
1584
+ throw new SkillNotFoundError(name, `run ${ctx.bin} skills list to see them all`);
1585
+ throw error;
1586
+ })
1587
+ )
1588
+ ),
1545
1589
  (skills2) => {
1546
1590
  const width = Math.max(...skills2.map((skill) => skill.name.length));
1547
1591
  return {
@@ -1561,7 +1605,7 @@ var InstallFlow = class {
1561
1605
  this.deps,
1562
1606
  skill,
1563
1607
  lock.skills[skill.name],
1564
- dirs.map((dir) => path6.join(dir, skill.name))
1608
+ dirs.map((dir) => path7.join(dir, skill.name))
1565
1609
  )
1566
1610
  )
1567
1611
  )).flat();
@@ -1580,15 +1624,20 @@ var InstallFlow = class {
1580
1624
  });
1581
1625
  return 0;
1582
1626
  }
1583
- async chooseSkills(ui, options, ctx, available, lock) {
1584
- if (options.all) return [...available];
1627
+ async chooseSkills(ui, options, ctx, lock) {
1585
1628
  if (options.names.length > 0) {
1586
- const missing = options.names.find((name) => !available.includes(name));
1587
- if (missing) throw new CliError(`No skill named ${missing}`, `run ${ctx.bin} skills list to see them all`);
1588
1629
  const names = [...new Set(options.names)];
1589
1630
  ui.step({ title: "Skills", lines: [names.join(", ")] });
1590
1631
  return names;
1591
1632
  }
1633
+ const { api } = this.deps;
1634
+ const available = await ui.task(
1635
+ "Fetching the list of skills",
1636
+ (signal) => api.list(signal),
1637
+ (names) => ({ title: `${plural(names.length, "skill")} available` })
1638
+ );
1639
+ if (available.length === 0) throw new CliError(`${api.host} has no skills right now`, "try again later");
1640
+ if (options.all) return [...available];
1592
1641
  return ui.multiselect({
1593
1642
  message: "Which skills?",
1594
1643
  options: available.map((name) => ({
@@ -1599,36 +1648,201 @@ var InstallFlow = class {
1599
1648
  nonInteractiveHint: `name them, e.g. ${ctx.bin} skills install ${available[0]}, or pass --all`
1600
1649
  });
1601
1650
  }
1602
- async chooseTargets(ui, options, ctx, lock) {
1603
- const { targets, files } = this.deps;
1604
- if (options.targets.length > 0) {
1605
- const chosen = targets.filter((target) => options.targets.includes(target.id));
1606
- ui.step({ title: "Install into", lines: [chosen.map((target) => tildify(target.dir)).join(", ")] });
1607
- return chosen;
1651
+ };
1652
+
1653
+ // src/commands/skills/ManageFlow.ts
1654
+ import path9 from "path";
1655
+
1656
+ // src/commands/skills/removals.ts
1657
+ import path8 from "path";
1658
+ async function planRemovals({ files }, lock, names, only) {
1659
+ const removals = [];
1660
+ for (const name of names) {
1661
+ const { paths, files: expected } = lock.skills[name];
1662
+ for (const dir of paths.filter((dir2) => !only || only.has(path8.dirname(dir2)))) {
1663
+ const { exists, changed } = await files.compare(dir, expected);
1664
+ removals.push({ name, dir, exists, edited: exists && changed.length > 0 });
1608
1665
  }
1609
- const used = new Set(Object.values(lock.skills).flatMap((skill) => skill.paths.map((dir) => path6.dirname(dir))));
1610
- let suggested = targets.filter((target) => used.has(target.dir));
1611
- if (suggested.length === 0) {
1612
- const present = await Promise.all(targets.map((target) => files.exists(target.home)));
1613
- suggested = targets.filter((_, i) => present[i]);
1666
+ }
1667
+ return removals;
1668
+ }
1669
+ async function applyRemovals({ files, lockfile }, lock, removals) {
1670
+ const kept = [];
1671
+ for (const removal of removals) {
1672
+ const owned = Object.keys(lock.skills[removal.name].files);
1673
+ const left = removal.exists ? await files.remove(removal.dir, owned) : [];
1674
+ if (left.length > 0) kept.push(`${tildify(removal.dir)} ${plural(left.length, "file")} zion didn't install`);
1675
+ await lockfile.update((data) => {
1676
+ const entry = data.skills[removal.name];
1677
+ if (!entry) return;
1678
+ entry.paths = entry.paths.filter((dir) => dir !== removal.dir);
1679
+ if (entry.paths.length === 0) delete data.skills[removal.name];
1680
+ });
1681
+ }
1682
+ return kept;
1683
+ }
1684
+ function describeKept(kept, removed) {
1685
+ return kept.length > 0 ? { title: "Removed, but kept", tone: "warning", lines: kept } : { title: "Removed", lines: [removed.join(", ")] };
1686
+ }
1687
+ var KEPT_ADVICE = "Delete what was kept yourself if you no longer need it.";
1688
+
1689
+ // src/commands/skills/ManageFlow.ts
1690
+ var ManageFlow = class {
1691
+ constructor(deps) {
1692
+ this.deps = deps;
1693
+ }
1694
+ async run(ui) {
1695
+ const { api, lockfile } = this.deps;
1696
+ const lock = await lockfile.read();
1697
+ const installed = Object.keys(lock.skills);
1698
+ const { available, latest } = await ui.task(
1699
+ "Fetching skills",
1700
+ (signal) => this.fetchCatalog(lock, signal),
1701
+ ({ available: available2, latest: latest2 }) => {
1702
+ const updates = installed.filter((name) => isOutdated(lock, name, latest2)).length;
1703
+ return {
1704
+ title: [plural(available2.length, "skill"), updates > 0 && plural(updates, "update")].filter(Boolean).join(" \xB7 ")
1705
+ };
1706
+ }
1707
+ );
1708
+ const names = [.../* @__PURE__ */ new Set([...available, ...installed])].sort();
1709
+ const ticked = new Set(
1710
+ await ui.multiselect({
1711
+ message: "Your skills",
1712
+ options: names.map((name) => ({ value: name, label: name, hint: this.hint(lock, name, latest) })),
1713
+ initialValues: installed,
1714
+ required: false
1715
+ })
1716
+ );
1717
+ const adding = names.filter((name) => ticked.has(name) && !lock.skills[name]);
1718
+ const updating = installed.filter((name) => ticked.has(name) && isOutdated(lock, name, latest));
1719
+ const removing = installed.filter((name) => !ticked.has(name));
1720
+ if (adding.length + updating.length + removing.length === 0) {
1721
+ ui.outro("Nothing to change.", { tone: "muted" });
1722
+ return 0;
1614
1723
  }
1615
- return ui.multiselect({
1616
- message: "Install into",
1617
- options: targets.map((target) => ({ value: target, label: tildify(target.dir), hint: target.hint })),
1618
- initialValues: suggested,
1619
- nonInteractiveHint: `pass --target (${targets.map((target) => target.id).join(", ")}), e.g. -t ${targets[0].id}`
1724
+ const targets = adding.length > 0 ? await chooseTargets(ui, this.deps, [], lock) : [];
1725
+ const added = adding.length > 0 ? await ui.task(
1726
+ `Downloading ${adding.join(", ")}`,
1727
+ (signal) => Promise.all(adding.map((name) => api.get(name, signal))),
1728
+ (skills) => ({ title: `Downloaded ${plural(skills.length, "skill")}` })
1729
+ ) : [];
1730
+ const updated = updating.map((name) => latest.get(name));
1731
+ const copies = [
1732
+ ...(await Promise.all(
1733
+ added.map(
1734
+ (skill) => planCopies(
1735
+ this.deps,
1736
+ skill,
1737
+ void 0,
1738
+ targets.map((target) => path9.join(target.dir, skill.name))
1739
+ )
1740
+ )
1741
+ )).flat(),
1742
+ ...(await Promise.all(updated.map((skill) => planCopies(this.deps, skill, lock.skills[skill.name], [])))).flat()
1743
+ ];
1744
+ const removals = await planRemovals(this.deps, lock, removing);
1745
+ this.summarise(ui, lock, added, updated, removing, copies, removals);
1746
+ const risky = copies.some((copy) => copy.problem) || removals.some((removal) => removal.edited);
1747
+ const total = added.length + updated.length + removing.length;
1748
+ if (!await ui.confirm({ message: `Apply ${plural(total, "change")}?`, defaultValue: !risky })) {
1749
+ ui.outro("Left everything as it was.", { tone: "muted" });
1750
+ return 0;
1751
+ }
1752
+ const kept = await ui.task(
1753
+ "Applying",
1754
+ async () => {
1755
+ await writeCopies(this.deps, [...added, ...updated], copies);
1756
+ return applyRemovals(this.deps, lock, removals);
1757
+ },
1758
+ (kept2) => kept2.length > 0 ? { title: "Done, but kept", tone: "warning", lines: kept2 } : { title: "Done" }
1759
+ );
1760
+ const [first, ...rest] = [
1761
+ ["installed", added.length],
1762
+ ["updated", updated.length],
1763
+ ["removed", removing.length]
1764
+ ].filter(([, count]) => count > 0);
1765
+ const message = [`${first[0]} ${plural(first[1], "skill")}`, ...rest.map(([verb, count]) => `${verb} ${count}`)];
1766
+ const sentence = message.join(", ");
1767
+ ui.outro(`${sentence[0].toUpperCase()}${sentence.slice(1)}.`, {
1768
+ lines: [
1769
+ ...added.length + updated.length > 0 ? ["Start a new agent session to use them."] : [],
1770
+ ...kept.length > 0 ? [KEPT_ADVICE] : []
1771
+ ]
1772
+ });
1773
+ return 0;
1774
+ }
1775
+ /** The list of skills, plus the latest version of each installed one to spot updates. */
1776
+ async fetchCatalog(lock, signal) {
1777
+ const { api } = this.deps;
1778
+ const installed = Object.keys(lock.skills);
1779
+ const [available, versions] = await Promise.all([
1780
+ api.list(signal),
1781
+ Promise.all(
1782
+ installed.map(
1783
+ (name) => api.get(name, signal).catch((error) => {
1784
+ if (error instanceof SkillNotFoundError) return null;
1785
+ throw error;
1786
+ })
1787
+ )
1788
+ )
1789
+ ]);
1790
+ return { available, latest: new Map(installed.map((name, i) => [name, versions[i]])) };
1791
+ }
1792
+ hint(lock, name, latest) {
1793
+ const entry = lock.skills[name];
1794
+ if (!entry) return void 0;
1795
+ const where = entry.paths.map((dir) => tildify(path9.dirname(dir))).join(", ");
1796
+ if (latest.get(name) === null) return `${where} \xB7 no longer available`;
1797
+ return isOutdated(lock, name, latest) ? `${where} \xB7 update available` : where;
1798
+ }
1799
+ summarise(ui, lock, added, updated, removing, copies, removals) {
1800
+ const dirsOf = (skill) => copies.filter((copy) => copy.skill === skill).map((copy) => tildify(path9.dirname(copy.dir)));
1801
+ const rows = [
1802
+ ...added.map((skill) => [paint.success("+"), skill.name, dirsOf(skill).join(", ")]),
1803
+ ...updated.map((skill) => [
1804
+ paint.accent("\u2191"),
1805
+ skill.name,
1806
+ describeChange(lock.skills[skill.name], skill)
1807
+ ]),
1808
+ ...removing.map((name) => [
1809
+ paint.error("\u2212"),
1810
+ name,
1811
+ lock.skills[name].paths.map((dir) => tildify(path9.dirname(dir))).join(", ")
1812
+ ])
1813
+ ];
1814
+ const width = Math.max(...rows.map(([, name]) => name.length));
1815
+ ui.step({
1816
+ title: "Changes",
1817
+ lines: rows.map(([mark, name, detail2]) => `${mark} ${name.padEnd(width)} ${paint.muted(detail2)}`)
1620
1818
  });
1819
+ const warnings = [
1820
+ ...copies.flatMap((copy) => copy.problem ? [[tildify(copy.dir), copy.problem]] : []),
1821
+ ...removals.flatMap((removal) => removal.edited ? [[tildify(removal.dir), "has local edits"]] : [])
1822
+ ];
1823
+ if (warnings.length > 0) {
1824
+ const dirWidth = Math.max(...warnings.map(([dir]) => dir.length));
1825
+ ui.step({
1826
+ title: warnings.length === 1 ? "This would overwrite changes" : "These would overwrite changes",
1827
+ tone: "warning",
1828
+ lines: warnings.map(([dir, problem]) => `${dir.padEnd(dirWidth)} ${problem}`)
1829
+ });
1830
+ }
1621
1831
  }
1622
1832
  };
1833
+ function isOutdated(lock, name, latest) {
1834
+ const version2 = latest.get(name);
1835
+ return Boolean(version2 && lock.skills[name] && version2.commit !== lock.skills[name].commit);
1836
+ }
1623
1837
 
1624
1838
  // src/commands/skills/RemoveFlow.ts
1625
- import path7 from "path";
1839
+ import path10 from "path";
1626
1840
  var RemoveFlow = class {
1627
1841
  constructor(deps) {
1628
1842
  this.deps = deps;
1629
1843
  }
1630
1844
  async run(ui, options, ctx) {
1631
- const { lockfile, files, targets } = this.deps;
1845
+ const { lockfile, targets } = this.deps;
1632
1846
  const lock = await lockfile.read();
1633
1847
  const installed = Object.keys(lock.skills).sort();
1634
1848
  if (installed.length === 0) {
@@ -1637,14 +1851,7 @@ var RemoveFlow = class {
1637
1851
  }
1638
1852
  const names = await this.chooseSkills(ui, options, ctx, installed, lock);
1639
1853
  const only = options.targets.length ? new Set(targets.filter((target) => options.targets.includes(target.id)).map((target) => target.dir)) : null;
1640
- const removals = [];
1641
- for (const name of names) {
1642
- const { paths, files: expected } = lock.skills[name];
1643
- for (const dir of paths.filter((dir2) => !only || only.has(path7.dirname(dir2)))) {
1644
- const { exists, changed } = await files.compare(dir, expected);
1645
- removals.push({ name, dir, exists, edited: exists && changed.length > 0 });
1646
- }
1647
- }
1854
+ const removals = await planRemovals(this.deps, lock, names, only ?? void 0);
1648
1855
  if (removals.length === 0)
1649
1856
  throw new CliError("They aren't installed there", `run ${ctx.bin} skills list to see where they are`);
1650
1857
  const width = Math.max(...removals.map((removal) => tildify(removal.dir).length));
@@ -1667,25 +1874,11 @@ var RemoveFlow = class {
1667
1874
  }
1668
1875
  const kept = await ui.task(
1669
1876
  "Removing",
1670
- async () => {
1671
- const kept2 = [];
1672
- for (const removal of removals) {
1673
- const { files: owned } = lock.skills[removal.name];
1674
- const left = removal.exists ? await files.remove(removal.dir, Object.keys(owned)) : [];
1675
- if (left.length > 0) kept2.push(`${tildify(removal.dir)} ${plural(left.length, "file")} zion didn't install`);
1676
- await lockfile.update((data) => {
1677
- const entry = data.skills[removal.name];
1678
- if (!entry) return;
1679
- entry.paths = entry.paths.filter((dir) => dir !== removal.dir);
1680
- if (entry.paths.length === 0) delete data.skills[removal.name];
1681
- });
1682
- }
1683
- return kept2;
1684
- },
1685
- (kept2) => kept2.length > 0 ? { title: "Removed, but kept", tone: "warning", lines: kept2 } : { title: "Removed", lines: [names.join(", ")] }
1877
+ () => applyRemovals(this.deps, lock, removals),
1878
+ (kept2) => describeKept(kept2, names)
1686
1879
  );
1687
1880
  ui.outro(`Removed ${plural(names.length, "skill")}.`, {
1688
- lines: kept.length > 0 ? ["Delete what was kept yourself if you no longer need it."] : []
1881
+ lines: kept.length > 0 ? [KEPT_ADVICE] : []
1689
1882
  });
1690
1883
  return 0;
1691
1884
  }
@@ -1701,7 +1894,7 @@ var RemoveFlow = class {
1701
1894
  options: installed.map((name) => ({
1702
1895
  value: name,
1703
1896
  label: name,
1704
- hint: lock.skills[name].paths.map((dir) => tildify(path7.dirname(dir))).join(", ")
1897
+ hint: lock.skills[name].paths.map((dir) => tildify(path10.dirname(dir))).join(", ")
1705
1898
  })),
1706
1899
  nonInteractiveHint: `name them, e.g. ${ctx.bin} skills remove ${installed[0]} --yes, or pass --all`
1707
1900
  });
@@ -1744,7 +1937,7 @@ var UpdateFlow = class {
1744
1937
  ),
1745
1938
  (checks2) => describeChecks(checks2, { listUpdates: !pick })
1746
1939
  );
1747
- const outdated = checks.filter(isOutdated);
1940
+ const outdated = checks.filter(isOutdated2);
1748
1941
  if (outdated.length === 0) {
1749
1942
  ui.outro(names.length === 1 ? `${names[0]} is up to date.` : "Everything is up to date.");
1750
1943
  return 0;
@@ -1771,29 +1964,17 @@ var UpdateFlow = class {
1771
1964
  options: outdated.map((check) => ({
1772
1965
  value: check.latest,
1773
1966
  label: check.name,
1774
- hint: describeChange(check).padStart(width)
1967
+ hint: describeChange(check.locked, check.latest).padStart(width)
1775
1968
  })),
1776
1969
  initialValues: outdated.map((check) => check.latest)
1777
1970
  });
1778
1971
  }
1779
1972
  };
1780
- function isOutdated(check) {
1973
+ function isOutdated2(check) {
1781
1974
  return check.latest !== null && check.latest.commit !== check.locked.commit;
1782
1975
  }
1783
- function describeChange({ locked, latest }) {
1784
- const before = locked.files;
1785
- const after = fileHashes(latest);
1786
- const count = (files2) => files2.length;
1787
- const changes = [
1788
- [count(Object.keys(after).filter((file) => file in before && before[file] !== after[file])), "changed"],
1789
- [count(Object.keys(after).filter((file) => !(file in before))), "added"],
1790
- [count(Object.keys(before).filter((file) => !(file in after))), "removed"]
1791
- ];
1792
- const files = changes.filter(([n]) => n > 0).map(([n, what]) => `${n} ${what}`);
1793
- return `${short(locked.commit)} \u2192 ${short(latest.commit)}${files.length ? ` \xB7 ${files.join(", ")}` : ""}`;
1794
- }
1795
1976
  function describeChecks(checks, { listUpdates }) {
1796
- const updates = checks.filter(isOutdated);
1977
+ const updates = checks.filter(isOutdated2);
1797
1978
  const gone = checks.filter((check) => !check.latest);
1798
1979
  if (updates.length === 0 && gone.length === 0) return { title: "Up to date" };
1799
1980
  const shown = [...listUpdates ? updates : [], ...gone];
@@ -1802,42 +1983,18 @@ function describeChecks(checks, { listUpdates }) {
1802
1983
  title: updates.length > 0 ? `${plural(updates.length, "update")} available` : `${plural(gone.length, "skill")} no longer available`,
1803
1984
  tone: gone.length > 0 ? "warning" : "success",
1804
1985
  lines: shown.map(
1805
- (check) => `${check.name.padEnd(width)} ${isOutdated(check) ? paint.muted(describeChange(check)) : "no longer available, left as is"}`
1986
+ (check) => `${check.name.padEnd(width)} ${isOutdated2(check) ? paint.muted(describeChange(check.locked, check.latest)) : "no longer available, left as is"}`
1806
1987
  )
1807
1988
  };
1808
1989
  }
1809
1990
 
1810
1991
  // src/commands/skills/actions.ts
1811
1992
  var SKILLS_ACTIONS = [
1812
- {
1813
- id: "install",
1814
- aliases: ["add"],
1815
- label: "Install skills",
1816
- hint: "choose skills and where they go",
1817
- interactive: true
1818
- },
1819
- {
1820
- id: "update",
1821
- aliases: ["upgrade"],
1822
- label: "Update skills",
1823
- hint: "get the latest of what you have",
1824
- interactive: true
1825
- },
1826
- {
1827
- id: "remove",
1828
- aliases: ["rm", "uninstall"],
1829
- label: "Remove skills",
1830
- hint: "delete skills zion installed",
1831
- interactive: true
1832
- },
1833
- {
1834
- id: "list",
1835
- aliases: ["ls"],
1836
- label: "List",
1837
- hint: "print every skill and where it is installed",
1838
- interactive: false
1839
- },
1840
- { id: "show", aliases: [], label: "Show", hint: "print a skill's SKILL.md", interactive: false }
1993
+ { id: "install", aliases: ["add"], hint: "choose skills and where they go" },
1994
+ { id: "update", aliases: ["upgrade"], hint: "get the latest of what you have" },
1995
+ { id: "remove", aliases: ["rm", "uninstall"], hint: "delete skills zion installed" },
1996
+ { id: "list", aliases: ["ls"], hint: "print every skill and where it is installed" },
1997
+ { id: "show", aliases: [], hint: "print a skill's SKILL.md" }
1841
1998
  ];
1842
1999
  function findSkillsAction(name) {
1843
2000
  return SKILLS_ACTIONS.find((action) => action.id === name || action.aliases.includes(name));
@@ -1894,10 +2051,23 @@ function parseSkillsOptions(args, bin, targetIds) {
1894
2051
  }
1895
2052
 
1896
2053
  // src/commands/skills/output.ts
1897
- import path8 from "path";
2054
+ import path11 from "path";
1898
2055
  async function listSkills({ api, lockfile }, ctx, json) {
1899
- const [available, lock] = await Promise.all([api.list(), lockfile.read()]);
1900
- const names = [.../* @__PURE__ */ new Set([...available, ...Object.keys(lock.skills)])].sort();
2056
+ const [listed, lock] = await Promise.all([api.list(), lockfile.read()]);
2057
+ const unlisted = Object.keys(lock.skills).filter((name) => !listed.includes(name));
2058
+ const found = await Promise.all(
2059
+ unlisted.map(
2060
+ (name) => api.get(name).then(
2061
+ () => true,
2062
+ (error) => {
2063
+ if (error instanceof SkillNotFoundError) return false;
2064
+ throw error;
2065
+ }
2066
+ )
2067
+ )
2068
+ );
2069
+ const available = [...listed, ...unlisted.filter((_, i) => found[i])];
2070
+ const names = [.../* @__PURE__ */ new Set([...listed, ...unlisted])].sort();
1901
2071
  const rows = names.map((name) => {
1902
2072
  const entry = lock.skills[name];
1903
2073
  return {
@@ -1914,7 +2084,7 @@ async function listSkills({ api, lockfile }, ctx, json) {
1914
2084
  useColorsFor(ctx.stdout, ctx.color);
1915
2085
  const width = Math.max(...names.map((name) => name.length));
1916
2086
  for (const row of rows) {
1917
- const status = row.installed ? `${paint.success("installed")} ${paint.muted(short(row.installed.commit))} ${row.installed.paths.map((dir) => tildify(path8.dirname(dir))).join(", ")}` : "";
2087
+ const status = row.installed ? `${paint.success("installed")} ${paint.muted(short(row.installed.commit))} ${row.installed.paths.map((dir) => tildify(path11.dirname(dir))).join(", ")}` : "";
1918
2088
  const gone = row.available ? "" : ` ${paint.warning("no longer available")}`;
1919
2089
  ctx.stdout.write(`${`${row.name.padEnd(width)} ${status}${gone}`.trimEnd()}
1920
2090
  `);
@@ -1943,7 +2113,7 @@ var SkillsCommand = class {
1943
2113
  const { targets, lockfile, api } = deps;
1944
2114
  this.help = {
1945
2115
  usage: `skills ${paint.muted("[action] [skill...] [options]")}`,
1946
- description: `Downloads skills from ${api.host} into the directories your agents load them from. Without an action, you choose one interactively. zion remembers what it installed in ${tildify(lockfile.path)}, and never touches files it didn't write without asking. Targets: ${targets.map((t) => `${t.id} is ${tildify(t.dir)}`).join(", ")}.`,
2116
+ description: `Downloads skills from ${api.host} into the directories your agents load them from. Without an action, it shows every skill as a checklist: tick to install, untick to remove, and installed skills are updated too. When not in a terminal, it prints the list instead. zion remembers what it installed in ${tildify(lockfile.path)}, and never touches files it didn't write without asking. Targets: ${targets.map((t) => `${t.id} is ${tildify(t.dir)}`).join(", ")}.`,
1947
2117
  arguments: {
1948
2118
  title: "Actions",
1949
2119
  rows: SKILLS_ACTIONS.map((action) => [
@@ -1980,47 +2150,30 @@ var SkillsCommand = class {
1980
2150
  if (options.action === "list") return listSkills(this.deps, ctx, options.json);
1981
2151
  if (options.action === "show") return showSkill(this.deps, ctx, options.names[0]);
1982
2152
  const given = options.action;
2153
+ if (!given && !ctx.interactive) return listSkills(this.deps, ctx, false);
1983
2154
  const ui = this.deps.createPrompter(ctx);
1984
2155
  return runSession(ui, async () => {
1985
2156
  ui.intro("skills", this.deps.api.host);
1986
- const action = given ?? await this.chooseAction(ui, ctx);
1987
2157
  const flows = { install: InstallFlow, update: UpdateFlow, remove: RemoveFlow };
1988
- return new flows[action](this.deps).run(ui, options, ctx);
1989
- });
1990
- }
1991
- /** Nothing to update or remove before the first install, so that's the only thing to do. */
1992
- async chooseAction(ui, ctx) {
1993
- const { skills } = await this.deps.lockfile.read();
1994
- if (Object.keys(skills).length === 0) return "install";
1995
- const actions = SKILLS_ACTIONS.filter((action) => action.interactive);
1996
- return ui.select({
1997
- message: "What would you like to do?",
1998
- options: actions.map((action) => ({
1999
- value: action.id,
2000
- label: action.label,
2001
- hint: action.hint
2002
- })),
2003
- nonInteractiveHint: `pass an action, e.g. ${ctx.bin} skills update (one of: ${SKILLS_ACTIONS.map(
2004
- (action) => action.id
2005
- ).join(", ")})`
2158
+ return given ? new flows[given](this.deps).run(ui, options, ctx) : new ManageFlow(this.deps).run(ui);
2006
2159
  });
2007
2160
  }
2008
2161
  };
2009
2162
 
2010
2163
  // src/commands/skills/targets.ts
2011
- import path9 from "path";
2164
+ import path12 from "path";
2012
2165
  function skillTargets(homedir) {
2013
2166
  return [
2014
2167
  {
2015
2168
  id: "agents",
2016
- dir: path9.join(homedir, ".agents", "skills"),
2017
- home: path9.join(homedir, ".agents"),
2169
+ dir: path12.join(homedir, ".agents", "skills"),
2170
+ home: path12.join(homedir, ".agents"),
2018
2171
  hint: "Copilot and other agents"
2019
2172
  },
2020
2173
  {
2021
2174
  id: "claude",
2022
- dir: path9.join(homedir, ".claude", "skills"),
2023
- home: path9.join(homedir, ".claude"),
2175
+ dir: path12.join(homedir, ".claude", "skills"),
2176
+ home: path12.join(homedir, ".claude"),
2024
2177
  hint: "Claude Code"
2025
2178
  }
2026
2179
  ];
@@ -2131,10 +2284,10 @@ var NodeProcessRunner = class {
2131
2284
 
2132
2285
  // src/services/xdg.ts
2133
2286
  import os2 from "os";
2134
- import path10 from "path";
2287
+ import path13 from "path";
2135
2288
  function stateHome(env) {
2136
2289
  const base = env.XDG_STATE_HOME;
2137
- return base && path10.isAbsolute(base) ? base : path10.join(os2.homedir(), ".local", "state");
2290
+ return base && path13.isAbsolute(base) ? base : path13.join(os2.homedir(), ".local", "state");
2138
2291
  }
2139
2292
 
2140
2293
  // src/cli.tsx
@@ -2152,7 +2305,7 @@ var registry = new CommandRegistry().register(
2152
2305
  slug: "zion-off/dotfiles",
2153
2306
  url: "https://github.com/zion-off/dotfiles.git",
2154
2307
  installer: "bin/dot",
2155
- installerLink: path11.join(os3.homedir(), ".local", "bin", "dot")
2308
+ installerLink: path14.join(os3.homedir(), ".local", "bin", "dot")
2156
2309
  }),
2157
2310
  git,
2158
2311
  runner,
@@ -2163,9 +2316,9 @@ var registry = new CommandRegistry().register(
2163
2316
  })
2164
2317
  ).register(
2165
2318
  new SkillsCommand({
2166
- api: new HttpSkillsApi("https://zzzzion.com/api/skills"),
2319
+ api: new HttpSkillsApi(process.env.ZION_SKILLS_URL || "https://zzzzion.com/api/skills"),
2167
2320
  files: new NodeSkillFiles(),
2168
- lockfile: new JsonLockfile(path11.join(stateHome(process.env), "zion.json")),
2321
+ lockfile: new JsonLockfile(path14.join(stateHome(process.env), "zion.json")),
2169
2322
  targets: skillTargets(os3.homedir()),
2170
2323
  createPrompter,
2171
2324
  now: () => /* @__PURE__ */ new Date()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zion",
3
- "version": "2.4.0",
3
+ "version": "2.5.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",