zion 2.4.0 → 2.5.0
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.js +278 -145
- 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
|
|
5
|
+
import path14 from "path";
|
|
6
6
|
|
|
7
7
|
// package.json
|
|
8
|
-
var version = "2.
|
|
8
|
+
var version = "2.5.0";
|
|
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
|
|
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
|
-
|
|
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({
|
|
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(
|
|
1232
|
-
this.path =
|
|
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(
|
|
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(
|
|
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:
|
|
1433
|
-
if (typeof
|
|
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}/${
|
|
1444
|
+
throw new CliError(`${this.host} sent a damaged copy of ${name}/${path15}`, "try again in a moment");
|
|
1437
1445
|
}
|
|
1438
|
-
return { path:
|
|
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
|
|
1459
|
+
import path7 from "path";
|
|
1452
1460
|
|
|
1453
|
-
// src/commands/skills/
|
|
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(
|
|
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"}`;
|
|
@@ -1538,7 +1580,7 @@ var InstallFlow = class {
|
|
|
1538
1580
|
);
|
|
1539
1581
|
if (available.length === 0) throw new CliError(`${api.host} has no skills right now`, "try again later");
|
|
1540
1582
|
const names = await this.chooseSkills(ui, options, ctx, available, lock);
|
|
1541
|
-
const targets = await
|
|
1583
|
+
const targets = await chooseTargets(ui, this.deps, options.targets, lock);
|
|
1542
1584
|
const skills = await ui.task(
|
|
1543
1585
|
`Downloading ${names.join(", ")}`,
|
|
1544
1586
|
(signal) => Promise.all(names.map((name) => api.get(name, signal))),
|
|
@@ -1561,7 +1603,7 @@ var InstallFlow = class {
|
|
|
1561
1603
|
this.deps,
|
|
1562
1604
|
skill,
|
|
1563
1605
|
lock.skills[skill.name],
|
|
1564
|
-
dirs.map((dir) =>
|
|
1606
|
+
dirs.map((dir) => path7.join(dir, skill.name))
|
|
1565
1607
|
)
|
|
1566
1608
|
)
|
|
1567
1609
|
)).flat();
|
|
@@ -1599,36 +1641,201 @@ var InstallFlow = class {
|
|
|
1599
1641
|
nonInteractiveHint: `name them, e.g. ${ctx.bin} skills install ${available[0]}, or pass --all`
|
|
1600
1642
|
});
|
|
1601
1643
|
}
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1644
|
+
};
|
|
1645
|
+
|
|
1646
|
+
// src/commands/skills/ManageFlow.ts
|
|
1647
|
+
import path9 from "path";
|
|
1648
|
+
|
|
1649
|
+
// src/commands/skills/removals.ts
|
|
1650
|
+
import path8 from "path";
|
|
1651
|
+
async function planRemovals({ files }, lock, names, only) {
|
|
1652
|
+
const removals = [];
|
|
1653
|
+
for (const name of names) {
|
|
1654
|
+
const { paths, files: expected } = lock.skills[name];
|
|
1655
|
+
for (const dir of paths.filter((dir2) => !only || only.has(path8.dirname(dir2)))) {
|
|
1656
|
+
const { exists, changed } = await files.compare(dir, expected);
|
|
1657
|
+
removals.push({ name, dir, exists, edited: exists && changed.length > 0 });
|
|
1608
1658
|
}
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1659
|
+
}
|
|
1660
|
+
return removals;
|
|
1661
|
+
}
|
|
1662
|
+
async function applyRemovals({ files, lockfile }, lock, removals) {
|
|
1663
|
+
const kept = [];
|
|
1664
|
+
for (const removal of removals) {
|
|
1665
|
+
const owned = Object.keys(lock.skills[removal.name].files);
|
|
1666
|
+
const left = removal.exists ? await files.remove(removal.dir, owned) : [];
|
|
1667
|
+
if (left.length > 0) kept.push(`${tildify(removal.dir)} ${plural(left.length, "file")} zion didn't install`);
|
|
1668
|
+
await lockfile.update((data) => {
|
|
1669
|
+
const entry = data.skills[removal.name];
|
|
1670
|
+
if (!entry) return;
|
|
1671
|
+
entry.paths = entry.paths.filter((dir) => dir !== removal.dir);
|
|
1672
|
+
if (entry.paths.length === 0) delete data.skills[removal.name];
|
|
1673
|
+
});
|
|
1674
|
+
}
|
|
1675
|
+
return kept;
|
|
1676
|
+
}
|
|
1677
|
+
function describeKept(kept, removed) {
|
|
1678
|
+
return kept.length > 0 ? { title: "Removed, but kept", tone: "warning", lines: kept } : { title: "Removed", lines: [removed.join(", ")] };
|
|
1679
|
+
}
|
|
1680
|
+
var KEPT_ADVICE = "Delete what was kept yourself if you no longer need it.";
|
|
1681
|
+
|
|
1682
|
+
// src/commands/skills/ManageFlow.ts
|
|
1683
|
+
var ManageFlow = class {
|
|
1684
|
+
constructor(deps) {
|
|
1685
|
+
this.deps = deps;
|
|
1686
|
+
}
|
|
1687
|
+
async run(ui) {
|
|
1688
|
+
const { api, lockfile } = this.deps;
|
|
1689
|
+
const lock = await lockfile.read();
|
|
1690
|
+
const installed = Object.keys(lock.skills);
|
|
1691
|
+
const { available, latest } = await ui.task(
|
|
1692
|
+
"Fetching skills",
|
|
1693
|
+
(signal) => this.fetchCatalog(lock, signal),
|
|
1694
|
+
({ available: available2, latest: latest2 }) => {
|
|
1695
|
+
const updates = installed.filter((name) => isOutdated(lock, name, latest2)).length;
|
|
1696
|
+
return {
|
|
1697
|
+
title: [plural(available2.length, "skill"), updates > 0 && plural(updates, "update")].filter(Boolean).join(" \xB7 ")
|
|
1698
|
+
};
|
|
1699
|
+
}
|
|
1700
|
+
);
|
|
1701
|
+
const names = [.../* @__PURE__ */ new Set([...available, ...installed])].sort();
|
|
1702
|
+
const ticked = new Set(
|
|
1703
|
+
await ui.multiselect({
|
|
1704
|
+
message: "Your skills",
|
|
1705
|
+
options: names.map((name) => ({ value: name, label: name, hint: this.hint(lock, name, latest) })),
|
|
1706
|
+
initialValues: installed,
|
|
1707
|
+
required: false
|
|
1708
|
+
})
|
|
1709
|
+
);
|
|
1710
|
+
const adding = names.filter((name) => ticked.has(name) && !lock.skills[name]);
|
|
1711
|
+
const updating = installed.filter((name) => ticked.has(name) && isOutdated(lock, name, latest));
|
|
1712
|
+
const removing = installed.filter((name) => !ticked.has(name));
|
|
1713
|
+
if (adding.length + updating.length + removing.length === 0) {
|
|
1714
|
+
ui.outro("Nothing to change.", { tone: "muted" });
|
|
1715
|
+
return 0;
|
|
1614
1716
|
}
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1717
|
+
const targets = adding.length > 0 ? await chooseTargets(ui, this.deps, [], lock) : [];
|
|
1718
|
+
const added = adding.length > 0 ? await ui.task(
|
|
1719
|
+
`Downloading ${adding.join(", ")}`,
|
|
1720
|
+
(signal) => Promise.all(adding.map((name) => api.get(name, signal))),
|
|
1721
|
+
(skills) => ({ title: `Downloaded ${plural(skills.length, "skill")}` })
|
|
1722
|
+
) : [];
|
|
1723
|
+
const updated = updating.map((name) => latest.get(name));
|
|
1724
|
+
const copies = [
|
|
1725
|
+
...(await Promise.all(
|
|
1726
|
+
added.map(
|
|
1727
|
+
(skill) => planCopies(
|
|
1728
|
+
this.deps,
|
|
1729
|
+
skill,
|
|
1730
|
+
void 0,
|
|
1731
|
+
targets.map((target) => path9.join(target.dir, skill.name))
|
|
1732
|
+
)
|
|
1733
|
+
)
|
|
1734
|
+
)).flat(),
|
|
1735
|
+
...(await Promise.all(updated.map((skill) => planCopies(this.deps, skill, lock.skills[skill.name], [])))).flat()
|
|
1736
|
+
];
|
|
1737
|
+
const removals = await planRemovals(this.deps, lock, removing);
|
|
1738
|
+
this.summarise(ui, lock, added, updated, removing, copies, removals);
|
|
1739
|
+
const risky = copies.some((copy) => copy.problem) || removals.some((removal) => removal.edited);
|
|
1740
|
+
const total = added.length + updated.length + removing.length;
|
|
1741
|
+
if (!await ui.confirm({ message: `Apply ${plural(total, "change")}?`, defaultValue: !risky })) {
|
|
1742
|
+
ui.outro("Left everything as it was.", { tone: "muted" });
|
|
1743
|
+
return 0;
|
|
1744
|
+
}
|
|
1745
|
+
const kept = await ui.task(
|
|
1746
|
+
"Applying",
|
|
1747
|
+
async () => {
|
|
1748
|
+
await writeCopies(this.deps, [...added, ...updated], copies);
|
|
1749
|
+
return applyRemovals(this.deps, lock, removals);
|
|
1750
|
+
},
|
|
1751
|
+
(kept2) => kept2.length > 0 ? { title: "Done, but kept", tone: "warning", lines: kept2 } : { title: "Done" }
|
|
1752
|
+
);
|
|
1753
|
+
const [first, ...rest] = [
|
|
1754
|
+
["installed", added.length],
|
|
1755
|
+
["updated", updated.length],
|
|
1756
|
+
["removed", removing.length]
|
|
1757
|
+
].filter(([, count]) => count > 0);
|
|
1758
|
+
const message = [`${first[0]} ${plural(first[1], "skill")}`, ...rest.map(([verb, count]) => `${verb} ${count}`)];
|
|
1759
|
+
const sentence = message.join(", ");
|
|
1760
|
+
ui.outro(`${sentence[0].toUpperCase()}${sentence.slice(1)}.`, {
|
|
1761
|
+
lines: [
|
|
1762
|
+
...added.length + updated.length > 0 ? ["Start a new agent session to use them."] : [],
|
|
1763
|
+
...kept.length > 0 ? [KEPT_ADVICE] : []
|
|
1764
|
+
]
|
|
1620
1765
|
});
|
|
1766
|
+
return 0;
|
|
1767
|
+
}
|
|
1768
|
+
/** The list of skills, plus the latest version of each installed one to spot updates. */
|
|
1769
|
+
async fetchCatalog(lock, signal) {
|
|
1770
|
+
const { api } = this.deps;
|
|
1771
|
+
const installed = Object.keys(lock.skills);
|
|
1772
|
+
const [available, versions] = await Promise.all([
|
|
1773
|
+
api.list(signal),
|
|
1774
|
+
Promise.all(
|
|
1775
|
+
installed.map(
|
|
1776
|
+
(name) => api.get(name, signal).catch((error) => {
|
|
1777
|
+
if (error instanceof SkillNotFoundError) return null;
|
|
1778
|
+
throw error;
|
|
1779
|
+
})
|
|
1780
|
+
)
|
|
1781
|
+
)
|
|
1782
|
+
]);
|
|
1783
|
+
return { available, latest: new Map(installed.map((name, i) => [name, versions[i]])) };
|
|
1784
|
+
}
|
|
1785
|
+
hint(lock, name, latest) {
|
|
1786
|
+
const entry = lock.skills[name];
|
|
1787
|
+
if (!entry) return void 0;
|
|
1788
|
+
const where = entry.paths.map((dir) => tildify(path9.dirname(dir))).join(", ");
|
|
1789
|
+
if (latest.get(name) === null) return `${where} \xB7 no longer available`;
|
|
1790
|
+
return isOutdated(lock, name, latest) ? `${where} \xB7 update available` : where;
|
|
1791
|
+
}
|
|
1792
|
+
summarise(ui, lock, added, updated, removing, copies, removals) {
|
|
1793
|
+
const dirsOf = (skill) => copies.filter((copy) => copy.skill === skill).map((copy) => tildify(path9.dirname(copy.dir)));
|
|
1794
|
+
const rows = [
|
|
1795
|
+
...added.map((skill) => [paint.success("+"), skill.name, dirsOf(skill).join(", ")]),
|
|
1796
|
+
...updated.map((skill) => [
|
|
1797
|
+
paint.accent("\u2191"),
|
|
1798
|
+
skill.name,
|
|
1799
|
+
describeChange(lock.skills[skill.name], skill)
|
|
1800
|
+
]),
|
|
1801
|
+
...removing.map((name) => [
|
|
1802
|
+
paint.error("\u2212"),
|
|
1803
|
+
name,
|
|
1804
|
+
lock.skills[name].paths.map((dir) => tildify(path9.dirname(dir))).join(", ")
|
|
1805
|
+
])
|
|
1806
|
+
];
|
|
1807
|
+
const width = Math.max(...rows.map(([, name]) => name.length));
|
|
1808
|
+
ui.step({
|
|
1809
|
+
title: "Changes",
|
|
1810
|
+
lines: rows.map(([mark, name, detail2]) => `${mark} ${name.padEnd(width)} ${paint.muted(detail2)}`)
|
|
1811
|
+
});
|
|
1812
|
+
const warnings = [
|
|
1813
|
+
...copies.flatMap((copy) => copy.problem ? [[tildify(copy.dir), copy.problem]] : []),
|
|
1814
|
+
...removals.flatMap((removal) => removal.edited ? [[tildify(removal.dir), "has local edits"]] : [])
|
|
1815
|
+
];
|
|
1816
|
+
if (warnings.length > 0) {
|
|
1817
|
+
const dirWidth = Math.max(...warnings.map(([dir]) => dir.length));
|
|
1818
|
+
ui.step({
|
|
1819
|
+
title: warnings.length === 1 ? "This would overwrite changes" : "These would overwrite changes",
|
|
1820
|
+
tone: "warning",
|
|
1821
|
+
lines: warnings.map(([dir, problem]) => `${dir.padEnd(dirWidth)} ${problem}`)
|
|
1822
|
+
});
|
|
1823
|
+
}
|
|
1621
1824
|
}
|
|
1622
1825
|
};
|
|
1826
|
+
function isOutdated(lock, name, latest) {
|
|
1827
|
+
const version2 = latest.get(name);
|
|
1828
|
+
return Boolean(version2 && lock.skills[name] && version2.commit !== lock.skills[name].commit);
|
|
1829
|
+
}
|
|
1623
1830
|
|
|
1624
1831
|
// src/commands/skills/RemoveFlow.ts
|
|
1625
|
-
import
|
|
1832
|
+
import path10 from "path";
|
|
1626
1833
|
var RemoveFlow = class {
|
|
1627
1834
|
constructor(deps) {
|
|
1628
1835
|
this.deps = deps;
|
|
1629
1836
|
}
|
|
1630
1837
|
async run(ui, options, ctx) {
|
|
1631
|
-
const { lockfile,
|
|
1838
|
+
const { lockfile, targets } = this.deps;
|
|
1632
1839
|
const lock = await lockfile.read();
|
|
1633
1840
|
const installed = Object.keys(lock.skills).sort();
|
|
1634
1841
|
if (installed.length === 0) {
|
|
@@ -1637,14 +1844,7 @@ var RemoveFlow = class {
|
|
|
1637
1844
|
}
|
|
1638
1845
|
const names = await this.chooseSkills(ui, options, ctx, installed, lock);
|
|
1639
1846
|
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
|
-
}
|
|
1847
|
+
const removals = await planRemovals(this.deps, lock, names, only ?? void 0);
|
|
1648
1848
|
if (removals.length === 0)
|
|
1649
1849
|
throw new CliError("They aren't installed there", `run ${ctx.bin} skills list to see where they are`);
|
|
1650
1850
|
const width = Math.max(...removals.map((removal) => tildify(removal.dir).length));
|
|
@@ -1667,25 +1867,11 @@ var RemoveFlow = class {
|
|
|
1667
1867
|
}
|
|
1668
1868
|
const kept = await ui.task(
|
|
1669
1869
|
"Removing",
|
|
1670
|
-
|
|
1671
|
-
|
|
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(", ")] }
|
|
1870
|
+
() => applyRemovals(this.deps, lock, removals),
|
|
1871
|
+
(kept2) => describeKept(kept2, names)
|
|
1686
1872
|
);
|
|
1687
1873
|
ui.outro(`Removed ${plural(names.length, "skill")}.`, {
|
|
1688
|
-
lines: kept.length > 0 ? [
|
|
1874
|
+
lines: kept.length > 0 ? [KEPT_ADVICE] : []
|
|
1689
1875
|
});
|
|
1690
1876
|
return 0;
|
|
1691
1877
|
}
|
|
@@ -1701,7 +1887,7 @@ var RemoveFlow = class {
|
|
|
1701
1887
|
options: installed.map((name) => ({
|
|
1702
1888
|
value: name,
|
|
1703
1889
|
label: name,
|
|
1704
|
-
hint: lock.skills[name].paths.map((dir) => tildify(
|
|
1890
|
+
hint: lock.skills[name].paths.map((dir) => tildify(path10.dirname(dir))).join(", ")
|
|
1705
1891
|
})),
|
|
1706
1892
|
nonInteractiveHint: `name them, e.g. ${ctx.bin} skills remove ${installed[0]} --yes, or pass --all`
|
|
1707
1893
|
});
|
|
@@ -1744,7 +1930,7 @@ var UpdateFlow = class {
|
|
|
1744
1930
|
),
|
|
1745
1931
|
(checks2) => describeChecks(checks2, { listUpdates: !pick })
|
|
1746
1932
|
);
|
|
1747
|
-
const outdated = checks.filter(
|
|
1933
|
+
const outdated = checks.filter(isOutdated2);
|
|
1748
1934
|
if (outdated.length === 0) {
|
|
1749
1935
|
ui.outro(names.length === 1 ? `${names[0]} is up to date.` : "Everything is up to date.");
|
|
1750
1936
|
return 0;
|
|
@@ -1771,29 +1957,17 @@ var UpdateFlow = class {
|
|
|
1771
1957
|
options: outdated.map((check) => ({
|
|
1772
1958
|
value: check.latest,
|
|
1773
1959
|
label: check.name,
|
|
1774
|
-
hint: describeChange(check).padStart(width)
|
|
1960
|
+
hint: describeChange(check.locked, check.latest).padStart(width)
|
|
1775
1961
|
})),
|
|
1776
1962
|
initialValues: outdated.map((check) => check.latest)
|
|
1777
1963
|
});
|
|
1778
1964
|
}
|
|
1779
1965
|
};
|
|
1780
|
-
function
|
|
1966
|
+
function isOutdated2(check) {
|
|
1781
1967
|
return check.latest !== null && check.latest.commit !== check.locked.commit;
|
|
1782
1968
|
}
|
|
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
1969
|
function describeChecks(checks, { listUpdates }) {
|
|
1796
|
-
const updates = checks.filter(
|
|
1970
|
+
const updates = checks.filter(isOutdated2);
|
|
1797
1971
|
const gone = checks.filter((check) => !check.latest);
|
|
1798
1972
|
if (updates.length === 0 && gone.length === 0) return { title: "Up to date" };
|
|
1799
1973
|
const shown = [...listUpdates ? updates : [], ...gone];
|
|
@@ -1802,42 +1976,18 @@ function describeChecks(checks, { listUpdates }) {
|
|
|
1802
1976
|
title: updates.length > 0 ? `${plural(updates.length, "update")} available` : `${plural(gone.length, "skill")} no longer available`,
|
|
1803
1977
|
tone: gone.length > 0 ? "warning" : "success",
|
|
1804
1978
|
lines: shown.map(
|
|
1805
|
-
(check) => `${check.name.padEnd(width)} ${
|
|
1979
|
+
(check) => `${check.name.padEnd(width)} ${isOutdated2(check) ? paint.muted(describeChange(check.locked, check.latest)) : "no longer available, left as is"}`
|
|
1806
1980
|
)
|
|
1807
1981
|
};
|
|
1808
1982
|
}
|
|
1809
1983
|
|
|
1810
1984
|
// src/commands/skills/actions.ts
|
|
1811
1985
|
var SKILLS_ACTIONS = [
|
|
1812
|
-
{
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
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 }
|
|
1986
|
+
{ id: "install", aliases: ["add"], hint: "choose skills and where they go" },
|
|
1987
|
+
{ id: "update", aliases: ["upgrade"], hint: "get the latest of what you have" },
|
|
1988
|
+
{ id: "remove", aliases: ["rm", "uninstall"], hint: "delete skills zion installed" },
|
|
1989
|
+
{ id: "list", aliases: ["ls"], hint: "print every skill and where it is installed" },
|
|
1990
|
+
{ id: "show", aliases: [], hint: "print a skill's SKILL.md" }
|
|
1841
1991
|
];
|
|
1842
1992
|
function findSkillsAction(name) {
|
|
1843
1993
|
return SKILLS_ACTIONS.find((action) => action.id === name || action.aliases.includes(name));
|
|
@@ -1894,7 +2044,7 @@ function parseSkillsOptions(args, bin, targetIds) {
|
|
|
1894
2044
|
}
|
|
1895
2045
|
|
|
1896
2046
|
// src/commands/skills/output.ts
|
|
1897
|
-
import
|
|
2047
|
+
import path11 from "path";
|
|
1898
2048
|
async function listSkills({ api, lockfile }, ctx, json) {
|
|
1899
2049
|
const [available, lock] = await Promise.all([api.list(), lockfile.read()]);
|
|
1900
2050
|
const names = [.../* @__PURE__ */ new Set([...available, ...Object.keys(lock.skills)])].sort();
|
|
@@ -1914,7 +2064,7 @@ async function listSkills({ api, lockfile }, ctx, json) {
|
|
|
1914
2064
|
useColorsFor(ctx.stdout, ctx.color);
|
|
1915
2065
|
const width = Math.max(...names.map((name) => name.length));
|
|
1916
2066
|
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(
|
|
2067
|
+
const status = row.installed ? `${paint.success("installed")} ${paint.muted(short(row.installed.commit))} ${row.installed.paths.map((dir) => tildify(path11.dirname(dir))).join(", ")}` : "";
|
|
1918
2068
|
const gone = row.available ? "" : ` ${paint.warning("no longer available")}`;
|
|
1919
2069
|
ctx.stdout.write(`${`${row.name.padEnd(width)} ${status}${gone}`.trimEnd()}
|
|
1920
2070
|
`);
|
|
@@ -1943,7 +2093,7 @@ var SkillsCommand = class {
|
|
|
1943
2093
|
const { targets, lockfile, api } = deps;
|
|
1944
2094
|
this.help = {
|
|
1945
2095
|
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,
|
|
2096
|
+
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
2097
|
arguments: {
|
|
1948
2098
|
title: "Actions",
|
|
1949
2099
|
rows: SKILLS_ACTIONS.map((action) => [
|
|
@@ -1980,47 +2130,30 @@ var SkillsCommand = class {
|
|
|
1980
2130
|
if (options.action === "list") return listSkills(this.deps, ctx, options.json);
|
|
1981
2131
|
if (options.action === "show") return showSkill(this.deps, ctx, options.names[0]);
|
|
1982
2132
|
const given = options.action;
|
|
2133
|
+
if (!given && !ctx.interactive) return listSkills(this.deps, ctx, false);
|
|
1983
2134
|
const ui = this.deps.createPrompter(ctx);
|
|
1984
2135
|
return runSession(ui, async () => {
|
|
1985
2136
|
ui.intro("skills", this.deps.api.host);
|
|
1986
|
-
const action = given ?? await this.chooseAction(ui, ctx);
|
|
1987
2137
|
const flows = { install: InstallFlow, update: UpdateFlow, remove: RemoveFlow };
|
|
1988
|
-
return new flows[
|
|
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(", ")})`
|
|
2138
|
+
return given ? new flows[given](this.deps).run(ui, options, ctx) : new ManageFlow(this.deps).run(ui);
|
|
2006
2139
|
});
|
|
2007
2140
|
}
|
|
2008
2141
|
};
|
|
2009
2142
|
|
|
2010
2143
|
// src/commands/skills/targets.ts
|
|
2011
|
-
import
|
|
2144
|
+
import path12 from "path";
|
|
2012
2145
|
function skillTargets(homedir) {
|
|
2013
2146
|
return [
|
|
2014
2147
|
{
|
|
2015
2148
|
id: "agents",
|
|
2016
|
-
dir:
|
|
2017
|
-
home:
|
|
2149
|
+
dir: path12.join(homedir, ".agents", "skills"),
|
|
2150
|
+
home: path12.join(homedir, ".agents"),
|
|
2018
2151
|
hint: "Copilot and other agents"
|
|
2019
2152
|
},
|
|
2020
2153
|
{
|
|
2021
2154
|
id: "claude",
|
|
2022
|
-
dir:
|
|
2023
|
-
home:
|
|
2155
|
+
dir: path12.join(homedir, ".claude", "skills"),
|
|
2156
|
+
home: path12.join(homedir, ".claude"),
|
|
2024
2157
|
hint: "Claude Code"
|
|
2025
2158
|
}
|
|
2026
2159
|
];
|
|
@@ -2131,10 +2264,10 @@ var NodeProcessRunner = class {
|
|
|
2131
2264
|
|
|
2132
2265
|
// src/services/xdg.ts
|
|
2133
2266
|
import os2 from "os";
|
|
2134
|
-
import
|
|
2267
|
+
import path13 from "path";
|
|
2135
2268
|
function stateHome(env) {
|
|
2136
2269
|
const base = env.XDG_STATE_HOME;
|
|
2137
|
-
return base &&
|
|
2270
|
+
return base && path13.isAbsolute(base) ? base : path13.join(os2.homedir(), ".local", "state");
|
|
2138
2271
|
}
|
|
2139
2272
|
|
|
2140
2273
|
// src/cli.tsx
|
|
@@ -2152,7 +2285,7 @@ var registry = new CommandRegistry().register(
|
|
|
2152
2285
|
slug: "zion-off/dotfiles",
|
|
2153
2286
|
url: "https://github.com/zion-off/dotfiles.git",
|
|
2154
2287
|
installer: "bin/dot",
|
|
2155
|
-
installerLink:
|
|
2288
|
+
installerLink: path14.join(os3.homedir(), ".local", "bin", "dot")
|
|
2156
2289
|
}),
|
|
2157
2290
|
git,
|
|
2158
2291
|
runner,
|
|
@@ -2165,7 +2298,7 @@ var registry = new CommandRegistry().register(
|
|
|
2165
2298
|
new SkillsCommand({
|
|
2166
2299
|
api: new HttpSkillsApi("https://zzzzion.com/api/skills"),
|
|
2167
2300
|
files: new NodeSkillFiles(),
|
|
2168
|
-
lockfile: new JsonLockfile(
|
|
2301
|
+
lockfile: new JsonLockfile(path14.join(stateHome(process.env), "zion.json")),
|
|
2169
2302
|
targets: skillTargets(os3.homedir()),
|
|
2170
2303
|
createPrompter,
|
|
2171
2304
|
now: () => /* @__PURE__ */ new Date()
|