feat: let Claude and other agents use apps and browser tabs on your Mac #14523
Closedt3dotgg(GitHub profile, opens in a new tab)wants to merge 5 commits into
main fromt3code/investigate-computer-use-integrationsopened View on GitHubt3dotgg(GitHub profile, opens in a new tab) added labelsWIP
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/server/src/mcp/ComputerAccess.ts lines 363 to 370OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +350,21 @@350+ },351+ browsers: (yield* browsers).map(({ id, name, inspectUrl, remoteDebugging }) => ({352+ id,353+ name,354+ inspectUrl,355+ remoteDebugging,356+ })),357+ browserToolError,358+ };359+ });360+361+ const runChecked = (input: ProcessRunner.ProcessRunInput, failure: string) =>362+ runner.run(input).pipe(363+ Effect.mapError(364+ (cause) => new ServerComputerAccessError({ detail: `${failure} ${cause.message}` }),365+ ),366+ Effect.flatMap((result) =>367+ result.code === 0368+ ? Effect.void369+ : Effect.fail(370+ new ServerComputerAccessError({ detail: `${failure}\n${outputTail(result)}` }),
- apps/web/src/components/settings/ComputerAccessSetupDialog.tsx lines 74 to 87Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +64,21 @@64+}) {65+ const run = useAtomCommand(serverEnvironment.runComputerAccessAction, { reportFailure: false });66+ const [pending, setPending] = useState<ServerComputerAccessAction | null>(null);67+ const [error, setError] = useState<string | null>(null);68+ const busy = pending !== null;69+ const requesting = status?.cuaDriver.requestingPermissions ?? false;70+71+ // The user grants access in System Settings or the browser, then comes back.72+ // While Cua waits on the user, status is also polled.73+ const refreshLatest = useEffectEvent(() => {74+ if (!busy) onRefresh();75+ });76+ useEffect(() => {77+ const refresh = () => refreshLatest();78+ window.addEventListener("focus", refresh);79+ const timer = requesting ? window.setInterval(refresh, 2000) : undefined;80+ return () => {81+ window.removeEventListener("focus", refresh);82+ window.clearInterval(timer);83+ };84+ }, [requesting]);apps/server/src/provider/Layers/ProviderService.ts line 1167Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1117,3 +1152,9 @@11171152 provider: canonicalEvent.provider,11181153 eventType: canonicalEvent.type,11191154 });1155+ if (1156+ canonicalEvent.type === "turn.completed" ||1157+ canonicalEvent.type === "turn.aborted" ||1158+ canonicalEvent.type === "runtime.error"1159+ ) {1160+ yield* endComputerSession(canonicalEvent.threadId);apps/web/src/components/settings/IntegrationsSettings.tsx line 975OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -856,0 +955,21 @@955+ </>956+ );957+958+ return (959+ <SettingsSection id="computer" title="Computer">960+ {macHost || environmentId === null ? (961+ rows962+ ) : (963+ <SettingsUnavailableGroup message="Available on macOS for now.">964+ {rows}965+ </SettingsUnavailableGroup>966+ )}967+ {setup && environmentId ? (968+ <ComputerAccessSetupDialog969+ kind={setup}970+ environmentId={environmentId}971+ hostLabel={hostLabel}972+ status={status}973+ onRefresh={refresh}974+ onFinish={() => {975+ updateSettings(apps/server/src/mcp/CuaMcpProxy.ts lines 87 to 87OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +67,21 @@67+ current.stdin.on("error", () => {});68+ current.stdout.on("data", (chunk) => {69+ buffer += chunk;70+ const lines = buffer.split("\\n");71+ buffer = lines.pop();72+ for (const line of lines) {73+ if (!line.trim()) continue;74+ const message = parse(line);75+ if (replay !== null && message?.id === replay) {76+ if (initialized) {77+ current.stdin.write(JSON.stringify({ jsonrpc: "2.0", method: "notifications/initialized" }) + "\\n");78+ }79+ ready = true;80+ flush();81+ continue;82+ }83+ if (message !== null && "id" in message && !("method" in message)) pending.delete(message.id);84+ process.stdout.write(line + "\\n");85+ }86+ });87+ current.on("exit", () => {
- apps/server/src/mcp/ComputerAccess.ts line 235Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +216,21 @@216+export const make = Effect.gen(function* () {217+ const config = yield* ServerConfig;218+ const settings = yield* ServerSettings.ServerSettingsService;219+ const fs = yield* FileSystem.FileSystem;220+ const path = yield* Path.Path;221+ const runner = yield* ProcessRunner.ProcessRunner;222+ const platform = yield* HostProcessPlatform;223+ const scope = yield* Scope.Scope;224+ const actionLock = yield* Semaphore.make(1);225+ // `cua-driver permissions grant` waits up to minutes for the user, so it226+ // runs in the background while the setup dialog polls status.227+ let permissionRequest: Fiber.Fiber<void> | undefined;228+ let permissionRequestId = 0;229+ let requestingPermissions = false;230+ let permissionsError: string | null = null;231+ const provide = <A, E, R>(effect: Effect.Effect<A, E, R>) =>232+ effect.pipe(233+ Effect.provideService(FileSystem.FileSystem, fs),234+ Effect.provideService(Path.Path, path),235+ Effect.provideService(ProcessRunner.ProcessRunner, runner),236+ );
- apps/server/src/mcp/ComputerAccess.ts line 217OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +197,21 @@197+ {198+ /** Servers to attach to a thread's new session. A server that cannot start is left out. */199+ readonly servers: (200+ access: ComputerAccessSettings,201+ threadId: string,202+ ) => Effect.Effect<ReadonlyArray<LocalMcpServer>>;203+ /** What the setup flows show. Installs Chrome DevTools MCP when browser tab access is on. */204+ readonly status: Effect.Effect<ServerComputerAccessStatus, ServerSettingsError>;205+ readonly runAction: (206+ action: ServerComputerAccessAction,207+ ) => Effect.Effect<ServerComputerAccessStatus, ServerComputerAccessError | ServerSettingsError>;208+ /**209+ * Ends the thread's Cua session, which removes its cursor. Called at turn210+ * end, on Stop, and on errors; the next tool call starts a new session.211+ */212+ readonly endSession: (threadId: string) => Effect.Effect<void>;213+ }214+>()("t3/mcp/ComputerAccess") {}215+216+export const make = Effect.gen(function* () {217+ const config = yield* ServerConfig;
- apps/web/src/components/settings/ComputerAccessSetupDialog.tsx line 177Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +137,21 @@137+ pending,138+ error,139+ onAction,140+ onFinish,141+ onClose,142+}: {143+ hostLabel: string;144+ status: ServerComputerAccessStatus | null;145+ pending: ServerComputerAccessAction | null;146+ error: string | null;147+ onAction: (action: ServerComputerAccessAction) => void;148+ onFinish: () => void;149+ onClose: () => void;150+}) {151+ const driver = status?.cuaDriver;152+ const installed = Boolean(driver?.path);153+ const permissions = driver?.permissions;154+ const [stepChoice, setStepChoice] = useState<number | null>(null);155+ // Open on the first step that still needs the user, until they pick one.156+ const step = stepChoice ?? (installed ? 1 : 0);157+ const loading = status === null;apps/web/src/components/settings/ComputerAccessSetupDialog.tsx line 348OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +328,21 @@328+ className="flex items-center gap-3 rounded-lg border px-3 py-2"329+ >330+ <div className="min-w-0 flex-1">331+ <p className="font-medium">{browser.name}</p>332+ {browser.remoteDebugging ? null : (333+ <p className="truncate font-mono text-xs text-muted-foreground">334+ {browser.inspectUrl}335+ </p>336+ )}337+ </div>338+ {browser.remoteDebugging ? (339+ <span role="status" className="flex items-center gap-1 text-xs text-success">340+ <CircleCheckIcon className="size-4" aria-hidden="true" />341+ On342+ </span>343+ ) : (344+ <Button345+ size="xs"346+ variant="outline"347+ onClick={() => {348+ setCopiedUrl(browser.inspectUrl);apps/server/src/mcp/ComputerAccess.ts lines 308 to 308Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +288,21 @@288+ if (platform !== "darwin") return result;289+ if (access.apps) {290+ const driverPath = yield* cuaDriver;291+ if (driverPath) {292+ result.push({293+ name: "cua-driver",294+ ...(yield* cuaServer(driverPath, threadId)),295+ instructions: CUA_DRIVER_INSTRUCTIONS,296+ });297+ } else {298+ yield* Effect.logWarning("Computer access is on, but Cua Driver is not installed.");299+ }300+ }301+ if (access.browserTabs) {302+ const tool = yield* chromeDevTools.pipe(303+ Effect.catch((cause) =>304+ Effect.logWarning("Chrome DevTools MCP is unavailable.", { cause }).pipe(Effect.as(null)),305+ ),306+ );307+ // Without a browser in remote debugging mode, fall back to Chrome's profile.308+ const browser = (yield* browsers).find((candidate) => candidate.remoteDebugging);apps/server/src/mcp/CuaMcpProxy.ts lines 63 to 81OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +61,21 @@61+function start() {62+ const current = spawn(driver, ["mcp"], { stdio: ["pipe", "pipe", "inherit"] });63+ const replay = restarted && initialize ? "t3-replay-" + ++replayCount : null;64+ child = current;65+ ready = replay === null;66+ let buffer = "";67+ current.stdin.on("error", () => {});68+ current.stdout.on("data", (chunk) => {69+ buffer += chunk;70+ const lines = buffer.split("\\n");71+ buffer = lines.pop();72+ for (const line of lines) {73+ if (!line.trim()) continue;74+ const message = parse(line);75+ if (replay !== null && message?.id === replay) {76+ if (initialized) {77+ current.stdin.write(JSON.stringify({ jsonrpc: "2.0", method: "notifications/initialized" }) + "\\n");78+ }79+ ready = true;80+ flush();81+ continue;
- apps/server/src/mcp/CuaMcpProxy.ts lines 68 to 68Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -0,0 +48,21 @@48+};49+const isRequest = (message) => message !== null && "id" in message && "method" in message;50+51+// Requests the old child never answered fail, so the provider is not left waiting.52+function failPending() {53+ for (const id of pending) {54+ const message = "Computer use stopped. Call the tool again to start a new session.";55+ process.stdout.write(JSON.stringify({ jsonrpc: "2.0", id, error: { code: -32000, message } }) + "\\n");56+ }57+ pending.clear();58+ queue = [];59+}60+61+function start() {62+ const current = spawn(driver, ["mcp"], { stdio: ["pipe", "pipe", "inherit"] });63+ let replay = restarted && initialize ? "t3-replay-" + ++replayCount : null;64+ child = current;65+ ready = replay === null;66+ let buffer = "";67+ current.stdin.on("error", () => {});68+ current.stdout.on("data", (chunk) => {
- @@ -0,0 +119,21 @@119+120+function end() {121+ const current = child;122+ child = null;123+ restarted = true;124+ current?.kill();125+ failPending();126+}127+128+function shutdown() {129+ child?.kill();130+ if (!process.platform.startsWith("win")) rmSync(controlPath, { force: true });131+ process.exit(0);132+}133+134+if (!process.platform.startsWith("win")) rmSync(controlPath, { force: true });135+// A connection is the whole message: end the session.136+createServer((socket) => {137+ socket.destroy();138+ end();139+}).listen(controlPath);@@ -0,0 +82,21 @@82+ const timer = requesting ? window.setInterval(refresh, 2000) : undefined;83+ return () => {84+ window.removeEventListener("focus", refresh);85+ window.clearInterval(timer);86+ };87+ }, [requesting]);88+89+ const runAction = async (action: ServerComputerAccessAction) => {90+ setPending(action);91+ setError(null);92+ const result = await run({ environmentId, input: { action } });93+ setPending(null);94+ if (result._tag === "Failure") setError(ACTION_FAILURES[action]);95+ onRefresh();96+ };97+ // A request left running would keep waiting on the user for minutes, so98+ // the dialog cancels it when it closes for any reason.99+ const cancelRequest = useEffectEvent(() => {100+ if (requesting) void run({ environmentId, input: { action: "cancel-cua-permissions" } });101+ });102+ useEffect(() => () => cancelRequest(), []);
juliusmarminge closed this
Sign in to join this conversation.

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