Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@ describe('subcommands', () => {
list

Global Options:
--dry-run Preview parsed inputs without executing
--filter-output <keys> Filter output by key paths (e.g. foo,bar.baz,a[0,3])
--format <toon|json|yaml|md|jsonl> Output format
--help Show help
Expand Down Expand Up @@ -1356,6 +1357,7 @@ describe('help', () => {
skills add Sync skill files to agents

Global Options:
--dry-run Preview parsed inputs without executing
--filter-output <keys> Filter output by key paths (e.g. foo,bar.baz,a[0,3])
--format <toon|json|yaml|md|jsonl> Output format
--help Show help
Expand Down Expand Up @@ -1394,6 +1396,7 @@ describe('help', () => {
skills add Sync skill files to agents

Global Options:
--dry-run Preview parsed inputs without executing
--filter-output <keys> Filter output by key paths (e.g. foo,bar.baz,a[0,3])
--format <toon|json|yaml|md|jsonl> Output format
--help Show help
Expand Down Expand Up @@ -1428,6 +1431,7 @@ describe('help', () => {
name Name

Global Options:
--dry-run Preview parsed inputs without executing
--filter-output <keys> Filter output by key paths (e.g. foo,bar.baz,a[0,3])
--format <toon|json|yaml|md|jsonl> Output format
--help Show help
Expand Down Expand Up @@ -1462,6 +1466,7 @@ describe('help', () => {
list List PRs

Global Options:
--dry-run Preview parsed inputs without executing
--filter-output <keys> Filter output by key paths (e.g. foo,bar.baz,a[0,3])
--format <toon|json|yaml|md|jsonl> Output format
--help Show help
Expand Down Expand Up @@ -1557,6 +1562,7 @@ describe('help', () => {
skills add Sync skill files to agents

Global Options:
--dry-run Preview parsed inputs without executing
--filter-output <keys> Filter output by key paths (e.g. foo,bar.baz,a[0,3])
--format <toon|json|yaml|md|jsonl> Output format
--help Show help
Expand Down Expand Up @@ -1589,6 +1595,7 @@ describe('help', () => {
Run "tool status" to check deployment progress.

Global Options:
--dry-run Preview parsed inputs without executing
--filter-output <keys> Filter output by key paths (e.g. foo,bar.baz,a[0,3])
--format <toon|json|yaml|md|jsonl> Output format
--help Show help
Expand Down Expand Up @@ -1684,6 +1691,7 @@ describe('env', () => {
Usage: test deploy

Global Options:
--dry-run Preview parsed inputs without executing
--filter-output <keys> Filter output by key paths (e.g. foo,bar.baz,a[0,3])
--format <toon|json|yaml|md|jsonl> Output format
--help Show help
Expand Down Expand Up @@ -1722,6 +1730,7 @@ describe('env', () => {
Usage: test deploy

Global Options:
--dry-run Preview parsed inputs without executing
--filter-output <keys> Filter output by key paths (e.g. foo,bar.baz,a[0,3])
--format <toon|json|yaml|md|jsonl> Output format
--help Show help
Expand Down
16 changes: 16 additions & 0 deletions src/Cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ export declare namespace create {
agent: boolean
/** Positional arguments. */
args: InferOutput<args>
/** Whether this is a dry-run invocation. Only `true` when the command sets `dryRun: true`. */
dryRun: boolean
/** Parsed environment variables. */
env: InferOutput<env>
/** Return an error result with optional CTAs. */
Expand Down Expand Up @@ -429,6 +431,7 @@ async function serveImpl(

const {
verbose,
dryRun,
format: formatFlag,
formatExplicit,
filterOutput,
Expand Down Expand Up @@ -1142,6 +1145,7 @@ async function serveImpl(
const mwCtx: MiddlewareContext = {
agent: !human,
command: path,
dryRun,
env: cliEnv,
error: errorFn,
format,
Expand Down Expand Up @@ -1217,6 +1221,7 @@ async function serveImpl(
const result = await Command.execute(command, {
agent: !human,
argv: rest,
dryRun,
env: options.envSchema,
envSource: options.env,
format,
Expand Down Expand Up @@ -1258,6 +1263,7 @@ async function serveImpl(
meta: {
command: path,
duration,
...(result.dryRun ? { dryRun: true } : undefined),
...(cta ? { cta } : undefined),
},
})
Expand Down Expand Up @@ -1302,6 +1308,8 @@ async function serveImpl(
/** @internal Options for fetchImpl. */
declare namespace fetchImpl {
type Options = {
/** Whether this is a dry-run invocation. */
dryRun?: boolean | undefined
/** CLI-level env schema. */
envSchema?: z.ZodObject<any> | undefined
/** Group-level middleware collected during command resolution. */
Expand Down Expand Up @@ -1391,6 +1399,7 @@ async function fetchImpl(
options: fetchImpl.Options = {},
): Promise<Response> {
const start = performance.now()
if (req.headers.get('x-dry-run') === 'true') options = { ...options, dryRun: true }

const url = new URL(req.url)
const segments = url.pathname.split('/').filter(Boolean)
Expand Down Expand Up @@ -1542,6 +1551,7 @@ async function executeCommand(
const result = await Command.execute(command, {
agent: true,
argv: rest,
dryRun: options.dryRun,
env: options.envSchema,
format: 'json',
formatExplicit: true,
Expand Down Expand Up @@ -1627,6 +1637,7 @@ async function executeCommand(
meta: {
command: path,
duration,
...(result.dryRun ? { dryRun: true } : undefined),
...(cta ? { cta } : undefined),
},
},
Expand Down Expand Up @@ -1794,6 +1805,7 @@ declare namespace serveImpl {
/** @internal Extracts built-in flags (--verbose, --format, --json, --llms, --help, --version) from argv. */
function extractBuiltinFlags(argv: string[]) {
let verbose = false
let dryRun = false
let llms = false
let llmsFull = false
let mcp = false
Expand All @@ -1811,6 +1823,7 @@ function extractBuiltinFlags(argv: string[]) {
for (let i = 0; i < argv.length; i++) {
const token = argv[i]!
if (token === '--verbose') verbose = true
else if (token === '--dry-run') dryRun = true
else if (token === '--llms') llms = true
else if (token === '--llms-full') llmsFull = true
else if (token === '--mcp') mcp = true
Expand Down Expand Up @@ -1839,6 +1852,7 @@ function extractBuiltinFlags(argv: string[]) {

return {
verbose,
dryRun,
format,
formatExplicit,
filterOutput,
Expand Down Expand Up @@ -2527,6 +2541,8 @@ type CommandDefinition<
agent: boolean
/** Positional arguments. */
args: InferOutput<args>
/** Whether this is a dry-run invocation. Only `true` when the command sets `dryRun: true`. */
dryRun: boolean
/** Parsed environment variables. */
env: InferOutput<env>
/** Return an error result with optional CTAs. */
Expand Down
7 changes: 7 additions & 0 deletions src/Help.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('formatCommand', () => {
--limit <number> Max PRs to return (default: 30)

Global Options:
--dry-run Preview parsed inputs without executing
--filter-output <keys> Filter output by key paths (e.g. foo,bar.baz,a[0,3])
--format <toon|json|yaml|md|jsonl> Output format
--help Show help
Expand All @@ -47,6 +48,7 @@ describe('formatCommand', () => {
Usage: tool ping

Global Options:
--dry-run Preview parsed inputs without executing
--filter-output <keys> Filter output by key paths (e.g. foo,bar.baz,a[0,3])
--format <toon|json|yaml|md|jsonl> Output format
--help Show help
Expand Down Expand Up @@ -76,6 +78,7 @@ describe('formatCommand', () => {
title Title

Global Options:
--dry-run Preview parsed inputs without executing
--filter-output <keys> Filter output by key paths (e.g. foo,bar.baz,a[0,3])
--format <toon|json|yaml|md|jsonl> Output format
--help Show help
Expand Down Expand Up @@ -153,6 +156,7 @@ describe('formatRoot', () => {
issue list List issues

Global Options:
--dry-run Preview parsed inputs without executing
--filter-output <keys> Filter output by key paths (e.g. foo,bar.baz,a[0,3])
--format <toon|json|yaml|md|jsonl> Output format
--help Show help
Expand All @@ -178,6 +182,7 @@ describe('formatRoot', () => {
ping Health check

Global Options:
--dry-run Preview parsed inputs without executing
--filter-output <keys> Filter output by key paths (e.g. foo,bar.baz,a[0,3])
--format <toon|json|yaml|md|jsonl> Output format
--help Show help
Expand Down Expand Up @@ -207,6 +212,7 @@ describe('formatRoot', () => {
fetch Fetch a URL

Global Options:
--dry-run Preview parsed inputs without executing
--filter-output <keys> Filter output by key paths (e.g. foo,bar.baz,a[0,3])
--format <toon|json|yaml|md|jsonl> Output format
--help Show help
Expand Down Expand Up @@ -236,6 +242,7 @@ describe('formatRoot', () => {
url URL to fetch

Global Options:
--dry-run Preview parsed inputs without executing
--filter-output <keys> Filter output by key paths (e.g. foo,bar.baz,a[0,3])
--format <toon|json|yaml|md|jsonl> Output format
--help Show help
Expand Down
1 change: 1 addition & 0 deletions src/Help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ function globalOptionsLines(root = false): string[] {
}

const flags = [
{ flag: '--dry-run', desc: 'Preview parsed inputs without executing' },
{
flag: '--filter-output <keys>',
desc: 'Filter output by key paths (e.g. foo,bar.baz,a[0,3])',
Expand Down
3 changes: 3 additions & 0 deletions src/Mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,12 @@ export async function callTool(
...((tool.command.middleware as MiddlewareHandler[] | undefined) ?? []),
]

const dryRun = (options.extra?._meta as any)?.dryRun === true

const result = await Command.execute(tool.command, {
agent: true,
argv: [],
dryRun: dryRun || undefined,
env: options.env,
format: 'json',
formatExplicit: true,
Expand Down
Loading