argsbarg 1.4.3 → 1.5.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/.private/scratch.md +1 -1
- package/CHANGELOG.md +16 -1
- package/README.md +17 -13
- package/docs/ai-skills.md +24 -52
- package/docs/install.md +84 -0
- package/docs/mcp.md +5 -5
- package/index.d.ts +9 -18
- package/package.json +1 -1
- package/src/builtins/builtins.test.ts +101 -0
- package/src/builtins/completion-bash.ts +240 -0
- package/src/builtins/completion-fish.ts +73 -0
- package/src/builtins/completion-group.ts +50 -0
- package/src/builtins/completion-zsh.ts +244 -0
- package/src/builtins/dispatch.ts +123 -0
- package/src/builtins/export.ts +46 -0
- package/src/builtins/index.ts +10 -0
- package/src/builtins/install.ts +99 -0
- package/src/builtins/mcp.ts +13 -0
- package/src/builtins/presentation.ts +39 -0
- package/src/builtins/scopes.ts +45 -0
- package/src/builtins/shell-helpers.ts +24 -0
- package/src/completion.ts +10 -693
- package/src/index.test.ts +44 -55
- package/src/index.ts +1 -0
- package/src/install/binary.ts +82 -0
- package/src/install/compiled.ts +15 -0
- package/src/install/completions.ts +52 -0
- package/src/install/detect-installed.ts +67 -0
- package/src/install/index.ts +196 -0
- package/src/install/install.test.ts +124 -0
- package/src/install/mcp-config.ts +70 -0
- package/src/install/paths.ts +69 -0
- package/src/install/plan.ts +183 -0
- package/src/install/shell.ts +56 -0
- package/src/install/status.ts +63 -0
- package/src/install/uninstall.ts +111 -0
- package/src/mcp/tools.ts +1 -1
- package/src/runtime.ts +21 -83
- package/src/schema.ts +7 -49
- package/src/skill/generate.ts +4 -4
- package/src/skill/install.ts +20 -18
- package/src/types.ts +9 -9
- package/src/validate.ts +10 -22
- package/src/ai.ts +0 -7
package/.private/scratch.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
- [x] --schema feature for ai agents
|
|
2
|
-
- [
|
|
2
|
+
- [x] opt-out install feature?
|
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.5.0] - 2026-06-20
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **`install` built-in** (compiled binaries only) — install binary, bash/zsh/fish completions, Cursor/Claude skills, and MCP config (`install --all --yes`, `--update`, `--status`, `--uninstall`).
|
|
15
|
+
- **`completion fish`** — fish tab-completion script generation.
|
|
16
|
+
- Root **`install`** config (`{ enabled?: boolean, prefix?: string }`).
|
|
17
|
+
|
|
18
|
+
### Changed (breaking)
|
|
19
|
+
|
|
20
|
+
- **Removed `ai` command group** — no more `ai mcp` or `ai skill`.
|
|
21
|
+
- **Restored top-level `mcp`** — `myapp mcp` (reserved only when `mcpServer` is set).
|
|
22
|
+
- **Removed `aiSkill` config** — skill directory name defaults to sanitized root `key`; use `install --skill` instead of `ai skill`.
|
|
23
|
+
|
|
10
24
|
## [1.4.3] - 2026-06-19
|
|
11
25
|
|
|
12
26
|
### Added
|
|
@@ -135,7 +149,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
135
149
|
- 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`).
|
|
136
150
|
- Imports: use `CliPositional` where needed; replace `CliOptionDef` with `CliOption` or `CliPositional` as appropriate.
|
|
137
151
|
|
|
138
|
-
[Unreleased]: https://github.com/bdombro/bun-argsbarg/compare/v1.
|
|
152
|
+
[Unreleased]: https://github.com/bdombro/bun-argsbarg/compare/v1.5.0...HEAD
|
|
153
|
+
[1.5.0]: https://github.com/bdombro/bun-argsbarg/releases/tag/v1.5.0
|
|
139
154
|
[1.4.3]: https://github.com/bdombro/bun-argsbarg/releases/tag/v1.4.3
|
|
140
155
|
[1.4.2]: https://github.com/bdombro/bun-argsbarg/releases/tag/v1.4.2
|
|
141
156
|
[1.4.1]: https://github.com/bdombro/bun-argsbarg/releases/tag/v1.4.1
|
package/README.md
CHANGED
|
@@ -14,9 +14,9 @@ Why another CLI parser?
|
|
|
14
14
|
|
|
15
15
|
*Beautiful `-h` screens* — scoped help at any routing depth, rendered in rounded UTF-8 boxes with tables, terminal-width wrapping, and color when stdout is a TTY. Errors print in red with contextual help on stderr.
|
|
16
16
|
|
|
17
|
-
*Shell completions* — `completion bash` and `completion
|
|
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
|
|
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).
|
|
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
|
|
|
@@ -95,30 +95,32 @@ Every app gets:
|
|
|
95
95
|
|
|
96
96
|
- `-h` / `--help` at any routing depth (scoped help).
|
|
97
97
|
- **`--schema`** at the program root — print the full command tree as JSON (for tooling and agents).
|
|
98
|
-
- **`completion bash` / `completion zsh`** — print shell completion scripts to stdout (injected by `cliRun`).
|
|
99
|
-
- **`
|
|
98
|
+
- **`completion bash` / `completion zsh` / `completion fish`** — print shell completion scripts to stdout (injected by `cliRun`).
|
|
99
|
+
- **`mcp`** — when `mcpServer` is set on the program root, run as an MCP stdio server (`myapp mcp`).
|
|
100
|
+
- **`install`** — when running as a compiled binary (`bun build --compile`), install the binary, completions, skills, and MCP config to the user environment (`myapp install --all --yes`). See [docs/install.md](docs/install.md).
|
|
100
101
|
|
|
101
|
-
Do not declare a top-level command named **`completion`** —
|
|
102
|
-
|
|
102
|
+
Do not declare a top-level command named **`completion`** or **`install`** — they are reserved.
|
|
103
|
+
When **`mcpServer`** is set, do not declare a top-level command named **`mcp`** — it is reserved for the MCP built-in.
|
|
103
104
|
Do not declare an option named **`schema`** — it is reserved for `--schema`.
|
|
104
105
|
|
|
105
106
|
|
|
106
107
|
### MCP (AI agents)
|
|
107
108
|
|
|
108
|
-
Opt in on the program root with `mcpServer: {}` (or `{ name, version, … }`), then run `myapp
|
|
109
|
+
Opt in on the program root with `mcpServer: {}` (or `{ name, version, … }`), then run `myapp mcp` for a stdio MCP server. Each leaf command becomes a tool; the CLI tree is available as resource `argsbarg://schema`. Handlers can read `ctx.invocation` and use `cliInvoke` for headless testing.
|
|
109
110
|
|
|
110
111
|
See **[docs/mcp.md](docs/mcp.md)** for configuration, env bootstrapping, custom resources, Cursor setup, and protocol details.
|
|
111
112
|
|
|
112
|
-
###
|
|
113
|
+
### Install (compiled binaries)
|
|
113
114
|
|
|
114
|
-
|
|
115
|
+
After `bun build --compile`, ship a self-contained binary and let users run:
|
|
115
116
|
|
|
116
117
|
```bash
|
|
117
|
-
myapp
|
|
118
|
-
myapp ai skill claude --global # ~/.claude/skills/<name>/
|
|
118
|
+
myapp install --all --yes
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
This copies the binary to `~/.local/bin`, installs shell completions (bash/zsh/fish when each shell is on PATH), writes Cursor/Claude skills when agent directories exist, and merges MCP server entries into Cursor and Claude config files.
|
|
122
|
+
|
|
123
|
+
See **[docs/install.md](docs/install.md)** for `--update`, `--status`, `--uninstall`, and flags.
|
|
122
124
|
|
|
123
125
|
|
|
124
126
|
### Shell completions
|
|
@@ -130,6 +132,8 @@ myapp completion bash > ~/.bash_completion.d/myapp
|
|
|
130
132
|
myapp completion zsh > ~/.zsh/completions/_myapp
|
|
131
133
|
# then: fpath+=(~/.zsh/completions); autoload -Uz compinit && compinit
|
|
132
134
|
# or, for a one-off test in the current shell: eval "$(myapp completion zsh)"
|
|
135
|
+
|
|
136
|
+
myapp completion fish > ~/.config/fish/completions/myapp.fish
|
|
133
137
|
```
|
|
134
138
|
|
|
135
139
|
|
|
@@ -218,7 +222,7 @@ The package root (`argsbarg` / `src/index.ts`) exports the types and runtime you
|
|
|
218
222
|
| `cliInvoke(root, argv)` | Parse and dispatch without exiting; returns captured stdout/stderr. |
|
|
219
223
|
| `cliErrWithHelp(ctx, msg)` | Print error + scoped help on stderr, exit 1. |
|
|
220
224
|
|
|
221
|
-
Reserved
|
|
225
|
+
Reserved identifiers (validated at startup): root commands **`completion`**, **`install`**, and **`mcp`** (only when `mcpServer` is set).
|
|
222
226
|
|
|
223
227
|
---
|
|
224
228
|
|
package/docs/ai-skills.md
CHANGED
|
@@ -1,75 +1,47 @@
|
|
|
1
|
-
# Agent skills
|
|
1
|
+
# Agent skills
|
|
2
2
|
|
|
3
|
-
ArgsBarg can
|
|
3
|
+
ArgsBarg can generate Cursor and Claude Code skill directories (`SKILL.md` + `reference.md`) from your CLI schema.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
| --- | --- |
|
|
7
|
-
| `SKILL.md` | Frontmatter + command catalog, execution notes, pitfalls |
|
|
8
|
-
| `reference.md` | Full `--schema` JSON export |
|
|
9
|
-
|
|
10
|
-
Skills are **install-only** — there is no print-to-stdout mode, because the artifact is always a two-file directory.
|
|
5
|
+
## Install via `install` (recommended)
|
|
11
6
|
|
|
12
|
-
|
|
7
|
+
In a **compiled binary**, install skills to the user environment:
|
|
13
8
|
|
|
14
9
|
```bash
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
# User-wide Claude Code skill
|
|
19
|
-
myapp ai skill claude --global
|
|
10
|
+
myapp install --skill --yes
|
|
11
|
+
# or
|
|
12
|
+
myapp install --all --yes
|
|
20
13
|
```
|
|
21
14
|
|
|
22
|
-
|
|
15
|
+
Skills are written when the agent home exists:
|
|
23
16
|
|
|
24
|
-
|
|
17
|
+
- Cursor: `~/.cursor/skills/<dir>/` when `~/.cursor` exists
|
|
18
|
+
- Claude Code: `~/.claude/skills/<dir>/` when `~/.claude` exists
|
|
25
19
|
|
|
26
|
-
|
|
20
|
+
The skill directory name defaults to the sanitized program `key` (e.g. `minimal.ts` → `minimal_ts`).
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
const cli: CliCommand = {
|
|
30
|
-
key: "myapp",
|
|
31
|
-
description: "My app.",
|
|
32
|
-
aiSkill: { enabled: false },
|
|
33
|
-
commands: [/* ... */],
|
|
34
|
-
};
|
|
35
|
-
```
|
|
22
|
+
Existing skill directories are removed and rewritten on each install.
|
|
36
23
|
|
|
37
|
-
|
|
24
|
+
## Programmatic install
|
|
38
25
|
|
|
39
26
|
```typescript
|
|
40
|
-
|
|
27
|
+
import { cliSkillInstall } from "argsbarg/skill/install"; // internal module
|
|
41
28
|
```
|
|
42
29
|
|
|
43
|
-
|
|
30
|
+
For library use, call `cliSkillInstall(root, "cursor" | "claude", { global: true, rimraf: true })` — it returns changed file paths.
|
|
44
31
|
|
|
45
|
-
|
|
32
|
+
## Generated content
|
|
46
33
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
| `--global` | Install under the user skills directory instead of the project |
|
|
50
|
-
| `--force` | Overwrite an existing skill directory |
|
|
51
|
-
|
|
52
|
-
## Install locations
|
|
53
|
-
|
|
54
|
-
| Target | Project (default) | `--global` |
|
|
55
|
-
| --- | --- | --- |
|
|
56
|
-
| Cursor | `.cursor/skills/<name>/` | `~/.cursor/skills/<name>/` |
|
|
57
|
-
| Claude Code | `.claude/skills/<name>/` | `~/.claude/skills/<name>/` |
|
|
58
|
-
|
|
59
|
-
`<name>` defaults to the sanitized program root `key` (same rules as MCP tool name segments).
|
|
60
|
-
|
|
61
|
-
Do **not** install under `~/.cursor/skills-cursor/` — that path is reserved for Cursor built-ins.
|
|
34
|
+
- **`SKILL.md`** — YAML frontmatter, when-to-use guidance, command catalog, MCP setup hints
|
|
35
|
+
- **`reference.md`** — full `--schema` JSON export
|
|
62
36
|
|
|
63
37
|
## MCP vs skills
|
|
64
38
|
|
|
65
|
-
| Mechanism |
|
|
39
|
+
| Mechanism | Role |
|
|
66
40
|
| --- | --- |
|
|
67
|
-
| **`myapp
|
|
68
|
-
| **`myapp
|
|
69
|
-
|
|
70
|
-
Generated `SKILL.md` recommends MCP when `mcpServer` is configured, and documents shell invocation as a fallback.
|
|
41
|
+
| **`myapp mcp`** (requires `mcpServer`) | Runtime tool execution over MCP |
|
|
42
|
+
| **`myapp install --skill`** | Static discovery files for agents |
|
|
71
43
|
|
|
72
|
-
|
|
44
|
+
See also:
|
|
73
45
|
|
|
74
|
-
- [MCP server](mcp.md) — `mcpServer` config and `
|
|
75
|
-
- [
|
|
46
|
+
- [MCP server](mcp.md) — `mcpServer` config and `mcp` protocol
|
|
47
|
+
- [Install](install.md) — binary, completions, skills, and MCP config
|
package/docs/install.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Install command
|
|
2
|
+
|
|
3
|
+
The `install` built-in is available only in **compiled binaries** (`bun build --compile`). It is hidden from help, `--schema`, and shell completions when running via `bun run`.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# First-time setup
|
|
9
|
+
myapp install --all --yes
|
|
10
|
+
|
|
11
|
+
# Refresh after upgrading
|
|
12
|
+
myapp install --update
|
|
13
|
+
|
|
14
|
+
# See what is installed
|
|
15
|
+
myapp install --status
|
|
16
|
+
|
|
17
|
+
# Remove everything detected
|
|
18
|
+
myapp install --uninstall --yes
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## What gets installed
|
|
22
|
+
|
|
23
|
+
| Target | Flag | Destination |
|
|
24
|
+
| --- | --- | --- |
|
|
25
|
+
| Binary | `--bin` | `~/.local/bin/<key>` (or `--prefix`) |
|
|
26
|
+
| Bash completion | `--completions` | `~/.bash_completion.d/<key>` + `.bashrc` PATH snippet |
|
|
27
|
+
| Zsh completion | `--completions` | `~/.zsh/completions/_<key>` + `.zshrc` fpath snippet |
|
|
28
|
+
| Fish completion | `--completions` | `~/.config/fish/completions/<key>.fish` |
|
|
29
|
+
| Cursor skill | `--skill` | `~/.cursor/skills/<dir>/` when `~/.cursor` exists |
|
|
30
|
+
| Claude skill | `--skill` | `~/.claude/skills/<dir>/` when `~/.claude` exists |
|
|
31
|
+
| MCP config | `--mcp` | `~/.cursor/mcp.json` and `~/.claude.json` when MCP is enabled |
|
|
32
|
+
|
|
33
|
+
`--all` expands to `--bin`, `--completions`, `--skill`, and `--mcp` (when `mcpServer` is set).
|
|
34
|
+
|
|
35
|
+
Shells not on PATH are skipped silently (no warnings).
|
|
36
|
+
|
|
37
|
+
## Configuration
|
|
38
|
+
|
|
39
|
+
On the program root:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
install: {
|
|
43
|
+
enabled: false, // opt out of the install built-in
|
|
44
|
+
prefix: "~/.local/bin", // default bin directory
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Environment:
|
|
49
|
+
|
|
50
|
+
- `INSTALL_PREFIX` — same as `install.prefix` / `--prefix`
|
|
51
|
+
|
|
52
|
+
## Flags
|
|
53
|
+
|
|
54
|
+
| Flag | Description |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| `--yes` | Skip confirmation (required for non-TTY unless `--json` / `--update`) |
|
|
57
|
+
| `--dry` | Preview changes; per-step messages on stderr with `[dry run]` |
|
|
58
|
+
| `--json` | Machine-readable output on stdout (implies `--yes`) |
|
|
59
|
+
| `--quiet` | Suppress summaries and per-step messages (requires `--yes`) |
|
|
60
|
+
| `--prefix <dir>` | Override binary install directory |
|
|
61
|
+
| `--update` | Update only artifacts already installed (implies `--bin` + `--yes`) |
|
|
62
|
+
| `--status` | Read-only inventory |
|
|
63
|
+
| `--uninstall` | Remove detected artifacts (scope with `--bin`, `--completions`, `--skill`, `--mcp`) |
|
|
64
|
+
|
|
65
|
+
## MCP merge behavior
|
|
66
|
+
|
|
67
|
+
When `--mcp` runs, entries are merged into `mcpServers[<name>]` with:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{ "command": "<root.key>", "args": ["mcp"] }
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
If an existing entry differs, the command exits with an error unless `--yes` is passed (then it overwrites).
|
|
74
|
+
|
|
75
|
+
## Opt out
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const cli: CliCommand = {
|
|
79
|
+
key: "myapp",
|
|
80
|
+
description: "...",
|
|
81
|
+
install: { enabled: false },
|
|
82
|
+
// ...
|
|
83
|
+
};
|
|
84
|
+
```
|
package/docs/mcp.md
CHANGED
|
@@ -22,7 +22,7 @@ const cli: CliCommand = {
|
|
|
22
22
|
2. Run the MCP server:
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
myapp
|
|
25
|
+
myapp mcp
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
The process reads NDJSON requests from stdin and writes NDJSON responses to stdout. It stays alive until stdin closes.
|
|
@@ -34,7 +34,7 @@ Optionally install an agent skill for discovery without MCP: see [docs/ai-skills
|
|
|
34
34
|
The `examples/nested.ts` demo enables MCP — try:
|
|
35
35
|
|
|
36
36
|
```bash
|
|
37
|
-
bun run examples/nested.ts
|
|
37
|
+
bun run examples/nested.ts mcp
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## Client setup
|
|
@@ -58,7 +58,7 @@ Use your real binary or script path. For a compiled CLI, `command` can be the in
|
|
|
58
58
|
|
|
59
59
|
### Other MCP hosts
|
|
60
60
|
|
|
61
|
-
Any host that spawns a subprocess and wires stdin/stdout works the same way: the **command** is your app, and **`
|
|
61
|
+
Any host that spawns a subprocess and wires stdin/stdout works the same way: the **command** is your app, and **`mcp`** starts the server.
|
|
62
62
|
|
|
63
63
|
## Configuration
|
|
64
64
|
|
|
@@ -277,7 +277,7 @@ Requests without an `id` are treated as notifications and do not receive a respo
|
|
|
277
277
|
### Manual smoke test
|
|
278
278
|
|
|
279
279
|
```bash
|
|
280
|
-
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' | bun run examples/nested.ts
|
|
280
|
+
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' | bun run examples/nested.ts mcp
|
|
281
281
|
```
|
|
282
282
|
|
|
283
283
|
You should get one JSON line on stdout with `result.capabilities` and `result.serverInfo`.
|
|
@@ -290,7 +290,7 @@ When MCP is enabled:
|
|
|
290
290
|
- Do not declare a top-level command named **`completion`** — reserved for shell completions.
|
|
291
291
|
- Do not declare an option named **`schema`** — reserved for `--schema`.
|
|
292
292
|
|
|
293
|
-
Running `myapp
|
|
293
|
+
Running `myapp mcp` without `mcpServer` on the root fails with an error (exit 1).
|
|
294
294
|
|
|
295
295
|
## Design notes
|
|
296
296
|
|
package/index.d.ts
CHANGED
|
@@ -105,7 +105,7 @@ export interface CliPositional {
|
|
|
105
105
|
argMax?: number;
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
|
-
* Root-only. Enables `myapp
|
|
108
|
+
* Root-only. Enables `myapp mcp` and MCP stdio server metadata.
|
|
109
109
|
*/
|
|
110
110
|
export interface CliMcpServerConfig {
|
|
111
111
|
/** `initialize` serverInfo.name (default: root `key`). */
|
|
@@ -166,13 +166,13 @@ export interface CliMcpToolConfig {
|
|
|
166
166
|
requiresEnv?: string[];
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
169
|
-
* Root-only. Opt
|
|
169
|
+
* Root-only. Opt-out and defaults for the `install` built-in (compiled binaries only).
|
|
170
170
|
*/
|
|
171
|
-
export interface
|
|
172
|
-
/** When `false`, disable `
|
|
171
|
+
export interface CliInstallConfig {
|
|
172
|
+
/** When `false`, hide/disable `install` (default: enabled). */
|
|
173
173
|
enabled?: boolean;
|
|
174
|
-
/**
|
|
175
|
-
|
|
174
|
+
/** Default bin directory (default: `~/.local/bin`). Overridden by `INSTALL_PREFIX` env and `--prefix`. */
|
|
175
|
+
prefix?: string;
|
|
176
176
|
}
|
|
177
177
|
/**
|
|
178
178
|
* Base properties shared by all command nodes.
|
|
@@ -186,10 +186,10 @@ export interface CliCommandBase {
|
|
|
186
186
|
notes?: string;
|
|
187
187
|
/** Global or command-level flags/options. */
|
|
188
188
|
options?: CliOption[];
|
|
189
|
-
/** Root-only. When set, enables the `
|
|
189
|
+
/** Root-only. When set, enables the `mcp` built-in subcommand. */
|
|
190
190
|
mcpServer?: CliMcpServerConfig;
|
|
191
|
-
/** Root-only. Opt
|
|
192
|
-
|
|
191
|
+
/** Root-only. Opt-out and defaults for `install` (compiled binaries only). */
|
|
192
|
+
install?: CliInstallConfig;
|
|
193
193
|
/** Leaf-only. Per-tool MCP exposure and metadata. */
|
|
194
194
|
mcpTool?: CliMcpToolConfig;
|
|
195
195
|
}
|
|
@@ -254,16 +254,7 @@ export interface CliInvokeResult {
|
|
|
254
254
|
* Never calls process.exit.
|
|
255
255
|
*/
|
|
256
256
|
export declare function cliInvoke(root: CliCommand, argv: string[]): Promise<CliInvokeResult>;
|
|
257
|
-
/**
|
|
258
|
-
* Validates the schema, parses argv, prints help or errors, runs completion or the leaf handler, then exits.
|
|
259
|
-
*
|
|
260
|
-
* @param root The root CliCommand.
|
|
261
|
-
* @param argv Override the default argv (process.argv.slice(2)).
|
|
262
|
-
*/
|
|
263
257
|
export declare function cliRun(root: CliCommand, argv?: string[]): Promise<never>;
|
|
264
|
-
/**
|
|
265
|
-
* Prints a red error line and contextual help on stderr, then exits with status 1.
|
|
266
|
-
*/
|
|
267
258
|
export declare function cliErrWithHelp(ctx: CliContext, msg: string): never;
|
|
268
259
|
/** True when stdin is a TTY. */
|
|
269
260
|
export declare const isInteractiveTty: boolean;
|
package/package.json
CHANGED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { describe, expect, test, afterEach } from "bun:test";
|
|
2
|
+
import { cliBuiltinInstallCommand, installBuiltinOptions } from "./install.ts";
|
|
3
|
+
import { cliBuiltinMcpCommand } from "./mcp.ts";
|
|
4
|
+
import { cliPresentationRoot } from "./presentation.ts";
|
|
5
|
+
import { completionBashScript, completionFishScript, completionZshScript } from "./index.ts";
|
|
6
|
+
import { exportPresentationBuiltins } from "./export.ts";
|
|
7
|
+
import { CliCommand } from "../types.ts";
|
|
8
|
+
import { setCompiledExecutableOverride } from "../install/compiled.ts";
|
|
9
|
+
|
|
10
|
+
const fixture: CliCommand = {
|
|
11
|
+
key: "myapp",
|
|
12
|
+
description: "Demo app.",
|
|
13
|
+
mcpServer: { name: "myapp" },
|
|
14
|
+
commands: [
|
|
15
|
+
{
|
|
16
|
+
key: "hello",
|
|
17
|
+
description: "Say hello.",
|
|
18
|
+
handler: () => {},
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
setCompiledExecutableOverride(null);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe("builtins help copy", () => {
|
|
28
|
+
test("install command includes description and option text when compiled", () => {
|
|
29
|
+
setCompiledExecutableOverride(true);
|
|
30
|
+
const install = cliBuiltinInstallCommand(fixture);
|
|
31
|
+
expect(install.description).toContain("Install the binary");
|
|
32
|
+
expect(install.notes).toContain("bun build --compile");
|
|
33
|
+
const names = installBuiltinOptions(fixture).map((o) => o.name);
|
|
34
|
+
expect(names).toContain("all");
|
|
35
|
+
expect(names).toContain("mcp");
|
|
36
|
+
expect(names).toContain("prefix");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("install omits --mcp option when mcpServer unset", () => {
|
|
40
|
+
setCompiledExecutableOverride(true);
|
|
41
|
+
const noMcp: CliCommand = { key: "x", description: "x", handler: () => {} };
|
|
42
|
+
const names = installBuiltinOptions(noMcp).map((o) => o.name);
|
|
43
|
+
expect(names).not.toContain("mcp");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("mcp builtin description is user-facing", () => {
|
|
47
|
+
const mcp = cliBuiltinMcpCommand();
|
|
48
|
+
expect(mcp.description).toContain("MCP server");
|
|
49
|
+
expect(mcp.notes).toContain('["mcp"]');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe("presentation root", () => {
|
|
54
|
+
test("includes mcp when mcpServer set", () => {
|
|
55
|
+
setCompiledExecutableOverride(false);
|
|
56
|
+
const root = cliPresentationRoot(fixture);
|
|
57
|
+
expect(root.commands?.map((c) => c.key)).toContain("mcp");
|
|
58
|
+
expect(root.commands?.map((c) => c.key)).not.toContain("install");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("includes install when compiled", () => {
|
|
62
|
+
setCompiledExecutableOverride(true);
|
|
63
|
+
const root = cliPresentationRoot(fixture);
|
|
64
|
+
expect(root.commands?.map((c) => c.key)).toContain("install");
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("completion emitters", () => {
|
|
69
|
+
test("fish script references app key and subcommands", () => {
|
|
70
|
+
setCompiledExecutableOverride(true);
|
|
71
|
+
const schema = cliPresentationRoot(fixture);
|
|
72
|
+
const fish = completionFishScript(schema);
|
|
73
|
+
expect(fish).toContain("complete -c myapp");
|
|
74
|
+
expect(fish).toContain("hello");
|
|
75
|
+
expect(fish).toContain("install");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("bash script includes install flags when compiled", () => {
|
|
79
|
+
setCompiledExecutableOverride(true);
|
|
80
|
+
const schema = cliPresentationRoot(fixture);
|
|
81
|
+
const bash = completionBashScript(schema);
|
|
82
|
+
expect(bash).toContain("--all");
|
|
83
|
+
expect(bash).toContain("install");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("zsh script registers compdef", () => {
|
|
87
|
+
const schema = cliPresentationRoot({ key: "zapp", description: "z", handler: () => {} });
|
|
88
|
+
const zsh = completionZshScript(schema);
|
|
89
|
+
expect(zsh).toContain("#compdef zapp");
|
|
90
|
+
expect(zsh).toContain("compdef _zapp zapp");
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("schema export builtins", () => {
|
|
95
|
+
test("exportPresentationBuiltins includes install options when compiled", () => {
|
|
96
|
+
setCompiledExecutableOverride(true);
|
|
97
|
+
const builtins = exportPresentationBuiltins(fixture);
|
|
98
|
+
const install = builtins.find((b) => b.key === "install");
|
|
99
|
+
expect(install?.options?.find((o) => o.name === "all")?.description).toContain("binary");
|
|
100
|
+
});
|
|
101
|
+
});
|