@duyquangnvx/agent-cli 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -0
- package/dist/agent-cli.js +1 -1
- package/dist/agent-cli.js.map +1 -1
- package/dist/{built-ins.d.ts → built-ins/commands.d.ts} +1 -1
- package/dist/{built-ins.js → built-ins/commands.js} +1 -1
- package/dist/built-ins/commands.js.map +1 -0
- package/dist/built-ins/doctor-rows.d.ts +16 -0
- package/dist/{doctor-rows.js → built-ins/doctor-rows.js} +34 -38
- package/dist/built-ins/doctor-rows.js.map +1 -0
- package/dist/{doctor.d.ts → built-ins/doctor.d.ts} +2 -2
- package/dist/{doctor.js → built-ins/doctor.js} +25 -14
- package/dist/built-ins/doctor.js.map +1 -0
- package/dist/{global-install.js → built-ins/global-install.js} +1 -1
- package/dist/built-ins/global-install.js.map +1 -0
- package/dist/{npm.d.ts → built-ins/npm.d.ts} +2 -2
- package/dist/{npm.js → built-ins/npm.js} +3 -3
- package/dist/built-ins/npm.js.map +1 -0
- package/dist/built-ins/semver.js.map +1 -0
- package/dist/built-ins/skills.d.ts +18 -0
- package/dist/built-ins/skills.js +97 -0
- package/dist/built-ins/skills.js.map +1 -0
- package/dist/{update.d.ts → built-ins/update.d.ts} +2 -2
- package/dist/{update.js → built-ins/update.js} +25 -15
- package/dist/built-ins/update.js.map +1 -0
- package/dist/{upgrade-notes.js → built-ins/upgrade-notes.js} +1 -1
- package/dist/built-ins/upgrade-notes.js.map +1 -0
- package/dist/clock.d.ts +1 -0
- package/dist/clock.js.map +1 -1
- package/dist/command-spec.d.ts +12 -2
- package/dist/command-spec.js +23 -9
- package/dist/command-spec.js.map +1 -1
- package/dist/context.d.ts +56 -19
- package/dist/define.d.ts +72 -10
- package/dist/define.js.map +1 -1
- package/dist/error-table.d.ts +6 -1
- package/dist/error-table.js +5 -1
- package/dist/error-table.js.map +1 -1
- package/dist/errors.d.ts +10 -2
- package/dist/errors.js +19 -10
- package/dist/errors.js.map +1 -1
- package/dist/exit-classes.d.ts +1 -0
- package/dist/exit-classes.js +37 -40
- package/dist/exit-classes.js.map +1 -1
- package/dist/files.d.ts +8 -3
- package/dist/files.js +4 -3
- package/dist/files.js.map +1 -1
- package/dist/help-json.d.ts +1 -1
- package/dist/help-json.js +2 -1
- package/dist/help-json.js.map +1 -1
- package/dist/help.js +3 -2
- package/dist/help.js.map +1 -1
- package/dist/index.d.ts +16 -4
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/interrupts.d.ts +4 -1
- package/dist/interrupts.js +25 -12
- package/dist/interrupts.js.map +1 -1
- package/dist/list.d.ts +12 -3
- package/dist/list.js +34 -5
- package/dist/list.js.map +1 -1
- package/dist/manifest.d.ts +17 -0
- package/dist/manifest.js +24 -0
- package/dist/manifest.js.map +1 -0
- package/dist/output.d.ts +2 -3
- package/dist/output.js +1 -6
- package/dist/output.js.map +1 -1
- package/dist/parse-input.js +10 -1
- package/dist/parse-input.js.map +1 -1
- package/dist/project.d.ts +2 -1
- package/dist/project.js +11 -10
- package/dist/project.js.map +1 -1
- package/dist/run-cli.d.ts +7 -46
- package/dist/run-cli.js +32 -194
- package/dist/run-cli.js.map +1 -1
- package/dist/run-command.d.ts +11 -0
- package/dist/run-command.js +234 -0
- package/dist/run-command.js.map +1 -0
- package/dist/run-options.d.ts +48 -0
- package/dist/run-options.js +2 -0
- package/dist/run-options.js.map +1 -0
- package/dist/run-process.js +4 -2
- package/dist/run-process.js.map +1 -1
- package/dist/secrets.d.ts +6 -3
- package/dist/secrets.js +6 -6
- package/dist/secrets.js.map +1 -1
- package/dist/side-task.d.ts +27 -0
- package/dist/side-task.js +31 -0
- package/dist/side-task.js.map +1 -0
- package/dist/spawn.d.ts +8 -2
- package/dist/spawn.js.map +1 -1
- package/dist/stdin.d.ts +23 -3
- package/dist/stdin.js +40 -3
- package/dist/stdin.js.map +1 -1
- package/dist/usage.d.ts +2 -0
- package/dist/usage.js +12 -1
- package/dist/usage.js.map +1 -1
- package/dist/version.d.ts +3 -0
- package/dist/version.js +7 -0
- package/dist/version.js.map +1 -0
- package/package.json +1 -1
- package/dist/built-ins.js.map +0 -1
- package/dist/doctor-rows.d.ts +0 -4
- package/dist/doctor-rows.js.map +0 -1
- package/dist/doctor.js.map +0 -1
- package/dist/global-install.js.map +0 -1
- package/dist/npm.js.map +0 -1
- package/dist/semver.js.map +0 -1
- package/dist/skill-source.d.ts +0 -4
- package/dist/skill-source.js +0 -42
- package/dist/skill-source.js.map +0 -1
- package/dist/skills.d.ts +0 -12
- package/dist/skills.js +0 -62
- package/dist/skills.js.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/upgrade-notes.js.map +0 -1
- /package/dist/{global-install.d.ts → built-ins/global-install.d.ts} +0 -0
- /package/dist/{semver.d.ts → built-ins/semver.d.ts} +0 -0
- /package/dist/{semver.js → built-ins/semver.js} +0 -0
- /package/dist/{upgrade-notes.d.ts → built-ins/upgrade-notes.d.ts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { isMissingFile } from "
|
|
3
|
+
import { isMissingFile } from "../errors.js";
|
|
4
4
|
import { compareVersions, isVersion } from "./semver.js";
|
|
5
5
|
const RELEASE_HEADING = /^## v?(\S+)/;
|
|
6
6
|
function releasesIn(changelog) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upgrade-notes.js","sourceRoot":"","sources":["../../src/built-ins/upgrade-notes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAOzD,MAAM,eAAe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AAC;QACpC,MAAM,KAAK,CAAC;IACd,CAAC;IACD,OAAO,UAAU,CAAC,SAAS,CAAC;SACzB,MAAM,CACL,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,CACzF;SACA,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
package/dist/clock.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Time as the Runtime sees it; a test replaces it through `runCli` to run every wait instantly. */
|
|
2
2
|
export interface Clock {
|
|
3
|
+
/** Milliseconds since the Unix epoch, as `Date.now()`. */
|
|
3
4
|
now(): number;
|
|
4
5
|
/** Resolves after `ms`, or rejects with the signal's reason once it aborts. */
|
|
5
6
|
sleep(ms: number, signal?: AbortSignal): Promise<void>;
|
package/dist/clock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clock.js","sourceRoot":"","sources":["../src/clock.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clock.js","sourceRoot":"","sources":["../src/clock.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,SAAS,GAAU;IAC9B,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;IACrB,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,CACpB,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC9B,IAAI,MAAM,EAAE,OAAO,KAAK,IAAI,EAAE,CAAC;YAC7B,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACtB,OAAO;QACT,CAAC;QACD,MAAM,OAAO,GAAG,GAAS,EAAE;YACzB,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACzB,CAAC,CAAC;QACF,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC9C,OAAO,EAAE,CAAC;QACZ,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC,CAAC;CACL,CAAC;AAEF,gFAAgF;AAChF,MAAM,UAAU,KAAK,CAAC,KAAY,EAAE,EAAU,EAAE,MAAmB,EAAE,IAAgB;IACnF,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAc,EAAE,EAAE;QACpD,IAAI,CAAC,MAAM,CAAC,OAAO;YAAE,MAAM,KAAK,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,IAAI,CACxB,KAAY,EACZ,KAAmD,EACnD,UAAkB,EAClB,MAAmB;IAEnB,SAAS,CAAC;QACR,MAAM,CAAC,cAAc,EAAE,CAAC;QACxB,MAAM,KAAK,GAAG,MAAM,KAAK,EAAE,CAAC;QAC5B,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;QACtC,MAAM,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC;AACH,CAAC"}
|
package/dist/command-spec.d.ts
CHANGED
|
@@ -7,7 +7,11 @@ import { type ListSpec } from "./list.js";
|
|
|
7
7
|
export interface CommandSpec {
|
|
8
8
|
readonly kind: "command";
|
|
9
9
|
readonly commandLine: string;
|
|
10
|
+
/** The keys that lead from the root to the Command; empty for a single-Command CLI. */
|
|
11
|
+
readonly path: readonly string[];
|
|
10
12
|
readonly command: Command;
|
|
13
|
+
/** Whether the Runtime added it, as `doctor`. */
|
|
14
|
+
readonly builtIn: boolean;
|
|
11
15
|
readonly description: string;
|
|
12
16
|
readonly help: string | undefined;
|
|
13
17
|
readonly hidden: boolean;
|
|
@@ -29,5 +33,11 @@ export interface GroupSpec {
|
|
|
29
33
|
export type SpecNode = CommandSpec | GroupSpec;
|
|
30
34
|
/** The group's Commands and groups that help and suggestions may name: hidden Commands left out. */
|
|
31
35
|
export declare function visibleCommands({ commands }: GroupSpec): Readonly<Record<string, SpecNode>>;
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
interface SpecPlace {
|
|
37
|
+
readonly path: readonly string[];
|
|
38
|
+
readonly builtIn: boolean;
|
|
39
|
+
}
|
|
40
|
+
export declare function commandSpec(commandLine: string, command: Command, { path, builtIn }?: SpecPlace): CommandSpec;
|
|
41
|
+
/** The root group of a multi-Command CLI: the author's Commands, then the Built-in Commands. */
|
|
42
|
+
export declare function groupSpec(commandLine: string, commands: Commands, builtIns: Commands): GroupSpec;
|
|
43
|
+
export {};
|
package/dist/command-spec.js
CHANGED
|
@@ -17,12 +17,15 @@ function declaredOf(command) {
|
|
|
17
17
|
cost: command.cost !== undefined,
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
const SINGLE_COMMAND = { path: [], builtIn: false };
|
|
21
|
+
export function commandSpec(commandLine, command, { path, builtIn } = SINGLE_COMMAND) {
|
|
21
22
|
const list = command.rows === undefined ? undefined : listSpec(command.rows);
|
|
22
23
|
return {
|
|
23
24
|
kind: "command",
|
|
24
25
|
commandLine,
|
|
26
|
+
path,
|
|
25
27
|
command,
|
|
28
|
+
builtIn,
|
|
26
29
|
description: command.description,
|
|
27
30
|
help: command.help,
|
|
28
31
|
hidden: command.hidden === true,
|
|
@@ -36,14 +39,25 @@ export function commandSpec(commandLine, command) {
|
|
|
36
39
|
output: list?.output ?? command.output,
|
|
37
40
|
};
|
|
38
41
|
}
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
function group(commandLine, commands) {
|
|
43
|
+
return { kind: "group", commandLine, commands };
|
|
44
|
+
}
|
|
45
|
+
/** The root group of a multi-Command CLI: the author's Commands, then the Built-in Commands. */
|
|
46
|
+
export function groupSpec(commandLine, commands, builtIns) {
|
|
47
|
+
return group(commandLine, {
|
|
48
|
+
...specsOf(commandLine, commands, { path: [], builtIn: false }),
|
|
49
|
+
...specsOf(commandLine, builtIns, { path: [], builtIn: true }),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function specsOf(commandLine, commands, { path, builtIn }) {
|
|
53
|
+
return Object.fromEntries(Object.entries(commands).map(([key, node]) => [
|
|
54
|
+
key,
|
|
55
|
+
specOf(`${commandLine} ${key}`, node, { path: [...path, key], builtIn }),
|
|
56
|
+
]));
|
|
45
57
|
}
|
|
46
|
-
function specOf(commandLine, node) {
|
|
47
|
-
return isCommand(node)
|
|
58
|
+
function specOf(commandLine, node, place) {
|
|
59
|
+
return isCommand(node)
|
|
60
|
+
? commandSpec(commandLine, node, place)
|
|
61
|
+
: group(commandLine, specsOf(commandLine, node, place));
|
|
48
62
|
}
|
|
49
63
|
//# sourceMappingURL=command-spec.js.map
|
package/dist/command-spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-spec.js","sourceRoot":"","sources":["../src/command-spec.ts"],"names":[],"mappings":"AACA,OAAO,EAA6C,SAAS,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EAAoC,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EAAE,SAAS,EAAmB,YAAY,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EAAiB,QAAQ,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":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B,EAClB,EAAE,IAAI,EAAE,OAAO,EAAa;IAE5B,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;QAC5C,GAAG;QACH,MAAM,CAAC,GAAG,WAAW,IAAI,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC;KACzE,CAAC,CACH,CAAC;AACJ,CAAC;AAED,SAAS,MAAM,CAAC,WAAmB,EAAE,IAAwB,EAAE,KAAgB;IAC7E,OAAO,SAAS,CAAC,IAAI,CAAC;QACpB,CAAC,CAAC,WAAW,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,CAAC;QACvC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AAC5D,CAAC"}
|
package/dist/context.d.ts
CHANGED
|
@@ -26,20 +26,39 @@ export interface Context<Ports = unknown, Settings = unknown> {
|
|
|
26
26
|
readonly build: BuildStamp | undefined;
|
|
27
27
|
/**
|
|
28
28
|
* The command line that reruns this CLI, to spawn one of its hidden Commands: Node, its flags and
|
|
29
|
-
* the bin, or the CLI's name, found on PATH, when run without a bin.
|
|
29
|
+
* the bin, or the CLI's name, found on PATH, when run without a bin. Spawn it as
|
|
30
|
+
* `ctx.spawn(self[0], [...self.slice(1), "daemon"])`.
|
|
30
31
|
*/
|
|
31
32
|
readonly self: readonly string[];
|
|
32
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* The folder holding this CLI's `package.json`, found from the running bin, for reading files the
|
|
35
|
+
* package ships; run through `runCli` without `bin`, it is found from `cwd`.
|
|
36
|
+
*/
|
|
33
37
|
readonly packageRoot: string;
|
|
34
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Writes a line to stderr, for long work; it never reaches stdout. Under `--json` the line is
|
|
40
|
+
* `{"progress":"..."}`.
|
|
41
|
+
*/
|
|
35
42
|
progress(message: string): void;
|
|
36
43
|
/**
|
|
37
|
-
* Aborts when the run is interrupted (Ctrl-C
|
|
38
|
-
* `fetch` and
|
|
44
|
+
* Aborts when the run is interrupted (Ctrl-C, SIGTERM, or `runCli`'s `signal`) or hits the
|
|
45
|
+
* Command's run deadline; pass it to `fetch` and the ports. An interrupt fails the run with
|
|
46
|
+
* `INTERRUPTED`, exit 130 for SIGINT or 143 for SIGTERM; a second Ctrl-C ends the process at once.
|
|
39
47
|
*/
|
|
40
48
|
readonly signal: AbortSignal;
|
|
41
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Returns a signal that aborts with `ctx.signal`, and with `DEADLINE_EXCEEDED` (exit 75) once
|
|
51
|
+
* `ms` have passed. The run reports that deadline for each error, or leaf of an `AggregateError`,
|
|
52
|
+
* that is not a `CliError` and whose `cause` chain holds its abort; any other error is reported
|
|
53
|
+
* as it is, so a `CliError` keeping the abort as `cause` keeps its own code.
|
|
54
|
+
*/
|
|
42
55
|
deadline(ms: number): AbortSignal;
|
|
56
|
+
/**
|
|
57
|
+
* Returns a signal that aborts with `DEADLINE_EXCEEDED` (exit 75) once `ms` have passed, and
|
|
58
|
+
* follows neither `ctx.signal` nor the run deadline: it bounds a call inside `runToEnd` that
|
|
59
|
+
* Ctrl-C must not cut short. Its abort is reported as `ctx.deadline`'s is.
|
|
60
|
+
*/
|
|
61
|
+
timeout(ms: number): AbortSignal;
|
|
43
62
|
/**
|
|
44
63
|
* Runs a step that must not stop halfway: the run waits for it even when stopped, and then
|
|
45
64
|
* prints `finishing <name>` on stderr.
|
|
@@ -47,33 +66,47 @@ export interface Context<Ports = unknown, Settings = unknown> {
|
|
|
47
66
|
runToEnd<T>(name: string, work: () => Promise<T>): Promise<T>;
|
|
48
67
|
/**
|
|
49
68
|
* Records the data done so far, in the shape `render` takes; the last call wins. A run that then
|
|
50
|
-
* fails, hits a deadline or is interrupted prints it
|
|
69
|
+
* fails, hits a deadline or is interrupted prints it on stdout beside its errors on stderr; a
|
|
70
|
+
* returned value replaces it. Delivered data spills like returned data.
|
|
51
71
|
*/
|
|
52
72
|
deliver(data: unknown): void;
|
|
53
73
|
/** The outside systems the CLI declared with `agentCli<Ports>()`. */
|
|
54
74
|
readonly ports: Ports;
|
|
55
75
|
/**
|
|
56
|
-
* Reads, lists, removes and atomically writes files and folders, paths resolved against `cwd
|
|
57
|
-
* failure fails the run
|
|
58
|
-
* `
|
|
76
|
+
* Reads, lists, removes and atomically writes files and folders, paths resolved against `cwd`. A
|
|
77
|
+
* failure fails the run naming the path: `PERMISSION_DENIED` (exit 2, with a hint on allowing the
|
|
78
|
+
* path in a Coding agent's sandbox), `DISK_FULL` (exit 2), `NOT_FOUND`, `NOT_A_FILE` or
|
|
79
|
+
* `ALREADY_EXISTS` (exit 1); the codes are exported.
|
|
59
80
|
*/
|
|
60
81
|
readonly files: Files;
|
|
61
82
|
/**
|
|
62
|
-
* Runs a child process
|
|
63
|
-
*
|
|
83
|
+
* Runs a child process in `cwd` with `env`, killed when the run is interrupted; on Windows every
|
|
84
|
+
* process it started is killed too. A program not found fails the run with `TOOL_MISSING` (exit 2).
|
|
64
85
|
*/
|
|
65
86
|
readonly spawn: ContextSpawn;
|
|
66
87
|
/** Deadlines, `poll` and the grace period after an interrupt run on it. */
|
|
67
88
|
readonly clock: Clock;
|
|
68
89
|
/**
|
|
69
90
|
* Calls `check` until it returns a value other than `undefined`, sleeping `intervalMs` between
|
|
70
|
-
* calls; it
|
|
91
|
+
* calls; it ends with the abort reason of `ctx.signal` or of the given `signal`.
|
|
71
92
|
*/
|
|
72
93
|
poll<T>(check: () => T | undefined | Promise<T | undefined>, options: PollOptions): Promise<T>;
|
|
73
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* The Project file found by walking up from `cwd`, parsed by the CLI's schema, or `undefined`
|
|
96
|
+
* when there is none. A file the schema rejects fails the run with `PROJECT_INVALID` (exit 2)
|
|
97
|
+
* before the Command runs. Of the built-in Commands only `doctor` reads it, for its rows.
|
|
98
|
+
*/
|
|
74
99
|
readonly project: Project<Settings> | undefined;
|
|
75
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* Reads `name` from the env, then from `$XDG_CONFIG_HOME/<cli>/.env` (default `~/.config`), with
|
|
102
|
+
* where it came from; a `.env` it cannot read fails the run with `PERMISSION_DENIED`.
|
|
103
|
+
*/
|
|
76
104
|
secret(name: string): Secret | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* The `.env` that `secret` reads: `$XDG_CONFIG_HOME/<cli>/.env`, or `~/.config/<cli>/.env`
|
|
107
|
+
* without it. Name it in a hint that asks for a missing key.
|
|
108
|
+
*/
|
|
109
|
+
readonly envFile: string;
|
|
77
110
|
/**
|
|
78
111
|
* Classifies an errno failure of the CLI's own file access, such as a store it opens itself, as
|
|
79
112
|
* `ctx.files` does; any other error comes back unchanged.
|
|
@@ -83,13 +116,17 @@ export interface Context<Ports = unknown, Settings = unknown> {
|
|
|
83
116
|
readonly force: boolean;
|
|
84
117
|
/**
|
|
85
118
|
* The command line as the caller typed it, starting with the CLI's name and shell-quoted, with
|
|
86
|
-
* each flag in `remove` dropped along with its value
|
|
87
|
-
*
|
|
119
|
+
* each flag in `remove` dropped along with its value (`--from 3` and `--from=3`, every time it was
|
|
120
|
+
* given) and the words in `add` placed before any `--`. Build every hint that names a command to
|
|
121
|
+
* run with it.
|
|
88
122
|
*/
|
|
89
123
|
commandLine(change?: CommandLineChange): string;
|
|
90
124
|
}
|
|
91
|
-
/**
|
|
92
|
-
|
|
125
|
+
/**
|
|
126
|
+
* The slice of `Context` the ports factory receives, which exists before the ports do; a test that
|
|
127
|
+
* keeps the real factory gives it the test's env and fakes.
|
|
128
|
+
*/
|
|
129
|
+
export type PortsBase = Pick<Context, "env" | "cwd" | "packageRoot" | "secret" | "envFile" | "spawn" | "files" | "clock" | "signal" | "progress" | "version" | "build" | "self" | "fileError">;
|
|
93
130
|
export interface Project<Settings = unknown> {
|
|
94
131
|
/** The folder holding the Project file. */
|
|
95
132
|
readonly root: string;
|
package/dist/define.d.ts
CHANGED
|
@@ -3,8 +3,11 @@ import type { BuildStamp, Context, PortsBase, ProjectFile } from "./context.js";
|
|
|
3
3
|
import type { ErrorTable } from "./error-table.js";
|
|
4
4
|
import { type StandardFlagName } from "./flags.js";
|
|
5
5
|
import type { Page, PageInput, RowSchema } from "./list.js";
|
|
6
|
+
import type { SideTaskRun } from "./side-task.js";
|
|
6
7
|
import type { Style } from "./style.js";
|
|
8
|
+
/** Shown in help and help JSON. */
|
|
7
9
|
export interface Example {
|
|
10
|
+
/** A realistic full command line, starting with the CLI's name. */
|
|
8
11
|
readonly command: string;
|
|
9
12
|
readonly note: string;
|
|
10
13
|
}
|
|
@@ -27,12 +30,15 @@ export interface RunDeadline<In> {
|
|
|
27
30
|
readonly ms: number;
|
|
28
31
|
/**
|
|
29
32
|
* The command line that continues the work, given as the hint of the run's `DEADLINE_EXCEEDED`;
|
|
30
|
-
* `commandLine` is `ctx.commandLine`.
|
|
33
|
+
* `commandLine` is `ctx.commandLine`. Once the deadline passes, every error of the run becomes
|
|
34
|
+
* `DEADLINE_EXCEEDED`.
|
|
31
35
|
*/
|
|
32
36
|
resume(input: In, commandLine: Context["commandLine"]): string;
|
|
33
37
|
}
|
|
34
38
|
interface CommandBase<Args extends InputSchema, Options extends InputSchema> {
|
|
39
|
+
/** The word the Command is listed under in `commands`; it labels the Command in errors and spill files. */
|
|
35
40
|
readonly name: string;
|
|
41
|
+
/** One line, shown in help and help JSON. */
|
|
36
42
|
readonly description: string;
|
|
37
43
|
/** A paragraph printed after the options in text help, and carried as `help` in help JSON. */
|
|
38
44
|
readonly help?: string;
|
|
@@ -41,48 +47,84 @@ interface CommandBase<Args extends InputSchema, Options extends InputSchema> {
|
|
|
41
47
|
readonly hidden?: boolean;
|
|
42
48
|
/**
|
|
43
49
|
* Only a person at a terminal runs it: under a Coding agent the run fails with `NEEDS_OPERATOR`
|
|
44
|
-
* before
|
|
50
|
+
* (exit 2) before its input is read, stdin included, and the hint asks the operator to type the
|
|
51
|
+
* command line after `!`. `--json` alone does not make it refuse.
|
|
45
52
|
*/
|
|
46
53
|
readonly operator?: true;
|
|
47
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* Looked up before `plan`, `run` or `start`, `--dry-run` included: missing ones fail the run with
|
|
56
|
+
* `TOOL_MISSING` (exit 2), naming each with its `install`, and `doctor` checks each.
|
|
57
|
+
*/
|
|
48
58
|
readonly tools?: readonly Tool[];
|
|
59
|
+
/**
|
|
60
|
+
* Positional operands, in the schema's order; each field's `.describe()` is its help. The last
|
|
61
|
+
* field may be a `z.array(...)`, which takes every remaining operand, and one string field may be
|
|
62
|
+
* wrapped in `orStdin`. Input the schema rejects is a usage error (exit 1) before the Command runs.
|
|
63
|
+
*/
|
|
49
64
|
readonly args?: Args;
|
|
65
|
+
/**
|
|
66
|
+
* Flags, a camelCase key typed in kebab-case; each field's `.describe()` is its help. A
|
|
67
|
+
* `z.array(...)` option collects every occurrence of its flag in order, and a repeated scalar flag
|
|
68
|
+
* keeps its last value. Input the schema rejects is a usage error (exit 1) before the Command runs.
|
|
69
|
+
*/
|
|
50
70
|
readonly options?: Options;
|
|
51
71
|
/** At `ms`, `ctx.signal` aborts and the run ends with `DEADLINE_EXCEEDED` (exit 75). */
|
|
52
72
|
readonly deadline?: RunDeadline<Input<Args, Options>>;
|
|
53
73
|
}
|
|
54
74
|
interface UnpagedCommand<Args extends InputSchema, Options extends InputSchema> extends CommandBase<Args, Options> {
|
|
75
|
+
/** The schema of the data the Command prints, published as JSON Schema in help JSON. */
|
|
55
76
|
readonly output?: z.ZodType;
|
|
56
77
|
readonly rows?: never;
|
|
57
78
|
}
|
|
58
79
|
export interface ReadCommand<Args extends InputSchema, Options extends InputSchema, Data, Ports = unknown, Settings = unknown> extends UnpagedCommand<Args, Options> {
|
|
59
80
|
readonly effect: "read";
|
|
60
81
|
run(input: Input<Args, Options>, ctx: Context<Ports, Settings>): Data | Promise<Data>;
|
|
82
|
+
/**
|
|
83
|
+
* Turns the data into short text; `--json` prints the data itself. `style` colours only when a
|
|
84
|
+
* person watches a terminal or `FORCE_COLOR` is set.
|
|
85
|
+
*/
|
|
61
86
|
render(data: Data, style: Style): string;
|
|
62
87
|
}
|
|
63
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* A read Command whose data is a page of rows, from `paginate` or `page`; the Runtime adds `--limit`
|
|
90
|
+
* (default 20), `--cursor` and `--fields`, and prints the page as `{ items, next? }`, `next` being
|
|
91
|
+
* the command line for the following page, and as text ends it with a line saying how many rows were
|
|
92
|
+
* shown and either that command line or that no pages remain. A page never spills, and `--fields` keeps only the named fields.
|
|
93
|
+
*/
|
|
64
94
|
export interface ListCommand<Args extends InputSchema, Options extends InputSchema, Row extends RowSchema, Ports = unknown, Settings = unknown> extends CommandBase<Args, Options> {
|
|
65
95
|
readonly effect: "read";
|
|
66
96
|
/** The schema of one row; the page's output schema is derived from it. */
|
|
67
97
|
readonly rows: Row;
|
|
68
98
|
readonly output?: never;
|
|
69
99
|
run(input: Flatten<OutputOf<Args> & OutputOf<Options> & PageInput>, ctx: Context<Ports, Settings>): Page<z.output<Row>> | Promise<Page<z.output<Row>>>;
|
|
100
|
+
/** Receives the page; render `page.items`. */
|
|
70
101
|
render(page: Page<z.output<Row>>, style: Style): string;
|
|
71
102
|
}
|
|
72
|
-
/**
|
|
103
|
+
/**
|
|
104
|
+
* A Command that changes something: `plan` has no side effects, `apply` performs the Plan. The
|
|
105
|
+
* Runtime adds `--dry-run`, which prints the Plan and stops; between `plan` and `apply` it checks
|
|
106
|
+
* `outputs`, then `cost`, then `confirm`, each refusal's hint holding the command line plus its flag.
|
|
107
|
+
*/
|
|
73
108
|
interface PlannedCommand<Args extends InputSchema, Options extends InputSchema, Plan, Data, Ports, Settings> extends UnpagedCommand<Args, Options> {
|
|
74
109
|
plan(input: Input<Args, Options>, ctx: Context<Ports, Settings>): Plan | Promise<Plan>;
|
|
75
110
|
apply(plan: Plan, ctx: Context<Ports, Settings>): Data | Promise<Data>;
|
|
76
111
|
render(data: Data, style: Style): string;
|
|
112
|
+
/**
|
|
113
|
+
* `--dry-run --json` prints the Plan itself, or `{ plan, outputs?, cost }` when the Command
|
|
114
|
+
* declares `outputs` or `cost`; a byte array in it prints as an index-keyed object.
|
|
115
|
+
*/
|
|
77
116
|
renderPlan(plan: Plan, style: Style): string;
|
|
78
117
|
/**
|
|
79
118
|
* A sentence stating what the Plan costs, or undefined when it is cheap. Declaring it adds
|
|
80
|
-
* `--yes
|
|
119
|
+
* `--yes`; a run whose cost is a sentence and lacks it refuses with `NOT_CONFIRMED` (exit 2), and
|
|
120
|
+
* `--dry-run` prints `cost: <sentence>`.
|
|
81
121
|
*/
|
|
82
122
|
cost?(plan: Plan): string | undefined;
|
|
83
123
|
/**
|
|
84
124
|
* The files the Plan writes, relative to `ctx.cwd`. Declaring it adds `--force`, without which
|
|
85
|
-
* a run refuses with `OUTPUT_EXISTS` when any of them exists.
|
|
125
|
+
* a run refuses with `OUTPUT_EXISTS` (exit 1) when any of them exists, and `--dry-run` lists them.
|
|
126
|
+
* Before `apply` the Runtime creates each one's folder and a temp file in it, so a sandbox denial
|
|
127
|
+
* fails with `PERMISSION_DENIED` first; without `--force` the first write to each is exclusive.
|
|
86
128
|
*/
|
|
87
129
|
outputs?(plan: Plan): readonly string[];
|
|
88
130
|
/**
|
|
@@ -96,10 +138,16 @@ export interface WriteCommand<Args extends InputSchema, Options extends InputSch
|
|
|
96
138
|
}
|
|
97
139
|
export interface DestructiveCommand<Args extends InputSchema, Options extends InputSchema, Plan, Data, Ports = unknown, Settings = unknown> extends PlannedCommand<Args, Options, Plan, Data, Ports, Settings> {
|
|
98
140
|
readonly effect: "destructive";
|
|
99
|
-
/**
|
|
141
|
+
/**
|
|
142
|
+
* The value the caller must repeat as `--confirm`, naming the target the Plan changes; without it
|
|
143
|
+
* the run refuses with exit 1.
|
|
144
|
+
*/
|
|
100
145
|
confirm(plan: Plan): string;
|
|
101
146
|
}
|
|
102
|
-
/**
|
|
147
|
+
/**
|
|
148
|
+
* A Command that keeps running, such as a preview server, until Ctrl-C or SIGTERM stops it with
|
|
149
|
+
* exit 0. Of the Standard flags it gets only `--json`.
|
|
150
|
+
*/
|
|
103
151
|
export interface ServeCommand<Args extends InputSchema, Options extends InputSchema, Data, Ports = unknown, Settings = unknown> extends UnpagedCommand<Args, Options> {
|
|
104
152
|
readonly effect: "serve";
|
|
105
153
|
/** Starts the work and returns its data, which prints at once; stop the work on `ctx.signal`. */
|
|
@@ -113,6 +161,8 @@ export interface Commands<Ports = unknown, Settings = unknown> {
|
|
|
113
161
|
interface CliBase<Ports, Settings> {
|
|
114
162
|
readonly name: string;
|
|
115
163
|
readonly version: string;
|
|
164
|
+
/** One line saying what the CLI does, shown under the first line of its help and in help JSON. */
|
|
165
|
+
readonly description: string;
|
|
116
166
|
/** The commit the build was made from and when, stamped by the bundler; `--version` prints it. */
|
|
117
167
|
readonly build?: BuildStamp;
|
|
118
168
|
/** Every code the CLI throws; a code missing here exits 70, as a bug. */
|
|
@@ -124,6 +174,14 @@ interface CliBase<Ports, Settings> {
|
|
|
124
174
|
readonly skill?: {
|
|
125
175
|
readonly source: string;
|
|
126
176
|
};
|
|
177
|
+
/**
|
|
178
|
+
* Work that runs beside every Command run, such as a usage count; return `undefined` to decline.
|
|
179
|
+
* It starts once the input is parsed, before `plan`, `run` or `start`, so it also runs for a run a
|
|
180
|
+
* guard refuses, and once the output is written the run waits for it at most `SIDE_TASK_WAIT_MS`.
|
|
181
|
+
* Nothing it throws changes stdout, stderr or the exit code; `<NAME>_DEBUG=1` prints it on stderr.
|
|
182
|
+
* It never runs for help, `--version`, a usage error or a built-in Command.
|
|
183
|
+
*/
|
|
184
|
+
sideTask?(run: SideTaskRun<Ports>): Promise<void> | undefined;
|
|
127
185
|
}
|
|
128
186
|
/** Where an Agent CLI is published and how it is installed; `doctor` and `update` read it. */
|
|
129
187
|
export interface GlobalInstall {
|
|
@@ -154,7 +212,11 @@ export interface DoctorCheck<Ports = unknown, Settings = unknown> {
|
|
|
154
212
|
readonly deadlineMs?: number;
|
|
155
213
|
/** A problem in an advisory row shows but never fails `doctor`. */
|
|
156
214
|
readonly advisory?: boolean;
|
|
157
|
-
/**
|
|
215
|
+
/**
|
|
216
|
+
* `ctx.signal` aborts at the row's deadline. A thrown error is reported as this row's problem.
|
|
217
|
+
* `ctx.project` is the Project file as a Command sees it, `undefined` when there is none;
|
|
218
|
+
* reading it when the file is unusable skips the row, since the `project` row reports the file.
|
|
219
|
+
*/
|
|
158
220
|
run(ctx: Context<Ports, Settings>): DoctorFinding | Promise<DoctorFinding>;
|
|
159
221
|
}
|
|
160
222
|
/** An Agent CLI whose Commands are reached by name, as in `tool voices list`. */
|
package/dist/define.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.js","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAyB,MAAM,YAAY,CAAC;AACrF,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAyB,MAAM,YAAY,CAAC;AACrF,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAsW5F,SAAS,cAAc,CAA2B,OAAiB;IACjE,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC9B,UAAU,CAAC,OAAO,CAAC,CAAC;IACpB,iBAAiB,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,gBAAgB,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9D,yBAAyB,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACzD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAA2B,gBAAgB,EAAE,CAAC;AAExE,0FAA0F;AAC1F,MAAM,UAAU,SAAS,CAAC,IAAwB;IAChD,OAAO,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC;AACzC,CAAC"}
|
package/dist/error-table.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { ExitClass } from "./exit-classes.js";
|
|
|
4
4
|
/** The Exit classes a CLI's own code can have; a bug or an interrupt is the Runtime's to tell. */
|
|
5
5
|
export type DeclaredExitClass = Exclude<ExitClass, "bug" | "interrupted">;
|
|
6
6
|
export interface ErrorDeclaration {
|
|
7
|
+
/** Who must act, which sets the exit code: `caller` 1, `operator` 2, `source` 3, `wait` 75. */
|
|
7
8
|
readonly class: DeclaredExitClass;
|
|
8
9
|
readonly details?: z.ZodType;
|
|
9
10
|
}
|
|
@@ -29,6 +30,10 @@ export type CliErrorInit<Declaration extends ErrorDeclaration> = {
|
|
|
29
30
|
readonly message: string;
|
|
30
31
|
readonly hint: string;
|
|
31
32
|
} & DetailsInit<Declaration> & RetryInit<Declaration>;
|
|
32
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* A `CliError` for a code of `table`, whose `details` must match the code's schema. The `hint`
|
|
35
|
+
* names the next command to run and says whether running it again can help; `retryAt` (ISO 8601)
|
|
36
|
+
* is allowed only on a wait-class code.
|
|
37
|
+
*/
|
|
33
38
|
export declare function cliError<Table extends ErrorTable, Code extends keyof Table & string>(_table: Table, code: Code, init: CliErrorInit<Table[Code]>, options?: ErrorOptions): CliError;
|
|
34
39
|
export {};
|
package/dist/error-table.js
CHANGED
|
@@ -3,7 +3,11 @@ import { CliError } from "./errors.js";
|
|
|
3
3
|
export function defineErrors(table) {
|
|
4
4
|
return table;
|
|
5
5
|
}
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* A `CliError` for a code of `table`, whose `details` must match the code's schema. The `hint`
|
|
8
|
+
* names the next command to run and says whether running it again can help; `retryAt` (ISO 8601)
|
|
9
|
+
* is allowed only on a wait-class code.
|
|
10
|
+
*/
|
|
7
11
|
export function cliError(_table, code, init, options) {
|
|
8
12
|
return new CliError({ ...init, code }, options);
|
|
9
13
|
}
|
package/dist/error-table.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-table.js","sourceRoot":"","sources":["../src/error-table.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"error-table.js","sourceRoot":"","sources":["../src/error-table.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAevC,oGAAoG;AACpG,MAAM,UAAU,YAAY,CAAiC,KAAY;IACvE,OAAO,KAAK,CAAC;AACf,CAAC;AAmBD;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CACtB,MAAa,EACb,IAAU,EACV,IAA+B,EAC/B,OAAsB;IAEtB,OAAO,IAAI,QAAQ,CAAC,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;AAClD,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -21,12 +21,14 @@ export type UsageErrorFields = Pick<CliErrorFields, "code" | "message" | "hint">
|
|
|
21
21
|
export declare class UsageError extends CliError {
|
|
22
22
|
constructor(fields: UsageErrorFields);
|
|
23
23
|
}
|
|
24
|
-
export declare const
|
|
24
|
+
export declare const INTERNAL = "INTERNAL";
|
|
25
25
|
export interface ErrorFormat {
|
|
26
26
|
readonly cliName: string;
|
|
27
27
|
readonly json: boolean;
|
|
28
28
|
readonly env: Env;
|
|
29
29
|
readonly style: Style;
|
|
30
|
+
/** Where the CLI takes bug reports, read from package.json `bugs` only when a hint names it. */
|
|
31
|
+
readonly bugs?: () => string | undefined;
|
|
30
32
|
/** Whether `error` is a bug: not a `CliError`, or one whose code nobody declared. */
|
|
31
33
|
readonly isBug: (error: unknown) => boolean;
|
|
32
34
|
}
|
|
@@ -35,6 +37,12 @@ export declare function isMissingFile(error: unknown): boolean;
|
|
|
35
37
|
export declare function isNothingThere(error: unknown): boolean;
|
|
36
38
|
export declare function debugVariable(cliName: string): string;
|
|
37
39
|
export declare function messageOf(error: unknown): string;
|
|
38
|
-
|
|
40
|
+
export declare function isDebug({ env, cliName }: Pick<ErrorFormat, "env" | "cliName">): boolean;
|
|
41
|
+
export declare function causesOf(error: unknown): unknown[];
|
|
42
|
+
export declare function traceOf(error: unknown): string;
|
|
43
|
+
/**
|
|
44
|
+
* The errors a run failed with: the leaves of nested `AggregateError`s, or the one it threw. An
|
|
45
|
+
* empty `AggregateError` is a leaf.
|
|
46
|
+
*/
|
|
39
47
|
export declare function errorsOf(error: unknown): readonly unknown[];
|
|
40
48
|
export declare function formatRuntimeError(error: unknown, format: ErrorFormat): string;
|
package/dist/errors.js
CHANGED
|
@@ -19,7 +19,7 @@ export class UsageError extends CliError {
|
|
|
19
19
|
this.name = "UsageError";
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
export const
|
|
22
|
+
export const INTERNAL = "INTERNAL";
|
|
23
23
|
export function errnoOf(error) {
|
|
24
24
|
return error instanceof Error && "code" in error && typeof error.code === "string"
|
|
25
25
|
? error.code
|
|
@@ -38,27 +38,31 @@ export function debugVariable(cliName) {
|
|
|
38
38
|
export function messageOf(error) {
|
|
39
39
|
return error instanceof Error ? error.message : String(error);
|
|
40
40
|
}
|
|
41
|
-
function isDebug({ env, cliName }) {
|
|
41
|
+
export function isDebug({ env, cliName }) {
|
|
42
42
|
return Boolean(env[debugVariable(cliName)]);
|
|
43
43
|
}
|
|
44
44
|
function bugHint(format) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
const bugs = format.bugs?.();
|
|
46
|
+
if (isDebug(format)) {
|
|
47
|
+
const where = "the stack trace shows where it failed";
|
|
48
|
+
return bugs === undefined ? where : `${where}; report it at ${bugs}`;
|
|
49
|
+
}
|
|
50
|
+
const rerun = `rerun with ${debugVariable(format.cliName)}=1 to see the stack trace`;
|
|
51
|
+
return bugs === undefined ? rerun : `${rerun}, then report it at ${bugs}`;
|
|
48
52
|
}
|
|
49
53
|
function fieldsOf(error, format) {
|
|
50
54
|
if (error instanceof CliError) {
|
|
51
55
|
const { code, message, hint, details, retryAt } = error;
|
|
52
56
|
return { code, message, hint: format.isBug(error) ? bugHint(format) : hint, details, retryAt };
|
|
53
57
|
}
|
|
54
|
-
return { code:
|
|
58
|
+
return { code: INTERNAL, message: messageOf(error), hint: bugHint(format) };
|
|
55
59
|
}
|
|
56
|
-
function causesOf(error) {
|
|
60
|
+
export function causesOf(error) {
|
|
57
61
|
return error instanceof Error && error.cause !== undefined
|
|
58
62
|
? [error.cause, ...causesOf(error.cause)]
|
|
59
63
|
: [];
|
|
60
64
|
}
|
|
61
|
-
function traceOf(error) {
|
|
65
|
+
export function traceOf(error) {
|
|
62
66
|
return error instanceof Error ? (error.stack ?? error.message) : String(error);
|
|
63
67
|
}
|
|
64
68
|
/** Under debug: a bug's stack trace, then every error's cause chain. */
|
|
@@ -71,9 +75,14 @@ function debugTrace(error, format) {
|
|
|
71
75
|
];
|
|
72
76
|
return lines.length === 0 ? undefined : lines.join("\n");
|
|
73
77
|
}
|
|
74
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* The errors a run failed with: the leaves of nested `AggregateError`s, or the one it threw. An
|
|
80
|
+
* empty `AggregateError` is a leaf.
|
|
81
|
+
*/
|
|
75
82
|
export function errorsOf(error) {
|
|
76
|
-
return error instanceof AggregateError && error.errors.length > 0
|
|
83
|
+
return error instanceof AggregateError && error.errors.length > 0
|
|
84
|
+
? error.errors.flatMap(errorsOf)
|
|
85
|
+
: [error];
|
|
77
86
|
}
|
|
78
87
|
function errorLines(error, format) {
|
|
79
88
|
const fields = fieldsOf(error, format);
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAaA,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,IAAI,CAAS;IACb,IAAI,CAAS;IACb,OAAO,CAAU;IACjB,OAAO,CAAqB;IAErC,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAkB,EAAE,OAAsB;QAC3F,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAID,0EAA0E;AAC1E,MAAM,OAAO,UAAW,SAAQ,QAAQ;IACtC,YAAY,MAAwB;QAClC,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AAED,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAaA,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,IAAI,CAAS;IACb,IAAI,CAAS;IACb,OAAO,CAAU;IACjB,OAAO,CAAqB;IAErC,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAkB,EAAE,OAAsB;QAC3F,K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AAC;AACjE,CAAC"}
|
package/dist/exit-classes.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare const EXIT_CODES: {
|
|
|
14
14
|
readonly wait: 75;
|
|
15
15
|
readonly bug: 70;
|
|
16
16
|
};
|
|
17
|
+
export declare const RUNTIME_EXIT_CLASSES: Readonly<Record<string, ExitClass>>;
|
|
17
18
|
/** The codes of `errors` that the Runtime already declares, which a CLI cannot redeclare. */
|
|
18
19
|
export declare function runtimeCodesIn(errors: ErrorTable): string[];
|
|
19
20
|
export declare function isBug(error: unknown, errors: ErrorTable): boolean;
|