@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 64 lines 2.14 KB
Raw
1 import { logChildLine } from "alchemy/Util/LogRecord";
2 import * as Data from "effect/Data";
3 import * as Effect from "effect/Effect";
4 import * as FileSystem from "effect/FileSystem";
5 import * as Path from "effect/Path";
6 import * as ChildProcess from "effect/process/ChildProcess";
7 import * as Schema from "effect/Schema";
8 import * as Stream from "effect/Stream";
9
10 export class TraceOperationFailed extends Data.TaggedError("TraceOperationFailed")<{
11 readonly message: string;
12 readonly cause?: unknown;
13 }> {}
14
15 export interface TraceInput {
16 readonly seeds: string[];
17 readonly base: string;
18 readonly root: string;
19 readonly next: boolean;
20 }
21
22 /** Keep dependency-parser heaps outside the long-lived deployment process. */
23 export const traceWebsiteFiles = Effect.fn(function* (input: TraceInput) {
24 const fs = yield* FileSystem.FileSystem;
25 const path = yield* Path.Path;
26 const directory = yield* fs.makeTempDirectoryScoped({
27 prefix: "alchemy-neon-trace-",
28 });
29 const inputPath = path.join(directory, "input.json");
30 const outputPath = path.join(directory, "output.json");
31 yield* fs.writeFileString(inputPath, JSON.stringify(input));
32 const runner = yield* path.fromFileUrl(
33 new URL(
34 import.meta.url.endsWith(".ts") ? "./TraceRunner.ts" : "./TraceRunner.js",
35 import.meta.url,
36 ),
37 );
38 const child = yield* ChildProcess.make(
39 "node",
40 ["--max-old-space-size=1536", runner, inputPath, outputPath],
41 { stdin: "ignore", stdout: "ignore", stderr: "pipe" },
42 );
43 // The runner's diagnostics become log records instead of raw terminal writes.
44 const [code] = yield* Effect.all(
45 [
46 child.exitCode,
47 child.stderr.pipe(
48 Stream.decodeText,
49 Stream.splitLines,
50 Stream.runForEach((line) => logChildLine(line, { stream: "stderr" })),
51 ),
52 ],
53 { concurrency: "unbounded" },
54 );
55 if (code !== 0)
56 return yield* new TraceOperationFailed({ message: `Website dependency trace exited ${code}` });
57 return yield* fs
58 .readFileString(outputPath)
59 .pipe(
60 Effect.flatMap(
61 Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Array(Schema.String))),
62 ),
63 );
64 }, Effect.scoped);