diff --git a/docs/integration.md b/docs/integration.md index b378ed8..1a2097e 100644 --- a/docs/integration.md +++ b/docs/integration.md @@ -2,11 +2,11 @@ ## Current interface -The router imports `runCli(argv)` from the exact Pages `src/program.ts` revision and calls it in the same process when the first argument is `pages`. Pages receives the original `process.argv` array. +The router mounts `createPagesCommand()` from the exact Pages `src/program.ts` revision with `addCommand` and parses the original `process.argv` array in the same process when the first argument is `pages`. This preserves every remaining argument and option, standard input for hidden interactive prompts, standard output including JSON, standard error and subprocess progress, the working directory and environment, and success or failure through the process exit status. -No extraction is used. Bun embeds the router, Pages source, and JavaScript dependencies in the executable. Pages v2.0.0 deploys through the Cloudflare HTTP API and does not invoke Wrangler. +No extraction is used. Bun embeds the router, Pages source, and JavaScript dependencies in the executable. Pages v3.0.0 deploys through the Cloudflare HTTP API and does not invoke Wrangler. Pages publishes no bins; the `pages` command surface exists only inside this binary. ## Pin and integrity policy diff --git a/docs/spec.md b/docs/spec.md index 83ffaca..8533613 100644 --- a/docs/spec.md +++ b/docs/spec.md @@ -7,7 +7,7 @@ Distribute one `alab` executable per supported operating system and CPU. The exe ## Decisions - Bun compile produces native executables and is used only in development and CI. -- Pages v2.0.0 plus its side-effect-free integration entry point is pinned as a Git submodule at merged commit `c6a71e826bfecb9f7c65c88c1f1d28ba23f72bd8`. +- Pages v3.0.0 plus its side-effect-free integration entry point is pinned as a Git submodule at commit `887e73f189c192423fd9f897730b06417fa82362`. - Runtime dependencies are exact versions in `package.json` and `bun.lock`. - Pages executes in-process. Arguments and process streams remain unchanged. Its rejection reaches one top-level error handler and sets exit code 1. - `alab --version` reports the router version and every integrated tool version and SHA. diff --git a/pins.json b/pins.json index dcfcd37..a5bcd2f 100644 --- a/pins.json +++ b/pins.json @@ -1,8 +1,8 @@ { "pages": { - "version": "2.0.0", + "version": "3.0.0", "repository": "https://github.com/agentlab-in/pages.git", - "commit": "c6a71e826bfecb9f7c65c88c1f1d28ba23f72bd8", - "packageSha256": "33359d14b47a323d4447890b4e5edf8700b25956e1a46f3843c6d0ab52287125" + "commit": "887e73f189c192423fd9f897730b06417fa82362", + "packageSha256": "0b4296a0d930002ed0a3cc36c7316501d272d1400576dc7a8e25719714e9dd0b" } } diff --git a/scripts/smoke-binary.sh b/scripts/smoke-binary.sh index 591d1ac..4ba98a4 100644 --- a/scripts/smoke-binary.sh +++ b/scripts/smoke-binary.sh @@ -36,7 +36,7 @@ assert_json() { capture --version assert_success -[[ "$stdout" == $'alab 0.1.0\npages 2.0.0 (c6a71e826bfecb9f7c65c88c1f1d28ba23f72bd8)' ]] +[[ "$stdout" == $'alab 0.1.0\npages 3.0.0 (887e73f189c192423fd9f897730b06417fa82362)' ]] capture pages --help assert_success @@ -78,11 +78,16 @@ assert_json capture pages read missing --json [[ "$status" -eq 1 ]] [[ -z "$stdout" ]] -[[ "$stderr" == 'Error: Unknown page id "missing". Run agentlab-pages list.' ]] +[[ "$stderr" == 'Error: Unknown page id "missing". Run alab pages list.' ]] capture unknown [[ "$status" -eq 1 ]] [[ -z "$stdout" ]] [[ "$stderr" == "Error: unknown tool 'unknown'. Run 'alab --help'." ]] +capture put +[[ "$status" -eq 1 ]] +[[ -z "$stdout" ]] +[[ "$stderr" == "Error: unknown tool 'put'. Run 'alab --help'." ]] + echo "compiled binary smoke test passed" diff --git a/src/cli.ts b/src/cli.ts index 2b637dc..f5adbda 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,8 +1,9 @@ #!/usr/bin/env bun +import { Command } from "commander"; import alabPackage from "../package.json"; import pins from "../pins.json"; import pagesPackage from "../vendor/pages/package.json"; -import { runCli as runPagesCli } from "../vendor/pages/src/program.ts"; +import { createPagesCommand } from "../vendor/pages/src/program.ts"; const HELP = `Alab ${alabPackage.version} @@ -21,6 +22,14 @@ export function versionText(): string { return `alab ${alabPackage.version}\npages ${pagesPackage.version} (${pins.pages.commit})`; } +export function createAlabProgram(): Command { + const program = new Command(); + program.exitOverride(); + program.name("alab").description("AgentLab tools").version(versionText()); + program.addCommand(createPagesCommand()); + return program; +} + export async function main(argv = process.argv): Promise { const args = argv.slice(2); if (args.length === 0 || args[0] === "help" || args[0] === "--help" || args[0] === "-h") { @@ -36,7 +45,14 @@ export async function main(argv = process.argv): Promise { return 1; } - await runPagesCli(argv); + try { + await createAlabProgram().parseAsync(argv); + } catch (error: unknown) { + const e = error as { code?: string }; + if (e?.code === "commander.helpDisplayed" || e?.code === "commander.version") return process.exitCode ?? 0; + console.error(`Error: ${error instanceof Error ? error.message : String(error)}`); + return 1; + } return process.exitCode ?? 0; } diff --git a/tests/router.test.ts b/tests/router.test.ts index aef9753..f4166c9 100644 --- a/tests/router.test.ts +++ b/tests/router.test.ts @@ -13,7 +13,7 @@ function run(args: string[]) { describe("Alab router", () => { test("reports combined and pinned Pages versions", () => { - expect(versionText()).toBe(`alab 0.1.0\npages 2.0.0 (${pins.pages.commit})`); + expect(versionText()).toBe(`alab 0.1.0\npages 3.0.0 (${pins.pages.commit})`); }); test("routes Pages help with exact successful streams", () => { @@ -34,4 +34,12 @@ describe("Alab router", () => { expect(result.stdout.toString()).toBe(""); expect(result.stderr.toString()).toBe("Error: unknown tool 'unknown'. Run 'alab --help'.\n"); }); + + test("rejects top-level Pages commands outside the pages tool", () => { + const result = run(["put"]); + + expect(result.exitCode).toBe(1); + expect(result.stdout.toString()).toBe(""); + expect(result.stderr.toString()).toBe("Error: unknown tool 'put'. Run 'alab --help'.\n"); + }); }); diff --git a/vendor/pages b/vendor/pages index c6a71e8..887e73f 160000 --- a/vendor/pages +++ b/vendor/pages @@ -1 +1 @@ -Subproject commit c6a71e826bfecb9f7c65c88c1f1d28ba23f72bd8 +Subproject commit 887e73f189c192423fd9f897730b06417fa82362