zion 4.1.2 → 4.2.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 +290 -272
  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 path12 from "path";
8
+ import path13 from "path";
9
9
 
10
10
  // package.json
11
- var version = "4.1.2";
11
+ var version = "4.2.1";
12
12
 
13
13
  // src/lib/theme.ts
14
14
  import { Chalk, supportsColor, supportsColorStderr } from "chalk";
@@ -23,8 +23,8 @@ var symbols = {
23
23
  start: "\u250C",
24
24
  bar: "\u2502",
25
25
  end: "\u2514",
26
- active: "\u25C6",
27
- done: "\u25C7",
26
+ active: "\u25CF",
27
+ done: "\u25CF",
28
28
  warning: "\u25B2",
29
29
  error: "\u25A0",
30
30
  radioOn: "\u25CF",
@@ -63,6 +63,9 @@ function paintFor(stream, { color, env }) {
63
63
  function toneColor(paint) {
64
64
  return { success: paint.success, warning: paint.warning, error: paint.error, info: paint.accent, muted: paint.muted };
65
65
  }
66
+ function stepColor(paint, tone) {
67
+ return tone === "warning" || tone === "error" ? toneColor(paint)[tone] : paint.muted;
68
+ }
66
69
  var stepSymbol = {
67
70
  success: symbols.done,
68
71
  warning: symbols.warning,
@@ -77,11 +80,12 @@ var finalSymbol = {
77
80
  info: symbols.radioOn,
78
81
  muted: symbols.error
79
82
  };
83
+ var MARGIN = " ";
80
84
  function bar(paint) {
81
85
  return paint.muted(symbols.bar);
82
86
  }
83
87
  function join(lines) {
84
- return lines.filter((line) => typeof line === "string").join("\n");
88
+ return lines.filter((line) => typeof line === "string").map((line) => line ? `${MARGIN}${line}` : line).join("\n");
85
89
  }
86
90
  function detail(paint, line, tone) {
87
91
  return tone === "warning" || tone === "error" ? toneColor(paint)[tone](line) : paint.dim(line);
@@ -96,7 +100,7 @@ function formatIntro(paint, title, subtitle) {
96
100
  function formatStep(paint, { title, lines = [], tone = "success" }) {
97
101
  return join([
98
102
  bar(paint),
99
- `${toneColor(paint)[tone](stepSymbol[tone])} ${title}`,
103
+ `${stepColor(paint, tone)(stepSymbol[tone])} ${title}`,
100
104
  ...lines.map((line) => `${bar(paint)} ${detail(paint, line, tone)}`)
101
105
  ]);
102
106
  }
@@ -481,13 +485,13 @@ var BORDER = "#4d4a44";
481
485
  var GRAIN = 14;
482
486
  var WIDTH = 52;
483
487
  var HEIGHT = 13;
484
- var MARGIN = " ";
488
+ var MARGIN2 = " ";
485
489
  function renderCard(paint, columns = Infinity) {
486
490
  const email3 = { text: "contact@zzzzion.com", color: SOFT, link: "mailto:contact@zzzzion.com" };
487
491
  const name = { text: spaced("ATIB JAWAD ZION"), color: INK };
488
- if (columns < WIDTH + MARGIN.length) {
492
+ if (columns < WIDTH + MARGIN2.length) {
489
493
  return `
490
- ${[name, null, email3].map((segment) => segment ? `${MARGIN}${draw(paint, segment)}` : "").join("\n")}
494
+ ${[name, null, email3].map((segment) => segment ? `${MARGIN2}${draw(paint, segment)}` : "").join("\n")}
491
495
 
492
496
  `;
493
497
  }
@@ -509,7 +513,7 @@ ${[
509
513
  edge(`\u250C${"\u2500".repeat(inner)}\u2510`),
510
514
  ...rows.map((row) => `${edge("\u2502")}${row}${edge("\u2502")}`),
511
515
  edge(`\u2514${"\u2500".repeat(inner)}\u2518`)
512
- ].map((line) => `${MARGIN}${line}`).join("\n")}
516
+ ].map((line) => `${MARGIN2}${line}`).join("\n")}
513
517
 
514
518
  `;
515
519
  }
@@ -529,7 +533,7 @@ function stock(paint, inner, lines) {
529
533
  const beside = segment && x >= start - 1 && x <= start + segment.text.length;
530
534
  row += beside ? " " : fiber(paint, x, y);
531
535
  }
532
- return `${MARGIN}${ground(row)}`;
536
+ return `${MARGIN2}${ground(row)}`;
533
537
  });
534
538
  }
535
539
  var FIBERS = ["\xB7", "\u02D9", ".", ",", "'", "`", "\xB8", "\u02DB"];
@@ -2286,10 +2290,10 @@ function mergeDefs(...defs) {
2286
2290
  function cloneDef(schema) {
2287
2291
  return mergeDefs(schema._zod.def);
2288
2292
  }
2289
- function getElementAtPath(obj, path13) {
2290
- if (!path13)
2293
+ function getElementAtPath(obj, path14) {
2294
+ if (!path14)
2291
2295
  return obj;
2292
- return path13.reduce((acc, key) => acc?.[key], obj);
2296
+ return path14.reduce((acc, key) => acc?.[key], obj);
2293
2297
  }
2294
2298
  function promiseAllObject(promisesObj) {
2295
2299
  const keys = Object.keys(promisesObj);
@@ -2629,11 +2633,11 @@ function explicitlyAborted(x, startIndex = 0) {
2629
2633
  }
2630
2634
  return false;
2631
2635
  }
2632
- function prefixIssues(path13, issues) {
2636
+ function prefixIssues(path14, issues) {
2633
2637
  return issues.map((iss) => {
2634
2638
  var _a3;
2635
2639
  (_a3 = iss).path ?? (_a3.path = []);
2636
- iss.path.unshift(path13);
2640
+ iss.path.unshift(path14);
2637
2641
  return iss;
2638
2642
  });
2639
2643
  }
@@ -3095,16 +3099,16 @@ function flattenError(error62, mapper = (issue2) => issue2.message) {
3095
3099
  }
3096
3100
  function formatError2(error62, mapper = (issue2) => issue2.message) {
3097
3101
  const fieldErrors = { _errors: [] };
3098
- const processError = (error63, path13 = []) => {
3102
+ const processError = (error63, path14 = []) => {
3099
3103
  for (const issue2 of error63.issues) {
3100
3104
  if (issue2.code === "invalid_union" && issue2.errors.length) {
3101
- issue2.errors.map((issues) => processError({ issues }, [...path13, ...issue2.path]));
3105
+ issue2.errors.map((issues) => processError({ issues }, [...path14, ...issue2.path]));
3102
3106
  } else if (issue2.code === "invalid_key") {
3103
- processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
3107
+ processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
3104
3108
  } else if (issue2.code === "invalid_element") {
3105
- processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
3109
+ processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
3106
3110
  } else {
3107
- const fullpath = [...path13, ...issue2.path];
3111
+ const fullpath = [...path14, ...issue2.path];
3108
3112
  if (fullpath.length === 0) {
3109
3113
  fieldErrors._errors.push(mapper(issue2));
3110
3114
  } else {
@@ -3143,17 +3147,17 @@ function formatError2(error62, mapper = (issue2) => issue2.message) {
3143
3147
  }
3144
3148
  function treeifyError(error62, mapper = (issue2) => issue2.message) {
3145
3149
  const result = { errors: [] };
3146
- const processError = (error63, path13 = []) => {
3150
+ const processError = (error63, path14 = []) => {
3147
3151
  var _a3;
3148
3152
  for (const issue2 of error63.issues) {
3149
3153
  if (issue2.code === "invalid_union" && issue2.errors.length) {
3150
- issue2.errors.map((issues) => processError({ issues }, [...path13, ...issue2.path]));
3154
+ issue2.errors.map((issues) => processError({ issues }, [...path14, ...issue2.path]));
3151
3155
  } else if (issue2.code === "invalid_key") {
3152
- processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
3156
+ processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
3153
3157
  } else if (issue2.code === "invalid_element") {
3154
- processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
3158
+ processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
3155
3159
  } else {
3156
- const fullpath = [...path13, ...issue2.path];
3160
+ const fullpath = [...path14, ...issue2.path];
3157
3161
  if (fullpath.length === 0) {
3158
3162
  result.errors.push(mapper(issue2));
3159
3163
  continue;
@@ -3192,8 +3196,8 @@ function treeifyError(error62, mapper = (issue2) => issue2.message) {
3192
3196
  }
3193
3197
  function toDotPath(_path) {
3194
3198
  const segs = [];
3195
- const path13 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
3196
- for (const seg of path13) {
3199
+ const path14 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
3200
+ for (const seg of path14) {
3197
3201
  if (typeof seg === "number")
3198
3202
  segs.push(`[${seg}]`);
3199
3203
  else if (typeof seg === "symbol")
@@ -20331,13 +20335,13 @@ function resolveRef(ref, ctx) {
20331
20335
  if (!ref.startsWith("#")) {
20332
20336
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
20333
20337
  }
20334
- const path13 = ref.slice(1).split("/").filter(Boolean);
20335
- if (path13.length === 0) {
20338
+ const path14 = ref.slice(1).split("/").filter(Boolean);
20339
+ if (path14.length === 0) {
20336
20340
  return ctx.rootSchema;
20337
20341
  }
20338
20342
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
20339
- if (path13[0] === defsKey) {
20340
- const key = path13[1] === void 0 ? void 0 : decodeJSONPointerSegment(path13[1]);
20343
+ if (path14[0] === defsKey) {
20344
+ const key = path14[1] === void 0 ? void 0 : decodeJSONPointerSegment(path14[1]);
20341
20345
  if (!key || !ctx.defs[key]) {
20342
20346
  throw new Error(`Reference not found: ${ref}`);
20343
20347
  }
@@ -21461,6 +21465,25 @@ import { createHash } from "crypto";
21461
21465
  function gitBlobSha(content) {
21462
21466
  return createHash("sha1").update(`blob ${content.length}\0`).update(content).digest("hex");
21463
21467
  }
21468
+ var DIRECTORY_MODE = "40000";
21469
+ function gitTreeSha(entries) {
21470
+ const key = (entry) => Buffer.from(entry.mode === DIRECTORY_MODE ? `${entry.name}/` : entry.name);
21471
+ const body = Buffer.concat(
21472
+ [...entries].sort((a, b) => Buffer.compare(key(a), key(b))).map((entry) => Buffer.concat([Buffer.from(`${entry.mode} ${entry.name}\0`), Buffer.from(entry.sha, "hex")]))
21473
+ );
21474
+ return createHash("sha1").update(`tree ${body.length}\0`).update(body).digest("hex");
21475
+ }
21476
+ function gitTreeShaOfFiles(files) {
21477
+ const here = [];
21478
+ const nested = /* @__PURE__ */ new Map();
21479
+ for (const file2 of files) {
21480
+ const [first, ...rest] = file2.path.split("/");
21481
+ if (rest.length === 0) here.push({ name: first, mode: file2.executable ? "100755" : "100644", sha: file2.sha });
21482
+ else nested.set(first, [...nested.get(first) ?? [], { ...file2, path: rest.join("/") }]);
21483
+ }
21484
+ for (const [name, children] of nested) here.push({ name, mode: DIRECTORY_MODE, sha: gitTreeShaOfFiles(children) });
21485
+ return gitTreeSha(here);
21486
+ }
21464
21487
 
21465
21488
  // src/commands/skills/SkillFiles.ts
21466
21489
  var NOISE = /* @__PURE__ */ new Set([".DS_Store"]);
@@ -21468,62 +21491,45 @@ var NodeSkillFiles = class {
21468
21491
  async exists(dir) {
21469
21492
  return (await fs2.stat(dir).catch(() => null))?.isDirectory() ?? false;
21470
21493
  }
21471
- async compare(dir, expected) {
21472
- if (!await fs2.lstat(dir).catch(() => null)) return { exists: false, changed: [], missing: [], extra: [] };
21473
- const actual = /* @__PURE__ */ new Map();
21474
- await walk(dir, async (relative, absolute, isFile) => {
21475
- actual.set(relative, isFile ? gitBlobSha(await fs2.readFile(absolute)) : null);
21476
- }).catch(() => {
21477
- });
21478
- return {
21479
- exists: true,
21480
- changed: Object.keys(expected).filter((file2) => actual.has(file2) && actual.get(file2) !== expected[file2]),
21481
- missing: Object.keys(expected).filter((file2) => !actual.has(file2)),
21482
- extra: [...actual.keys()].filter((file2) => !(file2 in expected))
21483
- };
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([]);
21484
21498
  }
21485
- async write(dir, files, stale) {
21486
- for (const file2 of files) {
21487
- const target = inside(dir, file2.path);
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];
21488
21504
  await fs2.mkdir(path3.dirname(target), { recursive: true });
21489
- await fs2.rm(target, { force: true });
21490
21505
  await fs2.writeFile(target, file2.content, { mode: file2.executable ? 493 : 420 });
21491
21506
  }
21492
- await this.delete(dir, stale);
21493
21507
  }
21494
- async remove(dir, files) {
21495
- await this.delete(dir, files);
21496
- const left = [];
21497
- await walk(dir, async (relative) => {
21498
- left.push(relative);
21499
- }).catch(() => {
21500
- });
21501
- if (left.length === 0) await fs2.rm(dir, { recursive: true, force: true });
21502
- return left;
21503
- }
21504
- async delete(dir, files) {
21505
- for (const file2 of files) {
21506
- const target = inside(dir, file2);
21507
- await fs2.rm(target, { force: true });
21508
- await pruneEmpty(path3.dirname(target), dir);
21509
- }
21508
+ async remove(dir) {
21509
+ await fs2.rm(dir, { recursive: true, force: true });
21510
21510
  }
21511
21511
  };
21512
- async function walk(dir, visit2, prefix = "") {
21512
+ var UNREADABLE = "unreadable";
21513
+ async function hashDirectory(dir) {
21514
+ const entries = [];
21513
21515
  for (const entry of await fs2.readdir(dir, { withFileTypes: true })) {
21514
21516
  if (NOISE.has(entry.name)) continue;
21515
21517
  const absolute = path3.join(dir, entry.name);
21516
- const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
21517
- if (entry.isDirectory()) await walk(absolute, visit2, relative);
21518
- else await visit2(relative, absolute, entry.isFile());
21519
- }
21520
- }
21521
- async function pruneEmpty(dir, root) {
21522
- for (let current = dir; current.startsWith(root + path3.sep); current = path3.dirname(current)) {
21523
- const entries = await fs2.readdir(current).catch(() => null);
21524
- if (!entries || entries.some((name) => !NOISE.has(name))) return;
21525
- await fs2.rm(current, { recursive: true, force: true });
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
+ }
21526
21531
  }
21532
+ return entries.length > 0 ? gitTreeSha(entries) : null;
21527
21533
  }
21528
21534
  function inside(dir, relative) {
21529
21535
  const target = path3.resolve(dir, relative);
@@ -21540,7 +21546,6 @@ var SkillList = external_exports.object({
21540
21546
  });
21541
21547
  var SkillBody = external_exports.object({
21542
21548
  commit: external_exports.string(),
21543
- updatedAt: external_exports.string(),
21544
21549
  files: external_exports.array(external_exports.object({ path: external_exports.string(), sha: external_exports.string(), executable: external_exports.boolean(), content: external_exports.string() }))
21545
21550
  });
21546
21551
  var SkillNotFoundError = class extends CliError {
@@ -21585,73 +21590,54 @@ var HttpSkillsApi = class {
21585
21590
  if (error62 instanceof HttpStatusError && error62.status === 404) throw new SkillNotFoundError(name);
21586
21591
  throw error62;
21587
21592
  }
21588
- return {
21589
- name,
21590
- commit: body.commit,
21591
- updatedAt: body.updatedAt,
21592
- files: body.files.map(({ path: path13, sha, executable, content }) => {
21593
- const bytes = Buffer.from(content, "base64");
21594
- if (gitBlobSha(bytes) !== sha) {
21595
- throw new CliError(`${this.host} sent a damaged copy of ${name}/${path13}`, "try again in a moment");
21596
- }
21597
- return { path: path13, sha, executable, content: bytes };
21598
- })
21599
- };
21593
+ const files = body.files.map(({ path: path14, sha, executable, content }) => {
21594
+ const bytes = Buffer.from(content, "base64");
21595
+ if (gitBlobSha(bytes) !== sha) {
21596
+ throw new CliError(`${this.host} sent a damaged copy of ${name}/${path14}`, "try again in a moment");
21597
+ }
21598
+ return { path: path14, sha, executable, content: bytes };
21599
+ });
21600
+ return { name, commit: body.commit, tree: gitTreeShaOfFiles(files), files };
21600
21601
  }
21601
21602
  };
21602
21603
 
21604
+ // src/commands/skills/SkillsCommand.ts
21605
+ import path9 from "path";
21606
+
21603
21607
  // src/commands/skills/InstallFlow.ts
21604
21608
  import path6 from "path";
21605
21609
 
21606
21610
  // src/commands/skills/chooseTargets.ts
21607
- import path4 from "path";
21608
- async function chooseTargets(ui, { targets, files }, given, lock) {
21609
- if (given.length > 0) {
21610
- const chosen = targets.filter((target) => given.includes(target.id));
21611
- ui.step({ title: "Install into", lines: [chosen.map((target) => tildify(target.dir)).join(", ")] });
21612
- return chosen;
21613
- }
21614
- const used = new Set(Object.values(lock.skills).flatMap((skill) => skill.paths.map((dir) => path4.dirname(dir))));
21615
- let suggested = targets.filter((target) => used.has(target.dir));
21616
- if (suggested.length === 0) {
21617
- const present = await Promise.all(targets.map((target) => files.exists(target.home)));
21618
- suggested = targets.filter((_, i) => present[i]);
21619
- }
21620
- return ui.multiselect({
21621
- message: "Install into",
21622
- options: targets.map((target) => ({ value: target, label: tildify(target.dir), hint: target.hint })),
21623
- initialValues: suggested,
21624
- nonInteractiveHint: `pass --target (${targets.map((target) => target.id).join(", ")}), e.g. -t ${targets[0].id}`
21625
- });
21626
- }
21611
+ import path5 from "path";
21627
21612
 
21628
21613
  // src/commands/skills/copies.ts
21629
- import path5 from "path";
21630
- function fileHashes(skill) {
21631
- return Object.fromEntries(skill.files.map((file2) => [file2.path, file2.sha]));
21632
- }
21633
- async function planCopies({ files }, skill, locked, chosen) {
21634
- const remote = fileHashes(skill);
21635
- const copies = [];
21636
- for (const dir of /* @__PURE__ */ new Set([...chosen, ...locked?.paths ?? []])) {
21637
- const ours = locked?.paths.includes(dir) ? locked : void 0;
21638
- const { exists, changed } = await files.compare(dir, ours?.files ?? remote);
21639
- if (!exists && !chosen.includes(dir)) continue;
21640
- copies.push({
21641
- skill,
21642
- dir,
21643
- stale: ours ? Object.keys(ours.files).filter((file2) => !(file2 in remote)) : [],
21644
- problem: exists && changed.length > 0 ? ours ? "has local edits" : "wasn't installed by zion" : void 0
21645
- });
21646
- }
21647
- return copies;
21614
+ import path4 from "path";
21615
+ var EDITED = "edited since zion installed it";
21616
+ async function installedDirs({ files, targets }, name) {
21617
+ const dirs = targets.map((target) => path4.join(target.dir, name));
21618
+ const present = await Promise.all(dirs.map((dir) => files.exists(dir)));
21619
+ return dirs.filter((_, i) => present[i]);
21620
+ }
21621
+ async function planCopies(deps, skill, locked, chosen) {
21622
+ const dirs = /* @__PURE__ */ new Set([...chosen, ...locked ? await installedDirs(deps, skill.name) : []]);
21623
+ return Promise.all(
21624
+ [...dirs].map(async (dir) => {
21625
+ const tree = await deps.files.treeSha(dir);
21626
+ const edited = tree !== null && tree !== skill.tree && tree !== locked?.tree;
21627
+ return {
21628
+ skill,
21629
+ dir,
21630
+ problem: edited ? locked ? EDITED : "not installed by zion" : void 0
21631
+ };
21632
+ })
21633
+ );
21648
21634
  }
21649
21635
  async function confirmConflicts(ui, copies, { yes: yes2, retry }) {
21650
21636
  const conflicts = copies.filter((copy) => copy.problem);
21651
21637
  if (conflicts.length === 0) return true;
21652
21638
  const width = Math.max(...conflicts.map((copy) => tildify(copy.dir).length));
21653
21639
  ui.step({
21654
- title: conflicts.length === 1 ? "Already there" : `${conflicts.length} already there`,
21640
+ title: `${plural(conflicts.length, "folder")} with local changes`,
21655
21641
  tone: "warning",
21656
21642
  lines: conflicts.map((copy) => `${tildify(copy.dir).padEnd(width)} ${copy.problem}`)
21657
21643
  });
@@ -21662,23 +21648,13 @@ async function confirmConflicts(ui, copies, { yes: yes2, retry }) {
21662
21648
  nonInteractiveHint: `pass --yes to replace: ${retry} --yes`
21663
21649
  });
21664
21650
  }
21665
- async function writeCopies({ files, lockfile, now }, skills, copies) {
21651
+ async function writeCopies({ files, lockfile }, skills, copies) {
21666
21652
  for (const skill of skills) {
21667
21653
  const mine = copiesOf(skill, copies);
21668
- for (const copy of mine) await files.write(copy.dir, skill.files, copy.stale);
21654
+ for (const copy of mine) await files.write(copy.dir, skill.files);
21669
21655
  await lockfile.update((data) => {
21670
- const previous = data.skills[skill.name];
21671
- if (mine.length === 0) {
21672
- delete data.skills[skill.name];
21673
- return;
21674
- }
21675
- data.skills[skill.name] = {
21676
- commit: skill.commit,
21677
- updatedAt: skill.updatedAt,
21678
- installedAt: previous?.installedAt ?? now().toISOString(),
21679
- paths: mine.map((copy) => copy.dir),
21680
- files: fileHashes(skill)
21681
- };
21656
+ if (mine.length === 0) delete data.skills[skill.name];
21657
+ else data.skills[skill.name] = { commit: skill.commit, tree: skill.tree };
21682
21658
  });
21683
21659
  }
21684
21660
  }
@@ -21696,22 +21672,40 @@ function copiesOf(skill, copies) {
21696
21672
  return copies.filter((copy) => copy.skill === skill);
21697
21673
  }
21698
21674
  function describeDirs(dirs) {
21699
- return dirs.map((dir) => tildify(path5.dirname(dir))).join(", ");
21675
+ return dirs.map((dir) => tildify(path4.dirname(dir))).join(", ");
21700
21676
  }
21701
21677
  function isNewer(latest, locked) {
21702
21678
  return Boolean(latest && locked && latest.commit !== locked.commit);
21703
21679
  }
21704
21680
  function describeChange(locked, latest) {
21705
- const before = locked.files;
21706
- const after = fileHashes(latest);
21707
- const count = (files2) => files2.length;
21708
- const changes = [
21709
- [count(Object.keys(after).filter((file2) => file2 in before && before[file2] !== after[file2])), "changed"],
21710
- [count(Object.keys(after).filter((file2) => !(file2 in before))), "added"],
21711
- [count(Object.keys(before).filter((file2) => !(file2 in after))), "removed"]
21712
- ];
21713
- const files = changes.filter(([n]) => n > 0).map(([n, what]) => `${n} ${what}`);
21714
- return `${shortCommit(locked.commit)} \u2192 ${shortCommit(latest.commit)}${files.length ? ` \xB7 ${files.join(", ")}` : ""}`;
21681
+ return `${shortCommit(locked.commit)} \u2192 ${shortCommit(latest.commit)}`;
21682
+ }
21683
+
21684
+ // src/commands/skills/chooseTargets.ts
21685
+ async function chooseTargets(ui, deps, given, lock) {
21686
+ const { targets, files } = deps;
21687
+ if (given.length > 0) {
21688
+ const chosen = targets.filter((target) => given.includes(target.id));
21689
+ ui.step({ title: "Install into", lines: [chosen.map((target) => target.name).join(", ")] });
21690
+ return chosen;
21691
+ }
21692
+ 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)));
21694
+ let suggested = targets.filter((target) => used.has(target.dir));
21695
+ if (suggested.length === 0) {
21696
+ const present = await Promise.all(targets.map((target) => files.exists(target.home)));
21697
+ suggested = targets.filter((_, i) => present[i]);
21698
+ }
21699
+ return ui.multiselect({
21700
+ message: "Install into",
21701
+ options: targets.map((target) => ({ value: target, label: target.name, hint: shown(target.dir) })),
21702
+ initialValues: suggested,
21703
+ nonInteractiveHint: `pass --target (${targets.map((target) => target.id).join(", ")}), e.g. -t ${targets[0].id}`
21704
+ });
21705
+ }
21706
+ function shown(dir) {
21707
+ const relative = path5.relative(process.cwd(), dir);
21708
+ return relative.startsWith("..") || path5.isAbsolute(relative) ? tildify(dir) : `./${relative}`;
21715
21709
  }
21716
21710
 
21717
21711
  // src/commands/skills/InstallFlow.ts
@@ -21770,19 +21764,19 @@ var InstallFlow = class {
21770
21764
  () => describeCopies(ctx.paint.stderr, "Installed", skills, copies)
21771
21765
  );
21772
21766
  ui.outro(`Installed ${plural(skills.length, "skill")}.`, {
21773
- lines: ["Start a new agent session to use them.", `Run ${ctx.bin} skills update to get new versions.`]
21767
+ lines: ["Start a new agent session to use them.", `Run ${ctx.bin} skills update later to get newer versions.`]
21774
21768
  });
21775
21769
  return 0;
21776
21770
  }
21777
21771
  async chooseSkills(ui, options, ctx, lock) {
21778
21772
  if (options.names.length > 0) {
21779
21773
  const names = [...new Set(options.names)];
21780
- ui.step({ title: "Skills", lines: [names.join(", ")] });
21774
+ ui.step({ title: "To install", lines: [names.join(", ")] });
21781
21775
  return names;
21782
21776
  }
21783
21777
  const { api } = this.deps;
21784
21778
  const available = await ui.task(
21785
- "Fetching the list of skills",
21779
+ "Fetching skills",
21786
21780
  (signal) => api.list({ signal }),
21787
21781
  (names) => ({ title: `${plural(names.length, "skill")} available` })
21788
21782
  );
@@ -21805,36 +21799,25 @@ import path8 from "path";
21805
21799
 
21806
21800
  // src/commands/skills/removals.ts
21807
21801
  import path7 from "path";
21808
- async function planRemovals({ files }, lock, names, only) {
21802
+ async function planRemovals(deps, lock, names, only) {
21809
21803
  const removals = [];
21810
21804
  for (const name of names) {
21811
- const { paths, files: expected } = lock.skills[name];
21812
- for (const dir of paths.filter((dir2) => !only || only.has(path7.dirname(dir2)))) {
21813
- const { exists, changed } = await files.compare(dir, expected);
21814
- removals.push({ name, dir, exists, edited: exists && changed.length > 0 });
21805
+ 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 });
21815
21808
  }
21816
21809
  }
21817
21810
  return removals;
21818
21811
  }
21819
- async function applyRemovals({ files, lockfile }, lock, removals) {
21820
- const kept = [];
21821
- for (const removal of removals) {
21822
- const owned = Object.keys(lock.skills[removal.name].files);
21823
- const left = removal.exists ? await files.remove(removal.dir, owned) : [];
21824
- if (left.length > 0) kept.push(`${tildify(removal.dir)} ${plural(left.length, "file")} zion didn't install`);
21825
- await lockfile.update((data) => {
21826
- const entry = data.skills[removal.name];
21827
- if (!entry) return;
21828
- entry.paths = entry.paths.filter((dir) => dir !== removal.dir);
21829
- if (entry.paths.length === 0) delete data.skills[removal.name];
21812
+ async function applyRemovals(deps, names, removals) {
21813
+ for (const removal of removals) await deps.files.remove(removal.dir);
21814
+ for (const name of names) {
21815
+ if ((await installedDirs(deps, name)).length > 0) continue;
21816
+ await deps.lockfile.update((data) => {
21817
+ delete data.skills[name];
21830
21818
  });
21831
21819
  }
21832
- return kept;
21833
- }
21834
- function describeKept(kept, removed) {
21835
- return kept.length > 0 ? { title: "Removed, but kept", tone: "warning", lines: kept } : { title: "Removed", lines: [removed.join(", ")] };
21836
21820
  }
21837
- var KEPT_ADVICE = "Delete what was kept yourself if you no longer need it.";
21838
21821
 
21839
21822
  // src/commands/skills/ManageFlow.ts
21840
21823
  var ManageFlow = class {
@@ -21846,21 +21829,24 @@ var ManageFlow = class {
21846
21829
  const { api, lockfile } = this.deps;
21847
21830
  const lock = await lockfile.read();
21848
21831
  const installed = Object.keys(lock.skills);
21832
+ const where = new Map(
21833
+ await Promise.all(installed.map(async (name) => [name, await installedDirs(this.deps, name)]))
21834
+ );
21849
21835
  const { available, latest } = await ui.task(
21850
21836
  "Fetching skills",
21851
21837
  (signal) => this.fetchCatalog(lock, signal),
21852
21838
  ({ available: available2, latest: latest2 }) => {
21853
21839
  const updates = installed.filter((name) => isNewer(latest2.get(name), lock.skills[name])).length;
21854
21840
  return {
21855
- title: [plural(available2.length, "skill"), updates > 0 && plural(updates, "update")].filter(Boolean).join(" \xB7 ")
21841
+ title: [`${plural(available2.length, "skill")} available`, updates > 0 && plural(updates, "update")].filter(Boolean).join(" \xB7 ")
21856
21842
  };
21857
21843
  }
21858
21844
  );
21859
21845
  const names = [.../* @__PURE__ */ new Set([...available, ...installed])].sort();
21860
21846
  const ticked = new Set(
21861
21847
  await ui.multiselect({
21862
- message: "Your skills",
21863
- options: names.map((name) => ({ value: name, label: name, hint: this.hint(lock, name, latest) })),
21848
+ message: "Skills",
21849
+ options: names.map((name) => ({ value: name, label: name, hint: this.hint(lock, name, latest, where) })),
21864
21850
  initialValues: installed,
21865
21851
  required: false
21866
21852
  })
@@ -21895,20 +21881,20 @@ var ManageFlow = class {
21895
21881
  ...(await Promise.all(updated.map((skill) => planCopies(this.deps, skill, lock.skills[skill.name], [])))).flat()
21896
21882
  ];
21897
21883
  const removals = await planRemovals(this.deps, lock, removing);
21898
- this.summarise(ui, ctx.paint.stderr, lock, { added, updated, removing, copies, removals });
21884
+ this.summarise(ui, ctx.paint.stderr, lock, where, { added, updated, removing, copies, removals });
21899
21885
  const risky = copies.some((copy) => copy.problem) || removals.some((removal) => removal.edited);
21900
21886
  const total = added.length + updated.length + removing.length;
21901
21887
  if (!await ui.confirm({ message: `Apply ${plural(total, "change")}?`, defaultValue: !risky })) {
21902
21888
  ui.outro("Left everything as it was.", { tone: "muted" });
21903
21889
  return 0;
21904
21890
  }
21905
- const kept = await ui.task(
21906
- "Applying",
21891
+ await ui.task(
21892
+ "Applying changes",
21907
21893
  async () => {
21908
21894
  await writeCopies(this.deps, [...added, ...updated], copies);
21909
- return applyRemovals(this.deps, lock, removals);
21895
+ await applyRemovals(this.deps, removing, removals);
21910
21896
  },
21911
- (kept2) => kept2.length > 0 ? { title: "Done, but kept", tone: "warning", lines: kept2 } : { title: "Done" }
21897
+ () => ({ title: "Changes applied" })
21912
21898
  );
21913
21899
  const [first, ...rest] = [
21914
21900
  ["installed", added.length],
@@ -21918,10 +21904,7 @@ var ManageFlow = class {
21918
21904
  const message = [`${first[0]} ${plural(first[1], "skill")}`, ...rest.map(([verb, count]) => `${verb} ${count}`)];
21919
21905
  const sentence = message.join(", ");
21920
21906
  ui.outro(`${sentence[0].toUpperCase()}${sentence.slice(1)}.`, {
21921
- lines: [
21922
- ...added.length + updated.length > 0 ? ["Start a new agent session to use them."] : [],
21923
- ...kept.length > 0 ? [KEPT_ADVICE] : []
21924
- ]
21907
+ lines: added.length + updated.length > 0 ? ["Start a new agent session to use them."] : []
21925
21908
  });
21926
21909
  return 0;
21927
21910
  }
@@ -21942,21 +21925,21 @@ var ManageFlow = class {
21942
21925
  ]);
21943
21926
  return { available, latest: new Map(installed.map((name, i) => [name, versions[i]])) };
21944
21927
  }
21945
- hint(lock, name, latest) {
21928
+ hint(lock, name, latest, dirs) {
21946
21929
  const entry = lock.skills[name];
21947
21930
  if (!entry) return void 0;
21948
- const where = describeDirs(entry.paths);
21931
+ const where = describeDirs(dirs.get(name) ?? []);
21949
21932
  const version3 = latest.get(name);
21950
21933
  if (version3 === null) return `${where} \xB7 no longer available`;
21951
21934
  return isNewer(version3, entry) ? `${where} \xB7 update available` : where;
21952
21935
  }
21953
- summarise(ui, paint, lock, { added, updated, removing, copies, removals }) {
21936
+ summarise(ui, paint, lock, where, { added, updated, removing, copies, removals }) {
21954
21937
  const rows = [
21955
21938
  ...added.map(
21956
21939
  (skill) => [paint.success("+"), skill.name, describeDirs(copiesOf(skill, copies).map((copy) => copy.dir))]
21957
21940
  ),
21958
21941
  ...updated.map((skill) => [paint.accent("\u2191"), skill.name, describeChange(lock.skills[skill.name], skill)]),
21959
- ...removing.map((name) => [paint.error("\u2212"), name, describeDirs(lock.skills[name].paths)])
21942
+ ...removing.map((name) => [paint.error("\u2212"), name, describeDirs(where.get(name) ?? [])])
21960
21943
  ];
21961
21944
  const width = Math.max(...rows.map(([, name]) => name.length));
21962
21945
  ui.step({
@@ -21965,12 +21948,12 @@ var ManageFlow = class {
21965
21948
  });
21966
21949
  const warnings = [
21967
21950
  ...copies.flatMap((copy) => copy.problem ? [[tildify(copy.dir), copy.problem]] : []),
21968
- ...removals.flatMap((removal) => removal.edited ? [[tildify(removal.dir), "has local edits"]] : [])
21951
+ ...removals.flatMap((removal) => removal.edited ? [[tildify(removal.dir), EDITED]] : [])
21969
21952
  ];
21970
21953
  if (warnings.length > 0) {
21971
21954
  const dirWidth = Math.max(...warnings.map(([dir]) => dir.length));
21972
21955
  ui.step({
21973
- title: warnings.length === 1 ? "This would overwrite changes" : "These would overwrite changes",
21956
+ title: `${plural(warnings.length, "folder")} with local changes`,
21974
21957
  tone: "warning",
21975
21958
  lines: warnings.map(([dir, problem]) => `${dir.padEnd(dirWidth)} ${problem}`)
21976
21959
  });
@@ -21995,15 +21978,20 @@ var RemoveFlow = class {
21995
21978
  const names = await this.chooseSkills(ui, options, ctx, installed, lock);
21996
21979
  const only = options.targets.length ? new Set(targets.filter((target) => options.targets.includes(target.id)).map((target) => target.dir)) : null;
21997
21980
  const removals = await planRemovals(this.deps, lock, names, only ?? void 0);
21998
- if (removals.length === 0)
21999
- throw new CliError("They aren't installed there", `run ${ctx.bin} skills list to see where they are`);
21981
+ if (removals.length === 0) {
21982
+ if (only)
21983
+ throw new CliError("Those skills aren't installed there", `run ${ctx.bin} skills list to see where they are`);
21984
+ await applyRemovals(this.deps, names, []);
21985
+ ui.outro(`Stopped tracking ${names.join(", ")}.`, { tone: "muted", lines: ["Their folders were already gone."] });
21986
+ return 0;
21987
+ }
22000
21988
  const width = Math.max(...removals.map((removal) => tildify(removal.dir).length));
22001
21989
  const edited = removals.some((removal) => removal.edited);
22002
21990
  ui.step({
22003
21991
  title: "To remove",
22004
21992
  tone: edited ? "warning" : "success",
22005
21993
  lines: removals.map(
22006
- (removal) => removal.edited ? `${tildify(removal.dir).padEnd(width)} has local edits` : tildify(removal.dir)
21994
+ (removal) => removal.edited ? `${tildify(removal.dir).padEnd(width)} ${EDITED}` : tildify(removal.dir)
22007
21995
  )
22008
21996
  });
22009
21997
  const confirmed = options.yes || await ui.confirm({
@@ -22015,14 +22003,12 @@ var RemoveFlow = class {
22015
22003
  ui.outro("Left everything as it was.", { tone: "muted" });
22016
22004
  return 0;
22017
22005
  }
22018
- const kept = await ui.task(
22006
+ await ui.task(
22019
22007
  "Removing",
22020
- () => applyRemovals(this.deps, lock, removals),
22021
- (kept2) => describeKept(kept2, names)
22008
+ () => applyRemovals(this.deps, names, removals),
22009
+ () => ({ title: "Removed", lines: [names.join(", ")] })
22022
22010
  );
22023
- ui.outro(`Removed ${plural(names.length, "skill")}.`, {
22024
- lines: kept.length > 0 ? [KEPT_ADVICE] : []
22025
- });
22011
+ ui.outro(`Removed ${plural(names.length, "skill")}.`);
22026
22012
  return 0;
22027
22013
  }
22028
22014
  async chooseSkills(ui, options, ctx, installed, lock) {
@@ -22032,12 +22018,13 @@ var RemoveFlow = class {
22032
22018
  if (missing) throw new CliError(`${missing} isn't installed`, `run ${ctx.bin} skills list to see what is`);
22033
22019
  return [...new Set(options.names)];
22034
22020
  }
22021
+ const dirs = await Promise.all(installed.map((name) => installedDirs(this.deps, name)));
22035
22022
  return ui.multiselect({
22036
22023
  message: "Which skills?",
22037
- options: installed.map((name) => ({
22024
+ options: installed.map((name, i) => ({
22038
22025
  value: name,
22039
22026
  label: name,
22040
- hint: describeDirs(lock.skills[name].paths)
22027
+ hint: describeDirs(dirs[i])
22041
22028
  })),
22042
22029
  nonInteractiveHint: `name them, e.g. ${ctx.bin} skills remove ${installed[0]} --yes, or pass --all`
22043
22030
  });
@@ -22051,11 +22038,11 @@ var UpdateFlow = class {
22051
22038
  }
22052
22039
  deps;
22053
22040
  async run(ui, options, ctx) {
22054
- const { api, lockfile } = this.deps;
22041
+ const { lockfile } = this.deps;
22055
22042
  const lock = await lockfile.read();
22056
22043
  const installed = Object.keys(lock.skills).sort();
22057
22044
  if (installed.length === 0) {
22058
- ui.outro("No skills are installed yet.", {
22045
+ ui.outro("No skills are installed.", {
22059
22046
  tone: "muted",
22060
22047
  lines: [`Install some with ${ctx.bin} skills install.`]
22061
22048
  });
@@ -22128,13 +22115,13 @@ function describeChecks(paint, checks, { listUpdates }) {
22128
22115
  const updates = checks.filter(isOutdated);
22129
22116
  const gone = checks.filter((check2) => check2.gone);
22130
22117
  if (updates.length === 0 && gone.length === 0) return { title: "Up to date" };
22131
- const shown = [...listUpdates ? updates : [], ...gone];
22132
- const width = Math.max(0, ...shown.map((check2) => check2.name.length));
22118
+ const shown2 = [...listUpdates ? updates : [], ...gone];
22119
+ const width = Math.max(0, ...shown2.map((check2) => check2.name.length));
22133
22120
  return {
22134
22121
  title: updates.length > 0 ? `${plural(updates.length, "update")} available` : `${plural(gone.length, "skill")} no longer available`,
22135
22122
  tone: gone.length > 0 ? "warning" : "success",
22136
- lines: shown.map(
22137
- (check2) => `${check2.name.padEnd(width)} ${isOutdated(check2) ? paint.muted(describeChange(check2.locked, check2.latest)) : "no longer available, left as is"}`
22123
+ lines: shown2.map(
22124
+ (check2) => `${check2.name.padEnd(width)} ${isOutdated(check2) ? paint.muted(describeChange(check2.locked, check2.latest)) : "no longer available, kept as is"}`
22138
22125
  )
22139
22126
  };
22140
22127
  }
@@ -22142,7 +22129,7 @@ function describeChecks(paint, checks, { listUpdates }) {
22142
22129
  // src/commands/skills/actions.ts
22143
22130
  var SKILLS_ACTIONS = [
22144
22131
  { id: "install", aliases: ["add"], hint: "choose skills and where they go" },
22145
- { id: "update", aliases: ["upgrade"], hint: "get the latest of what you have" },
22132
+ { id: "update", aliases: ["upgrade"], hint: "get newer versions of installed skills" },
22146
22133
  { id: "remove", aliases: ["rm", "uninstall"], hint: "delete skills zion installed" },
22147
22134
  { id: "list", aliases: ["ls"], hint: "print every skill and where it is installed" },
22148
22135
  { id: "show", aliases: [], hint: "print a skill's SKILL.md" }
@@ -22163,6 +22150,8 @@ function parseSkillsOptions(args, bin, targetIds) {
22163
22150
  strict: true,
22164
22151
  options: {
22165
22152
  target: { type: "string", short: "t", multiple: true, default: [] },
22153
+ project: { type: "boolean", short: "p", default: false },
22154
+ global: { type: "boolean", short: "g", default: false },
22166
22155
  all: { type: "boolean", short: "a", default: false },
22167
22156
  yes: { type: "boolean", short: "y", default: false },
22168
22157
  json: { type: "boolean", default: false }
@@ -22186,11 +22175,14 @@ function parseSkillsOptions(args, bin, targetIds) {
22186
22175
  throw new UsageError(`unknown target "${unknown2}"`, `choose one of: ${targetIds.join(", ")}`);
22187
22176
  }
22188
22177
  const targets = given.filter(isTarget);
22178
+ if (values.project && values.global) throw new UsageError("pass --project or --global, not both", usageHint);
22179
+ const scope = values.project ? "project" : values.global ? "global" : void 0;
22189
22180
  const id = action?.id;
22190
22181
  const only = (flag, allowed) => {
22191
22182
  if (!id || !allowed.includes(id)) throw new UsageError(`${flag} works with: ${allowed.join(", ")}`, usageHint);
22192
22183
  };
22193
22184
  if (targets.length > 0) only("--target", ["install", "remove"]);
22185
+ if (scope && id === "show") throw new UsageError("--project and --global don't apply to show", usageHint);
22194
22186
  if (values.all) only("--all", ["install", "remove"]);
22195
22187
  if (values.yes) only("--yes", ["install", "update", "remove"]);
22196
22188
  if (values.json) only("--json", ["list"]);
@@ -22199,23 +22191,26 @@ function parseSkillsOptions(args, bin, targetIds) {
22199
22191
  if (id === "show" && names.length !== 1) {
22200
22192
  throw new UsageError("show takes exactly one skill name", `e.g. ${bin} skills show commit`);
22201
22193
  }
22202
- return { action: id, names, targets, all: values.all, yes: values.yes, json: values.json };
22194
+ return { action: id, names, targets, scope, all: values.all, yes: values.yes, json: values.json };
22203
22195
  }
22204
22196
 
22205
22197
  // src/commands/skills/output.ts
22206
- async function listSkills({ api, lockfile }, ctx, json2) {
22198
+ async function listSkills(deps, ctx, json2) {
22199
+ const { api, lockfile } = deps;
22207
22200
  const lock = await lockfile.read();
22208
22201
  const installed = Object.keys(lock.skills);
22209
22202
  const available = await api.list({ include: installed });
22210
22203
  const names = [.../* @__PURE__ */ new Set([...available, ...installed])].sort();
22211
- const rows = names.map((name) => {
22212
- const entry = lock.skills[name];
22213
- return {
22214
- name,
22215
- available: available.includes(name),
22216
- installed: entry ? { commit: entry.commit, updatedAt: entry.updatedAt, paths: entry.paths } : null
22217
- };
22218
- });
22204
+ const rows = await Promise.all(
22205
+ names.map(async (name) => {
22206
+ const entry = lock.skills[name];
22207
+ return {
22208
+ name,
22209
+ available: available.includes(name),
22210
+ installed: entry ? { commit: entry.commit, paths: await installedDirs(deps, name) } : null
22211
+ };
22212
+ })
22213
+ );
22219
22214
  if (json2) {
22220
22215
  ctx.stdout.write(`${JSON.stringify({ skills: rows }, null, 2)}
22221
22216
  `);
@@ -22250,12 +22245,15 @@ async function showSkill({ api }, ctx, name) {
22250
22245
 
22251
22246
  // src/commands/skills/SkillsCommand.ts
22252
22247
  var SkillsCommand = class {
22253
- constructor(deps) {
22254
- this.deps = deps;
22255
- const { targets, lockfile, api } = deps;
22248
+ constructor(base) {
22249
+ this.base = base;
22250
+ const { scopes, api } = base;
22251
+ const { targets, lockfile } = scopes.global;
22256
22252
  this.help = {
22257
22253
  usage: "[action] [skill...] [options]",
22258
- description: `Downloads skills from ${api.host} into the directories your agents load them from. Without an action, it shows every skill as a checklist: tick to install, untick to remove, and installed skills are updated too. When not in a terminal, it prints the list instead. zion remembers what it installed in ${tildify(lockfile.path)}, and never touches files it didn't write without asking. Targets: ${targets.map((t) => `${t.id} is ${tildify(t.dir)}`).join(", ")}.`,
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)} (./${path9.basename(
22255
+ 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.`,
22259
22257
  arguments: {
22260
22258
  title: "Actions",
22261
22259
  rows: SKILLS_ACTIONS.map((action) => [
@@ -22264,10 +22262,12 @@ var SkillsCommand = class {
22264
22262
  ])
22265
22263
  },
22266
22264
  options: [
22267
- ["-t, --target <name>", `${targets.map((t) => t.id).join(" or ")}; repeat to install into both`],
22268
- ["-a, --all", "every skill, for install and remove"],
22269
- ["-y, --yes", "answer yes to every prompt, including replacing edited copies"],
22270
- ["--json", "print list as JSON"]
22265
+ ["-p, --project", `work in this folder, recorded in ./${path9.basename(scopes.project.lockfile.path)}`],
22266
+ ["-g, --global", "work in your home directory (the default without a terminal)"],
22267
+ ["-t, --target <name>", `${targets.map((t) => t.id).join(" or ")}; repeat for both`],
22268
+ ["-a, --all", "every skill (install and remove)"],
22269
+ ["-y, --yes", "say yes to every confirmation, including replacing edited folders"],
22270
+ ["--json", "print the list as JSON"]
22271
22271
  ],
22272
22272
  examples: [
22273
22273
  "skills",
@@ -22280,7 +22280,7 @@ var SkillsCommand = class {
22280
22280
  ]
22281
22281
  };
22282
22282
  }
22283
- deps;
22283
+ base;
22284
22284
  name = "skills";
22285
22285
  summary = "install my agent skills";
22286
22286
  group = "work";
@@ -22289,36 +22289,52 @@ var SkillsCommand = class {
22289
22289
  const options = parseSkillsOptions(
22290
22290
  args,
22291
22291
  ctx.bin,
22292
- this.deps.targets.map((target) => target.id)
22292
+ this.base.scopes.global.targets.map((target) => target.id)
22293
22293
  );
22294
- if (options.action === "list") return listSkills(this.deps, ctx, options.json);
22295
- if (options.action === "show") return showSkill(this.deps, ctx, options.names[0]);
22294
+ if (options.action === "list") return listSkills(this.depsFor(options.scope ?? "global"), ctx, options.json);
22295
+ if (options.action === "show") return showSkill(this.base, ctx, options.names[0]);
22296
22296
  const given = options.action;
22297
- if (!given && !ctx.interactive) return listSkills(this.deps, ctx, false);
22298
- const ui = this.deps.createPrompter(ctx);
22297
+ if (!given && !ctx.interactive) return listSkills(this.depsFor(options.scope ?? "global"), ctx, false);
22298
+ const ui = this.base.createPrompter(ctx);
22299
22299
  return runSession(ui, async () => {
22300
- ui.intro("skills", this.deps.api.host);
22300
+ ui.intro("skills", this.base.api.host);
22301
+ const scope = options.scope ?? await this.chooseScope(ui);
22302
+ const deps = this.depsFor(scope);
22301
22303
  const flows = { install: InstallFlow, update: UpdateFlow, remove: RemoveFlow };
22302
- return given ? new flows[given](this.deps).run(ui, options, ctx) : new ManageFlow(this.deps).run(ui, ctx);
22304
+ return given ? new flows[given](deps).run(ui, options, ctx) : new ManageFlow(deps).run(ui, ctx);
22305
+ });
22306
+ }
22307
+ depsFor(scope) {
22308
+ return { ...this.base, ...this.base.scopes[scope] };
22309
+ }
22310
+ chooseScope(ui) {
22311
+ const { project, global } = this.base.scopes;
22312
+ return ui.select({
22313
+ message: "Scope",
22314
+ options: [
22315
+ { value: "project", label: "Locally", hint: `tracked in ./${path9.basename(project.lockfile.path)}` },
22316
+ { value: "global", label: "Globally", hint: `tracked in ${tildify(global.lockfile.path)}` }
22317
+ ],
22318
+ initialValue: "global"
22303
22319
  });
22304
22320
  }
22305
22321
  };
22306
22322
 
22307
22323
  // src/commands/skills/targets.ts
22308
- import path9 from "path";
22324
+ import path10 from "path";
22309
22325
  function skillTargets(homedir) {
22310
22326
  return [
22311
22327
  {
22312
22328
  id: "agents",
22313
- dir: path9.join(homedir, ".agents", "skills"),
22314
- home: path9.join(homedir, ".agents"),
22315
- hint: "Copilot and other agents"
22329
+ dir: path10.join(homedir, ".agents", "skills"),
22330
+ home: path10.join(homedir, ".agents"),
22331
+ name: "Universal"
22316
22332
  },
22317
22333
  {
22318
22334
  id: "claude",
22319
- dir: path9.join(homedir, ".claude", "skills"),
22320
- home: path9.join(homedir, ".claude"),
22321
- hint: "Claude Code"
22335
+ dir: path10.join(homedir, ".claude", "skills"),
22336
+ home: path10.join(homedir, ".claude"),
22337
+ name: "Claude Code"
22322
22338
  }
22323
22339
  ];
22324
22340
  }
@@ -22385,28 +22401,23 @@ var CliGit = class {
22385
22401
 
22386
22402
  // src/services/Lockfile.ts
22387
22403
  import fs3 from "fs/promises";
22388
- import path10 from "path";
22389
- var VERSION = 1;
22404
+ import path11 from "path";
22405
+ var VERSION = 2;
22390
22406
  var LockedSkill = external_exports.looseObject({
22391
22407
  /** The last commit in zion-off/skills that changed this skill. */
22392
22408
  commit: external_exports.string(),
22393
- /** When that commit was made. */
22394
- updatedAt: external_exports.string(),
22395
- installedAt: external_exports.string(),
22396
- /** Every directory this skill was installed into. */
22397
- paths: external_exports.array(external_exports.string()),
22398
- /** Git blob hash of each installed file, keyed by its path inside the skill, to spot local edits. */
22399
- files: external_exports.record(external_exports.string(), external_exports.string())
22409
+ /** Git tree hash of the skill as installed, to spot local edits. */
22410
+ tree: external_exports.string()
22400
22411
  });
22401
22412
  var LockData = external_exports.looseObject({
22402
22413
  version: external_exports.literal(VERSION),
22403
22414
  /** Installed skills by name. */
22404
- skills: external_exports.record(external_exports.string(), LockedSkill).default({})
22415
+ skills: external_exports.record(external_exports.string().regex(SKILL_NAME), LockedSkill).default({})
22405
22416
  });
22406
22417
  var Versioned = jsonText(external_exports.looseObject({ version: external_exports.number() }));
22407
22418
  var JsonLockfile = class {
22408
- constructor(path13) {
22409
- this.path = path13;
22419
+ constructor(path14) {
22420
+ this.path = path14;
22410
22421
  }
22411
22422
  path;
22412
22423
  async read() {
@@ -22438,7 +22449,7 @@ var JsonLockfile = class {
22438
22449
  return data.data;
22439
22450
  }
22440
22451
  async write(data) {
22441
- await fs3.mkdir(path10.dirname(this.path), { recursive: true });
22452
+ await fs3.mkdir(path11.dirname(this.path), { recursive: true });
22442
22453
  const temporary = `${this.path}.${process.pid}.tmp`;
22443
22454
  try {
22444
22455
  await fs3.writeFile(temporary, JSON.stringify(data, null, 2) + "\n");
@@ -22455,10 +22466,10 @@ var JsonLockfile = class {
22455
22466
  );
22456
22467
  }
22457
22468
  };
22458
- function describeIssue({ path: path13, code }) {
22459
- if (path13.length === 0) return code === "custom" ? "it is not valid JSON" : "it is not an object";
22460
- if (path13[0] === "version") return `its version isn't ${VERSION}`;
22461
- return `"${path13.join(".")}" is not valid`;
22469
+ function describeIssue({ path: path14, code }) {
22470
+ if (path14.length === 0) return code === "custom" ? "it is not valid JSON" : "it is not an object";
22471
+ if (path14[0] === "version") return `its version isn't ${VERSION}`;
22472
+ return `"${path14.join(".")}" is not valid`;
22462
22473
  }
22463
22474
 
22464
22475
  // src/services/ProcessRunner.ts
@@ -22509,10 +22520,10 @@ var NodeProcessRunner = class {
22509
22520
 
22510
22521
  // src/services/xdg.ts
22511
22522
  import os2 from "os";
22512
- import path11 from "path";
22523
+ import path12 from "path";
22513
22524
  function stateHome(env) {
22514
22525
  const base = env.XDG_STATE_HOME;
22515
- return base && path11.isAbsolute(base) ? base : path11.join(os2.homedir(), ".local", "state");
22526
+ return base && path12.isAbsolute(base) ? base : path12.join(os2.homedir(), ".local", "state");
22516
22527
  }
22517
22528
 
22518
22529
  // src/cli.tsx
@@ -22530,7 +22541,7 @@ var registry2 = new CommandRegistry().register(
22530
22541
  slug: "zion-off/dotfiles",
22531
22542
  url: "https://github.com/zion-off/dotfiles.git",
22532
22543
  installer: "bin/dot",
22533
- installerLink: path12.join(os3.homedir(), ".local", "bin", "dot")
22544
+ installerLink: path13.join(os3.homedir(), ".local", "bin", "dot")
22534
22545
  }),
22535
22546
  git,
22536
22547
  runner,
@@ -22543,10 +22554,17 @@ var registry2 = new CommandRegistry().register(
22543
22554
  new SkillsCommand({
22544
22555
  api: new HttpSkillsApi(process.env.ZION_SKILLS_URL || "https://zzzzion.com/api/skills"),
22545
22556
  files: new NodeSkillFiles(),
22546
- lockfile: new JsonLockfile(path12.join(stateHome(process.env), "zion.json")),
22547
- targets: skillTargets(os3.homedir()),
22548
- createPrompter,
22549
- now: () => /* @__PURE__ */ new Date()
22557
+ scopes: {
22558
+ global: {
22559
+ lockfile: new JsonLockfile(path13.join(stateHome(process.env), "zion.json")),
22560
+ targets: skillTargets(os3.homedir())
22561
+ },
22562
+ project: {
22563
+ lockfile: new JsonLockfile(path13.join(process.cwd(), "zion.json")),
22564
+ targets: skillTargets(process.cwd())
22565
+ }
22566
+ },
22567
+ createPrompter
22550
22568
  })
22551
22569
  ).register(new TuiCommand()).register(new CardCommand()).register(
22552
22570
  new NowCommand({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zion",
3
- "version": "4.1.2",
3
+ "version": "4.2.1",
4
4
  "description": "my site, dotfiles, agent skills and more, in your terminal",
5
5
  "license": "MIT",
6
6
  "repository": {