@zinn-dev/cli 0.39.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 (113) hide show
  1. package/README.md +171 -40
  2. package/index.d.ts +2 -0
  3. package/index.js +34 -0
  4. package/package.json +27 -18
  5. package/skills/zinn/SKILL.md +63 -0
  6. package/src/actor.d.ts +7 -0
  7. package/src/actor.js +129 -0
  8. package/src/capabilities-schema.d.ts +163 -0
  9. package/src/capabilities-schema.js +124 -0
  10. package/src/capabilities.d.ts +21 -0
  11. package/src/capabilities.js +22 -0
  12. package/src/database.d.ts +6 -0
  13. package/src/database.js +27 -0
  14. package/src/errors.d.ts +158 -0
  15. package/src/errors.js +224 -0
  16. package/src/input.d.ts +116 -0
  17. package/src/input.js +119 -0
  18. package/src/lib.d.ts +66 -0
  19. package/src/lib.js +333 -0
  20. package/src/presentation/activity-presentation.d.ts +23 -0
  21. package/src/presentation/activity-presentation.js +403 -0
  22. package/src/presentation/color.d.ts +9 -0
  23. package/src/presentation/color.js +21 -0
  24. package/src/presentation/column-presentation.d.ts +14 -0
  25. package/src/presentation/column-presentation.js +29 -0
  26. package/src/presentation/description-presentation.d.ts +3 -0
  27. package/src/presentation/description-presentation.js +11 -0
  28. package/src/presentation/info-presentation.d.ts +4 -0
  29. package/src/presentation/info-presentation.js +96 -0
  30. package/src/presentation/row-layout.d.ts +22 -0
  31. package/src/presentation/row-layout.js +58 -0
  32. package/src/presentation/section.d.ts +4 -0
  33. package/src/presentation/section.js +9 -0
  34. package/src/presentation/task-presentation.d.ts +9 -0
  35. package/src/presentation/task-presentation.js +62 -0
  36. package/src/presentation/time.d.ts +1 -0
  37. package/src/presentation/time.js +13 -0
  38. package/src/project.d.ts +12 -0
  39. package/src/project.js +44 -0
  40. package/src/release-identity.d.ts +2 -0
  41. package/src/release-identity.js +1 -0
  42. package/src/result-schemas.d.ts +987 -0
  43. package/src/result-schemas.js +220 -0
  44. package/src/results.d.ts +23 -0
  45. package/src/results.js +17 -0
  46. package/src/routes/activity-router.d.ts +81 -0
  47. package/src/routes/activity-router.js +119 -0
  48. package/src/routes/backup-router.d.ts +21 -0
  49. package/src/routes/backup-router.js +30 -0
  50. package/src/routes/capabilities-router.d.ts +21 -0
  51. package/src/routes/capabilities-router.js +28 -0
  52. package/src/routes/comment-router.d.ts +203 -0
  53. package/src/routes/comment-router.js +241 -0
  54. package/src/routes/info-router.d.ts +21 -0
  55. package/src/routes/info-router.js +29 -0
  56. package/src/routes/label-router.d.ts +183 -0
  57. package/src/routes/label-router.js +218 -0
  58. package/src/routes/migrate-router.d.ts +21 -0
  59. package/src/routes/migrate-router.js +49 -0
  60. package/src/routes/project-router.d.ts +389 -0
  61. package/src/routes/project-router.js +514 -0
  62. package/src/routes/reindex-router.d.ts +21 -0
  63. package/src/routes/reindex-router.js +33 -0
  64. package/src/routes/relation-router.d.ts +124 -0
  65. package/src/routes/relation-router.js +223 -0
  66. package/src/routes/restore-router.d.ts +33 -0
  67. package/src/routes/restore-router.js +88 -0
  68. package/src/routes/router.d.ts +6 -0
  69. package/src/routes/router.js +204 -0
  70. package/src/routes/routes.d.ts +1735 -0
  71. package/src/routes/routes.js +23 -0
  72. package/src/routes/task-router.d.ts +945 -0
  73. package/src/routes/task-router.js +789 -0
  74. package/src/text-edit.d.ts +43 -0
  75. package/src/text-edit.js +57 -0
  76. package/src/types.d.ts +24 -0
  77. package/src/types.js +1 -0
  78. package/index.ts +0 -26
  79. package/release-stamp.json +0 -1
  80. package/src/actor.test.ts +0 -41
  81. package/src/actor.ts +0 -78
  82. package/src/database.test.ts +0 -70
  83. package/src/database.ts +0 -41
  84. package/src/lib.test.ts +0 -86
  85. package/src/lib.ts +0 -159
  86. package/src/presentation/activity-presentation.test.ts +0 -112
  87. package/src/presentation/activity-presentation.ts +0 -490
  88. package/src/presentation/color.ts +0 -29
  89. package/src/presentation/column-presentation.ts +0 -48
  90. package/src/presentation/description-presentation.ts +0 -18
  91. package/src/presentation/row-layout.ts +0 -77
  92. package/src/presentation/section.ts +0 -16
  93. package/src/presentation/task-presentation.ts +0 -92
  94. package/src/presentation/time.ts +0 -17
  95. package/src/project.test.ts +0 -479
  96. package/src/project.ts +0 -53
  97. package/src/routes/activity-router.ts +0 -81
  98. package/src/routes/backup-router.ts +0 -24
  99. package/src/routes/comment-router.ts +0 -171
  100. package/src/routes/label-router.ts +0 -168
  101. package/src/routes/migrate-router.test.ts +0 -31
  102. package/src/routes/migrate-router.ts +0 -48
  103. package/src/routes/project-router.ts +0 -415
  104. package/src/routes/reindex-router.ts +0 -27
  105. package/src/routes/relation-router.ts +0 -194
  106. package/src/routes/restore-router.test.ts +0 -44
  107. package/src/routes/restore-router.ts +0 -90
  108. package/src/routes/router.test.ts +0 -136
  109. package/src/routes/router.ts +0 -248
  110. package/src/routes/routes.ts +0 -20
  111. package/src/routes/task-router.ts +0 -649
  112. package/src/text-edit.ts +0 -68
  113. package/src/types.ts +0 -6
@@ -0,0 +1,789 @@
1
+ import { jsonResult, taskDetailResults, taskChangeResults } from "../results.js";
2
+ import { parseArgs } from "node:util";
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";
8
+ import { formatRelations, presentRelations, relationRouter } from "./relation-router.js";
9
+ import { commentRouter, formatComments, presentComments } from "./comment-router.js";
10
+ import { currentActor } from "../actor.js";
11
+ import { resolveProjectKey, projectScopeConstraint, requiredProjectDescription, projectScopeDescription, } from "../project.js";
12
+ import { formatSection } from "../presentation/section.js";
13
+ import { formatActivityList, presentActivities } from "../presentation/activity-presentation.js";
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
+ };
226
+ export const taskRouter = {
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")],
233
+ run: (args) => {
234
+ const { values, positionals, tokens } = parseArgs({
235
+ args,
236
+ options: taskInputs.create.options,
237
+ allowPositionals: true,
238
+ strict: true,
239
+ tokens: true,
240
+ });
241
+ validateUniqueOptions(tokens, taskInputs.create.options);
242
+ validatePositionals(positionals, taskInputs.create.forms[0]);
243
+ const projectKey = resolveProjectKey(positionals[0], { required: true });
244
+ const title = requireStringOption(taskInputs.create.options.title, values.title, "title", "A task needs at least a title: use --title");
245
+ const projectMatch = project.getByKey(projectKey);
246
+ if (projectMatch == null) {
247
+ throw new CliError(`Project with key "${project.standardizeKey(projectKey)}" does not exist`, "not_found", { entity: "project", key: project.standardizeKey(projectKey), source: "explicit" });
248
+ }
249
+ const createdTask = task.create({
250
+ project_id: projectMatch.id,
251
+ title,
252
+ description: values.description ?? null,
253
+ priority: parsePriority(values.priority),
254
+ labelNames: values.label,
255
+ columnName: values.column,
256
+ relations: parseNewTaskRelations(values),
257
+ }, currentActor());
258
+ output(presentTask(createdTask), formatTaskRow);
259
+ },
260
+ help: `${generateCommandUsage("task create", taskInputs.create)}
261
+
262
+ Create a task at the bottom of a column. Without --column, it starts in the project's first column.
263
+
264
+ ${requiredProjectDescription}
265
+
266
+ Column names are matched case-insensitively. An unknown column is an error and creates nothing.
267
+ Priority defaults to none (unassigned). Priority values are case-insensitive.
268
+ Priority values: ${priorityOption.value.choices.join(", ")}.
269
+ Repeat --label to attach multiple existing labels. Unknown labels are errors.
270
+ Label names are matched case-insensitively.
271
+ Titles are trimmed and cannot be blank or contain line breaks or control characters.
272
+
273
+ ${dashValueHelp("--description")}
274
+
275
+ Relations are set from the new task's perspective: it becomes a subtask of --parent, depends on --depends-on,
276
+ is a duplicate of --duplicate-of, and is related to --related.
277
+ Repeat --depends-on and --related to name several tasks.
278
+ A target task that does not exist causes an error, and task creation is aborted.
279
+
280
+ Examples:
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`,
284
+ },
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")],
291
+ run: (args) => {
292
+ const { values, positionals, tokens } = parseArgs({
293
+ args,
294
+ options: taskInputs.list.options,
295
+ allowPositionals: true,
296
+ strict: true,
297
+ tokens: true,
298
+ });
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" });
303
+ }
304
+ const projectKey = resolveProjectKey(positionals[0], { allProjects: values["all-projects"] });
305
+ const archive = values.all ? "all" : values.archived ? "archived" : "active";
306
+ const tasks = task.getAll({
307
+ projectKey,
308
+ archive,
309
+ labelNames: values.label,
310
+ columnName: values.column,
311
+ });
312
+ output(tasks.map(presentTask), (presentedTasks) => formatTaskList(presentedTasks, { showsStatus: values.all }));
313
+ },
314
+ help: `${generateCommandUsage("task list", taskInputs.list)}
315
+
316
+ List active tasks by default.
317
+ ${projectScopeDescription}
318
+ Use --archived to list archived tasks or --all to list both.
319
+ Use --label to filter for tasks with a specific label, no case-sensitivity is applied for matching.
320
+ Use --column to filter by an exact column name without case sensitivty.
321
+ Column, label and archive filters can be combined together. No matches print nothing, or return [] for --json, and exit successfully.
322
+
323
+ Each row shows a task's key, column, priority marker, title, and labels. --all adds an Active or Archived status after the key.
324
+ Priority markers: - unassigned, L low, M medium, H high, U urgent.
325
+ Use 'task view' to see a task's full details, including its description.
326
+
327
+ Example: zinn task list MDR --label cli`,
328
+ },
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")],
335
+ run: (args) => {
336
+ const { values, positionals, tokens } = parseArgs({
337
+ args,
338
+ options: taskInputs.search.options,
339
+ allowPositionals: true,
340
+ strict: true,
341
+ tokens: true,
342
+ });
343
+ validateUniqueOptions(tokens, taskInputs.search.options);
344
+ validatePositionals(positionals, taskInputs.search.forms[0]);
345
+ const query = positionals[0];
346
+ if (violatesConstraint(archiveConstraint, getOptionInputs(values))) {
347
+ quit('Use either "--archived" or "--all", not both', undefined, { argument: "--archived" });
348
+ }
349
+ const archive = values.all ? "all" : values.archived ? "archived" : "active";
350
+ const limitPattern = new RegExp(taskInputs.search.options.limit.value.pattern);
351
+ if (values.limit !== undefined && !limitPattern.test(values.limit)) {
352
+ quit(searchLimitMessage, undefined, { argument: "--limit" });
353
+ }
354
+ const isTaskKeyQuery = parseTaskKey(query.trim()) !== null;
355
+ const projectKey = resolveProjectKey(positionals[1], {
356
+ allProjects: values["all-projects"],
357
+ useDefault: !isTaskKeyQuery,
358
+ });
359
+ const limit = values.limit === undefined ? undefined : Number(values.limit);
360
+ const result = task.search({
361
+ query,
362
+ projectKey,
363
+ archive,
364
+ limit,
365
+ labelNames: values.label,
366
+ });
367
+ output(result.tasks.map(presentTask), (presentedTasks) => formatTaskList(presentedTasks, { showsStatus: values.all }));
368
+ if (result.hiddenArchivedCount > 0) {
369
+ const count = result.hiddenArchivedCount;
370
+ const noun = count === 1 ? "match" : "matches";
371
+ diagnostic(`${count} archived ${noun} hidden, use --all to include them`);
372
+ }
373
+ },
374
+ help: `${generateCommandUsage("task search", taskInputs.search)}
375
+
376
+ Search task titles, descriptions, and comments. A comment match lists the task it belongs to.
377
+ ${projectScopeDescription}
378
+ Each word matches the start of a word, ignoring case and accents: e.g. "auth" finds "Authentication".
379
+ Every word must match. Quote a query with several words.
380
+
381
+ A query that is exactly a task key, such as MDR-1, lists that task first.
382
+ If given, a task key query overrides the configured default, and a typed project key still filters the search.
383
+ Other results are ordered by relevance, with title matches weighted highest.
384
+ Equally relevant tasks are ordered by project key, then task number.
385
+
386
+ By default, only active tasks are searched. Use --archived to search archived tasks or --all to search both.
387
+ When archived matches are hidden, a note is printed to say how many.
388
+ Use --limit to show at most <n> results.
389
+ Use --label to filter for tasks with a specific label, no case-sensitivity is applied for matching.
390
+ A search result's output matches that of 'task list'.
391
+
392
+ Example: zinn task search 'refinement quota' MDR --limit 5`,
393
+ },
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,
400
+ run: (args) => {
401
+ const { values, positionals, tokens } = parseArgs({
402
+ args,
403
+ options: taskInputs.view.options,
404
+ allowPositionals: true,
405
+ strict: true,
406
+ tokens: true,
407
+ });
408
+ validateUniqueOptions(tokens, taskInputs.view.options);
409
+ validatePositionals(positionals, taskInputs.view.forms[0]);
410
+ const taskMatch = task.getByKey(positionals[0]);
411
+ const detail = {
412
+ ...presentTask(taskMatch),
413
+ relations: presentRelations(taskMatch),
414
+ comments: presentComments(taskMatch.key),
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 };
424
+ output(viewedTask, (t) => {
425
+ const MIN_SECTION_SEPARATOR_WIDTH = 60;
426
+ const terminalWidth = process.stdout.columns;
427
+ const hasTerminalWidth = process.stdout.isTTY === true && terminalWidth > 0;
428
+ const sectionOptions = {
429
+ separatorWidth: hasTerminalWidth ? terminalWidth : MIN_SECTION_SEPARATOR_WIDTH,
430
+ };
431
+ const relations = formatRelations(t.relations);
432
+ const comments = formatComments(t.comments);
433
+ const isArchived = t.status === "Archived";
434
+ const sections = [
435
+ formatTaskList([t], { showsStatus: isArchived, showsFullPriority: true }),
436
+ ];
437
+ if (t.description != null) {
438
+ sections.push(formatSection("Description", t.description, sectionOptions));
439
+ }
440
+ if (relations.length > 0) {
441
+ sections.push(formatSection("Relations", relations, sectionOptions));
442
+ }
443
+ if (comments.length > 0) {
444
+ sections.push(formatSection("Comments", comments, sectionOptions));
445
+ }
446
+ if ("activity" in t) {
447
+ const history = formatActivityList(presentActivities(t.activity));
448
+ if (history.length > 0) {
449
+ sections.push(formatSection("History", history, sectionOptions));
450
+ }
451
+ }
452
+ return sections.join("\n\n");
453
+ });
454
+ },
455
+ help: `${generateCommandUsage("task view", taskInputs.view)}
456
+
457
+ Show a task with its description, relations, and comments.
458
+ A section is shown when the task has that content. The description prints in full, keeping its line breaks.
459
+ Use --history to include this task's recorded activity, newest first, including reorders and comment changes.
460
+ Use activity view <activity-id> for full recorded changes. Text times are local with a UTC offset.
461
+ With --history --json, the activity field contains full activity records, or [] when none are recorded.
462
+ Without --history, JSON omits activity.
463
+
464
+ Examples:
465
+ zinn task view MDR-1
466
+ zinn task view MDR-1 --history`,
467
+ },
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")],
474
+ run: (args) => {
475
+ const { values, positionals, tokens } = parseArgs({
476
+ args,
477
+ options: taskInputs.edit.options,
478
+ allowPositionals: true,
479
+ strict: true,
480
+ tokens: true,
481
+ });
482
+ validateUniqueOptions(tokens, taskInputs.edit.options);
483
+ validatePositionals(positionals, taskInputs.edit.forms[0]);
484
+ const taskKey = positionals[0];
485
+ const description = resolveTextEdit(values.description, values, "--description");
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: [] });
488
+ }
489
+ const editedTask = task.edit({
490
+ taskKey,
491
+ title: values.title,
492
+ description,
493
+ priority: parsePriority(values.priority),
494
+ addLabelNames: values["add-label"],
495
+ removeLabelNames: values["remove-label"],
496
+ }, currentActor());
497
+ output(presentTask(editedTask), formatTaskRow);
498
+ },
499
+ help: `${generateCommandUsage("task edit", taskInputs.edit)}
500
+
501
+ Edit a task's title, description, priority, or label attachments.
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.
505
+
506
+ ${textEditHelp("--description")}
507
+
508
+ Repeat --add-label or --remove-label for multiple existing labels.
509
+ Label names are matched case-insensitively.
510
+ Adding an attached label or removing an unattached label does not do anything.
511
+ Archived tasks can be edited.
512
+
513
+ The same label cannot be both added and removed.
514
+ Titles are trimmed and cannot be blank or contain line breaks or control characters.
515
+
516
+ ${dashValueHelp("--description")}
517
+
518
+ Examples:
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
+ },
525
+ },
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,
532
+ run: (args) => {
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]);
540
+ const taskKeys = positionals.slice(0, -1);
541
+ const targetColumn = positionals.at(-1);
542
+ const moves = task.moveMany({ taskKeys, targetColumn }, currentActor());
543
+ outputTaskChanges(moves, formatTaskList, (movedTask) => `${movedTask.key} was already in the ${movedTask.column} column`);
544
+ },
545
+ help: `${generateCommandUsage("task move", taskInputs.move)}
546
+
547
+ Move tasks to another column in their projects.
548
+ Moving a task to a different column lists it last in that column,
549
+ matching placement at the bottom of a visual kanban column.
550
+ Several tasks are moved in the order given, and each task's column is looked up in its own project.
551
+
552
+ Giving a task's current column as the target will not do anything, and a note says so.
553
+ Archived tasks must be unarchived before they can be moved.
554
+ On bulk changes, if any task cannot be moved, the bulk operation is aborted.
555
+
556
+ With --json, one task prints an object and several print an array.
557
+ Each task's changed field is 'false' when it was already in the requested state.
558
+
559
+ Example: zinn task move MDR-1 MDR-2 'In Progress'`,
560
+ guessedFlags: { "--status": suggestTaskMove, "--column": suggestTaskMove },
561
+ },
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")],
568
+ run: (args) => {
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);
576
+ const taskKey = positionals[0];
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);
586
+ }
587
+ },
588
+ help: `${generateCommandUsage("task order", taskInputs.order)}
589
+
590
+ Change a task's position within its current column.
591
+ Use top or bottom for either end, up or down for one position,
592
+ or before or after to place it relative to another task.
593
+
594
+ Example: zinn task order MDR-2 before MDR-1`,
595
+ },
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,
602
+ run: (args) => {
603
+ const taskKeys = parseTaskKeys(args);
604
+ const archives = task.archiveMany(taskKeys, currentActor());
605
+ outputTaskChanges(archives, formatTaskListWithStatus, (archivedTask) => `${archivedTask.key} was already archived`);
606
+ },
607
+ help: `${generateCommandUsage("task archive", taskInputs.archive)}
608
+
609
+ Archive tasks so they no longer appear in active task lists.
610
+ Archiving an archived task does not do anything.
611
+ On bulk changes, if any task cannot be archived, the bulk operation is aborted.
612
+
613
+ With --json, one task prints an object and several print an array.
614
+ Each task's changed field is 'false' when it was already in the requested state.
615
+
616
+ Example: zinn task archive MDR-1 MDR-2`,
617
+ },
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,
624
+ run: (args) => {
625
+ const taskKeys = parseTaskKeys(args);
626
+ const unarchives = task.unarchiveMany(taskKeys, currentActor());
627
+ outputTaskChanges(unarchives, formatTaskListWithStatus, (unarchivedTask) => `${unarchivedTask.key} was already active`);
628
+ },
629
+ help: `${generateCommandUsage("task unarchive", taskInputs.archive)}
630
+
631
+ Unarchive tasks at the bottom of their previous columns, in the order given.
632
+ Unarchiving an active task does not do anything.
633
+ On bulk changes, if any task cannot be unarchived, the bulk operation is aborted.
634
+
635
+ With --json, one task prints an object and several print an array.
636
+ Each task's changed field is 'false' when it was already in the requested state.
637
+
638
+ Example: zinn task unarchive MDR-1 MDR-2`,
639
+ },
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")],
646
+ run: async (args) => {
647
+ const { values, positionals, tokens } = parseArgs({
648
+ args,
649
+ options: taskInputs.delete.options,
650
+ allowPositionals: true,
651
+ strict: true,
652
+ tokens: true,
653
+ });
654
+ validateUniqueOptions(tokens, taskInputs.delete.options);
655
+ validatePositionals(positionals, taskInputs.delete.forms[0]);
656
+ const taskKey = positionals[0];
657
+ try {
658
+ const taskMatch = task.getByKey(taskKey);
659
+ const canDelete = await confirmAction(`Are you sure you want to delete ${taskKey}?`, values.yes === true);
660
+ const presented = presentTask(taskMatch);
661
+ if (canDelete) {
662
+ task.delete(taskKey, currentActor());
663
+ output(presented, (t) => `Deleted ${formatTaskRow(t)}`);
664
+ }
665
+ else {
666
+ output(presented, (t) => `Deletion cancelled for ${formatTaskRow(t)}`);
667
+ }
668
+ }
669
+ catch (err) {
670
+ throw err;
671
+ }
672
+ },
673
+ help: `${generateCommandUsage("task delete", taskInputs.delete)}
674
+
675
+ Permanently delete a task after confirmation.
676
+ Use --yes to skip the confirmation prompt, for example in scripts or with --json.
677
+
678
+ Example: zinn task delete MDR-1`,
679
+ },
680
+ relation: relationRouter,
681
+ comment: commentRouter,
682
+ label: {
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")],
689
+ run: (args) => {
690
+ const props = parseTaskLabelArgs(args);
691
+ output(presentTask(task.label.add(props, currentActor())), formatTaskRow);
692
+ },
693
+ help: `${generateCommandUsage("task label add", taskInputs.label_add)}
694
+
695
+ Add existing labels to a task. Label names are matched case-insensitively.
696
+ Already attached labels are unchanged.`,
697
+ },
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")],
704
+ run: (args) => {
705
+ const props = parseTaskLabelArgs(args);
706
+ output(presentTask(task.label.remove(props, currentActor())), formatTaskRow);
707
+ },
708
+ help: `${generateCommandUsage("task label remove", taskInputs.label_add)}
709
+
710
+ Remove existing labels from a task. Label names are matched case-insensitively.`,
711
+ },
712
+ },
713
+ };
714
+ function parseTaskKeys(args) {
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]);
722
+ return positionals;
723
+ }
724
+ /**
725
+ * Prints the changed tasks as rows, or as JSON: an object for one task and an array for several.
726
+ * JSON includes each task's `changed` flag, and each unchanged task also gets a note on stderr.
727
+ */
728
+ function outputTaskChanges(changes, formatTasks, describeUnchanged) {
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
+ });
742
+ if (presentedChanges.length === 1) {
743
+ output(presentedChanges[0], (presentedChange) => formatTasks([presentedChange]));
744
+ }
745
+ else {
746
+ output(presentedChanges, formatTasks);
747
+ }
748
+ for (const presentedChange of presentedChanges) {
749
+ if (!presentedChange.changed) {
750
+ diagnostic(describeUnchanged(presentedChange));
751
+ }
752
+ }
753
+ }
754
+ function parseTaskLabelArgs(args) {
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]);
762
+ return { taskKey: positionals[0], labelNames: positionals.slice(1) };
763
+ }
764
+ // The new task is the source of each relation, so a flag names the type from its point of view.
765
+ function parseNewTaskRelations(flags) {
766
+ const targetsByType = [
767
+ ["subtask", flags.parent === undefined ? [] : [flags.parent]],
768
+ ["dependency", flags["depends-on"] ?? []],
769
+ ["duplicate", flags["duplicate-of"] === undefined ? [] : [flags["duplicate-of"]]],
770
+ ["related", flags.related ?? []],
771
+ ];
772
+ return targetsByType.flatMap(([relation_type, targetTaskKeys]) => targetTaskKeys.map((targetTaskKey) => ({ relation_type, targetTaskKey })));
773
+ }
774
+ function parsePriority(value) {
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
+ });
787
+ }
788
+ return priority.data;
789
+ }