@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
@@ -0,0 +1,109 @@
1
+ import { readFileSync, realpathSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { isMissingFileError } from "@zinn-dev/core";
5
+ /** The name the skills CLI and agents know the workflow skill by */
6
+ export const SKILL_NAME = "zinn";
7
+ /** The workflow skill folder that ships with the CLI */
8
+ export const bundledSkillDirectory = fileURLToPath(new URL("../skills/zinn", import.meta.url));
9
+ const SKILL_FILE_NAME = "SKILL.md";
10
+ /** The YAML frontmatter block that opens a skill file */
11
+ const FRONTMATTER_PATTERN = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/;
12
+ /**
13
+ * The reviewed version under the frontmatter's `metadata:`
14
+ * map, quoted or plain
15
+ */
16
+ const REVIEWED_VERSION_PATTERN = /^metadata:[ \t]*\r?\n(?:[ \t]+.*\r?\n)*?[ \t]+zinn-cli-reviewed-version:[ \t]*(?:"([^"\r\n]*)"|'([^'\r\n]*)'|([^\s#'"]+))/m;
17
+ /**
18
+ * Agent skill folders in lookup order.
19
+ *
20
+ * OpenCode prefers project `.agents/skills` over home directory,
21
+ * whereas Claude Code prefers home `.claude/skills` over project.
22
+ */
23
+ const SKILL_BASES = [
24
+ { scope: "home", segments: [".agents", "skills"] },
25
+ { scope: "home", segments: [".claude", "skills"] },
26
+ { scope: "project", segments: [".agents", "skills"] },
27
+ { scope: "project", segments: [".claude", "skills"] },
28
+ ];
29
+ /** The command that replaces a copy in the given scope with the bundled skill */
30
+ export function skillInstallCommand(scope, workingFolder) {
31
+ return scope === "project"
32
+ ? `\`zinn skill install --project\` run in ${workingFolder}`
33
+ : "`zinn skill install`";
34
+ }
35
+ /** A skill file's reviewed CLI version, `null` when the file has none that can be read */
36
+ export function readReviewedVersion(skill) {
37
+ const frontmatter = FRONTMATTER_PATTERN.exec(skill)?.[1];
38
+ if (frontmatter === undefined) {
39
+ return null;
40
+ }
41
+ const match = REVIEWED_VERSION_PATTERN.exec(frontmatter);
42
+ if (match === null) {
43
+ return null;
44
+ }
45
+ return match[1] ?? match[2] ?? match[3] ?? null;
46
+ }
47
+ /**
48
+ * The file a path reaches after following links, `null` when it reaches nothing.
49
+ * Any other failure gives the path itself, so the read that follows reports the copy as unreadable.
50
+ */
51
+ function resolveRealPath(path) {
52
+ try {
53
+ return realpathSync(path);
54
+ }
55
+ catch (error) {
56
+ if (isMissingFileError(error)) {
57
+ return null;
58
+ }
59
+ return path;
60
+ }
61
+ }
62
+ /**
63
+ * Finds the Zinn skill copies in the home folder and the working folder and compares each with the bundled skill.
64
+ * Paths that lead to one file through links give one copy. A link that leads nowhere is no copy.
65
+ */
66
+ export function findSkillCopies(home, workingFolder) {
67
+ // The skill ships with the CLI, and release checks guarantee its version.
68
+ const bundledVersion = readReviewedVersion(readFileSync(join(bundledSkillDirectory, SKILL_FILE_NAME), "utf8"));
69
+ const copies = [];
70
+ for (const { scope, segments } of SKILL_BASES) {
71
+ const path = join(scope === "home" ? home : workingFolder, ...segments, SKILL_NAME, SKILL_FILE_NAME);
72
+ const realPath = resolveRealPath(path);
73
+ if (realPath === null) {
74
+ continue;
75
+ }
76
+ const found = copies.find((copy) => copy.realPath === realPath);
77
+ if (found !== undefined) {
78
+ // A working folder equal to the home folder checks the same paths twice
79
+ const isNewPath = found.path !== path && !found.links.includes(path);
80
+ if (isNewPath) {
81
+ found.links.push(path);
82
+ }
83
+ continue;
84
+ }
85
+ let skill;
86
+ try {
87
+ skill = readFileSync(realPath, "utf8");
88
+ }
89
+ catch (error) {
90
+ if (isMissingFileError(error)) {
91
+ continue;
92
+ }
93
+ copies.push({
94
+ path,
95
+ links: [],
96
+ realPath,
97
+ scope,
98
+ readable: false,
99
+ reviewedVersion: null,
100
+ matches: false,
101
+ });
102
+ continue;
103
+ }
104
+ const reviewedVersion = readReviewedVersion(skill);
105
+ const matches = reviewedVersion !== null && reviewedVersion === bundledVersion;
106
+ copies.push({ path, links: [], realPath, scope, readable: true, reviewedVersion, matches });
107
+ }
108
+ return { bundledVersion, copies };
109
+ }
@@ -15,12 +15,12 @@ type MatchedRun = {
15
15
  commandArgs: Array<string>;
16
16
  help: boolean;
17
17
  };
18
- /** A successful run of a command that declares one of these only reads or reports, and leaves no record */
19
- export declare const UNRECORDED_STORAGE_EFFECTS: ReadonlyArray<ParsedRoute["effects"]["storage"]>;
20
18
  export declare function noteMatchedRun(run: MatchedRun): void;
21
19
  /** An option-shaped word is left out of `unmatchedWord` because it can carry a value. `options` names it */
22
20
  export declare function noteUnmatchedRun({ namespace, unmatchedWord, help }: UnmatchedRun): void;
23
21
  export declare function noteParseArgsThrew(): void;
22
+ /** A successful run leaves no record when its command only reads or reports and writes no files outside the store */
23
+ export declare function isUnrecordedOnSuccess(effects: ParsedRoute["effects"]): boolean;
24
24
  /**
25
25
  * Appends this run's record to the current record file in the store's `telemetry` folder.
26
26
  * A run that starts a new file first deletes old ones, so the newest records are the ones kept.
package/src/telemetry.js CHANGED
@@ -21,8 +21,8 @@ const FILES_PER_CAP = 10;
21
21
  const MILLISECONDS_PER_DAY = 86_400_000;
22
22
  /** parseArgs reads any word starting with `--` as an option up to its first `=`, spaces included */
23
23
  const OPTION_NAME_SHAPE = /^--?[A-Za-z0-9][\w-]*$/;
24
- /** A successful run of a command that declares one of these only reads or reports, and leaves no record */
25
- export const UNRECORDED_STORAGE_EFFECTS = [
24
+ /** A command that declares one of these only reads or reports Zinn's data */
25
+ const UNRECORDED_STORAGE_EFFECTS = [
26
26
  "none",
27
27
  "inspect",
28
28
  ];
@@ -187,11 +187,16 @@ function createRecord(outcome, startedAt, elapsedMs) {
187
187
  parentPid: process.ppid,
188
188
  };
189
189
  }
190
+ /** A successful run leaves no record when its command only reads or reports and writes no files outside the store */
191
+ export function isUnrecordedOnSuccess(effects) {
192
+ const writesExternalFiles = effects.external.includes("files");
193
+ return UNRECORDED_STORAGE_EFFECTS.includes(effects.storage) && !writesExternalFiles;
194
+ }
190
195
  function isUnrecordedRun({ failure }) {
191
196
  return (failure === undefined &&
192
197
  matchedRun !== null &&
193
198
  !matchedRun.help &&
194
- UNRECORDED_STORAGE_EFFECTS.includes(matchedRun.match.effects.storage));
199
+ isUnrecordedOnSuccess(matchedRun.match.effects));
195
200
  }
196
201
  /** One write on a descriptor opened for append, so parallel runs cannot split each other's lines */
197
202
  function appendLine(path, line) {
package/src/types.d.ts CHANGED
@@ -19,6 +19,10 @@ export declare const commandEffectsSchema: z.ZodObject<{
19
19
  restore: "restore";
20
20
  inspect: "inspect";
21
21
  }>;
22
+ external: z.ZodArray<z.ZodEnum<{
23
+ files: "files";
24
+ network: "network";
25
+ }>>;
22
26
  }, z.core.$strict>;
23
27
  export declare const commandConfirmationSchema: z.ZodObject<{
24
28
  kind: z.ZodEnum<{
package/src/types.js CHANGED
@@ -2,6 +2,12 @@ import { z } from "zod";
2
2
  export const commandEffectsSchema = z.strictObject({
3
3
  domain: z.enum(["read", "create", "update", "delete", "replace", "none"]),
4
4
  storage: z.enum(["normal-open", "backup", "restore", "migrate", "reindex", "inspect", "none"]),
5
+ /**
6
+ * Kinds of effect outside Zinn's own data,
7
+ * like files written or deleted outside the store
8
+ * or making HTTP requests
9
+ */
10
+ external: z.array(z.enum(["files", "network"])),
5
11
  });
6
12
  export const commandConfirmationSchema = z.strictObject({
7
13
  kind: z.enum(["none", "prompt", "project-delete"]),