@zinn-dev/cli 0.41.0 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +11 -689
  2. package/index.js +2 -2
  3. package/package.json +3 -2
  4. package/skills/zinn/SKILL.md +1 -1
  5. package/src/capabilities-schema.d.ts +22 -23
  6. package/src/capabilities-schema.js +17 -82
  7. package/src/capabilities.d.ts +11 -3
  8. package/src/capabilities.js +12 -4
  9. package/src/column-hint.d.ts +3 -0
  10. package/src/column-hint.js +225 -0
  11. package/src/database.js +1 -4
  12. package/src/errors.js +2 -0
  13. package/src/input.d.ts +154 -43
  14. package/src/input.js +86 -13
  15. package/src/lib.d.ts +30 -2
  16. package/src/lib.js +74 -13
  17. package/src/presentation/activity-presentation.d.ts +9 -1
  18. package/src/presentation/activity-presentation.js +108 -25
  19. package/src/presentation/capabilities-presentation.d.ts +2 -0
  20. package/src/presentation/capabilities-presentation.js +3 -0
  21. package/src/presentation/column-presentation.d.ts +6 -0
  22. package/src/presentation/column-presentation.js +10 -0
  23. package/src/presentation/comment-presentation.d.ts +15 -0
  24. package/src/presentation/comment-presentation.js +29 -0
  25. package/src/presentation/description-presentation.d.ts +17 -0
  26. package/src/presentation/description-presentation.js +26 -4
  27. package/src/presentation/label-presentation.d.ts +8 -0
  28. package/src/presentation/label-presentation.js +28 -0
  29. package/src/presentation/project-presentation.d.ts +7 -0
  30. package/src/presentation/project-presentation.js +19 -0
  31. package/src/presentation/relation-presentation.d.ts +7 -0
  32. package/src/presentation/relation-presentation.js +73 -0
  33. package/src/presentation/task-presentation.d.ts +3 -3
  34. package/src/presentation/task-presentation.js +22 -18
  35. package/src/project.d.ts +14 -5
  36. package/src/project.js +18 -6
  37. package/src/result-schemas.d.ts +230 -23
  38. package/src/result-schemas.js +62 -3
  39. package/src/results.d.ts +34 -17
  40. package/src/results.js +19 -0
  41. package/src/routes/activity-router.d.ts +34 -1
  42. package/src/routes/activity-router.js +104 -31
  43. package/src/routes/aliases.d.ts +2 -0
  44. package/src/routes/aliases.js +11 -0
  45. package/src/routes/capabilities-router.js +9 -3
  46. package/src/routes/comment-router.d.ts +41 -18
  47. package/src/routes/comment-router.js +65 -48
  48. package/src/routes/label-router.d.ts +57 -7
  49. package/src/routes/label-router.js +84 -39
  50. package/src/routes/project-router.d.ts +34 -12
  51. package/src/routes/project-router.js +59 -55
  52. package/src/routes/relation-router.d.ts +6 -6
  53. package/src/routes/relation-router.js +52 -69
  54. package/src/routes/restore-router.js +1 -1
  55. package/src/routes/router.d.ts +1 -1
  56. package/src/routes/router.js +38 -9
  57. package/src/routes/routes.d.ts +253 -45
  58. package/src/routes/routes.js +4 -0
  59. package/src/routes/task-router.d.ts +107 -26
  60. package/src/routes/task-router.js +151 -143
  61. package/src/routes/whoami-router.d.ts +21 -0
  62. package/src/routes/whoami-router.js +31 -0
  63. package/src/text-edit.d.ts +13 -9
  64. package/src/text-edit.js +23 -18
  65. package/src/text-input.d.ts +47 -0
  66. package/src/text-input.js +187 -0
  67. package/src/types.d.ts +32 -9
  68. package/src/types.js +9 -1
package/index.js CHANGED
@@ -11,8 +11,8 @@ else {
11
11
  prepareOutput(args);
12
12
  try {
13
13
  const { createRouter } = await import("./src/routes/router.js");
14
- const { routes } = await import("./src/routes/routes.js");
15
- const router = createRouter(routes, async (command) => {
14
+ const { parsedRoutes } = await import("./src/routes/routes.js");
15
+ const router = createRouter(parsedRoutes, async (command) => {
16
16
  if (command.effects.storage === "none") {
17
17
  return;
18
18
  }
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@zinn-dev/cli",
3
- "version": "0.41.0",
3
+ "version": "0.42.0",
4
4
  "description": "A kanban workflow in the terminal. Experimental.",
5
5
  "license": "MIT",
6
+ "homepage": "https://zinn.sh",
6
7
  "bugs": {
7
8
  "url": "https://github.com/yethranayeh/zinn/issues"
8
9
  },
@@ -36,7 +37,7 @@
36
37
  },
37
38
  "dependencies": {
38
39
  "zod": "4.6.4",
39
- "@zinn-dev/core": "0.30.0"
40
+ "@zinn-dev/core": "0.31.0"
40
41
  },
41
42
  "devDependencies": {
42
43
  "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.41.0"
10
+ zinn-cli-reviewed-version: "0.42.0"
11
11
  ---
12
12
 
13
13
  # Work with a Zinn board
@@ -19,7 +19,7 @@ export declare const capabilitiesSchema: z.ZodObject<{
19
19
  value: z.ZodOptional<z.ZodObject<{
20
20
  kind: z.ZodString;
21
21
  name: z.ZodOptional<z.ZodString>;
22
- choices: z.ZodOptional<z.ZodArray<z.ZodString>>;
22
+ choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
23
23
  caseInsensitive: z.ZodOptional<z.ZodBoolean>;
24
24
  pattern: z.ZodOptional<z.ZodString>;
25
25
  description: z.ZodOptional<z.ZodString>;
@@ -32,13 +32,7 @@ export declare const capabilitiesSchema: z.ZodObject<{
32
32
  singularOptions: z.ZodLiteral<"reject-repetition">;
33
33
  jsonFailure: z.ZodLiteral<"one-stderr-document-with-buffered-diagnostics">;
34
34
  jsonSuccessDiagnostics: z.ZodLiteral<"text-on-stderr-at-completion">;
35
- canonicalArgv: z.ZodArray<z.ZodEnum<{
36
- "command-path": "command-path";
37
- "options-with-equals-values": "options-with-equals-values";
38
- "--json": "--json";
39
- "separator-if-positionals": "separator-if-positionals";
40
- positionals: "positionals";
41
- }>>;
35
+ canonicalArgv: z.ZodTuple<[z.ZodLiteral<"command-path">, z.ZodLiteral<"options-with-equals-values">, z.ZodLiteral<"--json">, z.ZodLiteral<"separator-if-positionals">, z.ZodLiteral<"positionals">], null>;
42
36
  version: z.ZodObject<{
43
37
  spellings: z.ZodArray<z.ZodString>;
44
38
  placement: z.ZodLiteral<"sole-argument">;
@@ -55,6 +49,7 @@ export declare const capabilitiesSchema: z.ZodObject<{
55
49
  }, z.core.$strict>;
56
50
  commands: z.ZodArray<z.ZodObject<{
57
51
  path: z.ZodArray<z.ZodString>;
52
+ aliases: z.ZodArray<z.ZodArray<z.ZodString>>;
58
53
  summary: z.ZodString;
59
54
  input: z.ZodObject<{
60
55
  options: z.ZodRecord<z.ZodString, z.ZodObject<{
@@ -69,41 +64,45 @@ export declare const capabilitiesSchema: z.ZodObject<{
69
64
  value: z.ZodOptional<z.ZodObject<{
70
65
  kind: z.ZodString;
71
66
  name: z.ZodOptional<z.ZodString>;
72
- choices: z.ZodOptional<z.ZodArray<z.ZodString>>;
67
+ choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
73
68
  caseInsensitive: z.ZodOptional<z.ZodBoolean>;
74
69
  pattern: z.ZodOptional<z.ZodString>;
75
70
  description: z.ZodOptional<z.ZodString>;
76
71
  }, z.core.$strict>>;
77
72
  description: z.ZodOptional<z.ZodString>;
78
73
  }, z.core.$strict>>;
79
- forms: z.ZodArray<z.ZodObject<{
74
+ forms: z.ZodReadonly<z.ZodArray<z.ZodObject<{
80
75
  id: z.ZodString;
81
- positionals: z.ZodArray<z.ZodObject<{
76
+ positionals: z.ZodReadonly<z.ZodArray<z.ZodObject<{
82
77
  name: z.ZodString;
83
78
  min: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>]>;
84
79
  max: z.ZodNullable<z.ZodLiteral<1>>;
85
80
  value: z.ZodObject<{
86
81
  kind: z.ZodString;
87
82
  name: z.ZodOptional<z.ZodString>;
88
- choices: z.ZodOptional<z.ZodArray<z.ZodString>>;
83
+ choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
89
84
  caseInsensitive: z.ZodOptional<z.ZodBoolean>;
90
85
  pattern: z.ZodOptional<z.ZodString>;
91
86
  description: z.ZodOptional<z.ZodString>;
92
87
  }, z.core.$strict>;
93
- }, z.core.$strict>>;
94
- }, z.core.$strict>>;
95
- constraints: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
88
+ }, z.core.$strict>>>;
89
+ }, z.core.$strict>>>;
90
+ constraints: z.ZodReadonly<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
96
91
  kind: z.ZodLiteral<"exclusive">;
97
- members: z.ZodArray<z.ZodString>;
92
+ members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
98
93
  }, z.core.$strict>, z.ZodObject<{
99
94
  kind: z.ZodLiteral<"requires">;
100
- input: z.ZodString;
101
- requires: z.ZodString;
95
+ input: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
96
+ requires: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
97
+ }, z.core.$strict>, z.ZodObject<{
98
+ kind: z.ZodLiteral<"requiresAny">;
99
+ input: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
100
+ members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
102
101
  }, z.core.$strict>, z.ZodObject<{
103
102
  kind: z.ZodLiteral<"atLeastOne">;
104
- members: z.ZodArray<z.ZodString>;
105
- }, z.core.$strict>], "kind">>;
106
- notes: z.ZodOptional<z.ZodArray<z.ZodString>>;
103
+ members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
104
+ }, z.core.$strict>], "kind">>>;
105
+ notes: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
107
106
  }, z.core.$strict>;
108
107
  effects: z.ZodObject<{
109
108
  domain: z.ZodEnum<{
@@ -132,7 +131,7 @@ export declare const capabilitiesSchema: z.ZodObject<{
132
131
  }>;
133
132
  description: z.ZodOptional<z.ZodString>;
134
133
  }, z.core.$strict>;
135
- results: z.ZodArray<z.ZodObject<{
134
+ results: z.ZodReadonly<z.ZodArray<z.ZodObject<{
136
135
  selector: z.ZodDiscriminatedUnion<[z.ZodObject<{
137
136
  kind: z.ZodLiteral<"always">;
138
137
  }, z.core.$strict>, z.ZodObject<{
@@ -149,7 +148,7 @@ export declare const capabilitiesSchema: z.ZodObject<{
149
148
  mode: z.ZodLiteral<"json">;
150
149
  stream: z.ZodLiteral<"stdout">;
151
150
  exitCode: z.ZodLiteral<0>;
152
- }, z.core.$strict>>;
151
+ }, z.core.$strict>>>;
153
152
  }, z.core.$strict>>;
154
153
  error: z.ZodObject<{
155
154
  schemaRef: z.ZodString;
@@ -1,65 +1,26 @@
1
1
  import { z } from "zod";
2
- import { invocation } from "./input.js";
2
+ import { commandInputSchema, inputOptionsSchema, invocation } from "./input.js";
3
+ import { commandResultSchema, resultReferenceSchema } from "./results.js";
4
+ import { commandEffectsSchema, commandConfirmationSchema } from "./types.js";
3
5
  export const jsonValueSchema = z.json();
4
- const inputValue = z.strictObject({
5
- kind: z.string(),
6
- name: z.string().optional(),
7
- choices: z.array(z.string()).optional(),
8
- caseInsensitive: z.boolean().optional(),
9
- pattern: z.string().optional(),
10
- description: z.string().optional(),
11
- });
12
- const inputOption = z.strictObject({
13
- type: z.enum(["string", "boolean"]),
14
- short: z.string().optional(),
15
- multiple: z.boolean().optional(),
16
- default: z.union([z.string(), z.boolean(), z.array(z.string()), z.array(z.boolean())]).optional(),
17
- required: z.boolean().optional(),
18
- value: inputValue.optional(),
19
- description: z.string().optional(),
20
- });
21
- const options = z.record(z.string(), inputOption);
22
- const inputReference = z.string().regex(/^(option|positional):.+$/);
23
- const members = z.array(inputReference);
24
- const constraint = z.discriminatedUnion("kind", [
25
- z.strictObject({ kind: z.literal("exclusive"), members }),
26
- z.strictObject({ kind: z.literal("requires"), input: inputReference, requires: inputReference }),
27
- z.strictObject({ kind: z.literal("atLeastOne"), members }),
28
- ]);
29
- const form = z.strictObject({
30
- id: z.string(),
31
- positionals: z.array(z.strictObject({
32
- name: z.string(),
33
- min: z.union([z.literal(0), z.literal(1)]),
34
- max: z.literal(1).nullable(),
35
- value: inputValue,
36
- })),
37
- });
38
- const selector = z.discriminatedUnion("kind", [
39
- z.strictObject({ kind: z.literal("always") }),
40
- z.strictObject({ kind: z.literal("booleanOption"), name: z.string(), value: z.boolean() }),
41
- z.strictObject({
42
- kind: z.literal("positionalCount"),
43
- name: z.string(),
44
- min: z.number().int().nonnegative(),
45
- max: z.number().int().nonnegative().nullable(),
46
- }),
47
- ]);
48
- const schemaRef = z.string().regex(/^#\/schemas\/definitions\/[^/]+$/);
49
6
  export const capabilitiesSchema = z.strictObject({
50
7
  manifestVersion: z.literal(1),
51
8
  cli: z.strictObject({ name: z.string(), version: z.string() }),
52
9
  invocation: z.strictObject({
53
- routerOptions: options,
10
+ routerOptions: inputOptionsSchema,
54
11
  routerOptionPlacement: z.literal(invocation.routerOptionPlacement),
55
12
  optionSeparator: z.literal(invocation.optionSeparator),
56
13
  literalOptionValue: z.literal(invocation.literalOptionValue),
57
14
  singularOptions: z.literal(invocation.singularOptions),
58
15
  jsonFailure: z.literal(invocation.jsonFailure),
59
16
  jsonSuccessDiagnostics: z.literal(invocation.jsonSuccessDiagnostics),
60
- canonicalArgv: z
61
- .array(z.enum(invocation.canonicalArgv))
62
- .length(invocation.canonicalArgv.length),
17
+ canonicalArgv: z.tuple([
18
+ z.literal(invocation.canonicalArgv[0]),
19
+ z.literal(invocation.canonicalArgv[1]),
20
+ z.literal(invocation.canonicalArgv[2]),
21
+ z.literal(invocation.canonicalArgv[3]),
22
+ z.literal(invocation.canonicalArgv[4]),
23
+ ]),
63
24
  version: z.strictObject({
64
25
  spellings: z.array(z.string()),
65
26
  placement: z.literal(invocation.version.placement),
@@ -77,42 +38,16 @@ export const capabilitiesSchema = z.strictObject({
77
38
  commands: z
78
39
  .array(z.strictObject({
79
40
  path: z.array(z.string()).min(1),
41
+ aliases: z.array(z.array(z.string()).min(1)),
80
42
  summary: z.string(),
81
- input: z.strictObject({
82
- options,
83
- forms: z.array(form).min(1),
84
- constraints: z.array(constraint),
85
- notes: z.array(z.string()).optional(),
86
- }),
87
- effects: z.strictObject({
88
- domain: z.enum(["read", "create", "update", "delete", "replace", "none"]),
89
- storage: z.enum([
90
- "normal-open",
91
- "backup",
92
- "restore",
93
- "migrate",
94
- "reindex",
95
- "inspect",
96
- "none",
97
- ]),
98
- }),
99
- confirmation: z.strictObject({
100
- kind: z.enum(["none", "prompt", "project-delete"]),
101
- description: z.string().optional(),
102
- }),
103
- results: z
104
- .array(z.strictObject({
105
- selector,
106
- schemaRef,
107
- mode: z.literal("json"),
108
- stream: z.literal("stdout"),
109
- exitCode: z.literal(0),
110
- }))
111
- .min(1),
43
+ input: commandInputSchema,
44
+ effects: commandEffectsSchema,
45
+ confirmation: commandConfirmationSchema,
46
+ results: z.array(commandResultSchema).min(1).readonly(),
112
47
  }))
113
48
  .min(1),
114
49
  error: z.strictObject({
115
- schemaRef,
50
+ schemaRef: resultReferenceSchema,
116
51
  exitCode: z.literal(1),
117
52
  stream: z.literal("stderr"),
118
53
  }),
@@ -1,4 +1,4 @@
1
- import type { Command } from "./types.js";
1
+ import type { ParsedRoute } from "./types.js";
2
2
  import { invocation } from "./input.js";
3
3
  import { generateResultSchemas } from "./result-schemas.js";
4
4
  export type Capabilities = {
@@ -8,8 +8,8 @@ export type Capabilities = {
8
8
  version: string;
9
9
  };
10
10
  invocation: typeof invocation;
11
- commands: Array<Pick<Command, "summary" | "input" | "effects" | "confirmation" | "results"> & {
12
- path: string[];
11
+ commands: Array<Pick<ParsedRoute, "aliases" | "summary" | "input" | "effects" | "confirmation" | "results"> & {
12
+ path: Array<string>;
13
13
  }>;
14
14
  error: {
15
15
  schemaRef: "#/schemas/definitions/ErrorEnvelope";
@@ -18,4 +18,12 @@ export type Capabilities = {
18
18
  };
19
19
  schemas: ReturnType<typeof generateResultSchemas>;
20
20
  };
21
+ export declare function getCapabilitySummary(): {
22
+ cli: {
23
+ name: string;
24
+ version: string;
25
+ };
26
+ commandCount: number;
27
+ manifestVersion: number;
28
+ };
21
29
  export declare function generateCapabilities(): Capabilities;
@@ -1,15 +1,23 @@
1
1
  import { invocation } from "./input.js";
2
2
  import { generateResultSchemas } from "./result-schemas.js";
3
- import { parseRoutes } from "./routes/router.js";
4
- import { routes } from "./routes/routes.js";
3
+ import { parsedRoutes } from "./routes/routes.js";
5
4
  import packageJson from "../package.json" with { type: "json" };
5
+ export function getCapabilitySummary() {
6
+ return {
7
+ cli: { name: packageJson.name, version: packageJson.version },
8
+ commandCount: parsedRoutes.length,
9
+ manifestVersion: 1,
10
+ };
11
+ }
6
12
  export function generateCapabilities() {
13
+ const { cli } = getCapabilitySummary();
7
14
  return {
8
15
  manifestVersion: 1,
9
- cli: { name: packageJson.name, version: packageJson.version },
16
+ cli,
10
17
  invocation,
11
- commands: parseRoutes(routes).map(({ command, summary, input, effects, confirmation, results }) => ({
18
+ commands: parsedRoutes.map(({ command, aliases, summary, input, effects, confirmation, results }) => ({
12
19
  path: command.split(" "),
20
+ aliases,
13
21
  summary,
14
22
  input,
15
23
  effects,
@@ -0,0 +1,3 @@
1
+ import type { ParsedRoute } from "./types.js";
2
+ /** Recognizes only checked split-column mistakes after an invocation has failed. */
3
+ export declare function quotedColumnHint(error: unknown, route: ParsedRoute, rawArgs: string[], routeWordCount: number): string | undefined;
@@ -0,0 +1,225 @@
1
+ import { parseArgs } from "node:util";
2
+ import { column, columnCreateSchema, parseTaskKey } from "@zinn-dev/core";
3
+ import { classifyFailure } from "./errors.js";
4
+ import { routerOptions, getOptionInputs, violatesConstraint } from "./input.js";
5
+ import { formatCommand, isAllowLegacyReadFlag, isRouterFlag, UsageError, validateUniqueOptions, } from "./lib.js";
6
+ import { chooseProjectKey } from "./project.js";
7
+ function isEligible(error, command) {
8
+ const failure = classifyFailure(error);
9
+ const isExtraWord = error instanceof UsageError && failure.details?.field?.length === 0;
10
+ const isMissingProject = failure.code === "not_found" && failure.details?.entity === "project";
11
+ const isUsageErrorFor = (argument) => error instanceof UsageError && failure.details?.argument === argument;
12
+ switch (command) {
13
+ case "project column create":
14
+ case "project column edit":
15
+ return isExtraWord;
16
+ case "project column order":
17
+ return isExtraWord || isUsageErrorFor("direction");
18
+ case "task create":
19
+ case "task list":
20
+ return isExtraWord || isMissingProject || isUsageErrorFor("--all-projects");
21
+ case "task move": {
22
+ const isMissingEntity = failure.code === "not_found" &&
23
+ ["column", "task", "project"].includes(failure.details?.entity ?? "");
24
+ const isInvalidTaskKey = failure.code === "invalid_input" && failure.details?.field?.[0] === "taskKey";
25
+ return isMissingEntity || isInvalidTaskKey;
26
+ }
27
+ default:
28
+ return false;
29
+ }
30
+ }
31
+ function joinWords(words) {
32
+ const first = words[0];
33
+ const isContiguous = first !== undefined && words.every((word, offset) => word.index === first.index + offset);
34
+ if (!isContiguous || words.length < 2) {
35
+ return undefined;
36
+ }
37
+ return {
38
+ start: first.index,
39
+ end: words.at(-1).index + 1,
40
+ value: words.map((word) => word.value).join(" "),
41
+ };
42
+ }
43
+ function hasColumn(context, projectKey, name) {
44
+ const parsedName = columnCreateSchema.shape.name.safeParse(name);
45
+ if (!parsedName.success) {
46
+ return false;
47
+ }
48
+ const project = context.projects.find((entry) => entry.key === projectKey.toUpperCase());
49
+ if (project === undefined) {
50
+ return false;
51
+ }
52
+ return project.columns.some((columnName) => columnName.toLowerCase() === parsedName.data.toLowerCase());
53
+ }
54
+ function applyMerges(args, merges) {
55
+ const corrected = [...args];
56
+ for (const merge of [...merges].sort((left, right) => right.start - left.start)) {
57
+ corrected.splice(merge.start, merge.end - merge.start, merge.value);
58
+ }
59
+ return corrected;
60
+ }
61
+ /** Recognizes only checked split-column mistakes after an invocation has failed. */
62
+ export function quotedColumnHint(error, route, rawArgs, routeWordCount) {
63
+ if (!isEligible(error, route.command)) {
64
+ return undefined;
65
+ }
66
+ try {
67
+ let argumentStart = 0;
68
+ let wordsSeen = 0;
69
+ for (const [index, word] of rawArgs.entries()) {
70
+ if (!isRouterFlag(word)) {
71
+ wordsSeen++;
72
+ }
73
+ if (wordsSeen === routeWordCount) {
74
+ argumentStart = index + 1;
75
+ break;
76
+ }
77
+ }
78
+ const args = rawArgs.slice(argumentStart);
79
+ const separatorIndex = rawArgs.indexOf("--");
80
+ const optionArgs = separatorIndex === -1 ? rawArgs : rawArgs.slice(0, separatorIndex);
81
+ const options = { ...route.input.options, ...routerOptions };
82
+ const { tokens, values } = parseArgs({
83
+ args,
84
+ options,
85
+ allowPositionals: true,
86
+ strict: true,
87
+ tokens: true,
88
+ });
89
+ validateUniqueOptions(tokens, options);
90
+ const optionInputs = getOptionInputs(values);
91
+ const hasMissingOption = Object.entries(route.input.options).some(([name, option]) => option.required && values[name] === undefined);
92
+ const hasInvalidChoice = Object.entries(route.input.options).some(([name, option]) => {
93
+ const value = values[name];
94
+ const comparableValue = typeof value === "string" && option.value?.caseInsensitive ? value.toLowerCase() : value;
95
+ return (typeof comparableValue === "string" &&
96
+ option.value?.choices !== undefined &&
97
+ !option.value.choices.includes(comparableValue));
98
+ });
99
+ const hasConflictingOptions = route.input.constraints.some((constraint) => violatesConstraint(constraint, optionInputs));
100
+ const cannotSuggest = hasMissingOption || hasInvalidChoice || hasConflictingOptions;
101
+ if (cannotSuggest) {
102
+ return undefined;
103
+ }
104
+ const words = tokens.flatMap((token) => token.kind === "positional" ? [{ value: token.value, index: token.index }] : []);
105
+ const isMove = route.command === "task move";
106
+ const isColumnOption = route.command === "task create" || route.command === "task list";
107
+ const columnToken = tokens.find((token) => token.kind === "option" && token.name === "column");
108
+ const hasNoWords = words.length === 0;
109
+ const hasTooFewMoveWords = isMove && words.length < 3;
110
+ const hasNoColumnOption = isColumnOption && columnToken === undefined;
111
+ if (hasNoWords || hasTooFewMoveWords || hasNoColumnOption) {
112
+ return undefined;
113
+ }
114
+ const context = column.inspect({
115
+ taskKeys: isMove ? words.map((word) => word.value) : [],
116
+ allowsLegacyRead: optionArgs.some(isAllowLegacyReadFlag),
117
+ });
118
+ if (context === null) {
119
+ return undefined;
120
+ }
121
+ const candidates = new Set();
122
+ const addCandidate = (merges) => {
123
+ const corrected = [...rawArgs.slice(0, argumentStart), ...applyMerges(args, merges)];
124
+ candidates.add(formatCommand(corrected));
125
+ };
126
+ if (isMove) {
127
+ const targetWords = words.slice(-2);
128
+ const merge = joinWords(targetWords);
129
+ const existingKeys = new Set(context.taskKeys);
130
+ const absorbsTask = targetWords.some((word) => existingKeys.has(word.value.toUpperCase()));
131
+ const taskWords = words.slice(0, -2);
132
+ const validTasks = taskWords.every((word) => existingKeys.has(word.value.toUpperCase()));
133
+ const canSuggestMove = merge !== undefined &&
134
+ !absorbsTask &&
135
+ validTasks &&
136
+ taskWords.every((word) => hasColumn(context, parseTaskKey(word.value).projectKey, merge.value));
137
+ if (canSuggestMove) {
138
+ addCandidate([merge]);
139
+ }
140
+ }
141
+ else if (isColumnOption && typeof columnToken?.value === "string") {
142
+ const columnValue = columnToken.value;
143
+ const valueIndex = columnToken.inlineValue ? columnToken.index : columnToken.index + 1;
144
+ const fragments = words.filter((word) => word.index > valueIndex);
145
+ for (let count = 1; count <= fragments.length; count++) {
146
+ const consumed = fragments.slice(0, count);
147
+ const merge = joinWords([{ value: columnValue, index: valueIndex }, ...consumed]);
148
+ const remaining = words.filter((word) => !consumed.includes(word));
149
+ const discardsProject = consumed.some((word) => context.projects.some((project) => project.key === word.value.toUpperCase()));
150
+ const conflictsWithAllProjects = values["all-projects"] === true && remaining.length > 0;
151
+ if (merge === undefined) {
152
+ continue;
153
+ }
154
+ const cannotSuggestSplit = remaining.length > 1 || discardsProject || conflictsWithAllProjects;
155
+ if (cannotSuggestSplit) {
156
+ continue;
157
+ }
158
+ const choice = chooseProjectKey(remaining[0]?.value, {
159
+ required: route.command === "task create",
160
+ allProjects: values["all-projects"] === true,
161
+ });
162
+ const matches = choice === undefined
163
+ ? context.projects.some((project) => hasColumn(context, project.key, merge.value))
164
+ : hasColumn(context, choice.key, merge.value);
165
+ if (matches) {
166
+ addCandidate([
167
+ { ...merge, value: columnToken.inlineValue ? `--column=${merge.value}` : merge.value },
168
+ ]);
169
+ }
170
+ }
171
+ }
172
+ else if (route.command === "project column order") {
173
+ const projectKey = words[0].value;
174
+ const directionPosition = route.input.forms[0].positionals.findIndex((input) => input.name === "direction");
175
+ const originalDirection = words[directionPosition]?.value;
176
+ const hasRecognizedDirection = route.input.forms.some((form) => form.positionals[directionPosition].value.choices.includes(originalDirection ?? ""));
177
+ for (let directionIndex = directionPosition; directionIndex < words.length; directionIndex++) {
178
+ const replacesRecognizedDirection = hasRecognizedDirection && directionIndex !== directionPosition;
179
+ if (replacesRecognizedDirection) {
180
+ continue;
181
+ }
182
+ const direction = words[directionIndex].value;
183
+ const form = route.input.forms.find((candidate) => candidate.positionals
184
+ .find((input) => input.name === "direction")
185
+ ?.value.choices?.includes(direction));
186
+ if (form === undefined) {
187
+ continue;
188
+ }
189
+ const sourceWords = words.slice(1, directionIndex);
190
+ const targetWords = words.slice(directionIndex + 1);
191
+ const needsTarget = form.positionals.some((input) => input.name === "target-column-name");
192
+ const hasTarget = targetWords.length > 0;
193
+ const isUnexpectedTarget = !needsTarget && hasTarget;
194
+ const isMissingTarget = needsTarget && !hasTarget;
195
+ if (isUnexpectedTarget || isMissingTarget) {
196
+ continue;
197
+ }
198
+ const source = sourceWords.map((word) => word.value).join(" ");
199
+ const target = targetWords.map((word) => word.value).join(" ");
200
+ const sourceMerge = joinWords(sourceWords);
201
+ const targetMerge = joinWords(targetWords);
202
+ const invalidSource = sourceWords.length > 1 && sourceMerge === undefined;
203
+ const invalidTarget = targetWords.length > 1 && targetMerge === undefined;
204
+ const merges = [sourceMerge, targetMerge].filter((merge) => merge !== undefined);
205
+ const matchesSource = hasColumn(context, projectKey, source);
206
+ const matchesTarget = !needsTarget || hasColumn(context, projectKey, target);
207
+ const canSuggestOrder = !invalidSource && !invalidTarget && merges.length > 0 && matchesSource && matchesTarget;
208
+ if (canSuggestOrder) {
209
+ addCandidate(merges);
210
+ }
211
+ }
212
+ }
213
+ else {
214
+ const merge = joinWords(words.slice(1));
215
+ if (merge !== undefined && hasColumn(context, words[0].value, merge.value)) {
216
+ addCandidate([merge]);
217
+ }
218
+ }
219
+ return candidates.size === 1 ? [...candidates][0] : undefined;
220
+ }
221
+ catch {
222
+ // A diagnostic lookup must not replace the original failure.
223
+ return undefined;
224
+ }
225
+ }
package/src/database.js CHANGED
@@ -17,10 +17,7 @@ export function getCliOpenPolicy() {
17
17
  // The script the CLI runs from; the runtime itself when there is none.
18
18
  executable: process.argv[1] ?? process.execPath,
19
19
  release: RELEASE_MODE,
20
- // Read when the database opens, after the router has handled `--allow-legacy-read`
21
- get allowsLegacyRead() {
22
- return isLegacyReadAllowed();
23
- },
20
+ allowsLegacyRead: isLegacyReadAllowed(),
24
21
  onWait: reportLockWait,
25
22
  onLegacyRead: reportLegacyRead,
26
23
  };
package/src/errors.js CHANGED
@@ -109,6 +109,8 @@ const osReasons = {
109
109
  EBUSY: "busy",
110
110
  EIO: "io",
111
111
  ENOENT: "io",
112
+ ENAMETOOLONG: "io",
113
+ ELOOP: "io",
112
114
  ENOTDIR: "io",
113
115
  EISDIR: "io",
114
116
  EMFILE: "io",