@zinn-dev/cli 0.40.0 → 0.41.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 (60) hide show
  1. package/README.md +166 -38
  2. package/index.js +24 -13
  3. package/package.json +7 -2
  4. package/skills/zinn/SKILL.md +63 -0
  5. package/src/actor.d.ts +2 -1
  6. package/src/actor.js +78 -11
  7. package/src/capabilities-schema.d.ts +163 -0
  8. package/src/capabilities-schema.js +124 -0
  9. package/src/capabilities.d.ts +21 -0
  10. package/src/capabilities.js +22 -0
  11. package/src/database.d.ts +1 -1
  12. package/src/database.js +4 -4
  13. package/src/errors.d.ts +158 -0
  14. package/src/errors.js +224 -0
  15. package/src/input.d.ts +116 -0
  16. package/src/input.js +119 -0
  17. package/src/lib.d.ts +42 -7
  18. package/src/lib.js +213 -17
  19. package/src/presentation/activity-presentation.js +16 -2
  20. package/src/presentation/column-presentation.d.ts +3 -5
  21. package/src/presentation/info-presentation.d.ts +4 -0
  22. package/src/presentation/info-presentation.js +96 -0
  23. package/src/presentation/task-presentation.d.ts +2 -10
  24. package/src/project.d.ts +6 -0
  25. package/src/project.js +23 -10
  26. package/src/result-schemas.d.ts +987 -0
  27. package/src/result-schemas.js +220 -0
  28. package/src/results.d.ts +23 -0
  29. package/src/results.js +17 -0
  30. package/src/routes/activity-router.d.ts +71 -0
  31. package/src/routes/activity-router.js +59 -11
  32. package/src/routes/backup-router.d.ts +17 -0
  33. package/src/routes/backup-router.js +15 -3
  34. package/src/routes/capabilities-router.d.ts +21 -0
  35. package/src/routes/capabilities-router.js +28 -0
  36. package/src/routes/comment-router.d.ts +183 -4
  37. package/src/routes/comment-router.js +136 -29
  38. package/src/routes/info-router.d.ts +21 -0
  39. package/src/routes/info-router.js +29 -0
  40. package/src/routes/label-router.d.ts +165 -0
  41. package/src/routes/label-router.js +111 -29
  42. package/src/routes/migrate-router.d.ts +17 -0
  43. package/src/routes/migrate-router.js +17 -5
  44. package/src/routes/project-router.d.ts +349 -0
  45. package/src/routes/project-router.js +278 -92
  46. package/src/routes/reindex-router.d.ts +17 -0
  47. package/src/routes/reindex-router.js +15 -3
  48. package/src/routes/relation-router.d.ts +108 -12
  49. package/src/routes/relation-router.js +74 -14
  50. package/src/routes/restore-router.d.ts +29 -0
  51. package/src/routes/restore-router.js +30 -13
  52. package/src/routes/router.d.ts +1 -1
  53. package/src/routes/router.js +44 -25
  54. package/src/routes/routes.d.ts +1565 -0
  55. package/src/routes/routes.js +5 -1
  56. package/src/routes/task-router.d.ts +861 -0
  57. package/src/routes/task-router.js +419 -163
  58. package/src/text-edit.d.ts +20 -2
  59. package/src/text-edit.js +22 -10
  60. package/src/types.d.ts +14 -0
@@ -1,47 +1,254 @@
1
+ import { jsonResult, taskDetailResults, taskChangeResults } from "../results.js";
1
2
  import { parseArgs } from "node:util";
2
- import { task, project, positiveIntegerPattern, searchLimitMessage, parseTaskKey, } from "@zinn-dev/core";
3
- import { confirmAction, failureMessage, output, quit, UsageError, validatePositionals, validateUniqueOptions, } from "../lib.js";
4
- import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit.js";
3
+ import { task, project, positiveIntegerPattern, searchLimitMessage, parseTaskKey, taskPrioritySchema, } from "@zinn-dev/core";
4
+ import { CliError } from "../errors.js";
5
+ import { generateCommandUsage, taskKeyPositional, archiveConstraint, getOptionInputs, violatesConstraint, } from "../input.js";
6
+ import { confirmationDescription, confirmAction, dashValueHelp, diagnostic, output, quit, validatePositionals, validateOrderForms, requireStringOption, validateUniqueOptions, } from "../lib.js";
7
+ import { resolveTextEdit, textEditHelp, textEditOptions, textEditConstraints, } from "../text-edit.js";
5
8
  import { formatRelations, presentRelations, relationRouter } from "./relation-router.js";
6
9
  import { commentRouter, formatComments, presentComments } from "./comment-router.js";
7
10
  import { currentActor } from "../actor.js";
8
- import { resolveProjectKey } from "../project.js";
11
+ import { resolveProjectKey, projectScopeConstraint, requiredProjectDescription, projectScopeDescription, } from "../project.js";
9
12
  import { formatSection } from "../presentation/section.js";
10
13
  import { formatActivityList, presentActivities } from "../presentation/activity-presentation.js";
11
14
  import { formatTaskList, formatTaskListWithStatus, formatTaskRow, presentTask, } from "../presentation/task-presentation.js";
15
+ // A column is changed with task move, so a guessed --status or --column suggests it with the same task keys.
16
+ function suggestTaskMove(args, options = {}) {
17
+ const { values, positionals } = parseArgs({
18
+ args,
19
+ options,
20
+ allowPositionals: true,
21
+ strict: false,
22
+ });
23
+ const guessedColumn = values.status ?? values.column;
24
+ const columnWords = typeof guessedColumn === "string" ? [guessedColumn] : [];
25
+ return ["task", "move", ...positionals, ...columnWords];
26
+ }
27
+ const priorityOption = {
28
+ type: "string",
29
+ value: {
30
+ kind: "enum",
31
+ name: "priority",
32
+ choices: [...taskPrioritySchema.options, "none"],
33
+ caseInsensitive: true,
34
+ description: "Omission leaves priority unassigned on creation and unchanged on edit. none clears priority; JSON uses null.",
35
+ },
36
+ };
37
+ const taskEditConstraint = {
38
+ kind: "atLeastOne",
39
+ members: [
40
+ "option:title",
41
+ "option:description",
42
+ "option:priority",
43
+ "option:add-label",
44
+ "option:remove-label",
45
+ ],
46
+ };
47
+ const taskInputs = {
48
+ create: {
49
+ options: {
50
+ title: { type: "string", required: true, value: { kind: "text", name: "text" } },
51
+ description: { type: "string", value: { kind: "text", name: "text" } },
52
+ priority: priorityOption,
53
+ label: { type: "string", multiple: true, value: { kind: "label-name", name: "name" } },
54
+ column: { type: "string", value: { kind: "column-name", name: "name" } },
55
+ parent: { type: "string", value: { kind: "task-key", name: "task-key" } },
56
+ "depends-on": {
57
+ type: "string",
58
+ multiple: true,
59
+ value: { kind: "task-key", name: "task-key" },
60
+ },
61
+ "duplicate-of": { type: "string", value: { kind: "task-key", name: "task-key" } },
62
+ related: { type: "string", multiple: true, value: { kind: "task-key", name: "task-key" } },
63
+ },
64
+ forms: [
65
+ {
66
+ id: "default",
67
+ positionals: [{ name: "project-key", min: 0, max: 1, value: { kind: "project-key" } }],
68
+ },
69
+ ],
70
+ constraints: [],
71
+ notes: [requiredProjectDescription],
72
+ },
73
+ list: {
74
+ options: {
75
+ archived: { type: "boolean" },
76
+ all: { type: "boolean" },
77
+ "all-projects": { type: "boolean" },
78
+ label: { type: "string", multiple: true, value: { kind: "label-name", name: "name" } },
79
+ column: { type: "string", value: { kind: "column-name", name: "name" } },
80
+ },
81
+ forms: [
82
+ {
83
+ id: "default",
84
+ positionals: [{ name: "project-key", min: 0, max: 1, value: { kind: "project-key" } }],
85
+ },
86
+ ],
87
+ constraints: [archiveConstraint, projectScopeConstraint],
88
+ notes: [projectScopeDescription],
89
+ },
90
+ search: {
91
+ options: {
92
+ archived: { type: "boolean" },
93
+ all: { type: "boolean" },
94
+ "all-projects": { type: "boolean" },
95
+ limit: {
96
+ type: "string",
97
+ value: { kind: "positive-integer", name: "n", pattern: `^${positiveIntegerPattern}$` },
98
+ },
99
+ label: { type: "string", multiple: true, value: { kind: "label-name", name: "name" } },
100
+ },
101
+ forms: [
102
+ {
103
+ id: "default",
104
+ positionals: [
105
+ { name: "query", min: 1, max: 1, value: { kind: "text" } },
106
+ { name: "project-key", min: 0, max: 1, value: { kind: "project-key" } },
107
+ ],
108
+ },
109
+ ],
110
+ constraints: [archiveConstraint, projectScopeConstraint],
111
+ notes: [
112
+ projectScopeDescription,
113
+ "A query that is a task key ignores defaultProject unless a project was typed. --all-projects still excludes a typed project.",
114
+ ],
115
+ },
116
+ view: {
117
+ options: { history: { type: "boolean" } },
118
+ forms: [
119
+ {
120
+ id: "default",
121
+ positionals: [taskKeyPositional],
122
+ },
123
+ ],
124
+ constraints: [],
125
+ },
126
+ edit: {
127
+ options: {
128
+ title: { type: "string", value: { kind: "text", name: "text" } },
129
+ description: { type: "string", value: { kind: "text", name: "text" } },
130
+ ...textEditOptions,
131
+ priority: priorityOption,
132
+ "add-label": { type: "string", multiple: true, value: { kind: "label-name", name: "name" } },
133
+ "remove-label": {
134
+ type: "string",
135
+ multiple: true,
136
+ value: { kind: "label-name", name: "name" },
137
+ },
138
+ },
139
+ forms: [
140
+ {
141
+ id: "default",
142
+ positionals: [taskKeyPositional],
143
+ },
144
+ ],
145
+ constraints: [...textEditConstraints("--description"), taskEditConstraint],
146
+ notes: [textEditHelp("--description")],
147
+ },
148
+ move: {
149
+ options: {},
150
+ forms: [
151
+ {
152
+ id: "default",
153
+ positionals: [
154
+ { ...taskKeyPositional, max: null },
155
+ { name: "target-column", min: 1, max: 1, value: { kind: "column-name" } },
156
+ ],
157
+ },
158
+ ],
159
+ constraints: [],
160
+ },
161
+ order: {
162
+ options: {},
163
+ forms: [
164
+ {
165
+ id: "absolute",
166
+ positionals: [
167
+ taskKeyPositional,
168
+ {
169
+ name: "direction",
170
+ min: 1,
171
+ max: 1,
172
+ value: { kind: "enum", choices: ["top", "up", "down", "bottom"] },
173
+ },
174
+ ],
175
+ },
176
+ {
177
+ id: "relative",
178
+ positionals: [
179
+ taskKeyPositional,
180
+ {
181
+ name: "direction",
182
+ min: 1,
183
+ max: 1,
184
+ value: { kind: "enum", choices: ["before", "after"] },
185
+ },
186
+ { ...taskKeyPositional, name: "target-task-key" },
187
+ ],
188
+ },
189
+ ],
190
+ constraints: [],
191
+ },
192
+ archive: {
193
+ options: {},
194
+ forms: [
195
+ {
196
+ id: "default",
197
+ positionals: [{ ...taskKeyPositional, max: null }],
198
+ },
199
+ ],
200
+ constraints: [],
201
+ },
202
+ delete: {
203
+ options: { yes: { type: "boolean" } },
204
+ forms: [
205
+ {
206
+ id: "default",
207
+ positionals: [taskKeyPositional],
208
+ },
209
+ ],
210
+ constraints: [],
211
+ },
212
+ label_add: {
213
+ options: {},
214
+ forms: [
215
+ {
216
+ id: "default",
217
+ positionals: [
218
+ taskKeyPositional,
219
+ { name: "label-name", min: 1, max: null, value: { kind: "label-name" } },
220
+ ],
221
+ },
222
+ ],
223
+ constraints: [],
224
+ },
225
+ };
12
226
  export const taskRouter = {
13
227
  create: {
228
+ summary: "Create a task at the bottom of a column. Without --column, it starts in the project's first column.",
229
+ effects: { domain: "create", storage: "normal-open" },
230
+ confirmation: { kind: "none" },
231
+ input: taskInputs.create,
232
+ results: [jsonResult("Task")],
14
233
  run: (args) => {
15
234
  const { values, positionals, tokens } = parseArgs({
16
235
  args,
17
- options: {
18
- title: { type: "string" },
19
- description: { type: "string" },
20
- priority: { type: "string" },
21
- label: { type: "string", multiple: true },
22
- column: { type: "string" },
23
- parent: { type: "string" },
24
- "depends-on": { type: "string", multiple: true },
25
- "duplicate-of": { type: "string" },
26
- related: { type: "string", multiple: true },
27
- },
236
+ options: taskInputs.create.options,
28
237
  allowPositionals: true,
29
238
  strict: true,
30
239
  tokens: true,
31
240
  });
32
- validateUniqueOptions(tokens, ["label", "depends-on", "related"]);
33
- validatePositionals(positionals, ["[<project-key>]"]);
241
+ validateUniqueOptions(tokens, taskInputs.create.options);
242
+ validatePositionals(positionals, taskInputs.create.forms[0]);
34
243
  const projectKey = resolveProjectKey(positionals[0], { required: true });
35
- if (values.title === undefined) {
36
- quit("A task needs at least a title: use --title");
37
- }
244
+ const title = requireStringOption(taskInputs.create.options.title, values.title, "title", "A task needs at least a title: use --title");
38
245
  const projectMatch = project.getByKey(projectKey);
39
246
  if (projectMatch == null) {
40
- quit(`Project with key "${project.standardizeKey(projectKey)}" does not exist`);
247
+ throw new CliError(`Project with key "${project.standardizeKey(projectKey)}" does not exist`, "not_found", { entity: "project", key: project.standardizeKey(projectKey), source: "explicit" });
41
248
  }
42
249
  const createdTask = task.create({
43
250
  project_id: projectMatch.id,
44
- title: values.title,
251
+ title,
45
252
  description: values.description ?? null,
46
253
  priority: parsePriority(values.priority),
47
254
  labelNames: values.label,
@@ -50,18 +257,20 @@ export const taskRouter = {
50
257
  }, currentActor());
51
258
  output(presentTask(createdTask), formatTaskRow);
52
259
  },
53
- help: `Usage: zinn task create [<project-key>] --title <text> [--description <text>] [--priority {low|medium|high|urgent|none}] [--label <name>]... [--column <name>] [--parent <task-key>] [--depends-on <task-key>]... [--duplicate-of <task-key>] [--related <task-key>]...
260
+ help: `${generateCommandUsage("task create", taskInputs.create)}
54
261
 
55
262
  Create a task at the bottom of a column. Without --column, it starts in the project's first column.
56
263
 
57
- An omitted project key uses defaultProject from settings, if present.
58
- If no default project is set, the key is required.
264
+ ${requiredProjectDescription}
59
265
 
60
266
  Column names are matched case-insensitively. An unknown column is an error and creates nothing.
61
- Priority defaults to none (unassigned).
267
+ Priority defaults to none (unassigned). Priority values are case-insensitive.
268
+ Priority values: ${priorityOption.value.choices.join(", ")}.
62
269
  Repeat --label to attach multiple existing labels. Unknown labels are errors.
63
270
  Label names are matched case-insensitively.
64
- Titles are trimmed and cannot be blank or contain line breaks or control characters. Use --title="--example" for text beginning with a dash.
271
+ Titles are trimmed and cannot be blank or contain line breaks or control characters.
272
+
273
+ ${dashValueHelp("--description")}
65
274
 
66
275
  Relations are set from the new task's perspective: it becomes a subtask of --parent, depends on --depends-on,
67
276
  is a duplicate of --duplicate-of, and is related to --related.
@@ -69,29 +278,28 @@ Repeat --depends-on and --related to name several tasks.
69
278
  A target task that does not exist causes an error, and task creation is aborted.
70
279
 
71
280
  Examples:
72
- zinn task create MDR --title "Refine the numbers" --description "Meet the quarterly quota" --label urgent
73
- zinn task create MDR --title "Review the numbers" --column "In Progress"
74
- zinn task create MDR --title "Sort the files" --parent MDR-1 --depends-on MDR-2`,
281
+ zinn task create MDR --title 'Refine the numbers' --description 'Meet the quarterly quota' --label urgent
282
+ zinn task create MDR --title 'Review the numbers' --column 'In Progress'
283
+ zinn task create MDR --title 'Sort the files' --parent MDR-1 --depends-on MDR-2`,
75
284
  },
76
285
  list: {
286
+ summary: "List active tasks by default.",
287
+ effects: { domain: "read", storage: "normal-open" },
288
+ confirmation: { kind: "none" },
289
+ input: taskInputs.list,
290
+ results: [jsonResult("TaskList")],
77
291
  run: (args) => {
78
292
  const { values, positionals, tokens } = parseArgs({
79
293
  args,
80
- options: {
81
- archived: { type: "boolean" },
82
- all: { type: "boolean" },
83
- "all-projects": { type: "boolean" },
84
- label: { type: "string", multiple: true },
85
- column: { type: "string" },
86
- },
294
+ options: taskInputs.list.options,
87
295
  allowPositionals: true,
88
296
  strict: true,
89
297
  tokens: true,
90
298
  });
91
- validateUniqueOptions(tokens, ["label"]);
92
- validatePositionals(positionals, ["[<project-key>]"]);
93
- if (values.archived && values.all) {
94
- quit('Use either "--archived" or "--all", not both');
299
+ validateUniqueOptions(tokens, taskInputs.list.options);
300
+ validatePositionals(positionals, taskInputs.list.forms[0]);
301
+ if (violatesConstraint(archiveConstraint, getOptionInputs(values))) {
302
+ quit('Use either "--archived" or "--all", not both', undefined, { argument: "--archived" });
95
303
  }
96
304
  const projectKey = resolveProjectKey(positionals[0], { allProjects: values["all-projects"] });
97
305
  const archive = values.all ? "all" : values.archived ? "archived" : "active";
@@ -103,12 +311,10 @@ Examples:
103
311
  });
104
312
  output(tasks.map(presentTask), (presentedTasks) => formatTaskList(presentedTasks, { showsStatus: values.all }));
105
313
  },
106
- help: `Usage: zinn task list [<project-key>|--all-projects] [--archived|--all] [--label <name>]... [--column <name>]
314
+ help: `${generateCommandUsage("task list", taskInputs.list)}
107
315
 
108
316
  List active tasks by default.
109
- An omitted project key uses defaultProject from settings, if present.
110
- If no default project is set, the command lists every project.
111
- Use --all-projects to list every project, overriding the default. It cannot be combined with a typed project key.
317
+ ${projectScopeDescription}
112
318
  Use --archived to list archived tasks or --all to list both.
113
319
  Use --label to filter for tasks with a specific label, no case-sensitivity is applied for matching.
114
320
  Use --column to filter by an exact column name without case sensitivty.
@@ -121,30 +327,29 @@ Use 'task view' to see a task's full details, including its description.
121
327
  Example: zinn task list MDR --label cli`,
122
328
  },
123
329
  search: {
330
+ summary: "Search task titles, descriptions, and comments. A comment match lists the task it belongs to.",
331
+ effects: { domain: "read", storage: "normal-open" },
332
+ confirmation: { kind: "none" },
333
+ input: taskInputs.search,
334
+ results: [jsonResult("TaskList")],
124
335
  run: (args) => {
125
336
  const { values, positionals, tokens } = parseArgs({
126
337
  args,
127
- options: {
128
- archived: { type: "boolean" },
129
- all: { type: "boolean" },
130
- "all-projects": { type: "boolean" },
131
- limit: { type: "string" },
132
- label: { type: "string", multiple: true },
133
- },
338
+ options: taskInputs.search.options,
134
339
  allowPositionals: true,
135
340
  strict: true,
136
341
  tokens: true,
137
342
  });
138
- validateUniqueOptions(tokens, ["label"]);
139
- validatePositionals(positionals, ["<query>", "[<project-key>]"]);
343
+ validateUniqueOptions(tokens, taskInputs.search.options);
344
+ validatePositionals(positionals, taskInputs.search.forms[0]);
140
345
  const query = positionals[0];
141
- if (values.archived && values.all) {
142
- quit('Use either "--archived" or "--all", not both');
346
+ if (violatesConstraint(archiveConstraint, getOptionInputs(values))) {
347
+ quit('Use either "--archived" or "--all", not both', undefined, { argument: "--archived" });
143
348
  }
144
349
  const archive = values.all ? "all" : values.archived ? "archived" : "active";
145
- const limitPattern = new RegExp(`^${positiveIntegerPattern}$`);
350
+ const limitPattern = new RegExp(taskInputs.search.options.limit.value.pattern);
146
351
  if (values.limit !== undefined && !limitPattern.test(values.limit)) {
147
- quit(searchLimitMessage);
352
+ quit(searchLimitMessage, undefined, { argument: "--limit" });
148
353
  }
149
354
  const isTaskKeyQuery = parseTaskKey(query.trim()) !== null;
150
355
  const projectKey = resolveProjectKey(positionals[1], {
@@ -163,15 +368,13 @@ Example: zinn task list MDR --label cli`,
163
368
  if (result.hiddenArchivedCount > 0) {
164
369
  const count = result.hiddenArchivedCount;
165
370
  const noun = count === 1 ? "match" : "matches";
166
- console.error(`${count} archived ${noun} hidden, use --all to include them`);
371
+ diagnostic(`${count} archived ${noun} hidden, use --all to include them`);
167
372
  }
168
373
  },
169
- help: `Usage: zinn task search <query> [<project-key>|--all-projects] [--archived|--all] [--limit <n>] [--label <name>]...
374
+ help: `${generateCommandUsage("task search", taskInputs.search)}
170
375
 
171
376
  Search task titles, descriptions, and comments. A comment match lists the task it belongs to.
172
- An omitted project key uses defaultProject from settings, if present.
173
- If no default project is set, the command searches every project.
174
- Use --all-projects to search every project, overriding the default. It cannot be combined with a typed project key.
377
+ ${projectScopeDescription}
175
378
  Each word matches the start of a word, ignoring case and accents: e.g. "auth" finds "Authentication".
176
379
  Every word must match. Quote a query with several words.
177
380
 
@@ -186,32 +389,38 @@ Use --limit to show at most <n> results.
186
389
  Use --label to filter for tasks with a specific label, no case-sensitivity is applied for matching.
187
390
  A search result's output matches that of 'task list'.
188
391
 
189
- Example: zinn task search "refinement quota" MDR --limit 5`,
392
+ Example: zinn task search 'refinement quota' MDR --limit 5`,
190
393
  },
191
394
  view: {
395
+ summary: "Show a task with its description, relations, and comments.",
396
+ effects: { domain: "read", storage: "normal-open" },
397
+ confirmation: { kind: "none" },
398
+ input: taskInputs.view,
399
+ results: taskDetailResults,
192
400
  run: (args) => {
193
401
  const { values, positionals, tokens } = parseArgs({
194
402
  args,
195
- options: { history: { type: "boolean" } },
403
+ options: taskInputs.view.options,
196
404
  allowPositionals: true,
197
405
  strict: true,
198
406
  tokens: true,
199
407
  });
200
- validateUniqueOptions(tokens);
201
- validatePositionals(positionals, ["<task-key>"]);
408
+ validateUniqueOptions(tokens, taskInputs.view.options);
409
+ validatePositionals(positionals, taskInputs.view.forms[0]);
202
410
  const taskMatch = task.getByKey(positionals[0]);
203
- const viewedTask = {
411
+ const detail = {
204
412
  ...presentTask(taskMatch),
205
413
  relations: presentRelations(taskMatch),
206
414
  comments: presentComments(taskMatch.key),
207
- ...(values.history === true
208
- ? {
209
- activity: task
210
- .activity(taskMatch.key)
211
- .sort((left, right) => right.created_at - left.created_at || right.id.localeCompare(left.id)),
212
- }
213
- : {}),
214
415
  };
416
+ const viewedTask = values.history === true
417
+ ? {
418
+ ...detail,
419
+ activity: task
420
+ .activity(taskMatch.key)
421
+ .sort((left, right) => right.created_at - left.created_at || right.id.localeCompare(left.id)),
422
+ }
423
+ : { ...detail };
215
424
  output(viewedTask, (t) => {
216
425
  const MIN_SECTION_SEPARATOR_WIDTH = 60;
217
426
  const terminalWidth = process.stdout.columns;
@@ -234,7 +443,7 @@ Example: zinn task search "refinement quota" MDR --limit 5`,
234
443
  if (comments.length > 0) {
235
444
  sections.push(formatSection("Comments", comments, sectionOptions));
236
445
  }
237
- if (t.activity !== undefined) {
446
+ if ("activity" in t) {
238
447
  const history = formatActivityList(presentActivities(t.activity));
239
448
  if (history.length > 0) {
240
449
  sections.push(formatSection("History", history, sectionOptions));
@@ -243,7 +452,7 @@ Example: zinn task search "refinement quota" MDR --limit 5`,
243
452
  return sections.join("\n\n");
244
453
  });
245
454
  },
246
- help: `Usage: zinn task view <task-key> [--history]
455
+ help: `${generateCommandUsage("task view", taskInputs.view)}
247
456
 
248
457
  Show a task with its description, relations, and comments.
249
458
  A section is shown when the task has that content. The description prints in full, keeping its line breaks.
@@ -257,32 +466,25 @@ Examples:
257
466
  zinn task view MDR-1 --history`,
258
467
  },
259
468
  edit: {
469
+ summary: "Edit a task's title, description, priority, or label attachments.",
470
+ effects: { domain: "update", storage: "normal-open" },
471
+ confirmation: { kind: "none" },
472
+ input: taskInputs.edit,
473
+ results: [jsonResult("Task")],
260
474
  run: (args) => {
261
475
  const { values, positionals, tokens } = parseArgs({
262
476
  args,
263
- options: {
264
- title: { type: "string" },
265
- description: { type: "string" },
266
- ...textEditOptions,
267
- priority: { type: "string" },
268
- "add-label": { type: "string", multiple: true },
269
- "remove-label": { type: "string", multiple: true },
270
- },
477
+ options: taskInputs.edit.options,
271
478
  allowPositionals: true,
272
479
  strict: true,
273
480
  tokens: true,
274
481
  });
275
- validateUniqueOptions(tokens, ["add-label", "remove-label"]);
276
- validatePositionals(positionals, ["<task-key>"]);
482
+ validateUniqueOptions(tokens, taskInputs.edit.options);
483
+ validatePositionals(positionals, taskInputs.edit.forms[0]);
277
484
  const taskKey = positionals[0];
278
485
  const description = resolveTextEdit(values.description, values, "--description");
279
- const hasEditFlags = values.title !== undefined ||
280
- description !== undefined ||
281
- values.priority !== undefined ||
282
- values["add-label"] !== undefined ||
283
- values["remove-label"] !== undefined;
284
- if (!hasEditFlags) {
285
- quit("Provide at least one edit flag: --title, --description, --priority, --add-label, or --remove-label");
486
+ if (violatesConstraint(taskEditConstraint, getOptionInputs({ ...values, description }))) {
487
+ quit("Provide at least one edit flag: --title, --description, --priority, --add-label, or --remove-label", undefined, { field: [] });
286
488
  }
287
489
  const editedTask = task.edit({
288
490
  taskKey,
@@ -294,11 +496,12 @@ Examples:
294
496
  }, currentActor());
295
497
  output(presentTask(editedTask), formatTaskRow);
296
498
  },
297
- help: `Usage: zinn task edit <task-key> [--title <text>] [--description <text> ${textEditUsage}] [--priority {low|medium|high|urgent|none}] [--add-label <name>]... [--remove-label <name>]...
499
+ help: `${generateCommandUsage("task edit", taskInputs.edit)}
298
500
 
299
501
  Edit a task's title, description, priority, or label attachments.
300
- Use --priority none to clear priority.
301
- Provide at least one edit flag. Use --description "" to clear the description.
502
+ Use --priority none to clear priority. Priority values are case-insensitive.
503
+ Priority values: ${priorityOption.value.choices.join(", ")}.
504
+ Provide at least one edit flag. Use --description '' to clear the description.
302
505
 
303
506
  ${textEditHelp("--description")}
304
507
 
@@ -310,22 +513,36 @@ Archived tasks can be edited.
310
513
  The same label cannot be both added and removed.
311
514
  Titles are trimmed and cannot be blank or contain line breaks or control characters.
312
515
 
313
- Use --title="--example" for text beginning with a dash.
516
+ ${dashValueHelp("--description")}
314
517
 
315
518
  Examples:
316
- zinn task edit MDR-1 --title "Meet the quarterly refinement quota"
317
- zinn task edit MDR-1 --description "Bring waffles." --append`,
519
+ zinn task edit MDR-1 --title 'Meet the quarterly refinement quota'
520
+ zinn task edit MDR-1 --description 'Bring waffles.' --append`,
521
+ guessedFlags: {
522
+ "--status": (args) => suggestTaskMove(args, taskInputs.edit.options),
523
+ "--column": (args) => suggestTaskMove(args, taskInputs.edit.options),
524
+ },
318
525
  },
319
526
  move: {
527
+ summary: "Move tasks to another column in their projects.",
528
+ effects: { domain: "update", storage: "normal-open" },
529
+ confirmation: { kind: "none" },
530
+ input: taskInputs.move,
531
+ results: taskChangeResults,
320
532
  run: (args) => {
321
- const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
322
- validatePositionals(positionals, ["<task-key>...", "<target-column>"]);
533
+ const { positionals } = parseArgs({
534
+ options: taskInputs.move.options,
535
+ args,
536
+ allowPositionals: true,
537
+ strict: true,
538
+ });
539
+ validatePositionals(positionals, taskInputs.move.forms[0]);
323
540
  const taskKeys = positionals.slice(0, -1);
324
541
  const targetColumn = positionals.at(-1);
325
542
  const moves = task.moveMany({ taskKeys, targetColumn }, currentActor());
326
543
  outputTaskChanges(moves, formatTaskList, (movedTask) => `${movedTask.key} was already in the ${movedTask.column} column`);
327
544
  },
328
- help: `Usage: zinn task move <task-key>... <target-column>
545
+ help: `${generateCommandUsage("task move", taskInputs.move)}
329
546
 
330
547
  Move tasks to another column in their projects.
331
548
  Moving a task to a different column lists it last in that column,
@@ -339,42 +556,36 @@ On bulk changes, if any task cannot be moved, the bulk operation is aborted.
339
556
  With --json, one task prints an object and several print an array.
340
557
  Each task's changed field is 'false' when it was already in the requested state.
341
558
 
342
- Example: zinn task move MDR-1 MDR-2 "In Progress"`,
559
+ Example: zinn task move MDR-1 MDR-2 'In Progress'`,
560
+ guessedFlags: { "--status": suggestTaskMove, "--column": suggestTaskMove },
343
561
  },
344
562
  order: {
563
+ summary: "Change a task's position within its current column.",
564
+ effects: { domain: "update", storage: "normal-open" },
565
+ confirmation: { kind: "none" },
566
+ input: taskInputs.order,
567
+ results: [jsonResult("Task")],
345
568
  run: (args) => {
346
- const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
347
- /**
348
- * The words every direction needs. Only whether they are there is checked here,
349
- * since the direction decides whether a target task follows.
350
- */
351
- const leadingWords = ["<task-key>", "{top|up|down|bottom|before|after}"];
352
- validatePositionals(positionals.slice(0, leadingWords.length), leadingWords);
569
+ const { positionals } = parseArgs({
570
+ options: taskInputs.order.options,
571
+ args,
572
+ allowPositionals: true,
573
+ strict: true,
574
+ });
575
+ const form = validateOrderForms(positionals, taskInputs.order.forms);
353
576
  const taskKey = positionals[0];
354
- const direction = positionals[1];
355
- switch (direction) {
356
- case "before":
357
- case "after": {
358
- validatePositionals(positionals, [...leadingWords, "<target-task-key>"]);
359
- const orderedTask = task.order({ taskKey, direction, targetTaskKey: positionals[2] }, currentActor());
360
- output(presentTask(orderedTask), formatTaskRow);
361
- return;
362
- }
363
- case "top":
364
- case "up":
365
- case "down":
366
- case "bottom": {
367
- validatePositionals(positionals, leadingWords);
368
- const orderedTask = task.order({ taskKey, direction }, currentActor());
369
- output(presentTask(orderedTask), formatTaskRow);
370
- return;
371
- }
372
- default:
373
- throw new UsageError(`Unknown order direction "${direction}"`);
577
+ if (form.id === "relative") {
578
+ const direction = positionals[1];
579
+ const orderedTask = task.order({ taskKey, direction, targetTaskKey: positionals[2] }, currentActor());
580
+ output(presentTask(orderedTask), formatTaskRow);
581
+ }
582
+ else {
583
+ const direction = positionals[1];
584
+ const orderedTask = task.order({ taskKey, direction }, currentActor());
585
+ output(presentTask(orderedTask), formatTaskRow);
374
586
  }
375
587
  },
376
- help: `Usage: zinn task order <task-key> {top|up|down|bottom}
377
- zinn task order <task-key> {before|after} <target-task-key>
588
+ help: `${generateCommandUsage("task order", taskInputs.order)}
378
589
 
379
590
  Change a task's position within its current column.
380
591
  Use top or bottom for either end, up or down for one position,
@@ -383,12 +594,17 @@ or before or after to place it relative to another task.
383
594
  Example: zinn task order MDR-2 before MDR-1`,
384
595
  },
385
596
  archive: {
597
+ summary: "Archive tasks so they no longer appear in active task lists.",
598
+ effects: { domain: "update", storage: "normal-open" },
599
+ confirmation: { kind: "none" },
600
+ input: taskInputs.archive,
601
+ results: taskChangeResults,
386
602
  run: (args) => {
387
603
  const taskKeys = parseTaskKeys(args);
388
604
  const archives = task.archiveMany(taskKeys, currentActor());
389
605
  outputTaskChanges(archives, formatTaskListWithStatus, (archivedTask) => `${archivedTask.key} was already archived`);
390
606
  },
391
- help: `Usage: zinn task archive <task-key>...
607
+ help: `${generateCommandUsage("task archive", taskInputs.archive)}
392
608
 
393
609
  Archive tasks so they no longer appear in active task lists.
394
610
  Archiving an archived task does not do anything.
@@ -400,12 +616,17 @@ Each task's changed field is 'false' when it was already in the requested state.
400
616
  Example: zinn task archive MDR-1 MDR-2`,
401
617
  },
402
618
  unarchive: {
619
+ summary: "Unarchive tasks at the bottom of their previous columns, in the order given.",
620
+ effects: { domain: "update", storage: "normal-open" },
621
+ confirmation: { kind: "none" },
622
+ input: taskInputs.archive,
623
+ results: taskChangeResults,
403
624
  run: (args) => {
404
625
  const taskKeys = parseTaskKeys(args);
405
626
  const unarchives = task.unarchiveMany(taskKeys, currentActor());
406
627
  outputTaskChanges(unarchives, formatTaskListWithStatus, (unarchivedTask) => `${unarchivedTask.key} was already active`);
407
628
  },
408
- help: `Usage: zinn task unarchive <task-key>...
629
+ help: `${generateCommandUsage("task unarchive", taskInputs.archive)}
409
630
 
410
631
  Unarchive tasks at the bottom of their previous columns, in the order given.
411
632
  Unarchiving an active task does not do anything.
@@ -417,16 +638,21 @@ Each task's changed field is 'false' when it was already in the requested state.
417
638
  Example: zinn task unarchive MDR-1 MDR-2`,
418
639
  },
419
640
  delete: {
641
+ summary: "Permanently delete a task after confirmation.",
642
+ effects: { domain: "delete", storage: "normal-open" },
643
+ confirmation: { kind: "prompt", description: confirmationDescription },
644
+ input: taskInputs.delete,
645
+ results: [jsonResult("Task")],
420
646
  run: async (args) => {
421
647
  const { values, positionals, tokens } = parseArgs({
422
648
  args,
423
- options: { yes: { type: "boolean" } },
649
+ options: taskInputs.delete.options,
424
650
  allowPositionals: true,
425
651
  strict: true,
426
652
  tokens: true,
427
653
  });
428
- validateUniqueOptions(tokens);
429
- validatePositionals(positionals, ["<task-key>"]);
654
+ validateUniqueOptions(tokens, taskInputs.delete.options);
655
+ validatePositionals(positionals, taskInputs.delete.forms[0]);
430
656
  const taskKey = positionals[0];
431
657
  try {
432
658
  const taskMatch = task.getByKey(taskKey);
@@ -441,10 +667,10 @@ Example: zinn task unarchive MDR-1 MDR-2`,
441
667
  }
442
668
  }
443
669
  catch (err) {
444
- quit(failureMessage(err, "Something went wrong"));
670
+ throw err;
445
671
  }
446
672
  },
447
- help: `Usage: zinn task delete <task-key> [--yes]
673
+ help: `${generateCommandUsage("task delete", taskInputs.delete)}
448
674
 
449
675
  Permanently delete a task after confirmation.
450
676
  Use --yes to skip the confirmation prompt, for example in scripts or with --json.
@@ -455,29 +681,44 @@ Example: zinn task delete MDR-1`,
455
681
  comment: commentRouter,
456
682
  label: {
457
683
  add: {
684
+ summary: "Add existing labels to a task. Label names are matched case-insensitively.",
685
+ effects: { domain: "update", storage: "normal-open" },
686
+ confirmation: { kind: "none" },
687
+ input: taskInputs.label_add,
688
+ results: [jsonResult("Task")],
458
689
  run: (args) => {
459
690
  const props = parseTaskLabelArgs(args);
460
691
  output(presentTask(task.label.add(props, currentActor())), formatTaskRow);
461
692
  },
462
- help: `Usage: zinn task label add <task-key> <label-name>...
693
+ help: `${generateCommandUsage("task label add", taskInputs.label_add)}
463
694
 
464
695
  Add existing labels to a task. Label names are matched case-insensitively.
465
696
  Already attached labels are unchanged.`,
466
697
  },
467
698
  remove: {
699
+ summary: "Remove existing labels from a task. Label names are matched case-insensitively.",
700
+ effects: { domain: "update", storage: "normal-open" },
701
+ confirmation: { kind: "none" },
702
+ input: taskInputs.label_add,
703
+ results: [jsonResult("Task")],
468
704
  run: (args) => {
469
705
  const props = parseTaskLabelArgs(args);
470
706
  output(presentTask(task.label.remove(props, currentActor())), formatTaskRow);
471
707
  },
472
- help: `Usage: zinn task label remove <task-key> <label-name>...
708
+ help: `${generateCommandUsage("task label remove", taskInputs.label_add)}
473
709
 
474
710
  Remove existing labels from a task. Label names are matched case-insensitively.`,
475
711
  },
476
712
  },
477
713
  };
478
714
  function parseTaskKeys(args) {
479
- const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
480
- validatePositionals(positionals, ["<task-key>..."]);
715
+ const { positionals } = parseArgs({
716
+ options: taskInputs.archive.options,
717
+ args,
718
+ allowPositionals: true,
719
+ strict: true,
720
+ });
721
+ validatePositionals(positionals, taskInputs.archive.forms[0]);
481
722
  return positionals;
482
723
  }
483
724
  /**
@@ -485,10 +726,19 @@ function parseTaskKeys(args) {
485
726
  * JSON includes each task's `changed` flag, and each unchanged task also gets a note on stderr.
486
727
  */
487
728
  function outputTaskChanges(changes, formatTasks, describeUnchanged) {
488
- const presentedChanges = changes.map((change) => ({
489
- ...presentTask(change.task),
490
- changed: change.changed,
491
- }));
729
+ const presentedChanges = changes.map((change) => {
730
+ const presentedTask = presentTask(change.task);
731
+ return {
732
+ key: presentedTask.key,
733
+ status: presentedTask.status,
734
+ column: presentedTask.column,
735
+ title: presentedTask.title,
736
+ description: presentedTask.description,
737
+ priority: presentedTask.priority,
738
+ labels: presentedTask.labels,
739
+ changed: change.changed,
740
+ };
741
+ });
492
742
  if (presentedChanges.length === 1) {
493
743
  output(presentedChanges[0], (presentedChange) => formatTasks([presentedChange]));
494
744
  }
@@ -497,13 +747,18 @@ function outputTaskChanges(changes, formatTasks, describeUnchanged) {
497
747
  }
498
748
  for (const presentedChange of presentedChanges) {
499
749
  if (!presentedChange.changed) {
500
- console.error(describeUnchanged(presentedChange));
750
+ diagnostic(describeUnchanged(presentedChange));
501
751
  }
502
752
  }
503
753
  }
504
754
  function parseTaskLabelArgs(args) {
505
- const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
506
- validatePositionals(positionals, ["<task-key>", "<label-name>..."]);
755
+ const { positionals } = parseArgs({
756
+ options: taskInputs.label_add.options,
757
+ args,
758
+ strict: true,
759
+ allowPositionals: true,
760
+ });
761
+ validatePositionals(positionals, taskInputs.label_add.forms[0]);
507
762
  return { taskKey: positionals[0], labelNames: positionals.slice(1) };
508
763
  }
509
764
  // The new task is the source of each relation, so a flag names the type from its point of view.
@@ -517,17 +772,18 @@ function parseNewTaskRelations(flags) {
517
772
  return targetsByType.flatMap(([relation_type, targetTaskKeys]) => targetTaskKeys.map((targetTaskKey) => ({ relation_type, targetTaskKey })));
518
773
  }
519
774
  function parsePriority(value) {
520
- switch (value) {
521
- case undefined:
522
- return undefined;
523
- case "none":
524
- return null;
525
- case "low":
526
- case "medium":
527
- case "high":
528
- case "urgent":
529
- return value;
530
- default:
531
- quit("Priority must be low, medium, high, urgent, or none");
775
+ const normalizedPriority = value?.toLowerCase();
776
+ if (normalizedPriority === undefined) {
777
+ return undefined;
778
+ }
779
+ if (normalizedPriority === "none") {
780
+ return null;
781
+ }
782
+ const priority = taskPrioritySchema.safeParse(normalizedPriority);
783
+ if (!priority.success) {
784
+ quit("Priority must be low, medium, high, urgent, or none", undefined, {
785
+ argument: "--priority",
786
+ });
532
787
  }
788
+ return priority.data;
533
789
  }