@zinn-dev/cli 0.44.0 → 0.45.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 (56) hide show
  1. package/package.json +2 -2
  2. package/skills/zinn/SKILL.md +7 -9
  3. package/src/capabilities-schema.d.ts +5 -1
  4. package/src/column-hint.js +1 -3
  5. package/src/database.d.ts +1 -2
  6. package/src/database.js +1 -6
  7. package/src/duration-input.d.ts +7 -0
  8. package/src/duration-input.js +31 -0
  9. package/src/errors.d.ts +22 -0
  10. package/src/errors.js +30 -5
  11. package/src/expected-values.d.ts +48 -0
  12. package/src/expected-values.js +60 -0
  13. package/src/follow.d.ts +9 -0
  14. package/src/follow.js +58 -0
  15. package/src/input.d.ts +0 -8
  16. package/src/input.js +36 -16
  17. package/src/lib.d.ts +5 -2
  18. package/src/lib.js +18 -8
  19. package/src/list-continuation.js +1 -4
  20. package/src/presentation/activity-presentation.d.ts +2 -0
  21. package/src/presentation/activity-presentation.js +58 -3
  22. package/src/presentation/column-presentation.d.ts +9 -4
  23. package/src/presentation/column-presentation.js +29 -12
  24. package/src/presentation/doctor-presentation.d.ts +4 -0
  25. package/src/presentation/doctor-presentation.js +24 -0
  26. package/src/presentation/relation-presentation.js +2 -1
  27. package/src/presentation/task-blame-presentation.d.ts +1 -4
  28. package/src/presentation/task-blame-presentation.js +1 -1
  29. package/src/presentation/task-presentation.d.ts +2 -0
  30. package/src/presentation/task-presentation.js +39 -2
  31. package/src/result-schemas.d.ts +353 -58
  32. package/src/result-schemas.js +46 -2
  33. package/src/results.d.ts +6 -2
  34. package/src/results.js +9 -3
  35. package/src/routes/activity-router.d.ts +12 -3
  36. package/src/routes/activity-router.js +93 -59
  37. package/src/routes/aliases.js +1 -0
  38. package/src/routes/comment-router.d.ts +24 -6
  39. package/src/routes/comment-router.js +15 -5
  40. package/src/routes/doctor-router.d.ts +39 -0
  41. package/src/routes/doctor-router.js +103 -0
  42. package/src/routes/label-router.d.ts +39 -6
  43. package/src/routes/label-router.js +22 -5
  44. package/src/routes/project-router.d.ts +60 -11
  45. package/src/routes/project-router.js +100 -33
  46. package/src/routes/restore-router.js +2 -2
  47. package/src/routes/router.js +3 -7
  48. package/src/routes/routes.d.ts +404 -33
  49. package/src/routes/routes.js +4 -0
  50. package/src/routes/skill-router.d.ts +25 -0
  51. package/src/routes/skill-router.js +96 -0
  52. package/src/routes/task-router.d.ts +231 -13
  53. package/src/routes/task-router.js +247 -19
  54. package/src/text-edit.d.ts +2 -2
  55. package/src/text-input.d.ts +19 -1
  56. package/src/text-input.js +26 -5
@@ -0,0 +1,103 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { parseArgs } from "node:util";
5
+ import { doctor, isMissingFileError } from "@zinn-dev/core";
6
+ import { generateCommandUsage, noInput } from "../input.js";
7
+ import { output, validatePositionals } from "../lib.js";
8
+ import { jsonResult } from "../results.js";
9
+ import { formatDoctor, presentDoctor } from "../presentation/doctor-presentation.js";
10
+ import { bundledSkillDirectory } from "./skill-router.js";
11
+ /** Where the `skills` CLI installs the Zinn workflow skill, inside the home folder */
12
+ const INSTALLED_SKILL_PATH = [".agents", "skills", "zinn", "SKILL.md"];
13
+ const SKILL_FILE_NAME = "SKILL.md";
14
+ const SKILL_INSTALL_REMEDY = "Update the skill with `zinn skill install`";
15
+ /** The YAML frontmatter block that opens a skill file */
16
+ const FRONTMATTER_PATTERN = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/;
17
+ /**
18
+ * The reviewed version under the frontmatter's `metadata:`
19
+ * map, quoted or plain
20
+ */
21
+ const REVIEWED_VERSION_PATTERN = /^metadata:[ \t]*\r?\n(?:[ \t]+.*\r?\n)*?[ \t]+zinn-cli-reviewed-version:[ \t]*(?:"([^"\r\n]*)"|'([^'\r\n]*)'|([^\s#'"]+))/m;
22
+ /** A skill file's reviewed CLI version, `null` when the file has none that can be read */
23
+ function readReviewedVersion(skill) {
24
+ const frontmatter = FRONTMATTER_PATTERN.exec(skill)?.[1];
25
+ if (frontmatter === undefined) {
26
+ return null;
27
+ }
28
+ const match = REVIEWED_VERSION_PATTERN.exec(frontmatter);
29
+ if (match === null) {
30
+ return null;
31
+ }
32
+ return match[1] ?? match[2] ?? match[3] ?? null;
33
+ }
34
+ function checkAgentSkill() {
35
+ const path = join(homedir(), ...INSTALLED_SKILL_PATH);
36
+ let skill;
37
+ try {
38
+ skill = readFileSync(path, "utf8");
39
+ }
40
+ catch (error) {
41
+ if (isMissingFileError(error)) {
42
+ return {
43
+ id: "agent_skill",
44
+ status: "ok",
45
+ message: "No Zinn skill is installed for agents",
46
+ remedy: null,
47
+ };
48
+ }
49
+ return {
50
+ id: "agent_skill",
51
+ status: "warning",
52
+ message: `The installed Zinn skill at ${path} cannot be read`,
53
+ remedy: SKILL_INSTALL_REMEDY,
54
+ };
55
+ }
56
+ const reviewedVersion = readReviewedVersion(skill);
57
+ // The skill `zinn skill install` installs. It ships with the CLI, and release checks guarantee its version.
58
+ const bundledVersion = readReviewedVersion(readFileSync(join(bundledSkillDirectory, SKILL_FILE_NAME), "utf8"));
59
+ if (reviewedVersion !== null && reviewedVersion === bundledVersion) {
60
+ return {
61
+ id: "agent_skill",
62
+ status: "ok",
63
+ message: `The installed Zinn skill matches the one this CLI installs (reviewed for CLI ${bundledVersion})`,
64
+ remedy: null,
65
+ };
66
+ }
67
+ const found = reviewedVersion === null
68
+ ? "names no reviewed CLI version"
69
+ : `was reviewed for CLI ${reviewedVersion}`;
70
+ return {
71
+ id: "agent_skill",
72
+ status: "warning",
73
+ message: `The installed Zinn skill at ${path} ${found}, and the skill this CLI installs was reviewed for CLI ${bundledVersion}`,
74
+ remedy: SKILL_INSTALL_REMEDY,
75
+ };
76
+ }
77
+ export const doctorCommand = {
78
+ summary: "Check the selected settings, database and installed agent skill for problems.",
79
+ effects: { domain: "none", storage: "inspect" },
80
+ confirmation: { kind: "none" },
81
+ input: noInput,
82
+ results: [{ ...jsonResult("Doctor"), findingsExitCode: 1 }],
83
+ run: (args) => {
84
+ const { positionals } = parseArgs({
85
+ options: noInput.options,
86
+ args,
87
+ strict: true,
88
+ allowPositionals: true,
89
+ });
90
+ validatePositionals(positionals, noInput.forms[0]);
91
+ const report = presentDoctor(doctor.check(), checkAgentSkill());
92
+ output(report, formatDoctor);
93
+ if (!report.ok) {
94
+ process.exitCode = 1;
95
+ }
96
+ },
97
+ help: `${generateCommandUsage("doctor", noInput)}
98
+
99
+ Check the selected settings, store folder, database, search index and installed agent skill for problems, and suggest a fix for each.
100
+
101
+ Exits 0 when every check is ok and 1 when any reports a warning or problem. The checks print on standard output either way.
102
+ Changes nothing: it creates no folder, database or settings file, and repairs nothing. SQLite may perform its normal file housekeeping.`,
103
+ };
@@ -47,7 +47,7 @@ export declare const labelRouter: {
47
47
  }];
48
48
  readonly constraints: readonly [{
49
49
  readonly kind: "exclusive";
50
- readonly members: readonly ["option:description" | "option:text", "option:description-file" | "option:text-file"];
50
+ readonly members: readonly ["option:description" | "option:text" | "option:expect-description" | "option:expect-text", "option:description-file" | "option:text-file" | "option:expect-description-file" | "option:expect-text-file"];
51
51
  }];
52
52
  };
53
53
  results: import("../results.js").CommandResult[];
@@ -114,6 +114,36 @@ export declare const labelRouter: {
114
114
  };
115
115
  input: {
116
116
  readonly options: {
117
+ readonly "expect-name": {
118
+ readonly type: "string";
119
+ readonly value: {
120
+ readonly kind: "text";
121
+ readonly name: "text";
122
+ };
123
+ };
124
+ readonly "expect-description": {
125
+ readonly type: "string";
126
+ readonly value: {
127
+ readonly kind: "text";
128
+ readonly name: "text";
129
+ };
130
+ };
131
+ readonly "expect-color": {
132
+ readonly type: "string";
133
+ readonly value: {
134
+ readonly kind: "enum";
135
+ readonly name: "color";
136
+ readonly choices: ("red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray")[];
137
+ };
138
+ };
139
+ readonly "expect-description-file": {
140
+ readonly type: "string";
141
+ readonly value: {
142
+ readonly kind: "path";
143
+ readonly name: "path";
144
+ readonly description: "A UTF-8 file, or \"-\" for stdin. Trailing line breaks are dropped; empty or blank input is an error.";
145
+ };
146
+ };
117
147
  readonly color: {
118
148
  readonly type: "string";
119
149
  readonly value: {
@@ -171,18 +201,18 @@ export declare const labelRouter: {
171
201
  }];
172
202
  readonly constraints: readonly [{
173
203
  readonly kind: "exclusive";
174
- readonly members: readonly ["option:description" | "option:text", "option:description-file" | "option:text-file"];
204
+ readonly members: readonly ["option:description" | "option:text" | "option:expect-description" | "option:expect-text", "option:description-file" | "option:text-file" | "option:expect-description-file" | "option:expect-text-file"];
175
205
  }, {
176
206
  readonly kind: "exclusive";
177
207
  readonly members: readonly ["option:append", "option:replacing"];
178
208
  }, {
179
209
  readonly kind: "requiresAny";
180
210
  readonly input: "option:append";
181
- readonly members: readonly ["option:description" | "option:text", "option:description-file" | "option:text-file"];
211
+ readonly members: readonly ["option:description" | "option:text" | "option:expect-description" | "option:expect-text", "option:description-file" | "option:text-file" | "option:expect-description-file" | "option:expect-text-file"];
182
212
  }, {
183
213
  readonly kind: "requiresAny";
184
214
  readonly input: "option:replacing";
185
- readonly members: readonly ["option:description" | "option:text", "option:description-file" | "option:text-file"];
215
+ readonly members: readonly ["option:description" | "option:text" | "option:expect-description" | "option:expect-text", "option:description-file" | "option:text-file" | "option:expect-description-file" | "option:expect-text-file"];
186
216
  }, {
187
217
  readonly kind: "requires";
188
218
  readonly input: "option:all";
@@ -190,8 +220,11 @@ export declare const labelRouter: {
190
220
  }, {
191
221
  readonly kind: "atLeastOne";
192
222
  readonly members: `option:${string}`[];
193
- }];
194
- readonly notes: readonly [string];
223
+ }, ...{
224
+ readonly kind: "exclusive";
225
+ readonly members: readonly ["option:description" | "option:text" | "option:expect-description" | "option:expect-text", "option:description-file" | "option:text-file" | "option:expect-description-file" | "option:expect-text-file"];
226
+ }[]];
227
+ readonly notes: readonly [string, string];
195
228
  };
196
229
  results: import("../results.js").CommandResult[];
197
230
  run: (args: string[]) => Promise<void>;
@@ -5,7 +5,8 @@ import { CliError } from "../errors.js";
5
5
  import { generateCommandUsage, noInput } from "../input.js";
6
6
  import { confirmationDescription, confirmAction, dashValueHelp, output, outputChanges, validatePositionals, validateUniqueOptions, } from "../lib.js";
7
7
  import { resolveTextEdit, textEditHelp, textEditOptions, textEditConstraints, } from "../text-edit.js";
8
- import { checkFieldsBeforeText, resolveTextInput, textFileHelp, textFileOption, textSourceConstraint, } from "../text-input.js";
8
+ import { expectedValueFlags } from "../expected-values.js";
9
+ import { checkFieldsBeforeText, checkSingleStdinReader, resolveTextInput, textFileHelp, textFileOption, textSourceConstraint, } from "../text-input.js";
9
10
  import { currentActor } from "../actor.js";
10
11
  import { formatLabelList, presentLabel } from "../presentation/label-presentation.js";
11
12
  const colorOption = {
@@ -16,6 +17,11 @@ const colorOption = {
16
17
  choices: labelColorSchema.options,
17
18
  },
18
19
  };
20
+ const labelExpectations = expectedValueFlags({
21
+ name: { field: "name", option: { type: "string", value: { kind: "text", name: "text" } } },
22
+ description: { field: "description", text: true },
23
+ color: { field: "color", option: colorOption },
24
+ });
19
25
  const labelInputs = {
20
26
  create: {
21
27
  options: {
@@ -46,6 +52,7 @@ const labelInputs = {
46
52
  "description-file": textFileOption,
47
53
  ...textEditOptions,
48
54
  color: colorOption,
55
+ ...labelExpectations.options,
49
56
  },
50
57
  forms: [
51
58
  { id: "default", positionals: [{ name: "name", min: 1, max: 1, value: { kind: "name" } }] },
@@ -57,13 +64,14 @@ const labelInputs = {
57
64
  kind: "atLeastOne",
58
65
  // A description can also come from --description-file
59
66
  members: Object.keys(labelEditSchema.shape)
60
- .filter((name) => name !== "labelName")
67
+ .filter((name) => name !== "labelName" && name !== "expected")
61
68
  .flatMap((name) => name === "description"
62
69
  ? textSourceConstraint("--description").members
63
70
  : [`option:${name}`]),
64
71
  },
72
+ ...labelExpectations.constraints,
65
73
  ],
66
- notes: [textEditHelp("--description")],
74
+ notes: [textEditHelp("--description"), labelExpectations.help],
67
75
  },
68
76
  delete: {
69
77
  options: { yes: { type: "boolean" } },
@@ -185,19 +193,25 @@ Example: zinn label view bug`,
185
193
  });
186
194
  validateUniqueOptions(tokens, labelInputs.edit.options);
187
195
  validatePositionals(positionals, labelInputs.edit.forms[0]);
196
+ const expected = labelExpectations.parseValues(values);
188
197
  checkFieldsBeforeText(labelEditSchema, {
189
198
  labelName: positionals[0],
190
199
  name: values.name,
191
200
  color: values.color,
201
+ expected,
192
202
  });
203
+ checkSingleStdinReader(values, ["--description", ...labelExpectations.textFlags]);
193
204
  const description = await resolveTextEdit(values, "--description");
194
205
  const input = labelEditSchema.parse({
195
206
  labelName: positionals[0],
196
207
  name: values.name,
197
208
  description,
198
209
  color: values.color,
210
+ expected,
199
211
  });
200
- const edited = label.edit(input, currentActor());
212
+ // Read only after the parse, which refuses an edit without edit flags
213
+ const expectedText = await labelExpectations.resolveText(values);
214
+ const edited = label.edit({ ...input, expected: { ...input.expected, ...expectedText } }, currentActor());
201
215
  outputChanges([edited], (change) => presentLabel(change.label), (entries) => formatLabelList(entries, { showsDescriptionPreview: true }), (entry) => `Label "${entry.name}" was unchanged`);
202
216
  },
203
217
  help: `${generateCommandUsage("label edit", labelInputs.edit)}
@@ -211,13 +225,16 @@ Valid colors: ${labelInputs.edit.options.color.value.choices.join(", ")}.
211
225
 
212
226
  ${textEditHelp("--description")}
213
227
 
228
+ ${labelExpectations.help}
229
+
214
230
  Label names match without case sensitivity.
215
231
 
216
232
  ${dashValueHelp("--description")}
217
233
 
218
234
  Examples:
219
235
  zinn label edit bug --name defect --color yellow
220
- zinn label edit bug --description 'Reported by users.' --append`,
236
+ zinn label edit bug --description 'Reported by users.' --append
237
+ zinn label edit bug --color red --expect-color yellow`,
221
238
  },
222
239
  delete: {
223
240
  summary: "Delete a label definition and remove it from all tasks after confirmation.",
@@ -46,7 +46,7 @@ export declare const projectRouter: {
46
46
  }];
47
47
  readonly constraints: readonly [{
48
48
  readonly kind: "exclusive";
49
- readonly members: readonly ["option:description" | "option:text", "option:description-file" | "option:text-file"];
49
+ readonly members: readonly ["option:description" | "option:text" | "option:expect-description" | "option:expect-text", "option:description-file" | "option:text-file" | "option:expect-description-file" | "option:expect-text-file"];
50
50
  }];
51
51
  };
52
52
  results: import("../results.js").CommandResult[];
@@ -114,6 +114,28 @@ export declare const projectRouter: {
114
114
  };
115
115
  input: {
116
116
  readonly options: {
117
+ readonly "expect-name": {
118
+ readonly type: "string";
119
+ readonly value: {
120
+ readonly kind: "text";
121
+ readonly name: "text";
122
+ };
123
+ };
124
+ readonly "expect-description": {
125
+ readonly type: "string";
126
+ readonly value: {
127
+ readonly kind: "text";
128
+ readonly name: "text";
129
+ };
130
+ };
131
+ readonly "expect-description-file": {
132
+ readonly type: "string";
133
+ readonly value: {
134
+ readonly kind: "path";
135
+ readonly name: "path";
136
+ readonly description: "A UTF-8 file, or \"-\" for stdin. Trailing line breaks are dropped; empty or blank input is an error.";
137
+ };
138
+ };
117
139
  readonly append: {
118
140
  readonly type: "boolean";
119
141
  };
@@ -163,18 +185,18 @@ export declare const projectRouter: {
163
185
  }];
164
186
  readonly constraints: readonly [{
165
187
  readonly kind: "exclusive";
166
- readonly members: readonly ["option:description" | "option:text", "option:description-file" | "option:text-file"];
188
+ readonly members: readonly ["option:description" | "option:text" | "option:expect-description" | "option:expect-text", "option:description-file" | "option:text-file" | "option:expect-description-file" | "option:expect-text-file"];
167
189
  }, {
168
190
  readonly kind: "exclusive";
169
191
  readonly members: readonly ["option:append", "option:replacing"];
170
192
  }, {
171
193
  readonly kind: "requiresAny";
172
194
  readonly input: "option:append";
173
- readonly members: readonly ["option:description" | "option:text", "option:description-file" | "option:text-file"];
195
+ readonly members: readonly ["option:description" | "option:text" | "option:expect-description" | "option:expect-text", "option:description-file" | "option:text-file" | "option:expect-description-file" | "option:expect-text-file"];
174
196
  }, {
175
197
  readonly kind: "requiresAny";
176
198
  readonly input: "option:replacing";
177
- readonly members: readonly ["option:description" | "option:text", "option:description-file" | "option:text-file"];
199
+ readonly members: readonly ["option:description" | "option:text" | "option:expect-description" | "option:expect-text", "option:description-file" | "option:text-file" | "option:expect-description-file" | "option:expect-text-file"];
178
200
  }, {
179
201
  readonly kind: "requires";
180
202
  readonly input: "option:all";
@@ -182,8 +204,11 @@ export declare const projectRouter: {
182
204
  }, {
183
205
  readonly kind: "atLeastOne";
184
206
  readonly members: readonly ["option:name", "option:description", "option:description-file"];
185
- }];
186
- readonly notes: readonly ["Omit the project key to use defaultProject from settings; otherwise a project key is required.", string];
207
+ }, ...{
208
+ readonly kind: "exclusive";
209
+ readonly members: readonly ["option:description" | "option:text" | "option:expect-description" | "option:expect-text", "option:description-file" | "option:text-file" | "option:expect-description-file" | "option:expect-text-file"];
210
+ }[]];
211
+ readonly notes: readonly ["Omit the project key to use defaultProject from settings; otherwise a project key is required.", string, string];
187
212
  };
188
213
  results: import("../results.js").CommandResult[];
189
214
  run: (args: string[]) => Promise<void>;
@@ -234,7 +259,17 @@ export declare const projectRouter: {
234
259
  kind: "none";
235
260
  };
236
261
  input: {
237
- readonly options: {};
262
+ readonly options: {
263
+ readonly category: {
264
+ readonly required: true;
265
+ readonly type: "string";
266
+ readonly value: {
267
+ readonly kind: "enum";
268
+ readonly name: "category";
269
+ readonly choices: ("done" | "backlog" | "todo" | "in_progress" | "review" | "cancelled")[];
270
+ };
271
+ };
272
+ };
238
273
  readonly forms: readonly [{
239
274
  readonly id: "default";
240
275
  readonly positionals: readonly [{
@@ -295,18 +330,29 @@ export declare const projectRouter: {
295
330
  storage: "normal-open";
296
331
  };
297
332
  confirmation: {
298
- kind: "none";
333
+ kind: "prompt";
334
+ description: string;
299
335
  };
300
336
  input: {
301
337
  readonly options: {
302
338
  readonly name: {
303
339
  readonly type: "string";
304
- readonly required: true;
305
340
  readonly value: {
306
341
  readonly kind: "text";
307
342
  readonly name: "text";
308
343
  };
309
344
  };
345
+ readonly category: {
346
+ readonly type: "string";
347
+ readonly value: {
348
+ readonly kind: "enum";
349
+ readonly name: "category";
350
+ readonly choices: ("done" | "backlog" | "todo" | "in_progress" | "review" | "cancelled")[];
351
+ };
352
+ };
353
+ readonly yes: {
354
+ readonly type: "boolean";
355
+ };
310
356
  };
311
357
  readonly forms: readonly [{
312
358
  readonly id: "default";
@@ -326,10 +372,13 @@ export declare const projectRouter: {
326
372
  };
327
373
  }];
328
374
  }];
329
- readonly constraints: readonly [];
375
+ readonly constraints: readonly [{
376
+ readonly kind: "atLeastOne";
377
+ readonly members: readonly ["option:name", "option:category"];
378
+ }];
330
379
  };
331
380
  results: import("../results.js").CommandResult[];
332
- run: (args: Array<string>) => void;
381
+ run: (args: Array<string>) => Promise<void>;
333
382
  help: string;
334
383
  };
335
384
  order: {