feat(desktop): add opt-in Cua Driver computer use #5533
Closedf-trycua(GitHub profile, opens in a new tab)wants to merge 237 commits into
t3code/codex-turn-mapping fromrefs/pull/5533/headopened View on GitHub- apps/server/src/cua/CuaDriverEmbedded.ts line 139OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +105,21 @@105+ });106+ const driver = yield* Effect.try({107+ try: () => new EmbeddedCuaDriverHost(binaryPath, hostBundleId),108+ catch: (cause) => new CuaDriverStartError({ binaryPath, cause }),109+ });110+ yield* Effect.addFinalizer(() =>111+ Effect.tryPromise(() => driver.stop()).pipe(112+ Effect.ignore,113+ Effect.ensuring(114+ Effect.sync(() => driver.uniffiDestroy()).pipe(Effect.catchCause(() => Effect.void)),115+ ),116+ ),117+ );118+119+ const connection = yield* Effect.tryPromise({120+ try: () => driver.start(),121+ catch: (cause) => new CuaDriverStartError({ binaryPath, cause }),122+ });123+124+ const disableCua = yield* installCodexLaunchArgs(buildCodexLaunchArgs(connection));125+ yield* monitorEmbeddedCuaDriverExit(
- apps/server/src/serverRuntimeStartup.ts lines 423 to 425OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -409,3 +410,16 @@409410 );410411411412 const startup = Effect.gen(function* () {413+ const logCuaUnavailable = (context: Readonly<Record<string, string>>) =>414+ Effect.logWarning(415+ "embedded cua-driver failed to start; computer use is unavailable",416+ context,417+ );418+ yield* runStartupPhase(419+ "cua-driver.start",420+ startEmbeddedCuaDriver().pipe(421+ Effect.catchTags({422+ CuaDriverModuleLoadError: (error) =>423+ logCuaUnavailable({ modulePath: error.modulePath, cause: String(error.cause) }),424+ CuaDriverStartError: (error) =>425+ logCuaUnavailable({ binaryPath: error.binaryPath, cause: String(error.cause) }),
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
- apps/server/src/provider/Layers/codexLaunchArgs.ts line 12OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1,8 +1,12 @@11 import { tokenizeCliArgs } from "@t3tools/shared/cliArgs";2233 export const T3CODE_CODEX_LAUNCH_ARGS_ENV = "T3CODE_CODEX_LAUNCH_ARGS";4+export const T3CODE_CODEX_APPEND_LAUNCH_ARGS_ENV = "T3CODE_CODEX_APPEND_LAUNCH_ARGS";4556 export const resolveCodexLaunchArgs = (67 launchArgs?: string,78 environment: NodeJS.ProcessEnv = process.env,8-) => environment[T3CODE_CODEX_LAUNCH_ARGS_ENV]?.trim() || launchArgs?.trim() || "";9+) => {10+ const configured = environment[T3CODE_CODEX_LAUNCH_ARGS_ENV]?.trim() || launchArgs?.trim() || "";11+ const appended = environment[T3CODE_CODEX_APPEND_LAUNCH_ARGS_ENV]?.trim() || "";12+ return [configured, appended].filter((value) => value.length > 0).join(" ");
- apps/server/src/provider/Layers/codexLaunchArgs.ts lines 96 to 97OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -4,5 +78,20 @@78+ }79+ const configuredHome = environment.CODEX_HOME?.trim();80+ const homePath = configuredHome81+ ? expandHomePath(configuredHome)82+ : path.join(NodeOS.homedir(), ".codex");83+ return fileSystem84+ .readFileString(path.join(homePath, "config.toml"))85+ .pipe(Effect.orElseSucceed(() => undefined));86+};487588 export const resolveCodexLaunchArgs = (689 launchArgs?: string,790 environment: NodeJS.ProcessEnv = process.env,8-) => environment[T3CODE_CODEX_LAUNCH_ARGS_ENV]?.trim() || launchArgs?.trim() || "";91+ options: { readonly configToml?: string | undefined } = {},92+) => {93+ const configured = environment[T3CODE_CODEX_LAUNCH_ARGS_ENV]?.trim() || launchArgs?.trim() || "";94+ const appended = environment[T3CODE_CODEX_APPEND_LAUNCH_ARGS_ENV]?.trim() || "";95+ const cuaLaunchArgs = environment[T3CODE_CODEX_CUA_LAUNCH_ARGS_ENV]?.trim() || "";96+ const existingCuaDriver =97+ cuaLaunchArgs.length > 0 && hasConfiguredCuaDriver(configured, options.configToml);
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/server/src/cua/CuaDriverEmbedded.ts line 100Resolvedby f-trycua(GitHub profile, opens in a new tab)@@ -0,0 +80,21 @@80+ else process.env[T3CODE_CODEX_CUA_LAUNCH_ARGS_ENV] = previous;81+ return true;82+ });83+ yield* Effect.addFinalizer(() => deactivate.pipe(Effect.asVoid));84+ process.env[T3CODE_CODEX_CUA_LAUNCH_ARGS_ENV] = launchArgs;85+ return () => deactivate;86+});87+88+/**89+ * Uses the descriptor supplied by the permission-owning desktop host. The90+ * server launches only the stdio proxy; it does not own or restart the daemon.91+ */92+export const installDesktopCuaDriver = Effect.fn("server.installDesktopCuaDriver")(function* (93+ mcp: CuaDriverMcpConfiguration,94+) {95+ yield* installCodexLaunchArgs(buildCodexLaunchArgs({ mcp }));96+ yield* Effect.logInfo("desktop-hosted cua-driver ready", {97+ component: "embedded-cua-driver",98+ command: mcp.command,99+ });100+});
- @@ -285,0 +343,21 @@343+ ),344+ }),345+ );346+ if (cuaStarted) {347+ const pool = yield* DesktopBackendPool.DesktopBackendPool;348+ const primaryBackend = yield* pool.primary;349+ const state = yield* DesktopState.DesktopState;350+ yield* cuaDriver.awaitUnavailable.pipe(351+ Effect.andThen(restartBackendAfterCuaDriverExit(primaryBackend, Ref.get(state.quitting))),352+ Effect.tap((restarted) =>353+ restarted354+ ? logStartupInfo("desktop backend restarted without unavailable cua-driver")355+ : Effect.void,356+ ),357+ Effect.catchCause((cause) =>358+ logStartupError("failed to remove unavailable cua-driver from desktop backend", {359+ cause,360+ }),361+ ),362+ Effect.forkScoped,363+ );
t3dotgg(GitHub profile, opens in a new tab) closed this
juliusmarminge reopened this
juliusmarminge closed this
github-actions[bot](GitHub profile, opens in a new tab) removed labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
e4c79c38-5273-4714-b35e-c8dd87658338You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share