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