@zinn-dev/cli 0.40.0 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +11 -561
  2. package/index.js +24 -13
  3. package/package.json +8 -2
  4. package/skills/zinn/SKILL.md +63 -0
  5. package/src/actor.d.ts +2 -1
  6. package/src/actor.js +78 -11
  7. package/src/capabilities-schema.d.ts +162 -0
  8. package/src/capabilities-schema.js +59 -0
  9. package/src/capabilities.d.ts +29 -0
  10. package/src/capabilities.js +30 -0
  11. package/src/column-hint.d.ts +3 -0
  12. package/src/column-hint.js +225 -0
  13. package/src/database.d.ts +1 -1
  14. package/src/database.js +5 -8
  15. package/src/errors.d.ts +158 -0
  16. package/src/errors.js +226 -0
  17. package/src/input.d.ts +227 -0
  18. package/src/input.js +192 -0
  19. package/src/lib.d.ts +71 -8
  20. package/src/lib.js +275 -18
  21. package/src/presentation/activity-presentation.d.ts +9 -1
  22. package/src/presentation/activity-presentation.js +120 -23
  23. package/src/presentation/capabilities-presentation.d.ts +2 -0
  24. package/src/presentation/capabilities-presentation.js +3 -0
  25. package/src/presentation/column-presentation.d.ts +9 -5
  26. package/src/presentation/column-presentation.js +10 -0
  27. package/src/presentation/comment-presentation.d.ts +15 -0
  28. package/src/presentation/comment-presentation.js +29 -0
  29. package/src/presentation/description-presentation.d.ts +17 -0
  30. package/src/presentation/description-presentation.js +26 -4
  31. package/src/presentation/info-presentation.d.ts +4 -0
  32. package/src/presentation/info-presentation.js +96 -0
  33. package/src/presentation/label-presentation.d.ts +8 -0
  34. package/src/presentation/label-presentation.js +28 -0
  35. package/src/presentation/project-presentation.d.ts +7 -0
  36. package/src/presentation/project-presentation.js +19 -0
  37. package/src/presentation/relation-presentation.d.ts +7 -0
  38. package/src/presentation/relation-presentation.js +73 -0
  39. package/src/presentation/task-presentation.d.ts +4 -12
  40. package/src/presentation/task-presentation.js +22 -18
  41. package/src/project.d.ts +18 -3
  42. package/src/project.js +37 -12
  43. package/src/result-schemas.d.ts +1194 -0
  44. package/src/result-schemas.js +279 -0
  45. package/src/results.d.ts +40 -0
  46. package/src/results.js +36 -0
  47. package/src/routes/activity-router.d.ts +104 -0
  48. package/src/routes/activity-router.js +155 -34
  49. package/src/routes/aliases.d.ts +2 -0
  50. package/src/routes/aliases.js +11 -0
  51. package/src/routes/backup-router.d.ts +17 -0
  52. package/src/routes/backup-router.js +15 -3
  53. package/src/routes/capabilities-router.d.ts +21 -0
  54. package/src/routes/capabilities-router.js +34 -0
  55. package/src/routes/comment-router.d.ts +210 -8
  56. package/src/routes/comment-router.js +189 -65
  57. package/src/routes/info-router.d.ts +21 -0
  58. package/src/routes/info-router.js +29 -0
  59. package/src/routes/label-router.d.ts +217 -2
  60. package/src/routes/label-router.js +189 -62
  61. package/src/routes/migrate-router.d.ts +17 -0
  62. package/src/routes/migrate-router.js +17 -5
  63. package/src/routes/project-router.d.ts +373 -2
  64. package/src/routes/project-router.js +322 -132
  65. package/src/routes/reindex-router.d.ts +17 -0
  66. package/src/routes/reindex-router.js +15 -3
  67. package/src/routes/relation-router.d.ts +110 -14
  68. package/src/routes/relation-router.js +122 -79
  69. package/src/routes/restore-router.d.ts +29 -0
  70. package/src/routes/restore-router.js +31 -14
  71. package/src/routes/router.d.ts +1 -1
  72. package/src/routes/router.js +80 -32
  73. package/src/routes/routes.d.ts +1781 -8
  74. package/src/routes/routes.js +9 -1
  75. package/src/routes/task-router.d.ts +946 -4
  76. package/src/routes/task-router.js +524 -260
  77. package/src/routes/whoami-router.d.ts +21 -0
  78. package/src/routes/whoami-router.js +31 -0
  79. package/src/text-edit.d.ts +28 -6
  80. package/src/text-edit.js +40 -23
  81. package/src/text-input.d.ts +47 -0
  82. package/src/text-input.js +187 -0
  83. package/src/types.d.ts +37 -0
  84. package/src/types.js +9 -1
@@ -1,131 +1,258 @@
1
+ import { jsonResult } from "../results.js";
1
2
  import { parseArgs } from "node:util";
2
- import { label, labelCreateSchema, labelDeleteSchema, labelEditSchema } from "@zinn-dev/core";
3
- import { confirmAction, output, quit, validatePositionals, validateUniqueOptions } from "../lib.js";
4
- import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit.js";
3
+ import { label, labelColorSchema, labelCreateSchema, labelDeleteSchema, labelEditSchema, } from "@zinn-dev/core";
4
+ import { CliError } from "../errors.js";
5
+ import { generateCommandUsage, noInput } from "../input.js";
6
+ import { confirmationDescription, confirmAction, dashValueHelp, output, outputChanges, validatePositionals, validateUniqueOptions, } from "../lib.js";
7
+ import { resolveTextEdit, textEditHelp, textEditOptions, textEditConstraints, } from "../text-edit.js";
8
+ import { checkFieldsBeforeText, resolveTextInput, textFileHelp, textFileOption, textSourceConstraint, } from "../text-input.js";
5
9
  import { currentActor } from "../actor.js";
6
- import { isColorEnabled } from "../presentation/color.js";
7
- import { formatRows } from "../presentation/row-layout.js";
8
- function presentLabel(labelMatch) {
9
- return { name: labelMatch.name, color: labelMatch.color, description: labelMatch.description };
10
- }
11
- function formatLabel(presented) {
12
- return formatLabelList([presented]);
13
- }
14
- function formatLabelList(presentedLabels) {
15
- return formatRows(presentedLabels.map((presented) => {
16
- const descriptionCells = presented.description == null ? [] : [{ text: presented.description }];
17
- /**
18
- * The colored name shows the color, and if the environment
19
- * does not support color, it is explicitly printed instead
20
- */
21
- if (isColorEnabled()) {
22
- return [{ text: presented.name, style: presented.color }, ...descriptionCells];
23
- }
24
- return [{ text: presented.name }, { text: presented.color }, ...descriptionCells];
25
- }));
26
- }
10
+ import { formatLabelList, presentLabel } from "../presentation/label-presentation.js";
11
+ const colorOption = {
12
+ type: "string",
13
+ value: {
14
+ kind: "enum",
15
+ name: "color",
16
+ choices: labelColorSchema.options,
17
+ },
18
+ };
19
+ const labelInputs = {
20
+ create: {
21
+ options: {
22
+ description: { type: "string", value: { kind: "text", name: "text" } },
23
+ "description-file": textFileOption,
24
+ color: colorOption,
25
+ },
26
+ forms: [
27
+ { id: "default", positionals: [{ name: "name", min: 1, max: 1, value: { kind: "name" } }] },
28
+ ],
29
+ constraints: [textSourceConstraint("--description")],
30
+ },
31
+ list: noInput,
32
+ view: {
33
+ options: {},
34
+ forms: [
35
+ {
36
+ id: "default",
37
+ positionals: [{ name: "name", min: 1, max: 1, value: { kind: "label-name" } }],
38
+ },
39
+ ],
40
+ constraints: [],
41
+ },
42
+ edit: {
43
+ options: {
44
+ name: { type: "string", value: { kind: "text", name: "text" } },
45
+ description: { type: "string", value: { kind: "text", name: "text" } },
46
+ "description-file": textFileOption,
47
+ ...textEditOptions,
48
+ color: colorOption,
49
+ },
50
+ forms: [
51
+ { id: "default", positionals: [{ name: "name", min: 1, max: 1, value: { kind: "name" } }] },
52
+ ],
53
+ constraints: [
54
+ textSourceConstraint("--description"),
55
+ ...textEditConstraints("--description"),
56
+ {
57
+ kind: "atLeastOne",
58
+ // A description can also come from --description-file
59
+ members: Object.keys(labelEditSchema.shape)
60
+ .filter((name) => name !== "labelName")
61
+ .flatMap((name) => name === "description"
62
+ ? textSourceConstraint("--description").members
63
+ : [`option:${name}`]),
64
+ },
65
+ ],
66
+ notes: [textEditHelp("--description")],
67
+ },
68
+ delete: {
69
+ options: { yes: { type: "boolean" } },
70
+ forms: [
71
+ { id: "default", positionals: [{ name: "name", min: 1, max: 1, value: { kind: "name" } }] },
72
+ ],
73
+ constraints: [],
74
+ },
75
+ };
27
76
  export const labelRouter = {
28
77
  create: {
29
- run: (args) => {
78
+ summary: "Create a global label. Names preserve casing, but uniqueness is case-insensitive.",
79
+ effects: { domain: "create", storage: "normal-open" },
80
+ confirmation: { kind: "none" },
81
+ input: labelInputs.create,
82
+ results: [jsonResult("Label")],
83
+ run: async (args) => {
30
84
  const { values, positionals, tokens } = parseArgs({
31
85
  args,
32
- options: { description: { type: "string" }, color: { type: "string" } },
86
+ options: labelInputs.create.options,
33
87
  allowPositionals: true,
34
88
  strict: true,
35
89
  tokens: true,
36
90
  });
37
- validateUniqueOptions(tokens);
38
- validatePositionals(positionals, ["<name>"]);
39
- const input = labelCreateSchema.parse({ name: positionals[0], ...values });
91
+ validateUniqueOptions(tokens, labelInputs.create.options);
92
+ validatePositionals(positionals, labelInputs.create.forms[0]);
93
+ checkFieldsBeforeText(labelCreateSchema, { name: positionals[0], color: values.color });
94
+ const description = await resolveTextInput(values.description, values["description-file"], "--description");
95
+ const input = labelCreateSchema.parse({
96
+ name: positionals[0],
97
+ description,
98
+ color: values.color,
99
+ });
40
100
  const created = label.create(input, currentActor());
41
- output(presentLabel(created), formatLabel);
101
+ output(presentLabel(created), (entry) => formatLabelList([entry], { showsDescriptionPreview: true }));
42
102
  },
43
- help: `Usage: zinn label create <name> [--description <text>] [--color <color>]
103
+ help: `${generateCommandUsage("label create", labelInputs.create)}
44
104
 
45
105
  Create a global label. Names preserve casing, but uniqueness is case-insensitive.
46
106
  Names are trimmed and cannot be blank or contain line breaks or control characters.
47
107
  Description is optional.
108
+ ${textFileHelp("--description")}
109
+ The printed result is a preview. 'label view' and --json show the full text.
48
110
 
49
111
  Color defaults to white.
50
- Valid colors: red, green, yellow, blue, magenta, cyan, white, gray.
112
+ Valid colors: ${labelInputs.create.options.color.value.choices.join(", ")}.
51
113
 
52
- Example: zinn label create bug --description "Unexpected behavior" --color red`,
114
+ ${dashValueHelp("--description")}
115
+
116
+ Example: zinn label create bug --description 'Unexpected behavior' --color red`,
53
117
  },
54
118
  list: {
119
+ summary: "List all global label definitions.",
120
+ effects: { domain: "read", storage: "normal-open" },
121
+ confirmation: { kind: "none" },
122
+ input: labelInputs.list,
123
+ results: [jsonResult("LabelList")],
124
+ run: (args) => {
125
+ const { positionals } = parseArgs({
126
+ options: labelInputs.list.options,
127
+ args,
128
+ strict: true,
129
+ allowPositionals: true,
130
+ });
131
+ validatePositionals(positionals, labelInputs.list.forms[0]);
132
+ output(label.getAll().map(presentLabel), (entries) => formatLabelList(entries, { showsDescriptionPreview: true }));
133
+ },
134
+ help: `${generateCommandUsage("label list", labelInputs.list)}
135
+
136
+ List all global label definitions.
137
+ Descriptions are previews.
138
+ Use label view <name> for the full description. --json keeps the full text.`,
139
+ },
140
+ view: {
141
+ summary: "Show a global label with its full description.",
142
+ effects: { domain: "read", storage: "normal-open" },
143
+ confirmation: { kind: "none" },
144
+ input: labelInputs.view,
145
+ results: [jsonResult("Label")],
55
146
  run: (args) => {
56
- const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
57
- validatePositionals(positionals, []);
58
- output(label.getAll().map(presentLabel), formatLabelList);
147
+ const { positionals } = parseArgs({
148
+ args,
149
+ options: labelInputs.view.options,
150
+ strict: true,
151
+ allowPositionals: true,
152
+ });
153
+ validatePositionals(positionals, labelInputs.view.forms[0]);
154
+ const props = labelDeleteSchema.parse({ name: positionals[0] });
155
+ const labelMatch = label.getByName(props.name);
156
+ if (labelMatch == null) {
157
+ throw new CliError(`A label with name "${props.name}" does not exist`, "not_found", {
158
+ entity: "label",
159
+ key: props.name,
160
+ source: "explicit",
161
+ });
162
+ }
163
+ output(presentLabel(labelMatch), (entry) => formatLabelList([entry]));
59
164
  },
60
- help: `Usage: zinn label list
165
+ help: `${generateCommandUsage("label view", labelInputs.view)}
166
+
167
+ Show a global label with its full description, preserving line breaks and whitespace.
168
+ Label names are matched case-insensitively.
61
169
 
62
- List all global label definitions.`,
170
+ Example: zinn label view bug`,
63
171
  },
64
172
  edit: {
65
- run: (args) => {
173
+ summary: "Change specified fields.",
174
+ effects: { domain: "update", storage: "normal-open" },
175
+ confirmation: { kind: "none" },
176
+ input: labelInputs.edit,
177
+ results: [jsonResult("LabelChange")],
178
+ run: async (args) => {
66
179
  const { values, positionals, tokens } = parseArgs({
67
180
  args,
68
- options: {
69
- name: { type: "string" },
70
- description: { type: "string" },
71
- ...textEditOptions,
72
- color: { type: "string" },
73
- },
181
+ options: labelInputs.edit.options,
74
182
  allowPositionals: true,
75
183
  strict: true,
76
184
  tokens: true,
77
185
  });
78
- validateUniqueOptions(tokens);
79
- validatePositionals(positionals, ["<name>"]);
186
+ validateUniqueOptions(tokens, labelInputs.edit.options);
187
+ validatePositionals(positionals, labelInputs.edit.forms[0]);
188
+ checkFieldsBeforeText(labelEditSchema, {
189
+ labelName: positionals[0],
190
+ name: values.name,
191
+ color: values.color,
192
+ });
193
+ const description = await resolveTextEdit(values, "--description");
80
194
  const input = labelEditSchema.parse({
81
195
  labelName: positionals[0],
82
196
  name: values.name,
83
- description: resolveTextEdit(values.description, values, "--description"),
197
+ description,
84
198
  color: values.color,
85
199
  });
86
200
  const edited = label.edit(input, currentActor());
87
- output(presentLabel(edited), formatLabel);
201
+ outputChanges([edited], (change) => presentLabel(change.label), (entries) => formatLabelList(entries, { showsDescriptionPreview: true }), (entry) => `Label "${entry.name}" was unchanged`);
88
202
  },
89
- help: `Usage: zinn label edit <name> [--name <text>] [--description <text> ${textEditUsage}] [--color <color>]
203
+ help: `${generateCommandUsage("label edit", labelInputs.edit)}
90
204
 
91
205
  Change specified fields.
92
- Provide at least one edit flag. Use --description "" to clear the description.
206
+ With --json, changed is false when all supplied values already match.
207
+ Provide at least one edit flag. Use --description '' to clear the description.
208
+ ${textFileHelp("--description")}
209
+ Description echoes use a preview; label view and --json keep the full text.
210
+ Valid colors: ${labelInputs.edit.options.color.value.choices.join(", ")}.
93
211
 
94
212
  ${textEditHelp("--description")}
95
213
 
96
- Names are matched and kept unique case-insensitively while preserving their casing.
97
- Names are trimmed. Changing only the casing is allowed.
98
- Editing does not affect task attachments or task timestamps.
214
+ Label names match without case sensitivity.
215
+
216
+ ${dashValueHelp("--description")}
99
217
 
100
218
  Examples:
101
219
  zinn label edit bug --name defect --color yellow
102
- zinn label edit bug --description "Reported by users." --append`,
220
+ zinn label edit bug --description 'Reported by users.' --append`,
103
221
  },
104
222
  delete: {
223
+ summary: "Delete a label definition and remove it from all tasks after confirmation.",
224
+ effects: { domain: "delete", storage: "normal-open" },
225
+ confirmation: { kind: "prompt", description: confirmationDescription },
226
+ input: labelInputs.delete,
227
+ results: [jsonResult("Label")],
105
228
  run: async (args) => {
106
229
  const { values, positionals, tokens } = parseArgs({
107
230
  args,
108
- options: { yes: { type: "boolean" } },
231
+ options: labelInputs.delete.options,
109
232
  strict: true,
110
233
  allowPositionals: true,
111
234
  tokens: true,
112
235
  });
113
- validateUniqueOptions(tokens);
114
- validatePositionals(positionals, ["<name>"]);
236
+ validateUniqueOptions(tokens, labelInputs.delete.options);
237
+ validatePositionals(positionals, labelInputs.delete.forms[0]);
115
238
  const props = labelDeleteSchema.parse({ name: positionals[0] });
116
239
  const labelMatch = label.getByName(props.name);
117
240
  if (labelMatch == null) {
118
- quit(`A label with name "${props.name}" does not exist`);
241
+ throw new CliError(`A label with name "${props.name}" does not exist`, "not_found", {
242
+ entity: "label",
243
+ key: props.name,
244
+ source: "explicit",
245
+ });
119
246
  }
120
247
  const canDelete = await confirmAction(`Are you sure you want to delete label "${labelMatch.name}" and remove it from all tasks?`, values.yes === true);
121
248
  if (!canDelete) {
122
- output(presentLabel(labelMatch), (l) => `Deletion cancelled for label "${l.name}"`);
249
+ output(presentLabel(labelMatch), (entry) => `Deletion cancelled for ${formatLabelList([entry], { showsDescriptionPreview: true })}`);
123
250
  return;
124
251
  }
125
252
  const deleted = label.delete(props, currentActor());
126
- output(presentLabel(deleted), (l) => `Deleted label "${l.name}"`);
253
+ output(presentLabel(deleted), (entry) => `Deleted ${formatLabelList([entry], { showsDescriptionPreview: true })}`);
127
254
  },
128
- help: `Usage: zinn label delete <name> [--yes]
255
+ help: `${generateCommandUsage("label delete", labelInputs.delete)}
129
256
 
130
257
  Delete a label definition and remove it from all tasks after confirmation.
131
258
  To remove a label from just one task, use zinn task label remove.
@@ -1,4 +1,21 @@
1
1
  export declare const migrateCommand: {
2
+ summary: string;
3
+ effects: {
4
+ domain: "none";
5
+ storage: "migrate";
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[];
2
19
  run: (args: string[]) => void;
3
20
  help: string;
4
21
  };
@@ -1,12 +1,24 @@
1
+ import { jsonResult } from "../results.js";
1
2
  import { parseArgs } from "node:util";
2
3
  import { migrate, MigrationRefusedError, getStorage } from "@zinn-dev/core";
4
+ import { generateCommandUsage, noInput } from "../input.js";
3
5
  import { reportLockWait } from "../database.js";
4
- import { output, validatePositionals } from "../lib.js";
6
+ import { diagnostic, output, validatePositionals } from "../lib.js";
5
7
  import packageJson from "../../package.json" with { type: "json" };
6
8
  export const migrateCommand = {
9
+ summary: "Upgrade an existing database to the latest schema version.",
10
+ effects: { domain: "none", storage: "migrate" },
11
+ confirmation: { kind: "none" },
12
+ input: noInput,
13
+ results: [jsonResult("Migrate")],
7
14
  run: (args) => {
8
- const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
9
- validatePositionals(positionals, []);
15
+ const { positionals } = parseArgs({
16
+ options: noInput.options,
17
+ args,
18
+ strict: true,
19
+ allowPositionals: true,
20
+ });
21
+ validatePositionals(positionals, noInput.forms[0]);
10
22
  // Resolved before the try, so a store that cannot be resolved fails without the note about backups.
11
23
  const { backupDirectory } = getStorage();
12
24
  try {
@@ -22,12 +34,12 @@ export const migrateCommand = {
22
34
  catch (error) {
23
35
  // A refusal attempted nothing, so only a failed upgrade points at the backups.
24
36
  if (!(error instanceof MigrationRefusedError)) {
25
- console.error(`The database is unchanged. Backups taken before each upgrade attempt are kept in ${backupDirectory}.`);
37
+ diagnostic(`The database is unchanged. Backups taken before each upgrade attempt are kept in ${backupDirectory}.`);
26
38
  }
27
39
  throw error;
28
40
  }
29
41
  },
30
- help: `Usage: zinn migrate
42
+ help: `${generateCommandUsage("migrate", noInput)}
31
43
 
32
44
  Upgrade an existing database to the latest schema version.
33
45