balchemy 0.2.2 → 0.2.3

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.
@@ -0,0 +1,29 @@
1
+ import type { JsonValue, Reporter } from "./output.js";
2
+ export type TerminalErrorCode = "UNKNOWN_COMMAND" | "UNKNOWN_FLAG" | "CONFIG_FILE_MISSING" | "CONFIG_ENV_MISSING" | "CONFIG_YAML_INVALID" | "FILE_OVERWRITE_CONFIRMATION_REQUIRED" | "FILE_PERMISSION_DENIED" | "CI_PROMPT_BLOCKED" | "TERMINAL_UNSUPPORTED_TUI" | "RUNTIME_ERROR";
3
+ export interface TerminalErrorParams {
4
+ code: TerminalErrorCode;
5
+ title: string;
6
+ cause: string;
7
+ fix: string;
8
+ commandSuggestion?: string;
9
+ docsHint?: string;
10
+ exitCode: number;
11
+ retryable?: boolean;
12
+ debugDetails?: string;
13
+ }
14
+ export declare class TerminalError extends Error {
15
+ readonly code: TerminalErrorCode;
16
+ readonly title: string;
17
+ readonly cause: string;
18
+ readonly fix: string;
19
+ readonly commandSuggestion?: string;
20
+ readonly docsHint: string;
21
+ readonly exitCode: number;
22
+ readonly retryable: boolean;
23
+ readonly debugDetails?: string;
24
+ constructor(params: TerminalErrorParams);
25
+ }
26
+ export declare function toTerminalError(err: unknown): TerminalError;
27
+ export declare function terminalErrorToJson(error: TerminalError): JsonValue;
28
+ export declare function renderTerminalError(reporter: Reporter, error: TerminalError): void;
29
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,MAAM,iBAAiB,GACzB,iBAAiB,GACjB,cAAc,GACd,qBAAqB,GACrB,oBAAoB,GACpB,qBAAqB,GACrB,sCAAsC,GACtC,wBAAwB,GACxB,mBAAmB,GACnB,0BAA0B,GAC1B,eAAe,CAAC;AAEpB,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,iBAAiB,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;gBAEnB,MAAM,EAAE,mBAAmB;CAaxC;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,aAAa,CA0D3D;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,CAWnE;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,GAAG,IAAI,CAiBlF"}
package/dist/errors.js ADDED
@@ -0,0 +1,115 @@
1
+ import { C } from "./colors.js";
2
+ export class TerminalError extends Error {
3
+ code;
4
+ title;
5
+ cause;
6
+ fix;
7
+ commandSuggestion;
8
+ docsHint;
9
+ exitCode;
10
+ retryable;
11
+ debugDetails;
12
+ constructor(params) {
13
+ super(params.title);
14
+ this.name = "TerminalError";
15
+ this.code = params.code;
16
+ this.title = params.title;
17
+ this.cause = params.cause;
18
+ this.fix = params.fix;
19
+ this.commandSuggestion = params.commandSuggestion;
20
+ this.docsHint = params.docsHint ?? "Run balchemy --help for command usage.";
21
+ this.exitCode = params.exitCode;
22
+ this.retryable = params.retryable ?? false;
23
+ this.debugDetails = params.debugDetails;
24
+ }
25
+ }
26
+ export function toTerminalError(err) {
27
+ if (err instanceof TerminalError)
28
+ return err;
29
+ const message = err instanceof Error ? err.message : String(err);
30
+ if (/Config file not found:/i.test(message)) {
31
+ return new TerminalError({
32
+ code: "CONFIG_FILE_MISSING",
33
+ title: "Missing config file",
34
+ cause: message,
35
+ fix: "Run balchemy init or pass a config path.",
36
+ commandSuggestion: "balchemy start ./agent.config.yaml",
37
+ exitCode: 2,
38
+ debugDetails: err instanceof Error ? err.stack : undefined,
39
+ });
40
+ }
41
+ if (/Environment variable '.+' referenced in config is not set/i.test(message)) {
42
+ return new TerminalError({
43
+ code: "CONFIG_ENV_MISSING",
44
+ title: "Missing environment variable",
45
+ cause: message,
46
+ fix: "Add the missing variable to .env next to the config file or export it before running balchemy start.",
47
+ commandSuggestion: "balchemy config validate agent.config.yaml --verbose",
48
+ exitCode: 2,
49
+ debugDetails: err instanceof Error ? err.stack : undefined,
50
+ });
51
+ }
52
+ if (/Failed to parse YAML config:/i.test(message)) {
53
+ return new TerminalError({
54
+ code: "CONFIG_YAML_INVALID",
55
+ title: "Invalid YAML config",
56
+ cause: message,
57
+ fix: "Check indentation and validate the config before starting the cockpit.",
58
+ commandSuggestion: "balchemy config validate agent.config.yaml --verbose",
59
+ exitCode: 2,
60
+ debugDetails: err instanceof Error ? err.stack : undefined,
61
+ });
62
+ }
63
+ if (/EACCES|permission denied/i.test(message)) {
64
+ return new TerminalError({
65
+ code: "FILE_PERMISSION_DENIED",
66
+ title: "Cannot access file",
67
+ cause: message,
68
+ fix: "Choose a writable path or adjust permissions.",
69
+ exitCode: 6,
70
+ debugDetails: err instanceof Error ? err.stack : undefined,
71
+ });
72
+ }
73
+ return new TerminalError({
74
+ code: "RUNTIME_ERROR",
75
+ title: "Command failed",
76
+ cause: message,
77
+ fix: "Run the command again with --debug for technical details, or run balchemy --help for usage.",
78
+ commandSuggestion: "balchemy --help",
79
+ exitCode: 1,
80
+ retryable: false,
81
+ debugDetails: err instanceof Error ? err.stack : undefined,
82
+ });
83
+ }
84
+ export function terminalErrorToJson(error) {
85
+ return {
86
+ code: error.code,
87
+ title: error.title,
88
+ cause: error.cause,
89
+ fix: error.fix,
90
+ commandSuggestion: error.commandSuggestion ?? null,
91
+ docsHint: error.docsHint,
92
+ exitCode: error.exitCode,
93
+ retryable: error.retryable,
94
+ };
95
+ }
96
+ export function renderTerminalError(reporter, error) {
97
+ if (reporter.flags.json)
98
+ return;
99
+ reporter.error(`\n ${C.ERR}${error.title}${C.R}\n`);
100
+ reporter.error(` ${C.D}Cause${C.R} ${error.cause}\n`);
101
+ reporter.error(` ${C.D}Fix${C.R} ${error.fix}\n`);
102
+ if (error.commandSuggestion) {
103
+ reporter.error(` ${C.D}Command${C.R} ${C.W}${error.commandSuggestion}${C.R}\n`);
104
+ }
105
+ reporter.error(` ${C.D}Help${C.R} ${error.docsHint}\n`);
106
+ reporter.error(` ${C.D}Exit${C.R} ${error.exitCode}\n`);
107
+ if (reporter.flags.debug && error.debugDetails) {
108
+ reporter.error(`\n${C.D}${error.debugDetails}${C.R}\n`);
109
+ }
110
+ else if (error.debugDetails) {
111
+ reporter.error(` ${C.D}Debug${C.R} Re-run with --debug for technical details.\n`);
112
+ }
113
+ reporter.error("\n");
114
+ }
115
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AA2BhC,MAAM,OAAO,aAAc,SA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CAAC,GAAG,IAAI,CAAC,CAAC;IACtD,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC5B,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACnF,CAAC;IACD,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC,QAAQ,IAAI,CAAC,CAAC;IAC5D,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC,QAAQ,IAAI,CAAC,CAAC;IAC5D,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;QAC/C,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC1D,CAAC;SAAM,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;QAC9B,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,iDAAiD,CAAC,CAAC;IACvF,CAAC;IACD,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACvB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -2,21 +2,8 @@
2
2
  /**
3
3
  * balchemy CLI entry point.
4
4
  *
5
- * On launch:
6
- * - If ~/.balchemy/agents.enc has saved agents offer resume, choose, or create/connect
7
- * - If no saved agent → run wizard
8
- *
9
- * Sub-commands:
10
- * (no args) Resume cached agent or run wizard
11
- * init / --init Force run wizard (ignore cache)
12
- * start [config] Start from agent.config.yaml
13
- * docker [outDir] Generate Docker files
14
- * list List saved agents
15
- *
16
- * Flags:
17
- * --help, -h Show help
18
- * --version, -v Show version
19
- * --no-color Disable colored output
5
+ * Public terminal surface for setup, local agent context, config validation,
6
+ * Docker file generation, and the Ink cockpit.
20
7
  */
21
8
  export {};
22
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;GAkBG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;GAKG"}