@zinn-dev/cli 0.41.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 (68) hide show
  1. package/README.md +11 -689
  2. package/index.js +2 -2
  3. package/package.json +3 -2
  4. package/skills/zinn/SKILL.md +1 -1
  5. package/src/capabilities-schema.d.ts +22 -23
  6. package/src/capabilities-schema.js +17 -82
  7. package/src/capabilities.d.ts +11 -3
  8. package/src/capabilities.js +12 -4
  9. package/src/column-hint.d.ts +3 -0
  10. package/src/column-hint.js +225 -0
  11. package/src/database.js +1 -4
  12. package/src/errors.js +2 -0
  13. package/src/input.d.ts +154 -43
  14. package/src/input.js +86 -13
  15. package/src/lib.d.ts +30 -2
  16. package/src/lib.js +74 -13
  17. package/src/presentation/activity-presentation.d.ts +9 -1
  18. package/src/presentation/activity-presentation.js +108 -25
  19. package/src/presentation/capabilities-presentation.d.ts +2 -0
  20. package/src/presentation/capabilities-presentation.js +3 -0
  21. package/src/presentation/column-presentation.d.ts +6 -0
  22. package/src/presentation/column-presentation.js +10 -0
  23. package/src/presentation/comment-presentation.d.ts +15 -0
  24. package/src/presentation/comment-presentation.js +29 -0
  25. package/src/presentation/description-presentation.d.ts +17 -0
  26. package/src/presentation/description-presentation.js +26 -4
  27. package/src/presentation/label-presentation.d.ts +8 -0
  28. package/src/presentation/label-presentation.js +28 -0
  29. package/src/presentation/project-presentation.d.ts +7 -0
  30. package/src/presentation/project-presentation.js +19 -0
  31. package/src/presentation/relation-presentation.d.ts +7 -0
  32. package/src/presentation/relation-presentation.js +73 -0
  33. package/src/presentation/task-presentation.d.ts +3 -3
  34. package/src/presentation/task-presentation.js +22 -18
  35. package/src/project.d.ts +14 -5
  36. package/src/project.js +18 -6
  37. package/src/result-schemas.d.ts +230 -23
  38. package/src/result-schemas.js +62 -3
  39. package/src/results.d.ts +34 -17
  40. package/src/results.js +19 -0
  41. package/src/routes/activity-router.d.ts +34 -1
  42. package/src/routes/activity-router.js +104 -31
  43. package/src/routes/aliases.d.ts +2 -0
  44. package/src/routes/aliases.js +11 -0
  45. package/src/routes/capabilities-router.js +9 -3
  46. package/src/routes/comment-router.d.ts +41 -18
  47. package/src/routes/comment-router.js +65 -48
  48. package/src/routes/label-router.d.ts +57 -7
  49. package/src/routes/label-router.js +84 -39
  50. package/src/routes/project-router.d.ts +34 -12
  51. package/src/routes/project-router.js +59 -55
  52. package/src/routes/relation-router.d.ts +6 -6
  53. package/src/routes/relation-router.js +52 -69
  54. package/src/routes/restore-router.js +1 -1
  55. package/src/routes/router.d.ts +1 -1
  56. package/src/routes/router.js +38 -9
  57. package/src/routes/routes.d.ts +253 -45
  58. package/src/routes/routes.js +4 -0
  59. package/src/routes/task-router.d.ts +107 -26
  60. package/src/routes/task-router.js +151 -143
  61. package/src/routes/whoami-router.d.ts +21 -0
  62. package/src/routes/whoami-router.js +31 -0
  63. package/src/text-edit.d.ts +13 -9
  64. package/src/text-edit.js +23 -18
  65. package/src/text-input.d.ts +47 -0
  66. package/src/text-input.js +187 -0
  67. package/src/types.d.ts +32 -9
  68. package/src/types.js +9 -1
@@ -1,17 +1,20 @@
1
1
  import { jsonResult, taskDetailResults, taskChangeResults } from "../results.js";
2
2
  import { parseArgs } from "node:util";
3
- import { task, project, positiveIntegerPattern, searchLimitMessage, parseTaskKey, taskPrioritySchema, } from "@zinn-dev/core";
3
+ import { task, project, positiveIntegerPattern, searchLimitMessage, parseTaskKey, taskCreateSchema, taskEditSchema, taskDeleteManySchema, taskPrioritySchema, } from "@zinn-dev/core";
4
4
  import { CliError } from "../errors.js";
5
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";
6
+ import { confirmationDescription, confirmAction, dashValueHelp, diagnostic, output, outputChanges, quit, validatePositionals, validateOrderForms, requireStringOption, renameFlag, validateUniqueOptions, } from "../lib.js";
7
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";
8
+ import { checkFieldsBeforeText, resolveTextInput, textFileHelp, textFileOption, textSourceConstraint, } from "../text-input.js";
10
9
  import { currentActor } from "../actor.js";
11
- import { resolveProjectKey, projectScopeConstraint, requiredProjectDescription, projectScopeDescription, } 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";
12
15
  import { formatSection } from "../presentation/section.js";
13
16
  import { formatActivityList, presentActivities } from "../presentation/activity-presentation.js";
14
- import { formatTaskList, formatTaskListWithStatus, formatTaskRow, presentTask, } from "../presentation/task-presentation.js";
17
+ import { formatTaskList, formatTaskTimestamps, presentTask, } from "../presentation/task-presentation.js";
15
18
  // A column is changed with task move, so a guessed --status or --column suggests it with the same task keys.
16
19
  function suggestTaskMove(args, options = {}) {
17
20
  const { values, positionals } = parseArgs({
@@ -39,6 +42,7 @@ const taskEditConstraint = {
39
42
  members: [
40
43
  "option:title",
41
44
  "option:description",
45
+ "option:description-file",
42
46
  "option:priority",
43
47
  "option:add-label",
44
48
  "option:remove-label",
@@ -49,6 +53,7 @@ const taskInputs = {
49
53
  options: {
50
54
  title: { type: "string", required: true, value: { kind: "text", name: "text" } },
51
55
  description: { type: "string", value: { kind: "text", name: "text" } },
56
+ "description-file": textFileOption,
52
57
  priority: priorityOption,
53
58
  label: { type: "string", multiple: true, value: { kind: "label-name", name: "name" } },
54
59
  column: { type: "string", value: { kind: "column-name", name: "name" } },
@@ -67,7 +72,7 @@ const taskInputs = {
67
72
  positionals: [{ name: "project-key", min: 0, max: 1, value: { kind: "project-key" } }],
68
73
  },
69
74
  ],
70
- constraints: [],
75
+ constraints: [textSourceConstraint("--description")],
71
76
  notes: [requiredProjectDescription],
72
77
  },
73
78
  list: {
@@ -127,6 +132,7 @@ const taskInputs = {
127
132
  options: {
128
133
  title: { type: "string", value: { kind: "text", name: "text" } },
129
134
  description: { type: "string", value: { kind: "text", name: "text" } },
135
+ "description-file": textFileOption,
130
136
  ...textEditOptions,
131
137
  priority: priorityOption,
132
138
  "add-label": { type: "string", multiple: true, value: { kind: "label-name", name: "name" } },
@@ -142,7 +148,11 @@ const taskInputs = {
142
148
  positionals: [taskKeyPositional],
143
149
  },
144
150
  ],
145
- constraints: [...textEditConstraints("--description"), taskEditConstraint],
151
+ constraints: [
152
+ textSourceConstraint("--description"),
153
+ ...textEditConstraints("--description"),
154
+ taskEditConstraint,
155
+ ],
146
156
  notes: [textEditHelp("--description")],
147
157
  },
148
158
  move: {
@@ -164,19 +174,26 @@ const taskInputs = {
164
174
  {
165
175
  id: "absolute",
166
176
  positionals: [
167
- taskKeyPositional,
177
+ { ...taskKeyPositional, max: null },
168
178
  {
169
179
  name: "direction",
170
180
  min: 1,
171
181
  max: 1,
172
- value: { kind: "enum", choices: ["top", "up", "down", "bottom"] },
182
+ value: { kind: "enum", choices: ["top", "bottom"] },
173
183
  },
174
184
  ],
175
185
  },
176
186
  {
177
- id: "relative",
187
+ id: "step",
178
188
  positionals: [
179
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 },
180
197
  {
181
198
  name: "direction",
182
199
  min: 1,
@@ -204,7 +221,7 @@ const taskInputs = {
204
221
  forms: [
205
222
  {
206
223
  id: "default",
207
- positionals: [taskKeyPositional],
224
+ positionals: [{ ...taskKeyPositional, max: null }],
208
225
  },
209
226
  ],
210
227
  constraints: [],
@@ -230,7 +247,19 @@ export const taskRouter = {
230
247
  confirmation: { kind: "none" },
231
248
  input: taskInputs.create,
232
249
  results: [jsonResult("Task")],
233
- run: (args) => {
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) => {
234
263
  const { values, positionals, tokens } = parseArgs({
235
264
  args,
236
265
  options: taskInputs.create.options,
@@ -240,22 +269,26 @@ export const taskRouter = {
240
269
  });
241
270
  validateUniqueOptions(tokens, taskInputs.create.options);
242
271
  validatePositionals(positionals, taskInputs.create.forms[0]);
243
- const projectKey = resolveProjectKey(positionals[0], { required: true });
272
+ const projectChoice = chooseProjectKey(positionals[0], { required: true });
244
273
  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,
274
+ const priority = parsePriority(values.priority);
275
+ const fields = {
251
276
  title,
252
- description: values.description ?? null,
253
- priority: parsePriority(values.priority),
277
+ priority,
254
278
  labelNames: values.label,
255
279
  columnName: values.column,
256
280
  relations: parseNewTaskRelations(values),
257
- }, currentActor());
258
- 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]));
259
292
  },
260
293
  help: `${generateCommandUsage("task create", taskInputs.create)}
261
294
 
@@ -263,19 +296,16 @@ Create a task at the bottom of a column. Without --column, it starts in the proj
263
296
 
264
297
  ${requiredProjectDescription}
265
298
 
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.
299
+ Priority values: ${priorityOption.value.choices.join(", ")}; defaults to none.
300
+ Repeat --label to attach multiple existing labels.
301
+ ${textFileHelp("--description")}
272
302
 
273
303
  ${dashValueHelp("--description")}
274
304
 
275
- Relations are set from the new task's perspective: it becomes a subtask of --parent, depends on --depends-on,
305
+ The new task is a subtask of --parent, depends on --depends-on,
276
306
  is a duplicate of --duplicate-of, and is related to --related.
277
307
  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.
308
+ Unknown columns, labels or related tasks abort creation.
279
309
 
280
310
  Examples:
281
311
  zinn task create MDR --title 'Refine the numbers' --description 'Meet the quarterly quota' --label urgent
@@ -316,12 +346,10 @@ Examples:
316
346
  List active tasks by default.
317
347
  ${projectScopeDescription}
318
348
  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.
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.
322
352
 
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
353
  Use 'task view' to see a task's full details, including its description.
326
354
 
327
355
  Example: zinn task list MDR --label cli`,
@@ -378,21 +406,16 @@ ${projectScopeDescription}
378
406
  Each word matches the start of a word, ignoring case and accents: e.g. "auth" finds "Authentication".
379
407
  Every word must match. Quote a query with several words.
380
408
 
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.
409
+ A task-key query overrides the configured default project; a typed project key still filters it.
385
410
 
386
411
  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
412
  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'.
413
+ Repeat --label to require every specified label, ignoring case.
391
414
 
392
415
  Example: zinn task search 'refinement quota' MDR --limit 5`,
393
416
  },
394
417
  view: {
395
- summary: "Show a task with its description, relations, and comments.",
418
+ summary: "Show a task with its description, relations, comments, and creation and update times.",
396
419
  effects: { domain: "read", storage: "normal-open" },
397
420
  confirmation: { kind: "none" },
398
421
  input: taskInputs.view,
@@ -410,6 +433,8 @@ Example: zinn task search 'refinement quota' MDR --limit 5`,
410
433
  const taskMatch = task.getByKey(positionals[0]);
411
434
  const detail = {
412
435
  ...presentTask(taskMatch),
436
+ created_at: taskMatch.created_at,
437
+ updated_at: taskMatch.updated_at,
413
438
  relations: presentRelations(taskMatch),
414
439
  comments: presentComments(taskMatch.key),
415
440
  };
@@ -428,8 +453,8 @@ Example: zinn task search 'refinement quota' MDR --limit 5`,
428
453
  const sectionOptions = {
429
454
  separatorWidth: hasTerminalWidth ? terminalWidth : MIN_SECTION_SEPARATOR_WIDTH,
430
455
  };
431
- const relations = formatRelations(t.relations);
432
- const comments = formatComments(t.comments);
456
+ const relations = formatRelationList(t.relations);
457
+ const comments = formatCommentList(t.comments);
433
458
  const isArchived = t.status === "Archived";
434
459
  const sections = [
435
460
  formatTaskList([t], { showsStatus: isArchived, showsFullPriority: true }),
@@ -449,13 +474,16 @@ Example: zinn task search 'refinement quota' MDR --limit 5`,
449
474
  sections.push(formatSection("History", history, sectionOptions));
450
475
  }
451
476
  }
477
+ sections.push(formatTaskTimestamps(t));
452
478
  return sections.join("\n\n");
453
479
  });
454
480
  },
455
481
  help: `${generateCommandUsage("task view", taskInputs.view)}
456
482
 
457
- Show a task with its description, relations, and comments.
483
+ Show a task with its description, relations, comments, and creation and update times.
458
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.
459
487
  Use --history to include this task's recorded activity, newest first, including reorders and comment changes.
460
488
  Use activity view <activity-id> for full recorded changes. Text times are local with a UTC offset.
461
489
  With --history --json, the activity field contains full activity records, or [] when none are recorded.
@@ -470,8 +498,8 @@ Examples:
470
498
  effects: { domain: "update", storage: "normal-open" },
471
499
  confirmation: { kind: "none" },
472
500
  input: taskInputs.edit,
473
- results: [jsonResult("Task")],
474
- run: (args) => {
501
+ results: [jsonResult("TaskChange")],
502
+ run: async (args) => {
475
503
  const { values, positionals, tokens } = parseArgs({
476
504
  args,
477
505
  options: taskInputs.edit.options,
@@ -482,36 +510,36 @@ Examples:
482
510
  validateUniqueOptions(tokens, taskInputs.edit.options);
483
511
  validatePositionals(positionals, taskInputs.edit.forms[0]);
484
512
  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({
513
+ const fields = {
490
514
  taskKey,
491
515
  title: values.title,
492
- description,
493
516
  priority: parsePriority(values.priority),
494
517
  addLabelNames: values["add-label"],
495
518
  removeLabelNames: values["remove-label"],
496
- }, currentActor());
497
- 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`);
498
528
  },
499
529
  help: `${generateCommandUsage("task edit", taskInputs.edit)}
500
530
 
501
531
  Edit a task's title, description, priority, or label attachments.
502
- Use --priority none to clear priority. Priority values are case-insensitive.
532
+ Use --priority none to clear priority.
503
533
  Priority values: ${priorityOption.value.choices.join(", ")}.
504
534
  Provide at least one edit flag. Use --description '' to clear the description.
535
+ ${textFileHelp("--description")}
505
536
 
506
537
  ${textEditHelp("--description")}
507
538
 
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
-
539
+ Repeat --add-label or --remove-label for multiple existing labels, ignoring case.
513
540
  The same label cannot be both added and removed.
514
- 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.
515
543
 
516
544
  ${dashValueHelp("--description")}
517
545
 
@@ -521,6 +549,11 @@ Examples:
521
549
  guessedFlags: {
522
550
  "--status": (args) => suggestTaskMove(args, taskInputs.edit.options),
523
551
  "--column": (args) => suggestTaskMove(args, taskInputs.edit.options),
552
+ "--body": (args) => [
553
+ "task",
554
+ "edit",
555
+ ...renameFlag(args, taskInputs.edit.options, "body", "description"),
556
+ ],
524
557
  },
525
558
  },
526
559
  move: {
@@ -540,31 +573,27 @@ Examples:
540
573
  const taskKeys = positionals.slice(0, -1);
541
574
  const targetColumn = positionals.at(-1);
542
575
  const moves = task.moveMany({ taskKeys, targetColumn }, currentActor());
543
- 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`);
544
577
  },
545
578
  help: `${generateCommandUsage("task move", taskInputs.move)}
546
579
 
547
580
  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.
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.
551
583
 
552
- 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.
553
585
  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.
586
+ If any task cannot be moved, none change.
558
587
 
559
588
  Example: zinn task move MDR-1 MDR-2 'In Progress'`,
560
589
  guessedFlags: { "--status": suggestTaskMove, "--column": suggestTaskMove },
561
590
  },
562
591
  order: {
563
- summary: "Change a task's position within its current column.",
592
+ summary: "Change task positions within their current column.",
564
593
  effects: { domain: "update", storage: "normal-open" },
565
594
  confirmation: { kind: "none" },
566
595
  input: taskInputs.order,
567
- results: [jsonResult("Task")],
596
+ results: taskChangeResults,
568
597
  run: (args) => {
569
598
  const { positionals } = parseArgs({
570
599
  options: taskInputs.order.options,
@@ -573,23 +602,29 @@ Example: zinn task move MDR-1 MDR-2 'In Progress'`,
573
602
  strict: true,
574
603
  });
575
604
  const form = validateOrderForms(positionals, taskInputs.order.forms);
576
- const taskKey = positionals[0];
605
+ const taskKeys = positionals.slice(0, form.directionIndex);
606
+ let orders;
577
607
  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);
608
+ orders = task.orderMany({
609
+ taskKeys,
610
+ direction: form.direction,
611
+ targetTaskKey: positionals[form.directionIndex + 1],
612
+ }, currentActor());
581
613
  }
582
614
  else {
583
- const direction = positionals[1];
584
- const orderedTask = task.order({ taskKey, direction }, currentActor());
585
- output(presentTask(orderedTask), formatTaskRow);
615
+ orders = task.orderMany({ taskKeys, direction: form.direction }, currentActor());
586
616
  }
617
+ outputChanges(orders, (change) => presentTask(change.task), formatTaskList, (entry) => `${entry.key} was already in that position`);
587
618
  },
588
619
  help: `${generateCommandUsage("task order", taskInputs.order)}
589
620
 
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.
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.
593
628
 
594
629
  Example: zinn task order MDR-2 before MDR-1`,
595
630
  },
@@ -602,7 +637,7 @@ Example: zinn task order MDR-2 before MDR-1`,
602
637
  run: (args) => {
603
638
  const taskKeys = parseTaskKeys(args);
604
639
  const archives = task.archiveMany(taskKeys, currentActor());
605
- 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`);
606
641
  },
607
642
  help: `${generateCommandUsage("task archive", taskInputs.archive)}
608
643
 
@@ -624,7 +659,7 @@ Example: zinn task archive MDR-1 MDR-2`,
624
659
  run: (args) => {
625
660
  const taskKeys = parseTaskKeys(args);
626
661
  const unarchives = task.unarchiveMany(taskKeys, currentActor());
627
- 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`);
628
663
  },
629
664
  help: `${generateCommandUsage("task unarchive", taskInputs.archive)}
630
665
 
@@ -638,11 +673,14 @@ Each task's changed field is 'false' when it was already in the requested state.
638
673
  Example: zinn task unarchive MDR-1 MDR-2`,
639
674
  },
640
675
  delete: {
641
- summary: "Permanently delete a task after confirmation.",
676
+ summary: "Permanently delete tasks after confirmation.",
642
677
  effects: { domain: "delete", storage: "normal-open" },
643
678
  confirmation: { kind: "prompt", description: confirmationDescription },
644
679
  input: taskInputs.delete,
645
- results: [jsonResult("Task")],
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
+ ],
646
684
  run: async (args) => {
647
685
  const { values, positionals, tokens } = parseArgs({
648
686
  args,
@@ -653,29 +691,26 @@ Example: zinn task unarchive MDR-1 MDR-2`,
653
691
  });
654
692
  validateUniqueOptions(tokens, taskInputs.delete.options);
655
693
  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;
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());
671
700
  }
701
+ output(presented.length === 1 ? presented[0] : presented, (entries) => formatTaskList(Array.isArray(entries) ? entries : [entries], {
702
+ prefix: canDelete ? "Deleted " : "Deletion cancelled for ",
703
+ }));
672
704
  },
673
705
  help: `${generateCommandUsage("task delete", taskInputs.delete)}
674
706
 
675
- 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.
676
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.
677
712
 
678
- Example: zinn task delete MDR-1`,
713
+ Example: zinn task delete MDR-1 MDR-2`,
679
714
  },
680
715
  relation: relationRouter,
681
716
  comment: commentRouter,
@@ -685,29 +720,32 @@ Example: zinn task delete MDR-1`,
685
720
  effects: { domain: "update", storage: "normal-open" },
686
721
  confirmation: { kind: "none" },
687
722
  input: taskInputs.label_add,
688
- results: [jsonResult("Task")],
723
+ results: [jsonResult("TaskChange")],
689
724
  run: (args) => {
690
725
  const props = parseTaskLabelArgs(args);
691
- 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`);
692
727
  },
693
728
  help: `${generateCommandUsage("task label add", taskInputs.label_add)}
694
729
 
695
730
  Add existing labels to a task. Label names are matched case-insensitively.
696
- Already attached labels are unchanged.`,
731
+ Already attached labels are unchanged.
732
+ With --json, changed is false when all the labels were already attached.`,
697
733
  },
698
734
  remove: {
699
735
  summary: "Remove existing labels from a task. Label names are matched case-insensitively.",
700
736
  effects: { domain: "update", storage: "normal-open" },
701
737
  confirmation: { kind: "none" },
702
738
  input: taskInputs.label_add,
703
- results: [jsonResult("Task")],
739
+ results: [jsonResult("TaskChange")],
704
740
  run: (args) => {
705
741
  const props = parseTaskLabelArgs(args);
706
- 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`);
707
743
  },
708
744
  help: `${generateCommandUsage("task label remove", taskInputs.label_add)}
709
745
 
710
- 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.`,
711
749
  },
712
750
  },
713
751
  };
@@ -721,36 +759,6 @@ function parseTaskKeys(args) {
721
759
  validatePositionals(positionals, taskInputs.archive.forms[0]);
722
760
  return positionals;
723
761
  }
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
762
  function parseTaskLabelArgs(args) {
755
763
  const { positionals } = parseArgs({
756
764
  options: taskInputs.label_add.options,
@@ -0,0 +1,21 @@
1
+ export declare const whoamiCommand: {
2
+ summary: string;
3
+ effects: {
4
+ domain: "none";
5
+ storage: "none";
6
+ };
7
+ confirmation: {
8
+ kind: "none";
9
+ };
10
+ input: {
11
+ readonly options: {};
12
+ readonly forms: readonly [{
13
+ readonly id: "default";
14
+ readonly positionals: readonly [];
15
+ }];
16
+ readonly constraints: readonly [];
17
+ };
18
+ results: import("../results.js").CommandResult[];
19
+ run: (args: string[]) => void;
20
+ help: string;
21
+ };
@@ -0,0 +1,31 @@
1
+ import { parseArgs } from "node:util";
2
+ import { currentActor } from "../actor.js";
3
+ import { generateCommandUsage, noInput } from "../input.js";
4
+ import { output, validatePositionals } from "../lib.js";
5
+ import { formatActor, presentActor } from "../presentation/activity-presentation.js";
6
+ import { jsonResult } from "../results.js";
7
+ export const whoamiCommand = {
8
+ summary: "Show the actor a change would record in the current environment and folder.",
9
+ effects: { domain: "none", storage: "none" },
10
+ confirmation: { kind: "none" },
11
+ input: noInput,
12
+ results: [jsonResult("Actor")],
13
+ run: (args) => {
14
+ const { positionals } = parseArgs({
15
+ options: noInput.options,
16
+ args,
17
+ strict: true,
18
+ allowPositionals: true,
19
+ });
20
+ validatePositionals(positionals, noInput.forms[0]);
21
+ output(presentActor(currentActor()), formatActor);
22
+ },
23
+ help: `${generateCommandUsage("whoami", noInput)}
24
+
25
+ Show the actor a change would record in the current environment and folder.
26
+ Includes name, email, kind, source, session, thread, agent, model and effort.
27
+ Git identity is read from the current folder.
28
+
29
+ Works without reading settings or opening storage.
30
+ Use --json for the actor_* fields carried by activity records.`,
31
+ };