From 7addf7c6d6f0fa33d59d84c023859ba8da18ac93 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 18 Jun 2026 22:00:25 -0700 Subject: [PATCH] Remove legacy local backend and telemetry RPC - drop browser-only local backend stubs in favor of desktop bridge - route resource telemetry through the subscription path --- apps/server/src/server.test.ts | 17 +++ apps/server/src/ws.ts | 5 - apps/web/src/env.ts | 6 +- apps/web/src/localApi.test.ts | 19 +-- apps/web/src/localApi.ts | 29 +--- apps/web/src/vite-env.d.ts | 3 +- packages/contracts/src/ipc.ts | 264 +-------------------------------- packages/contracts/src/rpc.ts | 8 - 8 files changed, 26 insertions(+), 325 deletions(-) diff --git a/apps/server/src/server.test.ts b/apps/server/src/server.test.ts index f084b89a2f..5adc814c7f 100644 --- a/apps/server/src/server.test.ts +++ b/apps/server/src/server.test.ts @@ -4272,6 +4272,23 @@ it.layer(NodeServices.layer)("server router seam", (it) => { }).pipe(Effect.provide(NodeHttpServer.layerTest)), ); + it.effect("routes websocket resource telemetry through the subscription", () => + Effect.gen(function* () { + yield* buildAppUnderTest(); + + const wsUrl = yield* getWsServerUrl("/ws"); + const snapshot = yield* Effect.scoped( + withWsRpcClient(wsUrl, (client) => + client[WS_METHODS.subscribeResourceTelemetry]({}).pipe(Stream.runHead), + ), + ); + + assertTrue(Option.isSome(snapshot)); + assert.equal(snapshot.value.processes.length, 0); + assert.equal(snapshot.value.groups.backend.processCount, 0); + }).pipe(Effect.provide(NodeHttpServer.layerTest)), + ); + it.effect("routes websocket rpc subscribeServerConfig emits provider status updates", () => Effect.gen(function* () { const nextProviders = [ diff --git a/apps/server/src/ws.ts b/apps/server/src/ws.ts index 57822a2e73..db2475e8d3 100644 --- a/apps/server/src/ws.ts +++ b/apps/server/src/ws.ts @@ -160,7 +160,6 @@ const RPC_REQUIRED_SCOPE = new Map([ [WS_METHODS.serverGetTraceDiagnostics, AuthOrchestrationReadScope], [WS_METHODS.serverGetProcessDiagnostics, AuthOrchestrationReadScope], [WS_METHODS.serverGetProcessResourceHistory, AuthOrchestrationReadScope], - [WS_METHODS.serverGetResourceTelemetry, AuthOrchestrationReadScope], [WS_METHODS.serverGetResourceTelemetryHistory, AuthOrchestrationReadScope], [WS_METHODS.serverRetryResourceTelemetry, AuthOrchestrationOperateScope], [WS_METHODS.serverSignalProcess, AuthOrchestrationOperateScope], @@ -1124,10 +1123,6 @@ const makeWsRpcLayer = (currentSession: AuthenticatedSession) => "rpc.aggregate": "server", }, ), - [WS_METHODS.serverGetResourceTelemetry]: (_input) => - observeRpcEffect(WS_METHODS.serverGetResourceTelemetry, resourceTelemetry.latest, { - "rpc.aggregate": "server", - }), [WS_METHODS.serverGetResourceTelemetryHistory]: (input) => observeRpcEffect( WS_METHODS.serverGetResourceTelemetryHistory, diff --git a/apps/web/src/env.ts b/apps/web/src/env.ts index fb2e493cad..2e08dd3369 100644 --- a/apps/web/src/env.ts +++ b/apps/web/src/env.ts @@ -1,8 +1,6 @@ /** * True when running inside the Electron preload bridge, false in a regular browser. - * The preload script sets window.nativeApi via contextBridge before any web-app + * The preload script sets window.desktopBridge via contextBridge before any web-app * code executes, so this is reliable at module load time. */ -export const isElectron = - typeof window !== "undefined" && - (window.desktopBridge !== undefined || window.nativeApi !== undefined); +export const isElectron = typeof window !== "undefined" && window.desktopBridge !== undefined; diff --git a/apps/web/src/localApi.test.ts b/apps/web/src/localApi.test.ts index 3379f5ed98..260256c125 100644 --- a/apps/web/src/localApi.test.ts +++ b/apps/web/src/localApi.test.ts @@ -49,7 +49,6 @@ beforeEach(() => { }); } Reflect.deleteProperty(testWindow(), "desktopBridge"); - Reflect.deleteProperty(testWindow(), "nativeApi"); Object.defineProperty(testWindow(), "localStorage", { configurable: true, value: createLocalStorageStub(), @@ -61,16 +60,12 @@ afterEach(() => { }); describe("LocalApi", () => { - it("keeps backend operations unavailable in the browser facade", async () => { + it("keeps backend operations out of the local host facade", async () => { const { createLocalApi } = await import("./localApi"); const api = createLocalApi(); - await expect(api.server.getConfig()).rejects.toThrow( - "Local backend API is unavailable before a backend is paired.", - ); - await expect(api.shell.openInEditor("/tmp", "cursor")).rejects.toThrow( - "Local backend API is unavailable before a backend is paired.", - ); + expect(api).not.toHaveProperty("server"); + expect(api.shell).not.toHaveProperty("openInEditor"); }); it("uses the browser context-menu fallback without a desktop bridge", async () => { @@ -120,12 +115,4 @@ describe("LocalApi", () => { await api.persistence.setClientSettings(settings); await expect(api.persistence.getClientSettings()).resolves.toEqual(settings); }); - - it("prefers the native LocalApi when one is injected", async () => { - const nativeApi = { dialogs: {} }; - testWindow().nativeApi = nativeApi as never; - const { readLocalApi } = await import("./localApi"); - - expect(readLocalApi()).toBe(nativeApi); - }); }); diff --git a/apps/web/src/localApi.ts b/apps/web/src/localApi.ts index 41f50193b4..b42702c7a4 100644 --- a/apps/web/src/localApi.ts +++ b/apps/web/src/localApi.ts @@ -6,10 +6,6 @@ import { readBrowserClientSettings, writeBrowserClientSettings } from "./clientP let cachedApi: LocalApi | undefined; -function unavailableLocalBackendError(): Error { - return new Error("Local backend API is unavailable before a backend is paired."); -} - function createBrowserLocalApi(): LocalApi { return { dialogs: { @@ -25,7 +21,6 @@ function createBrowserLocalApi(): LocalApi { }, }, shell: { - openInEditor: () => Promise.reject(unavailableLocalBackendError()), openExternal: async (url) => { if (window.desktopBridge) { const opened = await window.desktopBridge.openExternal(url); @@ -63,23 +58,6 @@ function createBrowserLocalApi(): LocalApi { writeBrowserClientSettings(settings); }, }, - server: { - getConfig: () => Promise.reject(unavailableLocalBackendError()), - refreshProviders: () => Promise.reject(unavailableLocalBackendError()), - updateProvider: () => Promise.reject(unavailableLocalBackendError()), - upsertKeybinding: () => Promise.reject(unavailableLocalBackendError()), - removeKeybinding: () => Promise.reject(unavailableLocalBackendError()), - getSettings: () => Promise.reject(unavailableLocalBackendError()), - updateSettings: () => Promise.reject(unavailableLocalBackendError()), - discoverSourceControl: () => Promise.reject(unavailableLocalBackendError()), - getTraceDiagnostics: () => Promise.reject(unavailableLocalBackendError()), - getProcessDiagnostics: () => Promise.reject(unavailableLocalBackendError()), - getProcessResourceHistory: () => Promise.reject(unavailableLocalBackendError()), - getResourceTelemetry: () => Promise.reject(unavailableLocalBackendError()), - getResourceTelemetryHistory: () => Promise.reject(unavailableLocalBackendError()), - retryResourceTelemetry: () => Promise.reject(unavailableLocalBackendError()), - signalProcess: () => Promise.reject(unavailableLocalBackendError()), - }, }; } @@ -91,12 +69,7 @@ export function readLocalApi(): LocalApi | undefined { if (typeof window === "undefined") return undefined; if (cachedApi) return cachedApi; - if (window.nativeApi) { - cachedApi = window.nativeApi; - return cachedApi; - } - - cachedApi = createBrowserLocalApi(); + cachedApi = createLocalApi(); return cachedApi; } diff --git a/apps/web/src/vite-env.d.ts b/apps/web/src/vite-env.d.ts index d8a6d71b49..d4fae7378f 100644 --- a/apps/web/src/vite-env.d.ts +++ b/apps/web/src/vite-env.d.ts @@ -1,6 +1,6 @@ /// -import type { DesktopBridge, LocalApi } from "@t3tools/contracts"; +import type { DesktopBridge } from "@t3tools/contracts"; interface ImportMetaEnv { readonly VITE_HTTP_URL: string; @@ -21,7 +21,6 @@ interface ImportMeta { declare global { interface Window { - nativeApi?: LocalApi; desktopBridge?: DesktopBridge; } } diff --git a/packages/contracts/src/ipc.ts b/packages/contracts/src/ipc.ts index b2a6140dbf..9f505c7d9d 100644 --- a/packages/contracts/src/ipc.ts +++ b/packages/contracts/src/ipc.ts @@ -1,121 +1,19 @@ -import type { - VcsCreateRefInput, - VcsCreateRefResult, - VcsCreateWorktreeInput, - VcsCreateWorktreeResult, - VcsInitInput, - VcsListRefsInput, - VcsListRefsResult, - VcsPullInput, - VcsPullResult, - VcsRemoveWorktreeInput, - VcsSwitchRefInput, - VcsSwitchRefResult, - GitPreparePullRequestThreadInput, - GitPreparePullRequestThreadResult, - GitPullRequestRefInput, - GitResolvePullRequestResult, - VcsStatusInput, - VcsStatusResult, -} from "./git.ts"; -import type { ReviewDiffPreviewInput, ReviewDiffPreviewResult } from "./review.ts"; -import type { FilesystemBrowseInput, FilesystemBrowseResult } from "./filesystem.ts"; -import type { AssetCreateUrlInput, AssetCreateUrlResult } from "./assets.ts"; -import type { - ProjectListEntriesInput, - ProjectListEntriesResult, - ProjectReadFileInput, - ProjectReadFileResult, - ProjectSearchEntriesInput, - ProjectSearchEntriesResult, - ProjectWriteFileInput, - ProjectWriteFileResult, -} from "./project.ts"; -import type { ProviderInstanceId } from "./providerInstance.ts"; -import type { - ResourceTelemetryHistory, - ResourceTelemetryHistoryInput, - ResourceTelemetryRetryResult, - ResourceTelemetrySnapshot, -} from "./resourceTelemetry.ts"; -import type { - ServerConfig, - ServerProcessDiagnosticsResult, - ServerProcessResourceHistoryInput, - ServerProcessResourceHistoryResult, - ServerProviderUpdateInput, - ServerProviderUpdatedPayload, - ServerRemoveKeybindingResult, - ServerSignalProcessInput, - ServerSignalProcessResult, - ServerTraceDiagnosticsResult, - ServerUpsertKeybindingResult, -} from "./server.ts"; -import type { - TerminalAttachInput, - TerminalAttachStreamEvent, - TerminalClearInput, - TerminalCloseInput, - TerminalMetadataStreamEvent, - TerminalOpenInput, - TerminalResizeInput, - TerminalRestartInput, - TerminalSessionSnapshot, - TerminalWriteInput, -} from "./terminal.ts"; -import type { ServerRemoveKeybindingInput, ServerUpsertKeybindingInput } from "./server.ts"; import * as Schema from "effect/Schema"; -import type { - DiscoveredLocalServerList, - PreviewCloseInput, - PreviewEvent, - PreviewListInput, - PreviewListResult, - PreviewNavigateInput, - PreviewOpenInput, - PreviewRefreshInput, - PreviewReportStatusInput, - PreviewSessionSnapshot, -} from "./preview.ts"; import { PreviewAutomationClickInput, PreviewAutomationEvaluateInput, - PreviewAutomationOwner, PreviewAutomationPressInput, - PreviewAutomationRequest, - PreviewAutomationResponse, PreviewAutomationScrollInput, PreviewAutomationSnapshot, PreviewAutomationStatus, PreviewAutomationTypeInput, PreviewAutomationWaitForInput, } from "./previewAutomation.ts"; -import type { - ClientOrchestrationCommand, - OrchestrationGetFullThreadDiffInput, - OrchestrationGetFullThreadDiffResult, - OrchestrationGetTurnDiffInput, - OrchestrationGetTurnDiffResult, - OrchestrationShellSnapshot, - OrchestrationShellStreamItem, - OrchestrationSubscribeThreadInput, - OrchestrationThreadStreamItem, -} from "./orchestration.ts"; import { EnvironmentId } from "./baseSchemas.ts"; import { AuthAccessTokenResult, AuthSessionState, AuthWebSocketTicketResult } from "./auth.ts"; import { AdvertisedEndpoint } from "./remoteAccess.ts"; -import { EditorId } from "./editor.ts"; import { ExecutionEnvironmentDescriptor } from "./environment.ts"; -import type { ClientSettings, ServerSettings, ServerSettingsPatch } from "./settings.ts"; -import type { - SourceControlCloneRepositoryInput, - SourceControlCloneRepositoryResult, - SourceControlDiscoveryResult, - SourceControlPublishRepositoryInput, - SourceControlPublishRepositoryResult, - SourceControlRepositoryInfo, - SourceControlRepositoryLookupInput, -} from "./sourceControl.ts"; +import type { ClientSettings } from "./settings.ts"; export interface ContextMenuItem { id: T; @@ -1027,7 +925,7 @@ export interface DesktopPreviewBridge { * APIs bound to the local app shell, not to any particular backend environment. * * These capabilities describe the desktop/browser host that the user is - * currently running: dialogs, editor/external-link opening, context menus, and + * currently running: dialogs, external-link opening, context menus, and * app-level settings/config access. They must not be used as a proxy for * "whatever environment the user is targeting", because in a multi-environment * world the local shell and a selected backend environment are distinct @@ -1039,7 +937,6 @@ export interface LocalApi { confirm: (message: string) => Promise; }; shell: { - openInEditor: (cwd: string, editor: EditorId) => Promise; openExternal: (url: string) => Promise; }; contextMenu: { @@ -1052,161 +949,4 @@ export interface LocalApi { getClientSettings: () => Promise; setClientSettings: (settings: ClientSettings) => Promise; }; - server: { - getConfig: () => Promise; - /** - * Refresh provider snapshots. When `input.instanceId` is supplied only that - * configured instance is probed; otherwise every configured instance is - * refreshed (legacy untargeted refresh). - */ - refreshProviders: (input?: { - readonly instanceId?: ProviderInstanceId; - }) => Promise; - updateProvider: (input: ServerProviderUpdateInput) => Promise; - upsertKeybinding: (input: ServerUpsertKeybindingInput) => Promise; - removeKeybinding: (input: ServerRemoveKeybindingInput) => Promise; - getSettings: () => Promise; - updateSettings: (patch: ServerSettingsPatch) => Promise; - discoverSourceControl: () => Promise; - getTraceDiagnostics: () => Promise; - getProcessDiagnostics: () => Promise; - getProcessResourceHistory: ( - input: ServerProcessResourceHistoryInput, - ) => Promise; - getResourceTelemetry: () => Promise; - getResourceTelemetryHistory: ( - input: ResourceTelemetryHistoryInput, - ) => Promise; - retryResourceTelemetry: () => Promise; - signalProcess: (input: ServerSignalProcessInput) => Promise; - }; -} - -/** - * APIs bound to a specific backend environment connection. - * - * These operations must always be routed with explicit environment context. - * They represent remote stateful capabilities such as orchestration, terminal, - * project, VCS, and provider operations. In multi-environment mode, each environment gets - * its own instance of this surface, and callers should resolve it by - * `environmentId` rather than reaching through the local desktop bridge. - */ -export interface EnvironmentApi { - terminal: { - open: (input: typeof TerminalOpenInput.Encoded) => Promise; - attach: ( - input: typeof TerminalAttachInput.Encoded, - callback: (event: TerminalAttachStreamEvent) => void, - options?: { - onResubscribe?: () => void; - }, - ) => () => void; - write: (input: typeof TerminalWriteInput.Encoded) => Promise; - resize: (input: typeof TerminalResizeInput.Encoded) => Promise; - clear: (input: typeof TerminalClearInput.Encoded) => Promise; - restart: (input: typeof TerminalRestartInput.Encoded) => Promise; - close: (input: typeof TerminalCloseInput.Encoded) => Promise; - onMetadata: ( - callback: (event: TerminalMetadataStreamEvent) => void, - options?: { - onResubscribe?: () => void; - }, - ) => () => void; - }; - projects: { - listEntries: (input: ProjectListEntriesInput) => Promise; - readFile: (input: ProjectReadFileInput) => Promise; - searchEntries: (input: ProjectSearchEntriesInput) => Promise; - writeFile: (input: ProjectWriteFileInput) => Promise; - }; - filesystem: { - browse: (input: FilesystemBrowseInput) => Promise; - }; - assets: { - createUrl: (input: AssetCreateUrlInput) => Promise; - }; - sourceControl: { - lookupRepository: ( - input: SourceControlRepositoryLookupInput, - ) => Promise; - cloneRepository: ( - input: SourceControlCloneRepositoryInput, - ) => Promise; - publishRepository: ( - input: SourceControlPublishRepositoryInput, - ) => Promise; - }; - vcs: { - listRefs: (input: VcsListRefsInput) => Promise; - createWorktree: (input: VcsCreateWorktreeInput) => Promise; - removeWorktree: (input: VcsRemoveWorktreeInput) => Promise; - createRef: (input: VcsCreateRefInput) => Promise; - switchRef: (input: VcsSwitchRefInput) => Promise; - init: (input: VcsInitInput) => Promise; - pull: (input: VcsPullInput) => Promise; - refreshStatus: (input: VcsStatusInput) => Promise; - onStatus: ( - input: VcsStatusInput, - callback: (status: VcsStatusResult) => void, - options?: { - onResubscribe?: () => void; - }, - ) => () => void; - }; - git: { - resolvePullRequest: (input: GitPullRequestRefInput) => Promise; - preparePullRequestThread: ( - input: GitPreparePullRequestThreadInput, - ) => Promise; - }; - review: { - getDiffPreview: (input: ReviewDiffPreviewInput) => Promise; - }; - orchestration: { - dispatchCommand: (command: ClientOrchestrationCommand) => Promise<{ sequence: number }>; - getTurnDiff: (input: OrchestrationGetTurnDiffInput) => Promise; - getFullThreadDiff: ( - input: OrchestrationGetFullThreadDiffInput, - ) => Promise; - getArchivedShellSnapshot: () => Promise; - subscribeShell: ( - callback: (event: OrchestrationShellStreamItem) => void, - options?: { - onResubscribe?: () => void; - }, - ) => () => void; - subscribeThread: ( - input: OrchestrationSubscribeThreadInput, - callback: (event: OrchestrationThreadStreamItem) => void, - options?: { - onResubscribe?: () => void; - }, - ) => () => void; - }; - preview: { - open: (input: typeof PreviewOpenInput.Encoded) => Promise; - navigate: (input: typeof PreviewNavigateInput.Encoded) => Promise; - refresh: (input: typeof PreviewRefreshInput.Encoded) => Promise; - close: (input: typeof PreviewCloseInput.Encoded) => Promise; - list: (input: typeof PreviewListInput.Encoded) => Promise; - reportStatus: (input: typeof PreviewReportStatusInput.Encoded) => Promise; - automation: { - connect: ( - input: { clientId: string }, - callback: (request: PreviewAutomationRequest) => void, - options?: { onResubscribe?: () => void }, - ) => () => void; - respond: (response: PreviewAutomationResponse) => Promise; - reportOwner: (owner: PreviewAutomationOwner) => Promise; - clearOwner: (input: { clientId: string }) => Promise; - }; - onEvent: ( - callback: (event: PreviewEvent) => void, - options?: { onResubscribe?: () => void }, - ) => () => void; - subscribePorts: ( - callback: (servers: DiscoveredLocalServerList) => void, - options?: { onResubscribe?: () => void }, - ) => () => void; - }; } diff --git a/packages/contracts/src/rpc.ts b/packages/contracts/src/rpc.ts index 11b8a6519d..f4aa570904 100644 --- a/packages/contracts/src/rpc.ts +++ b/packages/contracts/src/rpc.ts @@ -221,7 +221,6 @@ export const WS_METHODS = { serverGetTraceDiagnostics: "server.getTraceDiagnostics", serverGetProcessDiagnostics: "server.getProcessDiagnostics", serverGetProcessResourceHistory: "server.getProcessResourceHistory", - serverGetResourceTelemetry: "server.getResourceTelemetry", serverGetResourceTelemetryHistory: "server.getResourceTelemetryHistory", serverRetryResourceTelemetry: "server.retryResourceTelemetry", serverSignalProcess: "server.signalProcess", @@ -328,12 +327,6 @@ export const WsServerGetProcessResourceHistoryRpc = Rpc.make( }, ); -export const WsServerGetResourceTelemetryRpc = Rpc.make(WS_METHODS.serverGetResourceTelemetry, { - payload: Schema.Struct({}), - success: ResourceTelemetrySnapshot, - error: EnvironmentAuthorizationError, -}); - export const WsServerGetResourceTelemetryHistoryRpc = Rpc.make( WS_METHODS.serverGetResourceTelemetryHistory, { @@ -760,7 +753,6 @@ export const WsRpcGroup = RpcGroup.make( WsServerGetTraceDiagnosticsRpc, WsServerGetProcessDiagnosticsRpc, WsServerGetProcessResourceHistoryRpc, - WsServerGetResourceTelemetryRpc, WsServerGetResourceTelemetryHistoryRpc, WsServerRetryResourceTelemetryRpc, WsServerSignalProcessRpc,