argsbarg 3.3.0 → 3.3.1
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 -5
- package/README.md +1 -1
- package/docs/ai-skills.md +2 -0
- package/docs/cli-program.md +194 -0
- package/docs/mcp.md +7 -3
- package/docs/templates/cursor/rules/cli-program.mdc +29 -0
- package/index.d.ts +0 -2
- package/package.json +1 -1
- package/src/headless.test.ts +0 -6
- package/src/headless.ts +0 -5
- package/src/index.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,14 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
## [3.3.
|
|
10
|
+
## [3.3.1] - 2026-06-21
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **`docs/cli-program.md`** — authoring guide for `CliProgram` and leaves (MCP-free defaults); **headless-capable handlers** and **inline schema by default**.
|
|
15
|
+
- **`docs/templates/cursor/rules/cli-program.mdc`** — concise copy-paste Cursor rule for consumer apps.
|
|
11
16
|
|
|
17
|
+
### Removed
|
|
18
|
+
|
|
19
|
+
- **`mcpToolSchemaHints`** — redundant with MCP `inputSchema` option descriptions.
|
|
20
|
+
- **`wantsDryRun`** — use `ctx.hasFlag("dry-run")` instead.
|
|
12
21
|
|
|
13
|
-
## [3.3.0] - 2026-06-
|
|
22
|
+
## [3.3.0] - 2026-06-21
|
|
14
23
|
|
|
15
24
|
### Added
|
|
16
25
|
|
|
17
|
-
- **Headless helpers** — `shouldRunHeadless`, `shouldRunHeadlessWithPositionals`, `shouldRunHeadlessWithYes`, `
|
|
26
|
+
- **Headless helpers** — `shouldRunHeadless`, `shouldRunHeadlessWithPositionals`, `shouldRunHeadlessWithYes`, `wantsExplicitJson`, `requireYesInNonTty`, `formatDryRunMessage` for Ink/MCP CLIs.
|
|
18
27
|
- **`ghReleaseUpdateGetLatest`** — optional `install.updateGetLatest` factory for GitHub releases via `gh`.
|
|
19
28
|
- **`createGhVersionCheck`** — version-check cache, update notices, and background refresh helpers.
|
|
20
29
|
|
|
@@ -234,8 +243,8 @@ const cli = { ... } satisfies CliProgram; // or : CliProgram
|
|
|
234
243
|
- 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`).
|
|
235
244
|
- Imports: use `CliPositional` where needed; replace `CliOptionDef` with `CliOption` or `CliPositional` as appropriate.
|
|
236
245
|
|
|
237
|
-
[Unreleased]: https://github.com/bdombro/bun-argsbarg/compare/v3.3.
|
|
238
|
-
[3.3.
|
|
246
|
+
[Unreleased]: https://github.com/bdombro/bun-argsbarg/compare/v3.3.1...HEAD
|
|
247
|
+
[3.3.1]: https://github.com/bdombro/bun-argsbarg/releases/tag/v3.3.1
|
|
239
248
|
[3.3.0]: https://github.com/bdombro/bun-argsbarg/releases/tag/v3.3.0
|
|
240
249
|
[3.2.0]: https://github.com/bdombro/bun-argsbarg/releases/tag/v3.2.0
|
|
241
250
|
[3.1.0]: https://github.com/bdombro/bun-argsbarg/releases/tag/v3.1.0
|
package/README.md
CHANGED
|
@@ -110,7 +110,7 @@ When **`docs.enabled`** is `true`, do not declare a top-level command named **`d
|
|
|
110
110
|
|
|
111
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 docs schema`). Handlers can read `ctx.invocation` and use `cliInvoke` for headless testing.
|
|
112
112
|
|
|
113
|
-
See **[docs/mcp.md](docs/mcp.md)** for configuration, env bootstrapping, custom resources, Cursor setup, and protocol details.
|
|
113
|
+
See **[docs/mcp.md](docs/mcp.md)** for configuration, env bootstrapping, custom resources, Cursor setup, and protocol details. See **[docs/cli-program.md](docs/cli-program.md)** for schema authoring (consumer apps: copy **`docs/templates/cursor/rules/cli-program.mdc`** to **`.cursor/rules/cli-program.mdc`**).
|
|
114
114
|
|
|
115
115
|
### Install
|
|
116
116
|
|
package/docs/ai-skills.md
CHANGED
|
@@ -44,6 +44,8 @@ Skills describe **shell invocation only** — no MCP setup, `mcp.json`, or `tool
|
|
|
44
44
|
| **`myapp install --skill`** | Static shell command catalog for agents |
|
|
45
45
|
| **`myapp docs`** (requires `docs`) | Bundled markdown on stdout (`docs mcp` when MCP enabled) |
|
|
46
46
|
|
|
47
|
+
Command catalog lines reuse MCP tool descriptions. See [cli-program.md](cli-program.md).
|
|
48
|
+
|
|
47
49
|
See also:
|
|
48
50
|
|
|
49
51
|
- [Bundled docs](bundled-docs.md) — `docs` config and compile-time imports
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# Writing `CliProgram` and leaf commands
|
|
2
|
+
|
|
3
|
+
ArgsBarg turns your schema into help, shell completions, MCP tools, and agent skills. **The same `description` fields you write for humans are the agent contract** for basic apps.
|
|
4
|
+
|
|
5
|
+
## Minimal app (MCP is free)
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
const cli = {
|
|
9
|
+
key: "myapp",
|
|
10
|
+
version: "1.0.0",
|
|
11
|
+
description: "One-line summary of what the CLI does.",
|
|
12
|
+
mcpServer: { enabled: true },
|
|
13
|
+
commands: [
|
|
14
|
+
{
|
|
15
|
+
key: "greet",
|
|
16
|
+
description: "Greet someone by name.",
|
|
17
|
+
positionals: [
|
|
18
|
+
{ name: "name", description: "Who to greet.", kind: CliOptionKind.String },
|
|
19
|
+
],
|
|
20
|
+
handler: async (ctx) => { /* ... */ },
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
} satisfies CliProgram;
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
No `mcpTool` blocks required. Every leaf becomes an MCP tool; `inputSchema` comes from options and positionals.
|
|
27
|
+
|
|
28
|
+
## Inline schema by default
|
|
29
|
+
|
|
30
|
+
ArgsBarg is **schema-first** — the program tree is the product. **Keep `CliProgram` and leaf fields inline** (`key`, `description`, `options`, `positionals`, `handler`) so a reader sees the full command contract in one place.
|
|
31
|
+
|
|
32
|
+
**Inline by default:**
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
{
|
|
36
|
+
key: "reserve",
|
|
37
|
+
description: "Reserve a QA environment.",
|
|
38
|
+
options: [
|
|
39
|
+
{ name: "yes", description: "Skip confirmation; use for non-interactive runs.", kind: CliOptionKind.Presence },
|
|
40
|
+
{ name: "dry-run", description: "Preview without mutating.", kind: CliOptionKind.Presence },
|
|
41
|
+
],
|
|
42
|
+
positionals: [
|
|
43
|
+
{ name: "env", description: "Environment name.", kind: CliOptionKind.String, argMin: 0, argMax: 1 },
|
|
44
|
+
],
|
|
45
|
+
handler: async (ctx) => { /* … */ },
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Extract only when well justified:**
|
|
50
|
+
|
|
51
|
+
| Extract | When |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| Shared option objects (`DRY_RUN_OPTION`, `JSON_OPTION`) | Identical flag reused on many leaves |
|
|
54
|
+
| Shared spreads (`...MCP_TOOL_MUTATOR`) | Same `mcpTool` metadata on a family of commands |
|
|
55
|
+
| `somethingCommand()` factory | Entry file is large; handler/body is substantial (Ink page, headless dispatch) |
|
|
56
|
+
| `docs.topics` text imports | Compile-time markdown bundling — not schema shape |
|
|
57
|
+
|
|
58
|
+
**Avoid extracting** thin indirection: a file that only re-exports `{ key, description, options }` with no logic, or splitting every leaf into its own module when the handler is a few lines. If extraction does not reduce duplication or file size materially, keep it inline.
|
|
59
|
+
|
|
60
|
+
**`satisfies CliProgram`** on the root (or on extracted command factories) preserves type-checking whether inline or not.
|
|
61
|
+
|
|
62
|
+
## Descriptions
|
|
63
|
+
|
|
64
|
+
Write for **what the command does**, not how the UI works:
|
|
65
|
+
|
|
66
|
+
- **Good:** `Reserve a QA environment.`
|
|
67
|
+
- **Weak:** `Opens the reservation wizard.`
|
|
68
|
+
|
|
69
|
+
Option and positional `description` strings appear in `-h`, MCP `inputSchema`, and generated skills — keep them concrete (`Environment name (e.g. qa2).`).
|
|
70
|
+
|
|
71
|
+
Use root **`notes`** for cross-cutting hints shown in help (install commands, docs topics, VPN requirements).
|
|
72
|
+
|
|
73
|
+
## Well-known option names
|
|
74
|
+
|
|
75
|
+
Prefer **`yes`**, **`dry-run`**, and **`json`** when semantics match. They appear in `-h`, MCP `inputSchema`, and generated skills — write clear option `description` strings (e.g. "Skip confirmation; use for non-interactive runs.").
|
|
76
|
+
|
|
77
|
+
## When to use `mcpTool` (escape hatches only)
|
|
78
|
+
|
|
79
|
+
**Omit `mcpTool` unless you have a specific reason.**
|
|
80
|
+
|
|
81
|
+
### Fix the CLI first
|
|
82
|
+
|
|
83
|
+
Many "MCP problems" are schema or handler gaps. Prefer these over escape hatches:
|
|
84
|
+
|
|
85
|
+
| Problem | Fix (not `mcpTool`) |
|
|
86
|
+
| --- | --- |
|
|
87
|
+
| Agents don't know which flags to pass | Use standard option names (`yes`, `dry-run`, `json`); improve option `description` strings |
|
|
88
|
+
| MCP calls hang on prompts | Add `--yes` and a headless code path; use `shouldRunHeadlessWithYes` |
|
|
89
|
+
| Help text describes Ink UI | Rewrite leaf `description` as the action ("Reserve an environment.") |
|
|
90
|
+
| MCP needs different args than humans | Expose the same flags; resolve defaults in the handler for both `cli` and `mcp` |
|
|
91
|
+
| Command "doesn't work" over MCP | Branch on `ctx.invocation === "mcp"` in the handler (stdio is the wire) |
|
|
92
|
+
|
|
93
|
+
### When escape hatches are appropriate
|
|
94
|
+
|
|
95
|
+
| Field | Use when |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| `enabled: false` | Command is **genuinely** CLI-only (open browser, Ink-only flow with no scriptable equivalent) |
|
|
98
|
+
| `requiresEnv: [...]` | Runtime secrets; appended to MCP description and enforced at `tools/call` |
|
|
99
|
+
| `description: "..."` | **Irreducible** MCP limitation (e.g. live tail / `--watch` cannot be streamed on the MCP wire yet) |
|
|
100
|
+
|
|
101
|
+
Do **not** use `mcpTool.description` to paper over missing `--yes`, non-standard flag names, or handlers that only work interactively — fix those instead.
|
|
102
|
+
|
|
103
|
+
If help text and MCP behavior match after your fixes, **omit `mcpTool` entirely**.
|
|
104
|
+
|
|
105
|
+
## Headless-capable handlers
|
|
106
|
+
|
|
107
|
+
Simple leaves (read args, print stdout) are already headless — no extra work. **Any handler that might mount Ink, prompt, or open a browser should also implement a scriptable fast path** for:
|
|
108
|
+
|
|
109
|
+
- **MCP** (`ctx.invocation === "mcp"` — always non-interactive)
|
|
110
|
+
- **Non-TTY CLI** (pipes, CI, `myapp cmd --yes` in a script)
|
|
111
|
+
- **Explicit flags** (`--json`, `--dry-run`)
|
|
112
|
+
|
|
113
|
+
Use **one headless implementation** for all three; do not fork separate "MCP handlers."
|
|
114
|
+
|
|
115
|
+
### When to branch
|
|
116
|
+
|
|
117
|
+
| Command kind | Headless trigger | Helpers |
|
|
118
|
+
| --- | --- | --- |
|
|
119
|
+
| Read / query | MCP, `--json`, or non-TTY | `shouldRunHeadless`, `wantsExplicitJson` |
|
|
120
|
+
| Mutate | MCP with args + `yes`/`dry-run`, or non-TTY with `--yes` | `shouldRunHeadlessWithYes`, `requireYesInNonTty` |
|
|
121
|
+
| Mutate with positionals | Same, but avoid auto-headless on empty argv | `shouldRunHeadlessWithPositionals` |
|
|
122
|
+
|
|
123
|
+
### Recommended handler shape
|
|
124
|
+
|
|
125
|
+
**Mutating command** (wizard optional, script path required):
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import {
|
|
129
|
+
requireYesInNonTty,
|
|
130
|
+
shouldRunHeadlessWithYes,
|
|
131
|
+
} from "argsbarg";
|
|
132
|
+
|
|
133
|
+
handler: async (ctx) => {
|
|
134
|
+
const dryRun = ctx.hasFlag("dry-run");
|
|
135
|
+
const yes = ctx.hasFlag("yes");
|
|
136
|
+
const env = ctx.args[0];
|
|
137
|
+
|
|
138
|
+
requireYesInNonTty(yes, "Example: myapp reserve qa2 --yes", dryRun);
|
|
139
|
+
|
|
140
|
+
if (shouldRunHeadlessWithYes(ctx, { yes, hasRequiredArgs: !!env, dryRun })) {
|
|
141
|
+
const result = await executeReserve({ dryRun, env, yes });
|
|
142
|
+
process.stdout.write(`${result.message}\n`);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
await renderInteractiveWizard({ env, yes, dryRun });
|
|
147
|
+
};
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Read / query command** (optional `--json`):
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import { shouldRunHeadless, wantsExplicitJson } from "argsbarg";
|
|
154
|
+
|
|
155
|
+
handler: async (ctx) => {
|
|
156
|
+
const json = ctx.hasFlag("json");
|
|
157
|
+
|
|
158
|
+
if (shouldRunHeadless(ctx, json)) {
|
|
159
|
+
const data = await fetchStatus(ctx.args[0]);
|
|
160
|
+
if (wantsExplicitJson(ctx, json)) {
|
|
161
|
+
process.stdout.write(`${JSON.stringify(data, null, 2)}\n`);
|
|
162
|
+
} else {
|
|
163
|
+
process.stdout.write(formatStatusHuman(data));
|
|
164
|
+
}
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
await renderPage(<StatusPage env={ctx.args[0]} />);
|
|
169
|
+
};
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Rules of thumb
|
|
173
|
+
|
|
174
|
+
1. **Resolvable from flags** — if a human can complete the action with flags, an agent can too (`--env qa2 --yes`). Wizards are optional sugar on TTY.
|
|
175
|
+
2. **`--yes` on mutators** — required for non-TTY CLI scripts; MCP should pass `yes: true` in tool arguments when the schema exposes `yes`.
|
|
176
|
+
3. **Stdout is the contract** — headless paths write results to stdout (or JSON with `--json`); stderr for errors. No Ink on the MCP wire.
|
|
177
|
+
4. **`ctx.invocation === "mcp"`** — use only for wire-specific behavior (pipe child stdout, reject `--watch`, etc.), not to duplicate business logic.
|
|
178
|
+
5. **Hide only when impossible** — `mcpTool.enabled: false` after confirming no headless path exists (browser-only, irreducible streaming).
|
|
179
|
+
|
|
180
|
+
Basic synchronous handlers do not need this structure — only commands with an interactive branch.
|
|
181
|
+
|
|
182
|
+
## Reserved names
|
|
183
|
+
|
|
184
|
+
Do not declare user commands named `completion`, `install`, `mcp`, `version`, `docs`, or `update` at the root — ArgsBarg injects these when configured.
|
|
185
|
+
|
|
186
|
+
## Cursor rule for consumer repos
|
|
187
|
+
|
|
188
|
+
Copy `node_modules/argsbarg/docs/templates/cursor/rules/cli-program.mdc` to `.cursor/rules/cli-program.mdc` so agents editing your CLI schema follow these conventions.
|
|
189
|
+
|
|
190
|
+
## See also
|
|
191
|
+
|
|
192
|
+
- [MCP server](mcp.md) — tools, schema resource, env bootstrapping
|
|
193
|
+
- [Agent skills](ai-skills.md) — `install --skill`
|
|
194
|
+
- [Bundled docs](bundled-docs.md) — `docs` topics and `docs mcp`
|
package/docs/mcp.md
CHANGED
|
@@ -103,9 +103,9 @@ Tool names are derived from the command path, with each segment sanitized (non-a
|
|
|
103
103
|
|
|
104
104
|
### Tool descriptions
|
|
105
105
|
|
|
106
|
-
Each tool’s `description` includes the human CLI path and the leaf’s help text, separated by an em dash:
|
|
106
|
+
Each tool’s `description` includes the human CLI path and the leaf’s help text, separated by an em dash. Tool arguments are defined in `inputSchema` (options and positionals with their descriptions). `mcpTool.requiresEnv` is appended as `[requires env: …]`.
|
|
107
107
|
|
|
108
|
-
| CLI path | MCP `description` |
|
|
108
|
+
| CLI path | MCP `description` (example) |
|
|
109
109
|
| --- | --- |
|
|
110
110
|
| `stat owner lookup` | `stat owner lookup — Resolve owner info.` |
|
|
111
111
|
| `read` | `read — Print the first line of each file.` |
|
|
@@ -126,6 +126,8 @@ Set `mcpTool: { enabled: false }` on a **leaf command** to hide it from `tools/l
|
|
|
126
126
|
|
|
127
127
|
Omitted or `enabled: true` exposes the command (default). `mcpTool` is only valid on leaves — not on the program root or routing groups.
|
|
128
128
|
|
|
129
|
+
**Prefer fixing schema and handlers over `mcpTool` overrides** — standard option names (`yes`, `dry-run`, `json`), headless paths, and clear descriptions usually make MCP work without per-leaf config. See [cli-program.md](cli-program.md).
|
|
130
|
+
|
|
129
131
|
### Per-leaf tool metadata
|
|
130
132
|
|
|
131
133
|
```typescript
|
|
@@ -207,7 +209,9 @@ URIs must be unique and must not equal `schemaResourceUri`. `load()` runs synchr
|
|
|
207
209
|
|
|
208
210
|
Handlers receive `ctx.invocation`: `"cli"` for normal `cliRun` dispatch, `"mcp"` for MCP `tools/call`.
|
|
209
211
|
|
|
210
|
-
|
|
212
|
+
MCP is always non-interactive. Commands that can mount Ink or prompts should implement a **headless fast path** (same path as non-TTY CLI with `--yes` / `--json`) — see [cli-program.md — Headless-capable handlers](cli-program.md#headless-capable-handlers).
|
|
213
|
+
|
|
214
|
+
Use `ctx.invocation` to branch subprocess behavior — MCP stdout is the JSON-RPC wire, so child processes must not inherit it:
|
|
211
215
|
|
|
212
216
|
```typescript
|
|
213
217
|
handler: async (ctx) => {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Argsbarg CliProgram authoring; copy to .cursor/rules/cli-program.mdc
|
|
3
|
+
globs: "**/*.{ts,tsx}"
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
**argsbarg** — `CliProgram` drives help, MCP, and skills. Full guide: `node_modules/argsbarg/docs/cli-program.md`.
|
|
8
|
+
|
|
9
|
+
## Defaults
|
|
10
|
+
- `mcpServer: { enabled: true }` for MCP; **omit `mcpTool`** unless an escape hatch is required
|
|
11
|
+
- `description` on root, commands, options, and positionals (→ `-h`, MCP `inputSchema`, skills)
|
|
12
|
+
- `satisfies CliProgram`; root: `key`, `version`, `description`
|
|
13
|
+
- Reserved root commands (do not declare): `completion`, `install`, `mcp`, `version`, `docs`, `update`
|
|
14
|
+
|
|
15
|
+
## Schema
|
|
16
|
+
- **Inline** options, positionals, and handler schema; extract only for shared flags, `mcpTool` spreads, or large handlers (Ink/dispatch)
|
|
17
|
+
- Leaf descriptions: action-oriented, not UI jargon
|
|
18
|
+
- Prefer option names `yes`, `dry-run`, `json` when semantics match; describe non-interactive use on the option
|
|
19
|
+
|
|
20
|
+
## `mcpTool` (rare)
|
|
21
|
+
Fix schema/handler first — not for missing `--yes`, wrong flag names, or unfinished headless paths.
|
|
22
|
+
Only: `enabled: false` (CLI-only), `requiresEnv`, or irreducible limits (e.g. streaming `--watch`). Comment why if used.
|
|
23
|
+
|
|
24
|
+
## Headless
|
|
25
|
+
Interactive commands need one fast path for MCP, non-TTY CLI, and `--yes` / `--dry-run` / `--json`.
|
|
26
|
+
- Mutators: `requireYesInNonTty`, `shouldRunHeadlessWithYes`
|
|
27
|
+
- Queries: `shouldRunHeadless`, `wantsExplicitJson`
|
|
28
|
+
- Varargs/positionals: `shouldRunHeadlessWithPositionals`
|
|
29
|
+
- `ctx.invocation === "mcp"` only for subprocess/TTY wire behavior; use argsbarg headless helpers, not raw `isTTY`
|
package/index.d.ts
CHANGED
|
@@ -307,8 +307,6 @@ export declare function cliErrWithHelp(ctx: CliContext, msg: string): never;
|
|
|
307
307
|
export declare const isInteractiveTty: boolean;
|
|
308
308
|
/** Minimal context for headless routing helpers. */
|
|
309
309
|
export type HeadlessContext = Pick<CliContext, "invocation">;
|
|
310
|
-
/** True when `--dry-run` was passed. */
|
|
311
|
-
export declare function wantsDryRun(hasDryRunFlag: boolean): boolean;
|
|
312
310
|
/** True when `--json` was passed or the handler was invoked via MCP. */
|
|
313
311
|
export declare function wantsExplicitJson(ctx: HeadlessContext, hasJsonFlag: boolean): boolean;
|
|
314
312
|
/**
|
package/package.json
CHANGED
package/src/headless.test.ts
CHANGED
|
@@ -5,15 +5,9 @@ import {
|
|
|
5
5
|
shouldRunHeadless,
|
|
6
6
|
shouldRunHeadlessWithPositionals,
|
|
7
7
|
shouldRunHeadlessWithYes,
|
|
8
|
-
wantsDryRun,
|
|
9
8
|
wantsExplicitJson,
|
|
10
9
|
} from "./headless.ts";
|
|
11
10
|
|
|
12
|
-
test("wantsDryRun detects flag", () => {
|
|
13
|
-
expect(wantsDryRun(true)).toBe(true);
|
|
14
|
-
expect(wantsDryRun(false)).toBe(false);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
11
|
test("wantsExplicitJson includes MCP invocation", () => {
|
|
18
12
|
expect(wantsExplicitJson({ invocation: "cli" }, false)).toBe(false);
|
|
19
13
|
expect(wantsExplicitJson({ invocation: "mcp" }, false)).toBe(true);
|
package/src/headless.ts
CHANGED
|
@@ -4,11 +4,6 @@ import { isInteractiveTty } from "./utils.ts";
|
|
|
4
4
|
/** Minimal context for headless routing helpers. */
|
|
5
5
|
export type HeadlessContext = Pick<CliContext, "invocation">;
|
|
6
6
|
|
|
7
|
-
/** True when `--dry-run` was passed. */
|
|
8
|
-
export function wantsDryRun(hasDryRunFlag: boolean): boolean {
|
|
9
|
-
return hasDryRunFlag;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
7
|
/** True when `--json` was passed or the handler was invoked via MCP. */
|
|
13
8
|
export function wantsExplicitJson(ctx: HeadlessContext, hasJsonFlag: boolean): boolean {
|
|
14
9
|
return hasJsonFlag || ctx.invocation === "mcp";
|