@zinn-dev/cli 0.44.0 → 0.46.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/README.md +1 -1
- package/package.json +3 -3
- package/skills/zinn/SKILL.md +7 -9
- package/src/actor.d.ts +1 -1
- package/src/actor.js +4 -1
- package/src/capabilities-schema.d.ts +9 -1
- package/src/column-hint.js +1 -3
- package/src/database.d.ts +1 -2
- package/src/database.js +1 -6
- package/src/duration-input.d.ts +7 -0
- package/src/duration-input.js +31 -0
- package/src/errors.d.ts +26 -0
- package/src/errors.js +46 -8
- package/src/expected-values.d.ts +48 -0
- package/src/expected-values.js +60 -0
- package/src/follow.d.ts +9 -0
- package/src/follow.js +58 -0
- package/src/input.d.ts +0 -8
- package/src/input.js +36 -16
- package/src/lib.d.ts +7 -3
- package/src/lib.js +70 -28
- package/src/list-continuation.js +1 -4
- package/src/presentation/activity-presentation.d.ts +2 -0
- package/src/presentation/activity-presentation.js +60 -3
- package/src/presentation/column-presentation.d.ts +9 -4
- package/src/presentation/column-presentation.js +29 -12
- package/src/presentation/doctor-presentation.d.ts +10 -0
- package/src/presentation/doctor-presentation.js +28 -0
- package/src/presentation/relation-presentation.js +2 -1
- package/src/presentation/skill-status-presentation.d.ts +9 -0
- package/src/presentation/skill-status-presentation.js +43 -0
- package/src/presentation/task-blame-presentation.d.ts +2 -4
- package/src/presentation/task-blame-presentation.js +4 -2
- package/src/presentation/task-presentation.d.ts +18 -4
- package/src/presentation/task-presentation.js +94 -30
- package/src/result-schemas.d.ts +490 -58
- package/src/result-schemas.js +97 -2
- package/src/results.d.ts +6 -2
- package/src/results.js +9 -3
- package/src/routes/activity-router.d.ts +16 -5
- package/src/routes/activity-router.js +131 -70
- package/src/routes/aliases.js +1 -0
- package/src/routes/backup-router.d.ts +1 -0
- package/src/routes/backup-router.js +4 -3
- package/src/routes/capabilities-router.d.ts +1 -0
- package/src/routes/capabilities-router.js +1 -1
- package/src/routes/comment-router.d.ts +29 -6
- package/src/routes/comment-router.js +20 -10
- package/src/routes/doctor-router.d.ts +40 -0
- package/src/routes/doctor-router.js +83 -0
- package/src/routes/info-router.d.ts +1 -0
- package/src/routes/info-router.js +1 -1
- package/src/routes/label-router.d.ts +44 -6
- package/src/routes/label-router.js +27 -10
- package/src/routes/migrate-router.d.ts +1 -0
- package/src/routes/migrate-router.js +5 -7
- package/src/routes/project-router.d.ts +70 -11
- package/src/routes/project-router.js +130 -56
- package/src/routes/reindex-router.d.ts +1 -0
- package/src/routes/reindex-router.js +1 -1
- package/src/routes/relation-router.d.ts +3 -0
- package/src/routes/relation-router.js +9 -6
- package/src/routes/restore-router.d.ts +1 -0
- package/src/routes/restore-router.js +5 -6
- package/src/routes/router.js +5 -9
- package/src/routes/routes.d.ts +517 -35
- package/src/routes/routes.js +4 -0
- package/src/routes/skill-router.d.ts +76 -0
- package/src/routes/skill-router.js +179 -0
- package/src/routes/task-router.d.ts +264 -13
- package/src/routes/task-router.js +415 -93
- package/src/routes/whoami-router.d.ts +1 -0
- package/src/routes/whoami-router.js +1 -1
- package/src/skill-copies.d.ts +34 -0
- package/src/skill-copies.js +109 -0
- package/src/telemetry.d.ts +2 -2
- package/src/telemetry.js +8 -3
- package/src/text-edit.d.ts +2 -2
- package/src/text-input.d.ts +19 -1
- package/src/text-input.js +26 -5
- package/src/types.d.ts +4 -0
- package/src/types.js +6 -0
package/src/result-schemas.js
CHANGED
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { activityActionSchema, activityEntityTypeSchema, actorKindSchema, infoDatabaseStateSchema, labelColorSchema, relationTypeSchema, settingsFileSourceSchema, settingsFileStateSchema, settingsSchema, storageSourceSchema, taskPrioritySchema, telemetryModeSchema, telemetrySourceSchema, } from "@zinn-dev/core";
|
|
2
|
+
import { activityActionSchema, activityEntityTypeSchema, actorKindSchema, columnCategorySchema, doctorCheckIdSchema, doctorStatusSchema, infoDatabaseStateSchema, labelColorSchema, relationTypeSchema, settingsFileSourceSchema, settingsFileStateSchema, settingsSchema, storageSourceSchema, taskPrioritySchema, telemetryModeSchema, telemetrySourceSchema, CLAIM_WORK_LIMIT_MS, } from "@zinn-dev/core";
|
|
3
3
|
import { errorDocumentSchema } from "./errors.js";
|
|
4
|
+
import { formatDurationInput } from "./duration-input.js";
|
|
4
5
|
import { capabilitiesSchema, jsonValueSchema } from "./capabilities-schema.js";
|
|
5
6
|
const nullableText = z.string().nullable();
|
|
6
7
|
const count = z.number().int().nonnegative();
|
|
7
8
|
const timestamp = z.number().int().describe("Milliseconds since the Unix epoch.");
|
|
8
9
|
const taskStatus = z.enum(["Active", "Archived"]);
|
|
10
|
+
// A newer Zinn may store a category this version does not know.
|
|
11
|
+
const columnCategory = z.string().nullable();
|
|
12
|
+
const columnCategoryValues = `Known categories: ${columnCategorySchema.options.join(", ")}. Other stored values may occur.`;
|
|
13
|
+
export const taskClaimSchema = z.strictObject({
|
|
14
|
+
state: z
|
|
15
|
+
.enum(["live", "expired"])
|
|
16
|
+
.describe("live until expires_at, expired after it. An expired claim stays until it is replaced or released."),
|
|
17
|
+
actor_kind: z
|
|
18
|
+
.string()
|
|
19
|
+
.describe(`Known actor kinds: ${actorKindSchema.options.join(", ")}. Other stored values may occur.`),
|
|
20
|
+
actor_name: nullableText,
|
|
21
|
+
actor_session_id: nullableText,
|
|
22
|
+
actor_thread_id: nullableText,
|
|
23
|
+
claimed_at: timestamp,
|
|
24
|
+
renewed_at: timestamp.describe("When the holder last renewed the claim."),
|
|
25
|
+
worked_at: timestamp.describe("When the holder last recorded work on the task."),
|
|
26
|
+
lease_ms: z.number().int().positive().describe("Lease length in milliseconds."),
|
|
27
|
+
expires_at: timestamp.describe(`The end of the lease after renewed_at, or ${formatDurationInput(CLAIM_WORK_LIMIT_MS)} after worked_at, whichever comes first.`),
|
|
28
|
+
});
|
|
9
29
|
export const taskSchema = z.strictObject({
|
|
10
30
|
id: z.string().describe("Stored task ID."),
|
|
11
31
|
key: z.string().describe("Readable project key and task number."),
|
|
@@ -15,6 +35,7 @@ export const taskSchema = z.strictObject({
|
|
|
15
35
|
column_id: z.string().describe("Current column ID."),
|
|
16
36
|
is_first: z.boolean().describe("Whether the task's column is the first column of its board."),
|
|
17
37
|
is_last: z.boolean().describe("Whether the task's column is the last column of its board."),
|
|
38
|
+
column_category: columnCategory.describe(`The task's column category, or null on an older database opened read-only. ${columnCategoryValues}`),
|
|
18
39
|
title: z.string(),
|
|
19
40
|
description: nullableText,
|
|
20
41
|
priority: z
|
|
@@ -28,7 +49,25 @@ export const taskSchema = z.strictObject({
|
|
|
28
49
|
label_ids: z.array(z.string()).describe("Attached label IDs, in the same order as labels."),
|
|
29
50
|
created_at: timestamp,
|
|
30
51
|
updated_at: timestamp,
|
|
52
|
+
claim: taskClaimSchema
|
|
53
|
+
.nullable()
|
|
54
|
+
.describe("The task's claim, or null when it has none or the database predates claims."),
|
|
31
55
|
});
|
|
56
|
+
const searchExcerptFields = {
|
|
57
|
+
snippet: z.string().describe("Excerpt containing the first match in this source."),
|
|
58
|
+
highlights: z
|
|
59
|
+
.array(z.tuple([count, count]))
|
|
60
|
+
.describe("Zero-based, end-exclusive Unicode code-point ranges relative to the snippet."),
|
|
61
|
+
};
|
|
62
|
+
const taskSearchMatchSchema = z.discriminatedUnion("field", [
|
|
63
|
+
z.strictObject({ field: z.enum(["key", "title", "description"]), ...searchExcerptFields }),
|
|
64
|
+
z.strictObject({
|
|
65
|
+
field: z.literal("comment"),
|
|
66
|
+
comment_key: z.string(),
|
|
67
|
+
...searchExcerptFields,
|
|
68
|
+
}),
|
|
69
|
+
]);
|
|
70
|
+
const taskSearchResultSchema = taskSchema.extend({ matches: z.array(taskSearchMatchSchema) });
|
|
32
71
|
export const relationSchema = z.strictObject({
|
|
33
72
|
id: z.string().describe("Stored relation ID."),
|
|
34
73
|
type: z
|
|
@@ -46,6 +85,7 @@ export const relationSchema = z.strictObject({
|
|
|
46
85
|
column_id: true,
|
|
47
86
|
is_first: true,
|
|
48
87
|
is_last: true,
|
|
88
|
+
column_category: true,
|
|
49
89
|
title: true,
|
|
50
90
|
status: true,
|
|
51
91
|
}),
|
|
@@ -81,6 +121,7 @@ export const activitySchema = z.strictObject({
|
|
|
81
121
|
actor_model: nullableText,
|
|
82
122
|
actor_effort: nullableText,
|
|
83
123
|
actor_client: nullableText,
|
|
124
|
+
actor_directory: nullableText,
|
|
84
125
|
entity_type: z
|
|
85
126
|
.string()
|
|
86
127
|
.describe(`Known entity types: ${activityEntityTypeSchema.options.join(", ")}. Other stored values may occur.`),
|
|
@@ -104,6 +145,7 @@ export const actorSchema = activitySchema.pick({
|
|
|
104
145
|
actor_model: true,
|
|
105
146
|
actor_effort: true,
|
|
106
147
|
actor_client: true,
|
|
148
|
+
actor_directory: true,
|
|
107
149
|
});
|
|
108
150
|
export const taskAttributionSchema = actorSchema.extend({
|
|
109
151
|
id: activitySchema.shape.id,
|
|
@@ -143,15 +185,17 @@ export const columnSchema = z.strictObject({
|
|
|
143
185
|
name: z.string(),
|
|
144
186
|
is_first: z.boolean().describe("Whether this column is the first column of its board."),
|
|
145
187
|
is_last: z.boolean().describe("Whether this column is the last column of its board."),
|
|
188
|
+
category: columnCategory.describe(`What the column's tasks are to Zinn, or null on an older database opened read-only. ${columnCategoryValues}`),
|
|
146
189
|
});
|
|
147
190
|
export const columnChangeSchema = columnSchema.extend({
|
|
148
|
-
changed: z.boolean().describe("Whether the column's name or position changed."),
|
|
191
|
+
changed: z.boolean().describe("Whether the column's name, category or position changed."),
|
|
149
192
|
});
|
|
150
193
|
export const columnTaskCountSchema = z.strictObject({
|
|
151
194
|
id: columnSchema.shape.id,
|
|
152
195
|
name: z.string(),
|
|
153
196
|
is_first: columnSchema.shape.is_first,
|
|
154
197
|
is_last: columnSchema.shape.is_last,
|
|
198
|
+
category: columnSchema.shape.category,
|
|
155
199
|
taskCount: count,
|
|
156
200
|
});
|
|
157
201
|
export const projectViewSchema = projectSchema.extend({
|
|
@@ -253,7 +297,52 @@ export const infoSchema = z.strictObject({
|
|
|
253
297
|
runtime: z.strictObject({ name: z.enum(["Node", "Bun"]), version: z.string() }),
|
|
254
298
|
}),
|
|
255
299
|
});
|
|
300
|
+
export const doctorSchema = z.strictObject({
|
|
301
|
+
ok: z.boolean().describe("Whether every listed check is ok."),
|
|
302
|
+
checks: z
|
|
303
|
+
.array(z.strictObject({
|
|
304
|
+
id: z.enum([...doctorCheckIdSchema.options, "agent_skill"]),
|
|
305
|
+
status: doctorStatusSchema,
|
|
306
|
+
message: z.string(),
|
|
307
|
+
remedy: nullableText.describe("What to do about a warning or problem, null when the check is ok."),
|
|
308
|
+
}))
|
|
309
|
+
.describe("Checks that could not run because an earlier one failed are left out."),
|
|
310
|
+
});
|
|
256
311
|
export const backupSchema = z.strictObject({ path: z.string() });
|
|
312
|
+
export const skillInstallSchema = z.strictObject({
|
|
313
|
+
source: z.string().describe("The skill folder inside the CLI package that was installed."),
|
|
314
|
+
});
|
|
315
|
+
export const skillUninstallSchema = z.strictObject({
|
|
316
|
+
removed: z
|
|
317
|
+
.array(z.strictObject({
|
|
318
|
+
path: z.string().describe("The first checked path that reached the removed skill file."),
|
|
319
|
+
scope: z.enum(["home", "project"]),
|
|
320
|
+
}))
|
|
321
|
+
.describe("The checked skill copies that the run removed, empty when it removed none."),
|
|
322
|
+
});
|
|
323
|
+
export const skillStatusSchema = z.strictObject({
|
|
324
|
+
bundled: z
|
|
325
|
+
.strictObject({
|
|
326
|
+
path: z
|
|
327
|
+
.string()
|
|
328
|
+
.describe("The skill folder inside the CLI package, which `zinn skill install` installs."),
|
|
329
|
+
reviewedVersion: nullableText.describe("The CLI version the bundled skill was reviewed for."),
|
|
330
|
+
})
|
|
331
|
+
.describe("The skill this CLI installs."),
|
|
332
|
+
copies: z
|
|
333
|
+
.array(z.strictObject({
|
|
334
|
+
path: z.string().describe("The first checked path that reaches the skill file."),
|
|
335
|
+
links: z
|
|
336
|
+
.array(z.string())
|
|
337
|
+
.describe("The other checked paths that reach the same file, in checking order."),
|
|
338
|
+
scope: z.enum(["home", "project"]),
|
|
339
|
+
reviewedVersion: nullableText.describe("The CLI version the copy was reviewed for, null when it names none or cannot be read."),
|
|
340
|
+
matches: z.boolean().describe("Whether its reviewed version matches the bundled skill."),
|
|
341
|
+
readable: z.boolean(),
|
|
342
|
+
remedy: nullableText.describe("The command that updates the copy, null when it matches."),
|
|
343
|
+
}))
|
|
344
|
+
.describe("One entry per skill file agents may load, in checking order, empty when there is none."),
|
|
345
|
+
});
|
|
257
346
|
export const restoreSchema = z.strictObject({
|
|
258
347
|
databasePath: z.string(),
|
|
259
348
|
previousVersion: count.describe("Destination schema version before restore; zero when the destination had no schema version. backupPath says whether it was replaced."),
|
|
@@ -271,6 +360,8 @@ export const reindexSchema = z.strictObject({ databasePath: z.string(), taskCoun
|
|
|
271
360
|
export const resultSchemas = {
|
|
272
361
|
Task: taskSchema,
|
|
273
362
|
TaskList: z.array(taskSchema),
|
|
363
|
+
TaskSearchResults: z.array(taskSearchResultSchema),
|
|
364
|
+
NextTask: taskSchema.nullable(),
|
|
274
365
|
TaskDetail: taskDetailSchema,
|
|
275
366
|
TaskBlame: taskBlameSchema,
|
|
276
367
|
TaskDetailHistory: taskDetailHistorySchema,
|
|
@@ -297,10 +388,14 @@ export const resultSchemas = {
|
|
|
297
388
|
ActivityList: z.array(activitySchema),
|
|
298
389
|
Actor: actorSchema,
|
|
299
390
|
Info: infoSchema,
|
|
391
|
+
Doctor: doctorSchema,
|
|
300
392
|
Backup: backupSchema,
|
|
301
393
|
Restore: restoreSchema,
|
|
302
394
|
Migrate: migrateSchema,
|
|
303
395
|
Reindex: reindexSchema,
|
|
396
|
+
SkillInstall: skillInstallSchema,
|
|
397
|
+
SkillUninstall: skillUninstallSchema,
|
|
398
|
+
SkillStatus: skillStatusSchema,
|
|
304
399
|
ErrorEnvelope: errorDocumentSchema,
|
|
305
400
|
Capabilities: capabilitiesSchema,
|
|
306
401
|
JsonValue: jsonValueSchema,
|
package/src/results.d.ts
CHANGED
|
@@ -27,14 +27,18 @@ export declare const commandResultSchema: z.ZodObject<{
|
|
|
27
27
|
max: z.ZodNullable<z.ZodNumber>;
|
|
28
28
|
}, z.core.$strict>], "kind">;
|
|
29
29
|
schemaRef: z.ZodString;
|
|
30
|
-
mode: z.
|
|
30
|
+
mode: z.ZodEnum<{
|
|
31
|
+
json: "json";
|
|
32
|
+
"json-lines": "json-lines";
|
|
33
|
+
}>;
|
|
31
34
|
stream: z.ZodLiteral<"stdout">;
|
|
32
35
|
exitCode: z.ZodLiteral<0>;
|
|
36
|
+
findingsExitCode: z.ZodOptional<z.ZodLiteral<1>>;
|
|
33
37
|
}, z.core.$strict>;
|
|
34
38
|
export type ResultSelector = z.infer<typeof resultSelectorSchema>;
|
|
35
39
|
export type CommandResult = z.infer<typeof commandResultSchema> & {
|
|
36
40
|
schemaRef: `#/schemas/definitions/${ResultSchemaName}`;
|
|
37
41
|
};
|
|
38
|
-
export declare function jsonResult(schema: ResultSchemaName, selector?: ResultSelector): CommandResult;
|
|
42
|
+
export declare function jsonResult(schema: ResultSchemaName, selector?: ResultSelector, mode?: CommandResult["mode"]): CommandResult;
|
|
39
43
|
export declare const taskDetailResults: CommandResult[];
|
|
40
44
|
export declare const taskChangeResults: CommandResult[];
|
package/src/results.js
CHANGED
|
@@ -13,15 +13,21 @@ export const resultReferenceSchema = z.string().regex(/^#\/schemas\/definitions\
|
|
|
13
13
|
export const commandResultSchema = z.strictObject({
|
|
14
14
|
selector: resultSelectorSchema,
|
|
15
15
|
schemaRef: resultReferenceSchema,
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* json is one document,
|
|
18
|
+
* json-lines is one document per line written as each becomes available
|
|
19
|
+
*/
|
|
20
|
+
mode: z.enum(["json", "json-lines"]),
|
|
17
21
|
stream: z.literal("stdout"),
|
|
18
22
|
exitCode: z.literal(0),
|
|
23
|
+
/** The same document arrives on stdout with this exit code when it reports findings */
|
|
24
|
+
findingsExitCode: z.literal(1).optional(),
|
|
19
25
|
});
|
|
20
|
-
export function jsonResult(schema, selector = { kind: "always" }) {
|
|
26
|
+
export function jsonResult(schema, selector = { kind: "always" }, mode = "json") {
|
|
21
27
|
return {
|
|
22
28
|
selector,
|
|
23
29
|
schemaRef: `#/schemas/definitions/${schema}`,
|
|
24
|
-
mode
|
|
30
|
+
mode,
|
|
25
31
|
stream: "stdout",
|
|
26
32
|
exitCode: 0,
|
|
27
33
|
};
|
|
@@ -4,6 +4,7 @@ export declare const activityRouter: {
|
|
|
4
4
|
effects: {
|
|
5
5
|
domain: "read";
|
|
6
6
|
storage: "normal-open";
|
|
7
|
+
external: never[];
|
|
7
8
|
};
|
|
8
9
|
confirmation: {
|
|
9
10
|
kind: "none";
|
|
@@ -87,7 +88,7 @@ export declare const activityRouter: {
|
|
|
87
88
|
readonly value: {
|
|
88
89
|
readonly kind: "activity-action";
|
|
89
90
|
readonly name: "action";
|
|
90
|
-
readonly choices: ("create" | "delete" | "archive" | "edit" | "move" | "order" | "unarchive" | "relation_create" | "relation_delete" | "comment_create" | "comment_edit" | "comment_delete")[];
|
|
91
|
+
readonly choices: ("create" | "delete" | "claim" | "archive" | "edit" | "move" | "order" | "unarchive" | "relation_create" | "relation_delete" | "comment_create" | "comment_edit" | "comment_delete" | "claim_take" | "claim_heartbeat" | "claim_release")[];
|
|
91
92
|
};
|
|
92
93
|
};
|
|
93
94
|
readonly changed: {
|
|
@@ -96,10 +97,13 @@ export declare const activityRouter: {
|
|
|
96
97
|
readonly value: {
|
|
97
98
|
readonly kind: "activity-change";
|
|
98
99
|
readonly name: "field[=value]";
|
|
99
|
-
readonly pattern:
|
|
100
|
-
readonly description: `Fields: ${string}. Omit the value to match any change.
|
|
100
|
+
readonly pattern: string;
|
|
101
|
+
readonly description: `Fields: ${string}. Omit the value to match any change. ${string} priority=none matches an unassigned priority.`;
|
|
101
102
|
};
|
|
102
103
|
};
|
|
104
|
+
readonly follow: {
|
|
105
|
+
readonly type: "boolean";
|
|
106
|
+
};
|
|
103
107
|
readonly limit: {
|
|
104
108
|
readonly type: "string";
|
|
105
109
|
readonly value: {
|
|
@@ -128,11 +132,17 @@ export declare const activityRouter: {
|
|
|
128
132
|
readonly kind: "requiresAny";
|
|
129
133
|
readonly input: "option:show-deleted";
|
|
130
134
|
readonly members: readonly ["option:project", "option:task"];
|
|
135
|
+
}, {
|
|
136
|
+
readonly kind: "exclusive";
|
|
137
|
+
readonly members: readonly ["option:follow", "option:limit"];
|
|
138
|
+
}, {
|
|
139
|
+
readonly kind: "exclusive";
|
|
140
|
+
readonly members: readonly ["option:follow", "option:starting-after"];
|
|
131
141
|
}];
|
|
132
|
-
readonly notes: readonly ["Repeated --action flags match any listed action. Repeated --changed filters for one field match any of them. Different fields must match the same event. All other filters must also match, before --limit applies."];
|
|
142
|
+
readonly notes: readonly ["With --follow, the command prints activity committed after it starts, oldest first, and runs until stopped.", "Repeated --action flags match any listed action. Repeated --changed filters for one field match any of them. Different fields must match the same event. All other filters must also match, before --limit applies."];
|
|
133
143
|
};
|
|
134
144
|
results: import("../results.js").CommandResult[];
|
|
135
|
-
run: (args: string[]) => void;
|
|
145
|
+
run: (args: string[]) => Promise<void> | undefined;
|
|
136
146
|
help: string;
|
|
137
147
|
};
|
|
138
148
|
view: {
|
|
@@ -140,6 +150,7 @@ export declare const activityRouter: {
|
|
|
140
150
|
effects: {
|
|
141
151
|
domain: "read";
|
|
142
152
|
storage: "normal-open";
|
|
153
|
+
external: never[];
|
|
143
154
|
};
|
|
144
155
|
confirmation: {
|
|
145
156
|
kind: "none";
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { listLimitOption, listLimitDescription, parseListLimit } from "../list-limit.js";
|
|
2
2
|
import { jsonResult } from "../results.js";
|
|
3
3
|
import { parseArgs } from "node:util";
|
|
4
|
-
import { activity, activityActionSchema, activityChangedFieldSchema, activityChangedSchema, CoreError, } from "@zinn-dev/core";
|
|
4
|
+
import { activity, activityActionSchema, activityChangedFieldSchema, activityChangedFieldsWithOptionalValue, activityChangedFieldsWithoutValue, activityChangedSchema, activityIdSchema, activityListSchema, CoreError, InputValidationError, readSnapshot, } from "@zinn-dev/core";
|
|
5
5
|
import { generateCommandUsage, getOptionInputs, violatesConstraint } from "../input.js";
|
|
6
6
|
import { CliError } from "../errors.js";
|
|
7
7
|
import { parseTimestampInput } from "../timestamp-input.js";
|
|
8
8
|
import { formatListContinuation } from "../list-continuation.js";
|
|
9
|
-
import { diagnostic, output, quit, validatePositionals, validateUniqueOptions } from "../lib.js";
|
|
9
|
+
import { diagnostic, getOutputMode, output, outputStream, quit, validatePositionals, validateUniqueOptions, } from "../lib.js";
|
|
10
|
+
import { followUntilStopped } from "../follow.js";
|
|
10
11
|
import { formatActivityList, presentActivities } from "../presentation/activity-presentation.js";
|
|
11
12
|
const changedFieldList = activityChangedFieldSchema.options.join(", ");
|
|
13
|
+
const changedFieldListFormatter = new Intl.ListFormat("en-GB");
|
|
14
|
+
const changedFieldsWithoutValue = changedFieldListFormatter.format(activityChangedFieldsWithoutValue);
|
|
15
|
+
const changedFieldsWithValue = changedFieldListFormatter.format(activityChangedFieldsWithOptionalValue.map((field) => field === "labels" ? "added labels" : field));
|
|
16
|
+
const changedValueHelp = `Values apply to ${changedFieldsWithValue}, ignoring case.`;
|
|
12
17
|
const activityInputs = {
|
|
13
18
|
list: {
|
|
14
19
|
options: {
|
|
@@ -68,10 +73,11 @@ const activityInputs = {
|
|
|
68
73
|
value: {
|
|
69
74
|
kind: "activity-change",
|
|
70
75
|
name: "field[=value]",
|
|
71
|
-
pattern: `^((
|
|
72
|
-
description: `Fields: ${changedFieldList}. Omit the value to match any change.
|
|
76
|
+
pattern: String.raw `^(?:(?:${activityChangedFieldsWithOptionalValue.join("|")})(?:=[\s\S]+)?|${activityChangedFieldsWithoutValue.join("|")})$`,
|
|
77
|
+
description: `Fields: ${changedFieldList}. Omit the value to match any change. ${changedValueHelp} priority=none matches an unassigned priority.`,
|
|
73
78
|
},
|
|
74
79
|
},
|
|
80
|
+
follow: { type: "boolean" },
|
|
75
81
|
limit: listLimitOption,
|
|
76
82
|
"starting-after": { type: "string", value: { kind: "activity-id", name: "id" } },
|
|
77
83
|
},
|
|
@@ -86,8 +92,11 @@ const activityInputs = {
|
|
|
86
92
|
input: "option:show-deleted",
|
|
87
93
|
members: ["option:project", "option:task"],
|
|
88
94
|
},
|
|
95
|
+
{ kind: "exclusive", members: ["option:follow", "option:limit"] },
|
|
96
|
+
{ kind: "exclusive", members: ["option:follow", "option:starting-after"] },
|
|
89
97
|
],
|
|
90
98
|
notes: [
|
|
99
|
+
"With --follow, the command prints activity committed after it starts, oldest first, and runs until stopped.",
|
|
91
100
|
"Repeated --action flags match any listed action. Repeated --changed filters for one field match any of them. Different fields must match the same event. All other filters must also match, before --limit applies.",
|
|
92
101
|
],
|
|
93
102
|
},
|
|
@@ -105,10 +114,13 @@ const activityInputs = {
|
|
|
105
114
|
export const activityRouter = {
|
|
106
115
|
list: {
|
|
107
116
|
summary: "List recorded activity across the database, newest first.",
|
|
108
|
-
effects: { domain: "read", storage: "normal-open" },
|
|
117
|
+
effects: { domain: "read", storage: "normal-open", external: [] },
|
|
109
118
|
confirmation: { kind: "none" },
|
|
110
119
|
input: activityInputs.list,
|
|
111
|
-
results: [
|
|
120
|
+
results: [
|
|
121
|
+
jsonResult("ActivityList", { kind: "booleanOption", name: "follow", value: false }),
|
|
122
|
+
jsonResult("Activity", { kind: "booleanOption", name: "follow", value: true }, "json-lines"),
|
|
123
|
+
],
|
|
112
124
|
run: (args) => {
|
|
113
125
|
const { values, positionals, tokens } = parseArgs({
|
|
114
126
|
args,
|
|
@@ -119,7 +131,7 @@ export const activityRouter = {
|
|
|
119
131
|
});
|
|
120
132
|
validateUniqueOptions(tokens, activityInputs.list.options);
|
|
121
133
|
validatePositionals(positionals, activityInputs.list.forms[0]);
|
|
122
|
-
const [selectorConstraint, deletedHistoryConstraint] = activityInputs.list.constraints;
|
|
134
|
+
const [selectorConstraint, deletedHistoryConstraint, ...followConstraints] = activityInputs.list.constraints;
|
|
123
135
|
const optionInputs = getOptionInputs(values);
|
|
124
136
|
if (violatesConstraint(selectorConstraint, optionInputs)) {
|
|
125
137
|
const conflictingSelector = selectorConstraint.members.filter((member) => optionInputs[member] !== undefined)[1];
|
|
@@ -132,67 +144,63 @@ export const activityRouter = {
|
|
|
132
144
|
argument: "--show-deleted",
|
|
133
145
|
});
|
|
134
146
|
}
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
projectKey: values.project,
|
|
140
|
-
projectId: values["project-id"],
|
|
141
|
-
taskKey: values.task,
|
|
142
|
-
taskId: values["task-id"],
|
|
143
|
-
showDeleted: values["show-deleted"],
|
|
144
|
-
sessionId: values.session,
|
|
145
|
-
threadId: values.thread,
|
|
146
|
-
client: values.client,
|
|
147
|
-
actions: values.action?.map((action) => {
|
|
148
|
-
const parsed = activityActionSchema.safeParse(action);
|
|
149
|
-
if (!parsed.success) {
|
|
150
|
-
quit(`Unknown action "${action}". Use ${activityActionSchema.options.join(", ")}`, undefined, {
|
|
151
|
-
argument: "--action",
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
return parsed.data;
|
|
155
|
-
}),
|
|
156
|
-
changed: values.changed?.map(parseChangedFilter),
|
|
157
|
-
since: parseTimestampInput(values.since, "--since"),
|
|
158
|
-
until: parseTimestampInput(values.until, "--until"),
|
|
159
|
-
limit,
|
|
160
|
-
startingAfter: values["starting-after"],
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
catch (error) {
|
|
164
|
-
const isInvalidUpperBound = error instanceof CoreError &&
|
|
165
|
-
error.kind === "input" &&
|
|
166
|
-
error.facts.field?.[0] === "until";
|
|
167
|
-
if (isInvalidUpperBound) {
|
|
168
|
-
throw new CliError(error.message, "invalid_input", {
|
|
169
|
-
argument: "--until",
|
|
170
|
-
field: error.facts.field,
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
const isMissingCurrentSelection = (values.task !== undefined || values.project !== undefined) &&
|
|
174
|
-
values["show-deleted"] !== true &&
|
|
175
|
-
error instanceof CoreError &&
|
|
176
|
-
error.kind === "missing" &&
|
|
177
|
-
error.facts.entity === (values.project !== undefined ? "project" : "task");
|
|
178
|
-
if (isMissingCurrentSelection) {
|
|
179
|
-
const selector = error.facts.entity === "project" ? "--project" : "--task";
|
|
180
|
-
throw new CliError(error.message, "not_found", {
|
|
181
|
-
entity: error.facts.entity,
|
|
182
|
-
key: error.facts.key,
|
|
183
|
-
source: "explicit",
|
|
184
|
-
argument: selector,
|
|
185
|
-
}, `Use ${selector} ${values.project ?? values.task} --show-deleted to include deleted history.`);
|
|
147
|
+
for (const constraint of followConstraints) {
|
|
148
|
+
if (violatesConstraint(constraint, optionInputs)) {
|
|
149
|
+
const argument = constraint.members[1].replace("option:", "--");
|
|
150
|
+
quit(`${argument} cannot be used with --follow`, undefined, { argument });
|
|
186
151
|
}
|
|
187
|
-
throw error;
|
|
188
152
|
}
|
|
189
|
-
|
|
153
|
+
const limit = parseListLimit(values.limit);
|
|
154
|
+
const selection = {
|
|
190
155
|
projectKey: values.project,
|
|
191
156
|
projectId: values["project-id"],
|
|
192
|
-
showDeleted: values["show-deleted"],
|
|
193
157
|
taskKey: values.task,
|
|
194
158
|
taskId: values["task-id"],
|
|
195
|
-
|
|
159
|
+
showDeleted: values["show-deleted"],
|
|
160
|
+
};
|
|
161
|
+
const filters = {
|
|
162
|
+
...selection,
|
|
163
|
+
sessionId: values.session,
|
|
164
|
+
threadId: values.thread,
|
|
165
|
+
client: values.client,
|
|
166
|
+
actions: values.action?.map((action) => {
|
|
167
|
+
const parsed = activityActionSchema.safeParse(action);
|
|
168
|
+
if (!parsed.success) {
|
|
169
|
+
quit(`Unknown action "${action}". Use ${activityActionSchema.options.join(", ")}`, undefined, {
|
|
170
|
+
argument: "--action",
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return parsed.data;
|
|
174
|
+
}),
|
|
175
|
+
changed: values.changed?.map(parseChangedFilter),
|
|
176
|
+
since: parseTimestampInput(values.since, "--since"),
|
|
177
|
+
until: parseTimestampInput(values.until, "--until"),
|
|
178
|
+
};
|
|
179
|
+
const presentTextEvents = (events) => getOutputMode() === "text" ? presentActivities(events, selection) : [];
|
|
180
|
+
if (values.follow === true) {
|
|
181
|
+
const follower = readSelectedActivity(values, () => activity.follow(filters));
|
|
182
|
+
return followUntilStopped(async (signal) => {
|
|
183
|
+
const polled = readSelectedActivity(values, () => readSnapshot(() => {
|
|
184
|
+
const polled = follower.poll();
|
|
185
|
+
return "stopped" in polled
|
|
186
|
+
? polled
|
|
187
|
+
: { ...polled, presented: presentTextEvents(polled.events) };
|
|
188
|
+
}));
|
|
189
|
+
if ("stopped" in polled) {
|
|
190
|
+
const reason = polled.stopped === "file_replaced"
|
|
191
|
+
? `The database file at ${polled.databasePath} was replaced or removed`
|
|
192
|
+
: `The database schema at ${polled.databasePath} changed`;
|
|
193
|
+
throw new CliError(`${reason}, so following stopped. Run the command again to follow new activity.`, "conflict", { entity: "database", databasePath: polled.databasePath });
|
|
194
|
+
}
|
|
195
|
+
await outputStream(polled.events, () => formatActivityList(polled.presented), signal);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
const input = { ...filters, limit, startingAfter: values["starting-after"] };
|
|
199
|
+
const page = readSelectedActivity(values, () => readWithActivityPresentation(activityListSchema, input, () => {
|
|
200
|
+
const page = activity.getAll(input);
|
|
201
|
+
return { ...page, presented: presentTextEvents(page.events) };
|
|
202
|
+
}));
|
|
203
|
+
output(page.events, () => formatActivityList(page.presented));
|
|
196
204
|
if (page.nextCursor !== undefined) {
|
|
197
205
|
diagnostic(`More activity. Continue with: ${formatListContinuation(["activity", "list"], [], tokens, "starting-after", page.nextCursor)}`);
|
|
198
206
|
}
|
|
@@ -219,10 +227,11 @@ Returns all matching events unless --limit is supplied.
|
|
|
219
227
|
--action <action> Match a recorded action. Repeat to match any listed action.
|
|
220
228
|
--changed <field>[=<value>] Match a task field change, with an optional value.
|
|
221
229
|
Fields: ${changedFieldList}.
|
|
222
|
-
|
|
230
|
+
${changedValueHelp}
|
|
223
231
|
Without a value, labels match additions and removals.
|
|
224
|
-
|
|
232
|
+
Use ${changedFieldsWithoutValue} without a value.
|
|
225
233
|
Use priority=none for an unassigned priority.
|
|
234
|
+
--follow Print new activity as it is committed, until stopped.
|
|
226
235
|
--limit <n> ${listLimitDescription}
|
|
227
236
|
--starting-after <id> Continue with older events after this activity ID.
|
|
228
237
|
|
|
@@ -241,8 +250,15 @@ Times accept integer epoch milliseconds or YYYY-MM-DDTHH:mm:ss with Z or a
|
|
|
241
250
|
numeric offset such as +01:00. Optional fractional seconds have 1 to 3 digits.
|
|
242
251
|
Both bounds are inclusive. --until must be at or after --since.
|
|
243
252
|
|
|
253
|
+
--follow prints only activity committed after it starts, oldest first, and the
|
|
254
|
+
filters apply to it. It ends on Ctrl-C, once its output is closed, and with an
|
|
255
|
+
error when the database schema changes, including a restore, migration or
|
|
256
|
+
reindex, or when its file is replaced or removed.
|
|
257
|
+
--follow cannot be used with --limit or --starting-after.
|
|
258
|
+
|
|
244
259
|
Use activity view <activity-id> for complete recorded changes.
|
|
245
260
|
With --json, return an array of full activity records.
|
|
261
|
+
With --follow --json, print each full activity record as one JSON object per line.
|
|
246
262
|
|
|
247
263
|
Examples:
|
|
248
264
|
zinn activity list --limit 10
|
|
@@ -254,11 +270,12 @@ Examples:
|
|
|
254
270
|
zinn activity list --changed column=Review
|
|
255
271
|
zinn activity list --changed priority=high --changed labels=bug
|
|
256
272
|
zinn activity list --task APP-2
|
|
257
|
-
zinn activity list --task APP-2 --show-deleted
|
|
273
|
+
zinn activity list --task APP-2 --show-deleted
|
|
274
|
+
zinn activity list --follow --changed column=Review`,
|
|
258
275
|
},
|
|
259
276
|
view: {
|
|
260
277
|
summary: "Show one recorded event with full activity/entity IDs, actor and complete changes.",
|
|
261
|
-
effects: { domain: "read", storage: "normal-open" },
|
|
278
|
+
effects: { domain: "read", storage: "normal-open", external: [] },
|
|
262
279
|
confirmation: { kind: "none" },
|
|
263
280
|
input: activityInputs.view,
|
|
264
281
|
results: [jsonResult("Activity")],
|
|
@@ -270,10 +287,13 @@ Examples:
|
|
|
270
287
|
strict: true,
|
|
271
288
|
});
|
|
272
289
|
validatePositionals(positionals, activityInputs.view.forms[0]);
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
290
|
+
const id = positionals[0];
|
|
291
|
+
const { viewed, presented } = readWithActivityPresentation(activityIdSchema, id, () => {
|
|
292
|
+
const viewed = activity.getById(id);
|
|
293
|
+
const presented = getOutputMode() === "text" ? presentActivities([viewed], { showsFullIds: true }) : [];
|
|
294
|
+
return { viewed, presented };
|
|
295
|
+
});
|
|
296
|
+
output(viewed, () => formatActivityList(presented, { showsDetails: true }));
|
|
277
297
|
},
|
|
278
298
|
help: `${generateCommandUsage("activity view", activityInputs.view)}
|
|
279
299
|
|
|
@@ -286,6 +306,47 @@ With --json, return one full activity record.
|
|
|
286
306
|
Example: zinn activity view 019abcdf-1234-7`,
|
|
287
307
|
},
|
|
288
308
|
};
|
|
309
|
+
/** Text adds database lookups. Validate the input before opening their shared snapshot. */
|
|
310
|
+
function readWithActivityPresentation(schema, input, read) {
|
|
311
|
+
if (getOutputMode() === "json") {
|
|
312
|
+
return read();
|
|
313
|
+
}
|
|
314
|
+
const validation = schema.safeParse(input);
|
|
315
|
+
if (!validation.success) {
|
|
316
|
+
throw new InputValidationError(validation.error.issues);
|
|
317
|
+
}
|
|
318
|
+
return readSnapshot(read);
|
|
319
|
+
}
|
|
320
|
+
/** Reads the selected activity, reporting core's refusals with the flag that caused them */
|
|
321
|
+
function readSelectedActivity(values, read) {
|
|
322
|
+
try {
|
|
323
|
+
return read();
|
|
324
|
+
}
|
|
325
|
+
catch (error) {
|
|
326
|
+
const isInvalidUpperBound = error instanceof CoreError && error.kind === "input" && error.facts.field?.[0] === "until";
|
|
327
|
+
if (isInvalidUpperBound) {
|
|
328
|
+
throw new CliError(error.message, "invalid_input", {
|
|
329
|
+
argument: "--until",
|
|
330
|
+
field: error.facts.field,
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
const isMissingCurrentSelection = (values.task !== undefined || values.project !== undefined) &&
|
|
334
|
+
values["show-deleted"] !== true &&
|
|
335
|
+
error instanceof CoreError &&
|
|
336
|
+
error.kind === "missing" &&
|
|
337
|
+
error.facts.entity === (values.project !== undefined ? "project" : "task");
|
|
338
|
+
if (isMissingCurrentSelection) {
|
|
339
|
+
const selector = error.facts.entity === "project" ? "--project" : "--task";
|
|
340
|
+
throw new CliError(error.message, "not_found", {
|
|
341
|
+
entity: error.facts.entity,
|
|
342
|
+
key: error.facts.key,
|
|
343
|
+
source: "explicit",
|
|
344
|
+
argument: selector,
|
|
345
|
+
}, `Use ${selector} ${values.project ?? values.task} --show-deleted to include deleted history.`);
|
|
346
|
+
}
|
|
347
|
+
throw error;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
289
350
|
function parseChangedFilter(input) {
|
|
290
351
|
const separator = input.indexOf("=");
|
|
291
352
|
const field = separator === -1 ? input : input.slice(0, separator);
|
package/src/routes/aliases.js
CHANGED
|
@@ -5,8 +5,8 @@ import { generateCommandUsage, noInput } from "../input.js";
|
|
|
5
5
|
import { output, validatePositionals } from "../lib.js";
|
|
6
6
|
import packageJson from "../../package.json" with { type: "json" };
|
|
7
7
|
export const backupCommand = {
|
|
8
|
-
summary: "Save a copy of the database to ~/.zinn/backups/, or to backups/ in ZINN_DIR when it is set.",
|
|
9
|
-
effects: { domain: "none", storage: "backup" },
|
|
8
|
+
summary: "Save a verified copy of the database to ~/.zinn/backups/, or to backups/ in ZINN_DIR when it is set.",
|
|
9
|
+
effects: { domain: "none", storage: "backup", external: [] },
|
|
10
10
|
confirmation: { kind: "none" },
|
|
11
11
|
input: noInput,
|
|
12
12
|
results: [jsonResult("Backup")],
|
|
@@ -23,8 +23,9 @@ export const backupCommand = {
|
|
|
23
23
|
},
|
|
24
24
|
help: `${generateCommandUsage("backup", noInput)}
|
|
25
25
|
|
|
26
|
-
Save a copy of the database to ~/.zinn/backups/, or to backups/ in ZINN_DIR when it is set.
|
|
26
|
+
Save a verified copy of the database to ~/.zinn/backups/, or to backups/ in ZINN_DIR when it is set.
|
|
27
27
|
|
|
28
28
|
The copy includes recent writes and is safe to take while Zinn is in use.
|
|
29
|
+
Zinn checks the copy's SQLite integrity and foreign keys. If a check fails, the command reports the path of the copy retained for recovery.
|
|
29
30
|
Fails when there is no database yet. Existing backups are never overwritten.`,
|
|
30
31
|
};
|
|
@@ -5,7 +5,7 @@ import { formatCapabilities } from "../presentation/capabilities-presentation.js
|
|
|
5
5
|
import { jsonResult } from "../results.js";
|
|
6
6
|
export const capabilitiesCommand = {
|
|
7
7
|
summary: "Describe the installed CLI commands, inputs, results and errors.",
|
|
8
|
-
effects: { domain: "none", storage: "none" },
|
|
8
|
+
effects: { domain: "none", storage: "none", external: [] },
|
|
9
9
|
confirmation: { kind: "none" },
|
|
10
10
|
input: noInput,
|
|
11
11
|
results: [jsonResult("Capabilities")],
|