@zinn-dev/cli 0.42.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.
Files changed (41) hide show
  1. package/package.json +3 -4
  2. package/skills/zinn/SKILL.md +1 -1
  3. package/src/capabilities-schema.d.ts +3 -3
  4. package/src/errors.d.ts +31 -3
  5. package/src/errors.js +75 -20
  6. package/src/lib.d.ts +14 -5
  7. package/src/lib.js +68 -33
  8. package/src/list-continuation.d.ts +11 -0
  9. package/src/list-continuation.js +18 -0
  10. package/src/list-limit.d.ts +11 -0
  11. package/src/list-limit.js +17 -0
  12. package/src/presentation/activity-presentation.js +18 -5
  13. package/src/presentation/description-presentation.d.ts +3 -16
  14. package/src/presentation/description-presentation.js +22 -21
  15. package/src/presentation/project-presentation.d.ts +6 -2
  16. package/src/presentation/project-presentation.js +9 -1
  17. package/src/presentation/relation-presentation.d.ts +6 -1
  18. package/src/presentation/relation-presentation.js +14 -0
  19. package/src/presentation/row-layout.d.ts +1 -1
  20. package/src/presentation/row-layout.js +6 -5
  21. package/src/presentation/task-presentation.js +7 -1
  22. package/src/presentation/text-width.d.ts +2 -0
  23. package/src/presentation/text-width.js +43 -0
  24. package/src/presentation/time.d.ts +3 -1
  25. package/src/presentation/time.js +5 -2
  26. package/src/result-schemas.d.ts +49 -3
  27. package/src/result-schemas.js +12 -3
  28. package/src/routes/activity-router.d.ts +45 -1
  29. package/src/routes/activity-router.js +113 -15
  30. package/src/routes/project-router.d.ts +40 -0
  31. package/src/routes/project-router.js +73 -12
  32. package/src/routes/relation-router.d.ts +7 -3
  33. package/src/routes/relation-router.js +73 -56
  34. package/src/routes/restore-router.js +2 -5
  35. package/src/routes/router.js +54 -27
  36. package/src/routes/routes.d.ts +169 -7
  37. package/src/routes/task-router.d.ts +84 -6
  38. package/src/routes/task-router.js +107 -19
  39. package/src/timestamp-input.d.ts +3 -0
  40. package/src/timestamp-input.js +31 -0
  41. package/src/types.d.ts +3 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zinn-dev/cli",
3
- "version": "0.42.0",
3
+ "version": "0.43.0",
4
4
  "description": "A kanban workflow in the terminal. Experimental.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://zinn.sh",
@@ -20,8 +20,7 @@
20
20
  "keywords": [
21
21
  "kanban",
22
22
  "cli",
23
- "terminal",
24
- "bun"
23
+ "terminal"
25
24
  ],
26
25
  "files": [
27
26
  "index.js",
@@ -37,7 +36,7 @@
37
36
  },
38
37
  "dependencies": {
39
38
  "zod": "4.6.4",
40
- "@zinn-dev/core": "0.31.0"
39
+ "@zinn-dev/core": "0.32.0"
41
40
  },
42
41
  "devDependencies": {
43
42
  "ajv": "8.20.0"
@@ -7,7 +7,7 @@ description: >-
7
7
  it, repository instructions mention it, zinn.local.json exists, or a Zinn task
8
8
  key is referenced.
9
9
  metadata:
10
- zinn-cli-reviewed-version: "0.42.0"
10
+ zinn-cli-reviewed-version: "0.43.0"
11
11
  ---
12
12
 
13
13
  # Work with a Zinn board
@@ -106,8 +106,8 @@ export declare const capabilitiesSchema: z.ZodObject<{
106
106
  }, z.core.$strict>;
107
107
  effects: z.ZodObject<{
108
108
  domain: z.ZodEnum<{
109
- read: "read";
110
109
  create: "create";
110
+ read: "read";
111
111
  update: "update";
112
112
  delete: "delete";
113
113
  replace: "replace";
@@ -115,11 +115,11 @@ export declare const capabilitiesSchema: z.ZodObject<{
115
115
  }>;
116
116
  storage: z.ZodEnum<{
117
117
  backup: "backup";
118
+ migrate: "migrate";
119
+ reindex: "reindex";
118
120
  none: "none";
119
121
  "normal-open": "normal-open";
120
122
  restore: "restore";
121
- migrate: "migrate";
122
- reindex: "reindex";
123
123
  inspect: "inspect";
124
124
  }>;
125
125
  }, z.core.$strict>;
package/src/errors.d.ts CHANGED
@@ -28,18 +28,27 @@ export declare const errorDetailsSchema: z.ZodObject<{
28
28
  settingsPath: z.ZodOptional<z.ZodString>;
29
29
  reason: z.ZodOptional<z.ZodEnum<{
30
30
  archived: "archived";
31
+ dash_value: "dash_value";
32
+ unknown_option: "unknown_option";
33
+ unknown_command: "unknown_command";
34
+ missing_command: "missing_command";
35
+ missing_argument: "missing_argument";
36
+ unexpected_argument: "unexpected_argument";
37
+ unquoted_column: "unquoted_column";
31
38
  confirmation_required: "confirmation_required";
32
39
  invalid_json: "invalid_json";
33
40
  invalid_settings: "invalid_settings";
34
41
  invalid_storage: "invalid_storage";
35
42
  already_exists: "already_exists";
36
43
  parent_exists: "parent_exists";
44
+ relation_changed: "relation_changed";
37
45
  cycle: "cycle";
38
46
  different_project: "different_project";
39
47
  different_column: "different_column";
40
48
  ambiguous_reference: "ambiguous_reference";
41
49
  text_match_count: "text_match_count";
42
50
  no_columns: "no_columns";
51
+ has_tasks: "has_tasks";
43
52
  unmarked_database: "unmarked_database";
44
53
  newer_database: "newer_database";
45
54
  older_database: "older_database";
@@ -101,18 +110,27 @@ export declare const errorDocumentSchema: z.ZodObject<{
101
110
  settingsPath: z.ZodOptional<z.ZodString>;
102
111
  reason: z.ZodOptional<z.ZodEnum<{
103
112
  archived: "archived";
113
+ dash_value: "dash_value";
114
+ unknown_option: "unknown_option";
115
+ unknown_command: "unknown_command";
116
+ missing_command: "missing_command";
117
+ missing_argument: "missing_argument";
118
+ unexpected_argument: "unexpected_argument";
119
+ unquoted_column: "unquoted_column";
104
120
  confirmation_required: "confirmation_required";
105
121
  invalid_json: "invalid_json";
106
122
  invalid_settings: "invalid_settings";
107
123
  invalid_storage: "invalid_storage";
108
124
  already_exists: "already_exists";
109
125
  parent_exists: "parent_exists";
126
+ relation_changed: "relation_changed";
110
127
  cycle: "cycle";
111
128
  different_project: "different_project";
112
129
  different_column: "different_column";
113
130
  ambiguous_reference: "ambiguous_reference";
114
131
  text_match_count: "text_match_count";
115
132
  no_columns: "no_columns";
133
+ has_tasks: "has_tasks";
116
134
  unmarked_database: "unmarked_database";
117
135
  newer_database: "newer_database";
118
136
  older_database: "older_database";
@@ -147,12 +165,22 @@ export declare const errorDocumentSchema: z.ZodObject<{
147
165
  export type ErrorCode = z.infer<typeof errorCodeSchema>;
148
166
  export type ErrorDetails = z.infer<typeof errorDetailsSchema>;
149
167
  export type CliFailure = z.infer<typeof errorDocumentSchema>["error"];
150
- /** A failure detected by the CLI, with only facts intended for its public output. */
168
+ type ClassifiedFailure = Omit<CliFailure, "message"> & {
169
+ suggestedRoute?: Array<string>;
170
+ };
171
+ /** A CLI failure with public facts and an internal recovery route. */
151
172
  export declare class CliError extends Error {
152
173
  readonly code: ErrorCode;
153
174
  readonly details?: ErrorDetails | undefined;
154
175
  help?: string | undefined;
155
- constructor(message: string, code?: ErrorCode, details?: ErrorDetails | undefined, help?: string | undefined);
176
+ readonly suggestedRoute?: Array<string> | undefined;
177
+ constructor(message: string, code?: ErrorCode, details?: ErrorDetails | undefined, help?: string | undefined, suggestedRoute?: Array<string> | undefined);
156
178
  }
179
+ /** Recovery text and its single suggested route, when one is identified. */
180
+ export declare function recoveryHint(error: unknown): {
181
+ suffix: string;
182
+ suggestedRoute?: Array<string>;
183
+ } | undefined;
157
184
  /** Finds causes of initialization wrappers without serializing their error chains. */
158
- export declare function classifyFailure(error: unknown): Omit<CliFailure, "message">;
185
+ export declare function classifyFailure(error: unknown): ClassifiedFailure;
186
+ export {};
package/src/errors.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { CoreError, SqliteError } from "@zinn-dev/core";
2
+ import { CoreError, ReadOnlyDatabaseError, SqliteError, TextEditMatchError, UnmarkedDatabaseError, isSqliteErrorFamily, } from "@zinn-dev/core";
3
3
  export const errorCodeSchema = z.enum([
4
4
  "invalid_input",
5
5
  "not_found",
@@ -28,6 +28,13 @@ export const errorDetailsSchema = z.strictObject({
28
28
  settingsPath: z.string().optional(),
29
29
  reason: z
30
30
  .enum([
31
+ "dash_value",
32
+ "unknown_option",
33
+ "unknown_command",
34
+ "missing_command",
35
+ "missing_argument",
36
+ "unexpected_argument",
37
+ "unquoted_column",
31
38
  "confirmation_required",
32
39
  "invalid_json",
33
40
  "invalid_settings",
@@ -35,12 +42,14 @@ export const errorDetailsSchema = z.strictObject({
35
42
  "already_exists",
36
43
  "archived",
37
44
  "parent_exists",
45
+ "relation_changed",
38
46
  "cycle",
39
47
  "different_project",
40
48
  "different_column",
41
49
  "ambiguous_reference",
42
50
  "text_match_count",
43
51
  "no_columns",
52
+ "has_tasks",
44
53
  "unmarked_database",
45
54
  "newer_database",
46
55
  "older_database",
@@ -81,19 +90,57 @@ export const errorDocumentSchema = z.strictObject({
81
90
  diagnostics: z.array(z.string()).optional(),
82
91
  }),
83
92
  });
84
- /** A failure detected by the CLI, with only facts intended for its public output. */
93
+ /** A CLI failure with public facts and an internal recovery route. */
85
94
  export class CliError extends Error {
86
95
  code;
87
96
  details;
88
97
  help;
89
- constructor(message, code = "invalid_input", details, help) {
98
+ suggestedRoute;
99
+ constructor(message, code = "invalid_input", details, help, suggestedRoute) {
90
100
  super(message);
91
101
  this.code = code;
92
102
  this.details = details;
93
103
  this.help = help;
104
+ this.suggestedRoute = suggestedRoute;
94
105
  this.name = "CliError";
95
106
  }
96
107
  }
108
+ /** Recovery text and its single suggested route, when one is identified. */
109
+ export function recoveryHint(error) {
110
+ if (error instanceof ReadOnlyDatabaseError && error.reason === "older") {
111
+ return { suffix: ". Run `zinn migrate` to upgrade it.", suggestedRoute: ["migrate"] };
112
+ }
113
+ if (error instanceof UnmarkedDatabaseError) {
114
+ return { suffix: ". Add --allow-legacy-read to read it anyway." };
115
+ }
116
+ if (error instanceof TextEditMatchError && error.matchCount > 1) {
117
+ return { suffix: " Use --all to replace every match." };
118
+ }
119
+ if (error instanceof CoreError && error.kind === "missing" && error.facts.entity === "database") {
120
+ return {
121
+ suffix: ". Create one with `zinn project create`.",
122
+ suggestedRoute: ["project", "create"],
123
+ };
124
+ }
125
+ if (error instanceof CoreError && error.facts.reason === "no_columns") {
126
+ return {
127
+ suffix: `. Add a column with zinn project column create ${error.facts.key} <name>.`,
128
+ suggestedRoute: ["project", "column", "create"],
129
+ };
130
+ }
131
+ if (error instanceof CoreError && error.facts.reason === "has_tasks") {
132
+ return {
133
+ suffix: ". Use zinn task move or zinn task delete to clear the column. Archived tasks must be unarchived before moving.",
134
+ };
135
+ }
136
+ if (error instanceof Error && error.message === "no such table: task_search") {
137
+ return {
138
+ suffix: ". Run `zinn reindex` to rebuild the search index.",
139
+ suggestedRoute: ["reindex"],
140
+ };
141
+ }
142
+ return undefined;
143
+ }
97
144
  const coreCodes = {
98
145
  input: "invalid_input",
99
146
  missing: "not_found",
@@ -120,19 +167,19 @@ const osReasons = {
120
167
  ENODEV: "io",
121
168
  EEXIST: "io",
122
169
  };
123
- const sqliteReasons = {
124
- SQLITE_BUSY: "busy",
125
- SQLITE_LOCKED: "locked",
126
- SQLITE_PERM: "permission_denied",
127
- SQLITE_AUTH: "permission_denied",
128
- SQLITE_READONLY: "read_only",
129
- SQLITE_FULL: "disk_full",
130
- SQLITE_CORRUPT: "corrupt",
131
- SQLITE_NOTADB: "not_database",
132
- SQLITE_IOERR: "io",
133
- SQLITE_CANTOPEN: "io",
134
- SQLITE_NOLFS: "io",
135
- };
170
+ const sqliteReasons = [
171
+ ["SQLITE_BUSY", "busy"],
172
+ ["SQLITE_LOCKED", "locked"],
173
+ ["SQLITE_PERM", "permission_denied"],
174
+ ["SQLITE_AUTH", "permission_denied"],
175
+ ["SQLITE_READONLY", "read_only"],
176
+ ["SQLITE_FULL", "disk_full"],
177
+ ["SQLITE_CORRUPT", "corrupt"],
178
+ ["SQLITE_NOTADB", "not_database"],
179
+ ["SQLITE_IOERR", "io"],
180
+ ["SQLITE_CANTOPEN", "io"],
181
+ ["SQLITE_NOLFS", "io"],
182
+ ];
136
183
  /** Selects public facts explicitly
137
184
  * Error properties and submitted objects do not go to output
138
185
  */
@@ -162,7 +209,7 @@ function nativeFailure(error) {
162
209
  return undefined;
163
210
  }
164
211
  const reason = error instanceof SqliteError
165
- ? Object.entries(sqliteReasons).find(([primary]) => code === primary || code.startsWith(`${primary}_`))?.[1]
212
+ ? sqliteReasons.find(([primary]) => isSqliteErrorFamily(error, primary))?.[1]
166
213
  : osReasons[code];
167
214
  if (reason === undefined) {
168
215
  return undefined;
@@ -179,13 +226,21 @@ function nativeFailure(error) {
179
226
  }
180
227
  /** Finds causes of initialization wrappers without serializing their error chains. */
181
228
  export function classifyFailure(error) {
229
+ const suggestedRoute = recoveryHint(error)?.suggestedRoute;
230
+ const recovery = suggestedRoute === undefined ? {} : { suggestedRoute };
182
231
  const visited = new Set();
183
232
  let current = error;
184
233
  let classified;
185
234
  while (current instanceof Error && !visited.has(current)) {
186
235
  visited.add(current);
187
236
  if (current instanceof CliError) {
188
- return { code: current.code, details: current.details, help: current.help };
237
+ return {
238
+ code: current.code,
239
+ details: current.details,
240
+ help: current.help,
241
+ ...recovery,
242
+ ...(current.suggestedRoute === undefined ? {} : { suggestedRoute: current.suggestedRoute }),
243
+ };
189
244
  }
190
245
  if (current instanceof CoreError && classified === undefined) {
191
246
  const details = publicDetails(current.facts);
@@ -213,7 +268,7 @@ export function classifyFailure(error) {
213
268
  }
214
269
  if (native !== undefined) {
215
270
  if (classified === undefined) {
216
- return { code: "storage", details: native };
271
+ return { code: "storage", details: native, ...recovery };
217
272
  }
218
273
  if (classified.code === "storage") {
219
274
  classified.details = { ...native, ...classified.details, cause: native.cause };
@@ -222,5 +277,5 @@ export function classifyFailure(error) {
222
277
  }
223
278
  current = current.cause;
224
279
  }
225
- return classified ?? { code: "internal" };
280
+ return { ...(classified ?? { code: "internal" }), ...recovery };
226
281
  }
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, type ErrorDetails } from "./errors.js";
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. */
@@ -65,7 +71,7 @@ type SelectedOrderForm<Form extends InputForm> = Form extends unknown ? Form & {
65
71
  directionIndex: number;
66
72
  } : never;
67
73
  /** Selects an order form after checking its required leading words. */
68
- export declare function validateOrderForms<Form extends InputForm>(positionals: string[], forms: readonly Form[]): SelectedOrderForm<Form>;
74
+ export declare function validateOrderForms<Form extends InputForm>(positionals: Array<string>, forms: readonly Form[]): SelectedOrderForm<Form>;
69
75
  export declare function requireStringOption(option: InputOption & {
70
76
  required: true;
71
77
  }, value: string | undefined, name: string, message: string): string;
@@ -82,13 +88,16 @@ export declare function shellQuote(word: string): string;
82
88
  /** A command line to show, with each word quoted for the shell as needed. */
83
89
  export declare function formatCommand(args: Array<string>): string;
84
90
  /** The words of the command a user likely meant by a flag the command does not take, if known. */
85
- type SuggestFor = (flag: string) => Array<string> | undefined;
91
+ type SuggestFor = (flag: string) => {
92
+ args: Array<string>;
93
+ route: Array<string>;
94
+ } | undefined;
86
95
  /** Renames an option without changing values or words after `--` */
87
96
  export declare function renameFlag(args: Array<string>, options: ParseArgsOptionsConfig, source: string, target: string): string[];
88
97
  /**
89
- * The message for an argument error from parseArgs, rewritten where parseArgs' own advice misleads.
98
+ * An argument failure from parseArgs, rewritten where parseArgs' own advice misleads.
90
99
  * parseArgs names the flag only in its message text, which Node and Bun word the same.
91
100
  * `null` for any other error.
92
101
  */
93
- export declare function parseArgsMessage(error: any, args: Array<string>, suggestFor: SuggestFor): any;
102
+ export declare function parseArgsFailure(error: any, args: Array<string>, suggestFor: SuggestFor, route: Array<string>): CliError | null;
94
103
  export {};
package/src/lib.js CHANGED
@@ -1,13 +1,24 @@
1
1
  import { parseArgs } from "node:util";
2
2
  import { createInterface } from "node:readline/promises";
3
3
  import { z } from "zod";
4
- import { assertWritable, InputValidationError, ReadOnlyDatabaseError, TextEditMatchError, UnmarkedDatabaseError, } from "@zinn-dev/core";
5
- import { CliError, classifyFailure } from "./errors.js";
4
+ import { assertWritable, InputValidationError } from "@zinn-dev/core";
5
+ import { CliError, classifyFailure, recoveryHint } from "./errors.js";
6
6
  import { helpSpellings, routerOptionNames, positionalWords } from "./input.js";
7
+ import { formatParserReasonPreview } from "./presentation/description-presentation.js";
7
8
  let outputMode = "text";
8
9
  let legacyReadAllowed = false;
9
10
  const diagnostics = [];
10
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
+ }
11
22
  export function setOutputMode(mode) {
12
23
  outputMode = mode;
13
24
  }
@@ -128,18 +139,9 @@ export function failureMessage(error, fallback) {
128
139
  if (error instanceof z.ZodError) {
129
140
  return new InputValidationError(error.issues).message;
130
141
  }
131
- const isOlderReadOnly = error instanceof ReadOnlyDatabaseError && error.reason === "older";
132
- if (isOlderReadOnly) {
133
- return `${error.message}. Run \`zinn migrate\` to upgrade it.`;
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.`;
142
+ const hint = recoveryHint(error);
143
+ if (hint !== undefined) {
144
+ return `${error.message}${hint.suffix}`;
143
145
  }
144
146
  return typeof error?.message === "string" ? error.message : fallback;
145
147
  }
@@ -152,8 +154,11 @@ export function quit(reason, help, details) {
152
154
  }
153
155
  /** Emits one handled failure, including any notices collected before it. */
154
156
  export function renderFailure(reason) {
157
+ const classified = classifyFailure(reason);
155
158
  const failure = {
156
- ...classifyFailure(reason),
159
+ code: classified.code,
160
+ details: classified.details,
161
+ help: classified.help,
157
162
  message: failureMessage(reason, "Something went wrong"),
158
163
  };
159
164
  const pendingDiagnostics = diagnostics.splice(0);
@@ -180,7 +185,7 @@ export function renderFailure(reason) {
180
185
  /** A command was given the wrong words. The router prints the message with the command's usage lines. */
181
186
  export class UsageError extends CliError {
182
187
  constructor(message, details) {
183
- super(message, "invalid_input", details);
188
+ super(boundParserMessage(message), "invalid_input", details);
184
189
  }
185
190
  }
186
191
  /**
@@ -194,13 +199,17 @@ export function validatePositionals(positionals, form) {
194
199
  const missingWord = requiredWords[positionals.length];
195
200
  if (missingWord !== undefined) {
196
201
  throw new UsageError(`Missing argument ${missingWord}`, {
202
+ reason: "missing_argument",
197
203
  argument: missingWord.replaceAll(/[\[\]<>]/g, "").replace(/\.\.\.$/, ""),
198
204
  });
199
205
  }
200
206
  const hasRepeatingWord = words.some((word) => word.endsWith("..."));
201
207
  const extraWord = positionals[words.length];
202
208
  if (!hasRepeatingWord && extraWord !== undefined) {
203
- throw new UsageError(`Unexpected argument "${extraWord}"`, { field: [] });
209
+ throw new UsageError(`Unexpected argument "${extraWord}"`, {
210
+ field: [],
211
+ reason: "unexpected_argument",
212
+ });
204
213
  }
205
214
  }
206
215
  export function validateUniqueOptions(tokens, options) {
@@ -253,7 +262,7 @@ export function validateOrderForms(positionals, forms) {
253
262
  }
254
263
  export function requireStringOption(option, value, name, message) {
255
264
  if (value === undefined) {
256
- quit(message, undefined, { argument: `--${name}` });
265
+ quit(message, undefined, { argument: `--${name}`, reason: "missing_argument" });
257
266
  }
258
267
  return value;
259
268
  }
@@ -299,7 +308,11 @@ function dashValueMessage(error, args) {
299
308
  `${flag}=${shellQuote(value)}`,
300
309
  ...args.slice(flagIndex + 2).map(shellQuote),
301
310
  ].join(" ");
302
- return `Option "${flag}" is followed by "${value}", which begins with a dash. If it is the value, join it to the flag with =: ${fixedCommand}`;
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
+ });
303
316
  }
304
317
  // "Unknown option '--project'."
305
318
  const UNKNOWN_LONG_OPTION_PATTERN = /^Unknown option '(--[^']+)'/;
@@ -332,40 +345,54 @@ export function renameFlag(args, options, source, target) {
332
345
  * and otherwise the usage line shown with it is the fix.
333
346
  * A word with a single dash shows the user's command with it after `--`.
334
347
  */
335
- function unknownOptionMessage(message, args, suggestFor) {
348
+ function unknownOptionMessage(message, args, suggestFor, route) {
336
349
  const flag = UNKNOWN_LONG_OPTION_PATTERN.exec(message)?.[1];
337
350
  if (flag !== undefined) {
338
351
  const suggestion = suggestFor(flag);
339
352
  const reason = `Unknown option "${flag}"`;
340
353
  if (suggestion === undefined) {
341
- return reason;
354
+ return { message: boundParserMessage(reason) };
342
355
  }
343
- const separatorIndex = suggestion.indexOf(DOUBLE_DASH);
344
- const optionEnd = separatorIndex === -1 ? suggestion.length : separatorIndex;
356
+ const separatorIndex = suggestion.args.indexOf(DOUBLE_DASH);
357
+ const optionEnd = separatorIndex === -1 ? suggestion.args.length : separatorIndex;
345
358
  const correctedArgs = [
346
- ...suggestion.slice(0, optionEnd),
359
+ ...suggestion.args.slice(0, optionEnd),
347
360
  ...args.filter(isRouterFlag),
348
- ...suggestion.slice(optionEnd),
361
+ ...suggestion.args.slice(optionEnd),
349
362
  ];
350
- return `${reason}. Did you mean: ${formatCommand(correctedArgs)}`;
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
+ };
351
370
  }
352
371
  // Commands define no short options, so `parseArgs` refused the first single-dash word before `--`.
353
372
  const separatorIndex = args.indexOf(DOUBLE_DASH);
354
373
  const optionArgs = separatorIndex === -1 ? args : args.slice(0, separatorIndex);
355
374
  const wordIndex = optionArgs.findIndex((arg) => SHORT_OPTION_WORD_PATTERN.test(arg));
356
375
  if (wordIndex === -1) {
357
- return message;
376
+ return { message: boundParserMessage(message) };
358
377
  }
359
378
  const word = args[wordIndex];
360
379
  const readOptions = [...word.slice(1)].map((letter) => `-${letter}`);
361
380
  const readAs = readOptions.length > 1 ? ` (Zinn read ${word} as ${readOptions.join(" ")})` : "";
362
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.";
363
384
  // Flags after the word must stay before --, and only the router's own flags are known to be flags.
364
385
  const wordsAfter = args.slice(wordIndex + 1);
365
386
  const routerFlagsAfter = wordsAfter.filter(isRouterFlag);
366
387
  const plainWordsAfter = wordsAfter.filter((arg) => !isRouterFlag(arg));
367
388
  if (plainWordsAfter.some((arg) => arg.startsWith("-"))) {
368
- return `${reason}.`;
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
+ };
369
396
  }
370
397
  const fixedCommand = formatCommand([
371
398
  ...args.slice(0, wordIndex),
@@ -374,21 +401,29 @@ function unknownOptionMessage(message, args, suggestFor) {
374
401
  word,
375
402
  ...plainWordsAfter,
376
403
  ]);
377
- return `${reason}: ${fixedCommand}`;
404
+ return {
405
+ message: boundParserMessage(`${reason}: ${fixedCommand}`, { reason: compactReason, guidance }),
406
+ suggestedRoute: route,
407
+ };
378
408
  }
379
409
  /**
380
- * The message for an argument error from parseArgs, rewritten where parseArgs' own advice misleads.
410
+ * An argument failure from parseArgs, rewritten where parseArgs' own advice misleads.
381
411
  * parseArgs names the flag only in its message text, which Node and Bun word the same.
382
412
  * `null` for any other error.
383
413
  */
384
- export function parseArgsMessage(error, args, suggestFor) {
414
+ export function parseArgsFailure(error, args, suggestFor, route) {
385
415
  const code = error?.code;
386
416
  const isParseArgsError = typeof code === "string" && code.startsWith("ERR_PARSE_ARGS_");
387
417
  if (!isParseArgsError) {
388
418
  return null;
389
419
  }
420
+ const argument = /(?:Unknown option|Option) '(-[^' ]+)/.exec(error.message)?.[1];
390
421
  if (code === "ERR_PARSE_ARGS_UNKNOWN_OPTION") {
391
- return unknownOptionMessage(error.message, args, suggestFor);
422
+ const hint = unknownOptionMessage(error.message, args, suggestFor, route);
423
+ return new CliError(hint.message, "invalid_input", { argument, reason: "unknown_option" }, undefined, hint.suggestedRoute);
392
424
  }
393
- return dashValueMessage(error, args) ?? error.message;
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);
394
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
+ }