@taskset/cli 0.1.2 → 2.0.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.
- package/CHANGELOG.md +72 -0
- package/README.md +31 -11
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +632 -108
- package/package.json +17 -3
- package/src/cli.ts +760 -133
package/dist/cli.js
CHANGED
|
@@ -1,64 +1,239 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { parseArgs } from 'node:util';
|
|
3
|
-
import {
|
|
4
|
-
import { createTask, discoverRepository, initializeRepository,
|
|
3
|
+
import { TaskIdSchema, TaskPrioritySchema, TaskRiskSchema, TaskStatusSchema, TaskTimestampSchema, } from '@taskset/contracts';
|
|
4
|
+
import { buildTaskIndex, createSnapshot, createTask, deleteTask, diagnoseRepository, discoverRepository, generateViews, initializeRepository, listSnapshots, normalizeRepositoryPath, queryTasks, RepositoryPathError, readTask, restoreSnapshot, serializeTaskFile, TASK_SORT_DIRECTIONS, TASK_SORT_KEYS, TaskQuerySchema, updateTask, } from '@taskset/core';
|
|
5
|
+
import * as z from 'zod';
|
|
5
6
|
const USAGE = `Usage:
|
|
6
7
|
taskset init [--cwd <path>]
|
|
7
8
|
taskset config [--json] [--cwd <path>]
|
|
8
|
-
taskset
|
|
9
|
-
taskset
|
|
10
|
-
taskset
|
|
9
|
+
taskset doctor [--json] [--cwd <path>]
|
|
10
|
+
taskset generate [--json] [--cwd <path>]
|
|
11
|
+
taskset snapshot create|list [--json] [--cwd <path>]
|
|
12
|
+
taskset snapshot restore <snapshot-id> [--apply] [--json] [--cwd <path>]
|
|
13
|
+
taskset task create --title <title> [metadata options]
|
|
14
|
+
taskset task list [query options]
|
|
15
|
+
taskset task show <task-id> [--include-derived] [--json] [--cwd <path>]
|
|
16
|
+
taskset task update <task-id> [metadata options]
|
|
17
|
+
taskset task status <task-id> <status> [--json] [--cwd <path>]
|
|
18
|
+
taskset task delete <task-id> [--remove-dependencies] [--json] [--cwd <path>]
|
|
11
19
|
|
|
12
|
-
|
|
13
|
-
--status
|
|
14
|
-
--
|
|
15
|
-
--
|
|
16
|
-
--
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
Metadata options:
|
|
21
|
+
--status --priority --owner --team --estimate --effort --risk --due-date
|
|
22
|
+
--label --assignee --reviewer --depends-on --related --duplicate
|
|
23
|
+
--parent --file --directory --project --body
|
|
24
|
+
Repeat array options. Update commands also accept matching --clear-* options.
|
|
25
|
+
|
|
26
|
+
List query options:
|
|
27
|
+
--status --priority --label --owner --assignee --reviewer --team --risk
|
|
28
|
+
--project --depends-on --related --duplicate --parent --file --directory
|
|
29
|
+
--estimate-min --estimate-max --effort-min --effort-max
|
|
30
|
+
--due-before --due-after --created-before --created-after
|
|
31
|
+
--updated-before --updated-after --search --sort --direction
|
|
32
|
+
--impact --include-derived --json
|
|
19
33
|
`;
|
|
20
34
|
class CliUsageError extends Error {
|
|
21
|
-
|
|
35
|
+
issues;
|
|
36
|
+
constructor(message, issues = []) {
|
|
22
37
|
super(message);
|
|
23
38
|
this.name = 'CliUsageError';
|
|
39
|
+
this.issues = issues;
|
|
24
40
|
}
|
|
25
41
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
throw new CliUsageError(`Invalid task status "${value}"`);
|
|
32
|
-
}
|
|
33
|
-
return value;
|
|
42
|
+
const TrimmedStringSchema = z.string().trim().min(1);
|
|
43
|
+
function uniqueArray(schema) {
|
|
44
|
+
return z
|
|
45
|
+
.array(schema)
|
|
46
|
+
.refine((values) => new Set(values).size === values.length, 'Values must be unique');
|
|
34
47
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
48
|
+
const StringListSchema = uniqueArray(TrimmedStringSchema);
|
|
49
|
+
const TaskIdListSchema = uniqueArray(TaskIdSchema);
|
|
50
|
+
const CwdSchema = z.string().min(1).optional();
|
|
51
|
+
const JsonSchema = z.boolean().optional();
|
|
52
|
+
const CommonValuesSchema = z.strictObject({
|
|
53
|
+
cwd: CwdSchema,
|
|
54
|
+
json: JsonSchema,
|
|
55
|
+
});
|
|
56
|
+
const CreateValuesSchema = z.strictObject({
|
|
57
|
+
title: TrimmedStringSchema,
|
|
58
|
+
status: TaskStatusSchema.optional(),
|
|
59
|
+
priority: TaskPrioritySchema.optional(),
|
|
60
|
+
label: StringListSchema.optional(),
|
|
61
|
+
'depends-on': TaskIdListSchema.optional(),
|
|
62
|
+
file: StringListSchema.optional(),
|
|
63
|
+
owner: TrimmedStringSchema.optional(),
|
|
64
|
+
assignee: StringListSchema.optional(),
|
|
65
|
+
reviewer: StringListSchema.optional(),
|
|
66
|
+
team: TrimmedStringSchema.optional(),
|
|
67
|
+
estimate: z.coerce.number().int().nonnegative().optional(),
|
|
68
|
+
effort: z.coerce.number().finite().nonnegative().optional(),
|
|
69
|
+
risk: TaskRiskSchema.optional(),
|
|
70
|
+
'due-date': TaskTimestampSchema.optional(),
|
|
71
|
+
related: TaskIdListSchema.optional(),
|
|
72
|
+
duplicate: TaskIdListSchema.optional(),
|
|
73
|
+
parent: TaskIdSchema.optional(),
|
|
74
|
+
directory: StringListSchema.optional(),
|
|
75
|
+
project: StringListSchema.optional(),
|
|
76
|
+
body: z.string().optional(),
|
|
77
|
+
cwd: CwdSchema,
|
|
78
|
+
json: JsonSchema,
|
|
79
|
+
});
|
|
80
|
+
const UPDATE_CLEAR_PAIRS = [
|
|
81
|
+
['priority', 'clear-priority'],
|
|
82
|
+
['label', 'clear-labels'],
|
|
83
|
+
['depends-on', 'clear-dependencies'],
|
|
84
|
+
['file', 'clear-files'],
|
|
85
|
+
['owner', 'clear-owner'],
|
|
86
|
+
['assignee', 'clear-assignees'],
|
|
87
|
+
['reviewer', 'clear-reviewers'],
|
|
88
|
+
['team', 'clear-team'],
|
|
89
|
+
['estimate', 'clear-estimate'],
|
|
90
|
+
['effort', 'clear-effort'],
|
|
91
|
+
['risk', 'clear-risk'],
|
|
92
|
+
['due-date', 'clear-due-date'],
|
|
93
|
+
['related', 'clear-related'],
|
|
94
|
+
['duplicate', 'clear-duplicates'],
|
|
95
|
+
['parent', 'clear-parent'],
|
|
96
|
+
['directory', 'clear-directories'],
|
|
97
|
+
['project', 'clear-projects'],
|
|
98
|
+
];
|
|
99
|
+
const UpdateValuesSchema = z
|
|
100
|
+
.strictObject({
|
|
101
|
+
title: TrimmedStringSchema.optional(),
|
|
102
|
+
status: TaskStatusSchema.optional(),
|
|
103
|
+
priority: TaskPrioritySchema.optional(),
|
|
104
|
+
label: StringListSchema.optional(),
|
|
105
|
+
'depends-on': TaskIdListSchema.optional(),
|
|
106
|
+
file: StringListSchema.optional(),
|
|
107
|
+
owner: TrimmedStringSchema.optional(),
|
|
108
|
+
assignee: StringListSchema.optional(),
|
|
109
|
+
reviewer: StringListSchema.optional(),
|
|
110
|
+
team: TrimmedStringSchema.optional(),
|
|
111
|
+
estimate: z.coerce.number().int().nonnegative().optional(),
|
|
112
|
+
effort: z.coerce.number().finite().nonnegative().optional(),
|
|
113
|
+
risk: TaskRiskSchema.optional(),
|
|
114
|
+
'due-date': TaskTimestampSchema.optional(),
|
|
115
|
+
related: TaskIdListSchema.optional(),
|
|
116
|
+
duplicate: TaskIdListSchema.optional(),
|
|
117
|
+
parent: TaskIdSchema.optional(),
|
|
118
|
+
directory: StringListSchema.optional(),
|
|
119
|
+
project: StringListSchema.optional(),
|
|
120
|
+
body: z.string().optional(),
|
|
121
|
+
'clear-priority': z.boolean().optional(),
|
|
122
|
+
'clear-labels': z.boolean().optional(),
|
|
123
|
+
'clear-dependencies': z.boolean().optional(),
|
|
124
|
+
'clear-files': z.boolean().optional(),
|
|
125
|
+
'clear-owner': z.boolean().optional(),
|
|
126
|
+
'clear-assignees': z.boolean().optional(),
|
|
127
|
+
'clear-reviewers': z.boolean().optional(),
|
|
128
|
+
'clear-team': z.boolean().optional(),
|
|
129
|
+
'clear-estimate': z.boolean().optional(),
|
|
130
|
+
'clear-effort': z.boolean().optional(),
|
|
131
|
+
'clear-risk': z.boolean().optional(),
|
|
132
|
+
'clear-due-date': z.boolean().optional(),
|
|
133
|
+
'clear-related': z.boolean().optional(),
|
|
134
|
+
'clear-duplicates': z.boolean().optional(),
|
|
135
|
+
'clear-parent': z.boolean().optional(),
|
|
136
|
+
'clear-directories': z.boolean().optional(),
|
|
137
|
+
'clear-projects': z.boolean().optional(),
|
|
138
|
+
cwd: CwdSchema,
|
|
139
|
+
json: JsonSchema,
|
|
140
|
+
})
|
|
141
|
+
.superRefine((values, context) => {
|
|
142
|
+
for (const [valueKey, clearKey] of UPDATE_CLEAR_PAIRS) {
|
|
143
|
+
if (values[valueKey] !== undefined && values[clearKey]) {
|
|
144
|
+
context.addIssue({
|
|
145
|
+
code: 'custom',
|
|
146
|
+
path: [clearKey],
|
|
147
|
+
message: `Cannot set and clear ${valueKey} in the same update`,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const nonControlKeys = Object.keys(values).filter((key) => key !== 'cwd' && key !== 'json');
|
|
152
|
+
if (nonControlKeys.length === 0) {
|
|
153
|
+
context.addIssue({
|
|
154
|
+
code: 'custom',
|
|
155
|
+
message: 'Task update requires at least one field option',
|
|
156
|
+
});
|
|
38
157
|
}
|
|
39
|
-
|
|
40
|
-
|
|
158
|
+
});
|
|
159
|
+
const ListValuesSchema = z.strictObject({
|
|
160
|
+
status: z.array(TaskStatusSchema).optional(),
|
|
161
|
+
priority: z.array(TaskPrioritySchema).optional(),
|
|
162
|
+
label: StringListSchema.optional(),
|
|
163
|
+
owner: StringListSchema.optional(),
|
|
164
|
+
assignee: StringListSchema.optional(),
|
|
165
|
+
reviewer: StringListSchema.optional(),
|
|
166
|
+
team: StringListSchema.optional(),
|
|
167
|
+
risk: z.array(TaskRiskSchema).optional(),
|
|
168
|
+
project: StringListSchema.optional(),
|
|
169
|
+
'depends-on': TaskIdSchema.optional(),
|
|
170
|
+
related: TaskIdSchema.optional(),
|
|
171
|
+
duplicate: TaskIdSchema.optional(),
|
|
172
|
+
parent: TaskIdSchema.optional(),
|
|
173
|
+
file: StringListSchema.optional(),
|
|
174
|
+
directory: StringListSchema.optional(),
|
|
175
|
+
'estimate-min': z.coerce.number().finite().nonnegative().optional(),
|
|
176
|
+
'estimate-max': z.coerce.number().finite().nonnegative().optional(),
|
|
177
|
+
'effort-min': z.coerce.number().finite().nonnegative().optional(),
|
|
178
|
+
'effort-max': z.coerce.number().finite().nonnegative().optional(),
|
|
179
|
+
'due-before': TaskTimestampSchema.optional(),
|
|
180
|
+
'due-after': TaskTimestampSchema.optional(),
|
|
181
|
+
'created-before': TaskTimestampSchema.optional(),
|
|
182
|
+
'created-after': TaskTimestampSchema.optional(),
|
|
183
|
+
'updated-before': TaskTimestampSchema.optional(),
|
|
184
|
+
'updated-after': TaskTimestampSchema.optional(),
|
|
185
|
+
search: z.string().optional(),
|
|
186
|
+
sort: z.enum(TASK_SORT_KEYS).optional(),
|
|
187
|
+
direction: z.enum(TASK_SORT_DIRECTIONS).optional(),
|
|
188
|
+
impact: z.boolean().optional(),
|
|
189
|
+
'include-derived': z.boolean().optional(),
|
|
190
|
+
cwd: CwdSchema,
|
|
191
|
+
json: JsonSchema,
|
|
192
|
+
});
|
|
193
|
+
const metadataOptionDefinitions = {
|
|
194
|
+
body: { type: 'string' },
|
|
195
|
+
'depends-on': { type: 'string', multiple: true },
|
|
196
|
+
file: { type: 'string', multiple: true },
|
|
197
|
+
label: { type: 'string', multiple: true },
|
|
198
|
+
priority: { type: 'string' },
|
|
199
|
+
status: { type: 'string' },
|
|
200
|
+
title: { type: 'string' },
|
|
201
|
+
owner: { type: 'string' },
|
|
202
|
+
assignee: { type: 'string', multiple: true },
|
|
203
|
+
reviewer: { type: 'string', multiple: true },
|
|
204
|
+
team: { type: 'string' },
|
|
205
|
+
estimate: { type: 'string' },
|
|
206
|
+
effort: { type: 'string' },
|
|
207
|
+
risk: { type: 'string' },
|
|
208
|
+
'due-date': { type: 'string' },
|
|
209
|
+
related: { type: 'string', multiple: true },
|
|
210
|
+
duplicate: { type: 'string', multiple: true },
|
|
211
|
+
parent: { type: 'string' },
|
|
212
|
+
directory: { type: 'string', multiple: true },
|
|
213
|
+
project: { type: 'string', multiple: true },
|
|
214
|
+
};
|
|
215
|
+
const commonOptionDefinitions = {
|
|
216
|
+
cwd: { type: 'string' },
|
|
217
|
+
json: { type: 'boolean' },
|
|
218
|
+
};
|
|
219
|
+
function parseSchema(schema, value, label) {
|
|
220
|
+
const result = schema.safeParse(value);
|
|
221
|
+
if (!result.success) {
|
|
222
|
+
throw new CliUsageError(`Invalid ${label}`, result.error.issues.map((issue) => ({
|
|
223
|
+
field: issue.path.length > 0 ? issue.path.map(String).join('.') : label,
|
|
224
|
+
message: issue.message,
|
|
225
|
+
})));
|
|
41
226
|
}
|
|
42
|
-
return
|
|
227
|
+
return result.data;
|
|
43
228
|
}
|
|
44
229
|
function resolveCommandCwd(baseDirectory, cwdOption) {
|
|
45
230
|
return cwdOption ? path.resolve(baseDirectory, cwdOption) : baseDirectory;
|
|
46
231
|
}
|
|
47
|
-
function
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
allowPositionals: false,
|
|
51
|
-
options: {
|
|
52
|
-
cwd: { type: 'string' },
|
|
53
|
-
json: { type: 'boolean' },
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
function requireSinglePositional(positionals, name) {
|
|
58
|
-
if (positionals.length !== 1 || !positionals[0]) {
|
|
59
|
-
throw new CliUsageError(`Expected exactly one ${name}`);
|
|
232
|
+
function requirePositionals(positionals, count, description) {
|
|
233
|
+
if (positionals.length !== count || positionals.some((value) => value.length === 0)) {
|
|
234
|
+
throw new CliUsageError(`Expected ${description}`);
|
|
60
235
|
}
|
|
61
|
-
return positionals
|
|
236
|
+
return positionals;
|
|
62
237
|
}
|
|
63
238
|
function formatError(error) {
|
|
64
239
|
if (!(error instanceof Error)) {
|
|
@@ -73,116 +248,400 @@ function formatError(error) {
|
|
|
73
248
|
: '';
|
|
74
249
|
return `${error.message}${issues}`;
|
|
75
250
|
}
|
|
251
|
+
function taskRecordJson(record, derived) {
|
|
252
|
+
return {
|
|
253
|
+
relativePath: record.relativePath,
|
|
254
|
+
...record.task.metadata,
|
|
255
|
+
...(derived ? { derived } : {}),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function writeTaskRecord(record, json, stdout) {
|
|
259
|
+
if (json) {
|
|
260
|
+
stdout(`${JSON.stringify(taskRecordJson(record), null, 2)}\n`);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
stdout(`${record.task.metadata.id}\n`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function warningWriter(stderr) {
|
|
267
|
+
return (warning) => stderr(`warning: ${warning.message}\n`);
|
|
268
|
+
}
|
|
269
|
+
function normalizeMutationPaths(repository, values) {
|
|
270
|
+
return values?.map((value) => normalizeRepositoryPath(repository, value));
|
|
271
|
+
}
|
|
272
|
+
function updateInputFromValues(repository, values) {
|
|
273
|
+
return {
|
|
274
|
+
...(values.title !== undefined ? { title: values.title } : {}),
|
|
275
|
+
...(values.status !== undefined ? { status: values.status } : {}),
|
|
276
|
+
...(values['clear-priority']
|
|
277
|
+
? { priority: null }
|
|
278
|
+
: values.priority !== undefined
|
|
279
|
+
? { priority: values.priority }
|
|
280
|
+
: {}),
|
|
281
|
+
...(values['clear-labels']
|
|
282
|
+
? { labels: [] }
|
|
283
|
+
: values.label !== undefined
|
|
284
|
+
? { labels: values.label }
|
|
285
|
+
: {}),
|
|
286
|
+
...(values['clear-dependencies']
|
|
287
|
+
? { dependsOn: [] }
|
|
288
|
+
: values['depends-on'] !== undefined
|
|
289
|
+
? { dependsOn: values['depends-on'] }
|
|
290
|
+
: {}),
|
|
291
|
+
...(values['clear-files']
|
|
292
|
+
? { files: [] }
|
|
293
|
+
: values.file !== undefined
|
|
294
|
+
? { files: normalizeMutationPaths(repository, values.file) }
|
|
295
|
+
: {}),
|
|
296
|
+
...(values['clear-owner']
|
|
297
|
+
? { owner: null }
|
|
298
|
+
: values.owner !== undefined
|
|
299
|
+
? { owner: values.owner }
|
|
300
|
+
: {}),
|
|
301
|
+
...(values['clear-assignees']
|
|
302
|
+
? { assignees: [] }
|
|
303
|
+
: values.assignee !== undefined
|
|
304
|
+
? { assignees: values.assignee }
|
|
305
|
+
: {}),
|
|
306
|
+
...(values['clear-reviewers']
|
|
307
|
+
? { reviewers: [] }
|
|
308
|
+
: values.reviewer !== undefined
|
|
309
|
+
? { reviewers: values.reviewer }
|
|
310
|
+
: {}),
|
|
311
|
+
...(values['clear-team']
|
|
312
|
+
? { team: null }
|
|
313
|
+
: values.team !== undefined
|
|
314
|
+
? { team: values.team }
|
|
315
|
+
: {}),
|
|
316
|
+
...(values['clear-estimate']
|
|
317
|
+
? { estimate: null }
|
|
318
|
+
: values.estimate !== undefined
|
|
319
|
+
? { estimate: values.estimate }
|
|
320
|
+
: {}),
|
|
321
|
+
...(values['clear-effort']
|
|
322
|
+
? { effort: null }
|
|
323
|
+
: values.effort !== undefined
|
|
324
|
+
? { effort: values.effort }
|
|
325
|
+
: {}),
|
|
326
|
+
...(values['clear-risk']
|
|
327
|
+
? { risk: null }
|
|
328
|
+
: values.risk !== undefined
|
|
329
|
+
? { risk: values.risk }
|
|
330
|
+
: {}),
|
|
331
|
+
...(values['clear-due-date']
|
|
332
|
+
? { dueDate: null }
|
|
333
|
+
: values['due-date'] !== undefined
|
|
334
|
+
? { dueDate: values['due-date'] }
|
|
335
|
+
: {}),
|
|
336
|
+
...(values['clear-related']
|
|
337
|
+
? { related: [] }
|
|
338
|
+
: values.related !== undefined
|
|
339
|
+
? { related: values.related }
|
|
340
|
+
: {}),
|
|
341
|
+
...(values['clear-duplicates']
|
|
342
|
+
? { duplicates: [] }
|
|
343
|
+
: values.duplicate !== undefined
|
|
344
|
+
? { duplicates: values.duplicate }
|
|
345
|
+
: {}),
|
|
346
|
+
...(values['clear-parent']
|
|
347
|
+
? { parent: null }
|
|
348
|
+
: values.parent !== undefined
|
|
349
|
+
? { parent: values.parent }
|
|
350
|
+
: {}),
|
|
351
|
+
...(values['clear-directories']
|
|
352
|
+
? { directories: [] }
|
|
353
|
+
: values.directory !== undefined
|
|
354
|
+
? { directories: normalizeMutationPaths(repository, values.directory) }
|
|
355
|
+
: {}),
|
|
356
|
+
...(values['clear-projects']
|
|
357
|
+
? { projects: [] }
|
|
358
|
+
: values.project !== undefined
|
|
359
|
+
? { projects: values.project }
|
|
360
|
+
: {}),
|
|
361
|
+
...(values.body !== undefined ? { body: values.body } : {}),
|
|
362
|
+
};
|
|
363
|
+
}
|
|
76
364
|
export async function runCli(args, context = {}) {
|
|
77
365
|
const cwd = path.resolve(context.cwd ?? process.cwd());
|
|
78
366
|
const stdout = context.stdout ?? ((value) => process.stdout.write(value));
|
|
79
367
|
const stderr = context.stderr ?? ((value) => process.stderr.write(value));
|
|
368
|
+
const onWarning = warningWriter(stderr);
|
|
80
369
|
try {
|
|
81
370
|
const [command, subcommand] = args;
|
|
82
371
|
const commandArgs = args.slice(1);
|
|
83
|
-
const
|
|
372
|
+
const subcommandArgs = args.slice(2);
|
|
84
373
|
if (!command || command === 'help' || command === '--help' || command === '-h') {
|
|
85
374
|
stdout(USAGE);
|
|
86
375
|
return 0;
|
|
87
376
|
}
|
|
88
|
-
if (command === 'init') {
|
|
89
|
-
const parsed =
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
stdout(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
377
|
+
if (command === 'init' || command === 'config' || command === 'doctor') {
|
|
378
|
+
const parsed = parseArgs({
|
|
379
|
+
args: commandArgs,
|
|
380
|
+
allowPositionals: false,
|
|
381
|
+
options: commonOptionDefinitions,
|
|
382
|
+
});
|
|
383
|
+
const values = parseSchema(CommonValuesSchema, parsed.values, `${command} options`);
|
|
384
|
+
const commandCwd = resolveCommandCwd(cwd, values.cwd);
|
|
385
|
+
if (command === 'init') {
|
|
386
|
+
const repository = await initializeRepository(commandCwd);
|
|
387
|
+
stdout(`Initialized Taskset in ${repository.rootDirectory}\n`);
|
|
388
|
+
return 0;
|
|
389
|
+
}
|
|
390
|
+
const repository = await discoverRepository(commandCwd);
|
|
391
|
+
if (command === 'config') {
|
|
392
|
+
if (values.json) {
|
|
393
|
+
stdout(`${JSON.stringify({
|
|
394
|
+
rootDirectory: repository.rootDirectory,
|
|
395
|
+
configPath: repository.configPath,
|
|
396
|
+
dataDirectory: repository.dataDirectory,
|
|
397
|
+
config: repository.config,
|
|
398
|
+
}, null, 2)}\n`);
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
stdout(`${repository.configPath}\n`);
|
|
402
|
+
}
|
|
403
|
+
return 0;
|
|
404
|
+
}
|
|
405
|
+
const result = await diagnoseRepository(repository);
|
|
406
|
+
if (values.json) {
|
|
407
|
+
stdout(`${JSON.stringify(result, null, 2)}\n`);
|
|
408
|
+
}
|
|
409
|
+
else if (result.valid) {
|
|
410
|
+
stdout(`Taskset repository is valid (${result.taskCount} tasks)\n`);
|
|
104
411
|
}
|
|
105
412
|
else {
|
|
106
|
-
|
|
413
|
+
for (const diagnostic of result.diagnostics) {
|
|
414
|
+
stdout(`${diagnostic.code}\t${diagnostic.path ?? '-'}\t${diagnostic.message}\t${diagnostic.remediation}\n`);
|
|
415
|
+
}
|
|
107
416
|
}
|
|
417
|
+
return result.valid ? 0 : 1;
|
|
418
|
+
}
|
|
419
|
+
if (command === 'generate') {
|
|
420
|
+
const parsed = parseArgs({
|
|
421
|
+
args: commandArgs,
|
|
422
|
+
allowPositionals: false,
|
|
423
|
+
options: commonOptionDefinitions,
|
|
424
|
+
});
|
|
425
|
+
const values = parseSchema(CommonValuesSchema, parsed.values, 'generate options');
|
|
426
|
+
const repository = await discoverRepository(resolveCommandCwd(cwd, values.cwd));
|
|
427
|
+
const result = await generateViews(repository);
|
|
428
|
+
stdout(values.json
|
|
429
|
+
? `${JSON.stringify(result, null, 2)}\n`
|
|
430
|
+
: `Generated ${result.files.length} views in ${result.directory}\n`);
|
|
108
431
|
return 0;
|
|
109
432
|
}
|
|
433
|
+
if (command === 'snapshot') {
|
|
434
|
+
if (subcommand === 'create' || subcommand === 'list') {
|
|
435
|
+
const parsed = parseArgs({
|
|
436
|
+
args: subcommandArgs,
|
|
437
|
+
allowPositionals: false,
|
|
438
|
+
options: commonOptionDefinitions,
|
|
439
|
+
});
|
|
440
|
+
const values = parseSchema(CommonValuesSchema, parsed.values, `snapshot ${subcommand} options`);
|
|
441
|
+
const repository = await discoverRepository(resolveCommandCwd(cwd, values.cwd));
|
|
442
|
+
if (subcommand === 'create') {
|
|
443
|
+
const result = await createSnapshot(repository);
|
|
444
|
+
stdout(values.json ? `${JSON.stringify(result, null, 2)}\n` : `${result.id}\n`);
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
const results = await listSnapshots(repository);
|
|
448
|
+
if (values.json) {
|
|
449
|
+
stdout(`${JSON.stringify(results, null, 2)}\n`);
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
for (const result of results) {
|
|
453
|
+
stdout(`${result.id}\t${result.createdAt}\t${result.files.length}\n`);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return 0;
|
|
458
|
+
}
|
|
459
|
+
if (subcommand === 'restore') {
|
|
460
|
+
const parsed = parseArgs({
|
|
461
|
+
args: subcommandArgs,
|
|
462
|
+
allowPositionals: true,
|
|
463
|
+
options: {
|
|
464
|
+
...commonOptionDefinitions,
|
|
465
|
+
apply: { type: 'boolean' },
|
|
466
|
+
},
|
|
467
|
+
});
|
|
468
|
+
const [snapshotId] = requirePositionals(parsed.positionals, 1, 'exactly one snapshot ID');
|
|
469
|
+
const values = parseSchema(z.strictObject({
|
|
470
|
+
apply: z.boolean().optional(),
|
|
471
|
+
cwd: CwdSchema,
|
|
472
|
+
json: JsonSchema,
|
|
473
|
+
}), parsed.values, 'snapshot restore options');
|
|
474
|
+
const validatedSnapshotId = parseSchema(z.string().regex(/^\d{8}T\d{6}Z-[a-f0-9]{12}$/u), snapshotId, 'snapshot ID');
|
|
475
|
+
const repository = await discoverRepository(resolveCommandCwd(cwd, values.cwd));
|
|
476
|
+
const result = await restoreSnapshot(repository, validatedSnapshotId, {
|
|
477
|
+
apply: values.apply,
|
|
478
|
+
onWarning,
|
|
479
|
+
});
|
|
480
|
+
stdout(values.json
|
|
481
|
+
? `${JSON.stringify(result, null, 2)}\n`
|
|
482
|
+
: `${result.applied ? 'Restored' : 'Would restore'} ${result.changes.length} task files from ${validatedSnapshotId}\n`);
|
|
483
|
+
return 0;
|
|
484
|
+
}
|
|
485
|
+
throw new CliUsageError(`Unknown snapshot command "${subcommand ?? ''}"`);
|
|
486
|
+
}
|
|
110
487
|
if (command !== 'task') {
|
|
111
488
|
throw new CliUsageError(`Unknown command "${command}"`);
|
|
112
489
|
}
|
|
113
490
|
if (subcommand === 'create') {
|
|
114
491
|
const parsed = parseArgs({
|
|
115
|
-
args:
|
|
492
|
+
args: subcommandArgs,
|
|
493
|
+
allowPositionals: false,
|
|
494
|
+
options: { ...metadataOptionDefinitions, ...commonOptionDefinitions },
|
|
495
|
+
});
|
|
496
|
+
const values = parseSchema(CreateValuesSchema, parsed.values, 'task create options');
|
|
497
|
+
const repository = await discoverRepository(resolveCommandCwd(cwd, values.cwd));
|
|
498
|
+
const record = await createTask(repository, {
|
|
499
|
+
title: values.title,
|
|
500
|
+
...(values.status ? { status: values.status } : {}),
|
|
501
|
+
...(values.priority ? { priority: values.priority } : {}),
|
|
502
|
+
...(values.label ? { labels: values.label } : {}),
|
|
503
|
+
...(values['depends-on'] ? { dependsOn: values['depends-on'] } : {}),
|
|
504
|
+
...(values.file ? { files: normalizeMutationPaths(repository, values.file) } : {}),
|
|
505
|
+
...(values.owner ? { owner: values.owner } : {}),
|
|
506
|
+
...(values.assignee ? { assignees: values.assignee } : {}),
|
|
507
|
+
...(values.reviewer ? { reviewers: values.reviewer } : {}),
|
|
508
|
+
...(values.team ? { team: values.team } : {}),
|
|
509
|
+
...(values.estimate !== undefined ? { estimate: values.estimate } : {}),
|
|
510
|
+
...(values.effort !== undefined ? { effort: values.effort } : {}),
|
|
511
|
+
...(values.risk ? { risk: values.risk } : {}),
|
|
512
|
+
...(values['due-date'] ? { dueDate: values['due-date'] } : {}),
|
|
513
|
+
...(values.related ? { related: values.related } : {}),
|
|
514
|
+
...(values.duplicate ? { duplicates: values.duplicate } : {}),
|
|
515
|
+
...(values.parent ? { parent: values.parent } : {}),
|
|
516
|
+
...(values.directory
|
|
517
|
+
? { directories: normalizeMutationPaths(repository, values.directory) }
|
|
518
|
+
: {}),
|
|
519
|
+
...(values.project ? { projects: values.project } : {}),
|
|
520
|
+
...(values.body !== undefined ? { body: values.body } : {}),
|
|
521
|
+
}, { onWarning });
|
|
522
|
+
writeTaskRecord(record, values.json, stdout);
|
|
523
|
+
return 0;
|
|
524
|
+
}
|
|
525
|
+
if (subcommand === 'list') {
|
|
526
|
+
const parsed = parseArgs({
|
|
527
|
+
args: subcommandArgs,
|
|
116
528
|
allowPositionals: false,
|
|
117
529
|
options: {
|
|
118
|
-
body: { type: 'string' },
|
|
119
530
|
cwd: { type: 'string' },
|
|
120
|
-
'depends-on': { type: 'string', multiple: true },
|
|
121
|
-
file: { type: 'string', multiple: true },
|
|
122
531
|
json: { type: 'boolean' },
|
|
532
|
+
status: { type: 'string', multiple: true },
|
|
533
|
+
priority: { type: 'string', multiple: true },
|
|
123
534
|
label: { type: 'string', multiple: true },
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
535
|
+
owner: { type: 'string', multiple: true },
|
|
536
|
+
assignee: { type: 'string', multiple: true },
|
|
537
|
+
reviewer: { type: 'string', multiple: true },
|
|
538
|
+
team: { type: 'string', multiple: true },
|
|
539
|
+
risk: { type: 'string', multiple: true },
|
|
540
|
+
project: { type: 'string', multiple: true },
|
|
541
|
+
'depends-on': { type: 'string' },
|
|
542
|
+
related: { type: 'string' },
|
|
543
|
+
duplicate: { type: 'string' },
|
|
544
|
+
parent: { type: 'string' },
|
|
545
|
+
file: { type: 'string', multiple: true },
|
|
546
|
+
directory: { type: 'string', multiple: true },
|
|
547
|
+
'estimate-min': { type: 'string' },
|
|
548
|
+
'estimate-max': { type: 'string' },
|
|
549
|
+
'effort-min': { type: 'string' },
|
|
550
|
+
'effort-max': { type: 'string' },
|
|
551
|
+
'due-before': { type: 'string' },
|
|
552
|
+
'due-after': { type: 'string' },
|
|
553
|
+
'created-before': { type: 'string' },
|
|
554
|
+
'created-after': { type: 'string' },
|
|
555
|
+
'updated-before': { type: 'string' },
|
|
556
|
+
'updated-after': { type: 'string' },
|
|
557
|
+
search: { type: 'string' },
|
|
558
|
+
sort: { type: 'string' },
|
|
559
|
+
direction: { type: 'string' },
|
|
560
|
+
impact: { type: 'boolean' },
|
|
561
|
+
'include-derived': { type: 'boolean' },
|
|
127
562
|
},
|
|
128
563
|
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
...(
|
|
138
|
-
...(
|
|
139
|
-
...(
|
|
140
|
-
...(
|
|
141
|
-
...(
|
|
142
|
-
...(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
564
|
+
const values = parseSchema(ListValuesSchema, parsed.values, 'task list options');
|
|
565
|
+
const query = parseSchema(TaskQuerySchema, {
|
|
566
|
+
...(values.status ? { statuses: values.status } : {}),
|
|
567
|
+
...(values.priority ? { priorities: values.priority } : {}),
|
|
568
|
+
...(values.label ? { labels: values.label } : {}),
|
|
569
|
+
...(values.owner ? { owners: values.owner } : {}),
|
|
570
|
+
...(values.assignee ? { assignees: values.assignee } : {}),
|
|
571
|
+
...(values.reviewer ? { reviewers: values.reviewer } : {}),
|
|
572
|
+
...(values.team ? { teams: values.team } : {}),
|
|
573
|
+
...(values.risk ? { risks: values.risk } : {}),
|
|
574
|
+
...(values.project ? { projects: values.project } : {}),
|
|
575
|
+
...(values['depends-on'] ? { dependsOn: values['depends-on'] } : {}),
|
|
576
|
+
...(values.related ? { related: values.related } : {}),
|
|
577
|
+
...(values.duplicate ? { duplicate: values.duplicate } : {}),
|
|
578
|
+
...(values.parent ? { parent: values.parent } : {}),
|
|
579
|
+
...(values.file ? { files: values.file } : {}),
|
|
580
|
+
...(values.directory ? { directories: values.directory } : {}),
|
|
581
|
+
...(values['estimate-min'] !== undefined ? { estimateMin: values['estimate-min'] } : {}),
|
|
582
|
+
...(values['estimate-max'] !== undefined ? { estimateMax: values['estimate-max'] } : {}),
|
|
583
|
+
...(values['effort-min'] !== undefined ? { effortMin: values['effort-min'] } : {}),
|
|
584
|
+
...(values['effort-max'] !== undefined ? { effortMax: values['effort-max'] } : {}),
|
|
585
|
+
...(values['due-before'] ? { dueBefore: values['due-before'] } : {}),
|
|
586
|
+
...(values['due-after'] ? { dueAfter: values['due-after'] } : {}),
|
|
587
|
+
...(values['created-before'] ? { createdBefore: values['created-before'] } : {}),
|
|
588
|
+
...(values['created-after'] ? { createdAfter: values['created-after'] } : {}),
|
|
589
|
+
...(values['updated-before'] ? { updatedBefore: values['updated-before'] } : {}),
|
|
590
|
+
...(values['updated-after'] ? { updatedAfter: values['updated-after'] } : {}),
|
|
591
|
+
...(values.search !== undefined ? { text: values.search } : {}),
|
|
592
|
+
...(values.sort ? { sortBy: values.sort } : {}),
|
|
593
|
+
...(values.direction ? { direction: values.direction } : {}),
|
|
594
|
+
...(values.impact ? { impact: true } : {}),
|
|
595
|
+
}, 'task list query');
|
|
596
|
+
const repository = await discoverRepository(resolveCommandCwd(cwd, values.cwd));
|
|
597
|
+
const result = await queryTasks(repository, query);
|
|
598
|
+
const graph = values['include-derived'] ? (await buildTaskIndex(repository)).graph : undefined;
|
|
599
|
+
const serialize = (record) => taskRecordJson(record, graph?.derive(record.task.metadata.id));
|
|
600
|
+
if (values.json) {
|
|
601
|
+
stdout(`${JSON.stringify(values.impact
|
|
602
|
+
? {
|
|
603
|
+
direct: result.direct.map(serialize),
|
|
604
|
+
impacted: result.impacted.map(serialize),
|
|
605
|
+
}
|
|
606
|
+
: result.direct.map(serialize), null, 2)}\n`);
|
|
161
607
|
}
|
|
162
608
|
else {
|
|
163
|
-
for (const record of
|
|
164
|
-
stdout(`${record.task.metadata.id}\t${record.task.metadata.status}\t${record.task.metadata.title}\n`);
|
|
609
|
+
for (const record of result.direct) {
|
|
610
|
+
stdout(`${values.impact ? 'direct\t' : ''}${record.task.metadata.id}\t${record.task.metadata.status}\t${record.task.metadata.title}\n`);
|
|
611
|
+
}
|
|
612
|
+
for (const record of result.impacted) {
|
|
613
|
+
stdout(`impact\t${record.task.metadata.id}\t${record.task.metadata.status}\t${record.task.metadata.title}\n`);
|
|
165
614
|
}
|
|
166
615
|
}
|
|
167
616
|
return 0;
|
|
168
617
|
}
|
|
169
618
|
if (subcommand === 'show') {
|
|
170
619
|
const parsed = parseArgs({
|
|
171
|
-
args:
|
|
620
|
+
args: subcommandArgs,
|
|
172
621
|
allowPositionals: true,
|
|
173
622
|
options: {
|
|
174
|
-
|
|
175
|
-
|
|
623
|
+
...commonOptionDefinitions,
|
|
624
|
+
'include-derived': { type: 'boolean' },
|
|
176
625
|
},
|
|
177
626
|
});
|
|
178
|
-
const taskId =
|
|
179
|
-
const
|
|
180
|
-
const
|
|
181
|
-
|
|
627
|
+
const [taskId] = requirePositionals(parsed.positionals, 1, 'exactly one task ID');
|
|
628
|
+
const validatedTaskId = parseSchema(TaskIdSchema, taskId, 'task ID');
|
|
629
|
+
const values = parseSchema(z.strictObject({
|
|
630
|
+
cwd: CwdSchema,
|
|
631
|
+
json: JsonSchema,
|
|
632
|
+
'include-derived': z.boolean().optional(),
|
|
633
|
+
}), parsed.values, 'task show options');
|
|
634
|
+
const repository = await discoverRepository(resolveCommandCwd(cwd, values.cwd));
|
|
635
|
+
const record = await readTask(repository, validatedTaskId);
|
|
636
|
+
if (values.json) {
|
|
637
|
+
const derived = values['include-derived']
|
|
638
|
+
? (await buildTaskIndex(repository)).graph.derive(validatedTaskId)
|
|
639
|
+
: undefined;
|
|
182
640
|
stdout(`${JSON.stringify({
|
|
183
641
|
relativePath: record.relativePath,
|
|
184
642
|
metadata: record.task.metadata,
|
|
185
643
|
body: record.task.body,
|
|
644
|
+
...(derived ? { derived } : {}),
|
|
186
645
|
}, null, 2)}\n`);
|
|
187
646
|
}
|
|
188
647
|
else {
|
|
@@ -190,10 +649,75 @@ export async function runCli(args, context = {}) {
|
|
|
190
649
|
}
|
|
191
650
|
return 0;
|
|
192
651
|
}
|
|
652
|
+
if (subcommand === 'update') {
|
|
653
|
+
const clearDefinitions = Object.fromEntries(UPDATE_CLEAR_PAIRS.map(([, clear]) => [clear, { type: 'boolean' }]));
|
|
654
|
+
const parsed = parseArgs({
|
|
655
|
+
args: subcommandArgs,
|
|
656
|
+
allowPositionals: true,
|
|
657
|
+
options: {
|
|
658
|
+
...metadataOptionDefinitions,
|
|
659
|
+
...clearDefinitions,
|
|
660
|
+
...commonOptionDefinitions,
|
|
661
|
+
},
|
|
662
|
+
});
|
|
663
|
+
const [taskId] = requirePositionals(parsed.positionals, 1, 'exactly one task ID');
|
|
664
|
+
const validatedTaskId = parseSchema(TaskIdSchema, taskId, 'task ID');
|
|
665
|
+
const values = parseSchema(UpdateValuesSchema, parsed.values, 'task update options');
|
|
666
|
+
const repository = await discoverRepository(resolveCommandCwd(cwd, values.cwd));
|
|
667
|
+
const record = await updateTask(repository, validatedTaskId, updateInputFromValues(repository, values), { onWarning });
|
|
668
|
+
writeTaskRecord(record, values.json, stdout);
|
|
669
|
+
return 0;
|
|
670
|
+
}
|
|
671
|
+
if (subcommand === 'status') {
|
|
672
|
+
const parsed = parseArgs({
|
|
673
|
+
args: subcommandArgs,
|
|
674
|
+
allowPositionals: true,
|
|
675
|
+
options: commonOptionDefinitions,
|
|
676
|
+
});
|
|
677
|
+
const [taskId, status] = requirePositionals(parsed.positionals, 2, 'a task ID and status');
|
|
678
|
+
const validatedTaskId = parseSchema(TaskIdSchema, taskId, 'task ID');
|
|
679
|
+
const validatedStatus = parseSchema(TaskStatusSchema, status, 'task status');
|
|
680
|
+
const values = parseSchema(CommonValuesSchema, parsed.values, 'task status options');
|
|
681
|
+
const repository = await discoverRepository(resolveCommandCwd(cwd, values.cwd));
|
|
682
|
+
const record = await updateTask(repository, validatedTaskId, { status: validatedStatus }, { onWarning });
|
|
683
|
+
writeTaskRecord(record, values.json, stdout);
|
|
684
|
+
return 0;
|
|
685
|
+
}
|
|
686
|
+
if (subcommand === 'delete') {
|
|
687
|
+
const parsed = parseArgs({
|
|
688
|
+
args: subcommandArgs,
|
|
689
|
+
allowPositionals: true,
|
|
690
|
+
options: {
|
|
691
|
+
...commonOptionDefinitions,
|
|
692
|
+
'remove-dependencies': { type: 'boolean' },
|
|
693
|
+
},
|
|
694
|
+
});
|
|
695
|
+
const [taskId] = requirePositionals(parsed.positionals, 1, 'exactly one task ID');
|
|
696
|
+
const validatedTaskId = parseSchema(TaskIdSchema, taskId, 'task ID');
|
|
697
|
+
const values = parseSchema(z.strictObject({
|
|
698
|
+
cwd: CwdSchema,
|
|
699
|
+
json: JsonSchema,
|
|
700
|
+
'remove-dependencies': z.boolean().optional(),
|
|
701
|
+
}), parsed.values, 'task delete options');
|
|
702
|
+
const repository = await discoverRepository(resolveCommandCwd(cwd, values.cwd));
|
|
703
|
+
const record = await deleteTask(repository, validatedTaskId, {
|
|
704
|
+
removeDependencies: values['remove-dependencies'],
|
|
705
|
+
onWarning,
|
|
706
|
+
});
|
|
707
|
+
if (values.json) {
|
|
708
|
+
stdout(`${JSON.stringify({ deleted: true, ...taskRecordJson(record) }, null, 2)}\n`);
|
|
709
|
+
}
|
|
710
|
+
else {
|
|
711
|
+
stdout(`${validatedTaskId}\n`);
|
|
712
|
+
}
|
|
713
|
+
return 0;
|
|
714
|
+
}
|
|
193
715
|
throw new CliUsageError(`Unknown task command "${subcommand ?? ''}"`);
|
|
194
716
|
}
|
|
195
717
|
catch (error) {
|
|
196
|
-
if (error instanceof CliUsageError ||
|
|
718
|
+
if (error instanceof CliUsageError ||
|
|
719
|
+
error instanceof RepositoryPathError ||
|
|
720
|
+
error instanceof TypeError) {
|
|
197
721
|
stderr(`${formatError(error)}\n\n${USAGE}`);
|
|
198
722
|
return 2;
|
|
199
723
|
}
|