feat: let Claude and other agents use apps and browser tabs on your Mac #15006
Closedt3dotgg(GitHub profile, opens in a new tab)wants to merge 7 commits into
main fromt3code/take-over-computer-use-propened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
juliusmarminge added labelsmacroscope-review
- apps/server/src/orchestration-v2/ProviderSessionManager.ts line 1483Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1438,3 +1476,8 @@14381476 ? markIdle(entry.runtime.providerSessionId)14391477 : touchActivity(entry.runtime.providerSessionId),14401478 ).pipe(1479+ // Ends the Cua session before run subscribers see the terminal,1480+ // so the thread's next turn cannot start ahead of it.1481+ Effect.andThen(1482+ event.type === "turn.terminal"1483+ ? endComputerSession(event.providerThreadId).pipe(apps/server/src/orchestration-v2/Adapters/OpenCodeAdapterV2.ts line 1003Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -983,3 +985,16 @@983985 },984986 }),985987 );988+ // Computer access is an addition: a server that cannot start it still runs.989+ for (const local of localMcpServers) {990+ yield* OpenCodeRuntime.runOpenCodeSdk("mcp.add", () =>991+ client.mcp.add({992+ name: local.name,993+ config: {994+ type: "local",995+ command: [local.command, ...local.args],996+ environment: { ...local.env },997+ },998+ }),999+ ).pipe(1000+ Effect.catch((cause) =>apps/web/src/components/settings/ComputerAccessSetupDialog.tsx lines 110 to 110OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +90,21 @@90+ window.clearInterval(timer);91+ };92+ }, [requesting]);93+94+ // Set as soon as Start is pressed, since the status that reports the95+ // request can arrive after the dialog closes.96+ const requestStarted = useRef(false);97+ const runAction = async (action: ServerComputerAccessAction) => {98+ if (action === "request-cua-permissions") requestStarted.current = true;99+ setPending(action);100+ setError(null);101+ const result = await run({ environmentId, input: { action } });102+ setPending(null);103+ if (result._tag === "Failure") setError(ACTION_FAILURES[action]);104+ onRefresh();105+ return result._tag !== "Failure";106+ };107+ // A request left running would keep waiting on the user for minutes, so108+ // the dialog cancels it when it closes for any reason.109+ const cancelRequest = useEffectEvent(() => {110+ if (requesting || requestStarted.current) {apps/web/src/components/settings/IntegrationsSettings.tsx lines 902 to 902Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -856,0 +882,21 @@882+ const macHost = selected?.serverConfig?.environment.platform.os === "darwin";883+ const hostLabel = selected?.label ?? "this Mac";884+ const {885+ data: status,886+ error: statusError,887+ refresh,888+ } = useEnvironmentQuery(889+ environmentId === null || !macHost890+ ? null891+ : serverEnvironment.computerAccess({ environmentId, input: {} }),892+ );893+ const appsOn = settings.enableAgentComputerAccess;894+ const browserTabsOn = settings.enableAgentBrowserTabs;895+ const appsReady = status !== null && computerAppsReady(status);896+ const browser = status === null ? undefined : computerBrowserReady(status);897+ // Readiness was checked on the selected Mac only, so only it is turned on.898+ const enable = (patch: {899+ readonly enableAgentComputerAccess?: true;900+ readonly enableAgentBrowserTabs?: true;901+ }) => {902+ if (environmentId) void updateEnvironment({ environmentId, input: { patch } });apps/server/src/mcp/CuaMcpProxy.ts line 80Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +60,21 @@60+ pending.clear();61+ queue = [];62+}63+64+function start() {65+ const current = spawn(driver, ["mcp"], { stdio: ["pipe", "pipe", "inherit"] });66+ let replay = restarted && initialize ? "t3-replay-" + ++replayCount : null;67+ child = current;68+ ready = replay === null;69+ let buffer = "";70+ current.stdin.on("error", () => {});71+ current.stdout.on("data", (chunk) => {72+ // A replaced driver can still flush output; its calls were already failed.73+ if (child !== current) return;74+ buffer += chunk;75+ const lines = buffer.split("\\n");76+ buffer = lines.pop();77+ for (const line of lines) {78+ if (!line.trim()) continue;79+ const message = parse(line);80+ if (replay !== null && message?.id === replay) {
- @@ -0,0 +225,21 @@225+ Effect.provideService(FileSystem.FileSystem, fs),226+ Effect.provideService(Path.Path, path),227+ Effect.provideService(ProcessRunner.ProcessRunner, runner),228+ Effect.provideService(HostProcessPlatform, platform),229+ Effect.provideService(HostProcessEnvironment, environment),230+ );231+232+ const cuaDriver = provide(resolveCuaDriverPath());233+ const browsers = provide(detectBrowsers());234+ const installedChromeDevTools = provide(findPinnedTool(config.baseDir, CHROME_DEVTOOLS_MCP));235+236+ /** Unverified grants read as false; `permissions grant` verifies them. */237+ const cuaPermissions = (driverPath: string) =>238+ runner.run({ command: driverPath, args: ["permissions", "status", "--json"] }).pipe(239+ Effect.flatMap((result) => decodeCuaPermissions(result.stdout)),240+ Effect.map((granted) => ({241+ accessibility: granted.accessibility === true,242+ screenRecording: granted.screen_recording === true,243+ })),244+ Effect.orElseSucceed(() => ({ accessibility: false, screenRecording: false })),245+ );@@ -0,0 +54,21 @@54+// Requests the old child never answered fail, so the provider is not left waiting.55+function failPending() {56+ for (const id of pending) {57+ const message = "Computer use stopped. Call the tool again to start a new session.";58+ process.stdout.write(JSON.stringify({ jsonrpc: "2.0", id, error: { code: -32000, message } }) + "\\n");59+ }60+ pending.clear();61+ queue = [];62+}63+64+function start() {65+ const current = spawn(driver, ["mcp"], { stdio: ["pipe", "pipe", "inherit"] });66+ let replay = restarted && initialize ? "t3-replay-" + ++replayCount : null;67+ child = current;68+ ready = replay === null;69+ let buffer = "";70+ current.stdin.on("error", () => {});71+ current.stdout.on("data", (chunk) => {72+ // A replaced driver can still flush output; its calls were already failed.73+ if (child !== current) return;74+ buffer += chunk;@@ -7131,3 +7133,5 @@71317133 },71327134 })71337135 : null;7136+ const usingComputer = useMemo(7137+ () => isRunUsingComputer(serverProjection?.turnItems ?? [], activeRunningTurnId),@@ -0,0 +87,21 @@87+ const timer = requesting ? window.setInterval(refresh, 2000) : undefined;88+ return () => {89+ window.removeEventListener("focus", refresh);90+ window.clearInterval(timer);91+ };92+ }, [requesting]);93+94+ // Whether this dialog started a permission request. Set as soon as Start is95+ // pressed, since the status that reports the request can arrive after the96+ // dialog closes.97+ const requestStarted = useRef(false);98+ const runAction = async (action: ServerComputerAccessAction) => {99+ if (action === "request-cua-permissions") requestStarted.current = true;100+ setPending(action);101+ setError(null);102+ const result = await run({ environmentId, input: { action } });103+ setPending(null);104+ if (result._tag === "Failure") setError(ACTION_FAILURES[action]);105+ onRefresh();106+ return result._tag !== "Failure";107+ };
juliusmarminge closed this
Sign in to join this conversation.

macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed