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

main
ts 65 lines 2.28 KB
Raw
1 import { logChildLine } from "alchemy/Util/LogRecord";
2 import { sha256 } from "alchemy/Util/sha256";
3 import * as Data from "effect/Data";
4 import * as Effect from "effect/Effect";
5 import * as FileSystem from "effect/FileSystem";
6 import * as Path from "effect/Path";
7 import * as ChildProcess from "effect/process/ChildProcess";
8 import * as Stream from "effect/Stream";
9 import type { WebsiteArtifactProps } from "./Artifact.ts";
10
11 export class PackageOperationFailed extends Data.TaggedError("PackageOperationFailed")<{
12 readonly message: string;
13 readonly cause?: unknown;
14 }> {}
15
16 /** Release staging, compression and validation buffers between deployments. */
17 export const packageWebsiteInChild = Effect.fn(
18 function* (props: WebsiteArtifactProps) {
19 const fs = yield* FileSystem.FileSystem;
20 const path = yield* Path.Path;
21 const directory = yield* fs.makeTempDirectoryScoped({
22 prefix: "alchemy-neon-package-",
23 });
24 const inputPath = path.join(directory, "input.json");
25 const outputPath = path.join(directory, "output.zip");
26 yield* fs.writeFileString(inputPath, JSON.stringify(props));
27 const runner = yield* path.fromFileUrl(
28 new URL(
29 import.meta.url.endsWith(".ts") ? "./PackageRunner.ts" : "./PackageRunner.js",
30 import.meta.url,
31 ),
32 );
33 const child = yield* ChildProcess.make(
34 "node",
35 [
36 "--max-old-space-size=1536",
37 ...(runner.endsWith(".ts")
38 ? ["--experimental-transform-types", "--no-warnings=ExperimentalWarning"]
39 : []),
40 runner,
41 inputPath,
42 outputPath,
43 ],
44 { stdin: "ignore", stdout: "ignore", stderr: "pipe" },
45 );
46 // The runner's diagnostics become log records instead of raw terminal writes.
47 const [code] = yield* Effect.all(
48 [
49 child.exitCode,
50 child.stderr.pipe(
51 Stream.decodeText,
52 Stream.splitLines,
53 Stream.runForEach((line) => logChildLine(line, { stream: "stderr" })),
54 ),
55 ],
56 { concurrency: "unbounded" },
57 );
58 if (code !== 0)
59 return yield* new PackageOperationFailed({ message: `Website packaging exited ${code}` });
60 const archive = yield* fs.readFile(outputPath);
61 return { archive, hash: yield* sha256(archive) };
62 },
63 Effect.scoped,
64 Effect.timeout("90 seconds"),
65 );