The best way to control Claude Code, Codex and more from any computer or phone

main
ts 53 lines 1.57 KB
Raw
1 #!/usr/bin/env node
2
3 import { Framework } from "@alchemy.run/frontend-frameworks/core";
4 import * as Command from "effect/cli/Command";
5 import * as Flag from "effect/cli/Flag";
6 import * as Effect from "effect/Effect";
7 import * as Options from "./Options.ts";
8 import * as Runtime from "./Runtime.ts";
9 import * as Server from "./Server.ts";
10
11 const build = Command.make(
12 "build",
13 {},
14 Effect.fn(function* () {
15 // Build, then persist the BuildOutput to dist/build.json (the harness's
16 // E2E persistence mechanism — `e2e preview` serves from it).
17 yield* Server.buildAndPersist;
18 }),
19 );
20
21 const dev = Command.make(
22 "dev",
23 {
24 port: Flag.Int("port").pipe(Flag.optional),
25 },
26 Effect.fn(function* ({ port }) {
27 const framework = yield* Framework;
28 // Thread the fixture's project root (Options.root) into Framework.dev,
29 // mirroring what Server/buildAndPersist do for `live`/`build`.
30 const root = yield* Options.load().pipe(Effect.flatMap(Options.resolveRoot));
31 const { url } = yield* framework.dev({ port: port.valueOrUndefined, root });
32 yield* Effect.log(`Dev server running at ${url}`);
33 return yield* Effect.never;
34 }),
35 );
36
37 const preview = Command.make(
38 "preview",
39 {},
40 Effect.fn(function* () {
41 const server = yield* Server.Server;
42 const instance = yield* server.live();
43 yield* Effect.log("Previewing on", instance.url.toString());
44 return yield* Effect.never;
45 }),
46 );
47
48 Command.make("e2e").pipe(
49 Command.withSubcommands([build, dev, preview]),
50 Command.run({ version: "0.0.0" }),
51 Effect.provide(Runtime.layer),
52 Runtime.runMain,
53 );