@zinn-dev/cli 0.45.0 → 0.46.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 (59) hide show
  1. package/README.md +1 -1
  2. package/package.json +3 -3
  3. package/skills/zinn/SKILL.md +2 -2
  4. package/src/actor.d.ts +1 -1
  5. package/src/actor.js +4 -1
  6. package/src/capabilities-schema.d.ts +4 -0
  7. package/src/errors.d.ts +4 -0
  8. package/src/errors.js +18 -5
  9. package/src/lib.d.ts +2 -1
  10. package/src/lib.js +52 -20
  11. package/src/presentation/activity-presentation.js +2 -0
  12. package/src/presentation/doctor-presentation.d.ts +7 -1
  13. package/src/presentation/doctor-presentation.js +6 -2
  14. package/src/presentation/skill-status-presentation.d.ts +9 -0
  15. package/src/presentation/skill-status-presentation.js +43 -0
  16. package/src/presentation/task-blame-presentation.d.ts +1 -0
  17. package/src/presentation/task-blame-presentation.js +3 -1
  18. package/src/presentation/task-presentation.d.ts +16 -4
  19. package/src/presentation/task-presentation.js +60 -33
  20. package/src/result-schemas.d.ts +137 -0
  21. package/src/result-schemas.js +51 -0
  22. package/src/routes/activity-router.d.ts +4 -2
  23. package/src/routes/activity-router.js +44 -17
  24. package/src/routes/backup-router.d.ts +1 -0
  25. package/src/routes/backup-router.js +4 -3
  26. package/src/routes/capabilities-router.d.ts +1 -0
  27. package/src/routes/capabilities-router.js +1 -1
  28. package/src/routes/comment-router.d.ts +5 -0
  29. package/src/routes/comment-router.js +5 -5
  30. package/src/routes/doctor-router.d.ts +1 -0
  31. package/src/routes/doctor-router.js +33 -53
  32. package/src/routes/info-router.d.ts +1 -0
  33. package/src/routes/info-router.js +1 -1
  34. package/src/routes/label-router.d.ts +5 -0
  35. package/src/routes/label-router.js +5 -5
  36. package/src/routes/migrate-router.d.ts +1 -0
  37. package/src/routes/migrate-router.js +5 -7
  38. package/src/routes/project-router.d.ts +10 -0
  39. package/src/routes/project-router.js +31 -24
  40. package/src/routes/reindex-router.d.ts +1 -0
  41. package/src/routes/reindex-router.js +1 -1
  42. package/src/routes/relation-router.d.ts +3 -0
  43. package/src/routes/relation-router.js +9 -6
  44. package/src/routes/restore-router.d.ts +1 -0
  45. package/src/routes/restore-router.js +3 -4
  46. package/src/routes/router.js +2 -2
  47. package/src/routes/routes.d.ts +113 -2
  48. package/src/routes/skill-router.d.ts +53 -2
  49. package/src/routes/skill-router.js +114 -31
  50. package/src/routes/task-router.d.ts +33 -0
  51. package/src/routes/task-router.js +182 -88
  52. package/src/routes/whoami-router.d.ts +1 -0
  53. package/src/routes/whoami-router.js +1 -1
  54. package/src/skill-copies.d.ts +34 -0
  55. package/src/skill-copies.js +109 -0
  56. package/src/telemetry.d.ts +2 -2
  57. package/src/telemetry.js +8 -3
  58. package/src/types.d.ts +4 -0
  59. package/src/types.js +6 -0
@@ -1,12 +1,12 @@
1
1
  import { spawn } from "node:child_process";
2
- import { fileURLToPath } from "node:url";
2
+ import { homedir } from "node:os";
3
3
  import { parseArgs } from "node:util";
4
4
  import { CliError } from "../errors.js";
5
5
  import { generateCommandUsage, noInput } from "../input.js";
6
- import { diagnostic, getOutputMode, output, validatePositionals } from "../lib.js";
6
+ import { diagnostic, getOutputMode, output, validatePositionals, validateUniqueOptions, } from "../lib.js";
7
7
  import { jsonResult } from "../results.js";
8
- /** The workflow skill folder that ships with the CLI */
9
- export const bundledSkillDirectory = fileURLToPath(new URL("../../skills/zinn", import.meta.url));
8
+ import { formatSkillStatus, presentSkillStatus, } from "../presentation/skill-status-presentation.js";
9
+ import { bundledSkillDirectory, findSkillCopies, SKILL_NAME } from "../skill-copies.js";
10
10
  /** On Windows npx is `npx.cmd`, which Node only starts through a shell */
11
11
  const needsShell = process.platform === "win32";
12
12
  /** Starts npx with one argument per array item, or on Windows as one command line for the shell */
@@ -19,17 +19,43 @@ function startNpx(args, stdio) {
19
19
  }
20
20
  return spawn("npx", args, { stdio });
21
21
  }
22
+ const skillScopeInput = {
23
+ options: { project: { type: "boolean" } },
24
+ forms: [{ id: "default", positionals: [] }],
25
+ constraints: [],
26
+ };
27
+ const skillInputs = {
28
+ install: skillScopeInput,
29
+ uninstall: skillScopeInput,
30
+ };
31
+ /** Parses the shared skill command arguments and says whether the command targets the current folder */
32
+ function parseSkillScope(args) {
33
+ const { positionals, values, tokens } = parseArgs({
34
+ options: skillScopeInput.options,
35
+ args,
36
+ strict: true,
37
+ allowPositionals: true,
38
+ tokens: true,
39
+ });
40
+ validateUniqueOptions(tokens, skillScopeInput.options);
41
+ validatePositionals(positionals, skillScopeInput.forms[0]);
42
+ return values.project === true;
43
+ }
22
44
  /**
23
- * Runs the skills CLI and resolves with its exit code
24
- * If a signal ends it, it's `null`
45
+ * Runs the skills CLI with the given subcommand and arguments in the current working directory
46
+ * Resolves with its exit code, or `null` if a signal ends it
25
47
  */
26
- function runSkillsCli(skillDirectory) {
48
+ function runSkillsCli(skillsArgs, isProject, zinnCommand) {
27
49
  const isJson = getOutputMode() === "json";
28
- // JSON output keeps stdout for the result and stderr for one error document,
29
- // so the skills CLI's output is captured and reported as notices.
30
- const child = startNpx(["--yes", "skills", "add", skillDirectory, "-g", "-y"], ["inherit", isJson ? "pipe" : "inherit", isJson ? "pipe" : "inherit"]);
50
+ /**
51
+ * JSON output keeps stdout for the result and stderr for one error document,
52
+ * so the skills CLI's output is captured and reported as notices.
53
+ * Without `-g` the skills CLI works in the current folder.
54
+ */
55
+ const scopeArgs = isProject ? [] : ["-g"];
56
+ const child = startNpx(["--yes", "skills", ...skillsArgs, ...scopeArgs, "-y"], ["inherit", isJson ? "pipe" : "inherit", isJson ? "pipe" : "inherit"]);
31
57
  const captured = [];
32
- // Decoding per stream keeps a character whose bytes arrive in two chunks intact.
58
+ // Decoding per stream keeps a character intact when its bytes arrive across two chunks
33
59
  for (const stream of [child.stdout, child.stderr]) {
34
60
  stream?.setEncoding("utf8");
35
61
  stream?.on("data", (text) => captured.push(text));
@@ -37,7 +63,7 @@ function runSkillsCli(skillDirectory) {
37
63
  return new Promise((resolve, reject) => {
38
64
  child.once("error", (error) => {
39
65
  if (error.code === "ENOENT") {
40
- const message = "npx was not found. zinn skill install needs npx, which comes with npm.";
66
+ const message = `npx was not found. ${zinnCommand} needs npx, which comes with npm.`;
41
67
  reject(new CliError(message, "not_found", undefined, undefined, undefined, error));
42
68
  }
43
69
  else {
@@ -56,14 +82,51 @@ function runSkillsCli(skillDirectory) {
56
82
  });
57
83
  });
58
84
  }
85
+ /**
86
+ * Throws when the skills CLI failed, so Zinn exits with its exit code
87
+ * `details` adds what the error document names besides the exit code
88
+ */
89
+ function throwOnSkillsCliFailure(exitCode, details) {
90
+ if (exitCode === 0) {
91
+ return;
92
+ }
93
+ const endedBySignal = exitCode === null;
94
+ const failure = new CliError(endedBySignal ? "The skills CLI was stopped." : `The skills CLI exited with code ${exitCode}.`, "internal", { ...details, ...(endedBySignal ? {} : { exitCode }) });
95
+ if (!endedBySignal) {
96
+ failure.exitCode = exitCode;
97
+ }
98
+ throw failure;
99
+ }
59
100
  export const skillRouter = {
60
101
  install: {
61
102
  summary: "Install the agent skill bundled with this CLI using the skills CLI.",
62
- effects: { domain: "none", storage: "none" },
103
+ effects: { domain: "none", storage: "none", external: ["files", "network"] },
63
104
  confirmation: { kind: "none" },
64
- input: noInput,
105
+ input: skillInputs.install,
65
106
  results: [jsonResult("SkillInstall")],
66
107
  run: async (args) => {
108
+ const isProject = parseSkillScope(args);
109
+ const exitCode = await runSkillsCli(["add", bundledSkillDirectory], isProject, "zinn skill install");
110
+ throwOnSkillsCliFailure(exitCode, { path: bundledSkillDirectory });
111
+ const installed = { source: bundledSkillDirectory };
112
+ output(installed, () => "");
113
+ },
114
+ help: `${generateCommandUsage("skill install", skillInputs.install)}
115
+
116
+ Install the agent skill bundled with this CLI using the skills CLI (https://github.com/vercel-labs/skills).
117
+
118
+ Runs npx --yes skills add <skill folder> -g -y, where the skill folder is the one inside this CLI's package, and passes the skills CLI's output and exit code through.
119
+ Use --project to install into the current folder instead. It runs the same command without -g there, and the skills CLI records the copy in that folder's skills-lock.json.
120
+ Rerun it after upgrading Zinn, or run npx skills update -g, which reads the same folder. Each project with its own copy needs zinn skill install --project rerun there after an upgrade.
121
+ With --json, the skills CLI's output is reported as notices: on stderr after the result, or in error.diagnostics when it fails.`,
122
+ },
123
+ status: {
124
+ summary: "List the Zinn agent skill copies and whether each matches the skill this CLI installs.",
125
+ effects: { domain: "none", storage: "none", external: [] },
126
+ confirmation: { kind: "none" },
127
+ input: noInput,
128
+ results: [jsonResult("SkillStatus")],
129
+ run: (args) => {
67
130
  const { positionals } = parseArgs({
68
131
  options: noInput.options,
69
132
  args,
@@ -71,26 +134,46 @@ export const skillRouter = {
71
134
  allowPositionals: true,
72
135
  });
73
136
  validatePositionals(positionals, noInput.forms[0]);
74
- const exitCode = await runSkillsCli(bundledSkillDirectory);
75
- if (exitCode !== 0) {
76
- const endedBySignal = exitCode === null;
77
- const failure = new CliError(endedBySignal
78
- ? "The skills CLI was stopped."
79
- : `The skills CLI exited with code ${exitCode}.`, "internal", { path: bundledSkillDirectory, ...(endedBySignal ? {} : { exitCode }) });
80
- if (!endedBySignal) {
81
- failure.exitCode = exitCode;
82
- }
83
- throw failure;
84
- }
85
- const installed = { source: bundledSkillDirectory };
86
- output(installed, () => "");
137
+ const workingFolder = process.cwd();
138
+ const status = presentSkillStatus(findSkillCopies(homedir(), workingFolder), bundledSkillDirectory, workingFolder);
139
+ output(status, formatSkillStatus);
87
140
  },
88
- help: `${generateCommandUsage("skill install", noInput)}
141
+ help: `${generateCommandUsage("skill status", noInput)}
89
142
 
90
- Install the agent skill bundled with this CLI using the skills CLI (https://github.com/vercel-labs/skills).
143
+ List the Zinn skill copies agents may load and whether each matches the skill this CLI installs.
91
144
 
92
- Runs npx --yes skills add <skill folder> -g -y, where the skill folder is the one inside this CLI's package, and passes the skills CLI's output and exit code through.
93
- Rerun it after upgrading Zinn, or run npx skills update -g, which reads the same folder.
145
+ Checks ~/.agents/skills/zinn, ~/.claude/skills/zinn and the same two folders in the current folder, as zinn doctor does. Paths that reach one file through links count as one copy. Each copy that differs names the command that updates it.
146
+ Reads local files only and changes nothing.
147
+ Exits 0 when a copy differs. zinn doctor exits 1 then. With --json, matches says whether each copy matches.`,
148
+ },
149
+ uninstall: {
150
+ summary: "Remove the Zinn agent skill using the skills CLI.",
151
+ effects: { domain: "none", storage: "none", external: ["files", "network"] },
152
+ confirmation: { kind: "none" },
153
+ input: skillInputs.uninstall,
154
+ results: [jsonResult("SkillUninstall")],
155
+ run: async (args) => {
156
+ const isProject = parseSkillScope(args);
157
+ const copiesBefore = findSkillCopies(homedir(), process.cwd()).copies;
158
+ const exitCode = await runSkillsCli(["remove", SKILL_NAME], isProject, "zinn skill uninstall");
159
+ throwOnSkillsCliFailure(exitCode, {});
160
+ const realPathsAfter = new Set(findSkillCopies(homedir(), process.cwd()).copies.map((copy) => copy.realPath));
161
+ const result = {
162
+ removed: copiesBefore
163
+ .filter((copy) => !realPathsAfter.has(copy.realPath))
164
+ .map(({ path, scope }) => ({ path, scope })),
165
+ };
166
+ output(result, () => "");
167
+ },
168
+ help: `${generateCommandUsage("skill uninstall", skillInputs.uninstall)}
169
+
170
+ Remove the Zinn agent skill using the skills CLI (https://github.com/vercel-labs/skills).
171
+
172
+ Runs npx --yes skills remove zinn -g -y and passes the skills CLI's output and exit code through. It removes the global copy and its agent links.
173
+ Use --project to remove the copy in the current folder instead. It runs the same command without -g there.
174
+ The skill is removed by its name, zinn, so a copy installed from another source, such as the GitHub repository, is removed too.
175
+ zinn skill install puts the skill back.
176
+ With --json, the result lists the removed copies among ~/.agents/skills/zinn, ~/.claude/skills/zinn and the same two folders in the current folder, though the skills CLI may also remove copies in other agent folders.
94
177
  With --json, the skills CLI's output is reported as notices: on stderr after the result, or in error.diagnostics when it fails.`,
95
178
  },
96
179
  };
@@ -6,6 +6,7 @@ export declare const taskRouter: {
6
6
  effects: {
7
7
  domain: "create";
8
8
  storage: "normal-open";
9
+ external: never[];
9
10
  };
10
11
  confirmation: {
11
12
  kind: "none";
@@ -129,6 +130,7 @@ export declare const taskRouter: {
129
130
  effects: {
130
131
  domain: "read";
131
132
  storage: "normal-open";
133
+ external: never[];
132
134
  };
133
135
  confirmation: {
134
136
  kind: "none";
@@ -238,6 +240,7 @@ export declare const taskRouter: {
238
240
  effects: {
239
241
  domain: "read";
240
242
  storage: "normal-open";
243
+ external: never[];
241
244
  };
242
245
  confirmation: {
243
246
  kind: "none";
@@ -277,6 +280,10 @@ export declare const taskRouter: {
277
280
  readonly name: "name";
278
281
  };
279
282
  };
283
+ readonly "with-matches": {
284
+ readonly type: "boolean";
285
+ readonly description: "Include match excerpts in JSON results";
286
+ };
280
287
  readonly "due-since": {
281
288
  readonly type: "string";
282
289
  readonly value: {
@@ -318,6 +325,10 @@ export declare const taskRouter: {
318
325
  }, {
319
326
  readonly kind: "exclusive";
320
327
  readonly members: readonly ["positional:project-key", "option:all-projects"];
328
+ }, {
329
+ readonly kind: "requires";
330
+ readonly input: "option:with-matches";
331
+ readonly requires: "option:json";
321
332
  }];
322
333
  readonly notes: readonly ["An omitted project key uses defaultProject, or all projects if unset. --all-projects overrides the default and cannot be combined with a project key.", "A query that is a task key ignores defaultProject unless a project was typed. --all-projects still excludes a typed project."];
323
334
  };
@@ -330,6 +341,7 @@ export declare const taskRouter: {
330
341
  effects: {
331
342
  domain: "read";
332
343
  storage: "normal-open";
344
+ external: never[];
333
345
  };
334
346
  confirmation: {
335
347
  kind: "none";
@@ -373,6 +385,7 @@ export declare const taskRouter: {
373
385
  effects: {
374
386
  domain: "read";
375
387
  storage: "normal-open";
388
+ external: never[];
376
389
  };
377
390
  confirmation: {
378
391
  kind: "none";
@@ -405,6 +418,7 @@ export declare const taskRouter: {
405
418
  effects: {
406
419
  domain: "read";
407
420
  storage: "normal-open";
421
+ external: never[];
408
422
  };
409
423
  confirmation: {
410
424
  kind: "none";
@@ -433,6 +447,7 @@ export declare const taskRouter: {
433
447
  effects: {
434
448
  domain: "update";
435
449
  storage: "normal-open";
450
+ external: never[];
436
451
  };
437
452
  confirmation: {
438
453
  kind: "none";
@@ -601,6 +616,7 @@ export declare const taskRouter: {
601
616
  effects: {
602
617
  domain: "update";
603
618
  storage: "normal-open";
619
+ external: never[];
604
620
  };
605
621
  confirmation: {
606
622
  kind: "none";
@@ -648,6 +664,7 @@ export declare const taskRouter: {
648
664
  effects: {
649
665
  domain: "update";
650
666
  storage: "normal-open";
667
+ external: never[];
651
668
  };
652
669
  confirmation: {
653
670
  kind: "none";
@@ -727,6 +744,7 @@ export declare const taskRouter: {
727
744
  effects: {
728
745
  domain: "update";
729
746
  storage: "normal-open";
747
+ external: never[];
730
748
  };
731
749
  confirmation: {
732
750
  kind: "none";
@@ -755,6 +773,7 @@ export declare const taskRouter: {
755
773
  effects: {
756
774
  domain: "update";
757
775
  storage: "normal-open";
776
+ external: never[];
758
777
  };
759
778
  confirmation: {
760
779
  kind: "none";
@@ -783,6 +802,7 @@ export declare const taskRouter: {
783
802
  effects: {
784
803
  domain: "update";
785
804
  storage: "normal-open";
805
+ external: never[];
786
806
  };
787
807
  confirmation: {
788
808
  kind: "none";
@@ -825,6 +845,7 @@ export declare const taskRouter: {
825
845
  effects: {
826
846
  domain: "update";
827
847
  storage: "normal-open";
848
+ external: never[];
828
849
  };
829
850
  confirmation: {
830
851
  kind: "none";
@@ -853,6 +874,7 @@ export declare const taskRouter: {
853
874
  effects: {
854
875
  domain: "update";
855
876
  storage: "normal-open";
877
+ external: never[];
856
878
  };
857
879
  confirmation: {
858
880
  kind: "none";
@@ -881,6 +903,7 @@ export declare const taskRouter: {
881
903
  effects: {
882
904
  domain: "delete";
883
905
  storage: "normal-open";
906
+ external: never[];
884
907
  };
885
908
  confirmation: {
886
909
  kind: "prompt";
@@ -915,6 +938,7 @@ export declare const taskRouter: {
915
938
  effects: {
916
939
  domain: "replace";
917
940
  storage: "normal-open";
941
+ external: never[];
918
942
  };
919
943
  confirmation: {
920
944
  kind: "prompt";
@@ -966,6 +990,7 @@ export declare const taskRouter: {
966
990
  effects: {
967
991
  domain: "read";
968
992
  storage: "normal-open";
993
+ external: never[];
969
994
  };
970
995
  confirmation: {
971
996
  kind: "none";
@@ -994,6 +1019,7 @@ export declare const taskRouter: {
994
1019
  effects: {
995
1020
  domain: "delete";
996
1021
  storage: "normal-open";
1022
+ external: never[];
997
1023
  };
998
1024
  confirmation: {
999
1025
  kind: "none";
@@ -1043,6 +1069,7 @@ export declare const taskRouter: {
1043
1069
  effects: {
1044
1070
  domain: "create";
1045
1071
  storage: "normal-open";
1072
+ external: never[];
1046
1073
  };
1047
1074
  confirmation: {
1048
1075
  kind: "none";
@@ -1096,6 +1123,7 @@ export declare const taskRouter: {
1096
1123
  effects: {
1097
1124
  domain: "read";
1098
1125
  storage: "normal-open";
1126
+ external: never[];
1099
1127
  };
1100
1128
  confirmation: {
1101
1129
  kind: "none";
@@ -1124,6 +1152,7 @@ export declare const taskRouter: {
1124
1152
  effects: {
1125
1153
  domain: "read";
1126
1154
  storage: "normal-open";
1155
+ external: never[];
1127
1156
  };
1128
1157
  confirmation: {
1129
1158
  kind: "none";
@@ -1152,6 +1181,7 @@ export declare const taskRouter: {
1152
1181
  effects: {
1153
1182
  domain: "update";
1154
1183
  storage: "normal-open";
1184
+ external: never[];
1155
1185
  };
1156
1186
  confirmation: {
1157
1187
  kind: "none";
@@ -1252,6 +1282,7 @@ export declare const taskRouter: {
1252
1282
  effects: {
1253
1283
  domain: "delete";
1254
1284
  storage: "normal-open";
1285
+ external: never[];
1255
1286
  };
1256
1287
  confirmation: {
1257
1288
  kind: "prompt";
@@ -1287,6 +1318,7 @@ export declare const taskRouter: {
1287
1318
  effects: {
1288
1319
  domain: "update";
1289
1320
  storage: "normal-open";
1321
+ external: never[];
1290
1322
  };
1291
1323
  confirmation: {
1292
1324
  kind: "none";
@@ -1322,6 +1354,7 @@ export declare const taskRouter: {
1322
1354
  effects: {
1323
1355
  domain: "update";
1324
1356
  storage: "normal-open";
1357
+ external: never[];
1325
1358
  };
1326
1359
  confirmation: {
1327
1360
  kind: "none";