@zinn-dev/cli 0.46.0 → 0.47.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 (53) hide show
  1. package/package.json +2 -2
  2. package/skills/zinn/SKILL.md +1 -1
  3. package/src/capabilities-schema.d.ts +74 -0
  4. package/src/capabilities-schema.js +44 -0
  5. package/src/capabilities.d.ts +2 -0
  6. package/src/capabilities.js +2 -0
  7. package/src/column-hint.js +2 -9
  8. package/src/errors.d.ts +1 -0
  9. package/src/errors.js +1 -0
  10. package/src/input.d.ts +30 -0
  11. package/src/input.js +18 -0
  12. package/src/lib.d.ts +73 -5
  13. package/src/lib.js +69 -13
  14. package/src/presentation/activity-presentation.d.ts +2 -1
  15. package/src/presentation/activity-presentation.js +21 -6
  16. package/src/presentation/color.d.ts +12 -0
  17. package/src/presentation/color.js +12 -0
  18. package/src/presentation/project-presentation.d.ts +4 -1
  19. package/src/presentation/project-presentation.js +18 -0
  20. package/src/presentation/relation-presentation.js +8 -20
  21. package/src/presentation/section.d.ts +7 -4
  22. package/src/presentation/section.js +21 -7
  23. package/src/presentation/task-blame-presentation.d.ts +2 -1
  24. package/src/presentation/task-blame-presentation.js +4 -4
  25. package/src/presentation/task-presentation.d.ts +12 -1
  26. package/src/presentation/task-presentation.js +60 -9
  27. package/src/result-schemas.d.ts +93 -14
  28. package/src/result-schemas.js +1 -0
  29. package/src/routes/activity-router.d.ts +1 -1
  30. package/src/routes/activity-router.js +15 -31
  31. package/src/routes/backup-router.js +2 -9
  32. package/src/routes/capabilities-router.js +2 -9
  33. package/src/routes/comment-router.d.ts +2 -6
  34. package/src/routes/comment-router.js +13 -61
  35. package/src/routes/doctor-router.js +2 -9
  36. package/src/routes/info-router.js +2 -9
  37. package/src/routes/label-router.js +6 -43
  38. package/src/routes/migrate-router.js +2 -9
  39. package/src/routes/project-router.js +14 -100
  40. package/src/routes/reindex-router.js +2 -9
  41. package/src/routes/relation-router.d.ts +10 -4
  42. package/src/routes/relation-router.js +7 -18
  43. package/src/routes/restore-router.js +2 -11
  44. package/src/routes/router.js +32 -11
  45. package/src/routes/routes.d.ts +29 -30
  46. package/src/routes/skill-router.js +3 -18
  47. package/src/routes/task-router.d.ts +28 -28
  48. package/src/routes/task-router.js +62 -195
  49. package/src/routes/whoami-router.js +2 -9
  50. package/src/telemetry.js +3 -4
  51. package/src/types.d.ts +5 -1
  52. package/src/views.d.ts +117 -0
  53. package/src/views.js +54 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zinn-dev/cli",
3
- "version": "0.46.0",
3
+ "version": "0.47.0",
4
4
  "description": "A kanban workflow in the terminal. Experimental.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://zinn.sh",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "zod": "4.6.7",
42
- "@zinn-dev/core": "0.35.0"
42
+ "@zinn-dev/core": "0.36.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "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.46.0"
10
+ zinn-cli-reviewed-version: "0.47.0"
11
11
  ---
12
12
 
13
13
  # Work with a Zinn board
@@ -12,6 +12,7 @@ export declare const capabilitiesSchema: z.ZodObject<{
12
12
  string: "string";
13
13
  boolean: "boolean";
14
14
  }>;
15
+ aliases: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
15
16
  short: z.ZodOptional<z.ZodString>;
16
17
  multiple: z.ZodOptional<z.ZodBoolean>;
17
18
  default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodArray<z.ZodBoolean>]>>;
@@ -57,6 +58,7 @@ export declare const capabilitiesSchema: z.ZodObject<{
57
58
  string: "string";
58
59
  boolean: "boolean";
59
60
  }>;
61
+ aliases: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
60
62
  short: z.ZodOptional<z.ZodString>;
61
63
  multiple: z.ZodOptional<z.ZodBoolean>;
62
64
  default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodArray<z.ZodBoolean>]>>;
@@ -163,6 +165,78 @@ export declare const capabilitiesSchema: z.ZodObject<{
163
165
  exitCode: z.ZodLiteral<1>;
164
166
  stream: z.ZodLiteral<"stderr">;
165
167
  }, z.core.$strict>;
168
+ views: z.ZodObject<{
169
+ version: z.ZodLiteral<"1.0">;
170
+ taskDetail: z.ZodObject<{
171
+ sections: z.ZodArray<z.ZodObject<{
172
+ id: z.ZodString;
173
+ rank: z.ZodNumber;
174
+ heading: z.ZodOptional<z.ZodString>;
175
+ short: z.ZodOptional<z.ZodEnum<{
176
+ keys: "keys";
177
+ firstParagraph: "firstParagraph";
178
+ countAndLatest: "countAndLatest";
179
+ }>>;
180
+ items: z.ZodOptional<z.ZodArray<z.ZodObject<{
181
+ role: z.ZodString;
182
+ rank: z.ZodNumber;
183
+ label: z.ZodOptional<z.ZodString>;
184
+ }, z.core.$strict>>>;
185
+ onRequest: z.ZodOptional<z.ZodBoolean>;
186
+ }, z.core.$strict>>;
187
+ }, z.core.$strict>;
188
+ words: z.ZodObject<{
189
+ relations: z.ZodObject<{
190
+ dependency: z.ZodObject<{
191
+ outgoing: z.ZodString;
192
+ incoming: z.ZodString;
193
+ }, z.core.$strict>;
194
+ subtask: z.ZodObject<{
195
+ outgoing: z.ZodString;
196
+ incoming: z.ZodString;
197
+ }, z.core.$strict>;
198
+ duplicate: z.ZodObject<{
199
+ outgoing: z.ZodString;
200
+ incoming: z.ZodString;
201
+ }, z.core.$strict>;
202
+ related: z.ZodString;
203
+ }, z.core.$strict>;
204
+ priorities: z.ZodObject<{
205
+ urgent: z.ZodObject<{
206
+ word: z.ZodString;
207
+ initial: z.ZodString;
208
+ }, z.core.$strict>;
209
+ high: z.ZodObject<{
210
+ word: z.ZodString;
211
+ initial: z.ZodString;
212
+ }, z.core.$strict>;
213
+ medium: z.ZodObject<{
214
+ word: z.ZodString;
215
+ initial: z.ZodString;
216
+ }, z.core.$strict>;
217
+ low: z.ZodObject<{
218
+ word: z.ZodString;
219
+ initial: z.ZodString;
220
+ }, z.core.$strict>;
221
+ }, z.core.$strict>;
222
+ }, z.core.$strict>;
223
+ glyphs: z.ZodObject<{
224
+ claimHolder: z.ZodObject<{
225
+ thisSession: z.ZodObject<{
226
+ glyph: z.ZodString;
227
+ words: z.ZodString;
228
+ }, z.core.$strict>;
229
+ otherHolder: z.ZodObject<{
230
+ glyph: z.ZodString;
231
+ words: z.ZodString;
232
+ }, z.core.$strict>;
233
+ unknownOwnership: z.ZodObject<{
234
+ glyph: z.ZodString;
235
+ words: z.ZodString;
236
+ }, z.core.$strict>;
237
+ }, z.core.$strict>;
238
+ }, z.core.$strict>;
239
+ }, z.core.$strict>;
166
240
  schemas: z.ZodObject<{
167
241
  $schema: z.ZodLiteral<"http://json-schema.org/draft-07/schema#">;
168
242
  definitions: z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
@@ -2,7 +2,50 @@ import { z } from "zod";
2
2
  import { commandInputSchema, inputOptionsSchema, invocation } from "./input.js";
3
3
  import { commandResultSchema, resultReferenceSchema } from "./results.js";
4
4
  import { commandEffectsSchema, commandConfirmationSchema } from "./types.js";
5
+ import { views } from "./views.js";
5
6
  export const jsonValueSchema = z.json();
7
+ const viewRank = z.number().int().nonnegative();
8
+ const viewItemSchema = z.strictObject({
9
+ role: z.string(),
10
+ rank: viewRank,
11
+ label: z.string().optional(),
12
+ });
13
+ const viewSectionSchema = z.strictObject({
14
+ id: z.string(),
15
+ rank: viewRank,
16
+ heading: z.string().optional(),
17
+ short: z.enum(["firstParagraph", "keys", "countAndLatest"]).optional(),
18
+ items: z.array(viewItemSchema).optional(),
19
+ onRequest: z.boolean().optional(),
20
+ });
21
+ const relationWordsSchema = z.strictObject({ outgoing: z.string(), incoming: z.string() });
22
+ const priorityWordsSchema = z.strictObject({ word: z.string(), initial: z.string() });
23
+ const claimHolderGlyphSchema = z.strictObject({ glyph: z.string(), words: z.string() });
24
+ const viewsSchema = z.strictObject({
25
+ version: z.literal(views.version),
26
+ taskDetail: z.strictObject({ sections: z.array(viewSectionSchema).min(1) }),
27
+ words: z.strictObject({
28
+ relations: z.strictObject({
29
+ dependency: relationWordsSchema,
30
+ subtask: relationWordsSchema,
31
+ duplicate: relationWordsSchema,
32
+ related: z.string(),
33
+ }),
34
+ priorities: z.strictObject({
35
+ urgent: priorityWordsSchema,
36
+ high: priorityWordsSchema,
37
+ medium: priorityWordsSchema,
38
+ low: priorityWordsSchema,
39
+ }),
40
+ }),
41
+ glyphs: z.strictObject({
42
+ claimHolder: z.strictObject({
43
+ thisSession: claimHolderGlyphSchema,
44
+ otherHolder: claimHolderGlyphSchema,
45
+ unknownOwnership: claimHolderGlyphSchema,
46
+ }),
47
+ }),
48
+ });
6
49
  export const capabilitiesSchema = z.strictObject({
7
50
  manifestVersion: z.literal(1),
8
51
  cli: z.strictObject({ name: z.string(), version: z.string() }),
@@ -51,6 +94,7 @@ export const capabilitiesSchema = z.strictObject({
51
94
  exitCode: z.literal(1),
52
95
  stream: z.literal("stderr"),
53
96
  }),
97
+ views: viewsSchema,
54
98
  schemas: z.strictObject({
55
99
  $schema: z.literal("http://json-schema.org/draft-07/schema#"),
56
100
  // Schema documents contain JSON values rather than another manifest instance.
@@ -1,6 +1,7 @@
1
1
  import type { ParsedRoute } from "./types.js";
2
2
  import { invocation } from "./input.js";
3
3
  import { generateResultSchemas } from "./result-schemas.js";
4
+ import { views } from "./views.js";
4
5
  export type Capabilities = {
5
6
  manifestVersion: 1;
6
7
  cli: {
@@ -16,6 +17,7 @@ export type Capabilities = {
16
17
  exitCode: 1;
17
18
  stream: "stderr";
18
19
  };
20
+ views: typeof views;
19
21
  schemas: ReturnType<typeof generateResultSchemas>;
20
22
  };
21
23
  export declare function getCapabilitySummary(): {
@@ -1,6 +1,7 @@
1
1
  import { invocation } from "./input.js";
2
2
  import { generateResultSchemas } from "./result-schemas.js";
3
3
  import { parsedRoutes } from "./routes/routes.js";
4
+ import { views } from "./views.js";
4
5
  import packageJson from "../package.json" with { type: "json" };
5
6
  export function getCapabilitySummary() {
6
7
  return {
@@ -25,6 +26,7 @@ export function generateCapabilities() {
25
26
  results,
26
27
  })),
27
28
  error: { schemaRef: "#/schemas/definitions/ErrorEnvelope", exitCode: 1, stream: "stderr" },
29
+ views,
28
30
  schemas: generateResultSchemas(),
29
31
  };
30
32
  }
@@ -2,7 +2,7 @@ import { parseArgs } from "node:util";
2
2
  import { column, columnCreateSchema, parseTaskKey } from "@zinn-dev/core";
3
3
  import { classifyFailure } from "./errors.js";
4
4
  import { routerOptions, getOptionInputs, isRouterFlag, splitAtOptionSeparator, violatesConstraint, } from "./input.js";
5
- import { formatCommand, UsageError, validateUniqueOptions } from "./lib.js";
5
+ import { formatCommand, parseOptionArgs, UsageError } from "./lib.js";
6
6
  import { chooseProjectKey } from "./project.js";
7
7
  function isEligible(error, command) {
8
8
  const failure = classifyFailure(error);
@@ -77,14 +77,7 @@ export function quotedColumnHint(error, route, rawArgs, routeWordCount) {
77
77
  }
78
78
  const args = rawArgs.slice(argumentStart);
79
79
  const options = { ...route.input.options, ...routerOptions };
80
- const { tokens, values } = parseArgs({
81
- args,
82
- options,
83
- allowPositionals: true,
84
- strict: true,
85
- tokens: true,
86
- });
87
- validateUniqueOptions(tokens, options);
80
+ const { tokens, values } = parseOptionArgs(args, options);
88
81
  const optionInputs = getOptionInputs(values);
89
82
  const hasMissingOption = Object.entries(route.input.options).some(([name, option]) => option.required && values[name] === undefined);
90
83
  const hasInvalidChoice = Object.entries(route.input.options).some(([name, option]) => {
package/src/errors.d.ts CHANGED
@@ -210,6 +210,7 @@ export declare class CliError extends Error {
210
210
  readonly suggestedRoute?: Array<string> | undefined;
211
211
  /** The process exit code, when it is not the usual 1 */
212
212
  exitCode?: number;
213
+ omitTextHelp: boolean;
213
214
  constructor(message: string, code?: ErrorCode, details?: ErrorDetails | undefined, help?: string | undefined, suggestedRoute?: Array<string> | undefined, cause?: unknown);
214
215
  }
215
216
  /** Recovery text and its single suggested route, when one is identified. */
package/src/errors.js CHANGED
@@ -120,6 +120,7 @@ export class CliError extends Error {
120
120
  suggestedRoute;
121
121
  /** The process exit code, when it is not the usual 1 */
122
122
  exitCode;
123
+ omitTextHelp = false;
123
124
  constructor(message, code = "invalid_input", details, help, suggestedRoute, cause) {
124
125
  super(message, cause === undefined ? undefined : { cause });
125
126
  this.code = code;
package/src/input.d.ts CHANGED
@@ -12,6 +12,7 @@ export declare const inputOptionSchema: z.ZodObject<{
12
12
  string: "string";
13
13
  boolean: "boolean";
14
14
  }>;
15
+ aliases: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
15
16
  short: z.ZodOptional<z.ZodString>;
16
17
  multiple: z.ZodOptional<z.ZodBoolean>;
17
18
  default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodArray<z.ZodBoolean>]>>;
@@ -31,6 +32,7 @@ export declare const inputOptionsSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
31
32
  string: "string";
32
33
  boolean: "boolean";
33
34
  }>;
35
+ aliases: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
34
36
  short: z.ZodOptional<z.ZodString>;
35
37
  multiple: z.ZodOptional<z.ZodBoolean>;
36
38
  default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodArray<z.ZodBoolean>]>>;
@@ -96,6 +98,7 @@ export declare const commandInputSchema: z.ZodObject<{
96
98
  string: "string";
97
99
  boolean: "boolean";
98
100
  }>;
101
+ aliases: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
99
102
  short: z.ZodOptional<z.ZodString>;
100
103
  multiple: z.ZodOptional<z.ZodBoolean>;
101
104
  default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodArray<z.ZodBoolean>]>>;
@@ -151,6 +154,33 @@ export type InputForm = z.infer<typeof inputFormSchema>;
151
154
  export type InputReference = z.infer<typeof inputReferenceSchema>;
152
155
  export type InputConstraint = z.infer<typeof inputConstraintSchema>;
153
156
  export type CommandInput = z.infer<typeof commandInputSchema>;
157
+ export declare function optionAliasEntries(options: InputOptions): (readonly [string, string])[];
158
+ /** Lets `parseArgs` recognize and tokenize the spelling the caller used */
159
+ export declare function parseArgsOptions(options: InputOptions, aliases?: (readonly [string, string])[]): {
160
+ [x: string]: {
161
+ type: "string" | "boolean";
162
+ aliases?: readonly string[] | undefined;
163
+ short?: string | undefined;
164
+ multiple?: boolean | undefined;
165
+ default?: string | boolean | string[] | boolean[] | undefined;
166
+ required?: boolean | undefined;
167
+ value?: {
168
+ kind: string;
169
+ name?: string | undefined;
170
+ choices?: readonly string[] | undefined;
171
+ caseInsensitive?: boolean | undefined;
172
+ pattern?: string | undefined;
173
+ description?: string | undefined;
174
+ } | undefined;
175
+ description?: string | undefined;
176
+ } | {
177
+ type: "string" | "boolean";
178
+ multiple?: undefined;
179
+ } | {
180
+ type: "string" | "boolean";
181
+ multiple: boolean;
182
+ };
183
+ };
154
184
  export declare const taskKeyPositional: {
155
185
  readonly name: "task-key";
156
186
  readonly min: 1;
package/src/input.js CHANGED
@@ -9,6 +9,7 @@ export const inputValueSchema = z.strictObject({
9
9
  });
10
10
  export const inputOptionSchema = z.strictObject({
11
11
  type: z.enum(["string", "boolean"]),
12
+ aliases: z.array(z.string()).readonly().optional(),
12
13
  short: z.string().optional(),
13
14
  multiple: z.boolean().optional(),
14
15
  default: z.union([z.string(), z.boolean(), z.array(z.string()), z.array(z.boolean())]).optional(),
@@ -48,6 +49,23 @@ export const commandInputSchema = z.strictObject({
48
49
  constraints: z.array(inputConstraintSchema).readonly(),
49
50
  notes: z.array(z.string()).readonly().optional(),
50
51
  });
52
+ export function optionAliasEntries(options) {
53
+ return Object.entries(options).flatMap(([name, option]) => (option.aliases ?? []).map((alias) => [alias, name]));
54
+ }
55
+ /** Lets `parseArgs` recognize and tokenize the spelling the caller used */
56
+ export function parseArgsOptions(options, aliases = optionAliasEntries(options)) {
57
+ if (aliases.length === 0) {
58
+ return options;
59
+ }
60
+ return {
61
+ ...options,
62
+ ...Object.fromEntries(aliases.map(([alias, name]) => {
63
+ const { type, multiple } = options[name];
64
+ // Node's parseArgs rejects a multiple key that is present but not a boolean.
65
+ return [alias, multiple === undefined ? { type } : { type, multiple }];
66
+ })),
67
+ };
68
+ }
51
69
  export const taskKeyPositional = {
52
70
  name: "task-key",
53
71
  min: 1,
package/src/lib.d.ts CHANGED
@@ -1,9 +1,18 @@
1
1
  import type { ParseArgsOptionsConfig } from "node:util";
2
- import type { InputForm, InputOptions, InputOption } from "./input.js";
2
+ import type { CommandInput, InputForm, InputOptions, InputOption } from "./input.js";
3
3
  import type { ErrorDetails } from "./errors.js";
4
+ import type { FlagCorrection } from "./types.js";
4
5
  import { parseArgs } from "node:util";
5
6
  import { CliError } from "./errors.js";
6
7
  type ParsedTokens = NonNullable<ReturnType<typeof parseArgs>["tokens"]>;
8
+ /** What strict parseArgs with tokens returns for these options */
9
+ type ParsedCommandArgs<Options extends ParseArgsOptionsConfig> = ReturnType<typeof parseArgs<{
10
+ args: Array<string>;
11
+ options: Options;
12
+ allowPositionals: true;
13
+ strict: true;
14
+ tokens: true;
15
+ }>>;
7
16
  type OutputMode = "text" | "json";
8
17
  /** Keeps recovery guidance outside the shortened reason and never clips a repair command. */
9
18
  export declare function boundParserMessage(message: string, options?: {
@@ -57,7 +66,67 @@ export declare class UsageError extends CliError {
57
66
  */
58
67
  export declare function validatePositionals(positionals: Array<string>, form: InputForm): void;
59
68
  export declare function validateTaskKey(taskKey: string): void;
60
- export declare function validateUniqueOptions(tokens: ParsedTokens, options: InputOptions): void;
69
+ /** `typedSpellings` maps an argument index to the flag the caller typed there, when it differs from the token name */
70
+ export declare function validateUniqueOptions(tokens: ParsedTokens, options: InputOptions, typedSpellings?: Map<number, string>): void;
71
+ /** Parses command options and collects positionals before checking their form. */
72
+ export declare function parseOptionArgs<Options extends InputOptions>(args: Array<string>, options: Options): ParsedCommandArgs<Options>;
73
+ /** Checks the positionals of a command with a single form. With several forms the caller selects one. */
74
+ export declare function parseCommandArgs<Input extends CommandInput>(args: Array<string>, input: Input): {
75
+ values: Input["options"] extends ParseArgsOptionsConfig ? (Input["options"] extends infer T extends ParseArgsOptionsConfig ? { -readonly [LongOption in keyof T]?: V[LongOption] | undefined; } : never) & (Input["options"] extends infer T_1 extends ParseArgsOptionsConfig ? { [LongOption_1 in keyof T_1 as Input["options"][LongOption_1]["default"] extends {} ? LongOption_1 : never]: V[LongOption_1]; } : never) extends infer P ? { [K in keyof P]: P[K]; } : never : {};
76
+ positionals: string[];
77
+ tokens: ({
78
+ kind: "positional";
79
+ index: number;
80
+ value: string;
81
+ } | {
82
+ kind: "option-terminator";
83
+ index: number;
84
+ } | (keyof Input["options"] extends infer T_2 ? T_2 extends keyof Input["options"] ? T_2 extends unknown ? Input["options"] extends ParseArgsOptionsConfig ? Input["options"][T_2]["type"] extends "string" ? {
85
+ kind: "option";
86
+ index: number;
87
+ name: T_2 & string;
88
+ rawName: string;
89
+ value: string;
90
+ inlineValue: boolean;
91
+ } : Input["options"][T_2]["type"] extends "boolean" ? {
92
+ kind: "option";
93
+ index: number;
94
+ name: T_2 & string;
95
+ rawName: string;
96
+ value: undefined;
97
+ inlineValue: undefined;
98
+ } : ({
99
+ kind: "option";
100
+ index: number;
101
+ name: string;
102
+ rawName: string;
103
+ value: string;
104
+ inlineValue: boolean;
105
+ } | {
106
+ kind: "option";
107
+ index: number;
108
+ name: string;
109
+ rawName: string;
110
+ value: undefined;
111
+ inlineValue: undefined;
112
+ }) & {
113
+ name: T_2 & string;
114
+ } : {
115
+ kind: "option";
116
+ index: number;
117
+ name: string;
118
+ rawName: string;
119
+ value: string;
120
+ inlineValue: boolean;
121
+ } | {
122
+ kind: "option";
123
+ index: number;
124
+ name: string;
125
+ rawName: string;
126
+ value: undefined;
127
+ inlineValue: undefined;
128
+ } : never : never : never))[];
129
+ };
61
130
  /** The choices a positional accepts; positionals without choices contribute never. */
62
131
  type PositionalChoices<Positional> = Positional extends {
63
132
  value: {
@@ -93,10 +162,9 @@ export declare function shellQuote(word: string): string;
93
162
  /** A command line to show, with each word quoted for the shell as needed. */
94
163
  export declare function formatCommand(args: Array<string>): string;
95
164
  /** The words of the command a user likely meant by a flag the command does not take, if known. */
96
- type SuggestFor = (flag: string) => {
97
- args: Array<string>;
165
+ type SuggestFor = (flag: string) => (FlagCorrection & {
98
166
  route: Array<string>;
99
- } | undefined;
167
+ }) | undefined;
100
168
  /** Renames an option without changing values or words after `--` */
101
169
  export declare function renameFlag(args: Array<string>, options: ParseArgsOptionsConfig, source: string, target: string): string[];
102
170
  export declare function isParseArgsError(error: any): boolean;
package/src/lib.js CHANGED
@@ -6,7 +6,7 @@ import { z } from "zod";
6
6
  import { assertWritable, getFailedUpgradeBackupPath, parseTaskKey, InputValidationError, } from "@zinn-dev/core";
7
7
  import { CliError, classifyFailure, recoveryHint } from "./errors.js";
8
8
  import { writeFailureLog } from "./failure-log.js";
9
- import { isJsonFlag, isRouterFlag, OPTION_SEPARATOR, positionalWords, splitAtOptionSeparator, } from "./input.js";
9
+ import { isJsonFlag, isRouterFlag, optionAliasEntries, OPTION_SEPARATOR, parseArgsOptions, positionalWords, splitAtOptionSeparator, } from "./input.js";
10
10
  import { formatParserReasonPreview } from "./presentation/description-presentation.js";
11
11
  import { writeRunRecord } from "./telemetry.js";
12
12
  let outputMode = "text";
@@ -213,7 +213,10 @@ export function renderFailure(reason) {
213
213
  for (const message of pendingDiagnostics) {
214
214
  console.error(message);
215
215
  }
216
- console.error(failure.help == null ? failure.message : `${failure.message}\n\n${failure.help}`);
216
+ const omitTextHelp = reason instanceof CliError && reason.omitTextHelp;
217
+ console.error(failure.help == null || omitTextHelp
218
+ ? failure.message
219
+ : `${failure.message}\n\n${failure.help}`);
217
220
  if (logPath !== undefined) {
218
221
  console.error(`Full log: ${logPath}`);
219
222
  }
@@ -259,22 +262,71 @@ export function validateTaskKey(taskKey) {
259
262
  });
260
263
  }
261
264
  }
262
- export function validateUniqueOptions(tokens, options) {
265
+ /** `typedSpellings` maps an argument index to the flag the caller typed there, when it differs from the token name */
266
+ export function validateUniqueOptions(tokens, options, typedSpellings = new Map()) {
263
267
  const repeatableOptions = Object.keys(options).filter((name) => options[name].multiple);
264
- const parsedArgs = new Set();
268
+ const firstSpellings = new Map();
265
269
  for (const token of tokens) {
266
270
  if (token.kind !== "option") {
267
271
  continue;
268
272
  }
273
+ const spelling = typedSpellings.get(token.index) ?? `--${token.name}`;
274
+ const firstSpelling = firstSpellings.get(token.name);
269
275
  const isRepeatable = repeatableOptions.includes(token.name);
270
- if (parsedArgs.has(token.name) && !isRepeatable) {
271
- quit(`Option "--${token.name}" can only be specified once`, undefined, {
272
- argument: `--${token.name}`,
273
- });
276
+ if (firstSpelling !== undefined && !isRepeatable) {
277
+ const message = firstSpelling === spelling
278
+ ? `Option "${spelling}" can only be specified once`
279
+ : `Options "${firstSpelling}" and "${spelling}" are the same option, which can only be specified once`;
280
+ quit(message, undefined, { argument: `--${token.name}` });
274
281
  }
275
- parsedArgs.add(token.name);
282
+ firstSpellings.set(token.name, spelling);
276
283
  }
277
284
  }
285
+ /** Parses command options and collects positionals before checking their form. */
286
+ export function parseOptionArgs(args, options) {
287
+ const parse = (words, spellings) => parseArgs({
288
+ args: words,
289
+ options: spellings,
290
+ allowPositionals: true,
291
+ strict: true,
292
+ tokens: true,
293
+ });
294
+ const aliases = optionAliasEntries(options);
295
+ let parsed = parse(args, parseArgsOptions(options, aliases));
296
+ let typedSpellings;
297
+ if (aliases.length > 0) {
298
+ const aliasNames = new Map(aliases);
299
+ let canonicalArgs;
300
+ typedSpellings = new Map();
301
+ for (const token of parsed.tokens) {
302
+ if (token.kind !== "option") {
303
+ continue;
304
+ }
305
+ const name = aliasNames.get(token.name);
306
+ if (name !== undefined) {
307
+ canonicalArgs ??= [...args];
308
+ typedSpellings.set(token.index, token.rawName);
309
+ canonicalArgs[token.index] = `--${name}${token.inlineValue ? `=${token.value}` : ""}`;
310
+ }
311
+ }
312
+ // Merge both spellings before checking duplicates and passing values to the command.
313
+ if (canonicalArgs !== undefined) {
314
+ parsed = parse(canonicalArgs, options);
315
+ }
316
+ }
317
+ validateUniqueOptions(parsed.tokens, options, typedSpellings);
318
+ // TypeScript widens the result inside this generic function, but callers get the precise type.
319
+ return parsed;
320
+ }
321
+ /** Checks the positionals of a command with a single form. With several forms the caller selects one. */
322
+ export function parseCommandArgs(args, input) {
323
+ const parsed = parseOptionArgs(args, input.options);
324
+ const [onlyForm] = input.forms;
325
+ if (onlyForm !== undefined && input.forms.length === 1) {
326
+ validatePositionals(parsed.positionals, onlyForm);
327
+ }
328
+ return parsed;
329
+ }
278
330
  /** Selects an order form after checking its required leading words. */
279
331
  export function validateOrderForms(positionals, forms) {
280
332
  const firstForm = forms[0];
@@ -418,13 +470,15 @@ function unknownOptionMessage(message, args, suggestFor, route) {
418
470
  return { message: boundParserMessage(reason) };
419
471
  }
420
472
  const { optionWords, passthroughWords } = splitAtOptionSeparator(suggestion.args);
421
- const correctedArgs = [...optionWords, ...args.filter(isRouterFlag), ...passthroughWords];
473
+ const routerFlags = splitAtOptionSeparator(args).optionWords.filter(isRouterFlag);
474
+ const correctedArgs = [...optionWords, ...routerFlags, ...passthroughWords];
422
475
  return {
423
476
  message: boundParserMessage(`${reason}. Did you mean: ${formatCommand(correctedArgs)}`, {
424
- reason,
425
- guidance: "See usage for accepted arguments. Full command omitted because it is long.",
477
+ reason: `${reason}.`,
478
+ guidance: `${suggestion.guidance} Full command omitted because it is long.`,
426
479
  }),
427
480
  suggestedRoute: suggestion.route,
481
+ omitTextHelp: true,
428
482
  };
429
483
  }
430
484
  // Commands define no short options, so `parseArgs` refused the first single-dash word before `--`.
@@ -481,7 +535,9 @@ export function parseArgsFailure(error, args, suggestFor, route, options) {
481
535
  const argument = /(?:Unknown option|Option) '(-[^' ]+)/.exec(error.message)?.[1];
482
536
  if (code === "ERR_PARSE_ARGS_UNKNOWN_OPTION") {
483
537
  const hint = unknownOptionMessage(error.message, args, suggestFor, route);
484
- return new CliError(hint.message, "invalid_input", { argument, reason: "unknown_option" }, undefined, hint.suggestedRoute);
538
+ const failure = new CliError(hint.message, "invalid_input", { argument, reason: "unknown_option" }, undefined, hint.suggestedRoute);
539
+ failure.omitTextHelp = hint.omitTextHelp ?? false;
540
+ return failure;
485
541
  }
486
542
  const dashMessage = dashValueMessage(error, args, options);
487
543
  const isMissingValue = code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE" && / argument missing$/.test(error.message);
@@ -1,5 +1,6 @@
1
1
  import type { Activity, ActivityTaskIdentity, Actor } from "@zinn-dev/core";
2
2
  import type { PresentedActor } from "../result-schemas.js";
3
+ import type { TerminalProps } from "./color.js";
3
4
  type NavigationIdentity = {
4
5
  /** Undefined when the entity no longer exists and this event recorded no name for it. */
5
6
  name?: string;
@@ -31,5 +32,5 @@ export declare function formatActor(actor: PresentedActor): string;
31
32
  export declare function formatActorLabel(actor: Pick<PresentedActor, "actor_name" | "actor_kind">): string;
32
33
  export declare function formatActivityList(entries: Array<PresentedActivity>, options?: {
33
34
  showsDetails?: boolean;
34
- }): string;
35
+ } & TerminalProps): string;
35
36
  export {};
@@ -483,6 +483,15 @@ function formatChangeSummary(entry, options = {}) {
483
483
  const removed = options.showsRemovedTasks === false ? "" : formatRemovedTasks(entry).join("; ");
484
484
  return [formatDescriptionPreview(summary), removed].filter((part) => part.length > 0).join("; ");
485
485
  }
486
+ function formatActivityAction(event) {
487
+ const previousExpiry = event.changes?.previous_expires_at;
488
+ const resumedExpiredClaim = event.action === "claim_heartbeat" &&
489
+ typeof previousExpiry === "number" &&
490
+ previousExpiry <= event.created_at;
491
+ return resumedExpiredClaim
492
+ ? "resumed expired claim"
493
+ : (ACTION_LABELS[event.action] ?? event.action);
494
+ }
486
495
  function formatActivityContent(entry) {
487
496
  const { event, navigation } = entry;
488
497
  const name = navigation.name ?? event.entity_id;
@@ -495,7 +504,7 @@ function formatActivityContent(entry) {
495
504
  : isMutableCurrentName
496
505
  ? " [current name]"
497
506
  : "";
498
- const action = ACTION_LABELS[event.action] ?? event.action;
507
+ const action = formatActivityAction(event);
499
508
  const summary = formatChangeSummary(entry, { showsRemovedTasks: false, omitsIdentity: true });
500
509
  const lines = [
501
510
  `${entityType}${shortName}${marker} · ${action}${summary === "-" ? "" : `: ${summary}`}`,
@@ -596,7 +605,11 @@ export function formatActivityList(entries, options = {}) {
596
605
  return [
597
606
  ...metadata,
598
607
  { text: formatNavigation(entry, { showsFullNames: true }) },
599
- { text: entry.event.action },
608
+ {
609
+ text: entry.event.action === "claim_heartbeat"
610
+ ? `${entry.event.action} (${formatActivityAction(entry.event)})`
611
+ : entry.event.action,
612
+ },
600
613
  { text: formatChangeSummary(entry) },
601
614
  ];
602
615
  });
@@ -606,12 +619,14 @@ export function formatActivityList(entries, options = {}) {
606
619
  return entries
607
620
  .map((entry, index) => [
608
621
  formatRows([rows[index]]),
609
- formatSection("Entity", `${entry.event.entity_type} ${entry.event.entity_id}`),
622
+ formatSection("Entity", `${entry.event.entity_type} ${entry.event.entity_id}`, options),
610
623
  ...(entry.navigation.name === undefined
611
624
  ? []
612
- : [formatSection("Navigation", formatNavigation(entry, { showsFullNames: true }))]),
613
- formatSection("Actor", formatActor(entry.event)),
614
- formatSection("Changes", formatRecordedChanges(entry.event)),
625
+ : [
626
+ formatSection("Navigation", formatNavigation(entry, { showsFullNames: true }), options),
627
+ ]),
628
+ formatSection("Actor", formatActor(entry.event), options),
629
+ formatSection("Changes", formatRecordedChanges(entry.event), options),
615
630
  ].join("\n\n"))
616
631
  .join("\n\n");
617
632
  }