@zinn-dev/cli 0.41.0 → 0.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -689
- package/index.js +2 -2
- package/package.json +3 -2
- package/skills/zinn/SKILL.md +1 -1
- package/src/capabilities-schema.d.ts +22 -23
- package/src/capabilities-schema.js +17 -82
- package/src/capabilities.d.ts +11 -3
- package/src/capabilities.js +12 -4
- package/src/column-hint.d.ts +3 -0
- package/src/column-hint.js +225 -0
- package/src/database.js +1 -4
- package/src/errors.js +2 -0
- package/src/input.d.ts +154 -43
- package/src/input.js +86 -13
- package/src/lib.d.ts +30 -2
- package/src/lib.js +74 -13
- package/src/presentation/activity-presentation.d.ts +9 -1
- package/src/presentation/activity-presentation.js +108 -25
- package/src/presentation/capabilities-presentation.d.ts +2 -0
- package/src/presentation/capabilities-presentation.js +3 -0
- package/src/presentation/column-presentation.d.ts +6 -0
- package/src/presentation/column-presentation.js +10 -0
- package/src/presentation/comment-presentation.d.ts +15 -0
- package/src/presentation/comment-presentation.js +29 -0
- package/src/presentation/description-presentation.d.ts +17 -0
- package/src/presentation/description-presentation.js +26 -4
- package/src/presentation/label-presentation.d.ts +8 -0
- package/src/presentation/label-presentation.js +28 -0
- package/src/presentation/project-presentation.d.ts +7 -0
- package/src/presentation/project-presentation.js +19 -0
- package/src/presentation/relation-presentation.d.ts +7 -0
- package/src/presentation/relation-presentation.js +73 -0
- package/src/presentation/task-presentation.d.ts +3 -3
- package/src/presentation/task-presentation.js +22 -18
- package/src/project.d.ts +14 -5
- package/src/project.js +18 -6
- package/src/result-schemas.d.ts +230 -23
- package/src/result-schemas.js +62 -3
- package/src/results.d.ts +34 -17
- package/src/results.js +19 -0
- package/src/routes/activity-router.d.ts +34 -1
- package/src/routes/activity-router.js +104 -31
- package/src/routes/aliases.d.ts +2 -0
- package/src/routes/aliases.js +11 -0
- package/src/routes/capabilities-router.js +9 -3
- package/src/routes/comment-router.d.ts +41 -18
- package/src/routes/comment-router.js +65 -48
- package/src/routes/label-router.d.ts +57 -7
- package/src/routes/label-router.js +84 -39
- package/src/routes/project-router.d.ts +34 -12
- package/src/routes/project-router.js +59 -55
- package/src/routes/relation-router.d.ts +6 -6
- package/src/routes/relation-router.js +52 -69
- package/src/routes/restore-router.js +1 -1
- package/src/routes/router.d.ts +1 -1
- package/src/routes/router.js +38 -9
- package/src/routes/routes.d.ts +253 -45
- package/src/routes/routes.js +4 -0
- package/src/routes/task-router.d.ts +107 -26
- package/src/routes/task-router.js +151 -143
- package/src/routes/whoami-router.d.ts +21 -0
- package/src/routes/whoami-router.js +31 -0
- package/src/text-edit.d.ts +13 -9
- package/src/text-edit.js +23 -18
- package/src/text-input.d.ts +47 -0
- package/src/text-input.js +187 -0
- package/src/types.d.ts +32 -9
- package/src/types.js +9 -1
package/src/input.d.ts
CHANGED
|
@@ -1,46 +1,156 @@
|
|
|
1
|
-
import
|
|
2
|
-
export
|
|
3
|
-
kind:
|
|
4
|
-
name
|
|
5
|
-
choices
|
|
6
|
-
caseInsensitive
|
|
7
|
-
pattern
|
|
8
|
-
description
|
|
9
|
-
}
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const inputValueSchema: z.ZodObject<{
|
|
3
|
+
kind: z.ZodString;
|
|
4
|
+
name: z.ZodOptional<z.ZodString>;
|
|
5
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
6
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
7
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
8
|
+
description: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, z.core.$strict>;
|
|
10
|
+
export declare const inputOptionSchema: z.ZodObject<{
|
|
11
|
+
type: z.ZodEnum<{
|
|
12
|
+
string: "string";
|
|
13
|
+
boolean: "boolean";
|
|
14
|
+
}>;
|
|
15
|
+
short: z.ZodOptional<z.ZodString>;
|
|
16
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
17
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodArray<z.ZodBoolean>]>>;
|
|
18
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
+
value: z.ZodOptional<z.ZodObject<{
|
|
20
|
+
kind: z.ZodString;
|
|
21
|
+
name: z.ZodOptional<z.ZodString>;
|
|
22
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
23
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
24
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
25
|
+
description: z.ZodOptional<z.ZodString>;
|
|
26
|
+
}, z.core.$strict>>;
|
|
27
|
+
description: z.ZodOptional<z.ZodString>;
|
|
28
|
+
}, z.core.$strict>;
|
|
29
|
+
export declare const inputOptionsSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
30
|
+
type: z.ZodEnum<{
|
|
31
|
+
string: "string";
|
|
32
|
+
boolean: "boolean";
|
|
33
|
+
}>;
|
|
34
|
+
short: z.ZodOptional<z.ZodString>;
|
|
35
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
36
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodArray<z.ZodBoolean>]>>;
|
|
37
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
38
|
+
value: z.ZodOptional<z.ZodObject<{
|
|
39
|
+
kind: z.ZodString;
|
|
40
|
+
name: z.ZodOptional<z.ZodString>;
|
|
41
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
42
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
43
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
44
|
+
description: z.ZodOptional<z.ZodString>;
|
|
45
|
+
}, z.core.$strict>>;
|
|
46
|
+
description: z.ZodOptional<z.ZodString>;
|
|
47
|
+
}, z.core.$strict>>;
|
|
48
|
+
declare const inputReferenceSchema: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
49
|
+
declare const inputConstraintSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
50
|
+
kind: z.ZodLiteral<"exclusive">;
|
|
51
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
|
|
52
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
53
|
+
kind: z.ZodLiteral<"requires">;
|
|
54
|
+
input: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
55
|
+
requires: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
56
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
57
|
+
kind: z.ZodLiteral<"requiresAny">;
|
|
58
|
+
input: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
59
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
|
|
60
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
61
|
+
kind: z.ZodLiteral<"atLeastOne">;
|
|
62
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
|
|
63
|
+
}, z.core.$strict>], "kind">;
|
|
64
|
+
declare const positionalInputSchema: z.ZodObject<{
|
|
65
|
+
name: z.ZodString;
|
|
66
|
+
min: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>]>;
|
|
67
|
+
max: z.ZodNullable<z.ZodLiteral<1>>;
|
|
68
|
+
value: z.ZodObject<{
|
|
69
|
+
kind: z.ZodString;
|
|
70
|
+
name: z.ZodOptional<z.ZodString>;
|
|
71
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
72
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
73
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
74
|
+
description: z.ZodOptional<z.ZodString>;
|
|
75
|
+
}, z.core.$strict>;
|
|
76
|
+
}, z.core.$strict>;
|
|
77
|
+
declare const inputFormSchema: z.ZodObject<{
|
|
78
|
+
id: z.ZodString;
|
|
79
|
+
positionals: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
80
|
+
name: z.ZodString;
|
|
81
|
+
min: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>]>;
|
|
82
|
+
max: z.ZodNullable<z.ZodLiteral<1>>;
|
|
83
|
+
value: z.ZodObject<{
|
|
84
|
+
kind: z.ZodString;
|
|
85
|
+
name: z.ZodOptional<z.ZodString>;
|
|
86
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
87
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
88
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
89
|
+
description: z.ZodOptional<z.ZodString>;
|
|
90
|
+
}, z.core.$strict>;
|
|
91
|
+
}, z.core.$strict>>>;
|
|
92
|
+
}, z.core.$strict>;
|
|
93
|
+
export declare const commandInputSchema: z.ZodObject<{
|
|
94
|
+
options: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
95
|
+
type: z.ZodEnum<{
|
|
96
|
+
string: "string";
|
|
97
|
+
boolean: "boolean";
|
|
98
|
+
}>;
|
|
99
|
+
short: z.ZodOptional<z.ZodString>;
|
|
100
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
101
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodArray<z.ZodBoolean>]>>;
|
|
102
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
103
|
+
value: z.ZodOptional<z.ZodObject<{
|
|
104
|
+
kind: z.ZodString;
|
|
105
|
+
name: z.ZodOptional<z.ZodString>;
|
|
106
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
107
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
108
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
109
|
+
description: z.ZodOptional<z.ZodString>;
|
|
110
|
+
}, z.core.$strict>>;
|
|
111
|
+
description: z.ZodOptional<z.ZodString>;
|
|
112
|
+
}, z.core.$strict>>;
|
|
113
|
+
forms: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
114
|
+
id: z.ZodString;
|
|
115
|
+
positionals: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
116
|
+
name: z.ZodString;
|
|
117
|
+
min: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>]>;
|
|
118
|
+
max: z.ZodNullable<z.ZodLiteral<1>>;
|
|
119
|
+
value: z.ZodObject<{
|
|
120
|
+
kind: z.ZodString;
|
|
121
|
+
name: z.ZodOptional<z.ZodString>;
|
|
122
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
123
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
124
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
125
|
+
description: z.ZodOptional<z.ZodString>;
|
|
126
|
+
}, z.core.$strict>;
|
|
127
|
+
}, z.core.$strict>>>;
|
|
128
|
+
}, z.core.$strict>>>;
|
|
129
|
+
constraints: z.ZodReadonly<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
130
|
+
kind: z.ZodLiteral<"exclusive">;
|
|
131
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
|
|
132
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
133
|
+
kind: z.ZodLiteral<"requires">;
|
|
134
|
+
input: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
135
|
+
requires: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
136
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
137
|
+
kind: z.ZodLiteral<"requiresAny">;
|
|
138
|
+
input: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
139
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
|
|
140
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
141
|
+
kind: z.ZodLiteral<"atLeastOne">;
|
|
142
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
|
|
143
|
+
}, z.core.$strict>], "kind">>>;
|
|
144
|
+
notes: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
145
|
+
}, z.core.$strict>;
|
|
146
|
+
export type InputValue = z.infer<typeof inputValueSchema>;
|
|
147
|
+
export type InputOption = z.infer<typeof inputOptionSchema>;
|
|
148
|
+
export type InputOptions = z.infer<typeof inputOptionsSchema>;
|
|
149
|
+
export type PositionalInput = z.infer<typeof positionalInputSchema>;
|
|
150
|
+
export type InputForm = z.infer<typeof inputFormSchema>;
|
|
151
|
+
export type InputReference = z.infer<typeof inputReferenceSchema>;
|
|
152
|
+
export type InputConstraint = z.infer<typeof inputConstraintSchema>;
|
|
153
|
+
export type CommandInput = z.infer<typeof commandInputSchema>;
|
|
44
154
|
export declare const taskKeyPositional: {
|
|
45
155
|
readonly name: "task-key";
|
|
46
156
|
readonly min: 1;
|
|
@@ -114,3 +224,4 @@ export declare function getOptionInputs(values: Record<string, unknown>): Partia
|
|
|
114
224
|
export declare function generateInputUsage(input: CommandInput): string[];
|
|
115
225
|
export declare const usageLabel = "Usage: ";
|
|
116
226
|
export declare function generateCommandUsage(path: string, input: CommandInput): string;
|
|
227
|
+
export {};
|
package/src/input.js
CHANGED
|
@@ -1,3 +1,53 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const inputValueSchema = z.strictObject({
|
|
3
|
+
kind: z.string(),
|
|
4
|
+
name: z.string().optional(),
|
|
5
|
+
choices: z.array(z.string()).readonly().optional(),
|
|
6
|
+
caseInsensitive: z.boolean().optional(),
|
|
7
|
+
pattern: z.string().optional(),
|
|
8
|
+
description: z.string().optional(),
|
|
9
|
+
});
|
|
10
|
+
export const inputOptionSchema = z.strictObject({
|
|
11
|
+
type: z.enum(["string", "boolean"]),
|
|
12
|
+
short: z.string().optional(),
|
|
13
|
+
multiple: z.boolean().optional(),
|
|
14
|
+
default: z.union([z.string(), z.boolean(), z.array(z.string()), z.array(z.boolean())]).optional(),
|
|
15
|
+
required: z.boolean().optional(),
|
|
16
|
+
value: inputValueSchema.optional(),
|
|
17
|
+
description: z.string().optional(),
|
|
18
|
+
});
|
|
19
|
+
export const inputOptionsSchema = z.record(z.string(), inputOptionSchema);
|
|
20
|
+
const inputReferenceSchema = z.templateLiteral([
|
|
21
|
+
z.enum(["option:", "positional:"]),
|
|
22
|
+
z.string().min(1),
|
|
23
|
+
]);
|
|
24
|
+
const members = z.array(inputReferenceSchema).readonly();
|
|
25
|
+
const inputConstraintSchema = z.discriminatedUnion("kind", [
|
|
26
|
+
z.strictObject({ kind: z.literal("exclusive"), members }),
|
|
27
|
+
z.strictObject({
|
|
28
|
+
kind: z.literal("requires"),
|
|
29
|
+
input: inputReferenceSchema,
|
|
30
|
+
requires: inputReferenceSchema,
|
|
31
|
+
}),
|
|
32
|
+
z.strictObject({ kind: z.literal("requiresAny"), input: inputReferenceSchema, members }),
|
|
33
|
+
z.strictObject({ kind: z.literal("atLeastOne"), members }),
|
|
34
|
+
]);
|
|
35
|
+
const positionalInputSchema = z.strictObject({
|
|
36
|
+
name: z.string(),
|
|
37
|
+
min: z.union([z.literal(0), z.literal(1)]),
|
|
38
|
+
max: z.literal(1).nullable(),
|
|
39
|
+
value: inputValueSchema,
|
|
40
|
+
});
|
|
41
|
+
const inputFormSchema = z.strictObject({
|
|
42
|
+
id: z.string(),
|
|
43
|
+
positionals: z.array(positionalInputSchema).readonly(),
|
|
44
|
+
});
|
|
45
|
+
export const commandInputSchema = z.strictObject({
|
|
46
|
+
options: inputOptionsSchema,
|
|
47
|
+
forms: z.array(inputFormSchema).min(1).readonly(),
|
|
48
|
+
constraints: z.array(inputConstraintSchema).readonly(),
|
|
49
|
+
notes: z.array(z.string()).readonly().optional(),
|
|
50
|
+
});
|
|
1
51
|
export const taskKeyPositional = {
|
|
2
52
|
name: "task-key",
|
|
3
53
|
min: 1,
|
|
@@ -60,6 +110,8 @@ export function violatesConstraint(constraint, inputs) {
|
|
|
60
110
|
return constraint.members.filter(supplied).length > 1;
|
|
61
111
|
case "requires":
|
|
62
112
|
return supplied(constraint.input) && !supplied(constraint.requires);
|
|
113
|
+
case "requiresAny":
|
|
114
|
+
return supplied(constraint.input) && !constraint.members.some(supplied);
|
|
63
115
|
case "atLeastOne":
|
|
64
116
|
return !constraint.members.some(supplied);
|
|
65
117
|
}
|
|
@@ -71,30 +123,51 @@ export function getOptionInputs(values) {
|
|
|
71
123
|
export function generateInputUsage(input) {
|
|
72
124
|
const options = Object.entries(input.options).map(([name, option]) => {
|
|
73
125
|
const value = option.value;
|
|
74
|
-
const valueWord =
|
|
126
|
+
const valueWord = value?.name === undefined && value?.choices !== undefined
|
|
127
|
+
? `{${value.choices.join("|")}}`
|
|
128
|
+
: `<${value?.name ?? "text"}>`;
|
|
75
129
|
const flag = `--${name}${option.type === "string" ? ` ${valueWord}` : ""}`;
|
|
76
130
|
return {
|
|
77
131
|
reference: `option:${name}`,
|
|
78
132
|
word: `${option.required ? flag : `[${flag}]`}${option.multiple ? "..." : ""}`,
|
|
79
133
|
};
|
|
80
134
|
});
|
|
135
|
+
/**
|
|
136
|
+
* Exclusive inputs that also need one of them are a required choice: (a|b) instead of [a|b],
|
|
137
|
+
* like how it is in git's synopsis notation.
|
|
138
|
+
* {a|b} stays reserved for a choice of literal words.
|
|
139
|
+
*/
|
|
140
|
+
const isRequiredChoice = (members) => input.constraints.some((constraint) => constraint.kind === "atLeastOne" &&
|
|
141
|
+
constraint.members.length === members.length &&
|
|
142
|
+
constraint.members.every((member) => members.includes(member)));
|
|
143
|
+
const choice = (alternatives, isRequired) => isRequired ? `(${alternatives.join("|")})` : `[${alternatives.join("|")}]`;
|
|
81
144
|
return input.forms.map((form) => {
|
|
82
145
|
const words = new Map([
|
|
83
146
|
...form.positionals.map((positional, index) => [`positional:${positional.name}`, positionalWords(form)[index]]),
|
|
84
147
|
...options.map(({ reference, word }) => [reference, word]),
|
|
85
148
|
]);
|
|
86
|
-
// Text modifiers share one syntax group with the text they change
|
|
87
|
-
const textRequirement = input.constraints.find((constraint) => constraint.kind === "
|
|
88
|
-
if (textRequirement?.kind === "
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
149
|
+
// Text modifiers share one syntax group with the text sources they change
|
|
150
|
+
const textRequirement = input.constraints.find((constraint) => constraint.kind === "requiresAny" && constraint.input === "option:append");
|
|
151
|
+
if (textRequirement?.kind === "requiresAny") {
|
|
152
|
+
const sources = textRequirement.members;
|
|
153
|
+
const sourceSyntax = sources.map((reference) => {
|
|
154
|
+
const name = reference.slice("option:".length);
|
|
155
|
+
return `--${name} <${input.options[name].value?.name ?? "text"}>`;
|
|
156
|
+
});
|
|
157
|
+
const isRequired = isRequiredChoice(sources);
|
|
158
|
+
const source = sourceSyntax.length === 1 ? sourceSyntax[0] : choice(sourceSyntax, true);
|
|
93
159
|
const replacing = words.get("option:replacing").slice(1, -1);
|
|
94
|
-
const
|
|
95
|
-
words.set(
|
|
96
|
-
|
|
97
|
-
|
|
160
|
+
const group = `${source} [--append|${replacing} ${words.get("option:all")}]`;
|
|
161
|
+
words.set(sources[0], isRequired ? group : `[${group}]`);
|
|
162
|
+
// The words written inside the first source's group
|
|
163
|
+
const foldedReferences = [
|
|
164
|
+
...sources.slice(1),
|
|
165
|
+
"option:append",
|
|
166
|
+
"option:replacing",
|
|
167
|
+
"option:all",
|
|
168
|
+
];
|
|
169
|
+
for (const reference of foldedReferences) {
|
|
170
|
+
words.delete(reference);
|
|
98
171
|
}
|
|
99
172
|
}
|
|
100
173
|
for (const constraint of input.constraints) {
|
|
@@ -103,7 +176,7 @@ export function generateInputUsage(input) {
|
|
|
103
176
|
continue;
|
|
104
177
|
}
|
|
105
178
|
const alternatives = constraint.members.map((member) => words.get(member).slice(1, -1));
|
|
106
|
-
words.set(constraint.members[0],
|
|
179
|
+
words.set(constraint.members[0], choice(alternatives, isRequiredChoice(constraint.members)));
|
|
107
180
|
for (const member of constraint.members.slice(1)) {
|
|
108
181
|
words.delete(member);
|
|
109
182
|
}
|
package/src/lib.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ParseArgsOptionsConfig } from "node:util";
|
|
2
2
|
import type { InputForm, InputOptions, InputOption } from "./input.js";
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
3
4
|
import { CliError, type ErrorDetails } from "./errors.js";
|
|
4
5
|
type ParsedTokens = NonNullable<ReturnType<typeof parseArgs>["tokens"]>;
|
|
5
6
|
type OutputMode = "text" | "json";
|
|
6
7
|
export declare function setOutputMode(mode: OutputMode): void;
|
|
8
|
+
export declare function getOutputMode(): OutputMode;
|
|
7
9
|
/** Selects output before routing, without treating words after `--` as flags. */
|
|
8
10
|
export declare function prepareOutput(args: Array<string>): void;
|
|
9
11
|
/** Keeps JSON failures parseable while text-mode notices remain immediate. */
|
|
@@ -16,6 +18,10 @@ export declare function isRouterFlag(flag: string): boolean;
|
|
|
16
18
|
export declare function setLegacyReadAllowed(allowed: boolean): void;
|
|
17
19
|
export declare function isLegacyReadAllowed(): boolean;
|
|
18
20
|
export declare function output<T>(data: T, transformToString: (data: T) => string): void;
|
|
21
|
+
/** Includes change data in JSON and adds a stderr note for each unchanged object */
|
|
22
|
+
export declare function outputChanges<Change extends {
|
|
23
|
+
changed: boolean;
|
|
24
|
+
}, Presented extends object>(changes: Array<Change>, present: (change: Change) => Presented, formatEntries: (entries: Array<Presented>) => string, describeUnchanged: (entry: Presented) => string): void;
|
|
19
25
|
/** Asks before a change that cannot be undone, unless --yes already confirmed it. */
|
|
20
26
|
export declare function confirmAction(message: string, isPreconfirmed: boolean, jsonRefusal?: string): Promise<boolean>;
|
|
21
27
|
export declare const confirmationDescription = "Requires --yes with --json or without a terminal. Otherwise prompts on stderr and only y or Y confirms. Declining exits successfully without the requested mutation; interruption exits 130.";
|
|
@@ -40,8 +46,26 @@ export declare class UsageError extends CliError {
|
|
|
40
46
|
*/
|
|
41
47
|
export declare function validatePositionals(positionals: Array<string>, form: InputForm): void;
|
|
42
48
|
export declare function validateUniqueOptions(tokens: ParsedTokens, options: InputOptions): void;
|
|
49
|
+
/** The choices a positional accepts; positionals without choices contribute never. */
|
|
50
|
+
type PositionalChoices<Positional> = Positional extends {
|
|
51
|
+
value: {
|
|
52
|
+
choices: readonly (infer Choice)[];
|
|
53
|
+
};
|
|
54
|
+
} ? Choice : never;
|
|
55
|
+
/** The direction words a form's direction positional accepts. */
|
|
56
|
+
type OrderDirection<Form extends InputForm> = PositionalChoices<Extract<Form["positionals"][number], {
|
|
57
|
+
name: "direction";
|
|
58
|
+
}>>;
|
|
59
|
+
/**
|
|
60
|
+
* A selected form with the direction word and the positional index it was read from.
|
|
61
|
+
* Distributes over the form union, so each form keeps its own direction choices.
|
|
62
|
+
*/
|
|
63
|
+
type SelectedOrderForm<Form extends InputForm> = Form extends unknown ? Form & {
|
|
64
|
+
direction: OrderDirection<Form>;
|
|
65
|
+
directionIndex: number;
|
|
66
|
+
} : never;
|
|
43
67
|
/** Selects an order form after checking its required leading words. */
|
|
44
|
-
export declare function validateOrderForms<Form extends InputForm>(positionals: string[], forms: readonly Form[]): Form
|
|
68
|
+
export declare function validateOrderForms<Form extends InputForm>(positionals: string[], forms: readonly Form[]): SelectedOrderForm<Form>;
|
|
45
69
|
export declare function requireStringOption(option: InputOption & {
|
|
46
70
|
required: true;
|
|
47
71
|
}, value: string | undefined, name: string, message: string): string;
|
|
@@ -55,8 +79,12 @@ export declare function isHelpFlag(flag: string): boolean;
|
|
|
55
79
|
export declare function dashValueHelp(flag: string): string;
|
|
56
80
|
/** Quotes a word for a POSIX shell when it needs it, like Python's `shlex.quote` */
|
|
57
81
|
export declare function shellQuote(word: string): string;
|
|
82
|
+
/** A command line to show, with each word quoted for the shell as needed. */
|
|
83
|
+
export declare function formatCommand(args: Array<string>): string;
|
|
58
84
|
/** The words of the command a user likely meant by a flag the command does not take, if known. */
|
|
59
85
|
type SuggestFor = (flag: string) => Array<string> | undefined;
|
|
86
|
+
/** Renames an option without changing values or words after `--` */
|
|
87
|
+
export declare function renameFlag(args: Array<string>, options: ParseArgsOptionsConfig, source: string, target: string): string[];
|
|
60
88
|
/**
|
|
61
89
|
* The message for an argument error from parseArgs, rewritten where parseArgs' own advice misleads.
|
|
62
90
|
* parseArgs names the flag only in its message text, which Node and Bun word the same.
|
package/src/lib.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
1
2
|
import { createInterface } from "node:readline/promises";
|
|
2
|
-
import {
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { assertWritable, InputValidationError, ReadOnlyDatabaseError, TextEditMatchError, UnmarkedDatabaseError, } from "@zinn-dev/core";
|
|
3
5
|
import { CliError, classifyFailure } from "./errors.js";
|
|
4
6
|
import { helpSpellings, routerOptionNames, positionalWords } from "./input.js";
|
|
5
7
|
let outputMode = "text";
|
|
@@ -9,6 +11,9 @@ const DOUBLE_DASH = "--";
|
|
|
9
11
|
export function setOutputMode(mode) {
|
|
10
12
|
outputMode = mode;
|
|
11
13
|
}
|
|
14
|
+
export function getOutputMode() {
|
|
15
|
+
return outputMode;
|
|
16
|
+
}
|
|
12
17
|
/** Selects output before routing, without treating words after `--` as flags. */
|
|
13
18
|
export function prepareOutput(args) {
|
|
14
19
|
const separatorIndex = args.indexOf(DOUBLE_DASH);
|
|
@@ -55,6 +60,24 @@ export function output(data, transformToString) {
|
|
|
55
60
|
console.info(dataText);
|
|
56
61
|
}
|
|
57
62
|
}
|
|
63
|
+
/** Includes change data in JSON and adds a stderr note for each unchanged object */
|
|
64
|
+
export function outputChanges(changes, present, formatEntries, describeUnchanged) {
|
|
65
|
+
const presentedChanges = changes.map((change) => ({
|
|
66
|
+
...present(change),
|
|
67
|
+
changed: change.changed,
|
|
68
|
+
}));
|
|
69
|
+
if (presentedChanges.length === 1) {
|
|
70
|
+
output(presentedChanges[0], (entry) => formatEntries([entry]));
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
output(presentedChanges, formatEntries);
|
|
74
|
+
}
|
|
75
|
+
for (const entry of presentedChanges) {
|
|
76
|
+
if (!entry.changed) {
|
|
77
|
+
diagnostic(describeUnchanged(entry));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
58
81
|
/** Asks before a change that cannot be undone, unless --yes already confirmed it. */
|
|
59
82
|
export async function confirmAction(message, isPreconfirmed, jsonRefusal) {
|
|
60
83
|
// Throws on a read-only database, to avoid asking for confirmation to an already refused action
|
|
@@ -102,6 +125,9 @@ export function canPrompt() {
|
|
|
102
125
|
}
|
|
103
126
|
/** The message to report for a failed command, or fallback when the error has none. */
|
|
104
127
|
export function failureMessage(error, fallback) {
|
|
128
|
+
if (error instanceof z.ZodError) {
|
|
129
|
+
return new InputValidationError(error.issues).message;
|
|
130
|
+
}
|
|
105
131
|
const isOlderReadOnly = error instanceof ReadOnlyDatabaseError && error.reason === "older";
|
|
106
132
|
if (isOlderReadOnly) {
|
|
107
133
|
return `${error.message}. Run \`zinn migrate\` to upgrade it.`;
|
|
@@ -196,11 +222,16 @@ export function validateUniqueOptions(tokens, options) {
|
|
|
196
222
|
/** Selects an order form after checking its required leading words. */
|
|
197
223
|
export function validateOrderForms(positionals, forms) {
|
|
198
224
|
const firstForm = forms[0];
|
|
199
|
-
const
|
|
200
|
-
const leadingPositionals = firstForm.positionals.slice(0,
|
|
201
|
-
const directions = forms.flatMap((form) => form.positionals[
|
|
202
|
-
|
|
203
|
-
|
|
225
|
+
const directionPosition = firstForm.positionals.findIndex(({ name }) => name === "direction");
|
|
226
|
+
const leadingPositionals = firstForm.positionals.slice(0, directionPosition + 1);
|
|
227
|
+
const directions = forms.flatMap((form) => form.positionals[directionPosition].value.choices);
|
|
228
|
+
const hasRepeatingSources = leadingPositionals.some((input) => input.max === null);
|
|
229
|
+
const recognizedDirectionIndex = positionals.findIndex((word, index) => index >= directionPosition && directions.includes(word));
|
|
230
|
+
const directionIndex = hasRepeatingSources && recognizedDirectionIndex !== -1
|
|
231
|
+
? recognizedDirectionIndex
|
|
232
|
+
: directionPosition;
|
|
233
|
+
leadingPositionals[directionPosition] = {
|
|
234
|
+
...leadingPositionals[directionPosition],
|
|
204
235
|
value: { kind: "enum", choices: directions },
|
|
205
236
|
};
|
|
206
237
|
validatePositionals(positionals.slice(0, leadingPositionals.length), {
|
|
@@ -208,12 +239,17 @@ export function validateOrderForms(positionals, forms) {
|
|
|
208
239
|
positionals: leadingPositionals,
|
|
209
240
|
});
|
|
210
241
|
const direction = positionals[directionIndex];
|
|
211
|
-
const form = forms.find((candidate) => candidate.positionals[
|
|
242
|
+
const form = forms.find((candidate) => candidate.positionals[directionPosition].value.choices.includes(direction));
|
|
212
243
|
if (form === undefined) {
|
|
213
244
|
throw new UsageError(`Unknown order direction "${direction}"`, { argument: "direction" });
|
|
214
245
|
}
|
|
215
|
-
|
|
216
|
-
|
|
246
|
+
const sourceCount = directionIndex - directionPosition + 1;
|
|
247
|
+
const expandedPositionals = form.positionals.flatMap((input) => input.max === null
|
|
248
|
+
? Array.from({ length: sourceCount }, () => ({ ...input, max: 1 }))
|
|
249
|
+
: [input]);
|
|
250
|
+
validatePositionals(positionals, { ...form, positionals: expandedPositionals });
|
|
251
|
+
// The direction is one of the matched form's choices, checked above.
|
|
252
|
+
return { ...form, direction, directionIndex };
|
|
217
253
|
}
|
|
218
254
|
export function requireStringOption(option, value, name, message) {
|
|
219
255
|
if (value === undefined) {
|
|
@@ -270,9 +306,26 @@ const UNKNOWN_LONG_OPTION_PATTERN = /^Unknown option '(--[^']+)'/;
|
|
|
270
306
|
// A word that begins with a single dash, such as -later.
|
|
271
307
|
const SHORT_OPTION_WORD_PATTERN = /^-[^-]/;
|
|
272
308
|
/** A command line to show, with each word quoted for the shell as needed. */
|
|
273
|
-
function formatCommand(args) {
|
|
309
|
+
export function formatCommand(args) {
|
|
274
310
|
return ["zinn", ...args].map(shellQuote).join(" ");
|
|
275
311
|
}
|
|
312
|
+
/** Renames an option without changing values or words after `--` */
|
|
313
|
+
export function renameFlag(args, options, source, target) {
|
|
314
|
+
const { tokens } = parseArgs({
|
|
315
|
+
args,
|
|
316
|
+
options,
|
|
317
|
+
allowPositionals: true,
|
|
318
|
+
strict: false,
|
|
319
|
+
tokens: true,
|
|
320
|
+
});
|
|
321
|
+
const renamed = [...args];
|
|
322
|
+
for (const token of tokens) {
|
|
323
|
+
if (token.kind === "option" && token.name === source) {
|
|
324
|
+
renamed[token.index] = `--${target}${token.inlineValue ? `=${token.value}` : ""}`;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return renamed;
|
|
328
|
+
}
|
|
276
329
|
/**
|
|
277
330
|
* The message for `parseArgs` refusal of an unknown option.
|
|
278
331
|
* A long flag is named, with the command the user likely meant when one is known,
|
|
@@ -284,9 +337,17 @@ function unknownOptionMessage(message, args, suggestFor) {
|
|
|
284
337
|
if (flag !== undefined) {
|
|
285
338
|
const suggestion = suggestFor(flag);
|
|
286
339
|
const reason = `Unknown option "${flag}"`;
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
340
|
+
if (suggestion === undefined) {
|
|
341
|
+
return reason;
|
|
342
|
+
}
|
|
343
|
+
const separatorIndex = suggestion.indexOf(DOUBLE_DASH);
|
|
344
|
+
const optionEnd = separatorIndex === -1 ? suggestion.length : separatorIndex;
|
|
345
|
+
const correctedArgs = [
|
|
346
|
+
...suggestion.slice(0, optionEnd),
|
|
347
|
+
...args.filter(isRouterFlag),
|
|
348
|
+
...suggestion.slice(optionEnd),
|
|
349
|
+
];
|
|
350
|
+
return `${reason}. Did you mean: ${formatCommand(correctedArgs)}`;
|
|
290
351
|
}
|
|
291
352
|
// Commands define no short options, so `parseArgs` refused the first single-dash word before `--`.
|
|
292
353
|
const separatorIndex = args.indexOf(DOUBLE_DASH);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type { Activity, ActivityTaskIdentity } from "@zinn-dev/core";
|
|
1
|
+
import type { Activity, ActivityTaskIdentity, Actor } from "@zinn-dev/core";
|
|
2
|
+
import type { PresentedActor } from "../result-schemas.js";
|
|
2
3
|
type NavigationIdentity = {
|
|
3
4
|
/** Undefined when the entity no longer exists and this event recorded no name for it. */
|
|
4
5
|
name?: string;
|
|
5
6
|
status: "current" | "archived" | "deleted";
|
|
6
7
|
distinguishesTaskId?: boolean;
|
|
8
|
+
showsStatus?: boolean;
|
|
7
9
|
};
|
|
8
10
|
export type PresentedActivity = {
|
|
9
11
|
event: Activity;
|
|
@@ -14,9 +16,15 @@ export type PresentedActivity = {
|
|
|
14
16
|
/** Neighbors in sorted UUID order determine the shortest globally unique left prefix. */
|
|
15
17
|
export declare function abbreviateActivityIds(ids: Array<string>): Map<string, string>;
|
|
16
18
|
export declare function presentActivities(events: Array<Activity>, options?: {
|
|
19
|
+
projectKey?: string;
|
|
20
|
+
projectId?: string;
|
|
21
|
+
showDeleted?: boolean;
|
|
17
22
|
taskKey?: string;
|
|
23
|
+
taskId?: string;
|
|
18
24
|
showsFullIds?: boolean;
|
|
19
25
|
}): Array<PresentedActivity>;
|
|
26
|
+
export declare function presentActor(actor: Actor): PresentedActor;
|
|
27
|
+
export declare function formatActor(actor: PresentedActor): string;
|
|
20
28
|
export declare function formatActivityList(entries: Array<PresentedActivity>, options?: {
|
|
21
29
|
showsDetails?: boolean;
|
|
22
30
|
}): string;
|