zion 4.2.1 → 4.3.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 +659 -181
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
|
|
6
6
|
// src/cli.tsx
|
|
7
7
|
import os3 from "os";
|
|
8
|
-
import
|
|
8
|
+
import path16 from "path";
|
|
9
9
|
|
|
10
10
|
// package.json
|
|
11
|
-
var version = "4.
|
|
11
|
+
var version = "4.3.0";
|
|
12
12
|
|
|
13
13
|
// src/lib/theme.ts
|
|
14
14
|
import { Chalk, supportsColor, supportsColorStderr } from "chalk";
|
|
@@ -733,26 +733,30 @@ function useListCursor(count, initialIndex = 0) {
|
|
|
733
733
|
|
|
734
734
|
// src/prompts/components/MultiSelectPrompt.tsx
|
|
735
735
|
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
736
|
-
function MultiSelectPrompt({ message, options, initialValues, required: required2, onSubmit }) {
|
|
736
|
+
function MultiSelectPrompt({ message, options, initialValues, required: required2, mark, onSubmit }) {
|
|
737
737
|
const paint = usePaint();
|
|
738
738
|
const count = options.length;
|
|
739
739
|
const { index, move } = useListCursor(count);
|
|
740
740
|
const [chosen, setChosen] = useState3(
|
|
741
741
|
() => new Set(options.flatMap((option, i) => initialValues.includes(option.value) ? [i] : []))
|
|
742
742
|
);
|
|
743
|
+
const [marked, setMarked] = useState3(
|
|
744
|
+
() => new Set(options.flatMap((option, i) => mark?.initialValues.includes(option.value) ? [i] : []))
|
|
745
|
+
);
|
|
743
746
|
const [error62, setError] = useState3(null);
|
|
744
747
|
const submitted = useRef2(false);
|
|
745
|
-
const
|
|
748
|
+
const flip = (i) => (current) => {
|
|
746
749
|
const next = new Set(current);
|
|
747
750
|
if (next.has(i)) next.delete(i);
|
|
748
751
|
else next.add(i);
|
|
749
752
|
return next;
|
|
750
|
-
}
|
|
753
|
+
};
|
|
751
754
|
useInput2((input2, key) => {
|
|
752
755
|
if (submitted.current) return;
|
|
753
756
|
setError(null);
|
|
754
757
|
if (move(input2, key)) return;
|
|
755
|
-
if (input2 === " ")
|
|
758
|
+
if (input2 === " ") setChosen(flip(index));
|
|
759
|
+
else if (mark && input2 === mark.key) setMarked(flip(index));
|
|
756
760
|
else if (input2 === "a") setChosen((current) => new Set(current.size === count ? [] : options.map((_, i) => i)));
|
|
757
761
|
else if (key.return) {
|
|
758
762
|
if (required2 && chosen.size === 0) {
|
|
@@ -760,10 +764,16 @@ function MultiSelectPrompt({ message, options, initialValues, required: required
|
|
|
760
764
|
return;
|
|
761
765
|
}
|
|
762
766
|
submitted.current = true;
|
|
763
|
-
onSubmit(
|
|
767
|
+
onSubmit(
|
|
768
|
+
options.filter((_, i) => chosen.has(i)),
|
|
769
|
+
options.filter((_, i) => marked.has(i))
|
|
770
|
+
);
|
|
764
771
|
}
|
|
765
772
|
});
|
|
766
|
-
const
|
|
773
|
+
const shown2 = options.map(
|
|
774
|
+
(option, i) => mark && marked.has(i) ? { ...option, hint: [mark.label, option.hint].filter(Boolean).join(" \xB7 ") } : option
|
|
775
|
+
);
|
|
776
|
+
const body = formatOptions(paint, shown2, index, (i, label) => {
|
|
767
777
|
const on = chosen.has(i);
|
|
768
778
|
return {
|
|
769
779
|
marker: on ? paint.accent(symbols.checkOn) : paint.muted(symbols.checkOff),
|
|
@@ -774,6 +784,7 @@ function MultiSelectPrompt({ message, options, initialValues, required: required
|
|
|
774
784
|
["\u2191\u2193", "move"],
|
|
775
785
|
["space", "choose"],
|
|
776
786
|
["a", "all"],
|
|
787
|
+
...mark ? [[mark.key, mark.label]] : [],
|
|
777
788
|
["enter", "confirm"],
|
|
778
789
|
["ctrl+c", "cancel"]
|
|
779
790
|
]);
|
|
@@ -967,6 +978,28 @@ var InkPrompter = class extends BasePrompter {
|
|
|
967
978
|
(values) => this.multiselectAnswer(message, options, values)
|
|
968
979
|
);
|
|
969
980
|
}
|
|
981
|
+
multiselectMarked({
|
|
982
|
+
message,
|
|
983
|
+
options,
|
|
984
|
+
initialValues = [],
|
|
985
|
+
required: required2 = true,
|
|
986
|
+
mark
|
|
987
|
+
}) {
|
|
988
|
+
return this.ask(
|
|
989
|
+
(submit) => /* @__PURE__ */ jsx8(
|
|
990
|
+
MultiSelectPrompt,
|
|
991
|
+
{
|
|
992
|
+
message,
|
|
993
|
+
options,
|
|
994
|
+
initialValues,
|
|
995
|
+
required: required2,
|
|
996
|
+
mark,
|
|
997
|
+
onSubmit: (chosen, marked) => submit({ chosen: chosen.map((option) => option.value), marked: marked.map((option) => option.value) })
|
|
998
|
+
}
|
|
999
|
+
),
|
|
1000
|
+
({ chosen }) => this.multiselectAnswer(message, options, chosen)
|
|
1001
|
+
);
|
|
1002
|
+
}
|
|
970
1003
|
confirm({ message, defaultValue = false }) {
|
|
971
1004
|
return this.ask(
|
|
972
1005
|
(submit) => /* @__PURE__ */ jsx8(ConfirmPrompt, { message, defaultValue, onSubmit: submit }),
|
|
@@ -1048,6 +1081,9 @@ var PlainPrompter = class extends BasePrompter {
|
|
|
1048
1081
|
this.step(this.multiselectAnswer(message, options, values));
|
|
1049
1082
|
return values;
|
|
1050
1083
|
}
|
|
1084
|
+
async multiselectMarked(options) {
|
|
1085
|
+
return { chosen: await this.multiselect(options), marked: [...options.mark.initialValues] };
|
|
1086
|
+
}
|
|
1051
1087
|
async confirm({ message, defaultValue, nonInteractiveHint }) {
|
|
1052
1088
|
this.assertCanPrompt();
|
|
1053
1089
|
if (defaultValue === void 0 || nonInteractiveHint) {
|
|
@@ -2290,10 +2326,10 @@ function mergeDefs(...defs) {
|
|
|
2290
2326
|
function cloneDef(schema) {
|
|
2291
2327
|
return mergeDefs(schema._zod.def);
|
|
2292
2328
|
}
|
|
2293
|
-
function getElementAtPath(obj,
|
|
2294
|
-
if (!
|
|
2329
|
+
function getElementAtPath(obj, path17) {
|
|
2330
|
+
if (!path17)
|
|
2295
2331
|
return obj;
|
|
2296
|
-
return
|
|
2332
|
+
return path17.reduce((acc, key) => acc?.[key], obj);
|
|
2297
2333
|
}
|
|
2298
2334
|
function promiseAllObject(promisesObj) {
|
|
2299
2335
|
const keys = Object.keys(promisesObj);
|
|
@@ -2633,11 +2669,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
2633
2669
|
}
|
|
2634
2670
|
return false;
|
|
2635
2671
|
}
|
|
2636
|
-
function prefixIssues(
|
|
2672
|
+
function prefixIssues(path17, issues) {
|
|
2637
2673
|
return issues.map((iss) => {
|
|
2638
2674
|
var _a3;
|
|
2639
2675
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
2640
|
-
iss.path.unshift(
|
|
2676
|
+
iss.path.unshift(path17);
|
|
2641
2677
|
return iss;
|
|
2642
2678
|
});
|
|
2643
2679
|
}
|
|
@@ -3099,16 +3135,16 @@ function flattenError(error62, mapper = (issue2) => issue2.message) {
|
|
|
3099
3135
|
}
|
|
3100
3136
|
function formatError2(error62, mapper = (issue2) => issue2.message) {
|
|
3101
3137
|
const fieldErrors = { _errors: [] };
|
|
3102
|
-
const processError = (error63,
|
|
3138
|
+
const processError = (error63, path17 = []) => {
|
|
3103
3139
|
for (const issue2 of error63.issues) {
|
|
3104
3140
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
3105
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
3141
|
+
issue2.errors.map((issues) => processError({ issues }, [...path17, ...issue2.path]));
|
|
3106
3142
|
} else if (issue2.code === "invalid_key") {
|
|
3107
|
-
processError({ issues: issue2.issues }, [...
|
|
3143
|
+
processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
|
|
3108
3144
|
} else if (issue2.code === "invalid_element") {
|
|
3109
|
-
processError({ issues: issue2.issues }, [...
|
|
3145
|
+
processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
|
|
3110
3146
|
} else {
|
|
3111
|
-
const fullpath = [...
|
|
3147
|
+
const fullpath = [...path17, ...issue2.path];
|
|
3112
3148
|
if (fullpath.length === 0) {
|
|
3113
3149
|
fieldErrors._errors.push(mapper(issue2));
|
|
3114
3150
|
} else {
|
|
@@ -3147,17 +3183,17 @@ function formatError2(error62, mapper = (issue2) => issue2.message) {
|
|
|
3147
3183
|
}
|
|
3148
3184
|
function treeifyError(error62, mapper = (issue2) => issue2.message) {
|
|
3149
3185
|
const result = { errors: [] };
|
|
3150
|
-
const processError = (error63,
|
|
3186
|
+
const processError = (error63, path17 = []) => {
|
|
3151
3187
|
var _a3;
|
|
3152
3188
|
for (const issue2 of error63.issues) {
|
|
3153
3189
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
3154
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
3190
|
+
issue2.errors.map((issues) => processError({ issues }, [...path17, ...issue2.path]));
|
|
3155
3191
|
} else if (issue2.code === "invalid_key") {
|
|
3156
|
-
processError({ issues: issue2.issues }, [...
|
|
3192
|
+
processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
|
|
3157
3193
|
} else if (issue2.code === "invalid_element") {
|
|
3158
|
-
processError({ issues: issue2.issues }, [...
|
|
3194
|
+
processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
|
|
3159
3195
|
} else {
|
|
3160
|
-
const fullpath = [...
|
|
3196
|
+
const fullpath = [...path17, ...issue2.path];
|
|
3161
3197
|
if (fullpath.length === 0) {
|
|
3162
3198
|
result.errors.push(mapper(issue2));
|
|
3163
3199
|
continue;
|
|
@@ -3196,8 +3232,8 @@ function treeifyError(error62, mapper = (issue2) => issue2.message) {
|
|
|
3196
3232
|
}
|
|
3197
3233
|
function toDotPath(_path) {
|
|
3198
3234
|
const segs = [];
|
|
3199
|
-
const
|
|
3200
|
-
for (const seg of
|
|
3235
|
+
const path17 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
3236
|
+
for (const seg of path17) {
|
|
3201
3237
|
if (typeof seg === "number")
|
|
3202
3238
|
segs.push(`[${seg}]`);
|
|
3203
3239
|
else if (typeof seg === "symbol")
|
|
@@ -20335,13 +20371,13 @@ function resolveRef(ref, ctx) {
|
|
|
20335
20371
|
if (!ref.startsWith("#")) {
|
|
20336
20372
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
20337
20373
|
}
|
|
20338
|
-
const
|
|
20339
|
-
if (
|
|
20374
|
+
const path17 = ref.slice(1).split("/").filter(Boolean);
|
|
20375
|
+
if (path17.length === 0) {
|
|
20340
20376
|
return ctx.rootSchema;
|
|
20341
20377
|
}
|
|
20342
20378
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
20343
|
-
if (
|
|
20344
|
-
const key =
|
|
20379
|
+
if (path17[0] === defsKey) {
|
|
20380
|
+
const key = path17[1] === void 0 ? void 0 : decodeJSONPointerSegment(path17[1]);
|
|
20345
20381
|
if (!key || !ctx.defs[key]) {
|
|
20346
20382
|
throw new Error(`Reference not found: ${ref}`);
|
|
20347
20383
|
}
|
|
@@ -21206,22 +21242,25 @@ function jsonText(schema) {
|
|
|
21206
21242
|
var TIMEOUT_MS = 15e3;
|
|
21207
21243
|
var ErrorBody = jsonText(external_exports.object({ error: external_exports.string() }));
|
|
21208
21244
|
var HttpStatusError = class extends CliError {
|
|
21209
|
-
constructor(status, message, hint) {
|
|
21245
|
+
constructor(status, message, hint, body = "") {
|
|
21210
21246
|
super(message, hint);
|
|
21211
21247
|
this.status = status;
|
|
21248
|
+
this.body = body;
|
|
21212
21249
|
this.name = "HttpStatusError";
|
|
21213
21250
|
}
|
|
21214
21251
|
status;
|
|
21252
|
+
body;
|
|
21215
21253
|
};
|
|
21216
21254
|
async function getJson(fetchImpl, request) {
|
|
21217
|
-
const { url: url2, schema, failure: failure2, signal } = request;
|
|
21218
|
-
const { status, text } = await send(fetchImpl, url2, signal);
|
|
21255
|
+
const { url: url2, schema, failure: failure2, signal, headers } = request;
|
|
21256
|
+
const { status, text } = await send(fetchImpl, url2, signal, headers);
|
|
21219
21257
|
if (status < 200 || status >= 300) {
|
|
21220
21258
|
const reason = ErrorBody.safeParse(text);
|
|
21221
21259
|
throw new HttpStatusError(
|
|
21222
21260
|
status,
|
|
21223
21261
|
`${url2.host} couldn't ${failure2} (HTTP ${status})`,
|
|
21224
|
-
reason.success ? `${reason.data.error.replace(/\.$/, "")}; try again in a moment` : "try again in a moment"
|
|
21262
|
+
reason.success ? `${reason.data.error.replace(/\.$/, "")}; try again in a moment` : "try again in a moment",
|
|
21263
|
+
text
|
|
21225
21264
|
);
|
|
21226
21265
|
}
|
|
21227
21266
|
const body = jsonText(schema).safeParse(text);
|
|
@@ -21233,11 +21272,11 @@ async function getJson(fetchImpl, request) {
|
|
|
21233
21272
|
}
|
|
21234
21273
|
return body.data;
|
|
21235
21274
|
}
|
|
21236
|
-
async function send(fetchImpl, url2, signal) {
|
|
21275
|
+
async function send(fetchImpl, url2, signal, headers) {
|
|
21237
21276
|
const timeout = AbortSignal.timeout(TIMEOUT_MS);
|
|
21238
21277
|
try {
|
|
21239
21278
|
const response = await fetchImpl(url2, {
|
|
21240
|
-
headers: { accept: "application/json" },
|
|
21279
|
+
headers: { accept: "application/json", ...headers },
|
|
21241
21280
|
signal: signal ? AbortSignal.any([signal, timeout]) : timeout
|
|
21242
21281
|
});
|
|
21243
21282
|
return { status: response.status, text: await response.text() };
|
|
@@ -21456,9 +21495,59 @@ function parseNowOptions(args, bin) {
|
|
|
21456
21495
|
}
|
|
21457
21496
|
}
|
|
21458
21497
|
|
|
21459
|
-
// src/commands/skills/
|
|
21498
|
+
// src/commands/skills/GitExclude.ts
|
|
21460
21499
|
import fs2 from "fs/promises";
|
|
21461
21500
|
import path3 from "path";
|
|
21501
|
+
var START = "# >>> zion skills (private)";
|
|
21502
|
+
var END = "# <<< zion skills (private)";
|
|
21503
|
+
var GitExclude = class {
|
|
21504
|
+
constructor(git2, dir) {
|
|
21505
|
+
this.git = git2;
|
|
21506
|
+
this.dir = dir;
|
|
21507
|
+
}
|
|
21508
|
+
git;
|
|
21509
|
+
dir;
|
|
21510
|
+
async available() {
|
|
21511
|
+
return await this.git.excludeFile(this.dir) !== null;
|
|
21512
|
+
}
|
|
21513
|
+
async write(paths) {
|
|
21514
|
+
const located = await this.git.excludeFile(this.dir);
|
|
21515
|
+
if (!located) {
|
|
21516
|
+
if (paths.length === 0) return [];
|
|
21517
|
+
throw new CliError("This folder is not in a git repository", "private skills need one");
|
|
21518
|
+
}
|
|
21519
|
+
const { file: file2, root } = located;
|
|
21520
|
+
const prefix = path3.relative(root, await fs2.realpath(this.dir));
|
|
21521
|
+
const lines = paths.map(
|
|
21522
|
+
(target) => `/${path3.join(prefix, path3.relative(this.dir, target)).split(path3.sep).join("/")}`
|
|
21523
|
+
);
|
|
21524
|
+
const current = await fs2.readFile(file2, "utf8").catch((error62) => {
|
|
21525
|
+
if (errorCode(error62) === "ENOENT") return "";
|
|
21526
|
+
throw error62;
|
|
21527
|
+
});
|
|
21528
|
+
const kept = withoutBlock(current.split("\n"));
|
|
21529
|
+
while (kept.at(-1) === "") kept.pop();
|
|
21530
|
+
const next = [...kept, ...lines.length > 0 ? [START, ...lines, END] : []];
|
|
21531
|
+
await fs2.mkdir(path3.dirname(file2), { recursive: true });
|
|
21532
|
+
await fs2.writeFile(file2, next.length > 0 ? `${next.join("\n")}
|
|
21533
|
+
` : "");
|
|
21534
|
+
const relative2 = paths.map((target) => path3.relative(this.dir, target));
|
|
21535
|
+
const files = await this.git.tracked(this.dir, relative2);
|
|
21536
|
+
return paths.filter(
|
|
21537
|
+
(_, i) => files.some((tracked) => tracked === relative2[i] || tracked.startsWith(`${relative2[i]}${path3.sep}`))
|
|
21538
|
+
);
|
|
21539
|
+
}
|
|
21540
|
+
};
|
|
21541
|
+
function withoutBlock(lines) {
|
|
21542
|
+
const kept = [];
|
|
21543
|
+
let inside2 = false;
|
|
21544
|
+
for (const line of lines) {
|
|
21545
|
+
if (line === START) inside2 = true;
|
|
21546
|
+
else if (inside2 && line === END) inside2 = false;
|
|
21547
|
+
else if (!inside2) kept.push(line);
|
|
21548
|
+
}
|
|
21549
|
+
return kept;
|
|
21550
|
+
}
|
|
21462
21551
|
|
|
21463
21552
|
// src/services/gitBlob.ts
|
|
21464
21553
|
import { createHash } from "crypto";
|
|
@@ -21485,60 +21574,6 @@ function gitTreeShaOfFiles(files) {
|
|
|
21485
21574
|
return gitTreeSha(here);
|
|
21486
21575
|
}
|
|
21487
21576
|
|
|
21488
|
-
// src/commands/skills/SkillFiles.ts
|
|
21489
|
-
var NOISE = /* @__PURE__ */ new Set([".DS_Store"]);
|
|
21490
|
-
var NodeSkillFiles = class {
|
|
21491
|
-
async exists(dir) {
|
|
21492
|
-
return (await fs2.stat(dir).catch(() => null))?.isDirectory() ?? false;
|
|
21493
|
-
}
|
|
21494
|
-
async treeSha(dir) {
|
|
21495
|
-
if (!await fs2.lstat(dir).catch(() => null)) return null;
|
|
21496
|
-
if (!await this.exists(dir)) return UNREADABLE;
|
|
21497
|
-
return await hashDirectory(dir).catch(() => UNREADABLE) ?? gitTreeSha([]);
|
|
21498
|
-
}
|
|
21499
|
-
async write(dir, files) {
|
|
21500
|
-
const targets = files.map((file2) => inside(dir, file2.path));
|
|
21501
|
-
await fs2.rm(dir, { recursive: true, force: true });
|
|
21502
|
-
for (const [i, file2] of files.entries()) {
|
|
21503
|
-
const target = targets[i];
|
|
21504
|
-
await fs2.mkdir(path3.dirname(target), { recursive: true });
|
|
21505
|
-
await fs2.writeFile(target, file2.content, { mode: file2.executable ? 493 : 420 });
|
|
21506
|
-
}
|
|
21507
|
-
}
|
|
21508
|
-
async remove(dir) {
|
|
21509
|
-
await fs2.rm(dir, { recursive: true, force: true });
|
|
21510
|
-
}
|
|
21511
|
-
};
|
|
21512
|
-
var UNREADABLE = "unreadable";
|
|
21513
|
-
async function hashDirectory(dir) {
|
|
21514
|
-
const entries = [];
|
|
21515
|
-
for (const entry of await fs2.readdir(dir, { withFileTypes: true })) {
|
|
21516
|
-
if (NOISE.has(entry.name)) continue;
|
|
21517
|
-
const absolute = path3.join(dir, entry.name);
|
|
21518
|
-
if (entry.isDirectory()) {
|
|
21519
|
-
const sha = await hashDirectory(absolute);
|
|
21520
|
-
if (sha) entries.push({ name: entry.name, mode: DIRECTORY_MODE, sha });
|
|
21521
|
-
} else if (entry.isSymbolicLink()) {
|
|
21522
|
-
entries.push({ name: entry.name, mode: "120000", sha: gitBlobSha(Buffer.from(await fs2.readlink(absolute))) });
|
|
21523
|
-
} else if (entry.isFile()) {
|
|
21524
|
-
const executable = ((await fs2.stat(absolute)).mode & 73) !== 0;
|
|
21525
|
-
entries.push({
|
|
21526
|
-
name: entry.name,
|
|
21527
|
-
mode: executable ? "100755" : "100644",
|
|
21528
|
-
sha: gitBlobSha(await fs2.readFile(absolute))
|
|
21529
|
-
});
|
|
21530
|
-
}
|
|
21531
|
-
}
|
|
21532
|
-
return entries.length > 0 ? gitTreeSha(entries) : null;
|
|
21533
|
-
}
|
|
21534
|
-
function inside(dir, relative) {
|
|
21535
|
-
const target = path3.resolve(dir, relative);
|
|
21536
|
-
if (relative.includes("\0") || path3.isAbsolute(relative) || !target.startsWith(path3.resolve(dir) + path3.sep)) {
|
|
21537
|
-
throw new CliError(`Refusing to write ${relative}`, `it would land outside ${tildify(dir)}`);
|
|
21538
|
-
}
|
|
21539
|
-
return target;
|
|
21540
|
-
}
|
|
21541
|
-
|
|
21542
21577
|
// src/commands/skills/SkillsApi.ts
|
|
21543
21578
|
var SKILL_NAME = /^\w[\w.-]*$/;
|
|
21544
21579
|
var SkillList = external_exports.object({
|
|
@@ -21590,35 +21625,259 @@ var HttpSkillsApi = class {
|
|
|
21590
21625
|
if (error62 instanceof HttpStatusError && error62.status === 404) throw new SkillNotFoundError(name);
|
|
21591
21626
|
throw error62;
|
|
21592
21627
|
}
|
|
21593
|
-
const files = body.files.map(({ path:
|
|
21628
|
+
const files = body.files.map(({ path: path17, sha, executable, content }) => {
|
|
21594
21629
|
const bytes = Buffer.from(content, "base64");
|
|
21595
21630
|
if (gitBlobSha(bytes) !== sha) {
|
|
21596
|
-
throw new CliError(`${this.host} sent a damaged copy of ${name}/${
|
|
21631
|
+
throw new CliError(`${this.host} sent a damaged copy of ${name}/${path17}`, "try again in a moment");
|
|
21597
21632
|
}
|
|
21598
|
-
return { path:
|
|
21633
|
+
return { path: path17, sha, executable, content: bytes };
|
|
21599
21634
|
});
|
|
21600
21635
|
return { name, commit: body.commit, tree: gitTreeShaOfFiles(files), files };
|
|
21601
21636
|
}
|
|
21602
21637
|
};
|
|
21603
21638
|
|
|
21639
|
+
// src/commands/skills/GithubSkillsApi.ts
|
|
21640
|
+
var SKILL_FILE = "SKILL.md";
|
|
21641
|
+
var REGULAR = "100644";
|
|
21642
|
+
var EXECUTABLE = "100755";
|
|
21643
|
+
var Commits = external_exports.array(external_exports.object({ sha: external_exports.string() }));
|
|
21644
|
+
var Tree = external_exports.object({
|
|
21645
|
+
tree: external_exports.array(external_exports.object({ path: external_exports.string(), mode: external_exports.string(), type: external_exports.string(), sha: external_exports.string() })),
|
|
21646
|
+
truncated: external_exports.boolean()
|
|
21647
|
+
});
|
|
21648
|
+
var Blob = external_exports.object({ content: external_exports.string(), encoding: external_exports.string() });
|
|
21649
|
+
var GithubSkillsApi = class {
|
|
21650
|
+
constructor(runner2, env, repo = "zion-off/skills", fetchImpl = fetch) {
|
|
21651
|
+
this.runner = runner2;
|
|
21652
|
+
this.env = env;
|
|
21653
|
+
this.repo = repo;
|
|
21654
|
+
this.fetchImpl = fetchImpl;
|
|
21655
|
+
}
|
|
21656
|
+
runner;
|
|
21657
|
+
env;
|
|
21658
|
+
repo;
|
|
21659
|
+
fetchImpl;
|
|
21660
|
+
token;
|
|
21661
|
+
get host() {
|
|
21662
|
+
return `github.com/${this.repo}`;
|
|
21663
|
+
}
|
|
21664
|
+
async list({ signal } = {}) {
|
|
21665
|
+
const tree = await this.read("/git/trees/HEAD?recursive=1", Tree, "send the skills", signal, true);
|
|
21666
|
+
if (tree.truncated) throw new CliError(`${this.repo} is too large to list`, "ask for the registry instead");
|
|
21667
|
+
const files = new Set(tree.tree.filter((entry) => entry.type === "blob").map((entry) => entry.path));
|
|
21668
|
+
return tree.tree.filter(
|
|
21669
|
+
(entry) => entry.type === "tree" && SKILL_NAME.test(entry.path) && files.has(`${entry.path}/${SKILL_FILE}`)
|
|
21670
|
+
).map((entry) => entry.path).sort();
|
|
21671
|
+
}
|
|
21672
|
+
async latestCommits(names, signal) {
|
|
21673
|
+
const commits = await inBatches(names, (name) => this.latestCommit(name, signal));
|
|
21674
|
+
return new Map(names.map((name, i) => [name, commits[i]]));
|
|
21675
|
+
}
|
|
21676
|
+
async get(name, signal) {
|
|
21677
|
+
if (!SKILL_NAME.test(name)) throw new SkillNotFoundError(name);
|
|
21678
|
+
const commit = await this.latestCommit(name, signal);
|
|
21679
|
+
if (!commit) throw new SkillNotFoundError(name);
|
|
21680
|
+
let tree;
|
|
21681
|
+
try {
|
|
21682
|
+
tree = await this.read(
|
|
21683
|
+
`/git/trees/${encodeURIComponent(`${commit}:${name}`)}?recursive=1`,
|
|
21684
|
+
Tree,
|
|
21685
|
+
`send ${name}`,
|
|
21686
|
+
signal
|
|
21687
|
+
);
|
|
21688
|
+
} catch (error62) {
|
|
21689
|
+
if (error62 instanceof HttpStatusError && error62.status === 404) throw new SkillNotFoundError(name);
|
|
21690
|
+
throw error62;
|
|
21691
|
+
}
|
|
21692
|
+
if (tree.truncated) throw new CliError(`${name} is too large to download`);
|
|
21693
|
+
const entries = tree.tree.filter(
|
|
21694
|
+
(entry) => entry.type === "blob" && (entry.mode === REGULAR || entry.mode === EXECUTABLE)
|
|
21695
|
+
);
|
|
21696
|
+
if (!entries.some((entry) => entry.path === SKILL_FILE)) throw new SkillNotFoundError(name);
|
|
21697
|
+
const files = await inBatches(entries, async (entry) => {
|
|
21698
|
+
const blob = await this.read(`/git/blobs/${entry.sha}`, Blob, `send ${name}/${entry.path}`, signal);
|
|
21699
|
+
const content = Buffer.from(blob.content.replace(/\n/g, ""), "base64");
|
|
21700
|
+
if (blob.encoding !== "base64" || gitBlobSha(content) !== entry.sha) {
|
|
21701
|
+
throw new CliError(`${this.host} sent a damaged copy of ${name}/${entry.path}`, "try again in a moment");
|
|
21702
|
+
}
|
|
21703
|
+
return { path: entry.path, sha: entry.sha, executable: entry.mode === EXECUTABLE, content };
|
|
21704
|
+
});
|
|
21705
|
+
return { name, commit, tree: gitTreeShaOfFiles(files), files };
|
|
21706
|
+
}
|
|
21707
|
+
/** The last commit that changed the skill's directory, or null if there is none. */
|
|
21708
|
+
async latestCommit(name, signal) {
|
|
21709
|
+
if (!SKILL_NAME.test(name)) return null;
|
|
21710
|
+
const [latest] = await this.read(
|
|
21711
|
+
`/commits?path=${encodeURIComponent(name)}&per_page=1`,
|
|
21712
|
+
Commits,
|
|
21713
|
+
`send ${name}`,
|
|
21714
|
+
signal,
|
|
21715
|
+
true
|
|
21716
|
+
);
|
|
21717
|
+
return latest?.sha ?? null;
|
|
21718
|
+
}
|
|
21719
|
+
/** `unreachable` says a 404 means the repository itself can't be read, not just the thing asked for. */
|
|
21720
|
+
async read(path17, schema, failure2, signal, unreachable = false) {
|
|
21721
|
+
const url2 = new URL(`https://api.github.com/repos/${this.repo}${path17}`);
|
|
21722
|
+
try {
|
|
21723
|
+
return await getJson(this.fetchImpl, {
|
|
21724
|
+
url: url2,
|
|
21725
|
+
schema,
|
|
21726
|
+
failure: failure2,
|
|
21727
|
+
signal,
|
|
21728
|
+
headers: {
|
|
21729
|
+
accept: "application/vnd.github+json",
|
|
21730
|
+
authorization: `Bearer ${await this.authToken()}`,
|
|
21731
|
+
"x-github-api-version": "2022-11-28"
|
|
21732
|
+
}
|
|
21733
|
+
});
|
|
21734
|
+
} catch (error62) {
|
|
21735
|
+
if (error62 instanceof HttpStatusError && isRateLimit(error62)) {
|
|
21736
|
+
throw new CliError("GitHub is rate limiting zion", "wait a minute, then try again");
|
|
21737
|
+
}
|
|
21738
|
+
if (error62 instanceof HttpStatusError && (error62.status === 401 || error62.status === 403 || unreachable && error62.status === 404)) {
|
|
21739
|
+
throw new CliError(
|
|
21740
|
+
`Can't read ${this.repo} on GitHub (HTTP ${error62.status})`,
|
|
21741
|
+
"it is private; the login zion found (GH_TOKEN, gh, or git) must be for an account that can read it"
|
|
21742
|
+
);
|
|
21743
|
+
}
|
|
21744
|
+
throw error62;
|
|
21745
|
+
}
|
|
21746
|
+
}
|
|
21747
|
+
authToken() {
|
|
21748
|
+
this.token ??= this.findToken();
|
|
21749
|
+
return this.token;
|
|
21750
|
+
}
|
|
21751
|
+
async findToken() {
|
|
21752
|
+
const fromEnv = this.env.GH_TOKEN || this.env.GITHUB_TOKEN;
|
|
21753
|
+
if (fromEnv) return fromEnv;
|
|
21754
|
+
const { GH_HOST: _host, ...env } = this.env;
|
|
21755
|
+
const gh = await this.runner.capture("gh", ["auth", "token", "--hostname", "github.com"], { env });
|
|
21756
|
+
if (gh.code === 0 && gh.stdout) return gh.stdout;
|
|
21757
|
+
const stored = await this.storedGitPassword();
|
|
21758
|
+
if (stored) return stored;
|
|
21759
|
+
throw new CliError(
|
|
21760
|
+
"--sudo needs a GitHub login",
|
|
21761
|
+
`set GH_TOKEN, run gh auth login, or sign in to github.com in git, as an account that can read ${this.repo}`
|
|
21762
|
+
);
|
|
21763
|
+
}
|
|
21764
|
+
/** The password git's credential helper keeps for github.com, which for GitHub is a token. */
|
|
21765
|
+
async storedGitPassword() {
|
|
21766
|
+
const { code, stdout } = await this.runner.capture("git", ["credential", "fill"], {
|
|
21767
|
+
env: { ...this.env, GIT_TERMINAL_PROMPT: "0", GCM_INTERACTIVE: "never" },
|
|
21768
|
+
input: "protocol=https\nhost=github.com\n\n"
|
|
21769
|
+
});
|
|
21770
|
+
if (code !== 0) return null;
|
|
21771
|
+
return /^password=(.+)$/m.exec(stdout)?.[1] ?? null;
|
|
21772
|
+
}
|
|
21773
|
+
};
|
|
21774
|
+
function isRateLimit({ status, body }) {
|
|
21775
|
+
return status === 429 || status === 403 && /rate limit/i.test(body);
|
|
21776
|
+
}
|
|
21777
|
+
async function inBatches(items, work, size = 8) {
|
|
21778
|
+
const results = [];
|
|
21779
|
+
for (let i = 0; i < items.length; i += size) {
|
|
21780
|
+
results.push(...await Promise.all(items.slice(i, i + size).map(work)));
|
|
21781
|
+
}
|
|
21782
|
+
return results;
|
|
21783
|
+
}
|
|
21784
|
+
|
|
21785
|
+
// src/commands/skills/SkillFiles.ts
|
|
21786
|
+
import fs3 from "fs/promises";
|
|
21787
|
+
import path4 from "path";
|
|
21788
|
+
var NOISE = /* @__PURE__ */ new Set([".DS_Store"]);
|
|
21789
|
+
var NodeSkillFiles = class {
|
|
21790
|
+
async exists(dir) {
|
|
21791
|
+
const entry = await fs3.lstat(dir).catch(() => null);
|
|
21792
|
+
return Boolean(entry?.isDirectory() || entry?.isSymbolicLink());
|
|
21793
|
+
}
|
|
21794
|
+
async treeSha(dir) {
|
|
21795
|
+
if (!await fs3.lstat(dir).catch(() => null)) return null;
|
|
21796
|
+
if (!await fs3.stat(dir).catch(() => null)) return (await fs3.lstat(dir)).isSymbolicLink() ? null : UNREADABLE;
|
|
21797
|
+
if (!(await fs3.stat(dir)).isDirectory()) return UNREADABLE;
|
|
21798
|
+
return await hashDirectory(dir).catch(() => UNREADABLE) ?? gitTreeSha([]);
|
|
21799
|
+
}
|
|
21800
|
+
async write(dir, files) {
|
|
21801
|
+
const targets = files.map((file2) => inside(dir, file2.path));
|
|
21802
|
+
await fs3.rm(dir, { recursive: true, force: true });
|
|
21803
|
+
for (const [i, file2] of files.entries()) {
|
|
21804
|
+
const target = targets[i];
|
|
21805
|
+
await fs3.mkdir(path4.dirname(target), { recursive: true });
|
|
21806
|
+
await fs3.writeFile(target, file2.content, { mode: file2.executable ? 493 : 420 });
|
|
21807
|
+
}
|
|
21808
|
+
}
|
|
21809
|
+
async remove(dir) {
|
|
21810
|
+
await fs3.rm(dir, { recursive: true, force: true });
|
|
21811
|
+
}
|
|
21812
|
+
async link(dir, target) {
|
|
21813
|
+
await fs3.rm(dir, { recursive: true, force: true });
|
|
21814
|
+
await fs3.mkdir(path4.dirname(dir), { recursive: true });
|
|
21815
|
+
const windows = process.platform === "win32";
|
|
21816
|
+
await fs3.symlink(windows ? target : path4.relative(path4.dirname(dir), target), dir, windows ? "junction" : "dir");
|
|
21817
|
+
}
|
|
21818
|
+
};
|
|
21819
|
+
var UNREADABLE = "unreadable";
|
|
21820
|
+
async function hashDirectory(dir) {
|
|
21821
|
+
const entries = [];
|
|
21822
|
+
for (const entry of await fs3.readdir(dir, { withFileTypes: true })) {
|
|
21823
|
+
if (NOISE.has(entry.name)) continue;
|
|
21824
|
+
const absolute = path4.join(dir, entry.name);
|
|
21825
|
+
if (entry.isDirectory()) {
|
|
21826
|
+
const sha = await hashDirectory(absolute);
|
|
21827
|
+
if (sha) entries.push({ name: entry.name, mode: DIRECTORY_MODE, sha });
|
|
21828
|
+
} else if (entry.isSymbolicLink()) {
|
|
21829
|
+
entries.push({ name: entry.name, mode: "120000", sha: gitBlobSha(Buffer.from(await fs3.readlink(absolute))) });
|
|
21830
|
+
} else if (entry.isFile()) {
|
|
21831
|
+
const executable = ((await fs3.stat(absolute)).mode & 73) !== 0;
|
|
21832
|
+
entries.push({
|
|
21833
|
+
name: entry.name,
|
|
21834
|
+
mode: executable ? "100755" : "100644",
|
|
21835
|
+
sha: gitBlobSha(await fs3.readFile(absolute))
|
|
21836
|
+
});
|
|
21837
|
+
}
|
|
21838
|
+
}
|
|
21839
|
+
return entries.length > 0 ? gitTreeSha(entries) : null;
|
|
21840
|
+
}
|
|
21841
|
+
function inside(dir, relative2) {
|
|
21842
|
+
const target = path4.resolve(dir, relative2);
|
|
21843
|
+
if (relative2.includes("\0") || path4.isAbsolute(relative2) || !target.startsWith(path4.resolve(dir) + path4.sep)) {
|
|
21844
|
+
throw new CliError(`Refusing to write ${relative2}`, `it would land outside ${tildify(dir)}`);
|
|
21845
|
+
}
|
|
21846
|
+
return target;
|
|
21847
|
+
}
|
|
21848
|
+
|
|
21604
21849
|
// src/commands/skills/SkillsCommand.ts
|
|
21605
|
-
import
|
|
21850
|
+
import path11 from "path";
|
|
21606
21851
|
|
|
21607
21852
|
// src/commands/skills/InstallFlow.ts
|
|
21608
|
-
import
|
|
21853
|
+
import path8 from "path";
|
|
21854
|
+
|
|
21855
|
+
// src/commands/skills/chooseMode.ts
|
|
21856
|
+
async function chooseLink(ui, { store }, given, linked = false) {
|
|
21857
|
+
if (given) return given === "link";
|
|
21858
|
+
const mode = await ui.select({
|
|
21859
|
+
message: "How to install",
|
|
21860
|
+
options: [
|
|
21861
|
+
{ value: "copy", label: "Copy", hint: "a separate copy in each folder" },
|
|
21862
|
+
{ value: "link", label: "Symlink", hint: `one copy in ${tildify(store)}, linked from each folder` }
|
|
21863
|
+
],
|
|
21864
|
+
initialValue: linked ? "link" : "copy"
|
|
21865
|
+
});
|
|
21866
|
+
return mode === "link";
|
|
21867
|
+
}
|
|
21609
21868
|
|
|
21610
21869
|
// src/commands/skills/chooseTargets.ts
|
|
21611
|
-
import
|
|
21870
|
+
import path6 from "path";
|
|
21612
21871
|
|
|
21613
21872
|
// src/commands/skills/copies.ts
|
|
21614
|
-
import
|
|
21873
|
+
import path5 from "path";
|
|
21615
21874
|
var EDITED = "edited since zion installed it";
|
|
21616
21875
|
async function installedDirs({ files, targets }, name) {
|
|
21617
|
-
const dirs = targets.map((target) =>
|
|
21876
|
+
const dirs = targets.map((target) => path5.join(target.dir, name));
|
|
21618
21877
|
const present = await Promise.all(dirs.map((dir) => files.exists(dir)));
|
|
21619
21878
|
return dirs.filter((_, i) => present[i]);
|
|
21620
21879
|
}
|
|
21621
|
-
async function planCopies(deps, skill, locked, chosen) {
|
|
21880
|
+
async function planCopies(deps, skill, locked, chosen, link = Boolean(locked?.link)) {
|
|
21622
21881
|
const dirs = /* @__PURE__ */ new Set([...chosen, ...locked ? await installedDirs(deps, skill.name) : []]);
|
|
21623
21882
|
return Promise.all(
|
|
21624
21883
|
[...dirs].map(async (dir) => {
|
|
@@ -21627,6 +21886,7 @@ async function planCopies(deps, skill, locked, chosen) {
|
|
|
21627
21886
|
return {
|
|
21628
21887
|
skill,
|
|
21629
21888
|
dir,
|
|
21889
|
+
link,
|
|
21630
21890
|
problem: edited ? locked ? EDITED : "not installed by zion" : void 0
|
|
21631
21891
|
};
|
|
21632
21892
|
})
|
|
@@ -21648,13 +21908,26 @@ async function confirmConflicts(ui, copies, { yes: yes2, retry }) {
|
|
|
21648
21908
|
nonInteractiveHint: `pass --yes to replace: ${retry} --yes`
|
|
21649
21909
|
});
|
|
21650
21910
|
}
|
|
21651
|
-
async function writeCopies({ files, lockfile }, skills, copies) {
|
|
21911
|
+
async function writeCopies({ files, lockfile, store }, skills, copies, hidden = /* @__PURE__ */ new Map()) {
|
|
21652
21912
|
for (const skill of skills) {
|
|
21653
21913
|
const mine = copiesOf(skill, copies);
|
|
21654
|
-
|
|
21914
|
+
const home = path5.join(store, skill.name);
|
|
21915
|
+
if (mine.some((copy) => copy.link)) await files.write(home, skill.files);
|
|
21916
|
+
for (const copy of mine) {
|
|
21917
|
+
if (copy.link) await files.link(copy.dir, home);
|
|
21918
|
+
else await files.write(copy.dir, skill.files);
|
|
21919
|
+
}
|
|
21920
|
+
if (!mine.some((copy) => copy.link)) await files.remove(home);
|
|
21655
21921
|
await lockfile.update((data) => {
|
|
21656
21922
|
if (mine.length === 0) delete data.skills[skill.name];
|
|
21657
|
-
else
|
|
21923
|
+
else {
|
|
21924
|
+
data.skills[skill.name] = {
|
|
21925
|
+
commit: skill.commit,
|
|
21926
|
+
tree: skill.tree,
|
|
21927
|
+
...mine.some((copy) => copy.link) && { link: true },
|
|
21928
|
+
...(hidden.get(skill.name) ?? data.skills[skill.name]?.private) && { private: true }
|
|
21929
|
+
};
|
|
21930
|
+
}
|
|
21658
21931
|
});
|
|
21659
21932
|
}
|
|
21660
21933
|
}
|
|
@@ -21672,7 +21945,7 @@ function copiesOf(skill, copies) {
|
|
|
21672
21945
|
return copies.filter((copy) => copy.skill === skill);
|
|
21673
21946
|
}
|
|
21674
21947
|
function describeDirs(dirs) {
|
|
21675
|
-
return dirs.map((dir) => tildify(
|
|
21948
|
+
return dirs.map((dir) => tildify(path5.dirname(dir))).join(", ");
|
|
21676
21949
|
}
|
|
21677
21950
|
function isNewer(latest, locked) {
|
|
21678
21951
|
return Boolean(latest && locked && latest.commit !== locked.commit);
|
|
@@ -21690,7 +21963,7 @@ async function chooseTargets(ui, deps, given, lock) {
|
|
|
21690
21963
|
return chosen;
|
|
21691
21964
|
}
|
|
21692
21965
|
const installed = await Promise.all(Object.keys(lock.skills).map((name) => installedDirs(deps, name)));
|
|
21693
|
-
const used = new Set(installed.flat().map((dir) =>
|
|
21966
|
+
const used = new Set(installed.flat().map((dir) => path6.dirname(dir)));
|
|
21694
21967
|
let suggested = targets.filter((target) => used.has(target.dir));
|
|
21695
21968
|
if (suggested.length === 0) {
|
|
21696
21969
|
const present = await Promise.all(targets.map((target) => files.exists(target.home)));
|
|
@@ -21704,8 +21977,37 @@ async function chooseTargets(ui, deps, given, lock) {
|
|
|
21704
21977
|
});
|
|
21705
21978
|
}
|
|
21706
21979
|
function shown(dir) {
|
|
21707
|
-
const
|
|
21708
|
-
return
|
|
21980
|
+
const relative2 = path6.relative(process.cwd(), dir);
|
|
21981
|
+
return relative2.startsWith("..") || path6.isAbsolute(relative2) ? tildify(dir) : `./${relative2}`;
|
|
21982
|
+
}
|
|
21983
|
+
|
|
21984
|
+
// src/commands/skills/privacy.ts
|
|
21985
|
+
import path7 from "path";
|
|
21986
|
+
async function syncExclude(deps) {
|
|
21987
|
+
const { exclude, lockfile, store } = deps;
|
|
21988
|
+
if (!exclude) return [];
|
|
21989
|
+
const { skills } = await lockfile.read();
|
|
21990
|
+
const names = Object.keys(skills);
|
|
21991
|
+
const hidden = names.filter((name) => skills[name].private);
|
|
21992
|
+
const paths = (await Promise.all(hidden.map((name) => installedDirs(deps, name)))).flat();
|
|
21993
|
+
if (hidden.length > 0 && hidden.length === names.length) paths.push(path7.dirname(lockfile.path));
|
|
21994
|
+
else {
|
|
21995
|
+
paths.push(...hidden.filter((name) => skills[name].link).map((name) => path7.join(store, name)));
|
|
21996
|
+
if (hidden.length > 0 && lockfile.hiddenPath) paths.push(lockfile.hiddenPath);
|
|
21997
|
+
}
|
|
21998
|
+
return exclude.write(paths);
|
|
21999
|
+
}
|
|
22000
|
+
function warnTracked(ui, tracked) {
|
|
22001
|
+
if (tracked.length === 0) return;
|
|
22002
|
+
const shown2 = tracked.map((target) => path7.relative(process.cwd(), target) || ".");
|
|
22003
|
+
ui.step({
|
|
22004
|
+
title: `${plural(tracked.length, "path")} already tracked by git`,
|
|
22005
|
+
tone: "warning",
|
|
22006
|
+
lines: [
|
|
22007
|
+
...shown2,
|
|
22008
|
+
`Excluding doesn't hide tracked files; stop tracking them with: git rm -r --cached ${shown2.join(" ")}`
|
|
22009
|
+
]
|
|
22010
|
+
});
|
|
21709
22011
|
}
|
|
21710
22012
|
|
|
21711
22013
|
// src/commands/skills/InstallFlow.ts
|
|
@@ -21717,8 +22019,16 @@ var InstallFlow = class {
|
|
|
21717
22019
|
async run(ui, options, ctx) {
|
|
21718
22020
|
const { api, lockfile } = this.deps;
|
|
21719
22021
|
const lock = await lockfile.read();
|
|
21720
|
-
const
|
|
22022
|
+
const canHide = await this.canHide(options, ctx);
|
|
22023
|
+
const { names, marked } = await this.chooseSkills(ui, options, ctx, lock, canHide);
|
|
21721
22024
|
const targets = await chooseTargets(ui, this.deps, options.targets, lock);
|
|
22025
|
+
const hidden = canHide ? await this.chooseHidden(ui, options, names, marked, lock) : /* @__PURE__ */ new Set();
|
|
22026
|
+
const link = await chooseLink(
|
|
22027
|
+
ui,
|
|
22028
|
+
this.deps,
|
|
22029
|
+
options.mode,
|
|
22030
|
+
names.some((name) => lock.skills[name]?.link)
|
|
22031
|
+
);
|
|
21722
22032
|
const skills = await ui.task(
|
|
21723
22033
|
`Downloading ${names.join(", ")}`,
|
|
21724
22034
|
(signal) => Promise.all(
|
|
@@ -21749,30 +22059,61 @@ var InstallFlow = class {
|
|
|
21749
22059
|
this.deps,
|
|
21750
22060
|
skill,
|
|
21751
22061
|
lock.skills[skill.name],
|
|
21752
|
-
dirs.map((dir) =>
|
|
22062
|
+
dirs.map((dir) => path8.join(dir, skill.name)),
|
|
22063
|
+
link
|
|
21753
22064
|
)
|
|
21754
22065
|
)
|
|
21755
22066
|
)).flat();
|
|
21756
|
-
const retry = `${ctx.bin} skills install ${names.join(" ")} ${targets.map((t) => `-t ${t.id}`).join(" ")}`;
|
|
22067
|
+
const retry = `${ctx.bin} skills install ${names.join(" ")} ${targets.map((t) => `-t ${t.id}`).join(" ")}${link ? " --link" : ""}`;
|
|
21757
22068
|
if (!await confirmConflicts(ui, copies, { yes: options.yes, retry })) {
|
|
21758
22069
|
ui.outro("Left everything as it was.", { tone: "muted" });
|
|
21759
22070
|
return 0;
|
|
21760
22071
|
}
|
|
21761
|
-
await ui.task(
|
|
22072
|
+
const tracked = await ui.task(
|
|
21762
22073
|
"Installing",
|
|
21763
|
-
() =>
|
|
22074
|
+
async () => {
|
|
22075
|
+
await writeCopies(
|
|
22076
|
+
this.deps,
|
|
22077
|
+
skills,
|
|
22078
|
+
copies,
|
|
22079
|
+
canHide ? new Map(names.map((name) => [name, hidden.has(name)])) : void 0
|
|
22080
|
+
);
|
|
22081
|
+
return syncExclude(this.deps);
|
|
22082
|
+
},
|
|
21764
22083
|
() => describeCopies(ctx.paint.stderr, "Installed", skills, copies)
|
|
21765
22084
|
);
|
|
22085
|
+
warnTracked(ui, tracked);
|
|
21766
22086
|
ui.outro(`Installed ${plural(skills.length, "skill")}.`, {
|
|
21767
22087
|
lines: ["Start a new agent session to use them.", `Run ${ctx.bin} skills update later to get newer versions.`]
|
|
21768
22088
|
});
|
|
21769
22089
|
return 0;
|
|
21770
22090
|
}
|
|
21771
|
-
|
|
22091
|
+
/** Whether skills can be kept out of git here: in a project that's in a git repository. */
|
|
22092
|
+
async canHide(options, ctx) {
|
|
22093
|
+
const available = await this.deps.exclude?.available() ?? false;
|
|
22094
|
+
if (options.private && !available) {
|
|
22095
|
+
throw new CliError(
|
|
22096
|
+
"--private needs a project that's in a git repository",
|
|
22097
|
+
`run ${ctx.bin} skills install --project inside one`
|
|
22098
|
+
);
|
|
22099
|
+
}
|
|
22100
|
+
return available;
|
|
22101
|
+
}
|
|
22102
|
+
/** --private and --public win; otherwise whatever was marked in the list, or else asks. */
|
|
22103
|
+
async chooseHidden(ui, options, names, marked, lock) {
|
|
22104
|
+
if (options.private !== void 0) return new Set(options.private ? names : []);
|
|
22105
|
+
if (marked) return new Set(marked.filter((name) => names.includes(name)));
|
|
22106
|
+
const hide2 = await ui.confirm({
|
|
22107
|
+
message: "Keep them out of git? (adds them to .git/info/exclude)",
|
|
22108
|
+
defaultValue: names.some((name) => lock.skills[name]?.private)
|
|
22109
|
+
});
|
|
22110
|
+
return new Set(hide2 ? names : []);
|
|
22111
|
+
}
|
|
22112
|
+
async chooseSkills(ui, options, ctx, lock, canHide) {
|
|
21772
22113
|
if (options.names.length > 0) {
|
|
21773
22114
|
const names = [...new Set(options.names)];
|
|
21774
22115
|
ui.step({ title: "To install", lines: [names.join(", ")] });
|
|
21775
|
-
return names;
|
|
22116
|
+
return { names };
|
|
21776
22117
|
}
|
|
21777
22118
|
const { api } = this.deps;
|
|
21778
22119
|
const available = await ui.task(
|
|
@@ -21781,8 +22122,8 @@ var InstallFlow = class {
|
|
|
21781
22122
|
(names) => ({ title: `${plural(names.length, "skill")} available` })
|
|
21782
22123
|
);
|
|
21783
22124
|
if (available.length === 0) throw new CliError(`${api.host} has no skills right now`, "try again later");
|
|
21784
|
-
if (options.all) return [...available];
|
|
21785
|
-
|
|
22125
|
+
if (options.all) return { names: [...available] };
|
|
22126
|
+
const picking = {
|
|
21786
22127
|
message: "Which skills?",
|
|
21787
22128
|
options: available.map((name) => ({
|
|
21788
22129
|
value: name,
|
|
@@ -21790,21 +22131,31 @@ var InstallFlow = class {
|
|
|
21790
22131
|
hint: lock.skills[name] ? `installed ${shortCommit(lock.skills[name].commit)}` : void 0
|
|
21791
22132
|
})),
|
|
21792
22133
|
nonInteractiveHint: `name them, e.g. ${ctx.bin} skills install ${available[0]}, or pass --all`
|
|
22134
|
+
};
|
|
22135
|
+
if (!canHide || options.private !== void 0) return { names: await ui.multiselect(picking) };
|
|
22136
|
+
const { chosen, marked } = await ui.multiselectMarked({
|
|
22137
|
+
...picking,
|
|
22138
|
+
mark: {
|
|
22139
|
+
key: "p",
|
|
22140
|
+
label: "private",
|
|
22141
|
+
initialValues: available.filter((name) => lock.skills[name]?.private)
|
|
22142
|
+
}
|
|
21793
22143
|
});
|
|
22144
|
+
return { names: chosen, marked };
|
|
21794
22145
|
}
|
|
21795
22146
|
};
|
|
21796
22147
|
|
|
21797
22148
|
// src/commands/skills/ManageFlow.ts
|
|
21798
|
-
import
|
|
22149
|
+
import path10 from "path";
|
|
21799
22150
|
|
|
21800
22151
|
// src/commands/skills/removals.ts
|
|
21801
|
-
import
|
|
22152
|
+
import path9 from "path";
|
|
21802
22153
|
async function planRemovals(deps, lock, names, only) {
|
|
21803
22154
|
const removals = [];
|
|
21804
22155
|
for (const name of names) {
|
|
21805
22156
|
for (const dir of await installedDirs(deps, name)) {
|
|
21806
|
-
if (only && !only.has(
|
|
21807
|
-
removals.push({ name, dir, edited: await deps.files.treeSha(dir)
|
|
22157
|
+
if (only && !only.has(path9.dirname(dir))) continue;
|
|
22158
|
+
removals.push({ name, dir, edited: !isUnchanged(await deps.files.treeSha(dir), lock.skills[name].tree) });
|
|
21808
22159
|
}
|
|
21809
22160
|
}
|
|
21810
22161
|
return removals;
|
|
@@ -21813,10 +22164,15 @@ async function applyRemovals(deps, names, removals) {
|
|
|
21813
22164
|
for (const removal of removals) await deps.files.remove(removal.dir);
|
|
21814
22165
|
for (const name of names) {
|
|
21815
22166
|
if ((await installedDirs(deps, name)).length > 0) continue;
|
|
22167
|
+
await deps.files.remove(path9.join(deps.store, name));
|
|
21816
22168
|
await deps.lockfile.update((data) => {
|
|
21817
22169
|
delete data.skills[name];
|
|
21818
22170
|
});
|
|
21819
22171
|
}
|
|
22172
|
+
await syncExclude(deps);
|
|
22173
|
+
}
|
|
22174
|
+
function isUnchanged(tree, locked) {
|
|
22175
|
+
return tree === null || tree === locked;
|
|
21820
22176
|
}
|
|
21821
22177
|
|
|
21822
22178
|
// src/commands/skills/ManageFlow.ts
|
|
@@ -21843,25 +22199,33 @@ var ManageFlow = class {
|
|
|
21843
22199
|
}
|
|
21844
22200
|
);
|
|
21845
22201
|
const names = [.../* @__PURE__ */ new Set([...available, ...installed])].sort();
|
|
21846
|
-
const
|
|
21847
|
-
|
|
21848
|
-
|
|
21849
|
-
|
|
21850
|
-
|
|
21851
|
-
|
|
21852
|
-
|
|
21853
|
-
|
|
22202
|
+
const canHide = await this.deps.exclude?.available() ?? false;
|
|
22203
|
+
const wasHidden = installed.filter((name) => lock.skills[name].private);
|
|
22204
|
+
const question = {
|
|
22205
|
+
message: "Skills",
|
|
22206
|
+
options: names.map((name) => ({ value: name, label: name, hint: this.hint(lock, name, latest, where) })),
|
|
22207
|
+
initialValues: installed,
|
|
22208
|
+
// Emptying the list removes everything, but with nothing installed an empty answer is a slip of the enter key.
|
|
22209
|
+
required: installed.length === 0
|
|
22210
|
+
};
|
|
22211
|
+
const { chosen, marked } = canHide ? await ui.multiselectMarked({ ...question, mark: { key: "p", label: "private", initialValues: wasHidden } }) : { chosen: await ui.multiselect(question), marked: wasHidden };
|
|
22212
|
+
const ticked = new Set(chosen);
|
|
22213
|
+
const hidden = new Set(marked.filter((name) => ticked.has(name)));
|
|
21854
22214
|
const adding = names.filter((name) => ticked.has(name) && !lock.skills[name]);
|
|
21855
22215
|
const updated = installed.flatMap((name) => {
|
|
21856
22216
|
const skill = latest.get(name);
|
|
21857
22217
|
return ticked.has(name) && isNewer(skill, lock.skills[name]) ? [skill] : [];
|
|
21858
22218
|
});
|
|
21859
22219
|
const removing = installed.filter((name) => !ticked.has(name));
|
|
21860
|
-
|
|
22220
|
+
const toggled = installed.filter(
|
|
22221
|
+
(name) => ticked.has(name) && hidden.has(name) !== Boolean(lock.skills[name].private)
|
|
22222
|
+
);
|
|
22223
|
+
if (adding.length + updated.length + removing.length + toggled.length === 0) {
|
|
21861
22224
|
ui.outro("Nothing to change.", { tone: "muted" });
|
|
21862
22225
|
return 0;
|
|
21863
22226
|
}
|
|
21864
22227
|
const targets = adding.length > 0 ? await chooseTargets(ui, this.deps, [], lock) : [];
|
|
22228
|
+
const link = adding.length > 0 && await chooseLink(ui, this.deps, void 0);
|
|
21865
22229
|
const added = adding.length > 0 ? await ui.task(
|
|
21866
22230
|
`Downloading ${adding.join(", ")}`,
|
|
21867
22231
|
(signal) => Promise.all(adding.map((name) => api.get(name, signal))),
|
|
@@ -21874,32 +22238,49 @@ var ManageFlow = class {
|
|
|
21874
22238
|
this.deps,
|
|
21875
22239
|
skill,
|
|
21876
22240
|
void 0,
|
|
21877
|
-
targets.map((target) =>
|
|
22241
|
+
targets.map((target) => path10.join(target.dir, skill.name)),
|
|
22242
|
+
link
|
|
21878
22243
|
)
|
|
21879
22244
|
)
|
|
21880
22245
|
)).flat(),
|
|
21881
22246
|
...(await Promise.all(updated.map((skill) => planCopies(this.deps, skill, lock.skills[skill.name], [])))).flat()
|
|
21882
22247
|
];
|
|
21883
22248
|
const removals = await planRemovals(this.deps, lock, removing);
|
|
21884
|
-
this.summarise(ui, ctx.paint.stderr, lock, where, { added, updated, removing, copies, removals });
|
|
22249
|
+
this.summarise(ui, ctx.paint.stderr, lock, where, { added, updated, removing, toggled, hidden, copies, removals });
|
|
21885
22250
|
const risky = copies.some((copy) => copy.problem) || removals.some((removal) => removal.edited);
|
|
21886
|
-
const total = added.length + updated.length + removing.length;
|
|
22251
|
+
const total = added.length + updated.length + removing.length + toggled.length;
|
|
21887
22252
|
if (!await ui.confirm({ message: `Apply ${plural(total, "change")}?`, defaultValue: !risky })) {
|
|
21888
22253
|
ui.outro("Left everything as it was.", { tone: "muted" });
|
|
21889
22254
|
return 0;
|
|
21890
22255
|
}
|
|
21891
|
-
await ui.task(
|
|
22256
|
+
const tracked = await ui.task(
|
|
21892
22257
|
"Applying changes",
|
|
21893
22258
|
async () => {
|
|
21894
|
-
|
|
22259
|
+
const written = [...added, ...updated];
|
|
22260
|
+
await writeCopies(
|
|
22261
|
+
this.deps,
|
|
22262
|
+
written,
|
|
22263
|
+
copies,
|
|
22264
|
+
canHide ? new Map(written.map((skill) => [skill.name, hidden.has(skill.name)])) : void 0
|
|
22265
|
+
);
|
|
21895
22266
|
await applyRemovals(this.deps, removing, removals);
|
|
22267
|
+
await this.deps.lockfile.update((data) => {
|
|
22268
|
+
for (const name of toggled) {
|
|
22269
|
+
if (!data.skills[name]) continue;
|
|
22270
|
+
if (hidden.has(name)) data.skills[name].private = true;
|
|
22271
|
+
else delete data.skills[name].private;
|
|
22272
|
+
}
|
|
22273
|
+
});
|
|
22274
|
+
return syncExclude(this.deps);
|
|
21896
22275
|
},
|
|
21897
22276
|
() => ({ title: "Changes applied" })
|
|
21898
22277
|
);
|
|
22278
|
+
warnTracked(ui, tracked);
|
|
21899
22279
|
const [first, ...rest] = [
|
|
21900
22280
|
["installed", added.length],
|
|
21901
22281
|
["updated", updated.length],
|
|
21902
|
-
["removed", removing.length]
|
|
22282
|
+
["removed", removing.length],
|
|
22283
|
+
["changed privacy of", toggled.length]
|
|
21903
22284
|
].filter(([, count]) => count > 0);
|
|
21904
22285
|
const message = [`${first[0]} ${plural(first[1], "skill")}`, ...rest.map(([verb, count]) => `${verb} ${count}`)];
|
|
21905
22286
|
const sentence = message.join(", ");
|
|
@@ -21933,13 +22314,14 @@ var ManageFlow = class {
|
|
|
21933
22314
|
if (version3 === null) return `${where} \xB7 no longer available`;
|
|
21934
22315
|
return isNewer(version3, entry) ? `${where} \xB7 update available` : where;
|
|
21935
22316
|
}
|
|
21936
|
-
summarise(ui, paint, lock, where, { added, updated, removing, copies, removals }) {
|
|
22317
|
+
summarise(ui, paint, lock, where, { added, updated, removing, toggled, hidden, copies, removals }) {
|
|
21937
22318
|
const rows = [
|
|
21938
22319
|
...added.map(
|
|
21939
22320
|
(skill) => [paint.success("+"), skill.name, describeDirs(copiesOf(skill, copies).map((copy) => copy.dir))]
|
|
21940
22321
|
),
|
|
21941
22322
|
...updated.map((skill) => [paint.accent("\u2191"), skill.name, describeChange(lock.skills[skill.name], skill)]),
|
|
21942
|
-
...removing.map((name) => [paint.error("\u2212"), name, describeDirs(where.get(name) ?? [])])
|
|
22323
|
+
...removing.map((name) => [paint.error("\u2212"), name, describeDirs(where.get(name) ?? [])]),
|
|
22324
|
+
...toggled.map((name) => [paint.accent("~"), name, hidden.has(name) ? "now private" : "now public"])
|
|
21943
22325
|
];
|
|
21944
22326
|
const width = Math.max(...rows.map(([, name]) => name.length));
|
|
21945
22327
|
ui.step({
|
|
@@ -22152,6 +22534,11 @@ function parseSkillsOptions(args, bin, targetIds) {
|
|
|
22152
22534
|
target: { type: "string", short: "t", multiple: true, default: [] },
|
|
22153
22535
|
project: { type: "boolean", short: "p", default: false },
|
|
22154
22536
|
global: { type: "boolean", short: "g", default: false },
|
|
22537
|
+
link: { type: "boolean", short: "l", default: false },
|
|
22538
|
+
copy: { type: "boolean", default: false },
|
|
22539
|
+
private: { type: "boolean", default: false },
|
|
22540
|
+
public: { type: "boolean", default: false },
|
|
22541
|
+
sudo: { type: "boolean", default: false },
|
|
22155
22542
|
all: { type: "boolean", short: "a", default: false },
|
|
22156
22543
|
yes: { type: "boolean", short: "y", default: false },
|
|
22157
22544
|
json: { type: "boolean", default: false }
|
|
@@ -22177,12 +22564,18 @@ function parseSkillsOptions(args, bin, targetIds) {
|
|
|
22177
22564
|
const targets = given.filter(isTarget);
|
|
22178
22565
|
if (values.project && values.global) throw new UsageError("pass --project or --global, not both", usageHint);
|
|
22179
22566
|
const scope = values.project ? "project" : values.global ? "global" : void 0;
|
|
22567
|
+
if (values.link && values.copy) throw new UsageError("pass --link or --copy, not both", usageHint);
|
|
22568
|
+
const mode = values.link ? "link" : values.copy ? "copy" : void 0;
|
|
22569
|
+
if (values.private && values.public) throw new UsageError("pass --private or --public, not both", usageHint);
|
|
22570
|
+
const hidden = values.private ? true : values.public ? false : void 0;
|
|
22180
22571
|
const id = action?.id;
|
|
22181
22572
|
const only = (flag, allowed) => {
|
|
22182
22573
|
if (!id || !allowed.includes(id)) throw new UsageError(`${flag} works with: ${allowed.join(", ")}`, usageHint);
|
|
22183
22574
|
};
|
|
22184
22575
|
if (targets.length > 0) only("--target", ["install", "remove"]);
|
|
22185
22576
|
if (scope && id === "show") throw new UsageError("--project and --global don't apply to show", usageHint);
|
|
22577
|
+
if (mode) only("--link and --copy", ["install"]);
|
|
22578
|
+
if (hidden !== void 0) only("--private and --public", ["install"]);
|
|
22186
22579
|
if (values.all) only("--all", ["install", "remove"]);
|
|
22187
22580
|
if (values.yes) only("--yes", ["install", "update", "remove"]);
|
|
22188
22581
|
if (values.json) only("--json", ["list"]);
|
|
@@ -22191,7 +22584,18 @@ function parseSkillsOptions(args, bin, targetIds) {
|
|
|
22191
22584
|
if (id === "show" && names.length !== 1) {
|
|
22192
22585
|
throw new UsageError("show takes exactly one skill name", `e.g. ${bin} skills show commit`);
|
|
22193
22586
|
}
|
|
22194
|
-
return {
|
|
22587
|
+
return {
|
|
22588
|
+
action: id,
|
|
22589
|
+
names,
|
|
22590
|
+
targets,
|
|
22591
|
+
scope,
|
|
22592
|
+
mode,
|
|
22593
|
+
private: hidden,
|
|
22594
|
+
all: values.all,
|
|
22595
|
+
yes: values.yes,
|
|
22596
|
+
sudo: values.sudo,
|
|
22597
|
+
json: values.json
|
|
22598
|
+
};
|
|
22195
22599
|
}
|
|
22196
22600
|
|
|
22197
22601
|
// src/commands/skills/output.ts
|
|
@@ -22207,7 +22611,7 @@ async function listSkills(deps, ctx, json2) {
|
|
|
22207
22611
|
return {
|
|
22208
22612
|
name,
|
|
22209
22613
|
available: available.includes(name),
|
|
22210
|
-
installed: entry ? { commit: entry.commit, paths: await installedDirs(deps, name) } : null
|
|
22614
|
+
installed: entry ? { commit: entry.commit, paths: await installedDirs(deps, name), private: Boolean(entry.private) } : null
|
|
22211
22615
|
};
|
|
22212
22616
|
})
|
|
22213
22617
|
);
|
|
@@ -22221,7 +22625,7 @@ async function listSkills(deps, ctx, json2) {
|
|
|
22221
22625
|
for (const row of rows) {
|
|
22222
22626
|
const status = row.installed ? `${paint.success("installed")} ${paint.muted(shortCommit(row.installed.commit))} ${describeDirs(
|
|
22223
22627
|
row.installed.paths
|
|
22224
|
-
)}` : "";
|
|
22628
|
+
)}${row.installed.private ? ` ${paint.muted("private")}` : ""}` : "";
|
|
22225
22629
|
const gone = row.available ? "" : ` ${paint.warning("no longer available")}`;
|
|
22226
22630
|
ctx.stdout.write(`${`${row.name.padEnd(width)} ${status}${gone}`.trimEnd()}
|
|
22227
22631
|
`);
|
|
@@ -22244,16 +22648,19 @@ async function showSkill({ api }, ctx, name) {
|
|
|
22244
22648
|
}
|
|
22245
22649
|
|
|
22246
22650
|
// src/commands/skills/SkillsCommand.ts
|
|
22651
|
+
function relative(file2) {
|
|
22652
|
+
return `./${path11.relative(process.cwd(), file2)}`;
|
|
22653
|
+
}
|
|
22247
22654
|
var SkillsCommand = class {
|
|
22248
22655
|
constructor(base) {
|
|
22249
22656
|
this.base = base;
|
|
22250
|
-
const { scopes, api } = base;
|
|
22251
|
-
const { targets, lockfile } = scopes.global;
|
|
22657
|
+
const { scopes, api, sudoApi } = base;
|
|
22658
|
+
const { targets, lockfile, store } = scopes.global;
|
|
22252
22659
|
this.help = {
|
|
22253
22660
|
usage: "[action] [skill...] [options]",
|
|
22254
|
-
description: `Downloads skills from ${api.host} into the folders your agents load them from, replacing each skill folder whole. Without an action, it shows every skill as a checklist where ticked means installed: tick to install, untick to remove, and installed skills with a newer version are updated too. When not in a terminal, it prints the list instead. It asks whether to work in this project or your home directory unless you pass --project or --global. zion records what it installed in ${tildify(lockfile.path)} (
|
|
22661
|
+
description: `Downloads skills from ${api.host} into the folders your agents load them from, replacing each skill folder whole, or symlinking it to a copy zion keeps in its own folder. Without an action, it shows every skill as a checklist where ticked means installed: tick to install, untick to remove, and installed skills with a newer version are updated too. When not in a terminal, it prints the list instead. It asks whether to work in this project or your home directory unless you pass --project or --global. zion records what it installed in ${tildify(lockfile.path)} (${relative(
|
|
22255
22662
|
scopes.project.lockfile.path
|
|
22256
|
-
)} with --project), and asks before replacing or deleting a skill folder that differs from what it installed. Targets: ${targets.map((t) => `${t.id} is ${tildify(t.dir)}`).join(", ")}; with --project, the same paths under the current folder.`,
|
|
22663
|
+
)} with --project), and asks before replacing or deleting a skill folder that differs from what it installed. Targets: ${targets.map((t) => `${t.id} is ${tildify(t.dir)}`).join(", ")}; with --project, the same paths under the current folder. Press p in the list to mark a skill private in a git project; zion then excludes it, and zion's whole folder once all are. Linked skills are kept in ${tildify(store)} (${tildify(scopes.project.store)} with --project).`,
|
|
22257
22664
|
arguments: {
|
|
22258
22665
|
title: "Actions",
|
|
22259
22666
|
rows: SKILLS_ACTIONS.map((action) => [
|
|
@@ -22262,9 +22669,17 @@ var SkillsCommand = class {
|
|
|
22262
22669
|
])
|
|
22263
22670
|
},
|
|
22264
22671
|
options: [
|
|
22265
|
-
["-p, --project", `work in this folder, recorded in
|
|
22672
|
+
["-p, --project", `work in this folder, recorded in ${relative(scopes.project.lockfile.path)}`],
|
|
22266
22673
|
["-g, --global", "work in your home directory (the default without a terminal)"],
|
|
22267
22674
|
["-t, --target <name>", `${targets.map((t) => t.id).join(" or ")}; repeat for both`],
|
|
22675
|
+
["-l, --link", "symlink to a copy zion keeps, instead of copying into each folder (install)"],
|
|
22676
|
+
["--copy", "copy into each folder without asking (install)"],
|
|
22677
|
+
["--private", "keep the installed skills out of git with .git/info/exclude (install, --project)"],
|
|
22678
|
+
["--public", "do not keep them out of git, without asking (install)"],
|
|
22679
|
+
[
|
|
22680
|
+
"--sudo",
|
|
22681
|
+
`read skills straight from the private ${sudoApi.host} repo, listing every folder in it, instead of from ${api.host}; needs a GitHub login that can read it`
|
|
22682
|
+
],
|
|
22268
22683
|
["-a, --all", "every skill (install and remove)"],
|
|
22269
22684
|
["-y, --yes", "say yes to every confirmation, including replacing edited folders"],
|
|
22270
22685
|
["--json", "print the list as JSON"]
|
|
@@ -22272,6 +22687,9 @@ var SkillsCommand = class {
|
|
|
22272
22687
|
examples: [
|
|
22273
22688
|
"skills",
|
|
22274
22689
|
"skills install commit author -t claude",
|
|
22690
|
+
"skills install commit --link -t claude",
|
|
22691
|
+
"skills install commit -p --private",
|
|
22692
|
+
"skills list --sudo",
|
|
22275
22693
|
"skills install --all -t agents -t claude --yes",
|
|
22276
22694
|
"skills update",
|
|
22277
22695
|
"skills list --json",
|
|
@@ -22291,28 +22709,29 @@ var SkillsCommand = class {
|
|
|
22291
22709
|
ctx.bin,
|
|
22292
22710
|
this.base.scopes.global.targets.map((target) => target.id)
|
|
22293
22711
|
);
|
|
22294
|
-
|
|
22295
|
-
if (options.action === "
|
|
22712
|
+
const base = options.sudo ? { ...this.base, api: this.base.sudoApi } : this.base;
|
|
22713
|
+
if (options.action === "list") return listSkills(this.depsFor(base, options.scope ?? "global"), ctx, options.json);
|
|
22714
|
+
if (options.action === "show") return showSkill(base, ctx, options.names[0]);
|
|
22296
22715
|
const given = options.action;
|
|
22297
|
-
if (!given && !ctx.interactive) return listSkills(this.depsFor(options.scope ?? "global"), ctx, false);
|
|
22298
|
-
const ui =
|
|
22716
|
+
if (!given && !ctx.interactive) return listSkills(this.depsFor(base, options.scope ?? "global"), ctx, false);
|
|
22717
|
+
const ui = base.createPrompter(ctx);
|
|
22299
22718
|
return runSession(ui, async () => {
|
|
22300
|
-
ui.intro("skills",
|
|
22719
|
+
ui.intro("skills", base.api.host);
|
|
22301
22720
|
const scope = options.scope ?? await this.chooseScope(ui);
|
|
22302
|
-
const deps = this.depsFor(scope);
|
|
22721
|
+
const deps = this.depsFor(base, scope);
|
|
22303
22722
|
const flows = { install: InstallFlow, update: UpdateFlow, remove: RemoveFlow };
|
|
22304
22723
|
return given ? new flows[given](deps).run(ui, options, ctx) : new ManageFlow(deps).run(ui, ctx);
|
|
22305
22724
|
});
|
|
22306
22725
|
}
|
|
22307
|
-
depsFor(scope) {
|
|
22308
|
-
return { ...
|
|
22726
|
+
depsFor(base, scope) {
|
|
22727
|
+
return { ...base, ...base.scopes[scope] };
|
|
22309
22728
|
}
|
|
22310
22729
|
chooseScope(ui) {
|
|
22311
22730
|
const { project, global } = this.base.scopes;
|
|
22312
22731
|
return ui.select({
|
|
22313
22732
|
message: "Scope",
|
|
22314
22733
|
options: [
|
|
22315
|
-
{ value: "project", label: "Locally", hint: `tracked in
|
|
22734
|
+
{ value: "project", label: "Locally", hint: `tracked in ${relative(project.lockfile.path)}` },
|
|
22316
22735
|
{ value: "global", label: "Globally", hint: `tracked in ${tildify(global.lockfile.path)}` }
|
|
22317
22736
|
],
|
|
22318
22737
|
initialValue: "global"
|
|
@@ -22321,25 +22740,26 @@ var SkillsCommand = class {
|
|
|
22321
22740
|
};
|
|
22322
22741
|
|
|
22323
22742
|
// src/commands/skills/targets.ts
|
|
22324
|
-
import
|
|
22743
|
+
import path12 from "path";
|
|
22325
22744
|
function skillTargets(homedir) {
|
|
22326
22745
|
return [
|
|
22327
22746
|
{
|
|
22328
22747
|
id: "agents",
|
|
22329
|
-
dir:
|
|
22330
|
-
home:
|
|
22748
|
+
dir: path12.join(homedir, ".agents", "skills"),
|
|
22749
|
+
home: path12.join(homedir, ".agents"),
|
|
22331
22750
|
name: "Universal"
|
|
22332
22751
|
},
|
|
22333
22752
|
{
|
|
22334
22753
|
id: "claude",
|
|
22335
|
-
dir:
|
|
22336
|
-
home:
|
|
22754
|
+
dir: path12.join(homedir, ".claude", "skills"),
|
|
22755
|
+
home: path12.join(homedir, ".claude"),
|
|
22337
22756
|
name: "Claude Code"
|
|
22338
22757
|
}
|
|
22339
22758
|
];
|
|
22340
22759
|
}
|
|
22341
22760
|
|
|
22342
22761
|
// src/services/Git.ts
|
|
22762
|
+
import path13 from "path";
|
|
22343
22763
|
var GitError = class extends Error {
|
|
22344
22764
|
constructor(args, stderr) {
|
|
22345
22765
|
super(stderr.split("\n").pop() || `git ${args.join(" ")} failed`);
|
|
@@ -22364,6 +22784,16 @@ var CliGit = class {
|
|
|
22364
22784
|
topLevel(dir) {
|
|
22365
22785
|
return this.query(["-C", dir, "rev-parse", "--show-toplevel"]);
|
|
22366
22786
|
}
|
|
22787
|
+
async excludeFile(dir) {
|
|
22788
|
+
const root = await this.topLevel(dir);
|
|
22789
|
+
const file2 = root && await this.query(["-C", dir, "rev-parse", "--git-path", "info/exclude"]);
|
|
22790
|
+
return root && file2 ? { file: path13.resolve(dir, file2), root } : null;
|
|
22791
|
+
}
|
|
22792
|
+
async tracked(dir, paths) {
|
|
22793
|
+
if (paths.length === 0) return [];
|
|
22794
|
+
const out = await this.run(["-C", dir, "ls-files", "--", ...paths]);
|
|
22795
|
+
return out.split("\n").filter(Boolean);
|
|
22796
|
+
}
|
|
22367
22797
|
remoteUrl(dir, remote) {
|
|
22368
22798
|
return this.query(["-C", dir, "remote", "get-url", remote]);
|
|
22369
22799
|
}
|
|
@@ -22400,14 +22830,18 @@ var CliGit = class {
|
|
|
22400
22830
|
};
|
|
22401
22831
|
|
|
22402
22832
|
// src/services/Lockfile.ts
|
|
22403
|
-
import
|
|
22404
|
-
import
|
|
22833
|
+
import fs4 from "fs/promises";
|
|
22834
|
+
import path14 from "path";
|
|
22405
22835
|
var VERSION = 2;
|
|
22406
22836
|
var LockedSkill = external_exports.looseObject({
|
|
22407
22837
|
/** The last commit in zion-off/skills that changed this skill. */
|
|
22408
22838
|
commit: external_exports.string(),
|
|
22409
22839
|
/** Git tree hash of the skill as installed, to spot local edits. */
|
|
22410
|
-
tree: external_exports.string()
|
|
22840
|
+
tree: external_exports.string(),
|
|
22841
|
+
/** Whether the skill's folders are symlinks to zion's own copy rather than copies. */
|
|
22842
|
+
link: external_exports.boolean().optional(),
|
|
22843
|
+
/** Whether the skill is kept out of git, in the project's .git/info/exclude. */
|
|
22844
|
+
private: external_exports.boolean().optional()
|
|
22411
22845
|
});
|
|
22412
22846
|
var LockData = external_exports.looseObject({
|
|
22413
22847
|
version: external_exports.literal(VERSION),
|
|
@@ -22416,14 +22850,14 @@ var LockData = external_exports.looseObject({
|
|
|
22416
22850
|
});
|
|
22417
22851
|
var Versioned = jsonText(external_exports.looseObject({ version: external_exports.number() }));
|
|
22418
22852
|
var JsonLockfile = class {
|
|
22419
|
-
constructor(
|
|
22420
|
-
this.path =
|
|
22853
|
+
constructor(path17) {
|
|
22854
|
+
this.path = path17;
|
|
22421
22855
|
}
|
|
22422
22856
|
path;
|
|
22423
22857
|
async read() {
|
|
22424
22858
|
let text;
|
|
22425
22859
|
try {
|
|
22426
|
-
text = await
|
|
22860
|
+
text = await fs4.readFile(this.path, "utf8");
|
|
22427
22861
|
} catch (error62) {
|
|
22428
22862
|
if (errorCode(error62) === "ENOENT") return { version: VERSION, skills: {} };
|
|
22429
22863
|
throw error62;
|
|
@@ -22449,13 +22883,13 @@ var JsonLockfile = class {
|
|
|
22449
22883
|
return data.data;
|
|
22450
22884
|
}
|
|
22451
22885
|
async write(data) {
|
|
22452
|
-
await
|
|
22886
|
+
await fs4.mkdir(path14.dirname(this.path), { recursive: true });
|
|
22453
22887
|
const temporary = `${this.path}.${process.pid}.tmp`;
|
|
22454
22888
|
try {
|
|
22455
|
-
await
|
|
22456
|
-
await
|
|
22889
|
+
await fs4.writeFile(temporary, JSON.stringify(data, null, 2) + "\n");
|
|
22890
|
+
await fs4.rename(temporary, this.path);
|
|
22457
22891
|
} catch (error62) {
|
|
22458
|
-
await
|
|
22892
|
+
await fs4.rm(temporary, { force: true });
|
|
22459
22893
|
throw error62;
|
|
22460
22894
|
}
|
|
22461
22895
|
}
|
|
@@ -22466,11 +22900,45 @@ var JsonLockfile = class {
|
|
|
22466
22900
|
);
|
|
22467
22901
|
}
|
|
22468
22902
|
};
|
|
22469
|
-
function describeIssue({ path:
|
|
22470
|
-
if (
|
|
22471
|
-
if (
|
|
22472
|
-
return `"${
|
|
22473
|
-
}
|
|
22903
|
+
function describeIssue({ path: path17, code }) {
|
|
22904
|
+
if (path17.length === 0) return code === "custom" ? "it is not valid JSON" : "it is not an object";
|
|
22905
|
+
if (path17[0] === "version") return `its version isn't ${VERSION}`;
|
|
22906
|
+
return `"${path17.join(".")}" is not valid`;
|
|
22907
|
+
}
|
|
22908
|
+
var SplitLockfile = class {
|
|
22909
|
+
constructor(path17, hiddenPath) {
|
|
22910
|
+
this.path = path17;
|
|
22911
|
+
this.hiddenPath = hiddenPath;
|
|
22912
|
+
this.shared = new JsonLockfile(path17);
|
|
22913
|
+
this.local = new JsonLockfile(hiddenPath);
|
|
22914
|
+
}
|
|
22915
|
+
path;
|
|
22916
|
+
hiddenPath;
|
|
22917
|
+
shared;
|
|
22918
|
+
local;
|
|
22919
|
+
async read() {
|
|
22920
|
+
const [shared, local] = await Promise.all([this.shared.read(), this.local.read()]);
|
|
22921
|
+
return { ...shared, skills: { ...shared.skills, ...local.skills } };
|
|
22922
|
+
}
|
|
22923
|
+
async update(change) {
|
|
22924
|
+
const data = await this.read();
|
|
22925
|
+
await change(data);
|
|
22926
|
+
const entries = Object.entries(data.skills);
|
|
22927
|
+
const isPrivate = ([, skill]) => Boolean(skill.private);
|
|
22928
|
+
await this.shared.update((shared) => {
|
|
22929
|
+
shared.skills = Object.fromEntries(entries.filter((entry) => !isPrivate(entry)));
|
|
22930
|
+
});
|
|
22931
|
+
const hidden = entries.filter(isPrivate);
|
|
22932
|
+
if (hidden.length > 0) {
|
|
22933
|
+
await this.local.update((local) => {
|
|
22934
|
+
local.skills = Object.fromEntries(hidden);
|
|
22935
|
+
});
|
|
22936
|
+
} else {
|
|
22937
|
+
await fs4.rm(this.hiddenPath, { force: true });
|
|
22938
|
+
}
|
|
22939
|
+
return data;
|
|
22940
|
+
}
|
|
22941
|
+
};
|
|
22474
22942
|
|
|
22475
22943
|
// src/services/ProcessRunner.ts
|
|
22476
22944
|
import { spawn } from "child_process";
|
|
@@ -22483,8 +22951,11 @@ var NodeProcessRunner = class {
|
|
|
22483
22951
|
cwd: options.cwd,
|
|
22484
22952
|
env: options.env ?? process.env,
|
|
22485
22953
|
signal: options.signal,
|
|
22486
|
-
stdio:
|
|
22954
|
+
stdio: "pipe"
|
|
22955
|
+
});
|
|
22956
|
+
child.stdin.on("error", () => {
|
|
22487
22957
|
});
|
|
22958
|
+
child.stdin.end(options.input);
|
|
22488
22959
|
let stdout = "";
|
|
22489
22960
|
let stderr = "";
|
|
22490
22961
|
child.stdout.on("data", (chunk) => stdout += chunk);
|
|
@@ -22520,10 +22991,10 @@ var NodeProcessRunner = class {
|
|
|
22520
22991
|
|
|
22521
22992
|
// src/services/xdg.ts
|
|
22522
22993
|
import os2 from "os";
|
|
22523
|
-
import
|
|
22994
|
+
import path15 from "path";
|
|
22524
22995
|
function stateHome(env) {
|
|
22525
22996
|
const base = env.XDG_STATE_HOME;
|
|
22526
|
-
return base &&
|
|
22997
|
+
return base && path15.isAbsolute(base) ? base : path15.join(os2.homedir(), ".local", "state");
|
|
22527
22998
|
}
|
|
22528
22999
|
|
|
22529
23000
|
// src/cli.tsx
|
|
@@ -22541,7 +23012,7 @@ var registry2 = new CommandRegistry().register(
|
|
|
22541
23012
|
slug: "zion-off/dotfiles",
|
|
22542
23013
|
url: "https://github.com/zion-off/dotfiles.git",
|
|
22543
23014
|
installer: "bin/dot",
|
|
22544
|
-
installerLink:
|
|
23015
|
+
installerLink: path16.join(os3.homedir(), ".local", "bin", "dot")
|
|
22545
23016
|
}),
|
|
22546
23017
|
git,
|
|
22547
23018
|
runner,
|
|
@@ -22553,15 +23024,22 @@ var registry2 = new CommandRegistry().register(
|
|
|
22553
23024
|
).register(
|
|
22554
23025
|
new SkillsCommand({
|
|
22555
23026
|
api: new HttpSkillsApi(process.env.ZION_SKILLS_URL || "https://zzzzion.com/api/skills"),
|
|
23027
|
+
sudoApi: new GithubSkillsApi(runner, process.env),
|
|
22556
23028
|
files: new NodeSkillFiles(),
|
|
22557
23029
|
scopes: {
|
|
22558
23030
|
global: {
|
|
22559
|
-
lockfile: new JsonLockfile(
|
|
22560
|
-
targets: skillTargets(os3.homedir())
|
|
23031
|
+
lockfile: new JsonLockfile(path16.join(stateHome(process.env), "zion", "zion.json")),
|
|
23032
|
+
targets: skillTargets(os3.homedir()),
|
|
23033
|
+
store: path16.join(stateHome(process.env), "zion", "skills")
|
|
22561
23034
|
},
|
|
22562
23035
|
project: {
|
|
22563
|
-
lockfile: new
|
|
22564
|
-
|
|
23036
|
+
lockfile: new SplitLockfile(
|
|
23037
|
+
path16.join(process.cwd(), ".zion", "zion.json"),
|
|
23038
|
+
path16.join(process.cwd(), ".zion", "private.json")
|
|
23039
|
+
),
|
|
23040
|
+
targets: skillTargets(process.cwd()),
|
|
23041
|
+
store: path16.join(process.cwd(), ".zion", "skills"),
|
|
23042
|
+
exclude: new GitExclude(git, process.cwd())
|
|
22565
23043
|
}
|
|
22566
23044
|
},
|
|
22567
23045
|
createPrompter
|