Durable coding-agent harnesses (Claude Code, Codex, OpenCode, Pi, fx) on a Workflow SDK World
fix(cli): handle explicit help consistently (#25)
Pranay Prakash9f42806dc241
diff --git a/.changeset/cli-explicit-help.md b/.changeset/cli-explicit-help.mdnew file mode 100644index 0000000..84b7f2a--- /dev/null+++ b/.changeset/cli-explicit-help.md@@ -0,0 +1,5 @@+---+"durable-harness": patch+---++Explicit CLI help prints to stdout and succeeds at every command level, including sandbox.diff --git a/packages/durable-harness/src/cli.ts b/packages/durable-harness/src/cli.tsindex d3e4d5e..95e7618 100644--- a/packages/durable-harness/src/cli.ts+++ b/packages/durable-harness/src/cli.ts@@ -50,6 +50,10 @@ In vercel.ts, call harnessFunctions() from durable-harness/vercel instead.`;/** `sandbox prepare [--region <region>]`. */async function sandboxCommand(argv: string[]): Promise<number> {const [sub, ...rest] = argv;+ if (sub === '--help' || sub === '-h') {+ console.log(USAGE);+ return 0;+ }if (sub !== 'prepare') {console.error(USAGE);return 1;@@ -71,10 +75,14 @@ async function sandboxCommand(argv: string[]): Promise<number> {function main(argv: string[]): number | Promise<number> {const [command, ...rest] = argv;+ if (command === '--help' || command === '-h') {+ console.log(USAGE);+ return 0;+ }if (command === 'sandbox') return sandboxCommand(rest);if (command !== 'vercel-json') {console.error(USAGE);- return command === undefined || command === '--help' || command === '-h' ? 0 : 1;+ return command === undefined ? 0 : 1;}const chat: string[] = [];const include: string[] = [];diff --git a/packages/durable-harness/test/cli.test.ts b/packages/durable-harness/test/cli.test.tsnew file mode 100644index 0000000..db2634e--- /dev/null+++ b/packages/durable-harness/test/cli.test.ts@@ -0,0 +1,47 @@+import { spawnSync } from 'node:child_process';+import { mkdtempSync, readdirSync, rmSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { fileURLToPath } from 'node:url';+import { afterAll, describe, expect, it } from 'vitest';++const CLI = fileURLToPath(new URL('../src/cli.ts', import.meta.url));+const cwd = mkdtempSync(join(tmpdir(), 'durable-harness-cli-help-'));+afterAll(() => rmSync(cwd, { recursive: true, force: true }));++const run = (args: string[]) => spawnSync(process.execPath, [CLI, ...args], { cwd, encoding: 'utf8' });++describe('explicit CLI help', () => {+ for (const command of [[], ['vercel-json'], ['sandbox'], ['sandbox', 'prepare']]) {+ for (const flag of ['--help', '-h']) {+ const args = [...command, flag];+ it(`${args.join(' ')} prints help to stdout and succeeds without doing work`, () => {+ const result = run(args);+ expect(result.error).toBeUndefined();+ expect(result.status).toBe(0);+ expect(result.stdout).toMatch(/^usage: durable-harness /);+ expect(result.stdout).toContain('durable-harness sandbox prepare');+ expect(result.stderr).toBe('');+ expect(readdirSync(cwd)).toEqual([]);+ });+ }+ }++ for (const args of [['bogus'], ['sandbox'], ['sandbox', 'bogus']]) {+ it(`${args.join(' ')} remains an error with usage on stderr`, () => {+ const result = run(args);+ expect(result.error).toBeUndefined();+ expect(result.status).toBe(1);+ expect(result.stdout).toBe('');+ expect(result.stderr).toMatch(/^usage: durable-harness /);+ });+ }++ it('keeps no-argument usage on stderr with a successful exit', () => {+ const result = run([]);+ expect(result.error).toBeUndefined();+ expect(result.status).toBe(0);+ expect(result.stdout).toBe('');+ expect(result.stderr).toMatch(/^usage: durable-harness /);+ });+});