@zinn-dev/cli 0.36.0 → 0.37.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.
@@ -0,0 +1,44 @@
1
+ import { expect, spyOn, test } from "bun:test";
2
+ import { backup, RestoreRefusedError, getStorage } from "@zinn-dev/core";
3
+
4
+ import { restoreCommand } from "./restore-router";
5
+
6
+ test("restore keeps the general hint for damaged search index internals and rethrows the error", () => {
7
+ const failure = Object.assign(new Error("vtable constructor failed: task_search"), {
8
+ code: "SQLITE_ERROR",
9
+ });
10
+ const restore = spyOn(backup, "restore").mockImplementation(() => {
11
+ throw failure;
12
+ });
13
+ const stderr = spyOn(console, "error").mockImplementation(() => {});
14
+
15
+ try {
16
+ expect(() => restoreCommand.run(["backup.sqlite", "--yes"])).toThrow(failure);
17
+ expect(stderr.mock.calls).toEqual([
18
+ [
19
+ `The database is unchanged. Backups taken before each restore attempt are kept in ${getStorage().backupDirectory}.`,
20
+ ],
21
+ ]);
22
+ } finally {
23
+ restore.mockRestore();
24
+ stderr.mockRestore();
25
+ }
26
+ });
27
+
28
+ test("a refused damaged backup does not get the damaged live database hint", () => {
29
+ const failure = new RestoreRefusedError("The backup is damaged, so nothing was restored", {
30
+ cause: Object.assign(new Error("database disk image is malformed"), { code: "SQLITE_CORRUPT" }),
31
+ });
32
+ const restore = spyOn(backup, "restore").mockImplementation(() => {
33
+ throw failure;
34
+ });
35
+ const stderr = spyOn(console, "error").mockImplementation(() => {});
36
+
37
+ try {
38
+ expect(() => restoreCommand.run(["backup.sqlite", "--yes"])).toThrow(failure);
39
+ expect(stderr.mock.calls).toEqual([]);
40
+ } finally {
41
+ restore.mockRestore();
42
+ stderr.mockRestore();
43
+ }
44
+ });
@@ -0,0 +1,90 @@
1
+ import type { Command } from "../types";
2
+
3
+ import { parseArgs } from "node:util";
4
+ import { resolve } from "node:path";
5
+ import { backup, RestoreRefusedError, getStorage } from "@zinn-dev/core";
6
+
7
+ import { reportLockWait } from "../database";
8
+ import { askConfirmation, output, validatePositionalCount, validateUniqueOptions } from "../lib";
9
+ import packageJson from "../../package.json";
10
+
11
+ const build = { client: "cli", version: packageJson.version };
12
+
13
+ export const restoreCommand = {
14
+ run: (args) => {
15
+ const { positionals, values, tokens } = parseArgs({
16
+ args,
17
+ strict: true,
18
+ allowPositionals: true,
19
+ tokens: true,
20
+ options: { yes: { type: "boolean" } },
21
+ });
22
+ validateUniqueOptions(tokens);
23
+ validatePositionalCount(positionals, 1, "Specify the backup file to restore");
24
+
25
+ const path = resolve(positionals[0]!);
26
+ const { databasePath, backupDirectory } = getStorage();
27
+ const isPreconfirmed = values.yes === true;
28
+
29
+ // A backup that would be refused is refused before the prompt.
30
+ if (!isPreconfirmed) {
31
+ backup.check({ ...build, path });
32
+ }
33
+
34
+ const isConfirmed = askConfirmation(
35
+ `Replace the database at ${databasePath} with the backup ${path}? Its current board is saved to ${backupDirectory} first.`,
36
+ isPreconfirmed,
37
+ );
38
+
39
+ if (!isConfirmed) {
40
+ output(null, () => `Restore cancelled. The database at ${databasePath} is unchanged`);
41
+ return;
42
+ }
43
+
44
+ try {
45
+ const result = backup.restore({ ...build, path, onWait: reportLockWait });
46
+
47
+ output(result, (r) => {
48
+ const restored = `Restored the board from ${path} at schema version ${r.restoredVersion}.`;
49
+ return r.backupPath == null
50
+ ? `${restored} There was no board to save`
51
+ : `${restored} The board it replaced was saved to ${r.backupPath}`;
52
+ });
53
+ } catch (error) {
54
+ // A refusal attempted nothing, so only a failed restore points at the backups.
55
+ if (!(error instanceof RestoreRefusedError)) {
56
+ const isDamagedDatabase =
57
+ error instanceof Error &&
58
+ "code" in error &&
59
+ typeof error.code === "string" &&
60
+ error.code.startsWith("SQLITE_CORRUPT");
61
+
62
+ if (isDamagedDatabase) {
63
+ console.error(
64
+ `The database at ${databasePath} is damaged. Nothing was changed. To restore it:\n` +
65
+ `1. Close every program that has the database open.\n` +
66
+ `2. Move ${databasePath}, ${databasePath}-wal and ${databasePath}-shm out of the data folder, keeping any that exist together. Keep these files; do not delete them.\n` +
67
+ `3. Run the same zinn restore command again to create the database from the backup.`,
68
+ );
69
+ } else {
70
+ console.error(
71
+ `The database is unchanged. Backups taken before each restore attempt are kept in ${backupDirectory}.`,
72
+ );
73
+ }
74
+ }
75
+
76
+ throw error;
77
+ }
78
+ },
79
+ help: `Usage: zinn restore <path> [--yes]
80
+
81
+ Replace the board with the one in a backup file, such as one saved by \`zinn backup\` or by an upgrade, after confirmation.
82
+
83
+ The current board is saved first, in the same place as \`zinn backup\`, and the restore is applied completely or not at all.
84
+ A backup with an older schema version is restored at that version. Zinn then upgrades it like any older database: by itself, except for ~/.zinn run from a source checkout, which needs \`zinn migrate\`.
85
+ Restoring onto a missing database creates it.
86
+ Fails, leaving the database as it is, when the backup has a newer schema version than this Zinn or none at all, is damaged, or is not a Zinn database.
87
+ Use --yes to skip the confirmation prompt, for example in scripts or with --json.
88
+
89
+ Example: zinn restore ~/.zinn/backups/2026-10-06T12-30-05Z-cli-0.40.0-1a2b3c4d.sqlite`,
90
+ } satisfies Command;
@@ -1,6 +1,7 @@
1
1
  import type { Command, RouteDef } from "../types";
2
2
 
3
3
  import { test, expect, mock, spyOn } from "bun:test";
4
+ import { isLegacyReadAllowed, setLegacyReadAllowed } from "../lib";
4
5
  import { createRouter, parseRoutes } from "./router";
5
6
 
6
7
  const mockCommand: Command = { run: mock(() => {}), help: `` };
@@ -93,3 +94,25 @@ test("a help request never runs a command even when its help is empty", () => {
93
94
  info.mockRestore();
94
95
  }
95
96
  });
97
+
98
+ test("--allow-legacy-read before a -- is taken out of the arguments and allows legacy reads", () => {
99
+ const run = mock(() => {});
100
+ const router = createRouter({ foo: { run, help: "" } });
101
+
102
+ try {
103
+ router.route(["foo", "--allow-legacy-read", "--", "literal"]);
104
+ expect(run).toHaveBeenCalledWith(["--", "literal"]);
105
+ expect(isLegacyReadAllowed()).toBe(true);
106
+ } finally {
107
+ setLegacyReadAllowed(false);
108
+ }
109
+ });
110
+
111
+ test("--allow-legacy-read after a -- stays command input and allows nothing", () => {
112
+ const run = mock(() => {});
113
+ const router = createRouter({ foo: { run, help: "" } });
114
+
115
+ router.route(["foo", "--", "--allow-legacy-read"]);
116
+ expect(run).toHaveBeenCalledWith(["--", "--allow-legacy-read"]);
117
+ expect(isLegacyReadAllowed()).toBe(false);
118
+ });
@@ -1,6 +1,14 @@
1
1
  import type { Command, ParsedRoute, RouteDef } from "../types";
2
2
 
3
- import { isHelpFlag, isJsonFlag, quit, setOutputMode } from "../lib";
3
+ import {
4
+ failureMessage,
5
+ isAllowLegacyReadFlag,
6
+ isHelpFlag,
7
+ isJsonFlag,
8
+ quit,
9
+ setLegacyReadAllowed,
10
+ setOutputMode,
11
+ } from "../lib";
4
12
 
5
13
  function getIsRunnable(obj: any): obj is Command {
6
14
  return Object.hasOwn(obj, "run");
@@ -12,7 +20,9 @@ function toCommand(args: Array<string>) {
12
20
 
13
21
  // Groups sibling commands into one line, e.g. " comment {create|list|edit|delete}".
14
22
  // A command without siblings is not a choice, so it gets no braces, e.g. " backup".
23
+ // Top-level commands in the root help are unrelated to each other, so each gets its own line.
15
24
  function formatCommands(parsedRoutes: Array<ParsedRoute>, prefix: string) {
25
+ const isRootHelp = prefix === "";
16
26
  const siblingsByParent = new Map<string, Array<string>>();
17
27
  for (const { command } of parsedRoutes) {
18
28
  if (!command.startsWith(prefix)) {
@@ -25,9 +35,14 @@ function formatCommands(parsedRoutes: Array<ParsedRoute>, prefix: string) {
25
35
  }
26
36
 
27
37
  return [...siblingsByParent]
28
- .map(([parent, siblings]) => {
38
+ .flatMap(([parent, siblings]) => {
39
+ const isTopLevel = isRootHelp && parent === "";
40
+ if (isTopLevel) {
41
+ return siblings.map((command) => ` ${command}`);
42
+ }
43
+
29
44
  const commands = siblings.length === 1 ? siblings[0] : `{${siblings.join("|")}}`;
30
- return ` ${parent === "" ? "" : `${parent} `}${commands}`;
45
+ return [` ${parent === "" ? "" : `${parent} `}${commands}`];
31
46
  })
32
47
  .join("\n");
33
48
  }
@@ -69,12 +84,18 @@ function route(parsedRoutes: Array<ParsedRoute>, rawArgs: Array<string>) {
69
84
  const separatorIndex = rawArgs.indexOf("--");
70
85
  const routableArgs = separatorIndex === -1 ? rawArgs : rawArgs.slice(0, separatorIndex);
71
86
  const passthroughArgs = separatorIndex === -1 ? [] : rawArgs.slice(separatorIndex);
72
- const filteredRoutableArgs = routableArgs.filter((arg) => !isJsonFlag(arg));
87
+ const filteredRoutableArgs = routableArgs.filter(
88
+ (arg) => !isJsonFlag(arg) && !isAllowLegacyReadFlag(arg),
89
+ );
73
90
 
74
- if (filteredRoutableArgs.length !== routableArgs.length) {
91
+ if (routableArgs.some(isJsonFlag)) {
75
92
  setOutputMode("json");
76
93
  }
77
94
 
95
+ if (routableArgs.some(isAllowLegacyReadFlag)) {
96
+ setLegacyReadAllowed(true);
97
+ }
98
+
78
99
  const args = [...filteredRoutableArgs, ...passthroughArgs];
79
100
  const isHelpRequest = isHelpFlag(filteredRoutableArgs.at(-1) ?? "");
80
101
 
@@ -123,8 +144,10 @@ function route(parsedRoutes: Array<ParsedRoute>, rawArgs: Array<string>) {
123
144
  match.run(commandArgs);
124
145
  } catch (err: any) {
125
146
  quit(
126
- err?.message ??
147
+ failureMessage(
148
+ err,
127
149
  `Something went wrong while running "${match.command}" with args: ${commandArgs.join(",")}`,
150
+ ),
128
151
  );
129
152
  }
130
153
  }
@@ -2,6 +2,9 @@ import { projectRouter } from "./project-router";
2
2
  import { taskRouter } from "./task-router";
3
3
  import { labelRouter } from "./label-router";
4
4
  import { backupCommand } from "./backup-router";
5
+ import { restoreCommand } from "./restore-router";
6
+ import { migrateCommand } from "./migrate-router";
7
+ import { reindexCommand } from "./reindex-router";
5
8
 
6
9
  // TODO: lazy load?
7
10
  export const routes = {
@@ -9,4 +12,7 @@ export const routes = {
9
12
  task: taskRouter,
10
13
  label: labelRouter,
11
14
  backup: backupCommand,
15
+ restore: restoreCommand,
16
+ migrate: migrateCommand,
17
+ reindex: reindexCommand,
12
18
  };
@@ -1,10 +1,13 @@
1
+ import type { TaskChange } from "@zinn-dev/core";
1
2
  import type { RouteDef } from "../types";
3
+ import type { PresentedTask } from "../presentation/task-presentation";
2
4
 
3
5
  import { parseArgs } from "node:util";
4
6
  import { task, project, positiveIntegerPattern, searchLimitMessage } from "@zinn-dev/core";
5
7
 
6
8
  import {
7
9
  confirmAction,
10
+ failureMessage,
8
11
  output,
9
12
  quit,
10
13
  validatePositionalCount,
@@ -13,16 +16,14 @@ import {
13
16
  import { formatRelations, presentRelations, relationRouter } from "./relation-router";
14
17
  import { commentRouter, formatComments, presentComments } from "./comment-router";
15
18
  import { currentActor } from "../actor";
19
+ import { formatSection } from "../presentation/section";
16
20
  import {
17
- formatTask,
18
21
  formatTaskList,
19
- formatTaskMove,
20
- formatTaskWithStatus,
22
+ formatTaskListWithStatus,
23
+ formatTaskRow,
21
24
  presentTask,
22
25
  } from "../presentation/task-presentation";
23
26
 
24
- const limitPattern = new RegExp(`^${positiveIntegerPattern}$`);
25
-
26
27
  export const taskRouter = {
27
28
  create: {
28
29
  run: (args) => {
@@ -65,7 +66,7 @@ export const taskRouter = {
65
66
  },
66
67
  currentActor(),
67
68
  );
68
- output(presentTask(createdTask), formatTask);
69
+ output(presentTask(createdTask), formatTaskRow);
69
70
  },
70
71
  help: `Usage: zinn task create <project-key> --title <text> [--description <text>] [--priority {low|medium|high|urgent|none}] [--label <name>]
71
72
 
@@ -116,7 +117,10 @@ Example: zinn task create MDR --title "Refine the numbers" --description "Meet t
116
117
  List active tasks by default.
117
118
  Use --archived to list archived tasks or --all to list both.
118
119
  Use --label to filter for tasks with a specific label, no case-sensitivity is applied for matching.
120
+
121
+ Each row shows a task's key, column, priority marker, title, and labels. --all adds an Active or Archived status after the key.
119
122
  Priority markers: - unassigned, L low, M medium, H high, U urgent.
123
+ Use 'task view' to see a task's full details, including its description.
120
124
 
121
125
  Example: zinn task list MDR --label cli`,
122
126
  },
@@ -152,6 +156,7 @@ Example: zinn task list MDR --label cli`,
152
156
  }
153
157
 
154
158
  const archive = values.all ? "all" : values.archived ? "archived" : "active";
159
+ const limitPattern = new RegExp(`^${positiveIntegerPattern}$`);
155
160
 
156
161
  if (values.limit !== undefined && !limitPattern.test(values.limit)) {
157
162
  quit(searchLimitMessage);
@@ -212,17 +217,29 @@ Example: zinn task search "refinement quota" MDR --limit 5`,
212
217
  };
213
218
 
214
219
  output(viewedTask, (t) => {
220
+ const MIN_SECTION_SEPARATOR_WIDTH = 60;
221
+
222
+ const terminalWidth = process.stdout.columns;
223
+ const hasTerminalWidth = process.stdout.isTTY === true && terminalWidth > 0;
224
+
225
+ const sectionOptions = {
226
+ separatorWidth: hasTerminalWidth ? terminalWidth : MIN_SECTION_SEPARATOR_WIDTH,
227
+ };
215
228
  const relations = formatRelations(t.relations);
216
229
  const comments = formatComments(t.comments);
217
- const formattedTask = formatTask(t);
218
- const sections = [formattedTask];
230
+ const isArchived = t.status === "Archived";
231
+ const sections = [formatTaskList([t], { showsStatus: isArchived })];
232
+
233
+ if (t.description != null) {
234
+ sections.push(formatSection("Description", t.description, sectionOptions));
235
+ }
219
236
 
220
237
  if (relations.length > 0) {
221
- sections.push(`Relations:\n${relations}`);
238
+ sections.push(formatSection("Relations", relations, sectionOptions));
222
239
  }
223
240
 
224
241
  if (comments.length > 0) {
225
- sections.push(`Comments:\n${comments}`);
242
+ sections.push(formatSection("Comments", comments, sectionOptions));
226
243
  }
227
244
 
228
245
  return sections.join("\n\n");
@@ -230,7 +247,8 @@ Example: zinn task search "refinement quota" MDR --limit 5`,
230
247
  },
231
248
  help: `Usage: zinn task view <task-key>
232
249
 
233
- Show a task with its current column, description, priority, labels, relations, and comments.
250
+ Show a task with its description, relations, and comments.
251
+ A section is shown when the task has that content. The description prints in full, keeping its line breaks.
234
252
 
235
253
  Example: zinn task view MDR-1`,
236
254
  },
@@ -285,18 +303,18 @@ Example: zinn task view MDR-1`,
285
303
  currentActor(),
286
304
  );
287
305
 
288
- output(presentTask(editedTask), formatTask);
306
+ output(presentTask(editedTask), formatTaskRow);
289
307
  },
290
308
  help: `Usage: zinn task edit <task-key> [--title <text>] [--description <text>] [--priority {low|medium|high|urgent|none}] [--add-label <name>] [--remove-label <name>]
291
309
 
292
- Change the supplied fields and preserve everything else.
310
+ Edit a task's title, description, priority, or label attachments.
293
311
  Use --priority none to clear priority.
294
312
  Provide at least one edit flag. Use --description "" to clear the description.
295
313
 
296
314
  Repeat --add-label or --remove-label for multiple existing labels.
297
315
  Label names are matched case-insensitively.
298
316
  Adding an attached label or removing an unattached label does not do anything.
299
- Archived tasks can be edited. Unchanged values leave the task unchanged.
317
+ Archived tasks can be edited.
300
318
 
301
319
  The same label cannot be both added and removed.
302
320
  Titles cannot be blank.
@@ -307,31 +325,40 @@ Example: zinn task edit MDR-1 --title "Meet the quarterly refinement quota"`,
307
325
  },
308
326
  move: {
309
327
  run: (args) => {
310
- const [taskKey, targetColumn] = args;
328
+ const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
329
+ const taskKeys = positionals.slice(0, -1);
330
+ const targetColumn = positionals.at(-1);
311
331
 
312
- if (taskKey == null) {
332
+ if (targetColumn == null) {
313
333
  quit("Task key must be specified");
314
334
  }
315
335
 
316
- if (targetColumn == null) {
336
+ if (taskKeys.length === 0) {
317
337
  quit("Target column must be specified");
318
338
  }
319
339
 
320
- const movedTask = task.move({ taskKey, targetColumn }, currentActor());
321
- output(presentTask(movedTask), formatTaskMove);
340
+ const moves = task.moveMany({ taskKeys, targetColumn }, currentActor());
341
+ outputTaskChanges(
342
+ moves,
343
+ formatTaskList,
344
+ (movedTask) => `${movedTask.key} was already in the ${movedTask.column} column`,
345
+ );
322
346
  },
323
- help: `Usage: zinn task move <task-key> <target-column>
347
+ help: `Usage: zinn task move <task-key>... <target-column>
324
348
 
325
- Move a task to another column in its project.
349
+ Move tasks to another column in their projects.
326
350
  Moving a task to a different column lists it last in that column,
327
351
  matching placement at the bottom of a visual kanban column.
352
+ Several tasks are moved in the order given, and each task's column is looked up in its own project.
328
353
 
329
- Prints the task's key and new column.
330
-
331
- Giving a task's current column as the target will not do anything.
354
+ Giving a task's current column as the target will not do anything, and a note says so.
332
355
  Archived tasks must be unarchived before they can be moved.
356
+ On bulk changes, if any task cannot be moved, the bulk operation is aborted.
357
+
358
+ With --json, one task prints an object and several print an array.
359
+ Each task's changed field is 'false' when it was already in the requested state.
333
360
 
334
- Example: zinn task move MDR-1 "In Progress"`,
361
+ Example: zinn task move MDR-1 MDR-2 "In Progress"`,
335
362
  },
336
363
  order: {
337
364
  run: (args) => {
@@ -357,7 +384,7 @@ Example: zinn task move MDR-1 "In Progress"`,
357
384
  }
358
385
 
359
386
  const orderedTask = task.order({ taskKey, direction, targetTaskKey }, currentActor());
360
- output(presentTask(orderedTask), formatTask);
387
+ output(presentTask(orderedTask), formatTaskRow);
361
388
  return;
362
389
  }
363
390
  case "top":
@@ -369,7 +396,7 @@ Example: zinn task move MDR-1 "In Progress"`,
369
396
  }
370
397
 
371
398
  const orderedTask = task.order({ taskKey, direction }, currentActor());
372
- output(presentTask(orderedTask), formatTask);
399
+ output(presentTask(orderedTask), formatTaskRow);
373
400
  return;
374
401
  }
375
402
  default:
@@ -387,37 +414,45 @@ Example: zinn task order MDR-2 before MDR-1`,
387
414
  },
388
415
  archive: {
389
416
  run: (args: Array<string>) => {
390
- const taskKey = args[0];
391
-
392
- if (taskKey == null) {
393
- quit("Task key must be specified");
394
- }
395
-
396
- const archivedTask = task.archive(taskKey, currentActor());
397
- output(presentTask(archivedTask), formatTaskWithStatus);
417
+ const taskKeys = parseTaskKeys(args);
418
+ const archives = task.archiveMany(taskKeys, currentActor());
419
+ outputTaskChanges(
420
+ archives,
421
+ formatTaskListWithStatus,
422
+ (archivedTask) => `${archivedTask.key} was already archived`,
423
+ );
398
424
  },
399
- help: `Usage: zinn task archive <task-key>
425
+ help: `Usage: zinn task archive <task-key>...
400
426
 
401
- Archive a task so it no longer appears in active task lists.
427
+ Archive tasks so they no longer appear in active task lists.
428
+ Archiving an archived task does not do anything.
429
+ On bulk changes, if any task cannot be archived, the bulk operation is aborted.
402
430
 
403
- Example: zinn task archive MDR-1`,
431
+ With --json, one task prints an object and several print an array.
432
+ Each task's changed field is 'false' when it was already in the requested state.
433
+
434
+ Example: zinn task archive MDR-1 MDR-2`,
404
435
  },
405
436
  unarchive: {
406
437
  run: (args: Array<string>) => {
407
- const taskKey = args[0];
408
-
409
- if (taskKey == null) {
410
- quit("Task key must be specified");
411
- }
412
-
413
- const unarchivedTask = task.unarchive(taskKey, currentActor());
414
- output(presentTask(unarchivedTask), formatTaskWithStatus);
438
+ const taskKeys = parseTaskKeys(args);
439
+ const unarchives = task.unarchiveMany(taskKeys, currentActor());
440
+ outputTaskChanges(
441
+ unarchives,
442
+ formatTaskListWithStatus,
443
+ (unarchivedTask) => `${unarchivedTask.key} was already active`,
444
+ );
415
445
  },
416
- help: `Usage: zinn task unarchive <task-key>
446
+ help: `Usage: zinn task unarchive <task-key>...
417
447
 
418
- Unarchive a task at the bottom of its previous column.
448
+ Unarchive tasks at the bottom of their previous columns, in the order given.
449
+ Unarchiving an active task does not do anything.
450
+ On bulk changes, if any task cannot be unarchived, the bulk operation is aborted.
419
451
 
420
- Example: zinn task unarchive MDR-1`,
452
+ With --json, one task prints an object and several print an array.
453
+ Each task's changed field is 'false' when it was already in the requested state.
454
+
455
+ Example: zinn task unarchive MDR-1 MDR-2`,
421
456
  },
422
457
  delete: {
423
458
  run: (args: Array<string>) => {
@@ -443,12 +478,12 @@ Example: zinn task unarchive MDR-1`,
443
478
 
444
479
  if (canDelete) {
445
480
  task.delete(taskKey, currentActor());
446
- output(presented, (t) => `Deleted ${formatTask(t)}`);
481
+ output(presented, (t) => `Deleted ${formatTaskRow(t)}`);
447
482
  } else {
448
- output(presented, (t) => `Deletion cancelled for ${formatTask(t)}`);
483
+ output(presented, (t) => `Deletion cancelled for ${formatTaskRow(t)}`);
449
484
  }
450
485
  } catch (err: any) {
451
- quit(err?.message ?? "Something went wrong");
486
+ quit(failureMessage(err, "Something went wrong"));
452
487
  }
453
488
  },
454
489
  help: `Usage: zinn task delete <task-key> [--yes]
@@ -464,7 +499,7 @@ Example: zinn task delete MDR-1`,
464
499
  add: {
465
500
  run: (args) => {
466
501
  const props = parseTaskLabelArgs(args);
467
- output(presentTask(task.label.add(props, currentActor())), formatTask);
502
+ output(presentTask(task.label.add(props, currentActor())), formatTaskRow);
468
503
  },
469
504
  help: `Usage: zinn task label add <task-key> <label-name>...
470
505
 
@@ -474,7 +509,7 @@ Already attached labels are unchanged.`,
474
509
  remove: {
475
510
  run: (args) => {
476
511
  const props = parseTaskLabelArgs(args);
477
- output(presentTask(task.label.remove(props, currentActor())), formatTask);
512
+ output(presentTask(task.label.remove(props, currentActor())), formatTaskRow);
478
513
  },
479
514
  help: `Usage: zinn task label remove <task-key> <label-name>...
480
515
 
@@ -483,6 +518,43 @@ Remove existing labels from a task. Label names are matched case-insensitively.`
483
518
  },
484
519
  } satisfies RouteDef;
485
520
 
521
+ function parseTaskKeys(args: Array<string>) {
522
+ const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
523
+
524
+ if (positionals.length === 0) {
525
+ quit("Task key must be specified");
526
+ }
527
+
528
+ return positionals;
529
+ }
530
+
531
+ /**
532
+ * Prints the changed tasks as rows, or as JSON: an object for one task and an array for several.
533
+ * JSON includes each task's `changed` flag, and each unchanged task also gets a note on stderr.
534
+ */
535
+ function outputTaskChanges(
536
+ changes: Array<TaskChange>,
537
+ formatTasks: (presentedTasks: Array<PresentedTask>) => string,
538
+ describeUnchanged: (presentedTask: PresentedTask) => string,
539
+ ) {
540
+ const presentedChanges = changes.map((change) => ({
541
+ ...presentTask(change.task),
542
+ changed: change.changed,
543
+ }));
544
+
545
+ if (presentedChanges.length === 1) {
546
+ output(presentedChanges[0]!, (presentedChange) => formatTasks([presentedChange]));
547
+ } else {
548
+ output(presentedChanges, formatTasks);
549
+ }
550
+
551
+ for (const presentedChange of presentedChanges) {
552
+ if (!presentedChange.changed) {
553
+ console.error(describeUnchanged(presentedChange));
554
+ }
555
+ }
556
+ }
557
+
486
558
  function parseTaskLabelArgs(args: string[]) {
487
559
  const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
488
560
  if (positionals.length < 2) {