Open source CapCut alternative.
TypeScript
fix(site): resolve Codex on every use so the ChatGPT app's copy is found [rebuild]
David Le502c66985ec5
diff --git a/site/src/cut/engine/serve.ts b/site/src/cut/engine/serve.tsindex 8be6cc32..02c11125 100644--- a/site/src/cut/engine/serve.ts+++ b/site/src/cut/engine/serve.ts@@ -3,7 +3,7 @@ import { matchCutRoute, runCutRoute } from "../server/http/routes";import { flattenCutUsers, migrateCutDataDir } from "../server/migrateDataDir";import { sweepPhoneInbox } from "../server/phoneLink";import { reconcileProjectDirs } from "../server/projects";-import { ensureCodexPath, ensureToolPath, resolveOnPath } from "../server/tool-path";+import { ensureToolPath, resolveOnPath } from "../server/tool-path";import { enginePort } from "./config";// Throws (and exits with a clear message) on a bad DONKEY_CUT_PORT rather than@@ -54,8 +54,6 @@ async function start() {const claude = await resolveOnPath("claude");if (claude) process.env.DONKEY_CUT_CLAUDE = claude;}- // Codex may live only inside the ChatGPT app's bundle, off every PATH.- await ensureCodexPath();native.serve({hostname: "127.0.0.1",diff --git a/site/src/cut/server/http/ai.ts b/site/src/cut/server/http/ai.tsindex 1edd0d34..380c8a63 100644--- a/site/src/cut/server/http/ai.ts+++ b/site/src/cut/server/http/ai.ts@@ -22,6 +22,7 @@ import { rewriteCaptions, translateCaptions } from "../ai/captions";import { writeVisualCues, type VisualFrame } from "../ai/visualSubtitles";import { AI_SKILL_INDEX, AI_TOOLS, attachedAssetsBlock, readSkill, skillRelevanceBlock, systemPrompt } from "../ai/catalog";import { STEP_BUDGET, stopText, turnClose, type TurnEnd } from "../../lib/turnBudget";+import { codexCommand } from "../tool-path";interface ChatBody {threadId: string;@@ -208,10 +209,6 @@ async function runClaude(}}-/** The Codex CLI the engine resolved at startup (tool-path.ts); bare- * `codex` when none was found, so the spawn fails as "not installed". */-const codexCommand = () => process.env.DONKEY_CUT_CODEX ?? "codex";-/** GPT models through the Codex CLI — the user's ChatGPT login. */async function runCodex(emit: UIChunkWriter["write"],@@ -222,6 +219,7 @@ async function runCodex(signal: AbortSignal) {signal.throwIfAborted();+ const codex = await codexCommand();const mcp = mcpCommand(base, sessionKey);const session = body.providerSession;const args = ["exec"];@@ -241,7 +239,7 @@ async function runCodex(await new Promise<void>((resolve, reject) => {// stdin must be closed: `codex exec` otherwise waits on it for EOF.- const proc = spawn(codexCommand(), args, { env: process.env, stdio: ["ignore", "pipe", "pipe"] });+ const proc = spawn(codex, args, { env: process.env, stdio: ["ignore", "pipe", "pipe"] });const onAbort = () => proc.kill("SIGTERM");signal.addEventListener("abort", onAbort);@@ -524,7 +522,7 @@ export const aiApi = {if (!value) {const [claude, codexLogin] = await Promise.all([probe("claude", ["--version"]),- probe(codexCommand(), ["login", "status"]),+ probe(await codexCommand(), ["login", "status"]),]);// The login probe running at all means codex is installed; only its// ENOENT failure (carried through in codexLogin) marks it missing.diff --git a/site/src/cut/server/http/next.ts b/site/src/cut/server/http/next.tsindex 1e78ee08..0889720f 100644--- a/site/src/cut/server/http/next.ts+++ b/site/src/cut/server/http/next.ts@@ -2,7 +2,7 @@ import { hostedApiBlock } from "../local-only";import { flattenCutUsers } from "../migrateDataDir";import { sweepPhoneInbox } from "../phoneLink";import { reconcileProjectDirs } from "../projects";-import { ensureCodexPath } from "../tool-path";+import { ensureToolPath } from "../tool-path";import { matchCutRoute, runCutRoute } from "./routes";let flattened = false;@@ -26,10 +26,9 @@ export async function cutCatchAll(req: Request): Promise<Response> {if (blocked) return blocked;// The dev server spawns tools (yt-dlp, ffmpeg, …) in-process, so it needs- // the same widened PATH the packaged engine builds at startup, the same- // resolved Codex, and it runs the same users/-dir flatten the engine runs- // before serving data routes.- await ensureCodexPath();+ // the same widened PATH the packaged engine builds at startup, and it runs+ // the same users/-dir flatten the engine runs before serving data routes.+ await ensureToolPath();flattenOnce();const { pathname } = new URL(req.url);diff --git a/site/src/cut/server/tool-path.ts b/site/src/cut/server/tool-path.tsindex 9a9dd03d..2b0ab918 100644--- a/site/src/cut/server/tool-path.ts+++ b/site/src/cut/server/tool-path.ts@@ -104,16 +104,10 @@ export async function resolveCodex(return null;}-let codexResolved: Promise<void> | null = null;--/** Resolve Codex once into DONKEY_CUT_CODEX, which the probe and the turn- * runner spawn. Widens PATH first. Missing is fine — the models probe reports it. */-export function ensureCodexPath(): Promise<void> {- codexResolved ??= (async () => {- await ensureToolPath();- if (process.env.DONKEY_CUT_CODEX) return;- const codex = await resolveCodex();- if (codex) process.env.DONKEY_CUT_CODEX = codex;- })();- return codexResolved;+/** The Codex CLI to spawn, resolved on every call so an install, uninstall or+ * ChatGPT app update takes effect without an engine restart; bare `codex`+ * when none is found, so the spawn fails as "not installed". */+export async function codexCommand(): Promise<string> {+ await ensureToolPath();+ return (await resolveCodex()) ?? "codex";}