Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,21 @@ function ServerSettingsDetail(props: { readonly page: SettingsPage }) {
onValueChange={(value) => write({ enableAgentBrowserAccess: value })}
/>
</SettingsSection>
<SettingsSection title={gt("Computer")}>
<SettingsSwitchRow
icon="desktopcomputer"
label={gt("Computer use")}
subtitle={managedSubtitle(
"enableCua",
gt(
"Allow agents to use apps on the selected environments' computers through Cua Driver. On macOS, grant Accessibility and Screen Recording on each host.",
),
)}
value={uniform("enableCua")}
disabled={disabledFor("enableCua")}
onValueChange={(value) => write({ enableCua: value })}
/>
</SettingsSection>
<AutoSettleSettingsRows write={write} pending={pendingWrites > 0} />
</>
) : null}
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -3535,6 +3535,8 @@
"006f2c2416a56768": "Vorschau-Browser",
"19e1f74805f4a1fb": "Browserzugriff für Agenten",
"74d09db9719594eb": "Agenten den In-App-Vorschau-Browser nutzen lassen.",
"5511e975ba69f726": "Computer",
"53d1d96a2699764a": "Agenten über Cua Driver Apps auf den Computern der ausgewählten Umgebungen nutzen lassen. Erteile unter macOS auf jedem Host Barrierefreiheit und Bildschirmaufnahme.",
"13087312bc6a0b45": "Pull Requests",
"efb65f53a2382026": "Agenten-Credits beim Mergen entfernen",
"88631d9ea293eccd": "Erkannte Agenten-Credits aus Merge- und Squash-Nachrichten entfernen, sofern der Host das unterstützt; menschliche Co-Autoren bleiben erhalten. Gilt auch für Auto-Merge. Ausgenommen sind Merge-Queues, Stack-Merges und bestehende Commits.",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3536,6 +3536,8 @@
"006f2c2416a56768": "Preview browser",
"19e1f74805f4a1fb": "Agent browser access",
"74d09db9719594eb": "Allow agents to use the in-app preview browser.",
"5511e975ba69f726": "Computer",
"53d1d96a2699764a": "Allow agents to use apps on the selected environments' computers through Cua Driver. On macOS, grant Accessibility and Screen Recording on each host.",
"13087312bc6a0b45": "Pull requests",
"efb65f53a2382026": "Remove agent credits when merging",
"88631d9ea293eccd": "Remove recognized agent credits from merge and squash messages on hosts that support it, keeping human co-authors. Includes auto-merge. Excludes merge queues, stack merges, and existing commits.",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -3530,6 +3530,8 @@
"006f2c2416a56768": "Navegador de vista previa",
"19e1f74805f4a1fb": "Acceso de agentes al navegador",
"74d09db9719594eb": "Permite que los agentes usen el navegador de vista previa de la app.",
"5511e975ba69f726": "Ordenador",
"53d1d96a2699764a": "Permite que los agentes usen apps en los ordenadores de los entornos seleccionados mediante Cua Driver. En macOS, concede Accesibilidad y Grabación de pantalla en cada host.",
"13087312bc6a0b45": "Pull requests",
"efb65f53a2382026": "Quitar créditos de agentes al fusionar",
"88631d9ea293eccd": "Quita los créditos de agentes reconocidos de los mensajes de fusión y squash en los hosts compatibles, manteniendo a los coautores humanos. Incluye la fusión automática. Excluye las colas de fusión, las fusiones de pilas y los commits existentes.",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -3530,6 +3530,8 @@
"006f2c2416a56768": "Navigateur d’aperçu",
"19e1f74805f4a1fb": "Accès des agents au navigateur",
"74d09db9719594eb": "Autorise les agents à utiliser le navigateur d’aperçu intégré.",
"5511e975ba69f726": "Ordinateur",
"53d1d96a2699764a": "Autorise les agents à utiliser les apps des ordinateurs des environnements sélectionnés via Cua Driver. Sous macOS, accordez l’Accessibilité et l’Enregistrement de l’écran sur chaque hôte.",
"13087312bc6a0b45": "Pull requests",
"efb65f53a2382026": "Retirer les crédits d’agent lors de la fusion",
"88631d9ea293eccd": "Retire les crédits d’agent reconnus des messages de fusion et de squash sur les hébergeurs qui le permettent, en gardant les co-auteurs humains. Inclut la fusion automatique. Exclut les files de fusion, les fusions de pile et les commits existants.",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -3527,6 +3527,8 @@
"006f2c2416a56768": "プレビューブラウザー",
"19e1f74805f4a1fb": "エージェントのブラウザーアクセス",
"74d09db9719594eb": "エージェントにアプリ内のプレビューブラウザーの使用を許可します。",
"5511e975ba69f726": "コンピューター",
"53d1d96a2699764a": "Cua Driver を通じて、選択した環境のコンピューター上のアプリをエージェントが使えるようにします。macOS では、各ホストでアクセシビリティと画面収録を許可してください。",
"13087312bc6a0b45": "プルリクエスト",
"efb65f53a2382026": "マージ時にエージェントのクレジットを削除",
"88631d9ea293eccd": "対応しているホストでは、マージとスカッシュのメッセージから認識されたエージェントのクレジットを削除し、人間の共同作成者は残します。自動マージにも適用されます。マージキュー、スタックのマージ、既存のコミットは対象外です。",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -3531,6 +3531,8 @@
"006f2c2416a56768": "미리 보기 브라우저",
"19e1f74805f4a1fb": "에이전트 브라우저 액세스",
"74d09db9719594eb": "에이전트가 앱 내 미리 보기 브라우저를 사용하도록 허용합니다.",
"5511e975ba69f726": "컴퓨터",
"53d1d96a2699764a": "에이전트가 Cua Driver를 통해 선택한 환경의 컴퓨터에서 앱을 사용할 수 있게 합니다. macOS에서는 각 호스트에서 손쉬운 사용과 화면 녹화 권한을 허용하세요.",
"13087312bc6a0b45": "풀 리퀘스트",
"efb65f53a2382026": "병합 시 에이전트 크레딧 제거",
"88631d9ea293eccd": "지원하는 호스트에서 병합 및 스쿼시 메시지에 포함된 에이전트 크레딧을 제거하고 사람 공동 작성자는 유지합니다. 자동 병합에도 적용됩니다. 병합 큐, 스택 병합, 기존 커밋은 제외됩니다.",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -3530,6 +3530,8 @@
"006f2c2416a56768": "Navegador de pré-visualização",
"19e1f74805f4a1fb": "Acesso dos agentes ao navegador",
"74d09db9719594eb": "Permite que os agentes usem o navegador de pré-visualização do app.",
"5511e975ba69f726": "Computador",
"53d1d96a2699764a": "Permite que agentes usem apps nos computadores dos ambientes selecionados pelo Cua Driver. No macOS, conceda Acessibilidade e Gravação de Tela em cada host.",
"13087312bc6a0b45": "Pull requests",
"efb65f53a2382026": "Remover créditos de agentes ao mesclar",
"88631d9ea293eccd": "Remove os créditos de agentes reconhecidos das mensagens de merge e squash nos hosts que oferecem suporte, mantendo os coautores humanos. Inclui o auto-merge. Exclui merge queues, merges de stack e commits existentes.",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -3584,6 +3584,8 @@
"006f2c2416a56768": "Браузер предпросмотра",
"19e1f74805f4a1fb": "Доступ агентов к браузеру",
"74d09db9719594eb": "Разрешить агентам использовать встроенный браузер предпросмотра.",
"5511e975ba69f726": "Компьютер",
"53d1d96a2699764a": "Разрешить агентам использовать приложения на компьютерах выбранных окружений через Cua Driver. В macOS предоставьте «Специальные возможности» и «Запись экрана» на каждом хосте.",
"13087312bc6a0b45": "Пул-реквесты",
"efb65f53a2382026": "Удалять авторство агентов при слиянии",
"88631d9ea293eccd": "Удалять распознанное авторство агентов из сообщений merge и squash на хостингах, которые это поддерживают, сохраняя соавторов-людей. Включая автослияние. Не касается очередей слияния, слияний стеков и существующих коммитов.",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -3536,6 +3536,8 @@
"006f2c2416a56768": "Förhandsvisningswebbläsare",
"19e1f74805f4a1fb": "Agenters webbläsaråtkomst",
"74d09db9719594eb": "Låt agenter använda förhandsvisningswebbläsaren i appen.",
"5511e975ba69f726": "Dator",
"53d1d96a2699764a": "Låt agenter använda appar på de valda miljöernas datorer via Cua Driver. På macOS, ge Tillgänglighet och Skärminspelning på varje värd.",
"13087312bc6a0b45": "Pull requests",
"efb65f53a2382026": "Ta bort agentmedförfattare vid merge",
"88631d9ea293eccd": "Ta bort igenkända agentmedförfattare från merge- och squash-meddelanden hos värdar som stöder det, och behåll mänskliga medförfattare. Gäller även automatisk merge. Gäller inte merge-köer, stack-merges och befintliga commits.",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -3532,6 +3532,8 @@
"006f2c2416a56768": "预览浏览器",
"19e1f74805f4a1fb": "智能体浏览器访问",
"74d09db9719594eb": "允许智能体使用应用内预览浏览器。",
"5511e975ba69f726": "计算机",
"53d1d96a2699764a": "允许智能体通过 Cua Driver 使用所选环境计算机上的应用。在 macOS 上,请在每台主机上授予辅助功能和屏幕录制权限。",
"13087312bc6a0b45": "PR",
"efb65f53a2382026": "合并时移除智能体署名",
"88631d9ea293eccd": "在支持的托管平台上,从合并和压缩合并的提交信息中移除可识别的智能体署名,保留人类共同作者。包括自动合并。不包括合并队列、堆叠合并和已有提交。",
Expand Down
26 changes: 26 additions & 0 deletions apps/server/src/auth/RpcAuthorization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Stream from "effect/Stream";
import * as RpcTest from "effect/rpc/RpcTest";
import { applyServerSettingsPatch } from "@t3tools/shared/serverSettings";

import {
RPC_REQUIRED_SCOPES,
Expand Down Expand Up @@ -266,6 +267,31 @@ describe("settings mutation authorization", () => {
instanceId: ProviderInstanceId.make("codex_work"),
};

it.effect("restores computer use alongside duration settings through authorization", () =>
Effect.gen(function* () {
const client = yield* RpcTest.makeClient(group).pipe(
Effect.provide(
Layer.mergeAll(
group.toLayerHandler(WS_METHODS.serverUpdateSettings, ({ patch }) =>
Effect.succeed(
applyServerSettingsPatch({ ...DEFAULT_SERVER_SETTINGS, enableCua: true }, patch),
),
),
RpcAuthorization.layer([AuthSettingsWriteScope]),
),
),
);
const defaults = {
enableCua: DEFAULT_SERVER_SETTINGS.enableCua,
automaticGitFetchInterval: DEFAULT_SERVER_SETTINGS.automaticGitFetchInterval,
providerHealthRefreshInterval: DEFAULT_SERVER_SETTINGS.providerHealthRefreshInterval,
};
expect(yield* client[WS_METHODS.serverUpdateSettings]({ patch: defaults })).toMatchObject(
defaults,
);
}).pipe(Effect.scoped),
);

it.effect("allows provider-only mutations while denying mixed settings without their grant", () =>
Effect.gen(function* () {
let handled = 0;
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/auth/RpcAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const RPC_REQUIRED_SCOPES = {
[WS_METHODS.serverProbe]: AuthOrchestrationReadScope,
[WS_METHODS.serverGetConfig]: AuthOrchestrationReadScope,
[WS_METHODS.serverGetNpmRelease]: AuthOrchestrationReadScope,
[WS_METHODS.serverCheckComputerUse]: AuthOrchestrationReadScope,
[WS_METHODS.serverRefreshProviders]: AuthOrchestrationReadScope,
[WS_METHODS.serverUpdateProvider]: AuthProvidersManageScope,
[WS_METHODS.providerAuthStart]: AuthProvidersManageScope,
Expand Down
67 changes: 67 additions & 0 deletions apps/server/src/cua/CuaDriver.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
import { it } from "@effect/vitest";
import type { CuaDriverMcpConfiguration, DesktopCuaDriverReport } from "@t3tools/contracts";
import * as HostProcess from "@t3tools/shared/HostProcess";
import type { EmbeddedDriverConnection } from "@trycua/cua-driver/embedded";
import { Deferred, Effect, Exit, Fiber, Option, PubSub, Ref, Scope, Stream } from "effect";
import { TestClock } from "effect/testing";
Expand Down Expand Up @@ -501,8 +502,10 @@ describe("CuaDriver", () => {
yield* Deferred.succeed(f.result, mcp);
expect(yield* f.service.acquire).toEqual(Option.some(mcp));
yield* Deferred.await(f.watching);
expect((yield* f.service.status).running).toBe(true);
yield* Deferred.succeed(f.exited, undefined);
yield* Deferred.await(f.stopped);
expect((yield* f.service.status).running).toBe(false);
expect(f.starts()).toBe(1);
expect(yield* f.service.acquire).toEqual(Option.some(mcp));
expect(f.starts()).toBe(2);
Expand Down Expand Up @@ -543,6 +546,70 @@ describe("CuaDriver", () => {
});

describe("Cua Driver readiness", () => {
it.effect("reports the host platform and runs only between readiness and disable", () =>
Effect.scoped(
Effect.gen(function* () {
const f = yield* fixture(false).pipe(Effect.provideService(HostProcess.Platform, "darwin"));
expect(yield* f.service.status).toEqual({ platform: "darwin", running: false });
yield* f.setEnabled(true);
const caller = yield* f.service.acquire.pipe(Effect.forkChild);
yield* Deferred.await(f.started);
expect(yield* f.service.status).toEqual({ platform: "darwin", running: false });
yield* Deferred.succeed(f.result, mcp);
expect(yield* Fiber.join(caller)).toEqual(Option.some(mcp));
expect(yield* f.service.status).toEqual({ platform: "darwin", running: true });
yield* f.setEnabled(false);
yield* Deferred.await(f.stopped);
expect(yield* f.service.status).toEqual({ platform: "darwin", running: false });
expect(yield* f.service.acquire).toEqual(Option.none());
}),
),
);

it.effect("reports a host start failure until the replacement is ready", () =>
Effect.scoped(
Effect.gen(function* () {
const failure = new CuaDriver.CuaDriverStartError({
binaryPath: "/driver",
cause: new Error("native start failed"),
});
const restarting = yield* Deferred.make<void>();
const ready = yield* Deferred.make<CuaDriverMcpConfiguration>();
let attempts = 0;
const service = yield* makeCuaDriver({
enabled: Effect.succeed(true),
changes: Stream.empty,
createHost: Effect.sync(() => ({
start:
++attempts === 1
? Effect.fail(failure)
: Deferred.succeed(restarting, undefined).pipe(
Effect.andThen(Deferred.await(ready)),
),
stop: Effect.void,
waitForExit: Effect.never,
})),
}).pipe(Effect.provideService(HostProcess.Platform, "win32"));
expect(yield* service.acquire).toEqual(Option.none());
expect(yield* service.status).toEqual({
platform: "win32",
running: false,
failure: failure.message,
});
const retry = yield* service.acquire.pipe(Effect.forkChild);
yield* Deferred.await(restarting);
expect(yield* service.status).toEqual({
platform: "win32",
running: false,
failure: failure.message,
});
yield* Deferred.succeed(ready, mcp);
expect(yield* Fiber.join(retry)).toEqual(Option.some(mcp));
expect(yield* service.status).toEqual({ platform: "win32", running: true });
}),
),
);

it.effect("remembers why the last start failed until a start succeeds", () =>
Effect.scoped(
Effect.gen(function* () {
Expand Down
18 changes: 17 additions & 1 deletion apps/server/src/cua/CuaDriver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import * as NodeModule from "node:module";

import type { CuaDriverMcpConfiguration, DesktopCuaDriverReport } from "@t3tools/contracts";
import type {
CuaDriverMcpConfiguration,
CuaHostStatus,
DesktopCuaDriverReport,
} from "@t3tools/contracts";
import * as HostProcess from "@t3tools/shared/HostProcess";
import type { EmbeddedCuaDriverHost, EmbeddedDriverConnection } from "@trycua/cua-driver/embedded";
import * as Config from "effect/Config";
import * as Context from "effect/Context";
Expand Down Expand Up @@ -145,6 +150,7 @@ export class CuaDriver extends Context.Service<
readonly acquire: Effect.Effect<Option.Option<CuaDriverMcpConfiguration>>;
/** Why the last start failed, until a later start succeeds. */
readonly lastFailure: Effect.Effect<Option.Option<string>>;
readonly status: Effect.Effect<CuaHostStatus>;
}
>()("t3/cua/CuaDriver") {}

Expand Down Expand Up @@ -176,6 +182,8 @@ export const make = Effect.fn("CuaDriver.make")(function* (
stopped?: boolean;
/** Message of the typed error that ended this attempt, for the readiness signal. */
failure?: string;
/** Set once the host reported its MCP descriptor. */
running?: boolean;
};
let current: Attempt | undefined;
let closed = false;
Expand Down Expand Up @@ -242,6 +250,7 @@ export const make = Effect.fn("CuaDriver.make")(function* (
return;
}
lastFailure = undefined;
attempt.running = true;
yield* Deferred.succeed(attempt.ready, Option.some(mcp));
}),
);
Expand Down Expand Up @@ -291,10 +300,17 @@ export const make = Effect.fn("CuaDriver.make")(function* (
return attempt ? yield* Deferred.await(attempt.ready) : Option.none();
});

const platform = yield* HostProcess.Platform;
return CuaDriver.of({
enabled: enabled,
acquire,
lastFailure: Effect.sync(() => Option.fromNullishOr(lastFailure)),
status: Effect.sync(() => ({
platform:
platform === "darwin" || platform === "linux" || platform === "win32" ? platform : "other",
running: current?.running === true,
...(lastFailure === undefined ? {} : { failure: lastFailure }),
})),
});
});

Expand Down
1 change: 1 addition & 0 deletions apps/server/src/observability/RpcInstrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const RPC_AGGREGATES = {
[ORCHESTRATION_V2_WS_METHODS.subscribePromptSuggestion]: "orchestrationV2",
[WS_METHODS.projectsMutate]: "orchestration",
[WS_METHODS.serverProbe]: "server",
[WS_METHODS.serverCheckComputerUse]: "server",
[WS_METHODS.serverGetConfig]: "server",
[WS_METHODS.serverGetNpmRelease]: "server",
[WS_METHODS.serverRefreshProviders]: "server",
Expand Down
9 changes: 9 additions & 0 deletions apps/server/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ import { makePrepareTerminalLaunch } from "./workspace/restoreMissingWorktree.ts
import { terminalOutputStream, withOutputWindow } from "./terminal/OutputProtocol.ts";
import * as ServerBrowser from "./preview/ServerBrowser.ts";
import * as DeviceService from "./device/DeviceService.ts";
import * as CuaDriver from "./cua/CuaDriver.ts";
import { remoteSshDeviceHosts } from "./device/localSshDeviceHost.ts";
import * as PreviewManager from "./preview/Manager.ts";
import { issueAssetUrl } from "./assets/AssetAccess.ts";
Expand Down Expand Up @@ -2360,6 +2361,14 @@ export const layerWsRpc = (
Effect.andThen(scheduledTasks.getWebhookDelivery(input)),
),
[WS_METHODS.serverProbe]: (_input) => Effect.succeed({}),
[WS_METHODS.serverCheckComputerUse]: (_input) =>
Effect.serviceOption(CuaDriver.CuaDriver).pipe(
Effect.flatMap((driver) =>
Option.isSome(driver)
? driver.value.status
: Effect.succeed({ platform: "other", running: false } as const),
),
),
[WS_METHODS.serverGetConfig]: (_input) =>
loadServerConfig({
usageLimitsCommand: false,
Expand Down
Loading
Loading