@zinn-dev/cli 0.43.0 → 0.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +1 -1
  2. package/index.js +3 -3
  3. package/package.json +7 -4
  4. package/skills/zinn/SKILL.md +1 -1
  5. package/src/actor.d.ts +8 -0
  6. package/src/actor.js +5 -1
  7. package/src/capabilities-schema.d.ts +1 -1
  8. package/src/column-hint.js +3 -4
  9. package/src/errors.d.ts +12 -3
  10. package/src/errors.js +19 -2
  11. package/src/failure-log.d.ts +6 -0
  12. package/src/failure-log.js +167 -0
  13. package/src/input.d.ts +11 -0
  14. package/src/input.js +25 -1
  15. package/src/lib.d.ts +7 -5
  16. package/src/lib.js +52 -33
  17. package/src/list-limit.d.ts +2 -2
  18. package/src/list-limit.js +2 -2
  19. package/src/overview.d.ts +10 -0
  20. package/src/overview.js +41 -0
  21. package/src/presentation/activity-presentation.d.ts +2 -0
  22. package/src/presentation/activity-presentation.js +96 -35
  23. package/src/presentation/column-presentation.d.ts +17 -2
  24. package/src/presentation/column-presentation.js +45 -6
  25. package/src/presentation/info-presentation.js +36 -6
  26. package/src/presentation/relation-presentation.d.ts +6 -2
  27. package/src/presentation/relation-presentation.js +36 -26
  28. package/src/presentation/task-blame-presentation.d.ts +11 -0
  29. package/src/presentation/task-blame-presentation.js +56 -0
  30. package/src/presentation/task-presentation.d.ts +6 -1
  31. package/src/presentation/task-presentation.js +21 -9
  32. package/src/result-schemas.d.ts +480 -15
  33. package/src/result-schemas.js +54 -1
  34. package/src/routes/activity-router.d.ts +9 -1
  35. package/src/routes/activity-router.js +15 -2
  36. package/src/routes/info-router.js +3 -2
  37. package/src/routes/migrate-router.js +2 -2
  38. package/src/routes/project-router.d.ts +1 -1
  39. package/src/routes/project-router.js +3 -12
  40. package/src/routes/restore-router.js +9 -3
  41. package/src/routes/router.js +24 -11
  42. package/src/routes/routes.d.ts +51 -8
  43. package/src/routes/task-router.d.ts +41 -6
  44. package/src/routes/task-router.js +81 -24
  45. package/src/routes/whoami-router.js +1 -1
  46. package/src/run-facts.d.ts +14 -0
  47. package/src/run-facts.js +14 -0
  48. package/src/store-folder.d.ts +5 -0
  49. package/src/store-folder.js +16 -0
  50. package/src/telemetry.d.ts +31 -0
  51. package/src/telemetry.js +329 -0
  52. package/src/text-input.js +1 -5
  53. package/src/types.d.ts +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @zinn-dev/cli
2
2
 
3
- The `zinn` command-line interface for Zinn.
3
+ The command-line interface for [Zinn](https://zinn.sh), local kanban and task management for developers and coding agents.
4
4
 
5
5
  > [!IMPORTANT]
6
6
  > **Experimental.** Commands, output, and the database schema may change between releases. Save a backup with `zinn backup` before upgrading.
package/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import packageJson from "./package.json" with { type: "json" };
3
- import { versionSpellings } from "./src/input.js";
3
+ import { isHelpFlag, versionSpellings } from "./src/input.js";
4
4
  const args = process.argv.slice(2);
5
5
  const isVersionRequest = args.length === 1 && versionSpellings.includes(args[0]);
6
6
  if (isVersionRequest) {
7
7
  console.info(packageJson.version);
8
8
  }
9
9
  else {
10
- const { isHelpFlag, prepareOutput, flushDiagnostics, renderFailure } = await import("./src/lib.js");
10
+ const { prepareOutput, finishRun, renderFailure } = await import("./src/lib.js");
11
11
  prepareOutput(args);
12
12
  try {
13
13
  const { createRouter } = await import("./src/routes/router.js");
@@ -22,7 +22,7 @@ else {
22
22
  });
23
23
  if (args.length === 0 || isHelpFlag(args[0])) {
24
24
  console.info(router.help);
25
- flushDiagnostics();
25
+ finishRun();
26
26
  }
27
27
  else {
28
28
  await router.route(args);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zinn-dev/cli",
3
- "version": "0.43.0",
3
+ "version": "0.44.0",
4
4
  "description": "A kanban workflow in the terminal. Experimental.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://zinn.sh",
@@ -20,7 +20,10 @@
20
20
  "keywords": [
21
21
  "kanban",
22
22
  "cli",
23
- "terminal"
23
+ "terminal",
24
+ "task-management",
25
+ "task-tracker",
26
+ "coding-agents"
24
27
  ],
25
28
  "files": [
26
29
  "index.js",
@@ -35,8 +38,8 @@
35
38
  "node": ">=24.15.0"
36
39
  },
37
40
  "dependencies": {
38
- "zod": "4.6.4",
39
- "@zinn-dev/core": "0.32.0"
41
+ "zod": "4.6.7",
42
+ "@zinn-dev/core": "0.33.0"
40
43
  },
41
44
  "devDependencies": {
42
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.43.0"
10
+ zinn-cli-reviewed-version: "0.44.0"
11
11
  ---
12
12
 
13
13
  # Work with a Zinn board
package/src/actor.d.ts CHANGED
@@ -1,5 +1,13 @@
1
1
  import type { Actor } from "@zinn-dev/core";
2
2
  type Env = Record<string, string | undefined>;
3
+ export declare function readExecutionIdentity(env: Env): {
4
+ sessionId: string | null;
5
+ threadId: string | null;
6
+ agent: string | null;
7
+ model: string | null;
8
+ effort: string | null;
9
+ client: string;
10
+ };
3
11
  /** Generic flags establish an unnamed agent only when no identifying marker follows. */
4
12
  export declare function detectAgent(env: Env): Actor | null;
5
13
  export declare function resolveActor(env: Env): Actor;
package/src/actor.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { execFileSync } from "node:child_process";
2
2
  import { userInfo } from "node:os";
3
+ import packageJson from "../package.json" with { type: "json" };
3
4
  /**
4
5
  * Environment variables that coding agents set in the shells they run.
5
6
  * Undetected tools can set `AI_AGENT` through their own env configuration.
@@ -27,7 +28,9 @@ function readDeclaration(env, variable) {
27
28
  const value = variable === null ? undefined : env[variable]?.trim();
28
29
  return value == null || value.length === 0 ? null : value;
29
30
  }
30
- function readExecutionIdentity(env) {
31
+ export function readExecutionIdentity(env) {
32
+ const ownClient = `zinn-cli/${packageJson.version}`;
33
+ const declaredClient = readDeclaration(env, "ZINN_CLIENT");
31
34
  let sessionId = null;
32
35
  let threadId = null;
33
36
  for (const declaration of SESSION_DECLARATIONS) {
@@ -46,6 +49,7 @@ function readExecutionIdentity(env) {
46
49
  agent: readDeclaration(env, "ZINN_AGENT"),
47
50
  model: readDeclaration(env, "ZINN_MODEL"),
48
51
  effort: readDeclaration(env, "ZINN_EFFORT"),
52
+ client: declaredClient === null ? ownClient : `${ownClient} ${declaredClient}`,
49
53
  };
50
54
  }
51
55
  /** Generic flags establish an unnamed agent only when no identifying marker follows. */
@@ -125,8 +125,8 @@ export declare const capabilitiesSchema: z.ZodObject<{
125
125
  }, z.core.$strict>;
126
126
  confirmation: z.ZodObject<{
127
127
  kind: z.ZodEnum<{
128
- prompt: "prompt";
129
128
  none: "none";
129
+ prompt: "prompt";
130
130
  "project-delete": "project-delete";
131
131
  }>;
132
132
  description: z.ZodOptional<z.ZodString>;
@@ -1,8 +1,8 @@
1
1
  import { parseArgs } from "node:util";
2
2
  import { column, columnCreateSchema, parseTaskKey } from "@zinn-dev/core";
3
3
  import { classifyFailure } from "./errors.js";
4
- import { routerOptions, getOptionInputs, violatesConstraint } from "./input.js";
5
- import { formatCommand, isAllowLegacyReadFlag, isRouterFlag, UsageError, validateUniqueOptions, } from "./lib.js";
4
+ import { routerOptions, getOptionInputs, isAllowLegacyReadFlag, isRouterFlag, splitAtOptionSeparator, violatesConstraint, } from "./input.js";
5
+ import { formatCommand, UsageError, validateUniqueOptions } from "./lib.js";
6
6
  import { chooseProjectKey } from "./project.js";
7
7
  function isEligible(error, command) {
8
8
  const failure = classifyFailure(error);
@@ -76,8 +76,7 @@ export function quotedColumnHint(error, route, rawArgs, routeWordCount) {
76
76
  }
77
77
  }
78
78
  const args = rawArgs.slice(argumentStart);
79
- const separatorIndex = rawArgs.indexOf("--");
80
- const optionArgs = separatorIndex === -1 ? rawArgs : rawArgs.slice(0, separatorIndex);
79
+ const { optionWords: optionArgs } = splitAtOptionSeparator(rawArgs);
81
80
  const options = { ...route.input.options, ...routerOptions };
82
81
  const { tokens, values } = parseArgs({
83
82
  args,
package/src/errors.d.ts CHANGED
@@ -46,6 +46,10 @@ export declare const errorDetailsSchema: z.ZodObject<{
46
46
  different_project: "different_project";
47
47
  different_column: "different_column";
48
48
  ambiguous_reference: "ambiguous_reference";
49
+ invalid_cursor: "invalid_cursor";
50
+ cursor_version: "cursor_version";
51
+ different_sort: "different_sort";
52
+ task_id_cursor: "task_id_cursor";
49
53
  text_match_count: "text_match_count";
50
54
  no_columns: "no_columns";
51
55
  has_tasks: "has_tasks";
@@ -71,6 +75,7 @@ export declare const errorDetailsSchema: z.ZodObject<{
71
75
  backupPath: z.ZodOptional<z.ZodString>;
72
76
  schemaVersion: z.ZodOptional<z.ZodNumber>;
73
77
  supportedSchemaVersion: z.ZodOptional<z.ZodNumber>;
78
+ logPath: z.ZodOptional<z.ZodString>;
74
79
  cause: z.ZodOptional<z.ZodObject<{
75
80
  code: z.ZodOptional<z.ZodString>;
76
81
  errcode: z.ZodOptional<z.ZodNumber>;
@@ -128,6 +133,10 @@ export declare const errorDocumentSchema: z.ZodObject<{
128
133
  different_project: "different_project";
129
134
  different_column: "different_column";
130
135
  ambiguous_reference: "ambiguous_reference";
136
+ invalid_cursor: "invalid_cursor";
137
+ cursor_version: "cursor_version";
138
+ different_sort: "different_sort";
139
+ task_id_cursor: "task_id_cursor";
131
140
  text_match_count: "text_match_count";
132
141
  no_columns: "no_columns";
133
142
  has_tasks: "has_tasks";
@@ -153,6 +162,7 @@ export declare const errorDocumentSchema: z.ZodObject<{
153
162
  backupPath: z.ZodOptional<z.ZodString>;
154
163
  schemaVersion: z.ZodOptional<z.ZodNumber>;
155
164
  supportedSchemaVersion: z.ZodOptional<z.ZodNumber>;
165
+ logPath: z.ZodOptional<z.ZodString>;
156
166
  cause: z.ZodOptional<z.ZodObject<{
157
167
  code: z.ZodOptional<z.ZodString>;
158
168
  errcode: z.ZodOptional<z.ZodNumber>;
@@ -165,7 +175,7 @@ export declare const errorDocumentSchema: z.ZodObject<{
165
175
  export type ErrorCode = z.infer<typeof errorCodeSchema>;
166
176
  export type ErrorDetails = z.infer<typeof errorDetailsSchema>;
167
177
  export type CliFailure = z.infer<typeof errorDocumentSchema>["error"];
168
- type ClassifiedFailure = Omit<CliFailure, "message"> & {
178
+ export type ClassifiedFailure = Omit<CliFailure, "message"> & {
169
179
  suggestedRoute?: Array<string>;
170
180
  };
171
181
  /** A CLI failure with public facts and an internal recovery route. */
@@ -174,7 +184,7 @@ export declare class CliError extends Error {
174
184
  readonly details?: ErrorDetails | undefined;
175
185
  help?: string | undefined;
176
186
  readonly suggestedRoute?: Array<string> | undefined;
177
- constructor(message: string, code?: ErrorCode, details?: ErrorDetails | undefined, help?: string | undefined, suggestedRoute?: Array<string> | undefined);
187
+ constructor(message: string, code?: ErrorCode, details?: ErrorDetails | undefined, help?: string | undefined, suggestedRoute?: Array<string> | undefined, cause?: unknown);
178
188
  }
179
189
  /** Recovery text and its single suggested route, when one is identified. */
180
190
  export declare function recoveryHint(error: unknown): {
@@ -183,4 +193,3 @@ export declare function recoveryHint(error: unknown): {
183
193
  } | undefined;
184
194
  /** Finds causes of initialization wrappers without serializing their error chains. */
185
195
  export declare function classifyFailure(error: unknown): ClassifiedFailure;
186
- export {};
package/src/errors.js CHANGED
@@ -47,6 +47,10 @@ export const errorDetailsSchema = z.strictObject({
47
47
  "different_project",
48
48
  "different_column",
49
49
  "ambiguous_reference",
50
+ "invalid_cursor",
51
+ "cursor_version",
52
+ "different_sort",
53
+ "task_id_cursor",
50
54
  "text_match_count",
51
55
  "no_columns",
52
56
  "has_tasks",
@@ -73,6 +77,7 @@ export const errorDetailsSchema = z.strictObject({
73
77
  backupPath: z.string().optional(),
74
78
  schemaVersion: z.number().int().nonnegative().optional(),
75
79
  supportedSchemaVersion: z.number().int().nonnegative().optional(),
80
+ logPath: z.string().optional(),
76
81
  cause: z
77
82
  .strictObject({
78
83
  code: z.string().optional(),
@@ -96,8 +101,8 @@ export class CliError extends Error {
96
101
  details;
97
102
  help;
98
103
  suggestedRoute;
99
- constructor(message, code = "invalid_input", details, help, suggestedRoute) {
100
- super(message);
104
+ constructor(message, code = "invalid_input", details, help, suggestedRoute, cause) {
105
+ super(message, cause === undefined ? undefined : { cause });
101
106
  this.code = code;
102
107
  this.details = details;
103
108
  this.help = help;
@@ -105,6 +110,12 @@ export class CliError extends Error {
105
110
  this.name = "CliError";
106
111
  }
107
112
  }
113
+ const taskCursorRecovery = {
114
+ invalid_cursor: ". Copy the cursor from the continuation command that zinn task list prints, or list again without --starting-after.",
115
+ cursor_version: ". Run zinn task list again without --starting-after to get a current cursor.",
116
+ different_sort: ". Keep the --sort of the zinn task list command that printed the cursor, or start again without --starting-after.",
117
+ task_id_cursor: ". When more tasks remain, zinn task list prints a continuation command with the cursor on stderr. Run that command.",
118
+ };
108
119
  /** Recovery text and its single suggested route, when one is identified. */
109
120
  export function recoveryHint(error) {
110
121
  if (error instanceof ReadOnlyDatabaseError && error.reason === "older") {
@@ -133,6 +144,12 @@ export function recoveryHint(error) {
133
144
  suffix: ". Use zinn task move or zinn task delete to clear the column. Archived tasks must be unarchived before moving.",
134
145
  };
135
146
  }
147
+ const cursorRecovery = error instanceof CoreError && error.facts.reason !== undefined
148
+ ? taskCursorRecovery[error.facts.reason]
149
+ : undefined;
150
+ if (cursorRecovery !== undefined) {
151
+ return { suffix: cursorRecovery, suggestedRoute: ["task", "list"] };
152
+ }
136
153
  if (error instanceof Error && error.message === "no such table: task_search") {
137
154
  return {
138
155
  suffix: ". Run `zinn reindex` to rebuild the search index.",
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Writes what a failure leaves out of its error message to a new file in the store's `logs` folder.
3
+ * Returns the file's path, or undefined when none was written. It never throws,
4
+ * so logging cannot hide the failure it reports.
5
+ */
6
+ export declare function writeFailureLog(error: unknown, notices: ReadonlyArray<string>): string | undefined;
@@ -0,0 +1,167 @@
1
+ import { closeSync, openSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
2
+ import { arch, platform, release } from "node:os";
3
+ import { join } from "node:path";
4
+ import { createOutputFileName, getConfiguredStorage, getStorage, readOutputFileName, readSchemaVersionWithoutWaiting, } from "@zinn-dev/core";
5
+ import packageJson from "../package.json" with { type: "json" };
6
+ import { currentRuntime, readRunClock } from "./run-facts.js";
7
+ import { ensureFolderInStore } from "./store-folder.js";
8
+ const LOG_EXTENSION = ".log";
9
+ /** Logs kept in the folder. Including ones written by a failing run */
10
+ const MAX_LOG_FILES = 10;
11
+ /** One thrown value as text. An error keeps its stack, and its code and `errcode` when it has them */
12
+ function describeValue(value) {
13
+ if (!(value instanceof Error)) {
14
+ return String(value);
15
+ }
16
+ const lines = [typeof value.stack === "string" ? value.stack : `${value.name}: ${value.message}`];
17
+ const { code, errcode } = value;
18
+ if (code !== undefined) {
19
+ lines.push(`code: ${String(code)}`);
20
+ }
21
+ if (errcode !== undefined) {
22
+ lines.push(`errcode: ${String(errcode)}`);
23
+ }
24
+ return lines.join("\n");
25
+ }
26
+ /** The thrown error, then each cause and suppressed error, stopping at one already shown */
27
+ function describeErrors(error) {
28
+ const shown = new Set();
29
+ const entries = [];
30
+ const add = (value, label) => {
31
+ if (shown.has(value)) {
32
+ return;
33
+ }
34
+ shown.add(value);
35
+ entries.push(label === null ? describeValue(value) : `${label}\n${describeValue(value)}`);
36
+ if (!(value instanceof Error)) {
37
+ return;
38
+ }
39
+ const { suppressed } = value;
40
+ if (value.cause !== undefined) {
41
+ add(value.cause, "Caused by:");
42
+ }
43
+ if (suppressed !== undefined) {
44
+ add(suppressed, "Suppressed:");
45
+ }
46
+ };
47
+ add(error, null);
48
+ return entries.join("\n\n");
49
+ }
50
+ function describeRuntime() {
51
+ const { name, version } = currentRuntime();
52
+ return `${name} ${version}`;
53
+ }
54
+ function section(title, lines) {
55
+ return [title, ...lines].join("\n");
56
+ }
57
+ /** The resolved database path and its schema version, or the configured path when it cannot be resolved. */
58
+ function readDatabaseFacts(configuredPath) {
59
+ try {
60
+ const { databasePath } = getStorage();
61
+ return { databasePath, schemaVersion: readSchemaVersionWithoutWaiting(databasePath) };
62
+ }
63
+ catch {
64
+ return { databasePath: configuredPath, schemaVersion: null };
65
+ }
66
+ }
67
+ function formatLog(error, notices, storage) {
68
+ const { databasePath, schemaVersion } = readDatabaseFacts(storage.databasePath);
69
+ const { now: failedAt, elapsedMs, startedAt } = readRunClock();
70
+ const sections = [
71
+ section("Error", [describeErrors(error)]),
72
+ section("Run", [
73
+ `Process id: ${process.pid}`,
74
+ `Zinn version: ${packageJson.version}`,
75
+ `Runtime: ${describeRuntime()}`,
76
+ `Operating system: ${platform()} ${release()} ${arch()}`,
77
+ ]),
78
+ section("Store", [
79
+ `Directory: ${storage.directory}`,
80
+ `Database: ${databasePath}`,
81
+ `Schema version: ${schemaVersion ?? "unknown"}`,
82
+ ]),
83
+ section("Arguments", [JSON.stringify(process.argv.slice(2))]),
84
+ section("Timings", [
85
+ `Started: ${startedAt.toISOString()}`,
86
+ `Failed: ${failedAt.toISOString()}`,
87
+ `Elapsed: ${elapsedMs} ms`,
88
+ ]),
89
+ ];
90
+ if (notices.length > 0) {
91
+ sections.push(section("Notices", [...notices]));
92
+ }
93
+ return `${sections.join("\n\n")}\n`;
94
+ }
95
+ /** Creates a file that does not exist yet, and removes it again when its text cannot be written */
96
+ function createFile(path, text) {
97
+ const descriptor = openSync(path, "wx");
98
+ let isWritten = false;
99
+ try {
100
+ try {
101
+ writeFileSync(descriptor, text);
102
+ }
103
+ finally {
104
+ closeSync(descriptor);
105
+ }
106
+ isWritten = true;
107
+ }
108
+ finally {
109
+ if (!isWritten) {
110
+ rmSync(path, { force: true });
111
+ }
112
+ }
113
+ }
114
+ /** Other runs' logs, oldest first by modification time, then by name */
115
+ function listOtherLogs(logDirectory, ownName) {
116
+ return readdirSync(logDirectory)
117
+ .filter((name) => name !== ownName && readOutputFileName(name, LOG_EXTENSION) !== null)
118
+ .flatMap((name) => {
119
+ try {
120
+ return [{ name, modifiedMs: statSync(join(logDirectory, name)).mtimeMs }];
121
+ }
122
+ catch {
123
+ // Another run may have removed it since the listing
124
+ return [];
125
+ }
126
+ })
127
+ .sort((a, b) => a.modifiedMs - b.modifiedMs || a.name.localeCompare(b.name))
128
+ .map(({ name }) => name);
129
+ }
130
+ /** Removes the oldest logs so that at most `MAX_LOG_FILES` remain. Other files stay */
131
+ function removeOldLogs(logDirectory, ownName) {
132
+ try {
133
+ const others = listOtherLogs(logDirectory, ownName);
134
+ const excess = others.length - (MAX_LOG_FILES - 1);
135
+ for (const name of others.slice(0, Math.max(excess, 0))) {
136
+ try {
137
+ rmSync(join(logDirectory, name), { force: true });
138
+ }
139
+ catch {
140
+ // Another run may have removed it, and a leftover only keeps one more file
141
+ }
142
+ }
143
+ }
144
+ catch {
145
+ // The new log is already written, so a failed listing only skips the cleanup
146
+ }
147
+ }
148
+ /**
149
+ * Writes what a failure leaves out of its error message to a new file in the store's `logs` folder.
150
+ * Returns the file's path, or undefined when none was written. It never throws,
151
+ * so logging cannot hide the failure it reports.
152
+ */
153
+ export function writeFailureLog(error, notices) {
154
+ try {
155
+ const storage = getConfiguredStorage();
156
+ const name = createOutputFileName({ client: "cli", version: packageJson.version }, LOG_EXTENSION);
157
+ const path = join(storage.logDirectory, name);
158
+ const text = formatLog(error, notices, storage);
159
+ ensureFolderInStore(storage.logDirectory);
160
+ createFile(path, text);
161
+ removeOldLogs(storage.logDirectory, name);
162
+ return path;
163
+ }
164
+ catch {
165
+ return undefined;
166
+ }
167
+ }
package/src/input.d.ts CHANGED
@@ -185,6 +185,17 @@ export declare const routerOptions: {
185
185
  };
186
186
  export declare const helpSpellings: readonly string[];
187
187
  export declare const versionSpellings: readonly string[];
188
+ export declare const OPTION_SEPARATOR = "--";
189
+ export declare function isJsonFlag(flag: string): boolean;
190
+ export declare function isAllowLegacyReadFlag(flag: string): boolean;
191
+ /** A flag the router reads wherever it appears before --, for every command. */
192
+ export declare function isRouterFlag(flag: string): boolean;
193
+ export declare function isHelpFlag(flag: string): boolean;
194
+ /** The words before the first `--`, and the rest starting with that `--` */
195
+ export declare function splitAtOptionSeparator(words: Array<string>): {
196
+ optionWords: string[];
197
+ passthroughWords: string[];
198
+ };
188
199
  export declare const invocation: {
189
200
  readonly routerOptions: {
190
201
  readonly json: {
package/src/input.js CHANGED
@@ -70,10 +70,34 @@ export const routerOptions = {
70
70
  };
71
71
  export const helpSpellings = ["-h", "--help"];
72
72
  export const versionSpellings = ["-v", "--version"];
73
+ export const OPTION_SEPARATOR = "--";
74
+ export function isJsonFlag(flag) {
75
+ return flag === `--${routerOptionNames.json}`;
76
+ }
77
+ export function isAllowLegacyReadFlag(flag) {
78
+ return flag === `--${routerOptionNames.legacyRead}`;
79
+ }
80
+ /** A flag the router reads wherever it appears before --, for every command. */
81
+ export function isRouterFlag(flag) {
82
+ return isJsonFlag(flag) || isAllowLegacyReadFlag(flag);
83
+ }
84
+ export function isHelpFlag(flag) {
85
+ return helpSpellings.includes(flag);
86
+ }
87
+ /** The words before the first `--`, and the rest starting with that `--` */
88
+ export function splitAtOptionSeparator(words) {
89
+ const separatorIndex = words.indexOf(OPTION_SEPARATOR);
90
+ return separatorIndex === -1
91
+ ? { optionWords: words, passthroughWords: [] }
92
+ : {
93
+ optionWords: words.slice(0, separatorIndex),
94
+ passthroughWords: words.slice(separatorIndex),
95
+ };
96
+ }
73
97
  export const invocation = {
74
98
  routerOptions,
75
99
  routerOptionPlacement: "exact-tokens-anywhere-before-separator",
76
- optionSeparator: "--",
100
+ optionSeparator: OPTION_SEPARATOR,
77
101
  literalOptionValue: "equals",
78
102
  singularOptions: "reject-repetition",
79
103
  jsonFailure: "one-stderr-document-with-buffered-diagnostics",
package/src/lib.d.ts CHANGED
@@ -17,10 +17,12 @@ export declare function prepareOutput(args: Array<string>): void;
17
17
  /** Keeps JSON failures parseable while text-mode notices remain immediate. */
18
18
  export declare function diagnostic(message: string): void;
19
19
  export declare function flushDiagnostics(): void;
20
- export declare function isJsonFlag(flag: string): boolean;
21
- export declare function isAllowLegacyReadFlag(flag: string): boolean;
22
- /** A flag the router reads wherever it appears before --, for every command. */
23
- export declare function isRouterFlag(flag: string): boolean;
20
+ export declare function isDebugOutputEnabled(): boolean;
21
+ /**
22
+ * Ends a successful run after its output, recording telemetry then releasing notices held back in JSON mode.
23
+ * Telemetry goes first so its own debug notice is released with the rest.
24
+ */
25
+ export declare function finishRun(): void;
24
26
  export declare function setLegacyReadAllowed(allowed: boolean): void;
25
27
  export declare function isLegacyReadAllowed(): boolean;
26
28
  export declare function output<T>(data: T, transformToString: (data: T) => string): void;
@@ -75,7 +77,6 @@ export declare function validateOrderForms<Form extends InputForm>(positionals:
75
77
  export declare function requireStringOption(option: InputOption & {
76
78
  required: true;
77
79
  }, value: string | undefined, name: string, message: string): string;
78
- export declare function isHelpFlag(flag: string): boolean;
79
80
  /**
80
81
  * Help sentence for a flag whose value may begin with a dash, such as a Markdown bullet.
81
82
  * `parseArgs` refuses `--flag -value`, since a value that looks like an option may mean the value
@@ -94,6 +95,7 @@ type SuggestFor = (flag: string) => {
94
95
  } | undefined;
95
96
  /** Renames an option without changing values or words after `--` */
96
97
  export declare function renameFlag(args: Array<string>, options: ParseArgsOptionsConfig, source: string, target: string): string[];
98
+ export declare function isParseArgsError(error: any): boolean;
97
99
  /**
98
100
  * An argument failure from parseArgs, rewritten where parseArgs' own advice misleads.
99
101
  * parseArgs names the flag only in its message text, which Node and Bun word the same.