zion 4.2.2 → 4.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +673 -203
  2. 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 path13 from "path";
8
+ import path16 from "path";
9
9
 
10
10
  // package.json
11
- var version = "4.2.2";
11
+ var version = "4.3.1";
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 toggle = (i) => setChosen((current) => {
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 === " ") toggle(index);
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(options.filter((_, i) => chosen.has(i)));
767
+ onSubmit(
768
+ options.filter((_, i) => chosen.has(i)),
769
+ options.filter((_, i) => marked.has(i))
770
+ );
764
771
  }
765
772
  });
766
- const body = formatOptions(paint, options, index, (i, label) => {
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, path14) {
2294
- if (!path14)
2329
+ function getElementAtPath(obj, path17) {
2330
+ if (!path17)
2295
2331
  return obj;
2296
- return path14.reduce((acc, key) => acc?.[key], obj);
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(path14, issues) {
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(path14);
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, path14 = []) => {
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 }, [...path14, ...issue2.path]));
3141
+ issue2.errors.map((issues) => processError({ issues }, [...path17, ...issue2.path]));
3106
3142
  } else if (issue2.code === "invalid_key") {
3107
- processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
3143
+ processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
3108
3144
  } else if (issue2.code === "invalid_element") {
3109
- processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
3145
+ processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
3110
3146
  } else {
3111
- const fullpath = [...path14, ...issue2.path];
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, path14 = []) => {
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 }, [...path14, ...issue2.path]));
3190
+ issue2.errors.map((issues) => processError({ issues }, [...path17, ...issue2.path]));
3155
3191
  } else if (issue2.code === "invalid_key") {
3156
- processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
3192
+ processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
3157
3193
  } else if (issue2.code === "invalid_element") {
3158
- processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
3194
+ processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
3159
3195
  } else {
3160
- const fullpath = [...path14, ...issue2.path];
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 path14 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
3200
- for (const seg of path14) {
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 path14 = ref.slice(1).split("/").filter(Boolean);
20339
- if (path14.length === 0) {
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 (path14[0] === defsKey) {
20344
- const key = path14[1] === void 0 ? void 0 : decodeJSONPointerSegment(path14[1]);
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/SkillFiles.ts
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: path14, sha, executable, content }) => {
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}/${path14}`, "try again in a moment");
21631
+ throw new CliError(`${this.host} sent a damaged copy of ${name}/${path17}`, "try again in a moment");
21597
21632
  }
21598
- return { path: path14, sha, executable, content: bytes };
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 path9 from "path";
21850
+ import path11 from "path";
21606
21851
 
21607
21852
  // src/commands/skills/InstallFlow.ts
21608
- import path6 from "path";
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 path5 from "path";
21870
+ import path6 from "path";
21612
21871
 
21613
21872
  // src/commands/skills/copies.ts
21614
- import path4 from "path";
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) => path4.join(target.dir, name));
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
- for (const copy of mine) await files.write(copy.dir, skill.files);
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 data.skills[skill.name] = { commit: skill.commit, tree: skill.tree };
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(path4.dirname(dir))).join(", ");
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) => path5.dirname(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 relative = path5.relative(process.cwd(), dir);
21708
- return relative.startsWith("..") || path5.isAbsolute(relative) ? tildify(dir) : `./${relative}`;
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 names = await this.chooseSkills(ui, options, ctx, lock);
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) => path6.join(dir, skill.name))
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
- () => writeCopies(this.deps, skills, copies),
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
- async chooseSkills(ui, options, ctx, lock) {
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
- return ui.multiselect({
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 path8 from "path";
22149
+ import path10 from "path";
21799
22150
 
21800
22151
  // src/commands/skills/removals.ts
21801
- import path7 from "path";
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(path7.dirname(dir))) continue;
21807
- removals.push({ name, dir, edited: await deps.files.treeSha(dir) !== lock.skills[name].tree });
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,26 +22199,33 @@ var ManageFlow = class {
21843
22199
  }
21844
22200
  );
21845
22201
  const names = [.../* @__PURE__ */ new Set([...available, ...installed])].sort();
21846
- const ticked = new Set(
21847
- await ui.multiselect({
21848
- message: "Skills",
21849
- options: names.map((name) => ({ value: name, label: name, hint: this.hint(lock, name, latest, where) })),
21850
- initialValues: installed,
21851
- // Emptying the list removes everything, but with nothing installed an empty answer is a slip of the enter key.
21852
- required: installed.length === 0
21853
- })
21854
- );
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)));
21855
22214
  const adding = names.filter((name) => ticked.has(name) && !lock.skills[name]);
21856
22215
  const updated = installed.flatMap((name) => {
21857
22216
  const skill = latest.get(name);
21858
22217
  return ticked.has(name) && isNewer(skill, lock.skills[name]) ? [skill] : [];
21859
22218
  });
21860
22219
  const removing = installed.filter((name) => !ticked.has(name));
21861
- if (adding.length + updated.length + removing.length === 0) {
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) {
21862
22224
  ui.outro("Nothing to change.", { tone: "muted" });
21863
22225
  return 0;
21864
22226
  }
21865
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);
21866
22229
  const added = adding.length > 0 ? await ui.task(
21867
22230
  `Downloading ${adding.join(", ")}`,
21868
22231
  (signal) => Promise.all(adding.map((name) => api.get(name, signal))),
@@ -21875,32 +22238,49 @@ var ManageFlow = class {
21875
22238
  this.deps,
21876
22239
  skill,
21877
22240
  void 0,
21878
- targets.map((target) => path8.join(target.dir, skill.name))
22241
+ targets.map((target) => path10.join(target.dir, skill.name)),
22242
+ link
21879
22243
  )
21880
22244
  )
21881
22245
  )).flat(),
21882
22246
  ...(await Promise.all(updated.map((skill) => planCopies(this.deps, skill, lock.skills[skill.name], [])))).flat()
21883
22247
  ];
21884
22248
  const removals = await planRemovals(this.deps, lock, removing);
21885
- 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 });
21886
22250
  const risky = copies.some((copy) => copy.problem) || removals.some((removal) => removal.edited);
21887
- const total = added.length + updated.length + removing.length;
22251
+ const total = added.length + updated.length + removing.length + toggled.length;
21888
22252
  if (!await ui.confirm({ message: `Apply ${plural(total, "change")}?`, defaultValue: !risky })) {
21889
22253
  ui.outro("Left everything as it was.", { tone: "muted" });
21890
22254
  return 0;
21891
22255
  }
21892
- await ui.task(
22256
+ const tracked = await ui.task(
21893
22257
  "Applying changes",
21894
22258
  async () => {
21895
- await writeCopies(this.deps, [...added, ...updated], copies);
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
+ );
21896
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);
21897
22275
  },
21898
22276
  () => ({ title: "Changes applied" })
21899
22277
  );
22278
+ warnTracked(ui, tracked);
21900
22279
  const [first, ...rest] = [
21901
22280
  ["installed", added.length],
21902
22281
  ["updated", updated.length],
21903
- ["removed", removing.length]
22282
+ ["removed", removing.length],
22283
+ ["changed privacy of", toggled.length]
21904
22284
  ].filter(([, count]) => count > 0);
21905
22285
  const message = [`${first[0]} ${plural(first[1], "skill")}`, ...rest.map(([verb, count]) => `${verb} ${count}`)];
21906
22286
  const sentence = message.join(", ");
@@ -21934,13 +22314,14 @@ var ManageFlow = class {
21934
22314
  if (version3 === null) return `${where} \xB7 no longer available`;
21935
22315
  return isNewer(version3, entry) ? `${where} \xB7 update available` : where;
21936
22316
  }
21937
- summarise(ui, paint, lock, where, { added, updated, removing, copies, removals }) {
22317
+ summarise(ui, paint, lock, where, { added, updated, removing, toggled, hidden, copies, removals }) {
21938
22318
  const rows = [
21939
22319
  ...added.map(
21940
22320
  (skill) => [paint.success("+"), skill.name, describeDirs(copiesOf(skill, copies).map((copy) => copy.dir))]
21941
22321
  ),
21942
22322
  ...updated.map((skill) => [paint.accent("\u2191"), skill.name, describeChange(lock.skills[skill.name], skill)]),
21943
- ...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"])
21944
22325
  ];
21945
22326
  const width = Math.max(...rows.map(([, name]) => name.length));
21946
22327
  ui.step({
@@ -22045,7 +22426,11 @@ var UpdateFlow = class {
22045
22426
  if (installed.length === 0) {
22046
22427
  ui.outro("No skills are installed.", {
22047
22428
  tone: "muted",
22048
- lines: [`Install some with ${ctx.bin} skills install.`]
22429
+ lines: [
22430
+ `Install some with ${ctx.bin} skills install.`,
22431
+ // Without --project or --global, this was only the project's skills.
22432
+ ...options.scope ? [] : [`Add -g to update your global skills instead.`]
22433
+ ]
22049
22434
  });
22050
22435
  return 0;
22051
22436
  }
@@ -22053,18 +22438,17 @@ var UpdateFlow = class {
22053
22438
  if (missing)
22054
22439
  throw new CliError(`${missing} isn't installed`, `install it with ${ctx.bin} skills install ${missing}`);
22055
22440
  const names = options.names.length > 0 ? [...new Set(options.names)] : installed;
22056
- const pick2 = ctx.interactive && options.names.length === 0 && !options.yes;
22057
22441
  const checks = await ui.task(
22058
22442
  `Checking ${plural(names.length, "skill")} for updates`,
22059
22443
  (signal) => this.check(names, lock.skills, signal),
22060
- (checks2) => describeChecks(ctx.paint.stderr, checks2, { listUpdates: !pick2 })
22444
+ (checks2) => describeChecks(ctx.paint.stderr, checks2)
22061
22445
  );
22062
22446
  const outdated = checks.filter(isOutdated);
22063
22447
  if (outdated.length === 0) {
22064
22448
  ui.outro(names.length === 1 ? `${names[0]} is up to date.` : "Everything is up to date.");
22065
22449
  return 0;
22066
22450
  }
22067
- const chosen = pick2 ? await this.chooseUpdates(ui, outdated) : outdated.map((check2) => check2.latest);
22451
+ const chosen = outdated.map((check2) => check2.latest);
22068
22452
  const copies = (await Promise.all(chosen.map((skill) => planCopies(this.deps, skill, lock.skills[skill.name], [])))).flat();
22069
22453
  const retry = `${ctx.bin} skills update ${options.names.join(" ")}`.trimEnd();
22070
22454
  if (!await confirmConflicts(ui, copies, { yes: options.yes, retry })) {
@@ -22096,27 +22480,15 @@ var UpdateFlow = class {
22096
22480
  })
22097
22481
  );
22098
22482
  }
22099
- async chooseUpdates(ui, outdated) {
22100
- const width = Math.max(...outdated.map((check2) => shortCommit(check2.locked.commit).length));
22101
- return ui.multiselect({
22102
- message: "Update which?",
22103
- options: outdated.map((check2) => ({
22104
- value: check2.latest,
22105
- label: check2.name,
22106
- hint: describeChange(check2.locked, check2.latest).padStart(width)
22107
- })),
22108
- initialValues: outdated.map((check2) => check2.latest)
22109
- });
22110
- }
22111
22483
  };
22112
22484
  function isOutdated(check2) {
22113
22485
  return isNewer(check2.latest, check2.locked);
22114
22486
  }
22115
- function describeChecks(paint, checks, { listUpdates }) {
22487
+ function describeChecks(paint, checks) {
22116
22488
  const updates = checks.filter(isOutdated);
22117
22489
  const gone = checks.filter((check2) => check2.gone);
22118
22490
  if (updates.length === 0 && gone.length === 0) return { title: "Up to date" };
22119
- const shown2 = [...listUpdates ? updates : [], ...gone];
22491
+ const shown2 = [...updates, ...gone];
22120
22492
  const width = Math.max(0, ...shown2.map((check2) => check2.name.length));
22121
22493
  return {
22122
22494
  title: updates.length > 0 ? `${plural(updates.length, "update")} available` : `${plural(gone.length, "skill")} no longer available`,
@@ -22130,7 +22502,7 @@ function describeChecks(paint, checks, { listUpdates }) {
22130
22502
  // src/commands/skills/actions.ts
22131
22503
  var SKILLS_ACTIONS = [
22132
22504
  { id: "install", aliases: ["add"], hint: "choose skills and where they go" },
22133
- { id: "update", aliases: ["upgrade"], hint: "get newer versions of installed skills" },
22505
+ { id: "update", aliases: ["upgrade"], hint: "update every installed skill in this project (-g for global)" },
22134
22506
  { id: "remove", aliases: ["rm", "uninstall"], hint: "delete skills zion installed" },
22135
22507
  { id: "list", aliases: ["ls"], hint: "print every skill and where it is installed" },
22136
22508
  { id: "show", aliases: [], hint: "print a skill's SKILL.md" }
@@ -22153,6 +22525,11 @@ function parseSkillsOptions(args, bin, targetIds) {
22153
22525
  target: { type: "string", short: "t", multiple: true, default: [] },
22154
22526
  project: { type: "boolean", short: "p", default: false },
22155
22527
  global: { type: "boolean", short: "g", default: false },
22528
+ link: { type: "boolean", short: "l", default: false },
22529
+ copy: { type: "boolean", default: false },
22530
+ private: { type: "boolean", default: false },
22531
+ public: { type: "boolean", default: false },
22532
+ sudo: { type: "boolean", default: false },
22156
22533
  all: { type: "boolean", short: "a", default: false },
22157
22534
  yes: { type: "boolean", short: "y", default: false },
22158
22535
  json: { type: "boolean", default: false }
@@ -22178,12 +22555,18 @@ function parseSkillsOptions(args, bin, targetIds) {
22178
22555
  const targets = given.filter(isTarget);
22179
22556
  if (values.project && values.global) throw new UsageError("pass --project or --global, not both", usageHint);
22180
22557
  const scope = values.project ? "project" : values.global ? "global" : void 0;
22558
+ if (values.link && values.copy) throw new UsageError("pass --link or --copy, not both", usageHint);
22559
+ const mode = values.link ? "link" : values.copy ? "copy" : void 0;
22560
+ if (values.private && values.public) throw new UsageError("pass --private or --public, not both", usageHint);
22561
+ const hidden = values.private ? true : values.public ? false : void 0;
22181
22562
  const id = action?.id;
22182
22563
  const only = (flag, allowed) => {
22183
22564
  if (!id || !allowed.includes(id)) throw new UsageError(`${flag} works with: ${allowed.join(", ")}`, usageHint);
22184
22565
  };
22185
22566
  if (targets.length > 0) only("--target", ["install", "remove"]);
22186
22567
  if (scope && id === "show") throw new UsageError("--project and --global don't apply to show", usageHint);
22568
+ if (mode) only("--link and --copy", ["install"]);
22569
+ if (hidden !== void 0) only("--private and --public", ["install"]);
22187
22570
  if (values.all) only("--all", ["install", "remove"]);
22188
22571
  if (values.yes) only("--yes", ["install", "update", "remove"]);
22189
22572
  if (values.json) only("--json", ["list"]);
@@ -22192,7 +22575,18 @@ function parseSkillsOptions(args, bin, targetIds) {
22192
22575
  if (id === "show" && names.length !== 1) {
22193
22576
  throw new UsageError("show takes exactly one skill name", `e.g. ${bin} skills show commit`);
22194
22577
  }
22195
- return { action: id, names, targets, scope, all: values.all, yes: values.yes, json: values.json };
22578
+ return {
22579
+ action: id,
22580
+ names,
22581
+ targets,
22582
+ scope,
22583
+ mode,
22584
+ private: hidden,
22585
+ all: values.all,
22586
+ yes: values.yes,
22587
+ sudo: values.sudo,
22588
+ json: values.json
22589
+ };
22196
22590
  }
22197
22591
 
22198
22592
  // src/commands/skills/output.ts
@@ -22208,7 +22602,7 @@ async function listSkills(deps, ctx, json2) {
22208
22602
  return {
22209
22603
  name,
22210
22604
  available: available.includes(name),
22211
- installed: entry ? { commit: entry.commit, paths: await installedDirs(deps, name) } : null
22605
+ installed: entry ? { commit: entry.commit, paths: await installedDirs(deps, name), private: Boolean(entry.private) } : null
22212
22606
  };
22213
22607
  })
22214
22608
  );
@@ -22222,7 +22616,7 @@ async function listSkills(deps, ctx, json2) {
22222
22616
  for (const row of rows) {
22223
22617
  const status = row.installed ? `${paint.success("installed")} ${paint.muted(shortCommit(row.installed.commit))} ${describeDirs(
22224
22618
  row.installed.paths
22225
- )}` : "";
22619
+ )}${row.installed.private ? ` ${paint.muted("private")}` : ""}` : "";
22226
22620
  const gone = row.available ? "" : ` ${paint.warning("no longer available")}`;
22227
22621
  ctx.stdout.write(`${`${row.name.padEnd(width)} ${status}${gone}`.trimEnd()}
22228
22622
  `);
@@ -22245,16 +22639,19 @@ async function showSkill({ api }, ctx, name) {
22245
22639
  }
22246
22640
 
22247
22641
  // src/commands/skills/SkillsCommand.ts
22642
+ function relative(file2) {
22643
+ return `./${path11.relative(process.cwd(), file2)}`;
22644
+ }
22248
22645
  var SkillsCommand = class {
22249
22646
  constructor(base) {
22250
22647
  this.base = base;
22251
- const { scopes, api } = base;
22252
- const { targets, lockfile } = scopes.global;
22648
+ const { scopes, api, sudoApi } = base;
22649
+ const { targets, lockfile, store } = scopes.global;
22253
22650
  this.help = {
22254
22651
  usage: "[action] [skill...] [options]",
22255
- 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)} (./${path9.basename(
22652
+ 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, except update, which takes this project unless you pass --global. zion records what it installed in ${tildify(lockfile.path)} (${relative(
22256
22653
  scopes.project.lockfile.path
22257
- )} 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.`,
22654
+ )} 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).`,
22258
22655
  arguments: {
22259
22656
  title: "Actions",
22260
22657
  rows: SKILLS_ACTIONS.map((action) => [
@@ -22263,9 +22660,17 @@ var SkillsCommand = class {
22263
22660
  ])
22264
22661
  },
22265
22662
  options: [
22266
- ["-p, --project", `work in this folder, recorded in ./${path9.basename(scopes.project.lockfile.path)}`],
22267
- ["-g, --global", "work in your home directory (the default without a terminal)"],
22663
+ ["-p, --project", `work in this folder, recorded in ${relative(scopes.project.lockfile.path)}`],
22664
+ ["-g, --global", "work in your home directory (the default without a terminal, except for update)"],
22268
22665
  ["-t, --target <name>", `${targets.map((t) => t.id).join(" or ")}; repeat for both`],
22666
+ ["-l, --link", "symlink to a copy zion keeps, instead of copying into each folder (install)"],
22667
+ ["--copy", "copy into each folder without asking (install)"],
22668
+ ["--private", "keep the installed skills out of git with .git/info/exclude (install, --project)"],
22669
+ ["--public", "do not keep them out of git, without asking (install)"],
22670
+ [
22671
+ "--sudo",
22672
+ `read skills straight from the private ${sudoApi.host} repo, listing every skill in it, instead of from ${api.host}; needs a GitHub login that can read it`
22673
+ ],
22269
22674
  ["-a, --all", "every skill (install and remove)"],
22270
22675
  ["-y, --yes", "say yes to every confirmation, including replacing edited folders"],
22271
22676
  ["--json", "print the list as JSON"]
@@ -22273,8 +22678,13 @@ var SkillsCommand = class {
22273
22678
  examples: [
22274
22679
  "skills",
22275
22680
  "skills install commit author -t claude",
22681
+ "skills install commit --link -t claude",
22682
+ "skills install commit -p --private",
22683
+ "skills list --sudo",
22276
22684
  "skills install --all -t agents -t claude --yes",
22277
22685
  "skills update",
22686
+ "skills update -g",
22687
+ "skills update --sudo",
22278
22688
  "skills list --json",
22279
22689
  "skills show commit | less",
22280
22690
  "skills remove commit --yes"
@@ -22292,28 +22702,29 @@ var SkillsCommand = class {
22292
22702
  ctx.bin,
22293
22703
  this.base.scopes.global.targets.map((target) => target.id)
22294
22704
  );
22295
- if (options.action === "list") return listSkills(this.depsFor(options.scope ?? "global"), ctx, options.json);
22296
- if (options.action === "show") return showSkill(this.base, ctx, options.names[0]);
22705
+ const base = options.sudo ? { ...this.base, api: this.base.sudoApi } : this.base;
22706
+ if (options.action === "list") return listSkills(this.depsFor(base, options.scope ?? "global"), ctx, options.json);
22707
+ if (options.action === "show") return showSkill(base, ctx, options.names[0]);
22297
22708
  const given = options.action;
22298
- if (!given && !ctx.interactive) return listSkills(this.depsFor(options.scope ?? "global"), ctx, false);
22299
- const ui = this.base.createPrompter(ctx);
22709
+ if (!given && !ctx.interactive) return listSkills(this.depsFor(base, options.scope ?? "global"), ctx, false);
22710
+ const ui = base.createPrompter(ctx);
22300
22711
  return runSession(ui, async () => {
22301
- ui.intro("skills", this.base.api.host);
22302
- const scope = options.scope ?? await this.chooseScope(ui);
22303
- const deps = this.depsFor(scope);
22712
+ ui.intro("skills", base.api.host);
22713
+ const scope = options.scope ?? (given === "update" ? "project" : await this.chooseScope(ui));
22714
+ const deps = this.depsFor(base, scope);
22304
22715
  const flows = { install: InstallFlow, update: UpdateFlow, remove: RemoveFlow };
22305
22716
  return given ? new flows[given](deps).run(ui, options, ctx) : new ManageFlow(deps).run(ui, ctx);
22306
22717
  });
22307
22718
  }
22308
- depsFor(scope) {
22309
- return { ...this.base, ...this.base.scopes[scope] };
22719
+ depsFor(base, scope) {
22720
+ return { ...base, ...base.scopes[scope] };
22310
22721
  }
22311
22722
  chooseScope(ui) {
22312
22723
  const { project, global } = this.base.scopes;
22313
22724
  return ui.select({
22314
22725
  message: "Scope",
22315
22726
  options: [
22316
- { value: "project", label: "Locally", hint: `tracked in ./${path9.basename(project.lockfile.path)}` },
22727
+ { value: "project", label: "Locally", hint: `tracked in ${relative(project.lockfile.path)}` },
22317
22728
  { value: "global", label: "Globally", hint: `tracked in ${tildify(global.lockfile.path)}` }
22318
22729
  ],
22319
22730
  initialValue: "global"
@@ -22322,25 +22733,26 @@ var SkillsCommand = class {
22322
22733
  };
22323
22734
 
22324
22735
  // src/commands/skills/targets.ts
22325
- import path10 from "path";
22736
+ import path12 from "path";
22326
22737
  function skillTargets(homedir) {
22327
22738
  return [
22328
22739
  {
22329
22740
  id: "agents",
22330
- dir: path10.join(homedir, ".agents", "skills"),
22331
- home: path10.join(homedir, ".agents"),
22741
+ dir: path12.join(homedir, ".agents", "skills"),
22742
+ home: path12.join(homedir, ".agents"),
22332
22743
  name: "Universal"
22333
22744
  },
22334
22745
  {
22335
22746
  id: "claude",
22336
- dir: path10.join(homedir, ".claude", "skills"),
22337
- home: path10.join(homedir, ".claude"),
22747
+ dir: path12.join(homedir, ".claude", "skills"),
22748
+ home: path12.join(homedir, ".claude"),
22338
22749
  name: "Claude Code"
22339
22750
  }
22340
22751
  ];
22341
22752
  }
22342
22753
 
22343
22754
  // src/services/Git.ts
22755
+ import path13 from "path";
22344
22756
  var GitError = class extends Error {
22345
22757
  constructor(args, stderr) {
22346
22758
  super(stderr.split("\n").pop() || `git ${args.join(" ")} failed`);
@@ -22365,6 +22777,16 @@ var CliGit = class {
22365
22777
  topLevel(dir) {
22366
22778
  return this.query(["-C", dir, "rev-parse", "--show-toplevel"]);
22367
22779
  }
22780
+ async excludeFile(dir) {
22781
+ const root = await this.topLevel(dir);
22782
+ const file2 = root && await this.query(["-C", dir, "rev-parse", "--git-path", "info/exclude"]);
22783
+ return root && file2 ? { file: path13.resolve(dir, file2), root } : null;
22784
+ }
22785
+ async tracked(dir, paths) {
22786
+ if (paths.length === 0) return [];
22787
+ const out = await this.run(["-C", dir, "ls-files", "--", ...paths]);
22788
+ return out.split("\n").filter(Boolean);
22789
+ }
22368
22790
  remoteUrl(dir, remote) {
22369
22791
  return this.query(["-C", dir, "remote", "get-url", remote]);
22370
22792
  }
@@ -22401,14 +22823,18 @@ var CliGit = class {
22401
22823
  };
22402
22824
 
22403
22825
  // src/services/Lockfile.ts
22404
- import fs3 from "fs/promises";
22405
- import path11 from "path";
22826
+ import fs4 from "fs/promises";
22827
+ import path14 from "path";
22406
22828
  var VERSION = 2;
22407
22829
  var LockedSkill = external_exports.looseObject({
22408
22830
  /** The last commit in zion-off/skills that changed this skill. */
22409
22831
  commit: external_exports.string(),
22410
22832
  /** Git tree hash of the skill as installed, to spot local edits. */
22411
- tree: external_exports.string()
22833
+ tree: external_exports.string(),
22834
+ /** Whether the skill's folders are symlinks to zion's own copy rather than copies. */
22835
+ link: external_exports.boolean().optional(),
22836
+ /** Whether the skill is kept out of git, in the project's .git/info/exclude. */
22837
+ private: external_exports.boolean().optional()
22412
22838
  });
22413
22839
  var LockData = external_exports.looseObject({
22414
22840
  version: external_exports.literal(VERSION),
@@ -22417,14 +22843,14 @@ var LockData = external_exports.looseObject({
22417
22843
  });
22418
22844
  var Versioned = jsonText(external_exports.looseObject({ version: external_exports.number() }));
22419
22845
  var JsonLockfile = class {
22420
- constructor(path14) {
22421
- this.path = path14;
22846
+ constructor(path17) {
22847
+ this.path = path17;
22422
22848
  }
22423
22849
  path;
22424
22850
  async read() {
22425
22851
  let text;
22426
22852
  try {
22427
- text = await fs3.readFile(this.path, "utf8");
22853
+ text = await fs4.readFile(this.path, "utf8");
22428
22854
  } catch (error62) {
22429
22855
  if (errorCode(error62) === "ENOENT") return { version: VERSION, skills: {} };
22430
22856
  throw error62;
@@ -22450,13 +22876,13 @@ var JsonLockfile = class {
22450
22876
  return data.data;
22451
22877
  }
22452
22878
  async write(data) {
22453
- await fs3.mkdir(path11.dirname(this.path), { recursive: true });
22879
+ await fs4.mkdir(path14.dirname(this.path), { recursive: true });
22454
22880
  const temporary = `${this.path}.${process.pid}.tmp`;
22455
22881
  try {
22456
- await fs3.writeFile(temporary, JSON.stringify(data, null, 2) + "\n");
22457
- await fs3.rename(temporary, this.path);
22882
+ await fs4.writeFile(temporary, JSON.stringify(data, null, 2) + "\n");
22883
+ await fs4.rename(temporary, this.path);
22458
22884
  } catch (error62) {
22459
- await fs3.rm(temporary, { force: true });
22885
+ await fs4.rm(temporary, { force: true });
22460
22886
  throw error62;
22461
22887
  }
22462
22888
  }
@@ -22467,11 +22893,45 @@ var JsonLockfile = class {
22467
22893
  );
22468
22894
  }
22469
22895
  };
22470
- function describeIssue({ path: path14, code }) {
22471
- if (path14.length === 0) return code === "custom" ? "it is not valid JSON" : "it is not an object";
22472
- if (path14[0] === "version") return `its version isn't ${VERSION}`;
22473
- return `"${path14.join(".")}" is not valid`;
22474
- }
22896
+ function describeIssue({ path: path17, code }) {
22897
+ if (path17.length === 0) return code === "custom" ? "it is not valid JSON" : "it is not an object";
22898
+ if (path17[0] === "version") return `its version isn't ${VERSION}`;
22899
+ return `"${path17.join(".")}" is not valid`;
22900
+ }
22901
+ var SplitLockfile = class {
22902
+ constructor(path17, hiddenPath) {
22903
+ this.path = path17;
22904
+ this.hiddenPath = hiddenPath;
22905
+ this.shared = new JsonLockfile(path17);
22906
+ this.local = new JsonLockfile(hiddenPath);
22907
+ }
22908
+ path;
22909
+ hiddenPath;
22910
+ shared;
22911
+ local;
22912
+ async read() {
22913
+ const [shared, local] = await Promise.all([this.shared.read(), this.local.read()]);
22914
+ return { ...shared, skills: { ...shared.skills, ...local.skills } };
22915
+ }
22916
+ async update(change) {
22917
+ const data = await this.read();
22918
+ await change(data);
22919
+ const entries = Object.entries(data.skills);
22920
+ const isPrivate = ([, skill]) => Boolean(skill.private);
22921
+ await this.shared.update((shared) => {
22922
+ shared.skills = Object.fromEntries(entries.filter((entry) => !isPrivate(entry)));
22923
+ });
22924
+ const hidden = entries.filter(isPrivate);
22925
+ if (hidden.length > 0) {
22926
+ await this.local.update((local) => {
22927
+ local.skills = Object.fromEntries(hidden);
22928
+ });
22929
+ } else {
22930
+ await fs4.rm(this.hiddenPath, { force: true });
22931
+ }
22932
+ return data;
22933
+ }
22934
+ };
22475
22935
 
22476
22936
  // src/services/ProcessRunner.ts
22477
22937
  import { spawn } from "child_process";
@@ -22484,8 +22944,11 @@ var NodeProcessRunner = class {
22484
22944
  cwd: options.cwd,
22485
22945
  env: options.env ?? process.env,
22486
22946
  signal: options.signal,
22487
- stdio: ["ignore", "pipe", "pipe"]
22947
+ stdio: "pipe"
22948
+ });
22949
+ child.stdin.on("error", () => {
22488
22950
  });
22951
+ child.stdin.end(options.input);
22489
22952
  let stdout = "";
22490
22953
  let stderr = "";
22491
22954
  child.stdout.on("data", (chunk) => stdout += chunk);
@@ -22521,10 +22984,10 @@ var NodeProcessRunner = class {
22521
22984
 
22522
22985
  // src/services/xdg.ts
22523
22986
  import os2 from "os";
22524
- import path12 from "path";
22987
+ import path15 from "path";
22525
22988
  function stateHome(env) {
22526
22989
  const base = env.XDG_STATE_HOME;
22527
- return base && path12.isAbsolute(base) ? base : path12.join(os2.homedir(), ".local", "state");
22990
+ return base && path15.isAbsolute(base) ? base : path15.join(os2.homedir(), ".local", "state");
22528
22991
  }
22529
22992
 
22530
22993
  // src/cli.tsx
@@ -22542,7 +23005,7 @@ var registry2 = new CommandRegistry().register(
22542
23005
  slug: "zion-off/dotfiles",
22543
23006
  url: "https://github.com/zion-off/dotfiles.git",
22544
23007
  installer: "bin/dot",
22545
- installerLink: path13.join(os3.homedir(), ".local", "bin", "dot")
23008
+ installerLink: path16.join(os3.homedir(), ".local", "bin", "dot")
22546
23009
  }),
22547
23010
  git,
22548
23011
  runner,
@@ -22554,15 +23017,22 @@ var registry2 = new CommandRegistry().register(
22554
23017
  ).register(
22555
23018
  new SkillsCommand({
22556
23019
  api: new HttpSkillsApi(process.env.ZION_SKILLS_URL || "https://zzzzion.com/api/skills"),
23020
+ sudoApi: new GithubSkillsApi(runner, process.env),
22557
23021
  files: new NodeSkillFiles(),
22558
23022
  scopes: {
22559
23023
  global: {
22560
- lockfile: new JsonLockfile(path13.join(stateHome(process.env), "zion.json")),
22561
- targets: skillTargets(os3.homedir())
23024
+ lockfile: new JsonLockfile(path16.join(stateHome(process.env), "zion", "zion.json")),
23025
+ targets: skillTargets(os3.homedir()),
23026
+ store: path16.join(stateHome(process.env), "zion", "skills")
22562
23027
  },
22563
23028
  project: {
22564
- lockfile: new JsonLockfile(path13.join(process.cwd(), "zion.json")),
22565
- targets: skillTargets(process.cwd())
23029
+ lockfile: new SplitLockfile(
23030
+ path16.join(process.cwd(), ".zion", "zion.json"),
23031
+ path16.join(process.cwd(), ".zion", "private.json")
23032
+ ),
23033
+ targets: skillTargets(process.cwd()),
23034
+ store: path16.join(process.cwd(), ".zion", "skills"),
23035
+ exclude: new GitExclude(git, process.cwd())
22566
23036
  }
22567
23037
  },
22568
23038
  createPrompter