argsbarg 5.1.15 → 6.0.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 +37 -1
- package/README.md +32 -24
- package/docs/README.md +2 -1
- package/docs/api-server.md +141 -0
- package/docs/bundled-docs.md +24 -10
- package/docs/cli-program.md +17 -2
- package/docs/configure.md +2 -2
- package/docs/developing.md +1 -1
- package/docs/mcp.md +5 -5
- package/docs/output-schema.md +3 -3
- package/examples/full-example/README.md +8 -0
- package/examples/full-example/docs/README.md +27 -0
- package/examples/full-example/docs/api.md +511 -0
- package/examples/full-example/docs/cli-schema.json +453 -0
- package/examples/full-example/docs/http.md +81 -0
- package/examples/full-example/docs/mcp.md +159 -0
- package/examples/full-example/docs/openapi.json +222 -0
- package/examples/full-example/docs/skill.md +46 -0
- package/examples/full-example/justfile +6 -2
- package/examples/full-example/scripts/dev-formula.ts +1 -1
- package/examples/full-example/src/commands/echo/command.ts +6 -1
- package/examples/full-example/src/program.ts +3 -0
- package/examples/mcp-test.ts +13 -2
- package/examples/nested.ts +12 -3
- package/examples/servers.ts +72 -0
- package/index.d.ts +66 -7
- package/package.json +1 -1
- package/src/api/openapi.ts +115 -0
- package/src/api/result.ts +89 -0
- package/src/api/server.ts +120 -0
- package/src/api.integration.test.ts +358 -0
- package/src/builtins/api.ts +38 -0
- package/src/builtins/dispatch.ts +26 -0
- package/src/builtins/registry.ts +4 -0
- package/src/capabilities.ts +12 -1
- package/src/cli-tool/full-example-capabilities.test.ts +3 -0
- package/src/cli.ts +60 -8
- package/src/config/bootstrap.test.ts +46 -0
- package/src/config/bootstrap.ts +22 -5
- package/src/config.integration.test.ts +22 -4
- package/src/configure/index.ts +1 -1
- package/src/context.ts +29 -1
- package/src/docs/api-guide.ts +2 -2
- package/src/docs/builtin.ts +11 -1
- package/src/docs/docs.test.ts +70 -12
- package/src/docs/http-guide.ts +132 -0
- package/src/docs/mcp-guide.ts +3 -3
- package/src/docs/resolve.ts +26 -2
- package/src/docs/save.ts +5 -2
- package/src/headless/tool-call.ts +147 -0
- package/src/headless.test.ts +4 -2
- package/src/headless.ts +10 -5
- package/src/index.ts +5 -0
- package/src/mcp/result.ts +39 -34
- package/src/mcp/server.ts +18 -36
- package/src/mcp/tools.ts +14 -3
- package/src/mcp.integration.test.ts +46 -39
- package/src/parse.test.ts +16 -6
- package/src/respond.ts +48 -0
- package/src/schema.ts +1 -1
- package/src/skill/generate.ts +1 -1
- package/src/types.ts +46 -4
- package/src/validate.ts +7 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
{
|
|
2
|
+
"openapi": "3.1.0",
|
|
3
|
+
"info": {
|
|
4
|
+
"title": "full-example",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"description": "Argsbarg full example reference app"
|
|
7
|
+
},
|
|
8
|
+
"paths": {
|
|
9
|
+
"/tools/echo": {
|
|
10
|
+
"post": {
|
|
11
|
+
"operationId": "echo",
|
|
12
|
+
"summary": "echo — Echo a message (MCP-friendly leaf).",
|
|
13
|
+
"requestBody": {
|
|
14
|
+
"required": false,
|
|
15
|
+
"content": {
|
|
16
|
+
"application/json; charset=utf-8": {
|
|
17
|
+
"schema": {
|
|
18
|
+
"type": "object",
|
|
19
|
+
"properties": {
|
|
20
|
+
"message": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "Text to print."
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"additionalProperties": false,
|
|
26
|
+
"required": [
|
|
27
|
+
"message"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"responses": {
|
|
34
|
+
"200": {
|
|
35
|
+
"description": "Successful tool invocation",
|
|
36
|
+
"content": {
|
|
37
|
+
"application/json": {
|
|
38
|
+
"schema": {
|
|
39
|
+
"type": "object"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"400": {
|
|
45
|
+
"description": "Invalid arguments or help requested",
|
|
46
|
+
"content": {
|
|
47
|
+
"application/json; charset=utf-8": {
|
|
48
|
+
"schema": {
|
|
49
|
+
"type": "object",
|
|
50
|
+
"properties": {
|
|
51
|
+
"error": {
|
|
52
|
+
"type": "string"
|
|
53
|
+
},
|
|
54
|
+
"exitCode": {
|
|
55
|
+
"type": "integer"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"required": [
|
|
59
|
+
"error"
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"404": {
|
|
66
|
+
"description": "Unknown tool",
|
|
67
|
+
"content": {
|
|
68
|
+
"application/json; charset=utf-8": {
|
|
69
|
+
"schema": {
|
|
70
|
+
"type": "object",
|
|
71
|
+
"properties": {
|
|
72
|
+
"error": {
|
|
73
|
+
"type": "string"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"required": [
|
|
77
|
+
"error"
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"500": {
|
|
84
|
+
"description": "Handler error",
|
|
85
|
+
"content": {
|
|
86
|
+
"application/json; charset=utf-8": {
|
|
87
|
+
"schema": {
|
|
88
|
+
"type": "object",
|
|
89
|
+
"properties": {
|
|
90
|
+
"error": {
|
|
91
|
+
"type": "string"
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
"required": [
|
|
95
|
+
"error"
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"/tools/status": {
|
|
105
|
+
"post": {
|
|
106
|
+
"operationId": "status",
|
|
107
|
+
"summary": "status — Show resolved config and app version.",
|
|
108
|
+
"requestBody": {
|
|
109
|
+
"required": false,
|
|
110
|
+
"content": {
|
|
111
|
+
"application/json; charset=utf-8": {
|
|
112
|
+
"schema": {
|
|
113
|
+
"type": "object",
|
|
114
|
+
"properties": {
|
|
115
|
+
"json": {
|
|
116
|
+
"type": "boolean",
|
|
117
|
+
"description": "Emit JSON."
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
"additionalProperties": false
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"responses": {
|
|
126
|
+
"200": {
|
|
127
|
+
"description": "Successful tool invocation",
|
|
128
|
+
"content": {
|
|
129
|
+
"application/json": {
|
|
130
|
+
"schema": {
|
|
131
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
132
|
+
"type": "object",
|
|
133
|
+
"properties": {
|
|
134
|
+
"defaultRegion": {
|
|
135
|
+
"type": "string",
|
|
136
|
+
"description": "Resolved AWS region."
|
|
137
|
+
},
|
|
138
|
+
"maxRetries": {
|
|
139
|
+
"type": "number",
|
|
140
|
+
"description": "Resolved retry count."
|
|
141
|
+
},
|
|
142
|
+
"apiTokenSet": {
|
|
143
|
+
"type": "boolean",
|
|
144
|
+
"description": "Whether apiToken is set (value never included)."
|
|
145
|
+
},
|
|
146
|
+
"version": {
|
|
147
|
+
"type": "string",
|
|
148
|
+
"description": "App version from program root."
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
"required": [
|
|
152
|
+
"apiTokenSet",
|
|
153
|
+
"version"
|
|
154
|
+
],
|
|
155
|
+
"description": "JSON payload for `full-example status --json`.",
|
|
156
|
+
"definitions": {}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
"400": {
|
|
162
|
+
"description": "Invalid arguments or help requested",
|
|
163
|
+
"content": {
|
|
164
|
+
"application/json; charset=utf-8": {
|
|
165
|
+
"schema": {
|
|
166
|
+
"type": "object",
|
|
167
|
+
"properties": {
|
|
168
|
+
"error": {
|
|
169
|
+
"type": "string"
|
|
170
|
+
},
|
|
171
|
+
"exitCode": {
|
|
172
|
+
"type": "integer"
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
"required": [
|
|
176
|
+
"error"
|
|
177
|
+
]
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
"404": {
|
|
183
|
+
"description": "Unknown tool",
|
|
184
|
+
"content": {
|
|
185
|
+
"application/json; charset=utf-8": {
|
|
186
|
+
"schema": {
|
|
187
|
+
"type": "object",
|
|
188
|
+
"properties": {
|
|
189
|
+
"error": {
|
|
190
|
+
"type": "string"
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
"required": [
|
|
194
|
+
"error"
|
|
195
|
+
]
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
"500": {
|
|
201
|
+
"description": "Handler error",
|
|
202
|
+
"content": {
|
|
203
|
+
"application/json; charset=utf-8": {
|
|
204
|
+
"schema": {
|
|
205
|
+
"type": "object",
|
|
206
|
+
"properties": {
|
|
207
|
+
"error": {
|
|
208
|
+
"type": "string"
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
"required": [
|
|
212
|
+
"error"
|
|
213
|
+
]
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: full_example
|
|
3
|
+
description: Operates the full-example CLI (echo, status). Use when the user mentions full-example, echo, status, or related tasks.
|
|
4
|
+
---
|
|
5
|
+
<!-- Generated by full-example docs skill --save; do not edit. -->
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# full-example
|
|
9
|
+
|
|
10
|
+
Argsbarg full example reference app
|
|
11
|
+
|
|
12
|
+
## Execution
|
|
13
|
+
|
|
14
|
+
Invoke via shell:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
full-example <subcommand> [options] [args]
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Commands
|
|
21
|
+
|
|
22
|
+
- **`full-example echo`** — Echo a message (MCP-friendly leaf).
|
|
23
|
+
- **`full-example status`** — Show resolved config and app version. (flags: --json)
|
|
24
|
+
|
|
25
|
+
## Configuration
|
|
26
|
+
|
|
27
|
+
- **apiToken** (`apiToken` (env: `FULL_EXAMPLE_API_TOKEN`)) — Create at https://example.com/settings/tokens
|
|
28
|
+
- **defaultRegion** (`defaultRegion`) — AWS region for API calls.
|
|
29
|
+
- **maxRetries** (`maxRetries`) — HTTP retry count (0–10).
|
|
30
|
+
- **prefs** (`prefs`) — Local cache preferences (not exported to env).
|
|
31
|
+
|
|
32
|
+
## Pitfalls
|
|
33
|
+
|
|
34
|
+
- Pass `--` before arguments that look like flags.
|
|
35
|
+
|
|
36
|
+
## Reference
|
|
37
|
+
|
|
38
|
+
For full detail, open `reference.md` in this skill directory (same as `full-example docs api`).
|
|
39
|
+
|
|
40
|
+
## Cursor install location
|
|
41
|
+
|
|
42
|
+
- Project: `.cursor/skills/full_example/`
|
|
43
|
+
- Global: `~/.cursor/skills/full_example/`
|
|
44
|
+
|
|
45
|
+
Do not install under `~/.cursor/skills-cursor/` (reserved for Cursor built-ins).
|
|
46
|
+
|
|
@@ -27,10 +27,14 @@ check: schemagen format typecheck
|
|
|
27
27
|
dev *ARGS:
|
|
28
28
|
bun --watch ./src/index.ts {{ARGS}}
|
|
29
29
|
|
|
30
|
-
# Regenerate docs
|
|
30
|
+
# Regenerate consumer docs under ./docs/
|
|
31
31
|
docgen: schemagen
|
|
32
|
-
@just run docs schema --save
|
|
32
|
+
@just run docs cli-schema --save
|
|
33
|
+
@just run docs api --save
|
|
33
34
|
@just run docs skill --save
|
|
35
|
+
@just run docs mcp --save
|
|
36
|
+
@just run docs http --save
|
|
37
|
+
@just run docs openapi --save
|
|
34
38
|
|
|
35
39
|
alias fmt := format
|
|
36
40
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
/**
|
|
3
3
|
* Stage or restore the dev Homebrew formula for `just install-local`.
|
|
4
|
-
* `install` — back up release `Formula/
|
|
4
|
+
* `install` — back up release `Formula/full-example.rb` and write a `file://` dev formula.
|
|
5
5
|
* `reset` — restore the release formula from backup.
|
|
6
6
|
*/
|
|
7
7
|
|
|
@@ -16,6 +16,11 @@ export const echoCommand = {
|
|
|
16
16
|
},
|
|
17
17
|
],
|
|
18
18
|
handler: (ctx) => {
|
|
19
|
-
|
|
19
|
+
const message = ctx.stringOpt("message") ?? "";
|
|
20
|
+
if (ctx.invocation === "cli") {
|
|
21
|
+
console.log(message);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
return message;
|
|
20
25
|
},
|
|
21
26
|
} satisfies CliLeaf;
|
package/examples/mcp-test.ts
CHANGED
|
@@ -49,7 +49,12 @@ const program = {
|
|
|
49
49
|
],
|
|
50
50
|
handler: (ctx) => {
|
|
51
51
|
const name = ctx.stringOpt("name") ?? "";
|
|
52
|
-
|
|
52
|
+
const value = process.env[name] ?? "";
|
|
53
|
+
if (ctx.invocation === "cli") {
|
|
54
|
+
console.log(value);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
53
58
|
},
|
|
54
59
|
},
|
|
55
60
|
{
|
|
@@ -65,7 +70,13 @@ const program = {
|
|
|
65
70
|
},
|
|
66
71
|
],
|
|
67
72
|
handler: (ctx) => {
|
|
68
|
-
|
|
73
|
+
const mode = ctx.stringOpt("mode") ?? "";
|
|
74
|
+
const text = `mode=${mode}`;
|
|
75
|
+
if (ctx.invocation === "cli") {
|
|
76
|
+
console.log(text);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
return text;
|
|
69
80
|
},
|
|
70
81
|
},
|
|
71
82
|
],
|
package/examples/nested.ts
CHANGED
|
@@ -64,10 +64,19 @@ const program = {
|
|
|
64
64
|
process.exit(1);
|
|
65
65
|
}
|
|
66
66
|
if (ctx.hasFlag("json")) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
const payload = { user, path };
|
|
68
|
+
if (ctx.invocation === "cli") {
|
|
69
|
+
console.log(JSON.stringify(payload));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
return payload;
|
|
70
73
|
}
|
|
74
|
+
const text = `lookup user=${user} path=${path}`;
|
|
75
|
+
if (ctx.invocation === "cli") {
|
|
76
|
+
console.log(text);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
return text;
|
|
71
80
|
},
|
|
72
81
|
},
|
|
73
82
|
],
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/*
|
|
3
|
+
This example shows the smallest end-to-end CLI+MCP+API setup.
|
|
4
|
+
It includes one command, a couple of options, and a direct call to the runtime so
|
|
5
|
+
readers can copy the pattern into their own scripts quickly.
|
|
6
|
+
|
|
7
|
+
Demonstrates: `servers.ts hello`, MCP tool `hello`, and `POST /tools/hello`.
|
|
8
|
+
|
|
9
|
+
Ex API Call:
|
|
10
|
+
curl -s -X POST http://127.0.0.1:3000/tools/hello \
|
|
11
|
+
-H 'content-type: application/json' \
|
|
12
|
+
-d '{"name":"alice"}'
|
|
13
|
+
Ex API Response:
|
|
14
|
+
{ "greeting": "hello alice" }
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import pkg from "../package.json" with { type: "json" };
|
|
20
|
+
import { Cli, CliOptionKind, type CliProgram } from "../src/index.ts";
|
|
21
|
+
|
|
22
|
+
const program = {
|
|
23
|
+
key: "servers.ts",
|
|
24
|
+
version: pkg.version,
|
|
25
|
+
description: "Tiny demo.",
|
|
26
|
+
mcpServer: { enabled: true },
|
|
27
|
+
apiServer: { enabled: true },
|
|
28
|
+
docs: {
|
|
29
|
+
enabled: true,
|
|
30
|
+
topics: {
|
|
31
|
+
readme: { text: "# servers.ts\n\nServers demo.\n" },
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
commands: [
|
|
35
|
+
{
|
|
36
|
+
key: "hello",
|
|
37
|
+
description: "Say hello.",
|
|
38
|
+
positionals: [
|
|
39
|
+
{
|
|
40
|
+
name: "name",
|
|
41
|
+
description: "Who to greet.",
|
|
42
|
+
kind: CliOptionKind.String,
|
|
43
|
+
argMin: 0,
|
|
44
|
+
argMax: 1,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
options: [
|
|
48
|
+
{
|
|
49
|
+
name: "verbose",
|
|
50
|
+
description: "Enable extra logging.",
|
|
51
|
+
kind: CliOptionKind.Presence,
|
|
52
|
+
shortName: "v",
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
handler: (ctx) => {
|
|
56
|
+
const name = ctx.args[0] ?? "world";
|
|
57
|
+
if (ctx.hasFlag("verbose") && ctx.invocation === "cli") {
|
|
58
|
+
console.log("verbose mode");
|
|
59
|
+
}
|
|
60
|
+
const greeting = `hello ${name}`;
|
|
61
|
+
if (ctx.invocation === "cli") {
|
|
62
|
+
console.log(greeting);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
return { greeting, verbose: ctx.hasFlag("verbose") };
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
} satisfies CliProgram;
|
|
70
|
+
|
|
71
|
+
const cli = new Cli(program);
|
|
72
|
+
await cli.run();
|
package/index.d.ts
CHANGED
|
@@ -57,8 +57,18 @@ export declare class CliContext {
|
|
|
57
57
|
readonly opts: Record<string, string>;
|
|
58
58
|
readonly invocation: CliInvocation;
|
|
59
59
|
readonly appConfig: AnyAppConfigSnapshot;
|
|
60
|
+
/** Original flat tool arguments for API/MCP invocations (when provided). */
|
|
61
|
+
readonly toolArgs?: Record<string, unknown>;
|
|
62
|
+
private response?;
|
|
60
63
|
/** Captures the program root, routed path, positional words, and option map for a leaf handler. */
|
|
61
|
-
constructor(appName: string, commandPath: string[], args: string[], opts: Record<string, string>, program: CliProgram, invocation?: CliInvocation, appConfig?: AnyAppConfigSnapshot);
|
|
64
|
+
constructor(appName: string, commandPath: string[], args: string[], opts: Record<string, string>, program: CliProgram, invocation?: CliInvocation, appConfig?: AnyAppConfigSnapshot, toolArgs?: Record<string, unknown>);
|
|
65
|
+
/**
|
|
66
|
+
* Sets the machine-readable response for API/MCP invocations, or writes to stdout in CLI mode.
|
|
67
|
+
* May only be called once per invocation.
|
|
68
|
+
*/
|
|
69
|
+
respond(opts: CliRespondOptions): void;
|
|
70
|
+
/** Returns the respond payload set by {@link respond}, if any. */
|
|
71
|
+
getResponse(): CliRespondOptions | undefined;
|
|
62
72
|
/** Returns whether a presence flag was set (including implicit "1" for boolean options). */
|
|
63
73
|
hasFlag(name: string): boolean;
|
|
64
74
|
/** Returns the string value for a string-valued option, if present. */
|
|
@@ -90,7 +100,7 @@ export declare class CliContext {
|
|
|
90
100
|
/**
|
|
91
101
|
* How a leaf handler was dispatched.
|
|
92
102
|
*/
|
|
93
|
-
export type CliInvocation = "cli" | "mcp";
|
|
103
|
+
export type CliInvocation = "cli" | "mcp" | "api";
|
|
94
104
|
/**
|
|
95
105
|
* Option kinds: presence (boolean flag), string (free-form text), number (strict double), or enum (fixed choices).
|
|
96
106
|
*/
|
|
@@ -227,6 +237,38 @@ export interface CliMcpServerConfig {
|
|
|
227
237
|
/** Optional MCP Bundle (`.mcpb`) metadata for `mcp bundle`. */
|
|
228
238
|
bundle?: CliMcpBundleConfig;
|
|
229
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Enables `myapp api` and the HTTP tool server (program root only).
|
|
242
|
+
* Must include `enabled: true`; omit `apiServer` entirely to disable HTTP.
|
|
243
|
+
*/
|
|
244
|
+
export interface CliApiServerConfig {
|
|
245
|
+
/** When `true`, enables the `api` built-in and HTTP tool server. */
|
|
246
|
+
enabled: boolean;
|
|
247
|
+
/** Listen host (default: `127.0.0.1`). */
|
|
248
|
+
host?: string;
|
|
249
|
+
/** Listen port (default: `3000`). */
|
|
250
|
+
port?: number;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Declarative HTTP response hints for a leaf (used by OpenAPI and default headers).
|
|
254
|
+
*/
|
|
255
|
+
export interface CliApiResponseConfig {
|
|
256
|
+
/** Default success Content-Type (default: `application/json`). */
|
|
257
|
+
contentType?: string;
|
|
258
|
+
/** Optional Content-Disposition (e.g. `attachment; filename="invoice.pdf"`). */
|
|
259
|
+
contentDisposition?: string;
|
|
260
|
+
}
|
|
261
|
+
/** Body types accepted by {@link CliContext.respond}. */
|
|
262
|
+
export type CliRespondBody = string | Uint8Array | Record<string, unknown> | unknown[];
|
|
263
|
+
/** Options for {@link CliContext.respond} and headless invoke results. */
|
|
264
|
+
export interface CliRespondOptions {
|
|
265
|
+
body: CliRespondBody;
|
|
266
|
+
/** Default: `application/json` for objects/arrays, `text/plain` for strings; binary requires explicit type. */
|
|
267
|
+
contentType?: string;
|
|
268
|
+
/** HTTP status (default: 200). */
|
|
269
|
+
status?: number;
|
|
270
|
+
headers?: Record<string, string>;
|
|
271
|
+
}
|
|
230
272
|
/**
|
|
231
273
|
* A custom MCP resource exposed under resources/list and resources/read.
|
|
232
274
|
*/
|
|
@@ -429,9 +471,13 @@ export type CliLeaf = CliNodeBase & {
|
|
|
429
471
|
positionals?: CliPositional[];
|
|
430
472
|
/**
|
|
431
473
|
* JSON Schema for structured stdout (e.g. with `--json` or MCP when the handler emits JSON).
|
|
432
|
-
* Exported in `docs schema`, `docs api`, and MCP `tools/list`; not validated at runtime yet.
|
|
474
|
+
* Exported in `docs cli-schema`, `docs api`, and MCP `tools/list`; not validated at runtime yet.
|
|
433
475
|
*/
|
|
434
476
|
outputSchema?: Record<string, unknown>;
|
|
477
|
+
/** JSON Schema for MCP/HTTP tool arguments (flat object). */
|
|
478
|
+
inputSchema?: Record<string, unknown>;
|
|
479
|
+
/** Declarative HTTP response metadata (Content-Type, Content-Disposition). */
|
|
480
|
+
apiResponse?: CliApiResponseConfig;
|
|
435
481
|
/** Per-tool MCP exposure and metadata. */
|
|
436
482
|
mcpTool?: CliMcpToolConfig;
|
|
437
483
|
};
|
|
@@ -461,6 +507,8 @@ export type CliProgram = CliNode & {
|
|
|
461
507
|
appConfig?: CliAppConfig;
|
|
462
508
|
/** When set with `enabled: true`, enables the `mcp` built-in subcommand. */
|
|
463
509
|
mcpServer?: CliMcpServerConfig;
|
|
510
|
+
/** When set with `enabled: true`, enables the `api` built-in HTTP server. */
|
|
511
|
+
apiServer?: CliApiServerConfig;
|
|
464
512
|
/** Opt-out and defaults for `configure`. */
|
|
465
513
|
configure?: CliConfigureConfig;
|
|
466
514
|
/** Opt-out for shell completion generation (`completion bash|zsh|fish`). */
|
|
@@ -470,9 +518,9 @@ export type CliProgram = CliNode & {
|
|
|
470
518
|
};
|
|
471
519
|
/**
|
|
472
520
|
* Handler closure type for leaf commands.
|
|
473
|
-
* Supports
|
|
521
|
+
* Supports sync and async handlers; non-undefined return values become implicit JSON responses for headless invocations.
|
|
474
522
|
*/
|
|
475
|
-
export type CliHandler = (ctx: CliContext) =>
|
|
523
|
+
export type CliHandler = (ctx: CliContext) => unknown | Promise<unknown>;
|
|
476
524
|
/**
|
|
477
525
|
* Error thrown when the static CLI tree violates ArgsBarg rules.
|
|
478
526
|
*/
|
|
@@ -480,8 +528,13 @@ export declare class CliSchemaValidationError extends Error {
|
|
|
480
528
|
/** Creates a schema validation error with a human-readable rule violation. */
|
|
481
529
|
constructor(message: string);
|
|
482
530
|
}
|
|
531
|
+
/** Generates an OpenAPI 3.1 document for the program's exposed tools. */
|
|
532
|
+
export declare function generateOpenApi(program: CliProgram): Record<string, unknown>;
|
|
533
|
+
/** Pretty-printed OpenAPI JSON (same document as `GET /openapi.json`). */
|
|
534
|
+
export declare function openApiJson(program: CliProgram): string;
|
|
483
535
|
/** Platform builtins derived from program config and runtime. */
|
|
484
536
|
export interface CliCapabilities {
|
|
537
|
+
api: boolean;
|
|
485
538
|
completion: boolean;
|
|
486
539
|
mcp: boolean;
|
|
487
540
|
configure: boolean;
|
|
@@ -510,6 +563,8 @@ export interface CliInvokeResult {
|
|
|
510
563
|
stdout: string;
|
|
511
564
|
stderr: string;
|
|
512
565
|
errorMsg?: string;
|
|
566
|
+
/** Headless response payload when invocation is `api` or `mcp` and the handler succeeded. */
|
|
567
|
+
response?: CliRespondOptions;
|
|
513
568
|
}
|
|
514
569
|
/** Argsbarg runtime for a validated, frozen {@link CliProgram}. */
|
|
515
570
|
export declare class Cli {
|
|
@@ -523,8 +578,12 @@ export declare class Cli {
|
|
|
523
578
|
exportCommandSchema(): CliSchemaExport;
|
|
524
579
|
exportAppConfigSchema(): Record<string, unknown> | undefined;
|
|
525
580
|
run(argv?: string[]): Promise<never>;
|
|
526
|
-
invoke(argv: string[]
|
|
581
|
+
invoke(argv: string[], opts?: {
|
|
582
|
+
invocation?: CliInvocation;
|
|
583
|
+
toolArgs?: Record<string, unknown>;
|
|
584
|
+
}): Promise<CliInvokeResult>;
|
|
527
585
|
serveMcp(): Promise<never>;
|
|
586
|
+
serveApi(): Promise<never>;
|
|
528
587
|
private prepareDispatch;
|
|
529
588
|
private buildAppConfigSnapshot;
|
|
530
589
|
}
|
|
@@ -539,7 +598,7 @@ export declare function parseDate(s: string): string;
|
|
|
539
598
|
export declare function parseDateTime(s: string): string;
|
|
540
599
|
/** Minimal context for headless routing helpers. */
|
|
541
600
|
export type HeadlessContext = Pick<CliContext, "invocation">;
|
|
542
|
-
/** True when `--json` was passed or the handler was invoked
|
|
601
|
+
/** True when `--json` was passed or the handler was invoked headlessly over MCP/HTTP. */
|
|
543
602
|
export declare function wantsExplicitJson(ctx: HeadlessContext, hasJsonFlag: boolean): boolean;
|
|
544
603
|
/**
|
|
545
604
|
* Headless when MCP, `--json`, `--dry-run`, or stdin is not a TTY.
|