argsbarg 2.1.1 → 3.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 +14 -1
- package/README.md +9 -7
- package/docs/install.md +2 -2
- package/docs/mcp.md +18 -13
- package/examples/mcp-test.ts +2 -2
- package/examples/minimal.ts +2 -0
- package/examples/nested.ts +3 -1
- package/examples/option-required.ts +2 -0
- package/index.d.ts +8 -7
- package/package.json +1 -1
- package/src/builtins/builtins.test.ts +8 -3
- package/src/builtins/dispatch.ts +22 -1
- package/src/builtins/export.ts +5 -1
- package/src/builtins/install.ts +2 -1
- package/src/builtins/presentation.ts +5 -1
- package/src/builtins/version.ts +10 -0
- package/src/capabilities.ts +2 -2
- package/src/index.test.ts +182 -122
- package/src/index.ts +0 -0
- package/src/install/index.ts +2 -1
- package/src/install/install.test.ts +2 -1
- package/src/install/paths.ts +2 -2
- package/src/install/plan.ts +3 -2
- package/src/install/uninstall.ts +2 -1
- package/src/invoke.ts +1 -1
- package/src/mcp/tools.ts +21 -24
- package/src/runtime.ts +1 -1
- package/src/skill/generate.ts +3 -3
- package/src/types.test.ts +3 -2
- package/src/types.ts +8 -7
- package/src/validate.ts +13 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [3.0.0] - 2026-06-20
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **`version` built-in** — `myapp version` prints `CliProgram.version` (always available; reserved command name).
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- **`CliProgram.version`** (required) — single source of truth for the `version` built-in and MCP `serverInfo.version`. Removed `mcpServer.version` and automatic `package.json` lookup.
|
|
19
|
+
- **MCP opt-in** — `mcpServer: { enabled: true }` enables MCP; omit `mcpServer` to disable. Empty `mcpServer: {}` is rejected at validation.
|
|
20
|
+
- **MCP identity from `key`** — removed `mcpServer.name`. MCP `serverInfo.name`, schema URI, and `mcp.json` entry keys use `sanitizeToolSegment(root.key)` (e.g. `nested.ts` → `nested_ts://schema`). Shell `command` stays the raw `key`.
|
|
21
|
+
|
|
10
22
|
## [2.1.1] - 2026-06-20
|
|
11
23
|
|
|
12
24
|
### Changed
|
|
@@ -186,7 +198,8 @@ const cli = { ... } satisfies CliProgram; // or : CliProgram
|
|
|
186
198
|
- Migrate schemas: rename every `children` property to **`commands`**; move positional definitions to **`CliPositional`** objects on `positionals` and strip `positional` / `argMin` / `argMax` from flag definitions under `options` (flags only carry `name`, `description`, `kind`, and optional `shortName`).
|
|
187
199
|
- Imports: use `CliPositional` where needed; replace `CliOptionDef` with `CliOption` or `CliPositional` as appropriate.
|
|
188
200
|
|
|
189
|
-
[Unreleased]: https://github.com/bdombro/bun-argsbarg/compare/
|
|
201
|
+
[Unreleased]: https://github.com/bdombro/bun-argsbarg/compare/v3.0.0...HEAD
|
|
202
|
+
[3.0.0]: https://github.com/bdombro/bun-argsbarg/releases/tag/v3.0.0
|
|
190
203
|
[2.1.1]: https://github.com/bdombro/bun-argsbarg/releases/tag/v2.1.1
|
|
191
204
|
[2.1.0]: https://github.com/bdombro/bun-argsbarg/releases/tag/v2.1.0
|
|
192
205
|
[2.0.1]: https://github.com/bdombro/bun-argsbarg/releases/tag/v2.0.1
|
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ Why another CLI parser?
|
|
|
16
16
|
|
|
17
17
|
*Shell completions* — `completion bash`, `completion zsh`, and `completion fish` built-ins generate installable scripts from your schema so users get tab completion for commands, flags, and positionals without extra tooling.
|
|
18
18
|
|
|
19
|
-
*Optional MCP server* — set `mcpServer: {}` on the program root to expose leaf commands as MCP tools and the full CLI tree as a schema resource (`myapp mcp` over stdio). See [docs/mcp.md](docs/mcp.md). Compiled binaries can install binary, completions, skills, and MCP config with `myapp install` — see [docs/install.md](docs/install.md).
|
|
19
|
+
*Optional MCP server* — set `mcpServer: { enabled: true }` on the program root to expose leaf commands as MCP tools and the full CLI tree as a schema resource (`myapp mcp` over stdio). See [docs/mcp.md](docs/mcp.md). Compiled binaries can install binary, completions, skills, and MCP config with `myapp install` — see [docs/install.md](docs/install.md).
|
|
20
20
|
|
|
21
21
|
*Bun-optimized* — built from the ground up for Bun and TypeScript, leveraging Bun’s performance and modern JavaScript features without any extra dependencies.
|
|
22
22
|
|
|
@@ -39,6 +39,7 @@ import { cliRun, type CliProgram, CliOptionKind } from "argsbarg";
|
|
|
39
39
|
|
|
40
40
|
const cli = {
|
|
41
41
|
key: "helloapp",
|
|
42
|
+
version: "1.0.0",
|
|
42
43
|
description: "Tiny demo.",
|
|
43
44
|
positionals: [
|
|
44
45
|
{
|
|
@@ -96,17 +97,18 @@ Every app gets:
|
|
|
96
97
|
- `-h` / `--help` at any routing depth (scoped help).
|
|
97
98
|
- **`--schema`** at the program root — print the full command tree as JSON (for tooling and agents).
|
|
98
99
|
- **`completion bash` / `completion zsh` / `completion fish`** — print shell completion scripts to stdout (injected by `cliRun`).
|
|
99
|
-
- **`
|
|
100
|
+
- **`version`** — print `CliProgram.version` (`myapp version`).
|
|
101
|
+
- **`mcp`** — when `mcpServer.enabled` is `true`, run as an MCP stdio server (`myapp mcp`).
|
|
100
102
|
- **`install`** — install the binary, completions, skills, and MCP config to the user environment (`myapp install --all --yes`). See [docs/install.md](docs/install.md).
|
|
101
103
|
|
|
102
|
-
Do not declare a top-level command named **`completion
|
|
103
|
-
When **`mcpServer`** is
|
|
104
|
+
Do not declare a top-level command named **`completion`**, **`version`**, or **`install`** — they are reserved.
|
|
105
|
+
When **`mcpServer.enabled`** is `true`, do not declare a top-level command named **`mcp`** — it is reserved for the MCP built-in.
|
|
104
106
|
Do not declare an option named **`schema`** — it is reserved for `--schema`.
|
|
105
107
|
|
|
106
108
|
|
|
107
109
|
### MCP (AI agents)
|
|
108
110
|
|
|
109
|
-
Opt in on the program root with `mcpServer: {
|
|
111
|
+
Opt in on the program root with `mcpServer: { enabled: true }`, then run `myapp mcp` for a stdio MCP server. Each leaf command becomes a tool; the CLI tree is available as resource `<sanitized-key>://schema` (same as `myapp --schema`). Handlers can read `ctx.invocation` and use `cliInvoke` for headless testing.
|
|
110
112
|
|
|
111
113
|
See **[docs/mcp.md](docs/mcp.md)** for configuration, env bootstrapping, custom resources, Cursor setup, and protocol details.
|
|
112
114
|
|
|
@@ -185,7 +187,7 @@ Add `CliPositional` entries to the command’s `positionals` list (separate from
|
|
|
185
187
|
|
|
186
188
|
### Capabilities (built-ins)
|
|
187
189
|
|
|
188
|
-
`completion`, `install`, and `mcp` are not part of your schema — they are injected at runtime from program-level config (`mcpServer`, `install`). Reserved command names
|
|
190
|
+
`completion`, `version`, `install`, and `mcp` are not part of your schema — they are injected at runtime from program-level config (`mcpServer`, `install`). Reserved command names: `completion` and `version` always; `install` unless `install.enabled: false`; `mcp` when `mcpServer.enabled` is `true`.
|
|
189
191
|
|
|
190
192
|
|
|
191
193
|
|
|
@@ -226,7 +228,7 @@ The package root (`argsbarg` / `src/index.ts`) exports the types and runtime you
|
|
|
226
228
|
| `cliInvoke(root, argv)` | Parse and dispatch without exiting; returns captured stdout/stderr. |
|
|
227
229
|
| `cliErrWithHelp(ctx, msg)` | Print error + scoped help on stderr, exit 1. |
|
|
228
230
|
|
|
229
|
-
Reserved identifiers (validated at startup): root commands **`completion`**, **`install`**, and **`mcp`** (only when `mcpServer` is
|
|
231
|
+
Reserved identifiers (validated at startup): root commands **`completion`**, **`version`**, **`install`**, and **`mcp`** (only when `mcpServer.enabled` is `true`).
|
|
230
232
|
|
|
231
233
|
---
|
|
232
234
|
|
package/docs/install.md
CHANGED
|
@@ -30,7 +30,7 @@ myapp install --uninstall --yes
|
|
|
30
30
|
| Claude skill | `--skill` | `~/.claude/skills/<dir>/` when `~/.claude` exists |
|
|
31
31
|
| MCP config | `--mcp` | `~/.cursor/mcp.json` and `~/.claude.json` when MCP is enabled |
|
|
32
32
|
|
|
33
|
-
`--all` expands to `--bin`, `--completions`, `--skill`, and `--mcp` (when `mcpServer` is
|
|
33
|
+
`--all` expands to `--bin`, `--completions`, `--skill`, and `--mcp` (when `mcpServer.enabled` is `true`).
|
|
34
34
|
|
|
35
35
|
Shells not on PATH are skipped silently (no warnings).
|
|
36
36
|
|
|
@@ -64,7 +64,7 @@ Environment:
|
|
|
64
64
|
|
|
65
65
|
## MCP merge behavior
|
|
66
66
|
|
|
67
|
-
When `--mcp` runs, entries are merged into `mcpServers[<
|
|
67
|
+
When `--mcp` runs, entries are merged into `mcpServers[<sanitized-key>]` with:
|
|
68
68
|
|
|
69
69
|
```json
|
|
70
70
|
{ "command": "<root.key>", "args": ["mcp"] }
|
package/docs/mcp.md
CHANGED
|
@@ -9,15 +9,18 @@ MCP is **opt-in**. Apps that do not set `mcpServer` on the program root behave e
|
|
|
9
9
|
1. Add `mcpServer` to your program root:
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
+
import pkg from "../package.json" with { type: "json" };
|
|
13
|
+
|
|
12
14
|
const cli = {
|
|
13
15
|
key: "myapp",
|
|
16
|
+
version: pkg.version,
|
|
14
17
|
description: "My app.",
|
|
15
|
-
mcpServer: {
|
|
18
|
+
mcpServer: { enabled: true },
|
|
16
19
|
commands: [/* ... */],
|
|
17
20
|
} satisfies CliProgram;
|
|
18
21
|
```
|
|
19
22
|
|
|
20
|
-
`mcpServer: {}`
|
|
23
|
+
`mcpServer: { enabled: true }` opts in. Omit `mcpServer` entirely to disable MCP. Empty `mcpServer: {}` is rejected at validation.
|
|
21
24
|
|
|
22
25
|
2. Run the MCP server:
|
|
23
26
|
|
|
@@ -66,26 +69,27 @@ Set `mcpServer` on the **program root only** (the `CliProgram` passed to `cliRun
|
|
|
66
69
|
|
|
67
70
|
| Field | Default | Purpose |
|
|
68
71
|
| --- | --- | --- |
|
|
69
|
-
| `
|
|
70
|
-
| `
|
|
71
|
-
| `schemaResourceUri` | `"argsbarg://schema"` | URI for the schema resource |
|
|
72
|
+
| `enabled` | *(required)* | Must be `true` when `mcpServer` is set |
|
|
73
|
+
| `schemaResourceUri` | `<sanitized root key>://schema` | URI for the built-in schema resource |
|
|
72
74
|
| `shellEnv` | off | Capture login-shell `env` at startup (`true` uses `$SHELL`, or pass a shell path) |
|
|
73
75
|
| `envFile` | off | Load a `.env` file after `shellEnv` (`~` supported); warns on stderr if missing |
|
|
74
|
-
| `resources` | `[]` | Custom `CliMcpResource` entries
|
|
76
|
+
| `resources` | `[]` | Custom `CliMcpResource` entries (additive; schema resource is always included) |
|
|
77
|
+
|
|
78
|
+
MCP `serverInfo.name` and the default schema URI use the sanitized program `key` (non-alphanumeric characters become `_`). Program `version` comes from `CliProgram.version` (also used by the `version` built-in).
|
|
75
79
|
|
|
76
|
-
Example with
|
|
80
|
+
Example with optional fields:
|
|
77
81
|
|
|
78
82
|
```typescript
|
|
79
83
|
mcpServer: {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
enabled: true,
|
|
85
|
+
shellEnv: true,
|
|
86
|
+
envFile: "~/.config/myapp/mcp.env",
|
|
83
87
|
}
|
|
84
88
|
```
|
|
85
89
|
|
|
86
90
|
## Tools
|
|
87
91
|
|
|
88
|
-
Every **user-defined leaf command** in your schema becomes one MCP tool. Built-ins (`completion`, `
|
|
92
|
+
Every **user-defined leaf command** in your schema becomes one MCP tool. Built-ins (`completion`, `version`, `install`, `mcp`) are not exposed as tools.
|
|
89
93
|
|
|
90
94
|
### Tool names
|
|
91
95
|
|
|
@@ -172,11 +176,11 @@ Help and `--schema` are not available through tool calls; use the schema resourc
|
|
|
172
176
|
|
|
173
177
|
## Schema and custom resources
|
|
174
178
|
|
|
175
|
-
The built-in resource
|
|
179
|
+
The built-in schema resource (default URI `<sanitized-key>://schema`, e.g. `nested.ts` → `nested_ts://schema`) exposes your full CLI tree as JSON — the same output as `myapp --schema`. Override with `schemaResourceUri` if needed.
|
|
176
180
|
|
|
177
181
|
| Property | Value |
|
|
178
182
|
| --- | --- |
|
|
179
|
-
| Default URI |
|
|
183
|
+
| Default URI | `<sanitized root key>://schema` |
|
|
180
184
|
| MIME type | `application/json` |
|
|
181
185
|
| Contents | `cliSchemaJson(root)` — handlers omitted, built-ins excluded |
|
|
182
186
|
|
|
@@ -184,6 +188,7 @@ Add custom resources on the program root:
|
|
|
184
188
|
|
|
185
189
|
```typescript
|
|
186
190
|
mcpServer: {
|
|
191
|
+
enabled: true,
|
|
187
192
|
resources: [
|
|
188
193
|
{
|
|
189
194
|
uri: "myapp://config",
|
package/examples/mcp-test.ts
CHANGED
|
@@ -9,10 +9,10 @@ const envFilePath = process.env.ARGS_TEST_ENV_FILE;
|
|
|
9
9
|
|
|
10
10
|
const cli = {
|
|
11
11
|
key: "mcp-test",
|
|
12
|
+
version: "0.0.0-test",
|
|
12
13
|
description: "MCP integration test fixture.",
|
|
13
14
|
mcpServer: {
|
|
14
|
-
|
|
15
|
-
version: "0.0.0-test",
|
|
15
|
+
enabled: true,
|
|
16
16
|
...(envFilePath ? { envFile: envFilePath } : {}),
|
|
17
17
|
resources: [
|
|
18
18
|
{
|
package/examples/minimal.ts
CHANGED
|
@@ -7,10 +7,12 @@ readers can copy the pattern into their own scripts quickly.
|
|
|
7
7
|
It demonstrates the minimal Bun integration path.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import pkg from "../package.json" with { type: "json" };
|
|
10
11
|
import { cliRun, CliProgram, CliOptionKind } from "../src/index.ts";
|
|
11
12
|
|
|
12
13
|
const cli = {
|
|
13
14
|
key: "minimal.ts",
|
|
15
|
+
version: pkg.version,
|
|
14
16
|
description: "Tiny demo.",
|
|
15
17
|
positionals: [
|
|
16
18
|
{
|
package/examples/nested.ts
CHANGED
|
@@ -7,12 +7,14 @@ and fallback commands fit together in one schema.
|
|
|
7
7
|
It demonstrates how the schema scales beyond one command.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import pkg from "../package.json" with { type: "json" };
|
|
10
11
|
import { cliRun, CliProgram, CliOptionKind, CliFallbackMode } from "../src/index.ts";
|
|
11
12
|
|
|
12
13
|
const cli = {
|
|
13
14
|
key: "nested.ts",
|
|
15
|
+
version: pkg.version,
|
|
14
16
|
description: "Nested groups demo.",
|
|
15
|
-
mcpServer: {
|
|
17
|
+
mcpServer: { enabled: true },
|
|
16
18
|
commands: [
|
|
17
19
|
{
|
|
18
20
|
key: "stat",
|
|
@@ -7,10 +7,12 @@ readers can copy the pattern into their own scripts quickly.
|
|
|
7
7
|
It demonstrates the minimal Bun integration path.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import pkg from "../package.json" with { type: "json" };
|
|
10
11
|
import { cliRun, CliProgram, CliOptionKind, CliFallbackMode, isInteractiveTty } from "../src/index.ts";
|
|
11
12
|
|
|
12
13
|
const cli = {
|
|
13
14
|
key: "option-required.ts",
|
|
15
|
+
version: pkg.version,
|
|
14
16
|
description: "Demo of a required option.",
|
|
15
17
|
options: [
|
|
16
18
|
{
|
package/index.d.ts
CHANGED
|
@@ -106,13 +106,12 @@ export interface CliPositional {
|
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
108
|
* Enables `myapp mcp` and MCP stdio server metadata (program root only).
|
|
109
|
+
* Must include `enabled: true`; omit `mcpServer` entirely to disable MCP.
|
|
109
110
|
*/
|
|
110
111
|
export interface CliMcpServerConfig {
|
|
111
|
-
/** `
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
version?: string;
|
|
115
|
-
/** Resource URI for schema export (default: `"argsbarg://schema"`). */
|
|
112
|
+
/** When `true`, enables the `mcp` built-in and MCP stdio server. */
|
|
113
|
+
enabled: boolean;
|
|
114
|
+
/** Resource URI for schema export (default: `<sanitized root key>://schema`). */
|
|
116
115
|
schemaResourceUri?: string;
|
|
117
116
|
/**
|
|
118
117
|
* Capture the user's login shell environment at MCP server start and merge it
|
|
@@ -127,7 +126,7 @@ export interface CliMcpServerConfig {
|
|
|
127
126
|
*/
|
|
128
127
|
envFile?: string;
|
|
129
128
|
/**
|
|
130
|
-
* Custom MCP resources exposed alongside the built-in
|
|
129
|
+
* Custom MCP resources exposed alongside the built-in schema resource.
|
|
131
130
|
* URIs must be unique and must not equal schemaResourceUri.
|
|
132
131
|
*/
|
|
133
132
|
resources?: CliMcpResource[];
|
|
@@ -218,7 +217,9 @@ export type CliNode = CliLeaf | CliRouter;
|
|
|
218
217
|
* May be a leaf or router, plus optional program-level MCP and install config.
|
|
219
218
|
*/
|
|
220
219
|
export type CliProgram = CliNode & {
|
|
221
|
-
/**
|
|
220
|
+
/** Program version (printed by the `version` built-in and MCP serverInfo). */
|
|
221
|
+
version: string;
|
|
222
|
+
/** When set with `enabled: true`, enables the `mcp` built-in subcommand. */
|
|
222
223
|
mcpServer?: CliMcpServerConfig;
|
|
223
224
|
/** Opt-out and defaults for `install`. */
|
|
224
225
|
install?: CliInstallConfig;
|
package/package.json
CHANGED
|
@@ -8,8 +8,9 @@ import { CliProgram } from "../types.ts";
|
|
|
8
8
|
|
|
9
9
|
const fixture: CliProgram = {
|
|
10
10
|
key: "myapp",
|
|
11
|
+
version: "0.0.0",
|
|
11
12
|
description: "Demo app.",
|
|
12
|
-
mcpServer: {
|
|
13
|
+
mcpServer: { enabled: true },
|
|
13
14
|
commands: [
|
|
14
15
|
{
|
|
15
16
|
key: "hello",
|
|
@@ -31,7 +32,7 @@ describe("builtins help copy", () => {
|
|
|
31
32
|
});
|
|
32
33
|
|
|
33
34
|
test("install omits --mcp option when mcpServer unset", () => {
|
|
34
|
-
const noMcp: CliProgram = { key: "x", description: "x", handler: () => {} };
|
|
35
|
+
const noMcp: CliProgram = { key: "x", version: "0.0.0", description: "x", handler: () => {} };
|
|
35
36
|
const names = installBuiltinOptions(noMcp).map((o) => o.name);
|
|
36
37
|
expect(names).not.toContain("mcp");
|
|
37
38
|
});
|
|
@@ -56,6 +57,10 @@ describe("presentation root", () => {
|
|
|
56
57
|
const root = cliPresentationRoot(disabled);
|
|
57
58
|
expect(root.commands?.map((c) => c.key)).not.toContain("install");
|
|
58
59
|
});
|
|
60
|
+
test("includes version builtin", () => {
|
|
61
|
+
const root = cliPresentationRoot(fixture);
|
|
62
|
+
expect(root.commands?.map((c) => c.key)).toContain("version");
|
|
63
|
+
});
|
|
59
64
|
});
|
|
60
65
|
|
|
61
66
|
describe("completion emitters", () => {
|
|
@@ -75,7 +80,7 @@ describe("completion emitters", () => {
|
|
|
75
80
|
});
|
|
76
81
|
|
|
77
82
|
test("zsh script registers compdef", () => {
|
|
78
|
-
const schema = cliPresentationRoot({ key: "zapp", description: "z", handler: () => {} });
|
|
83
|
+
const schema = cliPresentationRoot({ key: "zapp", version: "0.0.0", description: "z", handler: () => {} });
|
|
79
84
|
const zsh = completionZshScript(schema);
|
|
80
85
|
expect(zsh).toContain("#compdef zapp");
|
|
81
86
|
expect(zsh).toContain("compdef _zapp zapp");
|
package/src/builtins/dispatch.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { completionFishScript } from "./completion-fish.ts";
|
|
|
6
6
|
import { completionZshScript } from "./completion-zsh.ts";
|
|
7
7
|
import { cliBuiltinInstallCommand } from "./install.ts";
|
|
8
8
|
import { cliBuiltinMcpCommand } from "./mcp.ts";
|
|
9
|
+
import { cliBuiltinVersionCommand } from "./version.ts";
|
|
9
10
|
import { cliBuiltinCompletionGroup as completionGroup } from "./completion-group.ts";
|
|
10
11
|
import { cliPresentationRoot } from "./presentation.ts";
|
|
11
12
|
import { cliMcpServeStdio } from "../mcp.ts";
|
|
@@ -56,9 +57,18 @@ export async function dispatchBuiltin(
|
|
|
56
57
|
return;
|
|
57
58
|
}
|
|
58
59
|
|
|
60
|
+
if (pr.path[0] === "version") {
|
|
61
|
+
if (pr.path.length !== 1) {
|
|
62
|
+
process.stderr.write("Unknown subcommand: version " + pr.path.slice(1).join(" ") + "\n");
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
process.stdout.write(program.version + "\n");
|
|
66
|
+
process.exit(0);
|
|
67
|
+
}
|
|
68
|
+
|
|
59
69
|
if (pr.path[0] === "mcp") {
|
|
60
70
|
if (!caps.mcp) {
|
|
61
|
-
process.stderr.write("MCP is not enabled. Set mcpServer on the program root.\n");
|
|
71
|
+
process.stderr.write("MCP is not enabled. Set mcpServer: { enabled: true } on the program root.\n");
|
|
62
72
|
process.exit(1);
|
|
63
73
|
}
|
|
64
74
|
if (pr.path.length !== 1) {
|
|
@@ -127,5 +137,16 @@ export function builtinInterceptRoot(
|
|
|
127
137
|
};
|
|
128
138
|
}
|
|
129
139
|
|
|
140
|
+
if (first === "version") {
|
|
141
|
+
return {
|
|
142
|
+
parseRoot: {
|
|
143
|
+
key: program.key,
|
|
144
|
+
description: program.description,
|
|
145
|
+
commands: [cliBuiltinVersionCommand()],
|
|
146
|
+
},
|
|
147
|
+
isLeafCompletionIntercept: false,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
130
151
|
return { parseRoot: program, isLeafCompletionIntercept: false };
|
|
131
152
|
}
|
package/src/builtins/export.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { CliFallbackMode, CliOption, CliPositional, CliProgram } from "../t
|
|
|
3
3
|
import { cliBuiltinCompletionGroup } from "./completion-group.ts";
|
|
4
4
|
import { cliBuiltinInstallCommand } from "./install.ts";
|
|
5
5
|
import { cliBuiltinMcpCommand } from "./mcp.ts";
|
|
6
|
+
import { cliBuiltinVersionCommand } from "./version.ts";
|
|
6
7
|
|
|
7
8
|
/** JSON-safe command node (no handlers). */
|
|
8
9
|
export interface CliSchemaExport {
|
|
@@ -42,7 +43,10 @@ function exportBuiltinNode(cmd: {
|
|
|
42
43
|
/** Built-in subtrees matching help visibility for `--schema` export. */
|
|
43
44
|
export function exportPresentationBuiltins(program: CliProgram, caps?: CliCapabilities): CliSchemaExport[] {
|
|
44
45
|
const resolved = caps ?? resolveCapabilities(program);
|
|
45
|
-
const builtins: CliSchemaExport[] = [
|
|
46
|
+
const builtins: CliSchemaExport[] = [
|
|
47
|
+
exportBuiltinNode(cliBuiltinCompletionGroup(program.key)),
|
|
48
|
+
exportBuiltinNode(cliBuiltinVersionCommand()),
|
|
49
|
+
];
|
|
46
50
|
if (resolved.install) {
|
|
47
51
|
builtins.push(exportBuiltinNode(cliBuiltinInstallCommand(program)));
|
|
48
52
|
}
|
package/src/builtins/install.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveCapabilities } from "../capabilities.ts";
|
|
1
2
|
import { CliProgram, CliOption, CliOptionKind, type CliLeaf } from "../types.ts";
|
|
2
3
|
|
|
3
4
|
/** Install command options (dynamic: `--mcp` only when MCP is enabled). */
|
|
@@ -66,7 +67,7 @@ export function installBuiltinOptions(root: CliProgram): CliOption[] {
|
|
|
66
67
|
},
|
|
67
68
|
];
|
|
68
69
|
|
|
69
|
-
if (root.
|
|
70
|
+
if (resolveCapabilities(root).mcp) {
|
|
70
71
|
opts.splice(4, 0, {
|
|
71
72
|
name: "mcp",
|
|
72
73
|
description: "Add or update MCP server entries in Cursor and Claude config files.",
|
|
@@ -5,10 +5,14 @@ import { isCliLeaf, isCliRouter } from "../types.ts";
|
|
|
5
5
|
import { cliBuiltinCompletionGroup } from "./completion-group.ts";
|
|
6
6
|
import { cliBuiltinInstallCommand } from "./install.ts";
|
|
7
7
|
import { cliBuiltinMcpCommand } from "./mcp.ts";
|
|
8
|
+
import { cliBuiltinVersionCommand } from "./version.ts";
|
|
8
9
|
|
|
9
10
|
/** Built-in command nodes injected for help, schema, and completions. */
|
|
10
11
|
export function presentationBuiltins(program: CliProgram, caps: CliCapabilities): CliNode[] {
|
|
11
|
-
const builtins: CliNode[] = [
|
|
12
|
+
const builtins: CliNode[] = [
|
|
13
|
+
cliBuiltinCompletionGroup(program.key),
|
|
14
|
+
cliBuiltinVersionCommand(),
|
|
15
|
+
];
|
|
12
16
|
if (caps.install) {
|
|
13
17
|
builtins.push(cliBuiltinInstallCommand(program));
|
|
14
18
|
}
|
package/src/capabilities.ts
CHANGED
|
@@ -16,14 +16,14 @@ export interface CliCapabilities {
|
|
|
16
16
|
export function resolveCapabilities(program: CliProgram): CliCapabilities {
|
|
17
17
|
return {
|
|
18
18
|
completion: true,
|
|
19
|
-
mcp: program.mcpServer
|
|
19
|
+
mcp: program.mcpServer?.enabled === true,
|
|
20
20
|
install: program.install?.enabled !== false,
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/** Reserved top-level command names for the given capabilities. */
|
|
25
25
|
export function reservedCommandNames(caps: CliCapabilities): string[] {
|
|
26
|
-
const names = ["completion"];
|
|
26
|
+
const names = ["completion", "version"];
|
|
27
27
|
if (caps.install) {
|
|
28
28
|
names.push("install");
|
|
29
29
|
}
|