zion 4.1.2 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +281 -267
  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.0";
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,36 @@ 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) => tildify(target.dir)).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: tildify(target.dir), hint: target.hint })),
21702
+ initialValues: suggested,
21703
+ nonInteractiveHint: `pass --target (${targets.map((target) => target.id).join(", ")}), e.g. -t ${targets[0].id}`
21704
+ });
21715
21705
  }
21716
21706
 
21717
21707
  // src/commands/skills/InstallFlow.ts
@@ -21770,19 +21760,19 @@ var InstallFlow = class {
21770
21760
  () => describeCopies(ctx.paint.stderr, "Installed", skills, copies)
21771
21761
  );
21772
21762
  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.`]
21763
+ lines: ["Start a new agent session to use them.", `Run ${ctx.bin} skills update later to get newer versions.`]
21774
21764
  });
21775
21765
  return 0;
21776
21766
  }
21777
21767
  async chooseSkills(ui, options, ctx, lock) {
21778
21768
  if (options.names.length > 0) {
21779
21769
  const names = [...new Set(options.names)];
21780
- ui.step({ title: "Skills", lines: [names.join(", ")] });
21770
+ ui.step({ title: "To install", lines: [names.join(", ")] });
21781
21771
  return names;
21782
21772
  }
21783
21773
  const { api } = this.deps;
21784
21774
  const available = await ui.task(
21785
- "Fetching the list of skills",
21775
+ "Fetching skills",
21786
21776
  (signal) => api.list({ signal }),
21787
21777
  (names) => ({ title: `${plural(names.length, "skill")} available` })
21788
21778
  );
@@ -21805,36 +21795,25 @@ import path8 from "path";
21805
21795
 
21806
21796
  // src/commands/skills/removals.ts
21807
21797
  import path7 from "path";
21808
- async function planRemovals({ files }, lock, names, only) {
21798
+ async function planRemovals(deps, lock, names, only) {
21809
21799
  const removals = [];
21810
21800
  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 });
21801
+ for (const dir of await installedDirs(deps, name)) {
21802
+ if (only && !only.has(path7.dirname(dir))) continue;
21803
+ removals.push({ name, dir, edited: await deps.files.treeSha(dir) !== lock.skills[name].tree });
21815
21804
  }
21816
21805
  }
21817
21806
  return removals;
21818
21807
  }
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];
21808
+ async function applyRemovals(deps, names, removals) {
21809
+ for (const removal of removals) await deps.files.remove(removal.dir);
21810
+ for (const name of names) {
21811
+ if ((await installedDirs(deps, name)).length > 0) continue;
21812
+ await deps.lockfile.update((data) => {
21813
+ delete data.skills[name];
21830
21814
  });
21831
21815
  }
21832
- return kept;
21833
21816
  }
21834
- function describeKept(kept, removed) {
21835
- return kept.length > 0 ? { title: "Removed, but kept", tone: "warning", lines: kept } : { title: "Removed", lines: [removed.join(", ")] };
21836
- }
21837
- var KEPT_ADVICE = "Delete what was kept yourself if you no longer need it.";
21838
21817
 
21839
21818
  // src/commands/skills/ManageFlow.ts
21840
21819
  var ManageFlow = class {
@@ -21846,21 +21825,24 @@ var ManageFlow = class {
21846
21825
  const { api, lockfile } = this.deps;
21847
21826
  const lock = await lockfile.read();
21848
21827
  const installed = Object.keys(lock.skills);
21828
+ const where = new Map(
21829
+ await Promise.all(installed.map(async (name) => [name, await installedDirs(this.deps, name)]))
21830
+ );
21849
21831
  const { available, latest } = await ui.task(
21850
21832
  "Fetching skills",
21851
21833
  (signal) => this.fetchCatalog(lock, signal),
21852
21834
  ({ available: available2, latest: latest2 }) => {
21853
21835
  const updates = installed.filter((name) => isNewer(latest2.get(name), lock.skills[name])).length;
21854
21836
  return {
21855
- title: [plural(available2.length, "skill"), updates > 0 && plural(updates, "update")].filter(Boolean).join(" \xB7 ")
21837
+ title: [`${plural(available2.length, "skill")} available`, updates > 0 && plural(updates, "update")].filter(Boolean).join(" \xB7 ")
21856
21838
  };
21857
21839
  }
21858
21840
  );
21859
21841
  const names = [.../* @__PURE__ */ new Set([...available, ...installed])].sort();
21860
21842
  const ticked = new Set(
21861
21843
  await ui.multiselect({
21862
- message: "Your skills",
21863
- options: names.map((name) => ({ value: name, label: name, hint: this.hint(lock, name, latest) })),
21844
+ message: "Skills",
21845
+ options: names.map((name) => ({ value: name, label: name, hint: this.hint(lock, name, latest, where) })),
21864
21846
  initialValues: installed,
21865
21847
  required: false
21866
21848
  })
@@ -21895,20 +21877,20 @@ var ManageFlow = class {
21895
21877
  ...(await Promise.all(updated.map((skill) => planCopies(this.deps, skill, lock.skills[skill.name], [])))).flat()
21896
21878
  ];
21897
21879
  const removals = await planRemovals(this.deps, lock, removing);
21898
- this.summarise(ui, ctx.paint.stderr, lock, { added, updated, removing, copies, removals });
21880
+ this.summarise(ui, ctx.paint.stderr, lock, where, { added, updated, removing, copies, removals });
21899
21881
  const risky = copies.some((copy) => copy.problem) || removals.some((removal) => removal.edited);
21900
21882
  const total = added.length + updated.length + removing.length;
21901
21883
  if (!await ui.confirm({ message: `Apply ${plural(total, "change")}?`, defaultValue: !risky })) {
21902
21884
  ui.outro("Left everything as it was.", { tone: "muted" });
21903
21885
  return 0;
21904
21886
  }
21905
- const kept = await ui.task(
21906
- "Applying",
21887
+ await ui.task(
21888
+ "Applying changes",
21907
21889
  async () => {
21908
21890
  await writeCopies(this.deps, [...added, ...updated], copies);
21909
- return applyRemovals(this.deps, lock, removals);
21891
+ await applyRemovals(this.deps, removing, removals);
21910
21892
  },
21911
- (kept2) => kept2.length > 0 ? { title: "Done, but kept", tone: "warning", lines: kept2 } : { title: "Done" }
21893
+ () => ({ title: "Changes applied" })
21912
21894
  );
21913
21895
  const [first, ...rest] = [
21914
21896
  ["installed", added.length],
@@ -21918,10 +21900,7 @@ var ManageFlow = class {
21918
21900
  const message = [`${first[0]} ${plural(first[1], "skill")}`, ...rest.map(([verb, count]) => `${verb} ${count}`)];
21919
21901
  const sentence = message.join(", ");
21920
21902
  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
- ]
21903
+ lines: added.length + updated.length > 0 ? ["Start a new agent session to use them."] : []
21925
21904
  });
21926
21905
  return 0;
21927
21906
  }
@@ -21942,21 +21921,21 @@ var ManageFlow = class {
21942
21921
  ]);
21943
21922
  return { available, latest: new Map(installed.map((name, i) => [name, versions[i]])) };
21944
21923
  }
21945
- hint(lock, name, latest) {
21924
+ hint(lock, name, latest, dirs) {
21946
21925
  const entry = lock.skills[name];
21947
21926
  if (!entry) return void 0;
21948
- const where = describeDirs(entry.paths);
21927
+ const where = describeDirs(dirs.get(name) ?? []);
21949
21928
  const version3 = latest.get(name);
21950
21929
  if (version3 === null) return `${where} \xB7 no longer available`;
21951
21930
  return isNewer(version3, entry) ? `${where} \xB7 update available` : where;
21952
21931
  }
21953
- summarise(ui, paint, lock, { added, updated, removing, copies, removals }) {
21932
+ summarise(ui, paint, lock, where, { added, updated, removing, copies, removals }) {
21954
21933
  const rows = [
21955
21934
  ...added.map(
21956
21935
  (skill) => [paint.success("+"), skill.name, describeDirs(copiesOf(skill, copies).map((copy) => copy.dir))]
21957
21936
  ),
21958
21937
  ...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)])
21938
+ ...removing.map((name) => [paint.error("\u2212"), name, describeDirs(where.get(name) ?? [])])
21960
21939
  ];
21961
21940
  const width = Math.max(...rows.map(([, name]) => name.length));
21962
21941
  ui.step({
@@ -21965,12 +21944,12 @@ var ManageFlow = class {
21965
21944
  });
21966
21945
  const warnings = [
21967
21946
  ...copies.flatMap((copy) => copy.problem ? [[tildify(copy.dir), copy.problem]] : []),
21968
- ...removals.flatMap((removal) => removal.edited ? [[tildify(removal.dir), "has local edits"]] : [])
21947
+ ...removals.flatMap((removal) => removal.edited ? [[tildify(removal.dir), EDITED]] : [])
21969
21948
  ];
21970
21949
  if (warnings.length > 0) {
21971
21950
  const dirWidth = Math.max(...warnings.map(([dir]) => dir.length));
21972
21951
  ui.step({
21973
- title: warnings.length === 1 ? "This would overwrite changes" : "These would overwrite changes",
21952
+ title: `${plural(warnings.length, "folder")} with local changes`,
21974
21953
  tone: "warning",
21975
21954
  lines: warnings.map(([dir, problem]) => `${dir.padEnd(dirWidth)} ${problem}`)
21976
21955
  });
@@ -21995,15 +21974,20 @@ var RemoveFlow = class {
21995
21974
  const names = await this.chooseSkills(ui, options, ctx, installed, lock);
21996
21975
  const only = options.targets.length ? new Set(targets.filter((target) => options.targets.includes(target.id)).map((target) => target.dir)) : null;
21997
21976
  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`);
21977
+ if (removals.length === 0) {
21978
+ if (only)
21979
+ throw new CliError("Those skills aren't installed there", `run ${ctx.bin} skills list to see where they are`);
21980
+ await applyRemovals(this.deps, names, []);
21981
+ ui.outro(`Stopped tracking ${names.join(", ")}.`, { tone: "muted", lines: ["Their folders were already gone."] });
21982
+ return 0;
21983
+ }
22000
21984
  const width = Math.max(...removals.map((removal) => tildify(removal.dir).length));
22001
21985
  const edited = removals.some((removal) => removal.edited);
22002
21986
  ui.step({
22003
21987
  title: "To remove",
22004
21988
  tone: edited ? "warning" : "success",
22005
21989
  lines: removals.map(
22006
- (removal) => removal.edited ? `${tildify(removal.dir).padEnd(width)} has local edits` : tildify(removal.dir)
21990
+ (removal) => removal.edited ? `${tildify(removal.dir).padEnd(width)} ${EDITED}` : tildify(removal.dir)
22007
21991
  )
22008
21992
  });
22009
21993
  const confirmed = options.yes || await ui.confirm({
@@ -22015,14 +21999,12 @@ var RemoveFlow = class {
22015
21999
  ui.outro("Left everything as it was.", { tone: "muted" });
22016
22000
  return 0;
22017
22001
  }
22018
- const kept = await ui.task(
22002
+ await ui.task(
22019
22003
  "Removing",
22020
- () => applyRemovals(this.deps, lock, removals),
22021
- (kept2) => describeKept(kept2, names)
22004
+ () => applyRemovals(this.deps, names, removals),
22005
+ () => ({ title: "Removed", lines: [names.join(", ")] })
22022
22006
  );
22023
- ui.outro(`Removed ${plural(names.length, "skill")}.`, {
22024
- lines: kept.length > 0 ? [KEPT_ADVICE] : []
22025
- });
22007
+ ui.outro(`Removed ${plural(names.length, "skill")}.`);
22026
22008
  return 0;
22027
22009
  }
22028
22010
  async chooseSkills(ui, options, ctx, installed, lock) {
@@ -22032,12 +22014,13 @@ var RemoveFlow = class {
22032
22014
  if (missing) throw new CliError(`${missing} isn't installed`, `run ${ctx.bin} skills list to see what is`);
22033
22015
  return [...new Set(options.names)];
22034
22016
  }
22017
+ const dirs = await Promise.all(installed.map((name) => installedDirs(this.deps, name)));
22035
22018
  return ui.multiselect({
22036
22019
  message: "Which skills?",
22037
- options: installed.map((name) => ({
22020
+ options: installed.map((name, i) => ({
22038
22021
  value: name,
22039
22022
  label: name,
22040
- hint: describeDirs(lock.skills[name].paths)
22023
+ hint: describeDirs(dirs[i])
22041
22024
  })),
22042
22025
  nonInteractiveHint: `name them, e.g. ${ctx.bin} skills remove ${installed[0]} --yes, or pass --all`
22043
22026
  });
@@ -22051,11 +22034,11 @@ var UpdateFlow = class {
22051
22034
  }
22052
22035
  deps;
22053
22036
  async run(ui, options, ctx) {
22054
- const { api, lockfile } = this.deps;
22037
+ const { lockfile } = this.deps;
22055
22038
  const lock = await lockfile.read();
22056
22039
  const installed = Object.keys(lock.skills).sort();
22057
22040
  if (installed.length === 0) {
22058
- ui.outro("No skills are installed yet.", {
22041
+ ui.outro("No skills are installed.", {
22059
22042
  tone: "muted",
22060
22043
  lines: [`Install some with ${ctx.bin} skills install.`]
22061
22044
  });
@@ -22134,7 +22117,7 @@ function describeChecks(paint, checks, { listUpdates }) {
22134
22117
  title: updates.length > 0 ? `${plural(updates.length, "update")} available` : `${plural(gone.length, "skill")} no longer available`,
22135
22118
  tone: gone.length > 0 ? "warning" : "success",
22136
22119
  lines: shown.map(
22137
- (check2) => `${check2.name.padEnd(width)} ${isOutdated(check2) ? paint.muted(describeChange(check2.locked, check2.latest)) : "no longer available, left as is"}`
22120
+ (check2) => `${check2.name.padEnd(width)} ${isOutdated(check2) ? paint.muted(describeChange(check2.locked, check2.latest)) : "no longer available, kept as is"}`
22138
22121
  )
22139
22122
  };
22140
22123
  }
@@ -22142,7 +22125,7 @@ function describeChecks(paint, checks, { listUpdates }) {
22142
22125
  // src/commands/skills/actions.ts
22143
22126
  var SKILLS_ACTIONS = [
22144
22127
  { id: "install", aliases: ["add"], hint: "choose skills and where they go" },
22145
- { id: "update", aliases: ["upgrade"], hint: "get the latest of what you have" },
22128
+ { id: "update", aliases: ["upgrade"], hint: "get newer versions of installed skills" },
22146
22129
  { id: "remove", aliases: ["rm", "uninstall"], hint: "delete skills zion installed" },
22147
22130
  { id: "list", aliases: ["ls"], hint: "print every skill and where it is installed" },
22148
22131
  { id: "show", aliases: [], hint: "print a skill's SKILL.md" }
@@ -22163,6 +22146,8 @@ function parseSkillsOptions(args, bin, targetIds) {
22163
22146
  strict: true,
22164
22147
  options: {
22165
22148
  target: { type: "string", short: "t", multiple: true, default: [] },
22149
+ project: { type: "boolean", short: "p", default: false },
22150
+ global: { type: "boolean", short: "g", default: false },
22166
22151
  all: { type: "boolean", short: "a", default: false },
22167
22152
  yes: { type: "boolean", short: "y", default: false },
22168
22153
  json: { type: "boolean", default: false }
@@ -22186,11 +22171,14 @@ function parseSkillsOptions(args, bin, targetIds) {
22186
22171
  throw new UsageError(`unknown target "${unknown2}"`, `choose one of: ${targetIds.join(", ")}`);
22187
22172
  }
22188
22173
  const targets = given.filter(isTarget);
22174
+ if (values.project && values.global) throw new UsageError("pass --project or --global, not both", usageHint);
22175
+ const scope = values.project ? "project" : values.global ? "global" : void 0;
22189
22176
  const id = action?.id;
22190
22177
  const only = (flag, allowed) => {
22191
22178
  if (!id || !allowed.includes(id)) throw new UsageError(`${flag} works with: ${allowed.join(", ")}`, usageHint);
22192
22179
  };
22193
22180
  if (targets.length > 0) only("--target", ["install", "remove"]);
22181
+ if (scope && id === "show") throw new UsageError("--project and --global don't apply to show", usageHint);
22194
22182
  if (values.all) only("--all", ["install", "remove"]);
22195
22183
  if (values.yes) only("--yes", ["install", "update", "remove"]);
22196
22184
  if (values.json) only("--json", ["list"]);
@@ -22199,23 +22187,26 @@ function parseSkillsOptions(args, bin, targetIds) {
22199
22187
  if (id === "show" && names.length !== 1) {
22200
22188
  throw new UsageError("show takes exactly one skill name", `e.g. ${bin} skills show commit`);
22201
22189
  }
22202
- return { action: id, names, targets, all: values.all, yes: values.yes, json: values.json };
22190
+ return { action: id, names, targets, scope, all: values.all, yes: values.yes, json: values.json };
22203
22191
  }
22204
22192
 
22205
22193
  // src/commands/skills/output.ts
22206
- async function listSkills({ api, lockfile }, ctx, json2) {
22194
+ async function listSkills(deps, ctx, json2) {
22195
+ const { api, lockfile } = deps;
22207
22196
  const lock = await lockfile.read();
22208
22197
  const installed = Object.keys(lock.skills);
22209
22198
  const available = await api.list({ include: installed });
22210
22199
  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
- });
22200
+ const rows = await Promise.all(
22201
+ names.map(async (name) => {
22202
+ const entry = lock.skills[name];
22203
+ return {
22204
+ name,
22205
+ available: available.includes(name),
22206
+ installed: entry ? { commit: entry.commit, paths: await installedDirs(deps, name) } : null
22207
+ };
22208
+ })
22209
+ );
22219
22210
  if (json2) {
22220
22211
  ctx.stdout.write(`${JSON.stringify({ skills: rows }, null, 2)}
22221
22212
  `);
@@ -22250,12 +22241,15 @@ async function showSkill({ api }, ctx, name) {
22250
22241
 
22251
22242
  // src/commands/skills/SkillsCommand.ts
22252
22243
  var SkillsCommand = class {
22253
- constructor(deps) {
22254
- this.deps = deps;
22255
- const { targets, lockfile, api } = deps;
22244
+ constructor(base) {
22245
+ this.base = base;
22246
+ const { scopes, api } = base;
22247
+ const { targets, lockfile } = scopes.global;
22256
22248
  this.help = {
22257
22249
  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(", ")}.`,
22250
+ 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(
22251
+ scopes.project.lockfile.path
22252
+ )} 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
22253
  arguments: {
22260
22254
  title: "Actions",
22261
22255
  rows: SKILLS_ACTIONS.map((action) => [
@@ -22264,10 +22258,12 @@ var SkillsCommand = class {
22264
22258
  ])
22265
22259
  },
22266
22260
  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"]
22261
+ ["-p, --project", `work in this folder, recorded in ./${path9.basename(scopes.project.lockfile.path)}`],
22262
+ ["-g, --global", "work in your home directory (the default without a terminal)"],
22263
+ ["-t, --target <name>", `${targets.map((t) => t.id).join(" or ")}; repeat for both`],
22264
+ ["-a, --all", "every skill (install and remove)"],
22265
+ ["-y, --yes", "say yes to every confirmation, including replacing edited folders"],
22266
+ ["--json", "print the list as JSON"]
22271
22267
  ],
22272
22268
  examples: [
22273
22269
  "skills",
@@ -22280,7 +22276,7 @@ var SkillsCommand = class {
22280
22276
  ]
22281
22277
  };
22282
22278
  }
22283
- deps;
22279
+ base;
22284
22280
  name = "skills";
22285
22281
  summary = "install my agent skills";
22286
22282
  group = "work";
@@ -22289,35 +22285,51 @@ var SkillsCommand = class {
22289
22285
  const options = parseSkillsOptions(
22290
22286
  args,
22291
22287
  ctx.bin,
22292
- this.deps.targets.map((target) => target.id)
22288
+ this.base.scopes.global.targets.map((target) => target.id)
22293
22289
  );
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]);
22290
+ if (options.action === "list") return listSkills(this.depsFor(options.scope ?? "global"), ctx, options.json);
22291
+ if (options.action === "show") return showSkill(this.base, ctx, options.names[0]);
22296
22292
  const given = options.action;
22297
- if (!given && !ctx.interactive) return listSkills(this.deps, ctx, false);
22298
- const ui = this.deps.createPrompter(ctx);
22293
+ if (!given && !ctx.interactive) return listSkills(this.depsFor(options.scope ?? "global"), ctx, false);
22294
+ const ui = this.base.createPrompter(ctx);
22299
22295
  return runSession(ui, async () => {
22300
- ui.intro("skills", this.deps.api.host);
22296
+ ui.intro("skills", this.base.api.host);
22297
+ const scope = options.scope ?? await this.chooseScope(ui);
22298
+ const deps = this.depsFor(scope);
22301
22299
  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);
22300
+ return given ? new flows[given](deps).run(ui, options, ctx) : new ManageFlow(deps).run(ui, ctx);
22301
+ });
22302
+ }
22303
+ depsFor(scope) {
22304
+ return { ...this.base, ...this.base.scopes[scope] };
22305
+ }
22306
+ chooseScope(ui) {
22307
+ const { project, global } = this.base.scopes;
22308
+ return ui.select({
22309
+ message: "Scope",
22310
+ options: [
22311
+ { value: "project", label: "Locally", hint: `tracked in ./${path9.basename(project.lockfile.path)}` },
22312
+ { value: "global", label: "Globally", hint: `tracked in ${tildify(global.lockfile.path)}` }
22313
+ ],
22314
+ initialValue: "global"
22303
22315
  });
22304
22316
  }
22305
22317
  };
22306
22318
 
22307
22319
  // src/commands/skills/targets.ts
22308
- import path9 from "path";
22320
+ import path10 from "path";
22309
22321
  function skillTargets(homedir) {
22310
22322
  return [
22311
22323
  {
22312
22324
  id: "agents",
22313
- dir: path9.join(homedir, ".agents", "skills"),
22314
- home: path9.join(homedir, ".agents"),
22325
+ dir: path10.join(homedir, ".agents", "skills"),
22326
+ home: path10.join(homedir, ".agents"),
22315
22327
  hint: "Copilot and other agents"
22316
22328
  },
22317
22329
  {
22318
22330
  id: "claude",
22319
- dir: path9.join(homedir, ".claude", "skills"),
22320
- home: path9.join(homedir, ".claude"),
22331
+ dir: path10.join(homedir, ".claude", "skills"),
22332
+ home: path10.join(homedir, ".claude"),
22321
22333
  hint: "Claude Code"
22322
22334
  }
22323
22335
  ];
@@ -22385,28 +22397,23 @@ var CliGit = class {
22385
22397
 
22386
22398
  // src/services/Lockfile.ts
22387
22399
  import fs3 from "fs/promises";
22388
- import path10 from "path";
22389
- var VERSION = 1;
22400
+ import path11 from "path";
22401
+ var VERSION = 2;
22390
22402
  var LockedSkill = external_exports.looseObject({
22391
22403
  /** The last commit in zion-off/skills that changed this skill. */
22392
22404
  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())
22405
+ /** Git tree hash of the skill as installed, to spot local edits. */
22406
+ tree: external_exports.string()
22400
22407
  });
22401
22408
  var LockData = external_exports.looseObject({
22402
22409
  version: external_exports.literal(VERSION),
22403
22410
  /** Installed skills by name. */
22404
- skills: external_exports.record(external_exports.string(), LockedSkill).default({})
22411
+ skills: external_exports.record(external_exports.string().regex(SKILL_NAME), LockedSkill).default({})
22405
22412
  });
22406
22413
  var Versioned = jsonText(external_exports.looseObject({ version: external_exports.number() }));
22407
22414
  var JsonLockfile = class {
22408
- constructor(path13) {
22409
- this.path = path13;
22415
+ constructor(path14) {
22416
+ this.path = path14;
22410
22417
  }
22411
22418
  path;
22412
22419
  async read() {
@@ -22438,7 +22445,7 @@ var JsonLockfile = class {
22438
22445
  return data.data;
22439
22446
  }
22440
22447
  async write(data) {
22441
- await fs3.mkdir(path10.dirname(this.path), { recursive: true });
22448
+ await fs3.mkdir(path11.dirname(this.path), { recursive: true });
22442
22449
  const temporary = `${this.path}.${process.pid}.tmp`;
22443
22450
  try {
22444
22451
  await fs3.writeFile(temporary, JSON.stringify(data, null, 2) + "\n");
@@ -22455,10 +22462,10 @@ var JsonLockfile = class {
22455
22462
  );
22456
22463
  }
22457
22464
  };
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`;
22465
+ function describeIssue({ path: path14, code }) {
22466
+ if (path14.length === 0) return code === "custom" ? "it is not valid JSON" : "it is not an object";
22467
+ if (path14[0] === "version") return `its version isn't ${VERSION}`;
22468
+ return `"${path14.join(".")}" is not valid`;
22462
22469
  }
22463
22470
 
22464
22471
  // src/services/ProcessRunner.ts
@@ -22509,10 +22516,10 @@ var NodeProcessRunner = class {
22509
22516
 
22510
22517
  // src/services/xdg.ts
22511
22518
  import os2 from "os";
22512
- import path11 from "path";
22519
+ import path12 from "path";
22513
22520
  function stateHome(env) {
22514
22521
  const base = env.XDG_STATE_HOME;
22515
- return base && path11.isAbsolute(base) ? base : path11.join(os2.homedir(), ".local", "state");
22522
+ return base && path12.isAbsolute(base) ? base : path12.join(os2.homedir(), ".local", "state");
22516
22523
  }
22517
22524
 
22518
22525
  // src/cli.tsx
@@ -22530,7 +22537,7 @@ var registry2 = new CommandRegistry().register(
22530
22537
  slug: "zion-off/dotfiles",
22531
22538
  url: "https://github.com/zion-off/dotfiles.git",
22532
22539
  installer: "bin/dot",
22533
- installerLink: path12.join(os3.homedir(), ".local", "bin", "dot")
22540
+ installerLink: path13.join(os3.homedir(), ".local", "bin", "dot")
22534
22541
  }),
22535
22542
  git,
22536
22543
  runner,
@@ -22543,10 +22550,17 @@ var registry2 = new CommandRegistry().register(
22543
22550
  new SkillsCommand({
22544
22551
  api: new HttpSkillsApi(process.env.ZION_SKILLS_URL || "https://zzzzion.com/api/skills"),
22545
22552
  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()
22553
+ scopes: {
22554
+ global: {
22555
+ lockfile: new JsonLockfile(path13.join(stateHome(process.env), "zion.json")),
22556
+ targets: skillTargets(os3.homedir())
22557
+ },
22558
+ project: {
22559
+ lockfile: new JsonLockfile(path13.join(process.cwd(), "zion.json")),
22560
+ targets: skillTargets(process.cwd())
22561
+ }
22562
+ },
22563
+ createPrompter
22550
22564
  })
22551
22565
  ).register(new TuiCommand()).register(new CardCommand()).register(
22552
22566
  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.0",
4
4
  "description": "my site, dotfiles, agent skills and more, in your terminal",
5
5
  "license": "MIT",
6
6
  "repository": {