@zinn-dev/cli 0.42.0 → 0.44.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/index.js +3 -3
- package/package.json +6 -4
- package/skills/zinn/SKILL.md +1 -1
- package/src/actor.d.ts +8 -0
- package/src/actor.js +5 -1
- package/src/capabilities-schema.d.ts +4 -4
- package/src/column-hint.js +3 -4
- package/src/errors.d.ts +40 -3
- package/src/errors.js +93 -21
- package/src/failure-log.d.ts +6 -0
- package/src/failure-log.js +167 -0
- package/src/input.d.ts +11 -0
- package/src/input.js +25 -1
- package/src/lib.d.ts +21 -10
- package/src/lib.js +116 -62
- 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/overview.d.ts +10 -0
- package/src/overview.js +41 -0
- package/src/presentation/activity-presentation.d.ts +2 -0
- package/src/presentation/activity-presentation.js +112 -38
- package/src/presentation/column-presentation.d.ts +17 -2
- package/src/presentation/column-presentation.js +45 -6
- package/src/presentation/description-presentation.d.ts +3 -16
- package/src/presentation/description-presentation.js +22 -21
- package/src/presentation/info-presentation.js +36 -6
- package/src/presentation/project-presentation.d.ts +6 -2
- package/src/presentation/project-presentation.js +9 -1
- package/src/presentation/relation-presentation.d.ts +12 -3
- package/src/presentation/relation-presentation.js +50 -26
- package/src/presentation/row-layout.d.ts +1 -1
- package/src/presentation/row-layout.js +6 -5
- package/src/presentation/task-blame-presentation.d.ts +11 -0
- package/src/presentation/task-blame-presentation.js +56 -0
- package/src/presentation/task-presentation.d.ts +6 -1
- package/src/presentation/task-presentation.js +28 -10
- 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/result-schemas.d.ts +529 -18
- package/src/result-schemas.js +66 -4
- package/src/routes/activity-router.d.ts +53 -1
- package/src/routes/activity-router.js +126 -15
- package/src/routes/info-router.js +3 -2
- package/src/routes/migrate-router.js +2 -2
- package/src/routes/project-router.d.ts +41 -1
- package/src/routes/project-router.js +76 -24
- package/src/routes/relation-router.d.ts +7 -3
- package/src/routes/relation-router.js +73 -56
- package/src/routes/restore-router.js +10 -7
- package/src/routes/router.js +77 -37
- package/src/routes/routes.d.ts +213 -8
- package/src/routes/task-router.d.ts +119 -6
- package/src/routes/task-router.js +177 -32
- package/src/routes/whoami-router.js +1 -1
- package/src/run-facts.d.ts +14 -0
- package/src/run-facts.js +14 -0
- package/src/store-folder.d.ts +5 -0
- package/src/store-folder.js +16 -0
- package/src/telemetry.d.ts +31 -0
- package/src/telemetry.js +329 -0
- package/src/text-input.js +1 -5
- package/src/timestamp-input.d.ts +3 -0
- package/src/timestamp-input.js +31 -0
- package/src/types.d.ts +4 -4
package/src/input.js
CHANGED
|
@@ -70,10 +70,34 @@ export const routerOptions = {
|
|
|
70
70
|
};
|
|
71
71
|
export const helpSpellings = ["-h", "--help"];
|
|
72
72
|
export const versionSpellings = ["-v", "--version"];
|
|
73
|
+
export const OPTION_SEPARATOR = "--";
|
|
74
|
+
export function isJsonFlag(flag) {
|
|
75
|
+
return flag === `--${routerOptionNames.json}`;
|
|
76
|
+
}
|
|
77
|
+
export function isAllowLegacyReadFlag(flag) {
|
|
78
|
+
return flag === `--${routerOptionNames.legacyRead}`;
|
|
79
|
+
}
|
|
80
|
+
/** A flag the router reads wherever it appears before --, for every command. */
|
|
81
|
+
export function isRouterFlag(flag) {
|
|
82
|
+
return isJsonFlag(flag) || isAllowLegacyReadFlag(flag);
|
|
83
|
+
}
|
|
84
|
+
export function isHelpFlag(flag) {
|
|
85
|
+
return helpSpellings.includes(flag);
|
|
86
|
+
}
|
|
87
|
+
/** The words before the first `--`, and the rest starting with that `--` */
|
|
88
|
+
export function splitAtOptionSeparator(words) {
|
|
89
|
+
const separatorIndex = words.indexOf(OPTION_SEPARATOR);
|
|
90
|
+
return separatorIndex === -1
|
|
91
|
+
? { optionWords: words, passthroughWords: [] }
|
|
92
|
+
: {
|
|
93
|
+
optionWords: words.slice(0, separatorIndex),
|
|
94
|
+
passthroughWords: words.slice(separatorIndex),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
73
97
|
export const invocation = {
|
|
74
98
|
routerOptions,
|
|
75
99
|
routerOptionPlacement: "exact-tokens-anywhere-before-separator",
|
|
76
|
-
optionSeparator:
|
|
100
|
+
optionSeparator: OPTION_SEPARATOR,
|
|
77
101
|
literalOptionValue: "equals",
|
|
78
102
|
singularOptions: "reject-repetition",
|
|
79
103
|
jsonFailure: "one-stderr-document-with-buffered-diagnostics",
|
package/src/lib.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import type { ParseArgsOptionsConfig } from "node:util";
|
|
2
2
|
import type { InputForm, InputOptions, InputOption } from "./input.js";
|
|
3
|
+
import type { ErrorDetails } from "./errors.js";
|
|
3
4
|
import { parseArgs } from "node:util";
|
|
4
|
-
import { CliError
|
|
5
|
+
import { CliError } from "./errors.js";
|
|
5
6
|
type ParsedTokens = NonNullable<ReturnType<typeof parseArgs>["tokens"]>;
|
|
6
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;
|
|
7
13
|
export declare function setOutputMode(mode: OutputMode): void;
|
|
8
14
|
export declare function getOutputMode(): OutputMode;
|
|
9
15
|
/** Selects output before routing, without treating words after `--` as flags. */
|
|
@@ -11,10 +17,12 @@ export declare function prepareOutput(args: Array<string>): void;
|
|
|
11
17
|
/** Keeps JSON failures parseable while text-mode notices remain immediate. */
|
|
12
18
|
export declare function diagnostic(message: string): void;
|
|
13
19
|
export declare function flushDiagnostics(): void;
|
|
14
|
-
export declare function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
export declare function isDebugOutputEnabled(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Ends a successful run after its output, recording telemetry then releasing notices held back in JSON mode.
|
|
23
|
+
* Telemetry goes first so its own debug notice is released with the rest.
|
|
24
|
+
*/
|
|
25
|
+
export declare function finishRun(): void;
|
|
18
26
|
export declare function setLegacyReadAllowed(allowed: boolean): void;
|
|
19
27
|
export declare function isLegacyReadAllowed(): boolean;
|
|
20
28
|
export declare function output<T>(data: T, transformToString: (data: T) => string): void;
|
|
@@ -65,11 +73,10 @@ type SelectedOrderForm<Form extends InputForm> = Form extends unknown ? Form & {
|
|
|
65
73
|
directionIndex: number;
|
|
66
74
|
} : never;
|
|
67
75
|
/** Selects an order form after checking its required leading words. */
|
|
68
|
-
export declare function validateOrderForms<Form extends InputForm>(positionals: string
|
|
76
|
+
export declare function validateOrderForms<Form extends InputForm>(positionals: Array<string>, forms: readonly Form[]): SelectedOrderForm<Form>;
|
|
69
77
|
export declare function requireStringOption(option: InputOption & {
|
|
70
78
|
required: true;
|
|
71
79
|
}, value: string | undefined, name: string, message: string): string;
|
|
72
|
-
export declare function isHelpFlag(flag: string): boolean;
|
|
73
80
|
/**
|
|
74
81
|
* Help sentence for a flag whose value may begin with a dash, such as a Markdown bullet.
|
|
75
82
|
* `parseArgs` refuses `--flag -value`, since a value that looks like an option may mean the value
|
|
@@ -82,13 +89,17 @@ export declare function shellQuote(word: string): string;
|
|
|
82
89
|
/** A command line to show, with each word quoted for the shell as needed. */
|
|
83
90
|
export declare function formatCommand(args: Array<string>): string;
|
|
84
91
|
/** The words of the command a user likely meant by a flag the command does not take, if known. */
|
|
85
|
-
type SuggestFor = (flag: string) =>
|
|
92
|
+
type SuggestFor = (flag: string) => {
|
|
93
|
+
args: Array<string>;
|
|
94
|
+
route: Array<string>;
|
|
95
|
+
} | undefined;
|
|
86
96
|
/** Renames an option without changing values or words after `--` */
|
|
87
97
|
export declare function renameFlag(args: Array<string>, options: ParseArgsOptionsConfig, source: string, target: string): string[];
|
|
98
|
+
export declare function isParseArgsError(error: any): boolean;
|
|
88
99
|
/**
|
|
89
|
-
*
|
|
100
|
+
* An argument failure from parseArgs, rewritten where parseArgs' own advice misleads.
|
|
90
101
|
* parseArgs names the flag only in its message text, which Node and Bun word the same.
|
|
91
102
|
* `null` for any other error.
|
|
92
103
|
*/
|
|
93
|
-
export declare function
|
|
104
|
+
export declare function parseArgsFailure(error: any, args: Array<string>, suggestFor: SuggestFor, route: Array<string>): CliError | null;
|
|
94
105
|
export {};
|
package/src/lib.js
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
1
2
|
import { parseArgs } from "node:util";
|
|
2
3
|
import { createInterface } from "node:readline/promises";
|
|
3
4
|
import { z } from "zod";
|
|
4
|
-
import { assertWritable, InputValidationError
|
|
5
|
-
import { CliError, classifyFailure } from "./errors.js";
|
|
6
|
-
import {
|
|
5
|
+
import { assertWritable, InputValidationError } from "@zinn-dev/core";
|
|
6
|
+
import { CliError, classifyFailure, recoveryHint } from "./errors.js";
|
|
7
|
+
import { writeFailureLog } from "./failure-log.js";
|
|
8
|
+
import { isJsonFlag, isRouterFlag, OPTION_SEPARATOR, positionalWords, splitAtOptionSeparator, } from "./input.js";
|
|
9
|
+
import { formatParserReasonPreview } from "./presentation/description-presentation.js";
|
|
10
|
+
import { writeRunRecord } from "./telemetry.js";
|
|
7
11
|
let outputMode = "text";
|
|
8
12
|
let legacyReadAllowed = false;
|
|
9
13
|
const diagnostics = [];
|
|
10
|
-
|
|
14
|
+
/** Every notice of this run in order, kept for the failure log */
|
|
15
|
+
const runNotices = [];
|
|
16
|
+
/** Failures that write a log, because the error alone does not say what went wrong */
|
|
17
|
+
const LOGGED_ERROR_CODES = ["storage", "internal"];
|
|
18
|
+
const MAX_PARSER_MESSAGE_LENGTH = 1024;
|
|
19
|
+
/** Keeps recovery guidance outside the shortened reason and never clips a repair command. */
|
|
20
|
+
export function boundParserMessage(message, options = {}) {
|
|
21
|
+
if (message.length <= MAX_PARSER_MESSAGE_LENGTH) {
|
|
22
|
+
return message;
|
|
23
|
+
}
|
|
24
|
+
const guidance = options.guidance ?? "See usage for accepted arguments.";
|
|
25
|
+
const reason = formatParserReasonPreview(options.reason ?? message, MAX_PARSER_MESSAGE_LENGTH - guidance.length - 1);
|
|
26
|
+
return `${reason} ${guidance}`;
|
|
27
|
+
}
|
|
11
28
|
export function setOutputMode(mode) {
|
|
12
29
|
outputMode = mode;
|
|
13
30
|
}
|
|
@@ -16,12 +33,12 @@ export function getOutputMode() {
|
|
|
16
33
|
}
|
|
17
34
|
/** Selects output before routing, without treating words after `--` as flags. */
|
|
18
35
|
export function prepareOutput(args) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
setOutputMode(options.some(isJsonFlag) ? "json" : "text");
|
|
36
|
+
const { optionWords } = splitAtOptionSeparator(args);
|
|
37
|
+
setOutputMode(optionWords.some(isJsonFlag) ? "json" : "text");
|
|
22
38
|
}
|
|
23
39
|
/** Keeps JSON failures parseable while text-mode notices remain immediate. */
|
|
24
40
|
export function diagnostic(message) {
|
|
41
|
+
runNotices.push(message);
|
|
25
42
|
if (outputMode === "json") {
|
|
26
43
|
diagnostics.push(message);
|
|
27
44
|
}
|
|
@@ -34,15 +51,23 @@ export function flushDiagnostics() {
|
|
|
34
51
|
console.error(message);
|
|
35
52
|
}
|
|
36
53
|
}
|
|
37
|
-
|
|
38
|
-
|
|
54
|
+
// ZINN_DEBUG=1 prints routing detail on stderr, so stdout and `--json` results stay unchanged.
|
|
55
|
+
export function isDebugOutputEnabled() {
|
|
56
|
+
return process.env.ZINN_DEBUG === "1";
|
|
39
57
|
}
|
|
40
|
-
|
|
41
|
-
|
|
58
|
+
function recordRun(outcome) {
|
|
59
|
+
const problem = writeRunRecord(outcome);
|
|
60
|
+
if (problem !== undefined && isDebugOutputEnabled()) {
|
|
61
|
+
diagnostic(`::telemetry ${problem}`);
|
|
62
|
+
}
|
|
42
63
|
}
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Ends a successful run after its output, recording telemetry then releasing notices held back in JSON mode.
|
|
66
|
+
* Telemetry goes first so its own debug notice is released with the rest.
|
|
67
|
+
*/
|
|
68
|
+
export function finishRun() {
|
|
69
|
+
recordRun({});
|
|
70
|
+
flushDiagnostics();
|
|
46
71
|
}
|
|
47
72
|
export function setLegacyReadAllowed(allowed) {
|
|
48
73
|
legacyReadAllowed = allowed;
|
|
@@ -128,18 +153,9 @@ export function failureMessage(error, fallback) {
|
|
|
128
153
|
if (error instanceof z.ZodError) {
|
|
129
154
|
return new InputValidationError(error.issues).message;
|
|
130
155
|
}
|
|
131
|
-
const
|
|
132
|
-
if (
|
|
133
|
-
return `${error.message}.
|
|
134
|
-
}
|
|
135
|
-
if (error instanceof UnmarkedDatabaseError) {
|
|
136
|
-
return `${error.message}. Add --allow-legacy-read to read it anyway.`;
|
|
137
|
-
}
|
|
138
|
-
if (error instanceof TextEditMatchError && error.matchCount > 1) {
|
|
139
|
-
return `${error.message} Use --all to replace every match.`;
|
|
140
|
-
}
|
|
141
|
-
if (error?.message === "no such table: task_search") {
|
|
142
|
-
return `${error.message}. Run \`zinn reindex\` to rebuild the search index.`;
|
|
156
|
+
const hint = recoveryHint(error);
|
|
157
|
+
if (hint !== undefined) {
|
|
158
|
+
return `${error.message}${hint.suffix}`;
|
|
143
159
|
}
|
|
144
160
|
return typeof error?.message === "string" ? error.message : fallback;
|
|
145
161
|
}
|
|
@@ -152,18 +168,29 @@ export function quit(reason, help, details) {
|
|
|
152
168
|
}
|
|
153
169
|
/** Emits one handled failure, including any notices collected before it. */
|
|
154
170
|
export function renderFailure(reason) {
|
|
171
|
+
const classified = classifyFailure(reason);
|
|
155
172
|
const failure = {
|
|
156
|
-
|
|
173
|
+
code: classified.code,
|
|
174
|
+
details: classified.details,
|
|
175
|
+
help: classified.help,
|
|
157
176
|
message: failureMessage(reason, "Something went wrong"),
|
|
158
177
|
};
|
|
178
|
+
const logPath = LOGGED_ERROR_CODES.includes(failure.code)
|
|
179
|
+
? writeFailureLog(reason, runNotices)
|
|
180
|
+
: undefined;
|
|
181
|
+
recordRun({
|
|
182
|
+
failure: classified,
|
|
183
|
+
...(logPath === undefined ? {} : { logFileName: basename(logPath) }),
|
|
184
|
+
});
|
|
159
185
|
const pendingDiagnostics = diagnostics.splice(0);
|
|
160
186
|
if (outputMode === "json") {
|
|
161
|
-
const details =
|
|
162
|
-
|
|
163
|
-
|
|
187
|
+
const details = {
|
|
188
|
+
...Object.fromEntries(Object.entries(failure.details ?? {}).filter(([, value]) => value !== undefined)),
|
|
189
|
+
...(logPath === undefined ? {} : { logPath }),
|
|
190
|
+
};
|
|
164
191
|
const error = {
|
|
165
192
|
...failure,
|
|
166
|
-
details:
|
|
193
|
+
details: Object.keys(details).length > 0 ? details : undefined,
|
|
167
194
|
diagnostics: pendingDiagnostics.length > 0 ? pendingDiagnostics : undefined,
|
|
168
195
|
};
|
|
169
196
|
console.error(JSON.stringify({ error }, null, 2));
|
|
@@ -173,6 +200,9 @@ export function renderFailure(reason) {
|
|
|
173
200
|
console.error(message);
|
|
174
201
|
}
|
|
175
202
|
console.error(failure.help == null ? failure.message : `${failure.message}\n\n${failure.help}`);
|
|
203
|
+
if (logPath !== undefined) {
|
|
204
|
+
console.error(`Full log: ${logPath}`);
|
|
205
|
+
}
|
|
176
206
|
}
|
|
177
207
|
// Let piped stderr finish writing before Node exits
|
|
178
208
|
process.stderr.write("", () => process.exit(1));
|
|
@@ -180,7 +210,7 @@ export function renderFailure(reason) {
|
|
|
180
210
|
/** A command was given the wrong words. The router prints the message with the command's usage lines. */
|
|
181
211
|
export class UsageError extends CliError {
|
|
182
212
|
constructor(message, details) {
|
|
183
|
-
super(message, "invalid_input", details);
|
|
213
|
+
super(boundParserMessage(message), "invalid_input", details);
|
|
184
214
|
}
|
|
185
215
|
}
|
|
186
216
|
/**
|
|
@@ -194,13 +224,17 @@ export function validatePositionals(positionals, form) {
|
|
|
194
224
|
const missingWord = requiredWords[positionals.length];
|
|
195
225
|
if (missingWord !== undefined) {
|
|
196
226
|
throw new UsageError(`Missing argument ${missingWord}`, {
|
|
227
|
+
reason: "missing_argument",
|
|
197
228
|
argument: missingWord.replaceAll(/[\[\]<>]/g, "").replace(/\.\.\.$/, ""),
|
|
198
229
|
});
|
|
199
230
|
}
|
|
200
231
|
const hasRepeatingWord = words.some((word) => word.endsWith("..."));
|
|
201
232
|
const extraWord = positionals[words.length];
|
|
202
233
|
if (!hasRepeatingWord && extraWord !== undefined) {
|
|
203
|
-
throw new UsageError(`Unexpected argument "${extraWord}"`, {
|
|
234
|
+
throw new UsageError(`Unexpected argument "${extraWord}"`, {
|
|
235
|
+
field: [],
|
|
236
|
+
reason: "unexpected_argument",
|
|
237
|
+
});
|
|
204
238
|
}
|
|
205
239
|
}
|
|
206
240
|
export function validateUniqueOptions(tokens, options) {
|
|
@@ -253,13 +287,10 @@ export function validateOrderForms(positionals, forms) {
|
|
|
253
287
|
}
|
|
254
288
|
export function requireStringOption(option, value, name, message) {
|
|
255
289
|
if (value === undefined) {
|
|
256
|
-
quit(message, undefined, { argument: `--${name}
|
|
290
|
+
quit(message, undefined, { argument: `--${name}`, reason: "missing_argument" });
|
|
257
291
|
}
|
|
258
292
|
return value;
|
|
259
293
|
}
|
|
260
|
-
export function isHelpFlag(flag) {
|
|
261
|
-
return helpSpellings.includes(flag);
|
|
262
|
-
}
|
|
263
294
|
/**
|
|
264
295
|
* Help sentence for a flag whose value may begin with a dash, such as a Markdown bullet.
|
|
265
296
|
* `parseArgs` refuses `--flag -value`, since a value that looks like an option may mean the value
|
|
@@ -299,7 +330,11 @@ function dashValueMessage(error, args) {
|
|
|
299
330
|
`${flag}=${shellQuote(value)}`,
|
|
300
331
|
...args.slice(flagIndex + 2).map(shellQuote),
|
|
301
332
|
].join(" ");
|
|
302
|
-
|
|
333
|
+
const reason = `Option "${flag}" is followed by "${value}", which begins with a dash.`;
|
|
334
|
+
return boundParserMessage(`${reason} If it is the value, join it to the flag with =: ${fixedCommand}`, {
|
|
335
|
+
reason,
|
|
336
|
+
guidance: "Join the original value to its flag with =. Full command omitted because it is long.",
|
|
337
|
+
});
|
|
303
338
|
}
|
|
304
339
|
// "Unknown option '--project'."
|
|
305
340
|
const UNKNOWN_LONG_OPTION_PATTERN = /^Unknown option '(--[^']+)'/;
|
|
@@ -332,63 +367,82 @@ export function renameFlag(args, options, source, target) {
|
|
|
332
367
|
* and otherwise the usage line shown with it is the fix.
|
|
333
368
|
* A word with a single dash shows the user's command with it after `--`.
|
|
334
369
|
*/
|
|
335
|
-
function unknownOptionMessage(message, args, suggestFor) {
|
|
370
|
+
function unknownOptionMessage(message, args, suggestFor, route) {
|
|
336
371
|
const flag = UNKNOWN_LONG_OPTION_PATTERN.exec(message)?.[1];
|
|
337
372
|
if (flag !== undefined) {
|
|
338
373
|
const suggestion = suggestFor(flag);
|
|
339
374
|
const reason = `Unknown option "${flag}"`;
|
|
340
375
|
if (suggestion === undefined) {
|
|
341
|
-
return reason;
|
|
376
|
+
return { message: boundParserMessage(reason) };
|
|
342
377
|
}
|
|
343
|
-
const
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
378
|
+
const { optionWords, passthroughWords } = splitAtOptionSeparator(suggestion.args);
|
|
379
|
+
const correctedArgs = [...optionWords, ...args.filter(isRouterFlag), ...passthroughWords];
|
|
380
|
+
return {
|
|
381
|
+
message: boundParserMessage(`${reason}. Did you mean: ${formatCommand(correctedArgs)}`, {
|
|
382
|
+
reason,
|
|
383
|
+
guidance: "See usage for accepted arguments. Full command omitted because it is long.",
|
|
384
|
+
}),
|
|
385
|
+
suggestedRoute: suggestion.route,
|
|
386
|
+
};
|
|
351
387
|
}
|
|
352
388
|
// Commands define no short options, so `parseArgs` refused the first single-dash word before `--`.
|
|
353
|
-
const
|
|
354
|
-
const
|
|
355
|
-
const wordIndex = optionArgs.findIndex((arg) => SHORT_OPTION_WORD_PATTERN.test(arg));
|
|
389
|
+
const { optionWords } = splitAtOptionSeparator(args);
|
|
390
|
+
const wordIndex = optionWords.findIndex((arg) => SHORT_OPTION_WORD_PATTERN.test(arg));
|
|
356
391
|
if (wordIndex === -1) {
|
|
357
|
-
return message;
|
|
392
|
+
return { message: boundParserMessage(message) };
|
|
358
393
|
}
|
|
359
394
|
const word = args[wordIndex];
|
|
360
395
|
const readOptions = [...word.slice(1)].map((letter) => `-${letter}`);
|
|
361
396
|
const readAs = readOptions.length > 1 ? ` (Zinn read ${word} as ${readOptions.join(" ")})` : "";
|
|
362
397
|
const reason = `Unknown option "${readOptions[0]}"${readAs}. If it is a value, put it after --`;
|
|
398
|
+
const compactReason = `Unknown option in "${word}".`;
|
|
399
|
+
const guidance = "If it is a value, put the original word after --. Full command omitted because it is long.";
|
|
363
400
|
// Flags after the word must stay before --, and only the router's own flags are known to be flags.
|
|
364
401
|
const wordsAfter = args.slice(wordIndex + 1);
|
|
365
402
|
const routerFlagsAfter = wordsAfter.filter(isRouterFlag);
|
|
366
403
|
const plainWordsAfter = wordsAfter.filter((arg) => !isRouterFlag(arg));
|
|
367
404
|
if (plainWordsAfter.some((arg) => arg.startsWith("-"))) {
|
|
368
|
-
return
|
|
405
|
+
return {
|
|
406
|
+
message: boundParserMessage(`${reason}.`, {
|
|
407
|
+
reason: compactReason,
|
|
408
|
+
guidance: "If it is a value, put the original word after --.",
|
|
409
|
+
}),
|
|
410
|
+
suggestedRoute: route,
|
|
411
|
+
};
|
|
369
412
|
}
|
|
370
413
|
const fixedCommand = formatCommand([
|
|
371
414
|
...args.slice(0, wordIndex),
|
|
372
415
|
...routerFlagsAfter,
|
|
373
|
-
|
|
416
|
+
OPTION_SEPARATOR,
|
|
374
417
|
word,
|
|
375
418
|
...plainWordsAfter,
|
|
376
419
|
]);
|
|
377
|
-
return
|
|
420
|
+
return {
|
|
421
|
+
message: boundParserMessage(`${reason}: ${fixedCommand}`, { reason: compactReason, guidance }),
|
|
422
|
+
suggestedRoute: route,
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
export function isParseArgsError(error) {
|
|
426
|
+
const code = error?.code;
|
|
427
|
+
return typeof code === "string" && code.startsWith("ERR_PARSE_ARGS_");
|
|
378
428
|
}
|
|
379
429
|
/**
|
|
380
|
-
*
|
|
430
|
+
* An argument failure from parseArgs, rewritten where parseArgs' own advice misleads.
|
|
381
431
|
* parseArgs names the flag only in its message text, which Node and Bun word the same.
|
|
382
432
|
* `null` for any other error.
|
|
383
433
|
*/
|
|
384
|
-
export function
|
|
385
|
-
|
|
386
|
-
const isParseArgsError = typeof code === "string" && code.startsWith("ERR_PARSE_ARGS_");
|
|
387
|
-
if (!isParseArgsError) {
|
|
434
|
+
export function parseArgsFailure(error, args, suggestFor, route) {
|
|
435
|
+
if (!isParseArgsError(error)) {
|
|
388
436
|
return null;
|
|
389
437
|
}
|
|
438
|
+
const code = error.code;
|
|
439
|
+
const argument = /(?:Unknown option|Option) '(-[^' ]+)/.exec(error.message)?.[1];
|
|
390
440
|
if (code === "ERR_PARSE_ARGS_UNKNOWN_OPTION") {
|
|
391
|
-
|
|
441
|
+
const hint = unknownOptionMessage(error.message, args, suggestFor, route);
|
|
442
|
+
return new CliError(hint.message, "invalid_input", { argument, reason: "unknown_option" }, undefined, hint.suggestedRoute);
|
|
392
443
|
}
|
|
393
|
-
|
|
444
|
+
const dashMessage = dashValueMessage(error, args);
|
|
445
|
+
const isMissingValue = code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE" && / argument missing$/.test(error.message);
|
|
446
|
+
const reason = dashMessage !== null ? "dash_value" : isMissingValue ? "missing_argument" : undefined;
|
|
447
|
+
return new CliError(dashMessage ?? boundParserMessage(error.message), "invalid_input", { argument, reason }, undefined, dashMessage === null ? undefined : route);
|
|
394
448
|
}
|
|
@@ -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.";
|
|
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.";
|
|
10
|
+
};
|
|
11
|
+
export declare function parseListLimit(value: string | undefined): number | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { listLimitMessage, listLimitPattern } from "@zinn-dev/core";
|
|
2
|
+
import { quit } from "./lib.js";
|
|
3
|
+
export const listLimitDescription = "Return at most n results after all filters.";
|
|
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
|
+
}
|
package/src/overview.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export const overview = [
|
|
2
|
+
{
|
|
3
|
+
summary: "Set deadlines and sort or filter by them",
|
|
4
|
+
uses: [
|
|
5
|
+
{ command: "task create", flags: ["--due"] },
|
|
6
|
+
{ command: "task edit", flags: ["--due"] },
|
|
7
|
+
{ command: "task list", flags: ["--sort due", "--due-since", "--due-until"] },
|
|
8
|
+
],
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
summary: "Change several tasks in one command",
|
|
12
|
+
uses: [{ command: "task move" }, { command: "task archive" }, { command: "task delete" }],
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
summary: "Read text from a file or stdin",
|
|
16
|
+
uses: [
|
|
17
|
+
{ command: "task create", flags: ["--description-file"] },
|
|
18
|
+
{ command: "task comment create", flags: ["--text-file"] },
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
{ summary: "Search titles, descriptions and comments", uses: [{ command: "task search" }] },
|
|
22
|
+
{
|
|
23
|
+
summary: "Continue a long list",
|
|
24
|
+
uses: [
|
|
25
|
+
{ command: "task list", flags: ["--limit", "--starting-after"] },
|
|
26
|
+
{ command: "activity list", flags: ["--limit", "--starting-after"] },
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
summary: "See the agent and session behind each change",
|
|
31
|
+
uses: [{ command: "activity list" }, { command: "activity view" }],
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
export function formatOverview() {
|
|
35
|
+
return overview
|
|
36
|
+
.map(({ summary, uses }) => {
|
|
37
|
+
const named = uses.map(({ command, flags = [] }) => [command, ...flags].join(" "));
|
|
38
|
+
return ` ${summary}: ${named.join(", ")}`;
|
|
39
|
+
})
|
|
40
|
+
.join("\n");
|
|
41
|
+
}
|
|
@@ -22,6 +22,8 @@ export declare function presentActivities(events: Array<Activity>, options?: {
|
|
|
22
22
|
taskKey?: string;
|
|
23
23
|
taskId?: string;
|
|
24
24
|
showsFullIds?: boolean;
|
|
25
|
+
/** Only deletions among the events mark a reused key, as in one current task's history */
|
|
26
|
+
keysFromEventsOnly?: boolean;
|
|
25
27
|
}): Array<PresentedActivity>;
|
|
26
28
|
export declare function presentActor(actor: Actor): PresentedActor;
|
|
27
29
|
export declare function formatActor(actor: PresentedActor): string;
|