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, 03:37 UTC
| 1 | // @effect-diagnostics nodeBuiltinImport:off - runs inside Vite+ before project services start. |
| 2 | import * as NodeChildProcess from "node:child_process"; |
| 3 | import * as NodeURL from "node:url"; |
| 4 | import { remoteCacheUrl } from "./remoteCache.ts"; |
| 5 | import { flushTelemetry, observeSummaries } from "./telemetry.ts"; |
| 6 | |
| 7 | export default function start({ root }: { readonly root: string }) { |
| 8 | const url = remoteCacheUrl(root); |
| 9 | if (!url) return; |
| 10 | const endpoint = new URL(url); |
| 11 | endpoint.username = ""; |
| 12 | endpoint.password = ""; |
| 13 | const stop = |
| 14 | process.env.T3_TASK_CACHE_TELEMETRY === "off" |
| 15 | ? undefined |
| 16 | : observeSummaries(root, endpoint.href.replace(/\/$/, ""), process.env); |
| 17 | const finish = async () => { |
| 18 | if (!stop) return; |
| 19 | stop(); |
| 20 | // GitHub can terminate detached processes as soon as the final step exits. |
| 21 | if (process.env.GITHUB_ACTIONS === "true") { |
| 22 | await flushTelemetry(); |
| 23 | return; |
| 24 | } |
| 25 | // A transient flusher drains the durable queue without delaying tasks or Ctrl-C. |
| 26 | const child = NodeChildProcess.spawn( |
| 27 | process.execPath, |
| 28 | [NodeURL.fileURLToPath(new URL("./flush.ts", import.meta.url))], |
| 29 | { |
| 30 | detached: true, |
| 31 | stdio: "ignore", |
| 32 | env: { ...process.env, NODE_OPTIONS: "" }, |
| 33 | }, |
| 34 | ); |
| 35 | child.on("error", () => {}); |
| 36 | child.unref(); |
| 37 | }; |
| 38 | return Object.assign(finish, { |
| 39 | remoteCache: process.env.VP_REMOTE_CACHE || process.env.VP_T3_TASK_CACHE_MODE || "read-write", |
| 40 | }); |
| 41 | } |