argsbarg 6.1.2 → 6.1.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.
- package/CHANGELOG.md +65 -1
- package/README.md +17 -19
- package/bin/argsbarg +10 -0
- package/docs/README.md +4 -3
- package/docs/ai-skills.md +4 -2
- package/docs/bundled-docs.md +50 -25
- package/docs/cli-program.md +52 -10
- package/docs/config-schema.md +10 -11
- package/docs/configure.md +2 -0
- package/docs/decisions.md +40 -0
- package/docs/developing.md +43 -5
- package/docs/http-server.md +171 -0
- package/docs/json-schema-subset.md +51 -0
- package/docs/mcp.md +4 -2
- package/docs/output-schema.md +55 -62
- package/examples/formats.ts +6 -6
- package/examples/full-example/Formula/full-example.rb +35 -0
- package/examples/full-example/README.md +20 -21
- package/examples/full-example/docs/README.md +1 -1
- package/examples/full-example/docs/cli-schema.json +1790 -98
- package/examples/full-example/docs/cli.md +1990 -0
- package/examples/full-example/docs/http.md +28 -29
- package/examples/full-example/docs/mcp.md +8 -22
- package/examples/full-example/docs/openapi.json +783 -50
- package/examples/full-example/docs/skill.md +10 -10
- package/examples/full-example/justfile +11 -1
- package/examples/full-example/src/commands/render-json/__generated__/RenderJsonInputSchema.json +15 -0
- package/examples/full-example/src/commands/render-json/__generated__/index.ts +5 -0
- package/examples/full-example/src/commands/render-json/command.test.ts +46 -0
- package/examples/full-example/src/commands/render-json/command.ts +30 -0
- package/examples/full-example/src/commands/render-json/types.ts +9 -0
- package/examples/full-example/src/commands/status/__generated__/StatusJsonOutputSchema.json +15 -0
- package/examples/full-example/src/commands/status/__generated__/index.ts +2 -2
- package/examples/full-example/src/commands/status/command.ts +5 -13
- package/examples/full-example/src/commands/status/types.ts +1 -14
- package/examples/full-example/src/commands/workspaces/__generated__/WorkspaceNameInputSchema.json +15 -0
- package/examples/full-example/src/commands/workspaces/__generated__/index.ts +5 -0
- package/examples/full-example/src/commands/workspaces/command.test.ts +58 -0
- package/examples/full-example/src/commands/workspaces/command.ts +94 -0
- package/examples/full-example/src/commands/workspaces/types.ts +6 -0
- package/examples/full-example/src/db/index.test.ts +86 -0
- package/examples/full-example/src/db/index.ts +101 -0
- package/examples/full-example/src/db/migrate.test.ts +35 -0
- package/examples/full-example/src/db/migrate.ts +69 -0
- package/examples/full-example/src/db/migrations/001_workspaces.sql +6 -0
- package/examples/full-example/src/db/tables/workspaces.ts +66 -0
- package/examples/full-example/src/program.ts +11 -36
- package/examples/full-example/src/types/argsbarg.d.ts +11 -0
- package/examples/full-example/src/types/md.d.ts +4 -0
- package/examples/full-example/tsconfig.json +5 -2
- package/examples/mcp-test.ts +1 -2
- package/examples/minimal.ts +1 -7
- package/examples/nested.ts +1 -2
- package/examples/option-required.ts +1 -1
- package/examples/servers.ts +4 -5
- package/index.d.ts +431 -136
- package/package.json +19 -2
- package/src/builtins/builtins.test.ts +7 -7
- package/src/builtins/completion-bash.ts +1 -1
- package/src/builtins/completion-fish.ts +1 -1
- package/src/builtins/completion-group.ts +4 -4
- package/src/builtins/completion-simulate-shared.ts +9 -0
- package/src/builtins/completion-zsh.ts +1 -1
- package/src/builtins/config.test.ts +3 -3
- package/src/builtins/config.ts +9 -9
- package/src/builtins/configure-copy.ts +2 -2
- package/src/builtins/configure.ts +4 -4
- package/src/builtins/dispatch.ts +19 -18
- package/src/builtins/export.ts +7 -5
- package/src/builtins/http.ts +68 -0
- package/src/builtins/mcp.ts +28 -4
- package/src/builtins/presentation.ts +6 -6
- package/src/builtins/registry.ts +6 -6
- package/src/builtins/scopes.ts +2 -2
- package/src/builtins/version.ts +1 -1
- package/src/cli-tool/full-example-capabilities.test.ts +10 -15
- package/src/cli-tool/main.ts +1 -1
- package/src/cli-tool/program.ts +3 -2
- package/src/cli-tool/prompt.ts +1 -1
- package/src/cli-tool/run-schemagen.ts +1 -3
- package/src/cli-tool/schemagen/cleanup.ts +6 -7
- package/src/cli-tool/schemagen/discover-schema-roots.ts +66 -120
- package/src/cli-tool/schemagen/index.ts +2 -2
- package/src/cli-tool/schemagen/names.ts +8 -13
- package/src/cli-tool/schemagen/run.ts +21 -28
- package/src/cli-tool/schemagen/schemagen.test.ts +136 -46
- package/src/config/bindings.test.ts +1 -1
- package/src/config/bindings.ts +1 -1
- package/src/config/bootstrap.test.ts +1 -1
- package/src/config/bootstrap.ts +36 -4
- package/src/config/context.test.ts +1 -1
- package/src/config/context.ts +1 -1
- package/src/config/entry.ts +1 -1
- package/src/config/file.test.ts +1 -1
- package/src/config/file.ts +3 -3
- package/src/config/manifest.ts +1 -1
- package/src/config/resolve.test.ts +1 -1
- package/src/config/resolve.ts +1 -1
- package/src/config/schema.ts +1 -1
- package/src/config/validate.ts +1 -1
- package/src/{install → configure/artifacts}/binary-placement.test.ts +1 -1
- package/src/{install → configure/artifacts}/binary-placement.ts +1 -1
- package/src/{install → configure/artifacts}/gh-release-update.ts +1 -1
- package/src/{install → configure/artifacts}/install-validate.test.ts +3 -3
- package/src/{install → configure/artifacts}/mcp-config.ts +1 -1
- package/src/{install → configure/artifacts}/mcp-opencode.test.ts +1 -1
- package/src/{install → configure/artifacts}/mcp-opencode.ts +1 -1
- package/src/{install → configure/artifacts}/paths.ts +5 -5
- package/src/configure/artifacts/plan.ts +24 -0
- package/src/{install → configure/artifacts}/status.test.ts +1 -1
- package/src/{install → configure/artifacts}/status.ts +2 -2
- package/src/{install → configure/artifacts}/target-base.ts +1 -1
- package/src/{install → configure/artifacts}/target-detect.ts +1 -1
- package/src/{install → configure/artifacts}/target-effective.ts +3 -9
- package/src/{install → configure/artifacts}/target-mcp-cli.ts +1 -1
- package/src/{install → configure/artifacts}/target-mcp-json.ts +1 -1
- package/src/{install → configure/artifacts}/target-plan-build.ts +2 -2
- package/src/{install → configure/artifacts}/target-registry.ts +2 -2
- package/src/{install → configure/artifacts}/target-scope.ts +3 -3
- package/src/{install → configure/artifacts}/target-skill.ts +1 -1
- package/src/{install → configure/artifacts}/target-types.ts +2 -2
- package/src/{install → configure/artifacts}/targets/app.ts +5 -5
- package/src/{install → configure/artifacts}/targets/chatgpt-mcp.ts +2 -2
- package/src/{install → configure/artifacts}/targets/claude-code-mcp.ts +2 -2
- package/src/{install → configure/artifacts}/targets/claude-desktop-mcp.ts +2 -2
- package/src/{install → configure/artifacts}/targets/claude-skill.ts +2 -2
- package/src/{install → configure/artifacts}/targets/codex-mcp.ts +2 -2
- package/src/{install → configure/artifacts}/targets/codex-skill.ts +2 -2
- package/src/{install → configure/artifacts}/targets/configure.ts +5 -5
- package/src/{install → configure/artifacts}/targets/cursor-mcp.ts +2 -2
- package/src/{install → configure/artifacts}/targets/cursor-skill.ts +2 -2
- package/src/{install → configure/artifacts}/targets/index.ts +1 -1
- package/src/{install → configure/artifacts}/targets/openclaw-mcp.ts +2 -2
- package/src/{install → configure/artifacts}/targets/openclaw-skill.ts +3 -3
- package/src/{install → configure/artifacts}/targets/opencode-mcp.ts +5 -5
- package/src/{install → configure/artifacts}/targets/opencode-skill.ts +3 -3
- package/src/{install → configure/artifacts}/targets.test.ts +1 -1
- package/src/{install → configure/artifacts}/uninstall.ts +1 -1
- package/src/configure/configure.test.ts +11 -11
- package/src/configure/index.ts +14 -14
- package/src/configure/prompt.ts +2 -2
- package/src/{context.ts → core/context.ts} +26 -20
- package/src/{json-leaf.test.ts → core/json-leaf.test.ts} +4 -4
- package/src/{leaf-inputs.test.ts → core/leaf-inputs.test.ts} +7 -7
- package/src/{leaf-inputs.ts → core/leaf-inputs.ts} +16 -12
- package/src/{parse.test.ts → core/parse.test.ts} +97 -109
- package/src/{parse.ts → core/parse.ts} +129 -31
- package/src/{schema.ts → core/schema.ts} +25 -13
- package/src/{types.ts → core/types.ts} +225 -35
- package/src/{validate.ts → core/validate.ts} +39 -29
- package/src/docs/builtin.ts +8 -19
- package/src/docs/{api-guide.test.ts → cli-guide.test.ts} +21 -21
- package/src/docs/{api-guide.ts → cli-guide.ts} +45 -16
- package/src/docs/docs.test.ts +76 -41
- package/src/docs/http-guide.ts +37 -34
- package/src/docs/mcp-guide.ts +12 -14
- package/src/docs/mcp-resources.test.ts +2 -3
- package/src/docs/mcp-resources.ts +6 -11
- package/src/docs/resolve.ts +22 -30
- package/src/docs/save.ts +3 -3
- package/src/exports/cli.ts +47 -0
- package/src/exports/headless.ts +13 -0
- package/src/exports/http.ts +6 -0
- package/src/exports/mcp.ts +6 -0
- package/src/{headless.test.ts → headless/routing.test.ts} +3 -3
- package/src/{headless.ts → headless/routing.ts} +3 -3
- package/src/headless/tool-call.ts +114 -46
- package/src/help.test.ts +152 -0
- package/src/help.ts +3 -3
- package/src/hooks/builtin.ts +20 -0
- package/src/hooks/run.ts +142 -0
- package/src/http/openapi.ts +182 -0
- package/src/http/readiness.ts +78 -0
- package/src/{api → http}/result.ts +16 -5
- package/src/http/routes.ts +329 -0
- package/src/http/server.ts +225 -0
- package/src/index.ts +36 -25
- package/src/log/ecs.test.ts +43 -0
- package/src/log/ecs.ts +59 -0
- package/src/log/emitter.ts +166 -0
- package/src/mcp/bundle.ts +2 -2
- package/src/mcp/claude.test.ts +1 -1
- package/src/mcp/claude.ts +4 -4
- package/src/{hidden-mcpb.test.ts → mcp/hidden-mcpb.test.ts} +10 -9
- package/src/mcp/result.ts +2 -2
- package/src/mcp/server.ts +54 -6
- package/src/mcp/tools.ts +9 -20
- package/src/{capabilities.ts → runtime/capabilities.ts} +11 -11
- package/src/{cli-errors.ts → runtime/cli-errors.ts} +4 -4
- package/src/{cli.ts → runtime/cli.ts} +159 -49
- package/src/runtime/exposure.ts +102 -0
- package/src/{invoke.test.ts → runtime/invoke.test.ts} +31 -7
- package/src/server/context.ts +25 -0
- package/src/server/overrides.ts +112 -0
- package/src/skill/generate.ts +8 -8
- package/src/skill/hint.ts +1 -1
- package/src/skill/install.ts +2 -2
- package/src/skill/naming.ts +1 -1
- package/src/{test-fixtures.ts → test/fixtures.ts} +3 -2
- package/src/{config.integration.test.ts → test/integration/config.test.ts} +8 -8
- package/src/{api.integration.test.ts → test/integration/http.test.ts} +170 -67
- package/src/{mcp.integration.test.ts → test/integration/mcp.test.ts} +11 -57
- package/docs/api-server.md +0 -141
- package/examples/full-example/docs/api.md +0 -511
- package/examples/full-example/src/commands/status/__generated__/outputSchema.json +0 -28
- package/examples/full-example/src/config/__generated__/configSchema.json +0 -40
- package/examples/full-example/src/config/__generated__/index.ts +0 -5
- package/examples/full-example/src/config/types.ts +0 -24
- package/src/api/openapi.ts +0 -117
- package/src/api/server.ts +0 -120
- package/src/builtins/api.ts +0 -38
- package/src/hidden.ts +0 -30
- package/src/install/plan.ts +0 -53
- /package/src/{install → configure/artifacts}/detect-installed.ts +0 -0
- /package/src/{install → configure/artifacts}/gh-release-update.test.ts +0 -0
- /package/src/{install → configure/artifacts}/mcp-codex.test.ts +0 -0
- /package/src/{install → configure/artifacts}/mcp-codex.ts +0 -0
- /package/src/{install → configure/artifacts}/mcp-openclaw.test.ts +0 -0
- /package/src/{install → configure/artifacts}/mcp-openclaw.ts +0 -0
- /package/src/{install → configure/artifacts}/normalize-uninstall.ts +0 -0
- /package/src/{install → configure/artifacts}/normalize.ts +0 -0
- /package/src/{install → configure/artifacts}/opts.ts +0 -0
- /package/src/{install → configure/artifacts}/shell.ts +0 -0
- /package/src/{formats.test.ts → core/formats.test.ts} +0 -0
- /package/src/{formats.ts → core/formats.ts} +0 -0
- /package/src/{respond.ts → core/respond.ts} +0 -0
- /package/src/{types.test.ts → core/types.test.ts} +0 -0
- /package/src/{api → http}/schema-deref.test.ts +0 -0
- /package/src/{api → http}/schema-deref.ts +0 -0
package/index.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
-
/** Resolved absolute path to the app JSON config file (`~/.local/lib/<key>/config.json`). */
|
|
4
|
-
export declare function resolveAppConfigPath(program: CliProgram): string;
|
|
5
|
-
/** Human-readable config path for error messages (`~/…` when under home). */
|
|
6
|
-
export declare function displayAppConfigPath(program: CliProgram): string;
|
|
7
3
|
export type ResolvedConfig = Record<string, unknown>;
|
|
8
4
|
declare class EmptyAppConfigSnapshot {
|
|
9
5
|
private readonly program;
|
|
@@ -52,19 +48,25 @@ export type CliLeafInputs = Record<string, boolean | number | string | string[]
|
|
|
52
48
|
export declare class CliContext {
|
|
53
49
|
readonly appName: string;
|
|
54
50
|
readonly commandPath: string[];
|
|
55
|
-
|
|
51
|
+
args: string[];
|
|
56
52
|
readonly program: CliProgram;
|
|
57
|
-
|
|
53
|
+
opts: Record<string, string>;
|
|
58
54
|
readonly invocation: CliInvocation;
|
|
59
55
|
readonly appConfig: AnyAppConfigSnapshot;
|
|
60
56
|
/** Original flat tool arguments for API/MCP invocations (when provided). */
|
|
61
57
|
readonly toolArgs?: Record<string, unknown>;
|
|
58
|
+
/** Path parameter values from `:param` router descent. */
|
|
59
|
+
readonly pathParams: Record<string, string>;
|
|
62
60
|
/** Pipable Json option values read from stdin before the handler (CLI only). */
|
|
63
61
|
readonly preloadedJson: Record<string, unknown>;
|
|
62
|
+
/** Per-invocation bag; `beforeInvoke` may write. */
|
|
63
|
+
readonly locals: CliLocals;
|
|
64
|
+
/** Shared server state for HTTP/MCP invocations. */
|
|
65
|
+
runtime?: ServerRuntime;
|
|
64
66
|
private response?;
|
|
65
67
|
private leafInputsCache?;
|
|
66
68
|
/** Captures the program root, routed path, positional words, and option map for a leaf handler. */
|
|
67
|
-
constructor(appName: string, commandPath: string[], args: string[], opts: Record<string, string>, program: CliProgram, invocation?: CliInvocation, appConfig?: AnyAppConfigSnapshot, toolArgs?: Record<string, unknown>, preloadedJson?: Record<string, unknown
|
|
69
|
+
constructor(appName: string, commandPath: string[], args: string[], opts: Record<string, string>, program: CliProgram, invocation?: CliInvocation, appConfig?: AnyAppConfigSnapshot, toolArgs?: Record<string, unknown>, preloadedJson?: Record<string, unknown>, pathParams?: Record<string, string>, locals?: CliLocals, runtime?: ServerRuntime);
|
|
68
70
|
/**
|
|
69
71
|
* Sets the machine-readable response for API/MCP invocations, or writes to stdout in CLI mode.
|
|
70
72
|
* May only be called once per invocation.
|
|
@@ -107,14 +109,6 @@ export declare class CliContext {
|
|
|
107
109
|
* {@link inputs} cast to a schemagen or app-defined input type (consumer-asserted; not inferred from `inputSchema`).
|
|
108
110
|
*/
|
|
109
111
|
inputsAs<T = CliLeafInputs>(): T;
|
|
110
|
-
/**
|
|
111
|
-
* @deprecated Use {@link inputs} or {@link inputsAs}.
|
|
112
|
-
*/
|
|
113
|
-
readLeafInputs(): CliLeafInputs;
|
|
114
|
-
/**
|
|
115
|
-
* @deprecated Use sync {@link readLeafInputs} — stdin is preloaded before the handler runs.
|
|
116
|
-
*/
|
|
117
|
-
readLeafInputsAsync(): Promise<CliLeafInputs>;
|
|
118
112
|
private _leafNode;
|
|
119
113
|
private _posMap;
|
|
120
114
|
private _positionalMap;
|
|
@@ -122,7 +116,7 @@ export declare class CliContext {
|
|
|
122
116
|
/**
|
|
123
117
|
* How a leaf handler was dispatched.
|
|
124
118
|
*/
|
|
125
|
-
export type CliInvocation = "cli" | "mcp" | "
|
|
119
|
+
export type CliInvocation = "cli" | "mcp" | "http";
|
|
126
120
|
/**
|
|
127
121
|
* Option kinds: presence (boolean flag), string (free-form text), number (strict double), enum (fixed choices), or json (parsed JSON object/array).
|
|
128
122
|
*/
|
|
@@ -170,14 +164,52 @@ export declare enum CliFallbackMode {
|
|
|
170
164
|
*/
|
|
171
165
|
UnknownOnly = "unknownOnly"
|
|
172
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Per-surface CLI exposure (help, completions, cli-schema).
|
|
169
|
+
*/
|
|
170
|
+
export interface CliCliExposureConfig {
|
|
171
|
+
/** When `false`, not callable via CLI (cascades to descendants). Default: true. */
|
|
172
|
+
enabled?: boolean;
|
|
173
|
+
/** Callable; omit from help, completions, and schema export. */
|
|
174
|
+
hidden?: boolean;
|
|
175
|
+
completions?: {
|
|
176
|
+
enabled?: boolean;
|
|
177
|
+
hidden?: boolean;
|
|
178
|
+
};
|
|
179
|
+
schema?: {
|
|
180
|
+
enabled?: boolean;
|
|
181
|
+
hidden?: boolean;
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/** HTTP method for REST leaves. */
|
|
185
|
+
export type CliHttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
186
|
+
/**
|
|
187
|
+
* Per-node HTTP exposure and response defaults (routers: segment/enabled/hidden; leaves: full set).
|
|
188
|
+
*/
|
|
189
|
+
export interface CliHttpExposureConfig {
|
|
190
|
+
/** When `false`, omit from HTTP route table. Default: exposed. */
|
|
191
|
+
enabled?: boolean;
|
|
192
|
+
/** Callable; omit from OpenAPI / route discovery. */
|
|
193
|
+
hidden?: boolean;
|
|
194
|
+
/** Override inferred HTTP verb. */
|
|
195
|
+
method?: CliHttpMethod;
|
|
196
|
+
/** URL path segment override (≠ `key`). */
|
|
197
|
+
segment?: string;
|
|
198
|
+
/** Default success HTTP status when handler omits `ctx.respond({ status })`. */
|
|
199
|
+
successStatus?: number;
|
|
200
|
+
/** Default success Content-Type (OpenAPI + response headers). */
|
|
201
|
+
successContentType?: string;
|
|
202
|
+
/** Default Content-Disposition for binary/downloads. */
|
|
203
|
+
contentDisposition?: string;
|
|
204
|
+
}
|
|
173
205
|
/**
|
|
174
206
|
* A named flag or value option (`--long`, `-short`), listed on command `options`.
|
|
175
207
|
*/
|
|
176
208
|
export interface CliOption {
|
|
177
209
|
/** Option name (e.g., "name", "verbose"). */
|
|
178
210
|
name: string;
|
|
179
|
-
/**
|
|
180
|
-
|
|
211
|
+
/** Per-surface CLI exposure for this option. */
|
|
212
|
+
cli?: Pick<CliCliExposureConfig, "hidden">;
|
|
181
213
|
/** Description shown in help. */
|
|
182
214
|
description: string;
|
|
183
215
|
/** Option kind: presence flag, string value, or number value. */
|
|
@@ -227,7 +259,7 @@ export interface CliPositional {
|
|
|
227
259
|
*/
|
|
228
260
|
argMax?: number;
|
|
229
261
|
}
|
|
230
|
-
/**
|
|
262
|
+
/** @experimental MCP bundle output options (program root `mcpServer.bundle` only). */
|
|
231
263
|
export interface CliMcpBundleConfig {
|
|
232
264
|
author?: {
|
|
233
265
|
name: string;
|
|
@@ -242,10 +274,15 @@ export interface CliMcpBundleConfig {
|
|
|
242
274
|
/**
|
|
243
275
|
* Enables `myapp mcp` and MCP stdio server metadata (program root only).
|
|
244
276
|
* Must include `enabled: true`; omit `mcpServer` entirely to disable MCP.
|
|
277
|
+
* @experimental
|
|
245
278
|
*/
|
|
246
279
|
export interface CliMcpServerConfig {
|
|
247
280
|
/** When `true`, enables the `mcp` built-in and MCP stdio server. */
|
|
248
281
|
enabled: boolean;
|
|
282
|
+
/** MCP error response defaults. */
|
|
283
|
+
errors?: CliMcpServerErrorsConfig;
|
|
284
|
+
/** Observe-only hooks for JSON-RPC messages. */
|
|
285
|
+
hooks?: CliMcpWireHooks;
|
|
249
286
|
/** When `true`, `mcp bundle` writes `dist/<key>.mcpb` for Claude Desktop. Default false. */
|
|
250
287
|
mcpd?: boolean;
|
|
251
288
|
/** When `true`, `mcp bundle` also writes `dist/claude-plugin/<name>.zip`. Default false. */
|
|
@@ -266,26 +303,70 @@ export interface CliMcpServerConfig {
|
|
|
266
303
|
/** Optional MCP Bundle (`.mcpb`) metadata for `mcp bundle`. */
|
|
267
304
|
bundle?: CliMcpBundleConfig;
|
|
268
305
|
}
|
|
306
|
+
/** JSON Schema for structured error responses (OpenAPI + HTTP/MCP error bodies). */
|
|
307
|
+
export type CliJsonSchema = Record<string, unknown>;
|
|
308
|
+
/** Wire-level HTTP hooks (observe-only; all requests including health and 404s). */
|
|
309
|
+
export interface CliHttpWireHooks {
|
|
310
|
+
onRequest?: (ctx: CliHttpWireContext) => void | Promise<void>;
|
|
311
|
+
onResponse?: (ctx: CliHttpWireContext & {
|
|
312
|
+
status: number;
|
|
313
|
+
durationMs: number;
|
|
314
|
+
}) => void | Promise<void>;
|
|
315
|
+
onError?: (ctx: CliHttpWireContext & {
|
|
316
|
+
failureKind: InvokeFailureKind;
|
|
317
|
+
error: unknown;
|
|
318
|
+
}) => void | Promise<void>;
|
|
319
|
+
}
|
|
320
|
+
/** Per-request HTTP wire context for {@link CliHttpWireHooks}. */
|
|
321
|
+
export interface CliHttpWireContext {
|
|
322
|
+
request: Request;
|
|
323
|
+
requestId: string;
|
|
324
|
+
clientIp: string;
|
|
325
|
+
path: string;
|
|
326
|
+
method: string;
|
|
327
|
+
}
|
|
328
|
+
/** Wire-level MCP hooks on JSON-RPC messages (observe-only). */
|
|
329
|
+
export interface CliMcpWireHooks {
|
|
330
|
+
onRequest?: (ctx: CliMcpWireContext) => void | Promise<void>;
|
|
331
|
+
onResponse?: (ctx: CliMcpWireContext & {
|
|
332
|
+
durationMs: number;
|
|
333
|
+
}) => void | Promise<void>;
|
|
334
|
+
onError?: (ctx: CliMcpWireContext & {
|
|
335
|
+
failureKind: InvokeFailureKind;
|
|
336
|
+
error: unknown;
|
|
337
|
+
}) => void | Promise<void>;
|
|
338
|
+
}
|
|
339
|
+
/** Per-message MCP wire context for {@link CliMcpWireHooks}. */
|
|
340
|
+
export interface CliMcpWireContext {
|
|
341
|
+
rpcMethod: string;
|
|
342
|
+
requestId: string;
|
|
343
|
+
toolName?: string;
|
|
344
|
+
}
|
|
269
345
|
/**
|
|
270
|
-
* Enables `myapp
|
|
271
|
-
* Must include `enabled: true`; omit `
|
|
346
|
+
* Enables `myapp http` and the HTTP tool server (program root only).
|
|
347
|
+
* Must include `enabled: true`; omit `httpServer` entirely to disable HTTP.
|
|
272
348
|
*/
|
|
273
|
-
export interface
|
|
274
|
-
/** When `true`, enables the `
|
|
349
|
+
export interface CliHttpServerConfig {
|
|
350
|
+
/** When `true`, enables the `http` built-in and HTTP tool server. */
|
|
275
351
|
enabled: boolean;
|
|
276
352
|
/** Listen host (default: `127.0.0.1`). */
|
|
277
353
|
host?: string;
|
|
278
354
|
/** Listen port (default: `3000`). */
|
|
279
355
|
port?: number;
|
|
356
|
+
/** Honor `X-Forwarded-For` for client IP in hooks and logs. */
|
|
357
|
+
trustProxy?: boolean;
|
|
358
|
+
/** HTTP error response defaults. */
|
|
359
|
+
errors?: {
|
|
360
|
+
errorSchema?: CliJsonSchema;
|
|
361
|
+
obscureUnexpected?: boolean;
|
|
362
|
+
};
|
|
363
|
+
/** Observe-only hooks for all HTTP requests. */
|
|
364
|
+
hooks?: CliHttpWireHooks;
|
|
280
365
|
}
|
|
281
|
-
/**
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
/** Default success Content-Type (default: `application/json`). */
|
|
286
|
-
contentType?: string;
|
|
287
|
-
/** Optional Content-Disposition (e.g. `attachment; filename="invoice.pdf"`). */
|
|
288
|
-
contentDisposition?: string;
|
|
366
|
+
/** MCP server error defaults. */
|
|
367
|
+
export interface CliMcpServerErrorsConfig {
|
|
368
|
+
errorSchema?: CliJsonSchema;
|
|
369
|
+
obscureUnexpected?: boolean;
|
|
289
370
|
}
|
|
290
371
|
/** Body types accepted by {@link CliContext.respond}. */
|
|
291
372
|
export type CliRespondBody = string | Uint8Array | Record<string, unknown> | unknown[];
|
|
@@ -319,15 +400,13 @@ export interface CliMcpResource {
|
|
|
319
400
|
export interface CliMcpToolConfig {
|
|
320
401
|
/** When `false`, omit from `tools/list` (default: exposed). */
|
|
321
402
|
enabled?: boolean;
|
|
403
|
+
/** Callable; omit from `tools/list` and MCP tool schemas. */
|
|
404
|
+
hidden?: boolean;
|
|
322
405
|
/**
|
|
323
406
|
* Override the generated MCP tool description.
|
|
324
407
|
* Default: auto-generated from command path and description.
|
|
325
408
|
*/
|
|
326
409
|
description?: string;
|
|
327
|
-
/**
|
|
328
|
-
* @deprecated Set `outputSchema` on the leaf command instead.
|
|
329
|
-
*/
|
|
330
|
-
outputSchema?: Record<string, unknown>;
|
|
331
410
|
}
|
|
332
411
|
/** Context passed to {@link CliAppConfigEntry.resolve} for one config key. */
|
|
333
412
|
export interface CliAppConfigResolveContext {
|
|
@@ -392,6 +471,7 @@ export interface CliCompletionConfig {
|
|
|
392
471
|
/** When `false`, hide/disable `completion` (default: enabled). */
|
|
393
472
|
enabled?: boolean;
|
|
394
473
|
}
|
|
474
|
+
/** @experimental */
|
|
395
475
|
export interface CliConfigureConfig {
|
|
396
476
|
/** When `false`, hide/disable `configure` (default: enabled). */
|
|
397
477
|
enabled?: boolean;
|
|
@@ -459,21 +539,16 @@ export interface CliDocsTopic {
|
|
|
459
539
|
description?: string;
|
|
460
540
|
}
|
|
461
541
|
/**
|
|
462
|
-
*
|
|
463
|
-
*
|
|
542
|
+
* Opt-out and optional topics for the `docs` built-in (program root only).
|
|
543
|
+
* Docs is enabled by default; set `enabled: false` to disable.
|
|
464
544
|
*/
|
|
465
545
|
export interface CliDocsConfig {
|
|
466
|
-
/** When `
|
|
467
|
-
enabled
|
|
546
|
+
/** When `false`, hide/disable `docs` (default: enabled). */
|
|
547
|
+
enabled?: boolean;
|
|
468
548
|
/** Router description for `myapp docs` (default: "Print bundled CLI documentation."). */
|
|
469
549
|
description?: string;
|
|
470
|
-
/**
|
|
471
|
-
|
|
472
|
-
* When omitted, uses the first key in `topics` (insertion order).
|
|
473
|
-
*/
|
|
474
|
-
defaultTopic?: string;
|
|
475
|
-
/** Topic key → bundled markdown. Reserved keys: `mcp`, `all` (supplied by the built-in). */
|
|
476
|
-
topics: Record<string, CliDocsTopic>;
|
|
550
|
+
/** Optional consumer markdown topics. Reserved keys: `mcp`, `all` (supplied by the built-in). */
|
|
551
|
+
topics?: Record<string, CliDocsTopic>;
|
|
477
552
|
}
|
|
478
553
|
/**
|
|
479
554
|
* Base properties shared by all nodes in the user command tree.
|
|
@@ -481,8 +556,10 @@ export interface CliDocsConfig {
|
|
|
481
556
|
export interface CliNodeBase {
|
|
482
557
|
/** Program or command key (e.g., "myapp", "stat", "owner"). */
|
|
483
558
|
key: string;
|
|
484
|
-
/**
|
|
485
|
-
|
|
559
|
+
/** Per-surface CLI exposure. */
|
|
560
|
+
cli?: CliCliExposureConfig;
|
|
561
|
+
/** Per-surface HTTP exposure and response defaults. */
|
|
562
|
+
http?: CliHttpExposureConfig;
|
|
486
563
|
/** Short description shown in help. */
|
|
487
564
|
description: string;
|
|
488
565
|
/** Additional notes shown in help (`{argsbarg:program}` → program key). */
|
|
@@ -507,13 +584,11 @@ export type CliLeaf = CliNodeBase & {
|
|
|
507
584
|
positionals?: CliPositional[];
|
|
508
585
|
/**
|
|
509
586
|
* JSON Schema for structured stdout (e.g. with `--json` or MCP when the handler emits JSON).
|
|
510
|
-
* Exported in `docs cli-schema`, `docs
|
|
587
|
+
* Exported in `docs cli-schema`, `docs cli`, and MCP `tools/list`; not validated at runtime yet.
|
|
511
588
|
*/
|
|
512
589
|
outputSchema?: Record<string, unknown>;
|
|
513
590
|
/** JSON Schema for MCP/HTTP tool arguments (flat object). */
|
|
514
591
|
inputSchema?: Record<string, unknown>;
|
|
515
|
-
/** Declarative HTTP response metadata (Content-Type, Content-Disposition). */
|
|
516
|
-
apiResponse?: CliApiResponseConfig;
|
|
517
592
|
/** Per-tool MCP exposure and metadata. */
|
|
518
593
|
mcpTool?: CliMcpToolConfig;
|
|
519
594
|
};
|
|
@@ -532,6 +607,122 @@ export type CliRouter = CliNodeBase & {
|
|
|
532
607
|
* A node in the user-defined command tree (router or leaf).
|
|
533
608
|
*/
|
|
534
609
|
export type CliNode = CliLeaf | CliRouter;
|
|
610
|
+
/** Classified failure kind for invoke error pipeline and HTTP/MCP status mapping. */
|
|
611
|
+
export type InvokeFailureKind = "validation" | "help" | "unexpected" | "not_ready" | "missing_config" | "unknown_route";
|
|
612
|
+
/**
|
|
613
|
+
* Per-invocation context attached in hooks (e.g. DB handles, auth principals).
|
|
614
|
+
* Augment in app code: `declare module "argsbarg" { interface CliLocals { db: AppDb } }`.
|
|
615
|
+
*/
|
|
616
|
+
export interface CliLocals {
|
|
617
|
+
/** Correlation id seeded before hooks run (HTTP/MCP wire id or generated UUID). */
|
|
618
|
+
requestId?: string;
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Cross-request server state (HTTP/MCP runtime bag).
|
|
622
|
+
* Augment in app code: `declare module "argsbarg" { interface ServerState { db: AppDb } }`.
|
|
623
|
+
*/
|
|
624
|
+
export interface ServerState {
|
|
625
|
+
/** Set when app config soft-validation fails at server start. */
|
|
626
|
+
configFileError?: string;
|
|
627
|
+
/** Short-TTL cache for readiness probe results. */
|
|
628
|
+
readinessCache?: {
|
|
629
|
+
at: number;
|
|
630
|
+
result: {
|
|
631
|
+
ok: boolean;
|
|
632
|
+
checks: Record<string, {
|
|
633
|
+
ok: boolean;
|
|
634
|
+
error?: string;
|
|
635
|
+
missing?: string[];
|
|
636
|
+
}>;
|
|
637
|
+
};
|
|
638
|
+
};
|
|
639
|
+
/** Last readiness probe result. */
|
|
640
|
+
readiness?: {
|
|
641
|
+
ok: boolean;
|
|
642
|
+
checks: Record<string, {
|
|
643
|
+
ok: boolean;
|
|
644
|
+
error?: string;
|
|
645
|
+
missing?: string[];
|
|
646
|
+
}>;
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
/** Cross-request mutable state created at HTTP/MCP server start. */
|
|
650
|
+
export interface ServerRuntime {
|
|
651
|
+
/** Mutable global bag (DB pool, degraded flags, readiness cache, etc.). */
|
|
652
|
+
state: ServerState;
|
|
653
|
+
program: CliProgram;
|
|
654
|
+
surface: "http" | "mcp";
|
|
655
|
+
}
|
|
656
|
+
/** Context for program-level invoke hooks (CLI, HTTP, MCP user commands). */
|
|
657
|
+
export interface InvokeHookContext {
|
|
658
|
+
invocation: CliInvocation;
|
|
659
|
+
path: string[];
|
|
660
|
+
pathParams: Record<string, string>;
|
|
661
|
+
opts: Record<string, string>;
|
|
662
|
+
/** Per-invocation bag; `beforeInvoke` may write. Framework seeds `requestId` before hooks run. */
|
|
663
|
+
locals: CliLocals;
|
|
664
|
+
runtime?: ServerRuntime;
|
|
665
|
+
appConfig: AnyAppConfigSnapshot;
|
|
666
|
+
http?: {
|
|
667
|
+
request: Request;
|
|
668
|
+
clientIp: string;
|
|
669
|
+
requestId: string;
|
|
670
|
+
};
|
|
671
|
+
mcp?: {
|
|
672
|
+
rpcMethod: string;
|
|
673
|
+
toolName?: string;
|
|
674
|
+
requestId: string;
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
/** Error hook context after failure classification. */
|
|
678
|
+
export interface ErrorHookContext extends InvokeHookContext {
|
|
679
|
+
failureKind: InvokeFailureKind;
|
|
680
|
+
error: unknown;
|
|
681
|
+
/** Default client-facing error before `formatError` override. */
|
|
682
|
+
clientError: ClientErrorOverride;
|
|
683
|
+
}
|
|
684
|
+
/** Client-facing error payload; `formatError` may return a partial override. */
|
|
685
|
+
export interface ClientErrorOverride {
|
|
686
|
+
message: string;
|
|
687
|
+
exitCode?: number;
|
|
688
|
+
}
|
|
689
|
+
/** Minimal invoke result passed to `afterInvoke` (see {@link Cli.invoke}). */
|
|
690
|
+
export interface CliInvokeHookResult {
|
|
691
|
+
kind: "ok" | "help" | "error";
|
|
692
|
+
exitCode: number;
|
|
693
|
+
failureKind?: InvokeFailureKind;
|
|
694
|
+
errorMsg?: string;
|
|
695
|
+
}
|
|
696
|
+
/** Program-level invoke and error hooks (skipped for builtins). */
|
|
697
|
+
export interface CliProgramHooks {
|
|
698
|
+
/** May mutate `locals`, `opts`, `args`; may throw. Skipped for builtins. */
|
|
699
|
+
beforeInvoke?: (ctx: InvokeHookContext) => void | Promise<void>;
|
|
700
|
+
afterInvoke?: (ctx: InvokeHookContext & {
|
|
701
|
+
result: CliInvokeHookResult;
|
|
702
|
+
}) => void | Promise<void>;
|
|
703
|
+
/** Mutate client-facing error payload only. Runs before `onError`. */
|
|
704
|
+
formatError?: (ctx: ErrorHookContext) => ClientErrorOverride | undefined | Promise<ClientErrorOverride | undefined>;
|
|
705
|
+
/** Observe only — runs after `formatError`; may enrich `locals`. Never mutates client response. */
|
|
706
|
+
onError?: (ctx: ErrorHookContext) => void | Promise<void>;
|
|
707
|
+
}
|
|
708
|
+
/** Context for optional `program.readiness` (HTTP/MCP health only). */
|
|
709
|
+
export interface ReadinessContext {
|
|
710
|
+
program: CliProgram;
|
|
711
|
+
surface: "http" | "mcp";
|
|
712
|
+
appConfig: AnyAppConfigSnapshot;
|
|
713
|
+
runtime: ServerRuntime;
|
|
714
|
+
}
|
|
715
|
+
/** Framework logging defaults (ECS json or human text on stderr). */
|
|
716
|
+
export interface CliLogConfig {
|
|
717
|
+
/** `json` = ECS lines; `text` = human stderr lines. Default: `json`. */
|
|
718
|
+
format?: "json" | "text";
|
|
719
|
+
/** Tee stderr + append; relative paths resolve under the app config dir. */
|
|
720
|
+
file?: string;
|
|
721
|
+
/** Emit HTTP/MCP access logs. Default: true. */
|
|
722
|
+
access?: boolean;
|
|
723
|
+
/** Emit error events after the hook pipeline. Default: true. */
|
|
724
|
+
errors?: boolean;
|
|
725
|
+
}
|
|
535
726
|
/**
|
|
536
727
|
* Program root passed to {@link Cli}.
|
|
537
728
|
* May be a leaf or router, plus optional program-level MCP and install config.
|
|
@@ -543,14 +734,20 @@ export type CliProgram = CliNode & {
|
|
|
543
734
|
appConfig?: CliAppConfig;
|
|
544
735
|
/** When set with `enabled: true`, enables the `mcp` built-in subcommand. */
|
|
545
736
|
mcpServer?: CliMcpServerConfig;
|
|
546
|
-
/** When set with `enabled: true`, enables the `
|
|
547
|
-
|
|
737
|
+
/** When set with `enabled: true`, enables the `http` built-in HTTP server. */
|
|
738
|
+
httpServer?: CliHttpServerConfig;
|
|
548
739
|
/** Opt-out and defaults for `configure`. */
|
|
549
740
|
configure?: CliConfigureConfig;
|
|
550
741
|
/** Opt-out for shell completion generation (`completion bash|zsh|fish`). */
|
|
551
742
|
completion?: CliCompletionConfig;
|
|
552
|
-
/**
|
|
743
|
+
/** Opt-out and optional topics for the `docs` built-in (default: enabled). */
|
|
553
744
|
docs?: CliDocsConfig;
|
|
745
|
+
/** Invoke and error hooks for user commands on CLI, HTTP, and MCP. */
|
|
746
|
+
hooks?: CliProgramHooks;
|
|
747
|
+
/** Optional readiness probe for HTTP/MCP `GET /health/ready` only. */
|
|
748
|
+
readiness?: (ctx: ReadinessContext) => boolean | Promise<boolean>;
|
|
749
|
+
/** Framework logging (stderr + optional file). */
|
|
750
|
+
log?: CliLogConfig;
|
|
554
751
|
};
|
|
555
752
|
/** True when the leaf accepts a pure JSON body (no CLI flags). */
|
|
556
753
|
export declare function isJsonLeaf(leaf: CliLeaf): boolean;
|
|
@@ -566,68 +763,10 @@ export declare class CliSchemaValidationError extends Error {
|
|
|
566
763
|
/** Creates a schema validation error with a human-readable rule violation. */
|
|
567
764
|
constructor(message: string);
|
|
568
765
|
}
|
|
569
|
-
/**
|
|
570
|
-
export declare function
|
|
571
|
-
/**
|
|
572
|
-
export declare function
|
|
573
|
-
/** Platform builtins derived from program config and runtime. */
|
|
574
|
-
export interface CliCapabilities {
|
|
575
|
-
api: boolean;
|
|
576
|
-
completion: boolean;
|
|
577
|
-
mcp: boolean;
|
|
578
|
-
configure: boolean;
|
|
579
|
-
docs: boolean;
|
|
580
|
-
configCommands: boolean;
|
|
581
|
-
}
|
|
582
|
-
/** JSON-safe command node (no handlers). */
|
|
583
|
-
export interface CliSchemaExport {
|
|
584
|
-
key: string;
|
|
585
|
-
description: string;
|
|
586
|
-
notes?: string;
|
|
587
|
-
/** JSON Schema for structured stdout when set on the leaf. */
|
|
588
|
-
outputSchema?: Record<string, unknown>;
|
|
589
|
-
options?: CliOption[];
|
|
590
|
-
fallbackCommand?: string;
|
|
591
|
-
fallbackMode?: CliFallbackMode;
|
|
592
|
-
commands?: CliSchemaExport[];
|
|
593
|
-
positionals?: CliPositional[];
|
|
594
|
-
}
|
|
595
|
-
/** Outcome of a non-exiting CLI invocation. */
|
|
596
|
-
export type CliInvokeKind = "ok" | "help" | "error";
|
|
597
|
-
/** Result of Cli.invoke: captured output and exit metadata without process.exit. */
|
|
598
|
-
export interface CliInvokeResult {
|
|
599
|
-
kind: CliInvokeKind;
|
|
600
|
-
exitCode: number;
|
|
601
|
-
stdout: string;
|
|
602
|
-
stderr: string;
|
|
603
|
-
errorMsg?: string;
|
|
604
|
-
/** Headless response payload when invocation is `api` or `mcp` and the handler succeeded. */
|
|
605
|
-
response?: CliRespondOptions;
|
|
606
|
-
}
|
|
607
|
-
/** Argsbarg runtime for a validated, frozen {@link CliProgram}. */
|
|
608
|
-
export declare class Cli {
|
|
609
|
-
readonly program: CliProgram;
|
|
610
|
-
readonly caps: CliCapabilities;
|
|
611
|
-
private readonly parseRootMerged;
|
|
612
|
-
private readonly presentationRoot;
|
|
613
|
-
private _appConfig?;
|
|
614
|
-
constructor(program: CliProgram);
|
|
615
|
-
get appConfig(): AnyAppConfigSnapshot;
|
|
616
|
-
exportCommandSchema(): CliSchemaExport;
|
|
617
|
-
exportAppConfigSchema(): Record<string, unknown> | undefined;
|
|
618
|
-
run(argv?: string[]): Promise<never>;
|
|
619
|
-
invoke(argv: string[], opts?: {
|
|
620
|
-
invocation?: CliInvocation;
|
|
621
|
-
toolArgs?: Record<string, unknown>;
|
|
622
|
-
}): Promise<CliInvokeResult>;
|
|
623
|
-
serveMcp(): Promise<never>;
|
|
624
|
-
serveApi(): Promise<never>;
|
|
625
|
-
private ensureValidatedLeafInputs;
|
|
626
|
-
private exitLeafInputError;
|
|
627
|
-
private prepareDispatch;
|
|
628
|
-
private buildAppConfigSnapshot;
|
|
629
|
-
}
|
|
630
|
-
export declare function cliErrWithHelp(ctx: CliContext, msg: string): never;
|
|
766
|
+
/** Resolved absolute path to the app JSON config file (`~/.local/lib/<key>/config.json`). */
|
|
767
|
+
export declare function resolveAppConfigPath(program: CliProgram): string;
|
|
768
|
+
/** Human-readable config path for error messages (`~/…` when under home). */
|
|
769
|
+
export declare function displayAppConfigPath(program: CliProgram): string;
|
|
631
770
|
/** Parses a duration string (e.g. 20m, 1h, 30s) into milliseconds. */
|
|
632
771
|
export declare function parseDurationMs(durationStr: string): number;
|
|
633
772
|
/** Splits a comma-separated string into trimmed non-empty tokens. */
|
|
@@ -636,6 +775,17 @@ export declare function parseCommaList(s: string): string[];
|
|
|
636
775
|
export declare function parseDate(s: string): string;
|
|
637
776
|
/** Returns normalized ISO 8601 UTC after validation. */
|
|
638
777
|
export declare function parseDateTime(s: string): string;
|
|
778
|
+
/** Thrown when leaf input resolution or validation fails. */
|
|
779
|
+
export declare class LeafInputError extends Error {
|
|
780
|
+
constructor(message: string);
|
|
781
|
+
}
|
|
782
|
+
/** Resolves a Json option from argv, preloaded stdin, or toolArgs (flag wins). */
|
|
783
|
+
export declare function readJsonOptionValue(ctx: CliContext, name: string): unknown | undefined;
|
|
784
|
+
/**
|
|
785
|
+
* Reads piped stdin for a pipable Json option when the flag is omitted (CLI only).
|
|
786
|
+
* Call from {@link Cli.run} before constructing the handler context.
|
|
787
|
+
*/
|
|
788
|
+
export declare function preloadPipableJson(program: CliProgram, commandPath: string[], opts: Record<string, string>, invocation: CliInvocation, args?: string[]): Promise<Record<string, unknown>>;
|
|
639
789
|
/** Minimal context for headless routing helpers. */
|
|
640
790
|
export type HeadlessContext = Pick<CliContext, "invocation">;
|
|
641
791
|
/** True when `--json` was passed or the handler was invoked headlessly over MCP/HTTP. */
|
|
@@ -671,26 +821,10 @@ dryRun?: boolean,
|
|
|
671
821
|
interactive?: boolean): void;
|
|
672
822
|
/** Prefixes a success message when running in dry-run mode. */
|
|
673
823
|
export declare function formatDryRunMessage(message: string, dryRun: boolean): string;
|
|
674
|
-
/**
|
|
675
|
-
export declare
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
/** Resolves a Json option from argv, preloaded stdin, or toolArgs (flag wins). */
|
|
679
|
-
export declare function readJsonOptionValue(ctx: CliContext, name: string): unknown | undefined;
|
|
680
|
-
/**
|
|
681
|
-
* Reads piped stdin for a pipable Json option when the flag is omitted (CLI only).
|
|
682
|
-
* Call from {@link Cli.run} before constructing the handler context.
|
|
683
|
-
*/
|
|
684
|
-
export declare function preloadPipableJson(program: CliProgram, commandPath: string[], opts: Record<string, string>, invocation: CliInvocation, args?: string[]): Promise<Record<string, unknown>>;
|
|
685
|
-
/**
|
|
686
|
-
* Loads coerced leaf inputs and validates against `leaf.inputSchema` when set.
|
|
687
|
-
* Used by {@link CliContext.inputs}; prefer `ctx.inputs` or `ctx.inputsAs()` in handlers.
|
|
688
|
-
*/
|
|
689
|
-
export declare function loadLeafInputs(ctx: CliContext): CliLeafInputs;
|
|
690
|
-
/** @deprecated Use {@link CliContext.inputs} or {@link loadLeafInputs} via `ctx.inputs`. */
|
|
691
|
-
export declare function readLeafInputs(ctx: CliContext): CliLeafInputs;
|
|
692
|
-
/** @deprecated Use sync {@link readLeafInputs} — stdin is preloaded before the handler runs. */
|
|
693
|
-
export declare function readLeafInputsAsync(ctx: CliContext): Promise<CliLeafInputs>;
|
|
824
|
+
/** Generates an OpenAPI 3.1 document for the program's HTTP routes. */
|
|
825
|
+
export declare function generateOpenApi(program: CliProgram): Record<string, unknown>;
|
|
826
|
+
/** Pretty-printed OpenAPI JSON (same document as `GET /openapi.json`). */
|
|
827
|
+
export declare function openApiJson(program: CliProgram): string;
|
|
694
828
|
/** Resolved paths for `mcp bundle`. */
|
|
695
829
|
export interface McpBundlePaths {
|
|
696
830
|
binaryPath: string;
|
|
@@ -711,6 +845,167 @@ export interface PackMcpBundleOpts {
|
|
|
711
845
|
* Requires the compiled binary to exist.
|
|
712
846
|
*/
|
|
713
847
|
export declare function packMcpBundle(program: CliProgram, opts?: PackMcpBundleOpts): string;
|
|
848
|
+
/** JSON-safe command node (no handlers). */
|
|
849
|
+
export interface CliSchemaExport {
|
|
850
|
+
key: string;
|
|
851
|
+
description: string;
|
|
852
|
+
notes?: string;
|
|
853
|
+
/** JSON Schema for structured stdout when set on the leaf. */
|
|
854
|
+
outputSchema?: Record<string, unknown>;
|
|
855
|
+
/** Default success Content-Type when `outputSchema` is omitted but `http.successContentType` is set. */
|
|
856
|
+
outputContentType?: string;
|
|
857
|
+
options?: CliOption[];
|
|
858
|
+
fallbackCommand?: string;
|
|
859
|
+
fallbackMode?: CliFallbackMode;
|
|
860
|
+
commands?: CliSchemaExport[];
|
|
861
|
+
positionals?: CliPositional[];
|
|
862
|
+
}
|
|
863
|
+
/** JSON-safe command tree export (handlers omitted). */
|
|
864
|
+
export interface CliSchemaRootExport extends CliSchemaExport {
|
|
865
|
+
/** Program-level error JSON Schema when configured on `httpServer.errors` or `mcpServer.errors`. */
|
|
866
|
+
errorSchema?: Record<string, unknown>;
|
|
867
|
+
}
|
|
868
|
+
/** Severity label for ECS `log.level`. */
|
|
869
|
+
export type EcsLogLevel = "debug" | "info" | "warn" | "error";
|
|
870
|
+
/** Input for one ECS log event. */
|
|
871
|
+
export interface EcsLogEvent {
|
|
872
|
+
level: EcsLogLevel;
|
|
873
|
+
message: string;
|
|
874
|
+
action?: string;
|
|
875
|
+
labels?: Record<string, string | number | boolean>;
|
|
876
|
+
error?: unknown;
|
|
877
|
+
fields?: Record<string, unknown>;
|
|
878
|
+
}
|
|
879
|
+
/** Resolved logging options for a server or invoke session. */
|
|
880
|
+
export interface ResolvedLogConfig {
|
|
881
|
+
format: "json" | "text";
|
|
882
|
+
file?: string;
|
|
883
|
+
access: boolean;
|
|
884
|
+
errors: boolean;
|
|
885
|
+
dev: boolean;
|
|
886
|
+
}
|
|
887
|
+
/** Options for {@link LogEmitter}. */
|
|
888
|
+
export interface LogEmitterOpts {
|
|
889
|
+
program: CliProgram;
|
|
890
|
+
resolved: ResolvedLogConfig;
|
|
891
|
+
}
|
|
892
|
+
declare class LogEmitter {
|
|
893
|
+
private readonly service;
|
|
894
|
+
private readonly resolved;
|
|
895
|
+
constructor(opts: LogEmitterOpts);
|
|
896
|
+
get config(): ResolvedLogConfig;
|
|
897
|
+
/** Emits one log event to stderr (and optional file). */
|
|
898
|
+
emit(event: EcsLogEvent): void;
|
|
899
|
+
/** Human startup line or ECS/json event for lifecycle milestones. */
|
|
900
|
+
emitLifecycle(message: string, action: string, labels?: Record<string, string | number | boolean>): void;
|
|
901
|
+
/** Access log for one HTTP request or MCP RPC. */
|
|
902
|
+
emitAccess(fields: {
|
|
903
|
+
method: string;
|
|
904
|
+
path: string;
|
|
905
|
+
status: number;
|
|
906
|
+
durationMs: number;
|
|
907
|
+
requestId?: string;
|
|
908
|
+
clientIp?: string;
|
|
909
|
+
}): void;
|
|
910
|
+
/** Error log after the hook pipeline (real stack always included). */
|
|
911
|
+
emitInvokeError(failureKind: string, error: unknown, clientMessage: string, labels?: Record<string, string | number | boolean>): void;
|
|
912
|
+
private formatLine;
|
|
913
|
+
private formatTextLine;
|
|
914
|
+
private appendFile;
|
|
915
|
+
}
|
|
916
|
+
/** Overrides from `myapp http` / `serveHttp()` flags and embedders. */
|
|
917
|
+
export interface ServeOverrides {
|
|
918
|
+
host?: string;
|
|
919
|
+
port?: number;
|
|
920
|
+
trustProxy?: boolean;
|
|
921
|
+
obscureErrors?: boolean;
|
|
922
|
+
logFormat?: "json" | "text";
|
|
923
|
+
logFile?: string;
|
|
924
|
+
noAccessLog?: boolean;
|
|
925
|
+
dev?: boolean;
|
|
926
|
+
}
|
|
927
|
+
/** Resolved HTTP listen and error options after merging schema + overrides. */
|
|
928
|
+
export interface ResolvedHttpServeConfig {
|
|
929
|
+
hostname: string;
|
|
930
|
+
port: number;
|
|
931
|
+
trustProxy: boolean;
|
|
932
|
+
obscureUnexpected: boolean;
|
|
933
|
+
log: ResolvedLogConfig;
|
|
934
|
+
}
|
|
935
|
+
/** Resolved MCP serve options after merging schema + overrides. */
|
|
936
|
+
export interface ResolvedMcpServeConfig {
|
|
937
|
+
obscureUnexpected: boolean;
|
|
938
|
+
log: ResolvedLogConfig;
|
|
939
|
+
}
|
|
940
|
+
/** Shared server state for one HTTP or MCP serve session. */
|
|
941
|
+
export interface ServerHandleContext {
|
|
942
|
+
runtime: ServerRuntime;
|
|
943
|
+
emitter: LogEmitter;
|
|
944
|
+
http?: ResolvedHttpServeConfig;
|
|
945
|
+
mcp?: ResolvedMcpServeConfig;
|
|
946
|
+
httpHooks?: CliHttpWireHooks;
|
|
947
|
+
mcpHooks?: CliMcpWireHooks;
|
|
948
|
+
}
|
|
949
|
+
/** Platform builtins derived from program config and runtime. */
|
|
950
|
+
export interface CliCapabilities {
|
|
951
|
+
http: boolean;
|
|
952
|
+
completion: boolean;
|
|
953
|
+
mcp: boolean;
|
|
954
|
+
configure: boolean;
|
|
955
|
+
docs: boolean;
|
|
956
|
+
configCommands: boolean;
|
|
957
|
+
}
|
|
958
|
+
/** Outcome of a non-exiting CLI invocation. */
|
|
959
|
+
export type CliInvokeKind = "ok" | "help" | "error";
|
|
960
|
+
/** Result of Cli.invoke: captured output and exit metadata without process.exit. */
|
|
961
|
+
export interface CliInvokeResult {
|
|
962
|
+
kind: CliInvokeKind;
|
|
963
|
+
exitCode: number;
|
|
964
|
+
stdout: string;
|
|
965
|
+
stderr: string;
|
|
966
|
+
errorMsg?: string;
|
|
967
|
+
/** Classified failure for HTTP/MCP status mapping. */
|
|
968
|
+
failureKind?: InvokeFailureKind;
|
|
969
|
+
/** Headless response payload when invocation is `api` or `mcp` and the handler succeeded. */
|
|
970
|
+
response?: CliRespondOptions;
|
|
971
|
+
}
|
|
972
|
+
/** Argsbarg runtime for a validated, frozen {@link CliProgram}. */
|
|
973
|
+
export declare class Cli {
|
|
974
|
+
readonly program: CliProgram;
|
|
975
|
+
readonly caps: CliCapabilities;
|
|
976
|
+
private readonly parseRootMerged;
|
|
977
|
+
private readonly presentationRoot;
|
|
978
|
+
private _appConfig?;
|
|
979
|
+
/** Active HTTP/MCP server handle (set during serve). */
|
|
980
|
+
server?: ServerHandleContext;
|
|
981
|
+
constructor(program: CliProgram);
|
|
982
|
+
get appConfig(): AnyAppConfigSnapshot;
|
|
983
|
+
exportCommandSchema(): CliSchemaRootExport;
|
|
984
|
+
exportAppConfigSchema(): Record<string, unknown> | undefined;
|
|
985
|
+
run(argv?: string[]): Promise<never>;
|
|
986
|
+
invoke(argv: string[], opts?: {
|
|
987
|
+
invocation?: CliInvocation;
|
|
988
|
+
toolArgs?: Record<string, unknown>;
|
|
989
|
+
requestId?: string;
|
|
990
|
+
http?: {
|
|
991
|
+
request: Request;
|
|
992
|
+
clientIp: string;
|
|
993
|
+
requestId: string;
|
|
994
|
+
};
|
|
995
|
+
mcp?: {
|
|
996
|
+
rpcMethod: string;
|
|
997
|
+
toolName?: string;
|
|
998
|
+
requestId: string;
|
|
999
|
+
};
|
|
1000
|
+
}): Promise<CliInvokeResult>;
|
|
1001
|
+
serveMcp(overrides?: ServeOverrides): Promise<never>;
|
|
1002
|
+
serveHttp(overrides?: ServeOverrides): Promise<never>;
|
|
1003
|
+
private ensureValidatedLeafInputs;
|
|
1004
|
+
private exitLeafInputError;
|
|
1005
|
+
private prepareDispatch;
|
|
1006
|
+
private buildAppConfigSnapshot;
|
|
1007
|
+
}
|
|
1008
|
+
export declare function cliErrWithHelp(ctx: CliContext, msg: string): never;
|
|
714
1009
|
/** True when stdin is a TTY. */
|
|
715
1010
|
export declare const isInteractiveTty: boolean;
|
|
716
1011
|
|