@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,47 +1,26 @@
1
1
  import { jsonResult } from "../results.js";
2
2
  import { parseArgs } from "node:util";
3
- import { column, project, columnOrderSchema } from "@zinn-dev/core";
3
+ import { column, project, columnOrderSchema, projectCreateSchema, projectEditSchema, } from "@zinn-dev/core";
4
4
  import { CliError } from "../errors.js";
5
5
  import { generateCommandUsage, getOptionInputs, noInput, violatesConstraint } from "../input.js";
6
- import { confirmationDescription, canPrompt, confirmAction, dashValueHelp, diagnostic, output, quit, validatePositionals, validateOrderForms, requireStringOption, validateUniqueOptions, } from "../lib.js";
6
+ import { confirmationDescription, canPrompt, confirmAction, dashValueHelp, diagnostic, output, outputChanges, quit, validatePositionals, validateOrderForms, requireStringOption, validateUniqueOptions, } from "../lib.js";
7
7
  import { resolveTextEdit, textEditHelp, textEditOptions, textEditConstraints, } from "../text-edit.js";
8
- import { formatColumnList } from "../presentation/column-presentation.js";
9
- import { formatDescriptionPreview } from "../presentation/description-presentation.js";
10
- import { formatCellSeparator, formatRows } from "../presentation/row-layout.js";
8
+ import { checkFieldsBeforeText, resolveTextInput, textFileHelp, textFileOption, textSourceConstraint, } from "../text-input.js";
9
+ import { formatColumnList, presentColumn } from "../presentation/column-presentation.js";
10
+ import { formatProjectList, presentProject } from "../presentation/project-presentation.js";
11
11
  import { formatSection } from "../presentation/section.js";
12
12
  import { currentActor } from "../actor.js";
13
- import { resolveProjectKey, requiredProjectDescription } from "../project.js";
14
- function presentProject(projectMatch) {
15
- return { key: projectMatch.key, name: projectMatch.name, description: projectMatch.description };
16
- }
17
- function formatProject(presented, options = {}) {
18
- return formatProjectList([presented], options);
19
- }
20
- function formatProjectList(presentedProjects, { showsDescriptionPreview = true } = {}) {
21
- return formatRows(presentedProjects.map((presented) => {
22
- const descriptionPreview = showsDescriptionPreview
23
- ? formatDescriptionPreview(presented.description)
24
- : "";
25
- const description = descriptionPreview.length > 0 ? `${formatCellSeparator()}${descriptionPreview}` : "";
26
- return [{ text: presented.key }, { text: `${presented.name}${description}` }];
27
- }));
28
- }
29
- function presentColumn(columnMatch) {
30
- const columnProject = project.getById(columnMatch.project_id);
31
- return { project: columnProject.key, name: columnMatch.name };
32
- }
33
- function formatColumn(presented) {
34
- return formatColumnList([presented], { showsProject: true });
35
- }
13
+ import { checkDefaultProject, chooseProjectKey, resolveProjectKey, requiredProjectDescription, } from "../project.js";
36
14
  const projectEditConstraint = {
37
15
  kind: "atLeastOne",
38
- members: ["option:name", "option:description"],
16
+ members: ["option:name", "option:description", "option:description-file"],
39
17
  };
40
18
  const projectInputs = {
41
19
  create: {
42
20
  options: {
43
21
  name: { type: "string", value: { kind: "text", name: "text" } },
44
22
  description: { type: "string", value: { kind: "text", name: "text" } },
23
+ "description-file": textFileOption,
45
24
  },
46
25
  forms: [
47
26
  {
@@ -49,7 +28,7 @@ const projectInputs = {
49
28
  positionals: [{ name: "project-key", min: 1, max: 1, value: { kind: "project-key" } }],
50
29
  },
51
30
  ],
52
- constraints: [],
31
+ constraints: [textSourceConstraint("--description")],
53
32
  },
54
33
  list: noInput,
55
34
  view: {
@@ -67,6 +46,7 @@ const projectInputs = {
67
46
  options: {
68
47
  name: { type: "string", value: { kind: "text", name: "text" } },
69
48
  description: { type: "string", value: { kind: "text", name: "text" } },
49
+ "description-file": textFileOption,
70
50
  ...textEditOptions,
71
51
  },
72
52
  forms: [
@@ -75,7 +55,11 @@ const projectInputs = {
75
55
  positionals: [{ name: "project-key", min: 0, max: 1, value: { kind: "project-key" } }],
76
56
  },
77
57
  ],
78
- constraints: [...textEditConstraints("--description"), projectEditConstraint],
58
+ constraints: [
59
+ textSourceConstraint("--description"),
60
+ ...textEditConstraints("--description"),
61
+ projectEditConstraint,
62
+ ],
79
63
  notes: [requiredProjectDescription, textEditHelp("--description")],
80
64
  },
81
65
  delete: {
@@ -167,7 +151,7 @@ export const projectRouter = {
167
151
  confirmation: { kind: "none" },
168
152
  input: projectInputs.create,
169
153
  results: [jsonResult("Project")],
170
- run: (args) => {
154
+ run: async (args) => {
171
155
  const { values, positionals, tokens } = parseArgs({
172
156
  args,
173
157
  options: projectInputs.create.options,
@@ -178,9 +162,11 @@ export const projectRouter = {
178
162
  validateUniqueOptions(tokens, projectInputs.create.options);
179
163
  validatePositionals(positionals, projectInputs.create.forms[0]);
180
164
  const projectKey = positionals[0];
165
+ checkFieldsBeforeText(projectCreateSchema, { key: projectKey, name: values.name });
166
+ const description = await resolveTextInput(values.description, values["description-file"], "--description");
181
167
  try {
182
- const createdProject = project.create({ key: projectKey, name: values.name, description: values.description }, currentActor());
183
- output(presentProject(createdProject), formatProject);
168
+ const createdProject = project.create({ key: projectKey, name: values.name, description }, currentActor());
169
+ output(presentProject(createdProject), (entry) => formatProjectList([entry]));
184
170
  }
185
171
  catch (err) {
186
172
  throw err;
@@ -194,6 +180,7 @@ Project keys are stored in uppercase.
194
180
  An omitted name defaults to the uppercase project key.
195
181
  Names are trimmed and cannot be blank or contain line breaks or control characters.
196
182
  Descriptions may contain multiple lines. If omitted, they are saved as null.
183
+ ${textFileHelp("--description")}
197
184
 
198
185
  ${dashValueHelp("--description")}
199
186
 
@@ -245,6 +232,7 @@ Example: zinn project list`,
245
232
  const presentedProject = {
246
233
  ...presentProject(projectMatch),
247
234
  columns: taskCounts.columns.map((columnCount) => ({
235
+ id: columnCount.column.id,
248
236
  name: columnCount.column.name,
249
237
  taskCount: columnCount.taskCount,
250
238
  })),
@@ -252,7 +240,7 @@ Example: zinn project list`,
252
240
  };
253
241
  output(presentedProject, (viewedProject) => {
254
242
  // The full description follows as its own section, so the row leaves out the preview.
255
- const sections = [formatProject(viewedProject, { showsDescriptionPreview: false })];
243
+ const sections = [formatProjectList([viewedProject], { showsDescriptionPreview: false })];
256
244
  if (viewedProject.description != null) {
257
245
  sections.push(formatSection("Description", viewedProject.description));
258
246
  }
@@ -277,8 +265,8 @@ Example: zinn project view MDR`,
277
265
  effects: { domain: "update", storage: "normal-open" },
278
266
  confirmation: { kind: "none" },
279
267
  input: projectInputs.edit,
280
- results: [jsonResult("Project")],
281
- run: (args) => {
268
+ results: [jsonResult("ProjectChange")],
269
+ run: async (args) => {
282
270
  const { values, positionals, tokens } = parseArgs({
283
271
  args,
284
272
  options: projectInputs.edit.options,
@@ -288,19 +276,29 @@ Example: zinn project view MDR`,
288
276
  });
289
277
  validateUniqueOptions(tokens, projectInputs.edit.options);
290
278
  validatePositionals(positionals, projectInputs.edit.forms[0]);
291
- const projectKey = resolveProjectKey(positionals[0], { required: true });
292
- const description = resolveTextEdit(values.description, values, "--description");
293
- if (violatesConstraint(projectEditConstraint, getOptionInputs({ ...values, description }))) {
294
- quit("Provide an edit flag: --name or --description", undefined, { field: [] });
279
+ const projectChoice = chooseProjectKey(positionals[0], { required: true });
280
+ checkFieldsBeforeText(projectEditSchema, {
281
+ projectKey: projectChoice.key,
282
+ name: values.name,
283
+ });
284
+ const description = await resolveTextEdit(values, "--description");
285
+ // Without a text source nothing was read, so this usage error still comes before any input
286
+ if (violatesConstraint(projectEditConstraint, getOptionInputs(values))) {
287
+ quit("Provide an edit flag: --name, --description or --description-file", undefined, {
288
+ field: [],
289
+ });
295
290
  }
296
- const editedProject = project.edit({ projectKey, name: values.name, description }, currentActor());
297
- output(presentProject(editedProject), formatProject);
291
+ checkDefaultProject(projectChoice);
292
+ const editedProject = project.edit({ projectKey: projectChoice.key, name: values.name, description }, currentActor());
293
+ outputChanges([editedProject], (change) => presentProject(change.project), formatProjectList, (entry) => `Project ${entry.key} was unchanged`);
298
294
  },
299
295
  help: `${generateCommandUsage("project edit", projectInputs.edit)}
300
296
 
301
297
  Change the supplied project fields. At least one edit flag is required.
298
+ With --json, changed is false when all supplied values already match.
302
299
  ${requiredProjectDescription}
303
300
  Use --description '' to clear the description.
301
+ ${textFileHelp("--description")}
304
302
 
305
303
  ${textEditHelp("--description")}
306
304
 
@@ -353,10 +351,10 @@ Examples:
353
351
  : undefined);
354
352
  if (canDelete) {
355
353
  const deletedProject = project.delete(projectKey, currentActor());
356
- output(presentProject(deletedProject), (p) => `Deleted ${formatProject(p)}`);
354
+ output(presentProject(deletedProject), (p) => `Deleted ${formatProjectList([p])}`);
357
355
  }
358
356
  else {
359
- output(presentProject(projectMatch), (p) => `Deletion cancelled for ${formatProject(p)}`);
357
+ output(presentProject(projectMatch), (p) => `Deletion cancelled for ${formatProjectList([p])}`);
360
358
  }
361
359
  }
362
360
  catch (err) {
@@ -391,7 +389,7 @@ Example: zinn project delete MDR`,
391
389
  const columnName = positionals[1];
392
390
  try {
393
391
  const createdColumn = column.create({ projectKey, name: columnName }, currentActor());
394
- output(presentColumn(createdColumn), formatColumn);
392
+ output(presentColumn(createdColumn), (entry) => formatColumnList([entry], { showsProject: true }));
395
393
  }
396
394
  catch (err) {
397
395
  throw err;
@@ -421,6 +419,7 @@ Example: zinn project column create MDR Boardlog`,
421
419
  const projectKey = resolveProjectKey(positionals[0], { required: true });
422
420
  const taskCounts = column.getTaskCountsByProjectKey(projectKey);
423
421
  const columns = taskCounts.columns.map((columnCount) => ({
422
+ id: columnCount.column.id,
424
423
  name: columnCount.column.name,
425
424
  taskCount: columnCount.taskCount,
426
425
  }));
@@ -440,7 +439,7 @@ Example: zinn project column list MDR`,
440
439
  effects: { domain: "update", storage: "normal-open" },
441
440
  confirmation: { kind: "none" },
442
441
  input: projectInputs.column_edit,
443
- results: [jsonResult("Column")],
442
+ results: [jsonResult("ColumnChange")],
444
443
  run: (args) => {
445
444
  const { values, positionals, tokens } = parseArgs({
446
445
  args,
@@ -457,12 +456,13 @@ Example: zinn project column list MDR`,
457
456
  columnName: positionals[1],
458
457
  name,
459
458
  }, currentActor());
460
- output(presentColumn(editedColumn), formatColumn);
459
+ outputChanges([editedColumn], (change) => presentColumn(change.column), (entries) => formatColumnList(entries, { showsProject: true }), (entry) => `Column "${entry.name}" was unchanged`);
461
460
  },
462
461
  help: `${generateCommandUsage("project column edit", projectInputs.column_edit)}
463
462
 
464
463
  Rename a column.
465
464
  The --name flag is required.
465
+ With --json, changed is false when the name already matches.
466
466
 
467
467
  Columns are matched by name, and matching is case-insensitive.
468
468
  Names are trimmed, and must remain unique within the same project.
@@ -477,7 +477,7 @@ Example: zinn project column edit MDR 'In Progress' --name Refining`,
477
477
  effects: { domain: "update", storage: "normal-open" },
478
478
  confirmation: { kind: "none" },
479
479
  input: projectInputs.column_order,
480
- results: [jsonResult("Column")],
480
+ results: [jsonResult("ColumnChange")],
481
481
  run: (args) => {
482
482
  const { positionals } = parseArgs({
483
483
  options: projectInputs.column_order.options,
@@ -490,15 +490,17 @@ Example: zinn project column edit MDR 'In Progress' --name Refining`,
490
490
  const columnName = positionals[1];
491
491
  let orderedColumn;
492
492
  if (form.id === "relative") {
493
- const direction = positionals[2];
494
- orderedColumn = column.order({ projectKey, columnName, direction, targetColumnName: positionals[3] }, currentActor());
493
+ orderedColumn = column.order({
494
+ projectKey,
495
+ columnName,
496
+ direction: form.direction,
497
+ targetColumnName: positionals[form.directionIndex + 1],
498
+ }, currentActor());
495
499
  }
496
500
  else {
497
- const direction = positionals[2];
498
- orderedColumn = column.order({ projectKey, columnName, direction }, currentActor());
501
+ orderedColumn = column.order({ projectKey, columnName, direction: form.direction }, currentActor());
499
502
  }
500
- // TODO: maybe also print the new full column state?
501
- output(presentColumn(orderedColumn), formatColumn);
503
+ outputChanges([orderedColumn], (change) => presentColumn(change.column), (entries) => formatColumnList(entries, { showsProject: true }), (entry) => `Column "${entry.name}" was already in that position`);
502
504
  },
503
505
  help: `${generateCommandUsage("project column order", projectInputs.column_order)}
504
506
 
@@ -507,6 +509,8 @@ Use first or last for either end, previous or next for one position,
507
509
  or before or after to place it relative to another column.
508
510
 
509
511
  Columns are matched by name, and matching is case-insensitive.
512
+ Ordering to the current position, or before or after itself, leaves the column unchanged.
513
+ With --json, changed is false when the column was already in that position.
510
514
 
511
515
  Example: zinn project column order MDR Review before 'In Progress'`,
512
516
  },
@@ -1,7 +1,3 @@
1
- import type { PresentedRelation } from "../result-schemas.js";
2
- import type { TaskWithKey } from "@zinn-dev/core";
3
- export declare function presentRelations(taskMatch: TaskWithKey): Array<PresentedRelation>;
4
- export declare function formatRelations(relations: Array<PresentedRelation>): string;
5
1
  export declare const relationRouter: {
6
2
  create: {
7
3
  summary: string;
@@ -19,7 +15,6 @@ export declare const relationRouter: {
19
15
  readonly required: true;
20
16
  readonly value: {
21
17
  readonly kind: "enum";
22
- readonly name: "type";
23
18
  readonly choices: ("related" | "dependency" | "duplicate" | "subtask")[];
24
19
  };
25
20
  };
@@ -45,6 +40,9 @@ export declare const relationRouter: {
45
40
  readonly constraints: readonly [];
46
41
  };
47
42
  results: import("../results.js").CommandResult[];
43
+ guessedFlags: {
44
+ [k: string]: (args: Array<string>) => string[] | undefined;
45
+ };
48
46
  run: (args: string[]) => void;
49
47
  help: string;
50
48
  };
@@ -92,7 +90,6 @@ export declare const relationRouter: {
92
90
  readonly required: true;
93
91
  readonly value: {
94
92
  readonly kind: "enum";
95
- readonly name: "type";
96
93
  readonly choices: ("related" | "dependency" | "duplicate" | "subtask")[];
97
94
  };
98
95
  };
@@ -118,6 +115,9 @@ export declare const relationRouter: {
118
115
  readonly constraints: readonly [];
119
116
  };
120
117
  results: import("../results.js").CommandResult[];
118
+ guessedFlags: {
119
+ [k: string]: (args: Array<string>) => string[] | undefined;
120
+ };
121
121
  run: (args: string[]) => void;
122
122
  help: string;
123
123
  };
@@ -1,64 +1,48 @@
1
- import { jsonResult } from "../results.js";
2
1
  import { parseArgs } from "node:util";
3
- import { column, relation, relationTypeSchema, task } from "@zinn-dev/core";
2
+ import { relation, relationTypeSchema, task } from "@zinn-dev/core";
3
+ import { jsonResult } from "../results.js";
4
4
  import { generateCommandUsage, taskKeyPositional } from "../input.js";
5
5
  import { output, quit, requireStringOption, validatePositionals, validateUniqueOptions, } from "../lib.js";
6
6
  import { currentActor } from "../actor.js";
7
- import { formatCellSeparator, formatRows } from "../presentation/row-layout.js";
8
- import { columnNameCell } from "../presentation/column-presentation.js";
9
- export function presentRelations(taskMatch) {
10
- return relation.getAll(taskMatch.key, { include: { tasks: true } }).map((entry) => {
11
- const isSource = entry.source_task_id === taskMatch.id;
12
- const other = isSource ? entry.target : entry.source;
13
- if (other == null) {
14
- throw new Error("Connected task details were not included in the relation");
15
- }
16
- let direction = null;
17
- if (entry.relation_type !== "related") {
18
- direction = isSource ? "outgoing" : "incoming";
7
+ import { formatRelationChange, formatRelationList, presentRelations, } from "../presentation/relation-presentation.js";
8
+ const guessedRelationTypes = new Map([
9
+ ["depends-on", "dependency"],
10
+ ["parent", "subtask"],
11
+ ["duplicate-of", "duplicate"],
12
+ ["related", "related"],
13
+ ]);
14
+ function relationFlagSuggestions(action) {
15
+ const options = {
16
+ ...relationInputs.create.options,
17
+ ...Object.fromEntries([...guessedRelationTypes.keys()].map((name) => [name, { type: "string" }])),
18
+ };
19
+ const suggest = (args) => {
20
+ const { positionals, tokens } = parseArgs({
21
+ args,
22
+ options,
23
+ allowPositionals: true,
24
+ strict: false,
25
+ tokens: true,
26
+ });
27
+ const relationFlags = tokens.filter((token) => token.kind === "option" && guessedRelationTypes.has(token.name));
28
+ const guessed = relationFlags[0];
29
+ if (positionals.length !== 1 || relationFlags.length !== 1 || guessed?.kind !== "option") {
30
+ return undefined;
19
31
  }
20
- return {
21
- type: entry.relation_type,
22
- direction,
23
- task: {
24
- key: other.key,
25
- column: column.getById(other.column_id).name,
26
- title: other.title,
27
- status: other.archived_at == null ? "Active" : "Archived",
28
- },
29
- };
30
- });
31
- }
32
- export function formatRelations(relations) {
33
- return formatRows(relations.map((entry) => {
34
- const isOutgoing = entry.direction === "outgoing";
35
- let label = entry.type;
36
- switch (entry.type) {
37
- case "related": {
38
- label = "Related to";
39
- break;
40
- }
41
- case "dependency": {
42
- label = isOutgoing ? "Depends on" : "Depended on by";
43
- break;
44
- }
45
- case "subtask": {
46
- label = isOutgoing ? "Parent" : "Subtask";
47
- break;
48
- }
49
- case "duplicate": {
50
- label = isOutgoing ? "Duplicate of" : "Duplicated by";
51
- break;
52
- }
32
+ const type = guessedRelationTypes.get(guessed.name);
33
+ const typeFlags = tokens.filter((token) => token.kind === "option" && token.name === "type");
34
+ const hasConflictingType = typeFlags.some((token) => token.kind === "option" && token.value !== type);
35
+ const hasOtherOption = tokens.some((token) => token.kind === "option" && token.name !== "type" && !guessedRelationTypes.has(token.name));
36
+ const cannotSuggestRelation = typeof guessed.value !== "string" ||
37
+ typeFlags.length > 1 ||
38
+ hasConflictingType ||
39
+ hasOtherOption;
40
+ if (cannotSuggestRelation) {
41
+ return undefined;
53
42
  }
54
- const archived = entry.task.status === "Archived" ? `${formatCellSeparator()}Archived` : "";
55
- return [
56
- { text: label },
57
- { text: entry.task.key },
58
- columnNameCell(entry.task.column),
59
- { text: `${entry.task.title}${archived}` },
60
- ];
61
- }));
43
+ return ["task", "relation", action, positionals[0], guessed.value, "--type", type];
44
+ };
45
+ return Object.fromEntries([...guessedRelationTypes.keys()].map((name) => [`--${name}`, suggest]));
62
46
  }
63
47
  function parseRelationArgs(args) {
64
48
  const { values, positionals, tokens } = parseArgs({
@@ -89,7 +73,6 @@ const relationInputs = {
89
73
  required: true,
90
74
  value: {
91
75
  kind: "enum",
92
- name: "type",
93
76
  choices: relationTypeSchema.options,
94
77
  },
95
78
  },
@@ -123,26 +106,22 @@ export const relationRouter = {
123
106
  confirmation: { kind: "none" },
124
107
  input: relationInputs.create,
125
108
  results: [jsonResult("RelationChange")],
109
+ guessedFlags: relationFlagSuggestions("create"),
126
110
  run: (args) => {
127
111
  const props = parseRelationArgs(args);
128
112
  const { sourceTaskKey, targetTaskKey } = props;
129
- relation.create(props, currentActor());
113
+ const createdRelation = relation.create(props, currentActor());
130
114
  const source = task.getByKey(sourceTaskKey);
131
115
  const target = task.getByKey(targetTaskKey);
132
116
  const created = {
117
+ id: createdRelation.id,
133
118
  type: props.relation_type,
134
119
  source: source.key,
120
+ source_task_id: source.id,
135
121
  target: target.key,
122
+ target_task_id: target.id,
136
123
  };
137
- output(created, (r) => {
138
- const label = {
139
- related: "related to",
140
- dependency: "depends on",
141
- duplicate: "is a duplicate of",
142
- subtask: "is a subtask of",
143
- }[r.type];
144
- return `${r.source} ${label} ${r.target}`;
145
- });
124
+ output(created, (entry) => formatRelationChange(entry, { action: "create" }));
146
125
  },
147
126
  help: `${generateCommandUsage("task relation create", relationInputs.create)}
148
127
 
@@ -177,7 +156,7 @@ Example: zinn task relation create APP-1 APP-2 --type dependency`,
177
156
  strict: true,
178
157
  });
179
158
  validatePositionals(positionals, relationInputs.list.forms[0]);
180
- output(presentRelations(task.getByKey(positionals[0])), formatRelations);
159
+ output(presentRelations(task.getByKey(positionals[0])), formatRelationList);
181
160
  },
182
161
  help: `${generateCommandUsage("task relation list", relationInputs.list)}
183
162
 
@@ -193,17 +172,21 @@ Example: zinn task relation list APP-1`,
193
172
  confirmation: { kind: "none" },
194
173
  input: relationInputs.create,
195
174
  results: [jsonResult("RelationChange")],
175
+ guessedFlags: relationFlagSuggestions("delete"),
196
176
  run: (args) => {
197
177
  const props = parseRelationArgs(args);
198
- relation.delete(props, currentActor());
178
+ const deletedRelation = relation.delete(props, currentActor());
199
179
  const source = task.getByKey(props.sourceTaskKey);
200
180
  const target = task.getByKey(props.targetTaskKey);
201
181
  const deleted = {
182
+ id: deletedRelation.id,
202
183
  type: props.relation_type,
203
184
  source: source.key,
185
+ source_task_id: source.id,
204
186
  target: target.key,
187
+ target_task_id: target.id,
205
188
  };
206
- output(deleted, (r) => `Deleted ${r.type} relation from ${r.source} to ${r.target}`);
189
+ output(deleted, (entry) => formatRelationChange(entry, { action: "delete" }));
207
190
  },
208
191
  help: `${generateCommandUsage("task relation delete", relationInputs.create)}
209
192
 
@@ -80,7 +80,7 @@ Replace the database with the one in a backup file, such as one saved by \`zinn
80
80
 
81
81
  The current database is saved first, in the same place as \`zinn backup\`, and the restore is applied completely or not at all.
82
82
  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\`.
83
- Restoring onto a missing database creates it.
83
+ Restoring onto a missing database creates it inside an existing Zinn folder.
84
84
  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.
85
85
  Use --yes to skip the confirmation prompt, for example in scripts or with --json.
86
86
 
@@ -1,6 +1,6 @@
1
1
  import type { ParsedRoute, RouteDef } from "../types.js";
2
2
  export declare function parseRoutes(routesDef: RouteDef, prefix?: string): ParsedRoute[];
3
- export declare function createRouter(routesDef: RouteDef, beforeRun?: (command: ParsedRoute) => void | Promise<void>): {
3
+ export declare function createRouter(routesDef: RouteDef | Array<ParsedRoute>, beforeRun?: (command: ParsedRoute) => void | Promise<void>): {
4
4
  route: (args: Array<string>) => Promise<void>;
5
5
  help: string;
6
6
  };
@@ -1,6 +1,9 @@
1
1
  import { parseArgs } from "node:util";
2
2
  import { routerOptions, helpSpellings, versionSpellings, usageLabel } from "../input.js";
3
- import { dashValueHelp, diagnostic, flushDiagnostics, isAllowLegacyReadFlag, isHelpFlag, isRouterFlag, parseArgsMessage, prepareOutput, quit, renderFailure, setLegacyReadAllowed, UsageError, validateUniqueOptions, } from "../lib.js";
3
+ import { getCommandAliases } from "./aliases.js";
4
+ import { classifyFailure, CliError } from "../errors.js";
5
+ import { quotedColumnHint } from "../column-hint.js";
6
+ import { dashValueHelp, diagnostic, failureMessage, flushDiagnostics, isAllowLegacyReadFlag, isHelpFlag, isRouterFlag, parseArgsMessage, prepareOutput, quit, renderFailure, setLegacyReadAllowed, UsageError, validateUniqueOptions, } from "../lib.js";
4
7
  // ZINN_DEBUG=1 prints routing detail on stderr, so stdout and `--json` results stay unchanged.
5
8
  function isDebugOutputEnabled() {
6
9
  return process.env.ZINN_DEBUG === "1";
@@ -22,6 +25,14 @@ function validateRouterFlags(routableArgs) {
22
25
  function getUsage(help) {
23
26
  return help.split("\n\n")[0];
24
27
  }
28
+ function getCommandHelp(help, aliases) {
29
+ if (aliases.length === 0) {
30
+ return help;
31
+ }
32
+ const [usage, ...details] = help.split("\n\n");
33
+ const aliasLine = `Alias: ${aliases.map((path) => `zinn ${path.join(" ")}`).join(", ")}`;
34
+ return [usage, aliasLine, ...details].join("\n\n");
35
+ }
25
36
  function toCommand(args) {
26
37
  return args.join(" ");
27
38
  }
@@ -52,7 +63,7 @@ function formatCommands(parsedRoutes, prefix) {
52
63
  }
53
64
  function getRootHelp(parsedRoutes) {
54
65
  // TODO: maybe "brand" text that is exported and used here for title and desc
55
- return `ZINN - A kanban workflow in the terminal
66
+ return `ZINN - A kanban workflow in the terminal. Experimental.
56
67
 
57
68
  ${usageLabel}zinn <command>
58
69
 
@@ -67,10 +78,8 @@ ${formatCommands(parsedRoutes, "")}
67
78
 
68
79
  Run zinn <namespace> --help or zinn <command> --help for more information.
69
80
  --help shows help for the command words before it and runs nothing. The rest of the line is ignored.
70
- -- ends the options: everything after it is considered a plain word, even if it starts with a dash (e.g. 'zinn project column create SHOP -- -later').
71
- Flags after it are not read.
72
- ${dashValueHelp("--description")}
73
- Running zinn without a command shows this help.`;
81
+ -- ends the options; every word after it is positional, even if it starts with a dash.
82
+ ${dashValueHelp("--description")}`;
74
83
  }
75
84
  function getNamespaceHelp(parsedRoutes, namespace) {
76
85
  const commands = formatCommands(parsedRoutes, `${namespace} `);
@@ -120,7 +129,13 @@ export function parseRoutes(routesDef, prefix) {
120
129
  const isRunnable = getIsRunnable(definition);
121
130
  const combinedRoute = prefix ? `${prefix} ${key}` : key;
122
131
  if (isRunnable) {
123
- routeDefinitions.push({ command: combinedRoute, ...definition });
132
+ const aliases = getCommandAliases(combinedRoute);
133
+ routeDefinitions.push({
134
+ ...definition,
135
+ command: combinedRoute,
136
+ aliases,
137
+ help: getCommandHelp(definition.help, aliases),
138
+ });
124
139
  }
125
140
  else {
126
141
  const result = parseRoutes(definition, combinedRoute);
@@ -149,7 +164,7 @@ async function route(parsedRoutes, rawArgs, beforeRun) {
149
164
  let nestingLevel = 0;
150
165
  for (let endIndex = args.length; endIndex >= 0; endIndex--) {
151
166
  const command = toCommand(args.slice(0, endIndex));
152
- const matchedRoute = parsedRoutes.find((r) => r.command === command);
167
+ const matchedRoute = parsedRoutes.find((r) => r.command === command || r.aliases.some((path) => toCommand(path) === command));
153
168
  if (matchedRoute) {
154
169
  match = matchedRoute;
155
170
  nestingLevel = endIndex;
@@ -176,8 +191,22 @@ async function route(parsedRoutes, rawArgs, beforeRun) {
176
191
  catch (err) {
177
192
  if (err instanceof UsageError) {
178
193
  err.help = getUsage(match.help);
194
+ }
195
+ const columnHint = quotedColumnHint(err, match, rawArgs, nestingLevel);
196
+ if (columnHint !== undefined) {
197
+ const failure = classifyFailure(err);
198
+ throw new CliError(`${failureMessage(err, "Command failed")}. Did you mean: ${columnHint}`, failure.code, failure.details, failure.help ?? getUsage(match.help));
199
+ }
200
+ if (err instanceof UsageError) {
179
201
  throw err;
180
202
  }
203
+ if (match.command === "task search") {
204
+ const failure = classifyFailure(err);
205
+ const isMissingProject = failure.code === "not_found" && failure.details?.entity === "project";
206
+ if (isMissingProject) {
207
+ throw new CliError(failureMessage(err, "Search failed"), failure.code, failure.details, getUsage(match.help));
208
+ }
209
+ }
181
210
  const suggestFor = (flag) => match.guessedFlags?.[flag]?.(commandArgs);
182
211
  const parseArgsReason = parseArgsMessage(err, rawArgs, suggestFor);
183
212
  if (parseArgsReason != null) {
@@ -188,7 +217,7 @@ async function route(parsedRoutes, rawArgs, beforeRun) {
188
217
  }
189
218
  }
190
219
  export function createRouter(routesDef, beforeRun) {
191
- const parsedRoutes = parseRoutes(routesDef);
220
+ const parsedRoutes = Array.isArray(routesDef) ? routesDef : parseRoutes(routesDef);
192
221
  return {
193
222
  route: async (args) => {
194
223
  try {