@zinn-dev/cli 0.41.0 → 0.43.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 +4 -4
- package/skills/zinn/SKILL.md +1 -1
- package/src/capabilities-schema.d.ts +25 -26
- 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.d.ts +31 -3
- package/src/errors.js +77 -20
- package/src/input.d.ts +154 -43
- package/src/input.js +86 -13
- package/src/lib.d.ts +43 -6
- package/src/lib.js +134 -38
- package/src/list-continuation.d.ts +11 -0
- package/src/list-continuation.js +18 -0
- package/src/list-limit.d.ts +11 -0
- package/src/list-limit.js +17 -0
- package/src/presentation/activity-presentation.d.ts +9 -1
- package/src/presentation/activity-presentation.js +124 -28
- 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 +4 -0
- package/src/presentation/description-presentation.js +28 -5
- package/src/presentation/label-presentation.d.ts +8 -0
- package/src/presentation/label-presentation.js +28 -0
- package/src/presentation/project-presentation.d.ts +11 -0
- package/src/presentation/project-presentation.js +27 -0
- package/src/presentation/relation-presentation.d.ts +12 -0
- package/src/presentation/relation-presentation.js +87 -0
- package/src/presentation/row-layout.d.ts +1 -1
- package/src/presentation/row-layout.js +6 -5
- package/src/presentation/task-presentation.d.ts +3 -3
- package/src/presentation/task-presentation.js +29 -19
- package/src/presentation/text-width.d.ts +2 -0
- package/src/presentation/text-width.js +43 -0
- package/src/presentation/time.d.ts +3 -1
- package/src/presentation/time.js +5 -2
- package/src/project.d.ts +14 -5
- package/src/project.js +18 -6
- package/src/result-schemas.d.ts +279 -26
- package/src/result-schemas.js +72 -4
- package/src/results.d.ts +34 -17
- package/src/results.js +19 -0
- package/src/routes/activity-router.d.ts +79 -2
- package/src/routes/activity-router.js +209 -38
- 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 +74 -12
- package/src/routes/project-router.js +131 -66
- package/src/routes/relation-router.d.ts +13 -9
- package/src/routes/relation-router.js +116 -116
- package/src/routes/restore-router.js +3 -6
- package/src/routes/router.d.ts +1 -1
- package/src/routes/router.js +88 -32
- package/src/routes/routes.d.ts +420 -50
- package/src/routes/routes.js +4 -0
- package/src/routes/task-router.d.ts +189 -30
- package/src/routes/task-router.js +254 -158
- 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/timestamp-input.d.ts +3 -0
- package/src/timestamp-input.js +31 -0
- package/src/types.d.ts +32 -9
- package/src/types.js +9 -1
package/src/lib.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ParseArgsOptionsConfig } from "node:util";
|
|
2
2
|
import type { InputForm, InputOptions, InputOption } from "./input.js";
|
|
3
|
-
import {
|
|
3
|
+
import type { ErrorDetails } from "./errors.js";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
import { CliError } from "./errors.js";
|
|
4
6
|
type ParsedTokens = NonNullable<ReturnType<typeof parseArgs>["tokens"]>;
|
|
5
7
|
type OutputMode = "text" | "json";
|
|
8
|
+
/** Keeps recovery guidance outside the shortened reason and never clips a repair command. */
|
|
9
|
+
export declare function boundParserMessage(message: string, options?: {
|
|
10
|
+
reason?: string;
|
|
11
|
+
guidance?: string;
|
|
12
|
+
}): string;
|
|
6
13
|
export declare function setOutputMode(mode: OutputMode): void;
|
|
14
|
+
export declare function getOutputMode(): OutputMode;
|
|
7
15
|
/** Selects output before routing, without treating words after `--` as flags. */
|
|
8
16
|
export declare function prepareOutput(args: Array<string>): void;
|
|
9
17
|
/** Keeps JSON failures parseable while text-mode notices remain immediate. */
|
|
@@ -16,6 +24,10 @@ export declare function isRouterFlag(flag: string): boolean;
|
|
|
16
24
|
export declare function setLegacyReadAllowed(allowed: boolean): void;
|
|
17
25
|
export declare function isLegacyReadAllowed(): boolean;
|
|
18
26
|
export declare function output<T>(data: T, transformToString: (data: T) => string): void;
|
|
27
|
+
/** Includes change data in JSON and adds a stderr note for each unchanged object */
|
|
28
|
+
export declare function outputChanges<Change extends {
|
|
29
|
+
changed: boolean;
|
|
30
|
+
}, Presented extends object>(changes: Array<Change>, present: (change: Change) => Presented, formatEntries: (entries: Array<Presented>) => string, describeUnchanged: (entry: Presented) => string): void;
|
|
19
31
|
/** Asks before a change that cannot be undone, unless --yes already confirmed it. */
|
|
20
32
|
export declare function confirmAction(message: string, isPreconfirmed: boolean, jsonRefusal?: string): Promise<boolean>;
|
|
21
33
|
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 +52,26 @@ export declare class UsageError extends CliError {
|
|
|
40
52
|
*/
|
|
41
53
|
export declare function validatePositionals(positionals: Array<string>, form: InputForm): void;
|
|
42
54
|
export declare function validateUniqueOptions(tokens: ParsedTokens, options: InputOptions): void;
|
|
55
|
+
/** The choices a positional accepts; positionals without choices contribute never. */
|
|
56
|
+
type PositionalChoices<Positional> = Positional extends {
|
|
57
|
+
value: {
|
|
58
|
+
choices: readonly (infer Choice)[];
|
|
59
|
+
};
|
|
60
|
+
} ? Choice : never;
|
|
61
|
+
/** The direction words a form's direction positional accepts. */
|
|
62
|
+
type OrderDirection<Form extends InputForm> = PositionalChoices<Extract<Form["positionals"][number], {
|
|
63
|
+
name: "direction";
|
|
64
|
+
}>>;
|
|
65
|
+
/**
|
|
66
|
+
* A selected form with the direction word and the positional index it was read from.
|
|
67
|
+
* Distributes over the form union, so each form keeps its own direction choices.
|
|
68
|
+
*/
|
|
69
|
+
type SelectedOrderForm<Form extends InputForm> = Form extends unknown ? Form & {
|
|
70
|
+
direction: OrderDirection<Form>;
|
|
71
|
+
directionIndex: number;
|
|
72
|
+
} : never;
|
|
43
73
|
/** Selects an order form after checking its required leading words. */
|
|
44
|
-
export declare function validateOrderForms<Form extends InputForm>(positionals: string
|
|
74
|
+
export declare function validateOrderForms<Form extends InputForm>(positionals: Array<string>, forms: readonly Form[]): SelectedOrderForm<Form>;
|
|
45
75
|
export declare function requireStringOption(option: InputOption & {
|
|
46
76
|
required: true;
|
|
47
77
|
}, value: string | undefined, name: string, message: string): string;
|
|
@@ -55,12 +85,19 @@ export declare function isHelpFlag(flag: string): boolean;
|
|
|
55
85
|
export declare function dashValueHelp(flag: string): string;
|
|
56
86
|
/** Quotes a word for a POSIX shell when it needs it, like Python's `shlex.quote` */
|
|
57
87
|
export declare function shellQuote(word: string): string;
|
|
88
|
+
/** A command line to show, with each word quoted for the shell as needed. */
|
|
89
|
+
export declare function formatCommand(args: Array<string>): string;
|
|
58
90
|
/** The words of the command a user likely meant by a flag the command does not take, if known. */
|
|
59
|
-
type SuggestFor = (flag: string) =>
|
|
91
|
+
type SuggestFor = (flag: string) => {
|
|
92
|
+
args: Array<string>;
|
|
93
|
+
route: Array<string>;
|
|
94
|
+
} | undefined;
|
|
95
|
+
/** Renames an option without changing values or words after `--` */
|
|
96
|
+
export declare function renameFlag(args: Array<string>, options: ParseArgsOptionsConfig, source: string, target: string): string[];
|
|
60
97
|
/**
|
|
61
|
-
*
|
|
98
|
+
* An argument failure from parseArgs, rewritten where parseArgs' own advice misleads.
|
|
62
99
|
* parseArgs names the flag only in its message text, which Node and Bun word the same.
|
|
63
100
|
* `null` for any other error.
|
|
64
101
|
*/
|
|
65
|
-
export declare function
|
|
102
|
+
export declare function parseArgsFailure(error: any, args: Array<string>, suggestFor: SuggestFor, route: Array<string>): CliError | null;
|
|
66
103
|
export {};
|
package/src/lib.js
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
1
2
|
import { createInterface } from "node:readline/promises";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { assertWritable, InputValidationError } from "@zinn-dev/core";
|
|
5
|
+
import { CliError, classifyFailure, recoveryHint } from "./errors.js";
|
|
4
6
|
import { helpSpellings, routerOptionNames, positionalWords } from "./input.js";
|
|
7
|
+
import { formatParserReasonPreview } from "./presentation/description-presentation.js";
|
|
5
8
|
let outputMode = "text";
|
|
6
9
|
let legacyReadAllowed = false;
|
|
7
10
|
const diagnostics = [];
|
|
8
11
|
const DOUBLE_DASH = "--";
|
|
12
|
+
const MAX_PARSER_MESSAGE_LENGTH = 1024;
|
|
13
|
+
/** Keeps recovery guidance outside the shortened reason and never clips a repair command. */
|
|
14
|
+
export function boundParserMessage(message, options = {}) {
|
|
15
|
+
if (message.length <= MAX_PARSER_MESSAGE_LENGTH) {
|
|
16
|
+
return message;
|
|
17
|
+
}
|
|
18
|
+
const guidance = options.guidance ?? "See usage for accepted arguments.";
|
|
19
|
+
const reason = formatParserReasonPreview(options.reason ?? message, MAX_PARSER_MESSAGE_LENGTH - guidance.length - 1);
|
|
20
|
+
return `${reason} ${guidance}`;
|
|
21
|
+
}
|
|
9
22
|
export function setOutputMode(mode) {
|
|
10
23
|
outputMode = mode;
|
|
11
24
|
}
|
|
25
|
+
export function getOutputMode() {
|
|
26
|
+
return outputMode;
|
|
27
|
+
}
|
|
12
28
|
/** Selects output before routing, without treating words after `--` as flags. */
|
|
13
29
|
export function prepareOutput(args) {
|
|
14
30
|
const separatorIndex = args.indexOf(DOUBLE_DASH);
|
|
@@ -55,6 +71,24 @@ export function output(data, transformToString) {
|
|
|
55
71
|
console.info(dataText);
|
|
56
72
|
}
|
|
57
73
|
}
|
|
74
|
+
/** Includes change data in JSON and adds a stderr note for each unchanged object */
|
|
75
|
+
export function outputChanges(changes, present, formatEntries, describeUnchanged) {
|
|
76
|
+
const presentedChanges = changes.map((change) => ({
|
|
77
|
+
...present(change),
|
|
78
|
+
changed: change.changed,
|
|
79
|
+
}));
|
|
80
|
+
if (presentedChanges.length === 1) {
|
|
81
|
+
output(presentedChanges[0], (entry) => formatEntries([entry]));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
output(presentedChanges, formatEntries);
|
|
85
|
+
}
|
|
86
|
+
for (const entry of presentedChanges) {
|
|
87
|
+
if (!entry.changed) {
|
|
88
|
+
diagnostic(describeUnchanged(entry));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
58
92
|
/** Asks before a change that cannot be undone, unless --yes already confirmed it. */
|
|
59
93
|
export async function confirmAction(message, isPreconfirmed, jsonRefusal) {
|
|
60
94
|
// Throws on a read-only database, to avoid asking for confirmation to an already refused action
|
|
@@ -102,18 +136,12 @@ export function canPrompt() {
|
|
|
102
136
|
}
|
|
103
137
|
/** The message to report for a failed command, or fallback when the error has none. */
|
|
104
138
|
export function failureMessage(error, fallback) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return `${error.message}. Run \`zinn migrate\` to upgrade it.`;
|
|
108
|
-
}
|
|
109
|
-
if (error instanceof UnmarkedDatabaseError) {
|
|
110
|
-
return `${error.message}. Add --allow-legacy-read to read it anyway.`;
|
|
111
|
-
}
|
|
112
|
-
if (error instanceof TextEditMatchError && error.matchCount > 1) {
|
|
113
|
-
return `${error.message} Use --all to replace every match.`;
|
|
139
|
+
if (error instanceof z.ZodError) {
|
|
140
|
+
return new InputValidationError(error.issues).message;
|
|
114
141
|
}
|
|
115
|
-
|
|
116
|
-
|
|
142
|
+
const hint = recoveryHint(error);
|
|
143
|
+
if (hint !== undefined) {
|
|
144
|
+
return `${error.message}${hint.suffix}`;
|
|
117
145
|
}
|
|
118
146
|
return typeof error?.message === "string" ? error.message : fallback;
|
|
119
147
|
}
|
|
@@ -126,8 +154,11 @@ export function quit(reason, help, details) {
|
|
|
126
154
|
}
|
|
127
155
|
/** Emits one handled failure, including any notices collected before it. */
|
|
128
156
|
export function renderFailure(reason) {
|
|
157
|
+
const classified = classifyFailure(reason);
|
|
129
158
|
const failure = {
|
|
130
|
-
|
|
159
|
+
code: classified.code,
|
|
160
|
+
details: classified.details,
|
|
161
|
+
help: classified.help,
|
|
131
162
|
message: failureMessage(reason, "Something went wrong"),
|
|
132
163
|
};
|
|
133
164
|
const pendingDiagnostics = diagnostics.splice(0);
|
|
@@ -154,7 +185,7 @@ export function renderFailure(reason) {
|
|
|
154
185
|
/** A command was given the wrong words. The router prints the message with the command's usage lines. */
|
|
155
186
|
export class UsageError extends CliError {
|
|
156
187
|
constructor(message, details) {
|
|
157
|
-
super(message, "invalid_input", details);
|
|
188
|
+
super(boundParserMessage(message), "invalid_input", details);
|
|
158
189
|
}
|
|
159
190
|
}
|
|
160
191
|
/**
|
|
@@ -168,13 +199,17 @@ export function validatePositionals(positionals, form) {
|
|
|
168
199
|
const missingWord = requiredWords[positionals.length];
|
|
169
200
|
if (missingWord !== undefined) {
|
|
170
201
|
throw new UsageError(`Missing argument ${missingWord}`, {
|
|
202
|
+
reason: "missing_argument",
|
|
171
203
|
argument: missingWord.replaceAll(/[\[\]<>]/g, "").replace(/\.\.\.$/, ""),
|
|
172
204
|
});
|
|
173
205
|
}
|
|
174
206
|
const hasRepeatingWord = words.some((word) => word.endsWith("..."));
|
|
175
207
|
const extraWord = positionals[words.length];
|
|
176
208
|
if (!hasRepeatingWord && extraWord !== undefined) {
|
|
177
|
-
throw new UsageError(`Unexpected argument "${extraWord}"`, {
|
|
209
|
+
throw new UsageError(`Unexpected argument "${extraWord}"`, {
|
|
210
|
+
field: [],
|
|
211
|
+
reason: "unexpected_argument",
|
|
212
|
+
});
|
|
178
213
|
}
|
|
179
214
|
}
|
|
180
215
|
export function validateUniqueOptions(tokens, options) {
|
|
@@ -196,11 +231,16 @@ export function validateUniqueOptions(tokens, options) {
|
|
|
196
231
|
/** Selects an order form after checking its required leading words. */
|
|
197
232
|
export function validateOrderForms(positionals, forms) {
|
|
198
233
|
const firstForm = forms[0];
|
|
199
|
-
const
|
|
200
|
-
const leadingPositionals = firstForm.positionals.slice(0,
|
|
201
|
-
const directions = forms.flatMap((form) => form.positionals[
|
|
202
|
-
|
|
203
|
-
|
|
234
|
+
const directionPosition = firstForm.positionals.findIndex(({ name }) => name === "direction");
|
|
235
|
+
const leadingPositionals = firstForm.positionals.slice(0, directionPosition + 1);
|
|
236
|
+
const directions = forms.flatMap((form) => form.positionals[directionPosition].value.choices);
|
|
237
|
+
const hasRepeatingSources = leadingPositionals.some((input) => input.max === null);
|
|
238
|
+
const recognizedDirectionIndex = positionals.findIndex((word, index) => index >= directionPosition && directions.includes(word));
|
|
239
|
+
const directionIndex = hasRepeatingSources && recognizedDirectionIndex !== -1
|
|
240
|
+
? recognizedDirectionIndex
|
|
241
|
+
: directionPosition;
|
|
242
|
+
leadingPositionals[directionPosition] = {
|
|
243
|
+
...leadingPositionals[directionPosition],
|
|
204
244
|
value: { kind: "enum", choices: directions },
|
|
205
245
|
};
|
|
206
246
|
validatePositionals(positionals.slice(0, leadingPositionals.length), {
|
|
@@ -208,16 +248,21 @@ export function validateOrderForms(positionals, forms) {
|
|
|
208
248
|
positionals: leadingPositionals,
|
|
209
249
|
});
|
|
210
250
|
const direction = positionals[directionIndex];
|
|
211
|
-
const form = forms.find((candidate) => candidate.positionals[
|
|
251
|
+
const form = forms.find((candidate) => candidate.positionals[directionPosition].value.choices.includes(direction));
|
|
212
252
|
if (form === undefined) {
|
|
213
253
|
throw new UsageError(`Unknown order direction "${direction}"`, { argument: "direction" });
|
|
214
254
|
}
|
|
215
|
-
|
|
216
|
-
|
|
255
|
+
const sourceCount = directionIndex - directionPosition + 1;
|
|
256
|
+
const expandedPositionals = form.positionals.flatMap((input) => input.max === null
|
|
257
|
+
? Array.from({ length: sourceCount }, () => ({ ...input, max: 1 }))
|
|
258
|
+
: [input]);
|
|
259
|
+
validatePositionals(positionals, { ...form, positionals: expandedPositionals });
|
|
260
|
+
// The direction is one of the matched form's choices, checked above.
|
|
261
|
+
return { ...form, direction, directionIndex };
|
|
217
262
|
}
|
|
218
263
|
export function requireStringOption(option, value, name, message) {
|
|
219
264
|
if (value === undefined) {
|
|
220
|
-
quit(message, undefined, { argument: `--${name}
|
|
265
|
+
quit(message, undefined, { argument: `--${name}`, reason: "missing_argument" });
|
|
221
266
|
}
|
|
222
267
|
return value;
|
|
223
268
|
}
|
|
@@ -263,48 +308,91 @@ function dashValueMessage(error, args) {
|
|
|
263
308
|
`${flag}=${shellQuote(value)}`,
|
|
264
309
|
...args.slice(flagIndex + 2).map(shellQuote),
|
|
265
310
|
].join(" ");
|
|
266
|
-
|
|
311
|
+
const reason = `Option "${flag}" is followed by "${value}", which begins with a dash.`;
|
|
312
|
+
return boundParserMessage(`${reason} If it is the value, join it to the flag with =: ${fixedCommand}`, {
|
|
313
|
+
reason,
|
|
314
|
+
guidance: "Join the original value to its flag with =. Full command omitted because it is long.",
|
|
315
|
+
});
|
|
267
316
|
}
|
|
268
317
|
// "Unknown option '--project'."
|
|
269
318
|
const UNKNOWN_LONG_OPTION_PATTERN = /^Unknown option '(--[^']+)'/;
|
|
270
319
|
// A word that begins with a single dash, such as -later.
|
|
271
320
|
const SHORT_OPTION_WORD_PATTERN = /^-[^-]/;
|
|
272
321
|
/** A command line to show, with each word quoted for the shell as needed. */
|
|
273
|
-
function formatCommand(args) {
|
|
322
|
+
export function formatCommand(args) {
|
|
274
323
|
return ["zinn", ...args].map(shellQuote).join(" ");
|
|
275
324
|
}
|
|
325
|
+
/** Renames an option without changing values or words after `--` */
|
|
326
|
+
export function renameFlag(args, options, source, target) {
|
|
327
|
+
const { tokens } = parseArgs({
|
|
328
|
+
args,
|
|
329
|
+
options,
|
|
330
|
+
allowPositionals: true,
|
|
331
|
+
strict: false,
|
|
332
|
+
tokens: true,
|
|
333
|
+
});
|
|
334
|
+
const renamed = [...args];
|
|
335
|
+
for (const token of tokens) {
|
|
336
|
+
if (token.kind === "option" && token.name === source) {
|
|
337
|
+
renamed[token.index] = `--${target}${token.inlineValue ? `=${token.value}` : ""}`;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return renamed;
|
|
341
|
+
}
|
|
276
342
|
/**
|
|
277
343
|
* The message for `parseArgs` refusal of an unknown option.
|
|
278
344
|
* A long flag is named, with the command the user likely meant when one is known,
|
|
279
345
|
* and otherwise the usage line shown with it is the fix.
|
|
280
346
|
* A word with a single dash shows the user's command with it after `--`.
|
|
281
347
|
*/
|
|
282
|
-
function unknownOptionMessage(message, args, suggestFor) {
|
|
348
|
+
function unknownOptionMessage(message, args, suggestFor, route) {
|
|
283
349
|
const flag = UNKNOWN_LONG_OPTION_PATTERN.exec(message)?.[1];
|
|
284
350
|
if (flag !== undefined) {
|
|
285
351
|
const suggestion = suggestFor(flag);
|
|
286
352
|
const reason = `Unknown option "${flag}"`;
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
353
|
+
if (suggestion === undefined) {
|
|
354
|
+
return { message: boundParserMessage(reason) };
|
|
355
|
+
}
|
|
356
|
+
const separatorIndex = suggestion.args.indexOf(DOUBLE_DASH);
|
|
357
|
+
const optionEnd = separatorIndex === -1 ? suggestion.args.length : separatorIndex;
|
|
358
|
+
const correctedArgs = [
|
|
359
|
+
...suggestion.args.slice(0, optionEnd),
|
|
360
|
+
...args.filter(isRouterFlag),
|
|
361
|
+
...suggestion.args.slice(optionEnd),
|
|
362
|
+
];
|
|
363
|
+
return {
|
|
364
|
+
message: boundParserMessage(`${reason}. Did you mean: ${formatCommand(correctedArgs)}`, {
|
|
365
|
+
reason,
|
|
366
|
+
guidance: "See usage for accepted arguments. Full command omitted because it is long.",
|
|
367
|
+
}),
|
|
368
|
+
suggestedRoute: suggestion.route,
|
|
369
|
+
};
|
|
290
370
|
}
|
|
291
371
|
// Commands define no short options, so `parseArgs` refused the first single-dash word before `--`.
|
|
292
372
|
const separatorIndex = args.indexOf(DOUBLE_DASH);
|
|
293
373
|
const optionArgs = separatorIndex === -1 ? args : args.slice(0, separatorIndex);
|
|
294
374
|
const wordIndex = optionArgs.findIndex((arg) => SHORT_OPTION_WORD_PATTERN.test(arg));
|
|
295
375
|
if (wordIndex === -1) {
|
|
296
|
-
return message;
|
|
376
|
+
return { message: boundParserMessage(message) };
|
|
297
377
|
}
|
|
298
378
|
const word = args[wordIndex];
|
|
299
379
|
const readOptions = [...word.slice(1)].map((letter) => `-${letter}`);
|
|
300
380
|
const readAs = readOptions.length > 1 ? ` (Zinn read ${word} as ${readOptions.join(" ")})` : "";
|
|
301
381
|
const reason = `Unknown option "${readOptions[0]}"${readAs}. If it is a value, put it after --`;
|
|
382
|
+
const compactReason = `Unknown option in "${word}".`;
|
|
383
|
+
const guidance = "If it is a value, put the original word after --. Full command omitted because it is long.";
|
|
302
384
|
// Flags after the word must stay before --, and only the router's own flags are known to be flags.
|
|
303
385
|
const wordsAfter = args.slice(wordIndex + 1);
|
|
304
386
|
const routerFlagsAfter = wordsAfter.filter(isRouterFlag);
|
|
305
387
|
const plainWordsAfter = wordsAfter.filter((arg) => !isRouterFlag(arg));
|
|
306
388
|
if (plainWordsAfter.some((arg) => arg.startsWith("-"))) {
|
|
307
|
-
return
|
|
389
|
+
return {
|
|
390
|
+
message: boundParserMessage(`${reason}.`, {
|
|
391
|
+
reason: compactReason,
|
|
392
|
+
guidance: "If it is a value, put the original word after --.",
|
|
393
|
+
}),
|
|
394
|
+
suggestedRoute: route,
|
|
395
|
+
};
|
|
308
396
|
}
|
|
309
397
|
const fixedCommand = formatCommand([
|
|
310
398
|
...args.slice(0, wordIndex),
|
|
@@ -313,21 +401,29 @@ function unknownOptionMessage(message, args, suggestFor) {
|
|
|
313
401
|
word,
|
|
314
402
|
...plainWordsAfter,
|
|
315
403
|
]);
|
|
316
|
-
return
|
|
404
|
+
return {
|
|
405
|
+
message: boundParserMessage(`${reason}: ${fixedCommand}`, { reason: compactReason, guidance }),
|
|
406
|
+
suggestedRoute: route,
|
|
407
|
+
};
|
|
317
408
|
}
|
|
318
409
|
/**
|
|
319
|
-
*
|
|
410
|
+
* An argument failure from parseArgs, rewritten where parseArgs' own advice misleads.
|
|
320
411
|
* parseArgs names the flag only in its message text, which Node and Bun word the same.
|
|
321
412
|
* `null` for any other error.
|
|
322
413
|
*/
|
|
323
|
-
export function
|
|
414
|
+
export function parseArgsFailure(error, args, suggestFor, route) {
|
|
324
415
|
const code = error?.code;
|
|
325
416
|
const isParseArgsError = typeof code === "string" && code.startsWith("ERR_PARSE_ARGS_");
|
|
326
417
|
if (!isParseArgsError) {
|
|
327
418
|
return null;
|
|
328
419
|
}
|
|
420
|
+
const argument = /(?:Unknown option|Option) '(-[^' ]+)/.exec(error.message)?.[1];
|
|
329
421
|
if (code === "ERR_PARSE_ARGS_UNKNOWN_OPTION") {
|
|
330
|
-
|
|
422
|
+
const hint = unknownOptionMessage(error.message, args, suggestFor, route);
|
|
423
|
+
return new CliError(hint.message, "invalid_input", { argument, reason: "unknown_option" }, undefined, hint.suggestedRoute);
|
|
331
424
|
}
|
|
332
|
-
|
|
425
|
+
const dashMessage = dashValueMessage(error, args);
|
|
426
|
+
const isMissingValue = code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE" && / argument missing$/.test(error.message);
|
|
427
|
+
const reason = dashMessage !== null ? "dash_value" : isMissingValue ? "missing_argument" : undefined;
|
|
428
|
+
return new CliError(dashMessage ?? boundParserMessage(error.message), "invalid_input", { argument, reason }, undefined, dashMessage === null ? undefined : route);
|
|
333
429
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type ContinuationToken = {
|
|
2
|
+
kind: "option";
|
|
3
|
+
name: string;
|
|
4
|
+
rawName: string;
|
|
5
|
+
value: string | undefined;
|
|
6
|
+
} | {
|
|
7
|
+
kind: "positional" | "option-terminator";
|
|
8
|
+
};
|
|
9
|
+
/** Rebuilds a list command with its existing filters and the next cursor. */
|
|
10
|
+
export declare function formatListContinuation(command: Array<string>, positionals: Array<string>, tokens: Array<ContinuationToken>, cursorOption: string, cursorId: string): string;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { formatCommand, getOutputMode, isLegacyReadAllowed } from "./lib.js";
|
|
2
|
+
/** Rebuilds a list command with its existing filters and the next cursor. */
|
|
3
|
+
export function formatListContinuation(command, positionals, tokens, cursorOption, cursorId) {
|
|
4
|
+
const continuation = tokens.flatMap((token) => {
|
|
5
|
+
if (token.kind !== "option" || token.name === cursorOption) {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
8
|
+
return [token.value === undefined ? token.rawName : `${token.rawName}=${token.value}`];
|
|
9
|
+
});
|
|
10
|
+
if (getOutputMode() === "json") {
|
|
11
|
+
continuation.push("--json");
|
|
12
|
+
}
|
|
13
|
+
if (isLegacyReadAllowed()) {
|
|
14
|
+
continuation.push("--allow-legacy-read");
|
|
15
|
+
}
|
|
16
|
+
continuation.push(`--${cursorOption}`, cursorId);
|
|
17
|
+
return formatCommand([...command, ...positionals, ...continuation]);
|
|
18
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const listLimitDescription = "Return at most n results after all filters. Use an integer from 1 through 11871.";
|
|
2
|
+
export declare const listLimitOption: {
|
|
3
|
+
readonly type: "string";
|
|
4
|
+
readonly value: {
|
|
5
|
+
readonly kind: "positive-integer";
|
|
6
|
+
readonly name: "n";
|
|
7
|
+
readonly pattern: string;
|
|
8
|
+
};
|
|
9
|
+
readonly description: "Return at most n results after all filters. Use an integer from 1 through 11871.";
|
|
10
|
+
};
|
|
11
|
+
export declare function parseListLimit(value: string | undefined): number | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MAX_LIST_LIMIT, listLimitMessage, listLimitPattern } from "@zinn-dev/core";
|
|
2
|
+
import { quit } from "./lib.js";
|
|
3
|
+
export const listLimitDescription = `Return at most n results after all filters. Use an integer from 1 through ${MAX_LIST_LIMIT}.`;
|
|
4
|
+
export const listLimitOption = {
|
|
5
|
+
type: "string",
|
|
6
|
+
value: { kind: "positive-integer", name: "n", pattern: listLimitPattern },
|
|
7
|
+
description: listLimitDescription,
|
|
8
|
+
};
|
|
9
|
+
export function parseListLimit(value) {
|
|
10
|
+
if (value === undefined) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
if (!new RegExp(listLimitPattern).test(value)) {
|
|
14
|
+
quit(listLimitMessage, undefined, { argument: "--limit" });
|
|
15
|
+
}
|
|
16
|
+
return Number(value);
|
|
17
|
+
}
|
|
@@ -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;
|