Skip to content
Merged
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
4 changes: 2 additions & 2 deletions docs/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions pins.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
9 changes: 7 additions & 2 deletions scripts/smoke-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
20 changes: 18 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -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}

Expand All @@ -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<number> {
const args = argv.slice(2);
if (args.length === 0 || args[0] === "help" || args[0] === "--help" || args[0] === "-h") {
Expand All @@ -36,7 +45,14 @@ export async function main(argv = process.argv): Promise<number> {
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;
}

Expand Down
10 changes: 9 additions & 1 deletion tests/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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");
});
});
Loading