Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ipc.ts

1,405 lines47.9 KB

1import type {
2 VcsCreateRefInput,
3 VcsCreateRefResult,
4 VcsCreateWorktreeInput,
5 VcsCreateWorktreeResult,
6 VcsInitInput,
7 VcsListRefsInput,
8 VcsListRefsResult,
9 VcsPullInput,
10 VcsPullResult,
11 VcsRemoveWorktreeInput,
12 VcsSwitchRefInput,
13 VcsSwitchRefResult,
14 GitPreparePullRequestThreadInput,
15 GitPreparePullRequestThreadResult,
16 GitPullRequestRefInput,
17 GitResolvePullRequestResult,
18 VcsStatusInput,
19 VcsStatusResult,
20} from "./git.ts";
21import type {
22 ReviewDiffFileContentsInput,
23 ReviewDiffFileContentsResult,
24 ReviewDiffPreviewInput,
25 ReviewDiffPreviewResult,
26} from "./review.ts";
27import type { FilesystemBrowseInput, FilesystemBrowseResult } from "./filesystem.ts";
28import type { AssetCreateUrlInput, AssetCreateUrlResult } from "./assets.ts";
29import type {
30 ProjectListEntriesInput,
31 ProjectListEntriesResult,
32 ProjectReadFileInput,
33 ProjectReadFileResult,
34 ProjectSearchEntriesInput,
35 ProjectSearchEntriesResult,
36 ProjectWriteFileInput,
37 ProjectWriteFileResult,
38} from "./project.ts";
39import type {
40 TerminalAttachInput,
41 TerminalAttachStreamEvent,
42 TerminalClearInput,
43 TerminalCloseInput,
44 TerminalMetadataStreamEvent,
45 TerminalOpenInput,
46 TerminalResizeInput,
47 TerminalRestartInput,
48 TerminalSessionSnapshot,
49 TerminalWriteInput,
50} from "./terminal.ts";
51import * as Schema from "effect/Schema";
52import type {
53 DiscoveredLocalServerList,
54 PreviewCloseInput,
55 PreviewEvent,
56 PreviewListInput,
57 PreviewListResult,
58 PreviewNavigateInput,
59 PreviewOpenInput,
60 PreviewRefreshInput,
61 PreviewReportStatusInput,
62 PreviewResizeInput,
63 PreviewSessionSnapshot,
64} from "./preview.ts";
65import {
66 PreviewAutomationClickInput,
67 PreviewAutomationEvaluateInput,
68 PreviewAutomationHost,
69 PreviewAutomationHostFocus,
70 PreviewAutomationPressInput,
71 PreviewAutomationResponse,
72 PreviewAutomationScrollInput,
73 PreviewAutomationSnapshot,
74 PreviewAutomationStatus,
75 PreviewAutomationStreamEvent,
76 PreviewAutomationTypeInput,
77 PreviewAutomationWaitForInput,
78} from "./previewAutomation.ts";
79import type {
80 ClientOrchestrationCommand,
81 OrchestrationGetFullThreadDiffInput,
82 OrchestrationGetFullThreadDiffResult,
83 OrchestrationGetTurnDiffInput,
84 OrchestrationGetTurnDiffResult,
85 OrchestrationShellSnapshot,
86 OrchestrationShellStreamItem,
87 OrchestrationSubscribeThreadInput,
88 OrchestrationThreadStreamItem,
89} from "./orchestration.ts";
90import { EnvironmentId } from "./baseSchemas.ts";
91import { AuthAccessTokenResult, AuthSessionState, AuthWebSocketTicketResult } from "./auth.ts";
92import { AdvertisedEndpoint } from "./remoteAccess.ts";
93import { ExecutionEnvironmentDescriptor } from "./environment.ts";
94import type { ClientSettings } from "./settings.ts";
95import type { EditorId } from "./editor.ts";
96import type {
97 SourceControlCloneRepositoryInput,
98 SourceControlCloneRepositoryResult,
99 SourceControlPublishRepositoryInput,
100 SourceControlPublishRepositoryResult,
101 SourceControlRepositoryInfo,
102 SourceControlRepositoryLookupInput,
103} from "./sourceControl.ts";
104​
105export interface ContextMenuItem<T extends string = string> {
106 id: T;
107 label: string;
108 destructive?: boolean;
109 disabled?: boolean;
110 /** Renders as a non-interactive section header label. Web fallback only — stripped on desktop native menus. */
111 header?: boolean;
112 /** Icon keyword resolved by the web fallback. Stripped on desktop native menus. */
113 icon?: string;
114 /** Inserts a visual section divider immediately before this item. */
115 separatorBefore?: boolean;
116 children?: readonly ContextMenuItem<T>[];
118​
119export interface ContextMenuItemSchemaType {
120 readonly id: string;
121 readonly label: string;
122 readonly destructive?: boolean;
123 readonly disabled?: boolean;
124 readonly header?: boolean;
125 readonly icon?: string;
126 readonly separatorBefore?: boolean;
127 readonly children?: readonly ContextMenuItemSchemaType[];
129​
130export const ContextMenuItemSchema: Schema.Codec<ContextMenuItemSchemaType> = Schema.Struct({
131 id: Schema.String,
132 label: Schema.String,
133 destructive: Schema.optionalKey(Schema.Boolean),
134 disabled: Schema.optionalKey(Schema.Boolean),
135 header: Schema.optionalKey(Schema.Boolean),
136 icon: Schema.optionalKey(Schema.String),
137 separatorBefore: Schema.optionalKey(Schema.Boolean),
138 children: Schema.optionalKey(
139 Schema.Array(
140 Schema.suspend((): Schema.Codec<ContextMenuItemSchemaType> => ContextMenuItemSchema),
141 ),
142 ),
143});
144​
145export type DesktopUpdateStatus =
146 | "disabled"
147 | "idle"
148 | "checking"
149 | "up-to-date"
150 | "available"
151 | "downloading"
152 | "downloaded"
153 | "error";
154​
155export type DesktopRuntimeArch = "arm64" | "x64" | "other";
156export type DesktopTheme = "light" | "dark" | "system";
157export type DesktopUpdateChannel = "latest" | "nightly";
158export type DesktopAppStageLabel = "Alpha" | "Dev" | "Nightly";
159​
160export const DesktopUpdateStatusSchema = Schema.Literals([
161 "disabled",
162 "idle",
163 "checking",
164 "up-to-date",
165 "available",
166 "downloading",
167 "downloaded",
168 "error",
169]);
170export const DesktopRuntimeArchSchema = Schema.Literals(["arm64", "x64", "other"]);
171export const DesktopThemeSchema = Schema.Literals(["light", "dark", "system"]);
172export const DesktopUpdateChannelSchema = Schema.Literals(["latest", "nightly"]);
173export const DesktopAppStageLabelSchema = Schema.Literals(["Alpha", "Dev", "Nightly"]);
174​
175export interface DesktopAppBranding {
176 baseName: string;
177 stageLabel: DesktopAppStageLabel;
178 displayName: string;
180​
181export const DesktopAppBrandingSchema = Schema.Struct({
182 baseName: Schema.String,
183 stageLabel: DesktopAppStageLabelSchema,
184 displayName: Schema.String,
185});
186​
187export interface DesktopRuntimeInfo {
188 hostArch: DesktopRuntimeArch;
189 appArch: DesktopRuntimeArch;
190 runningUnderArm64Translation: boolean;
192​
193export const DesktopRuntimeInfoSchema = Schema.Struct({
194 hostArch: DesktopRuntimeArchSchema,
195 appArch: DesktopRuntimeArchSchema,
196 runningUnderArm64Translation: Schema.Boolean,
197});
198​
199export interface DesktopUpdateState {
200 enabled: boolean;
201 status: DesktopUpdateStatus;
202 channel: DesktopUpdateChannel;
203 currentVersion: string;
204 hostArch: DesktopRuntimeArch;
205 appArch: DesktopRuntimeArch;
206 runningUnderArm64Translation: boolean;
207 availableVersion: string | null;
208 downloadedVersion: string | null;
209 releaseNotes: ReadonlyArray<DesktopUpdateReleaseNote>;
210 downloadPercent: number | null;
211 checkedAt: string | null;
212 message: string | null;
213 errorContext: "check" | "download" | "install" | null;
214 canRetry: boolean;
216​
217export interface DesktopUpdateReleaseNote {
218 version: string;
219 items: ReadonlyArray<string>;
221​
222export const DesktopUpdateReleaseNoteSchema = Schema.Struct({
223 version: Schema.String,
224 items: Schema.Array(Schema.String),
225});
226​
227export const DesktopUpdateStateSchema = Schema.Struct({
228 enabled: Schema.Boolean,
229 status: DesktopUpdateStatusSchema,
230 channel: DesktopUpdateChannelSchema,
231 currentVersion: Schema.String,
232 hostArch: DesktopRuntimeArchSchema,
233 appArch: DesktopRuntimeArchSchema,
234 runningUnderArm64Translation: Schema.Boolean,
235 availableVersion: Schema.NullOr(Schema.String),
236 downloadedVersion: Schema.NullOr(Schema.String),
237 releaseNotes: Schema.Array(DesktopUpdateReleaseNoteSchema),
238 downloadPercent: Schema.NullOr(Schema.Number),
239 checkedAt: Schema.NullOr(Schema.String),
240 message: Schema.NullOr(Schema.String),
241 errorContext: Schema.NullOr(Schema.Literals(["check", "download", "install"])),
242 canRetry: Schema.Boolean,
243});
244​
245export interface DesktopUpdateActionResult {
246 accepted: boolean;
247 completed: boolean;
248 state: DesktopUpdateState;
250​
251export const DesktopUpdateActionResultSchema = Schema.Struct({
252 accepted: Schema.Boolean,
253 completed: Schema.Boolean,
254 state: DesktopUpdateStateSchema,
255});
256​
257export interface DesktopUpdateCheckResult {
258 checked: boolean;
259 state: DesktopUpdateState;
261​
262export const DesktopUpdateCheckResultSchema = Schema.Struct({
263 checked: Schema.Boolean,
264 state: DesktopUpdateStateSchema,
265});
266​
267// Stable id for the Windows-native primary backend. Desktop side wraps
268// this with a brand inside DesktopBackendManager; web side keeps it as
269// a plain string so the env-runtime can compare against it without
270// importing brand machinery from the desktop package.
271export const PRIMARY_LOCAL_ENVIRONMENT_ID = "primary";
272​
273export interface DesktopEnvironmentBootstrap {
274 // Stable backend instance id (e.g. "primary" or "wsl:ubuntu"). The
275 // web env runtime keys local environments off this so projects
276 // routed to a specific backend reopen against the same one.
277 id: string;
278 label: string;
279 // Concrete WSL distro used by the current backend run. This stays separate
280 // from id because a default-tracking instance keeps the stable
281 // "wsl:default" IPC target while each run launches a specific distro.
282 runningDistro?: string | null;
283 httpBaseUrl: string | null;
284 wsBaseUrl: string | null;
285 bootstrapToken?: string;
287​
288export const DesktopEnvironmentBootstrapSchema = Schema.Struct({
289 id: Schema.String,
290 label: Schema.String,
291 runningDistro: Schema.optionalKey(Schema.NullOr(Schema.String)),
292 httpBaseUrl: Schema.NullOr(Schema.String),
293 wsBaseUrl: Schema.NullOr(Schema.String),
294 bootstrapToken: Schema.optionalKey(Schema.String),
295});
296​
297export const DesktopSshEnvironmentTargetSchema = Schema.Struct({
298 alias: Schema.String,
299 hostname: Schema.String,
300 username: Schema.NullOr(Schema.String),
301 port: Schema.NullOr(Schema.Number),
302});
303export type DesktopSshEnvironmentTarget = typeof DesktopSshEnvironmentTargetSchema.Type;
304​
305export type DesktopSshHostSource = "ssh-config" | "known-hosts";
306export const DesktopSshHostSourceSchema = Schema.Literals(["ssh-config", "known-hosts"]);
307​
308export interface DesktopDiscoveredSshHost extends DesktopSshEnvironmentTarget {
309 source: DesktopSshHostSource;
311​
312export const DesktopDiscoveredSshHostSchema = Schema.Struct({
313 alias: Schema.String,
314 hostname: Schema.String,
315 username: Schema.NullOr(Schema.String),
316 port: Schema.NullOr(Schema.Number),
317 source: DesktopSshHostSourceSchema,
318});
319​
320export interface DesktopSshEnvironmentBootstrap {
321 target: DesktopSshEnvironmentTarget;
322 httpBaseUrl: string;
323 wsBaseUrl: string;
324 pairingToken: string | null;
325 remotePort?: number;
326 remoteServerKind?: "external" | "managed";
328​
329export const DesktopSshEnvironmentBootstrapSchema = Schema.Struct({
330 target: DesktopSshEnvironmentTargetSchema,
331 httpBaseUrl: Schema.String,
332 wsBaseUrl: Schema.String,
333 pairingToken: Schema.NullOr(Schema.String),
334 remotePort: Schema.optionalKey(Schema.Number),
335 remoteServerKind: Schema.optionalKey(Schema.Literals(["external", "managed"])),
336});
337​
338export interface DesktopSshPasswordPromptRequest {
339 requestId: string;
340 destination: string;
341 username: string | null;
342 prompt: string;
343 expiresAt: string;
345​
346export const DesktopSshPasswordPromptRequestSchema = Schema.Struct({
347 requestId: Schema.String,
348 destination: Schema.String,
349 username: Schema.NullOr(Schema.String),
350 prompt: Schema.String,
351 expiresAt: Schema.String,
352});
353​
354export const DesktopSshPasswordPromptCancelledType = "ssh-password-prompt-cancelled" as const;
355​
356export const DesktopSshPasswordPromptCancelledResultSchema = Schema.Struct({
357 type: Schema.Literal(DesktopSshPasswordPromptCancelledType),
358 message: Schema.String,
359});
360​
361export const DesktopSshEnvironmentEnsureOptionsSchema = Schema.Struct({
362 issuePairingToken: Schema.optionalKey(Schema.Boolean),
363});
364​
365export const DesktopSshEnvironmentEnsureInputSchema = Schema.Struct({
366 target: DesktopSshEnvironmentTargetSchema,
367 options: Schema.optionalKey(DesktopSshEnvironmentEnsureOptionsSchema),
368});
369​
370export const DesktopSshEnvironmentEnsureResultSchema = Schema.Union([
371 DesktopSshEnvironmentBootstrapSchema,
372 DesktopSshPasswordPromptCancelledResultSchema,
373]);
374​
375export const DesktopSshHttpBaseUrlInputSchema = Schema.Struct({
376 httpBaseUrl: Schema.String,
377});
378​
379export const DesktopSshBearerRequestInputSchema = Schema.Struct({
380 httpBaseUrl: Schema.String,
381 bearerToken: Schema.String,
382});
383​
384export const DesktopSshBearerBootstrapInputSchema = Schema.Struct({
385 httpBaseUrl: Schema.String,
386 credential: Schema.String,
387});
388​
389export const DesktopSshPasswordPromptResolutionInputSchema = Schema.Struct({
390 requestId: Schema.String,
391 password: Schema.NullOr(Schema.String),
392});
393​
394export const PersistedSavedEnvironmentRecordSchema = Schema.Struct({
395 environmentId: EnvironmentId,
396 label: Schema.String,
397 wsBaseUrl: Schema.String,
398 httpBaseUrl: Schema.String,
399 createdAt: Schema.String,
400 lastConnectedAt: Schema.NullOr(Schema.String),
401 desktopSsh: Schema.optionalKey(DesktopSshEnvironmentTargetSchema),
402 relayManaged: Schema.optionalKey(
403 Schema.Struct({
404 relayUrl: Schema.String,
405 }),
406 ),
407});
408export type PersistedSavedEnvironmentRecord = typeof PersistedSavedEnvironmentRecordSchema.Type;
409​
410export type DesktopServerExposureMode = "local-only" | "network-accessible";
411​
412export const DesktopServerExposureModeSchema = Schema.Literals([
413 "local-only",
414 "network-accessible",
415]);
416​
417export interface DesktopServerExposureState {
418 mode: DesktopServerExposureMode;
419 endpointUrl: string | null;
420 advertisedHost: string | null;
421 tailscaleServeEnabled: boolean;
422 tailscaleServePort: number;
424​
425export const DesktopServerExposureStateSchema = Schema.Struct({
426 mode: DesktopServerExposureModeSchema,
427 endpointUrl: Schema.NullOr(Schema.String),
428 advertisedHost: Schema.NullOr(Schema.String),
429 tailscaleServeEnabled: Schema.Boolean,
430 tailscaleServePort: Schema.Number,
431});
432​
433export interface PickFolderOptions {
434 initialPath?: string | null;
435 // When set, the desktop dialog opens against the named backend's
436 // filesystem instead of the primary's. Used by callers that already
437 // know which local environment they're targeting (e.g. opening a
438 // project that lives inside WSL). Omitting it keeps the historical
439 // behavior so non-WSL users never see a different picker.
440 targetEnvironmentId?: string;
442​
443export const PickFolderOptionsSchema = Schema.Struct({
444 initialPath: Schema.optionalKey(Schema.NullOr(Schema.String)),
445 targetEnvironmentId: Schema.optionalKey(Schema.String),
446});
447​
448/**
449 * A file returned by the desktop theme-file picker. Oversized files carry an
450 * empty text so the renderer can reject them by size without the main
451 * process ever holding their contents.
452 */
453export interface PickedThemeFile {
454 name: string;
455 size: number;
456 text: string;
458​
459export const PickedThemeFileSchema = Schema.Struct({
460 name: Schema.String,
461 size: Schema.Number,
462 text: Schema.String,
463});
464​
465export interface DesktopWslDistro {
466 name: string;
467 isDefault: boolean;
468 version: 1 | 2;
470​
471export const DesktopWslDistroSchema = Schema.Struct({
472 name: Schema.String,
473 isDefault: Schema.Boolean,
474 version: Schema.Literals([1, 2]),
475});
476​
477export interface DesktopWslState {
478 // True when the user has opted the WSL backend in; the actual backend
479 // process is registered with the desktop pool independently of this
480 // flag and may take a moment to come up after the user enables it.
481 enabled: boolean;
482 // null means "track the current WSL default distro".
483 distro: string | null;
484 available: boolean;
485 // When true (and `enabled` is also true) the desktop runs only the
486 // WSL backend as the primary; the Windows-side Node backend is not
487 // started. Toggling this requires an app restart because the
488 // primary backend's spec is captured once at layer init.
489 wslOnly: boolean;
490 distros: readonly DesktopWslDistro[];
491 // Reason the dual-mode WSL backend last failed preflight (no node, wrong
492 // version, missing build tools), or null. Surfaced inline in Connections
493 // settings. Always null in wsl-only mode — that path shows a dialog and
494 // falls back to Windows instead.
495 preflightError: string | null;
497​
498export const DesktopWslStateSchema = Schema.Struct({
499 enabled: Schema.Boolean,
500 distro: Schema.NullOr(Schema.String),
501 available: Schema.Boolean,
502 wslOnly: Schema.Boolean,
503 distros: Schema.Array(DesktopWslDistroSchema),
504 preflightError: Schema.NullOr(Schema.String),
505});
506​
507/**
508 * Renderer-facing snapshot of a desktop preview tab. Mirrors the main-process
509 * PreviewTabState shape but uses serialisable primitives only.
510 */
511export type DesktopPreviewNavStatus =
512 | { kind: "Idle" }
513 | { kind: "Loading"; url: string; title: string }
514 | { kind: "Success"; url: string; title: string }
515 | {
516 kind: "LoadFailed";
517 url: string;
518 title: string;
519 code: number;
520 description: string;
521 };
522​
523/**
524 * Emulated `prefers-color-scheme` for the guest page. "system" clears the
525 * override so the page follows the OS appearance.
526 */
527export type DesktopPreviewColorScheme = "system" | "light" | "dark";
528​
529export const DesktopPreviewColorSchemeSchema: Schema.Codec<DesktopPreviewColorScheme> =
530 Schema.Literals(["system", "light", "dark"]);
531​
532export const FAVICON_DATA_URL_MAX_LENGTH = 8192;
533export const FAVICON_CAPTURED_AT_MAX = 8_640_000_000_000_000;
534​
535export interface DesktopPreviewFavicon {
536 dataUrl: string;
537 pageUrl: string;
538 capturedAt: number;
540​
541export const DesktopPreviewFaviconSchema: Schema.Codec<DesktopPreviewFavicon> = Schema.Struct({
542 dataUrl: Schema.String.check(
543 Schema.isMaxLength(FAVICON_DATA_URL_MAX_LENGTH),
544 Schema.isPattern(/^data:image\/png;base64,[a-z0-9+/]+={0,2}$/i),
545 ),
546 pageUrl: Schema.String.check(Schema.isMaxLength(2_048)),
547 capturedAt: Schema.Number.check(
548 Schema.isFinite(),
549 Schema.isGreaterThanOrEqualTo(0),
550 Schema.isLessThanOrEqualTo(FAVICON_CAPTURED_AT_MAX),
551 ),
552});
553​
554export interface DesktopPreviewTabState {
555 tabId: string;
556 webContentsId: number | null;
557 navStatus: DesktopPreviewNavStatus;
558 canGoBack: boolean;
559 canGoForward: boolean;
560 /** Current zoom factor (1.0 = 100%). */
561 zoomFactor: number;
562 /** Whether this tab is currently mirrored into a desktop picture-in-picture window. */
563 pictureInPicture: boolean;
564 colorScheme: DesktopPreviewColorScheme;
565 /**
566 * Whether the user has silenced this tab. Per tab rather than per origin, so
567 * two tabs on the same site mute independently. Survives navigation and
568 * webview swaps, but is dropped when the tab closes.
569 */
570 audioMuted: boolean;
571 /**
572 * Whether the guest is currently emitting audio. Observed from Chromium, and
573 * independent of {@link audioMuted}: a muted tab that is playing still reports
574 * `true`, which is what lets the tab strip distinguish "muted and making
575 * sound" from "muted and silent".
576 */
577 audible: boolean;
578 controller: "human" | "agent" | "none";
579 favicon?: DesktopPreviewFavicon;
580 updatedAt: string;
582​
583export const DesktopPreviewTabIdSchema = Schema.String.check(Schema.isTrimmed()).check(
584 Schema.isNonEmpty(),
585);
586​
587export const DesktopPreviewNavStatusSchema = Schema.Union([
588 Schema.Struct({ kind: Schema.Literal("Idle") }),
589 Schema.Struct({
590 kind: Schema.Literal("Loading"),
591 url: Schema.String,
592 title: Schema.String,
593 }),
594 Schema.Struct({
595 kind: Schema.Literal("Success"),
596 url: Schema.String,
597 title: Schema.String,
598 }),
599 Schema.Struct({
600 kind: Schema.Literal("LoadFailed"),
601 url: Schema.String,
602 title: Schema.String,
603 code: Schema.Number,
604 description: Schema.String,
605 }),
606]);
607​
608export const DesktopPreviewTabStateSchema: Schema.Codec<DesktopPreviewTabState> = Schema.Struct({
609 tabId: DesktopPreviewTabIdSchema,
610 webContentsId: Schema.NullOr(Schema.Int),
611 navStatus: DesktopPreviewNavStatusSchema,
612 canGoBack: Schema.Boolean,
613 canGoForward: Schema.Boolean,
614 zoomFactor: Schema.Number,
615 pictureInPicture: Schema.Boolean,
616 colorScheme: DesktopPreviewColorSchemeSchema,
617 audioMuted: Schema.Boolean,
618 audible: Schema.Boolean,
619 controller: Schema.Literals(["human", "agent", "none"]),
620 favicon: Schema.optionalKey(DesktopPreviewFaviconSchema),
621 updatedAt: Schema.String,
622});
623​
624export interface DesktopPreviewPointerEvent {
625 tabId: string;
626 phase: "move" | "click";
627 x: number;
628 y: number;
629 sequence: number;
630 createdAt: string;
632​
633export const DesktopPreviewPointerEventSchema: Schema.Codec<DesktopPreviewPointerEvent> =
634 Schema.Struct({
635 tabId: DesktopPreviewTabIdSchema,
636 phase: Schema.Literals(["move", "click"]),
637 x: Schema.Number,
638 y: Schema.Number,
639 sequence: Schema.Int,
640 createdAt: Schema.String,
641 });
642​
643/**
644 * Static config a renderer needs to mount a preview `<webview>`. Returned
645 * atomically by `DesktopPreviewBridge.getPreviewConfig()` so the renderer
646 * doesn't have to wait on three separate IPC round-trips before the webview
647 * can attach.
648 */
649export interface DesktopPreviewWebviewConfig {
650 /** `persist:t3code-preview` (or whatever the desktop chose). */
651 partition: string;
652 /**
653 * Canonical `<webview webpreferences="...">` string. Encodes the security
654 * posture (sandboxed but contextIsolation off so the picker preload can
655 * read the page's React DevTools hook). Always present.
656 */
657 webPreferences: string;
658 /**
659 * Absolute `file://`-style URL to the picker preload bundle. Set to null
660 * when the bundle isn't present (older builds, broken install) — the
661 * renderer must then disable element-pick affordances.
662 */
663 preloadUrl: string | null;
665​
666export const DesktopPreviewWebviewConfigSchema: Schema.Codec<DesktopPreviewWebviewConfig> =
667 Schema.Struct({
668 partition: Schema.String,
669 webPreferences: Schema.String,
670 preloadUrl: Schema.NullOr(Schema.String),
671 });
672​
673export interface DesktopPreviewAnnotationTheme {
674 colorScheme: "light" | "dark";
675 radius: string;
676 background: string;
677 foreground: string;
678 popover: string;
679 popoverForeground: string;
680 primary: string;
681 primaryForeground: string;
682 muted: string;
683 mutedForeground: string;
684 accent: string;
685 accentForeground: string;
686 border: string;
687 input: string;
688 ring: string;
689 fontSans: string;
690 fontMono: string;
692​
693export const DesktopPreviewAnnotationThemeSchema: Schema.Codec<DesktopPreviewAnnotationTheme> =
694 Schema.Struct({
695 colorScheme: Schema.Literals(["light", "dark"]),
696 radius: Schema.String,
697 background: Schema.String,
698 foreground: Schema.String,
699 popover: Schema.String,
700 popoverForeground: Schema.String,
701 primary: Schema.String,
702 primaryForeground: Schema.String,
703 muted: Schema.String,
704 mutedForeground: Schema.String,
705 accent: Schema.String,
706 accentForeground: Schema.String,
707 border: Schema.String,
708 input: Schema.String,
709 ring: Schema.String,
710 fontSans: Schema.String,
711 fontMono: Schema.String,
712 });
713​
714export interface DesktopPreviewRecordingFrame {
715 tabId: string;
716 data: string;
717 width: number;
718 height: number;
719 receivedAt: string;
721​
722export const DesktopPreviewRecordingFrameSchema: Schema.Codec<DesktopPreviewRecordingFrame> =
723 Schema.Struct({
724 tabId: DesktopPreviewTabIdSchema,
725 data: Schema.String,
726 width: Schema.Number,
727 height: Schema.Number,
728 receivedAt: Schema.String,
729 });
730​
731export interface DesktopPreviewRecordingArtifact {
732 id: string;
733 tabId: string;
734 path: string;
735 mimeType: string;
736 sizeBytes: number;
737 createdAt: string;
739​
740export const DesktopPreviewRecordingArtifactSchema: Schema.Codec<DesktopPreviewRecordingArtifact> =
741 Schema.Struct({
742 id: Schema.String,
743 tabId: DesktopPreviewTabIdSchema,
744 path: Schema.String,
745 mimeType: Schema.String,
746 sizeBytes: Schema.Int,
747 createdAt: Schema.String,
748 });
749​
750export interface DesktopPreviewScreenshotArtifact {
751 id: string;
752 tabId: string;
753 path: string;
754 mimeType: "image/png";
755 sizeBytes: number;
756 createdAt: string;
758​
759export const DesktopPreviewScreenshotArtifactSchema: Schema.Codec<DesktopPreviewScreenshotArtifact> =
760 Schema.Struct({
761 id: Schema.String,
762 tabId: DesktopPreviewTabIdSchema,
763 path: Schema.String,
764 mimeType: Schema.Literal("image/png"),
765 sizeBytes: Schema.Int,
766 createdAt: Schema.String,
767 });
768​
769/**
770 * Single stack frame captured by react-grab's `getElementContext`. We surface
771 * the source file/line so coding agents can jump straight to the JSX that
772 * produced the picked DOM node.
773 */
774export interface PickedElementStackFrame {
775 functionName: string | null;
776 fileName: string | null;
777 lineNumber: number | null;
778 columnNumber: number | null;
780​
781export const PickedElementStackFrameSchema: Schema.Codec<PickedElementStackFrame> = Schema.Struct({
782 functionName: Schema.NullOr(Schema.String),
783 fileName: Schema.NullOr(Schema.String),
784 lineNumber: Schema.NullOr(Schema.Number),
785 columnNumber: Schema.NullOr(Schema.Number),
786});
787​
788/**
789 * A successful element pick from the preview webview. All fields are
790 * best-effort — pages that don't ship a React fiber tree (or aren't running
791 * in dev) will still produce a usable payload (selector + html preview),
792 * just without component / source attribution.
793 */
794export interface PickedElementPayload {
795 /** URL of the page the element was picked on. */
796 pageUrl: string;
797 /** Optional `<title>` of that page (best-effort). */
798 pageTitle: string | null;
799 /** Lowercase tag name, e.g. `"button"`. */
800 tagName: string;
801 /** CSS selector resolving back to the element on a re-render. */
802 selector: string | null;
803 /** Truncated outer-HTML preview (matches react-grab's `htmlPreview`). */
804 htmlPreview: string;
805 /** Nearest React component display name, or null when unavailable. */
806 componentName: string | null;
807 /** First source-mapped stack frame (file + line of the JSX source). */
808 source: PickedElementStackFrame | null;
809 /** Full owner-stack frames; can be empty. Useful for richer context. */
810 stack: ReadonlyArray<PickedElementStackFrame>;
811 /** Author CSS only (UA defaults stripped) — react-grab's `styles`. */
812 styles: string;
813 /** Wall-clock pick time as ISO-8601 string. */
814 pickedAt: string;
816​
817export const PickedElementPayloadSchema: Schema.Codec<PickedElementPayload> = Schema.Struct({
818 pageUrl: Schema.String,
819 pageTitle: Schema.NullOr(Schema.String),
820 tagName: Schema.String,
821 selector: Schema.NullOr(Schema.String),
822 htmlPreview: Schema.String,
823 componentName: Schema.NullOr(Schema.String),
824 source: Schema.NullOr(PickedElementStackFrameSchema),
825 stack: Schema.Array(PickedElementStackFrameSchema),
826 styles: Schema.String,
827 pickedAt: Schema.String,
828});
829​
830export interface PreviewAnnotationRect {
831 x: number;
832 y: number;
833 width: number;
834 height: number;
836​
837export const PreviewAnnotationRectSchema: Schema.Codec<PreviewAnnotationRect> = Schema.Struct({
838 x: Schema.Number,
839 y: Schema.Number,
840 width: Schema.Number,
841 height: Schema.Number,
842});
843​
844export interface PreviewAnnotationPoint {
845 x: number;
846 y: number;
848​
849export const PreviewAnnotationPointSchema: Schema.Codec<PreviewAnnotationPoint> = Schema.Struct({
850 x: Schema.Number,
851 y: Schema.Number,
852});
853​
854export interface PreviewAnnotationElementTarget {
855 id: string;
856 element: PickedElementPayload;
857 rect: PreviewAnnotationRect;
859​
860export const PreviewAnnotationElementTargetSchema: Schema.Codec<PreviewAnnotationElementTarget> =
861 Schema.Struct({
862 id: Schema.String,
863 element: PickedElementPayloadSchema,
864 rect: PreviewAnnotationRectSchema,
865 });
866​
867export interface PreviewAnnotationRegionTarget {
868 id: string;
869 rect: PreviewAnnotationRect;
871​
872export const PreviewAnnotationRegionTargetSchema: Schema.Codec<PreviewAnnotationRegionTarget> =
873 Schema.Struct({
874 id: Schema.String,
875 rect: PreviewAnnotationRectSchema,
876 });
877​
878export interface PreviewAnnotationStrokeTarget {
879 id: string;
880 color: string;
881 width: number;
882 points: ReadonlyArray<PreviewAnnotationPoint>;
883 bounds: PreviewAnnotationRect;
885​
886export const PreviewAnnotationStrokeTargetSchema: Schema.Codec<PreviewAnnotationStrokeTarget> =
887 Schema.Struct({
888 id: Schema.String,
889 color: Schema.String,
890 width: Schema.Number,
891 points: Schema.Array(PreviewAnnotationPointSchema),
892 bounds: PreviewAnnotationRectSchema,
893 });
894​
895export interface PreviewAnnotationStyleChange {
896 targetId: string;
897 selector: string | null;
898 property: string;
899 previousValue: string;
900 value: string;
902​
903export const PreviewAnnotationStyleChangeSchema: Schema.Codec<PreviewAnnotationStyleChange> =
904 Schema.Struct({
905 targetId: Schema.String,
906 selector: Schema.NullOr(Schema.String),
907 property: Schema.String,
908 previousValue: Schema.String,
909 value: Schema.String,
910 });
911​
912export interface PreviewAnnotationScreenshot {
913 dataUrl: string;
914 width: number;
915 height: number;
916 cropRect: PreviewAnnotationRect;
918​
919export const PreviewAnnotationScreenshotSchema: Schema.Codec<PreviewAnnotationScreenshot> =
920 Schema.Struct({
921 dataUrl: Schema.String,
922 width: Schema.Number,
923 height: Schema.Number,
924 cropRect: PreviewAnnotationRectSchema,
925 });
926​
927/**
928 * A submitted preview annotation. One annotation may reference multiple DOM
929 * elements, freeform regions, and ink strokes. The desktop main process adds
930 * the screenshot after the guest preload submits the structured draft.
931 */
932export interface PreviewAnnotationPayload {
933 id: string;
934 pageUrl: string;
935 pageTitle: string | null;
936 comment: string;
937 elements: ReadonlyArray<PreviewAnnotationElementTarget>;
938 regions: ReadonlyArray<PreviewAnnotationRegionTarget>;
939 strokes: ReadonlyArray<PreviewAnnotationStrokeTarget>;
940 styleChanges: ReadonlyArray<PreviewAnnotationStyleChange>;
941 screenshot: PreviewAnnotationScreenshot | null;
942 createdAt: string;
944​
945export const PreviewAnnotationPayloadSchema: Schema.Codec<PreviewAnnotationPayload> = Schema.Struct(
946 {
947 id: Schema.String,
948 pageUrl: Schema.String,
949 pageTitle: Schema.NullOr(Schema.String),
950 comment: Schema.String,
951 elements: Schema.Array(PreviewAnnotationElementTargetSchema),
952 regions: Schema.Array(PreviewAnnotationRegionTargetSchema),
953 strokes: Schema.Array(PreviewAnnotationStrokeTargetSchema),
954 styleChanges: Schema.Array(PreviewAnnotationStyleChangeSchema),
955 screenshot: Schema.NullOr(PreviewAnnotationScreenshotSchema),
956 createdAt: Schema.String,
957 },
958);
959​
960export type PreviewAnnotationSubmission = "attach" | "send";
961export const PreviewAnnotationSubmissionSchema: Schema.Codec<PreviewAnnotationSubmission> =
962 Schema.Literals(["attach", "send"]);
963​
964export interface PreviewAnnotationSubmissionResult {
965 annotation: PreviewAnnotationPayload;
966 submission: PreviewAnnotationSubmission;
968export const PreviewAnnotationSubmissionResultSchema: Schema.Codec<PreviewAnnotationSubmissionResult> =
969 Schema.Struct({
970 annotation: PreviewAnnotationPayloadSchema,
971 submission: PreviewAnnotationSubmissionSchema,
972 });
973​
974export const DesktopPreviewTabInputSchema = Schema.Struct({
975 tabId: DesktopPreviewTabIdSchema,
976});
977​
978/**
979 * Tab creation carries the client's configured browser defaults so the guest
980 * is born already zoomed and color-scheme-emulated. Applying them after
981 * creation instead would paint one frame at 100%/system first, which reads as
982 * a flash on every tab open. Both fields are optional so an older renderer
983 * still gets the historical defaults.
984 */
985export const DesktopPreviewCreateTabInputSchema = Schema.Struct({
986 tabId: DesktopPreviewTabIdSchema,
987 zoomFactor: Schema.optional(Schema.Number.check(Schema.isGreaterThan(0))),
988 colorScheme: Schema.optional(DesktopPreviewColorSchemeSchema),
989});
990​
991export interface DesktopPreviewTabDefaults {
992 readonly zoomFactor?: number | undefined;
993 readonly colorScheme?: DesktopPreviewColorScheme | undefined;
995​
996export const DesktopPreviewRegisterWebviewInputSchema = Schema.Struct({
997 tabId: DesktopPreviewTabIdSchema,
998 webContentsId: Schema.Int.check(Schema.isGreaterThan(0)),
999});
1000​
1001export const DesktopPreviewNavigateInputSchema = Schema.Struct({
1002 tabId: DesktopPreviewTabIdSchema,
1003 url: Schema.String,
1004});
1005​
1006export const DesktopPreviewConfigInputSchema = Schema.Struct({
1007 environmentId: EnvironmentId,
1008});
1009​
1010export const DesktopPreviewSetColorSchemeInputSchema = Schema.Struct({
1011 tabId: DesktopPreviewTabIdSchema,
1012 colorScheme: DesktopPreviewColorSchemeSchema,
1013});
1014​
1015export const DesktopPreviewSetAudioMutedInputSchema = Schema.Struct({
1016 tabId: DesktopPreviewTabIdSchema,
1017 audioMuted: Schema.Boolean,
1018});
1019​
1020export const DesktopPreviewAnnotationThemeInputSchema = Schema.Struct({
1021 theme: DesktopPreviewAnnotationThemeSchema,
1022});
1023​
1024export const DesktopPreviewArtifactInputSchema = Schema.Struct({
1025 path: Schema.String.check(Schema.isTrimmed()).check(Schema.isNonEmpty()),
1026});
1027​
1028export const DesktopPreviewRecordingSaveInputSchema = Schema.Struct({
1029 tabId: DesktopPreviewTabIdSchema,
1030 mimeType: Schema.String.check(Schema.isTrimmed()).check(Schema.isNonEmpty()),
1031 data: Schema.Uint8Array,
1032});
1033​
1034export const DesktopPreviewAutomationClickInputSchema = Schema.Struct({
1035 tabId: DesktopPreviewTabIdSchema,
1036 input: PreviewAutomationClickInput,
1037});
1038​
1039export const DesktopPreviewAutomationTypeInputSchema = Schema.Struct({
1040 tabId: DesktopPreviewTabIdSchema,
1041 input: PreviewAutomationTypeInput,
1042});
1043​
1044export const DesktopPreviewAutomationPressInputSchema = Schema.Struct({
1045 tabId: DesktopPreviewTabIdSchema,
1046 input: PreviewAutomationPressInput,
1047});
1048​
1049export const DesktopPreviewAutomationScrollInputSchema = Schema.Struct({
1050 tabId: DesktopPreviewTabIdSchema,
1051 input: PreviewAutomationScrollInput,
1052});
1053​
1054export const DesktopPreviewAutomationEvaluateInputSchema = Schema.Struct({
1055 tabId: DesktopPreviewTabIdSchema,
1056 input: PreviewAutomationEvaluateInput,
1057});
1058​
1059export const DesktopPreviewAutomationWaitForInputSchema = Schema.Struct({
1060 tabId: DesktopPreviewTabIdSchema,
1061 input: PreviewAutomationWaitForInput,
1062});
1063​
1064export interface DesktopBridge {
1065 getAppBranding: () => DesktopAppBranding | null;
1066 /**
1067 * The OS locale as a BCP-47 tag, which the renderer cannot read for itself:
1068 * the packaged app ships only the `en-US` Chromium locale pak, so
1069 * `navigator.language` and the default `Intl` locale are pinned to `en-US`
1070 * regardless of OS settings.
1071 */
1072 getSystemLocale?: () => string | null;
1073 /**
1074 * The filesystem path of a dropped/pasted `File`, which the renderer cannot
1075 * read for itself (Electron removed `File.path` in v32). Returns null when
1076 * the object has no path — e.g. a file synthesised in-page rather than
1077 * dragged in from the OS.
1078 */
1079 getPathForFile?: (file: File) => string | null;
1080 // One bootstrap per pool instance currently registered with bootstrap
1081 // info (omits instances whose backend hasn't produced a config yet).
1082 // The primary backend is identified by id === PRIMARY_LOCAL_ENVIRONMENT_ID.
1083 getLocalEnvironmentBootstraps: () => readonly DesktopEnvironmentBootstrap[];
1084 getLocalEnvironmentBearerToken: () => Promise<string>;
1085 getClientSettings: () => Promise<ClientSettings | null>;
1086 setClientSettings: (settings: ClientSettings) => Promise<void>;
1087 getConnectionCatalog?: () => Promise<string | null>;
1088 setConnectionCatalog?: (catalog: string) => Promise<boolean>;
1089 clearConnectionCatalog?: () => Promise<void>;
1090 discoverSshHosts: () => Promise<readonly DesktopDiscoveredSshHost[]>;
1091 ensureSshEnvironment: (
1092 target: DesktopSshEnvironmentTarget,
1093 options?: { issuePairingToken?: boolean },
1094 ) => Promise<DesktopSshEnvironmentBootstrap>;
1095 disconnectSshEnvironment: (target: DesktopSshEnvironmentTarget) => Promise<void>;
1096 fetchSshEnvironmentDescriptor: (httpBaseUrl: string) => Promise<ExecutionEnvironmentDescriptor>;
1097 bootstrapSshBearerSession: (
1098 httpBaseUrl: string,
1099 credential: string,
1100 ) => Promise<AuthAccessTokenResult>;
1101 fetchSshSessionState: (httpBaseUrl: string, bearerToken: string) => Promise<AuthSessionState>;
1102 issueSshWebSocketTicket: (
1103 httpBaseUrl: string,
1104 bearerToken: string,
1105 ) => Promise<AuthWebSocketTicketResult>;
1106 onSshPasswordPrompt: (listener: (request: DesktopSshPasswordPromptRequest) => void) => () => void;
1107 resolveSshPasswordPrompt: (requestId: string, password: string | null) => Promise<void>;
1108 getServerExposureState: () => Promise<DesktopServerExposureState>;
1109 setServerExposureMode: (mode: DesktopServerExposureMode) => Promise<DesktopServerExposureState>;
1110 setTailscaleServeEnabled: (input: {
1111 readonly enabled: boolean;
1112 readonly port?: number;
1113 }) => Promise<DesktopServerExposureState>;
1114 getAdvertisedEndpoints: () => Promise<readonly AdvertisedEndpoint[]>;
1115 getWslState: () => Promise<DesktopWslState>;
1116 setWslBackendEnabled: (enabled: boolean) => Promise<DesktopWslState>;
1117 setWslDistro: (distro: string | null) => Promise<DesktopWslState>;
1118 setWslOnly: (enabled: boolean) => Promise<DesktopWslState>;
1119 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
1120 /**
1121 * Multi-select JSON file picker that opens in the VS Code extensions
1122 * directory when one exists. Optional: older desktop builds lack it, and
1123 * web callers fall back to a plain file input.
1124 */
1125 pickThemeFiles?: () => Promise<readonly PickedThemeFile[] | null>;
1126 setTheme: (theme: DesktopTheme) => Promise<void>;
1127 showContextMenu: <T extends string>(
1128 items: readonly ContextMenuItem<T>[],
1129 position?: { x: number; y: number },
1130 ) => Promise<T | null>;
1131 openExternal: (url: string) => Promise<boolean>;
1132 /**
1133 * Probe this desktop machine for installed remote-capable editor CLIs
1134 * (used for remote open-in-editor deep links). Optional: older desktop
1135 * builds lack it; callers fall back to VS Code only.
1136 */
1137 probeRemoteEditors?: () => Promise<readonly EditorId[]>;
1138 onMenuAction: (listener: (action: string) => void) => () => void;
1139 /**
1140 * Hold-to-quit hint pushes: "down" when the quit shortcut is first pressed,
1141 * "up" when it is released before the hold completes. Optional: older
1142 * desktop builds never emit it.
1143 */
1144 onQuitShortcut?: (listener: (state: "down" | "up") => void) => () => void;
1145 getWindowFullscreenState: () => boolean;
1146 onWindowFullscreenStateChange: (listener: (fullscreen: boolean) => void) => () => void;
1147 getUpdateState: () => Promise<DesktopUpdateState>;
1148 setUpdateChannel: (channel: DesktopUpdateChannel) => Promise<DesktopUpdateState>;
1149 checkForUpdate: () => Promise<DesktopUpdateCheckResult>;
1150 downloadUpdate: () => Promise<DesktopUpdateActionResult>;
1151 installUpdate: () => Promise<DesktopUpdateActionResult>;
1152 onUpdateState: (listener: (state: DesktopUpdateState) => void) => () => void;
1153 /**
1154 * Desktop-only preview surface. Present iff the renderer is hosted by the
1155 * Electron desktop build; web builds have `preview === undefined`.
1156 */
1157 preview?: DesktopPreviewBridge;
1159​
1160export interface DesktopPreviewBridge {
1161 createTab: (tabId: string, defaults?: DesktopPreviewTabDefaults) => Promise<void>;
1162 closeTab: (tabId: string) => Promise<void>;
1163 registerWebview: (tabId: string, webContentsId: number) => Promise<void>;
1164 navigate: (tabId: string, url: string) => Promise<void>;
1165 goBack: (tabId: string) => Promise<void>;
1166 goForward: (tabId: string) => Promise<void>;
1167 refresh: (tabId: string) => Promise<void>;
1168 zoomIn: (tabId: string) => Promise<void>;
1169 zoomOut: (tabId: string) => Promise<void>;
1170 resetZoom: (tabId: string) => Promise<void>;
1171 /** Reload bypassing the HTTP cache. */
1172 hardReload: (tabId: string) => Promise<void>;
1173 /**
1174 * Emulate `prefers-color-scheme` on the guest page ("system" clears the
1175 * override). Persists per tab and is re-applied across webview swaps.
1176 */
1177 setColorScheme: (tabId: string, colorScheme: DesktopPreviewColorScheme) => Promise<void>;
1178 /**
1179 * Silence the tab's audio output. Persists per tab and is re-applied across
1180 * webview swaps, but is dropped when the tab closes. Muting a silent tab is
1181 * allowed; it simply takes effect once the page plays something.
1182 */
1183 setAudioMuted: (tabId: string, audioMuted: boolean) => Promise<void>;
1184 /** Open the guest webview's DevTools (detached). */
1185 openDevTools: (tabId: string) => Promise<void>;
1186 /** Drop cookies + storage data for the preview partition (all tabs). */
1187 clearCookies: () => Promise<void>;
1188 /** Drop the HTTP cache for the preview partition (all tabs). */
1189 clearCache: () => Promise<void>;
1190 /**
1191 * One-shot config for mounting a preview `<webview>`. Replaces three
1192 * earlier round-trip calls (`getBrowserPartition`, `getWebviewPreferences`,
1193 * `getPickPreloadPath`) so adding a new field here only requires touching
1194 * the contract + main, not the renderer's mount logic.
1195 */
1196 getPreviewConfig: (environmentId: EnvironmentId) => Promise<DesktopPreviewWebviewConfig>;
1197 setAnnotationTheme: (theme: DesktopPreviewAnnotationTheme) => Promise<void>;
1198 /**
1199 * Activate the in-page element picker for the given tab. Resolves with
1200 * the picked annotation and its attach/send intent, or `null` when the
1201 * user cancels (Escape / nav). The promise rejects if the picker can't be
1202 * activated (no webview, etc.).
1203 */
1204 pickElement: (tabId: string) => Promise<PreviewAnnotationSubmissionResult | null>;
1205 /** Cancel an in-flight preview annotation session. */
1206 cancelPickElement: (tabId: string) => Promise<void>;
1207 captureScreenshot: (tabId: string) => Promise<DesktopPreviewScreenshotArtifact>;
1208 revealArtifact: (path: string) => Promise<void>;
1209 copyArtifactToClipboard: (path: string) => Promise<void>;
1210 pictureInPicture: {
1211 open: (tabId: string) => Promise<void>;
1212 close: (tabId: string) => Promise<void>;
1213 };
1214 recording: {
1215 startScreencast: (tabId: string) => Promise<void>;
1216 stopScreencast: (tabId: string) => Promise<void>;
1217 save: (
1218 tabId: string,
1219 mimeType: string,
1220 data: Uint8Array,
1221 ) => Promise<DesktopPreviewRecordingArtifact>;
1222 onFrame: (listener: (frame: DesktopPreviewRecordingFrame) => void) => () => void;
1223 };
1224 automation: {
1225 status: (tabId: string) => Promise<PreviewAutomationStatus>;
1226 snapshot: (tabId: string) => Promise<PreviewAutomationSnapshot>;
1227 click: (tabId: string, input: PreviewAutomationClickInput) => Promise<void>;
1228 type: (tabId: string, input: PreviewAutomationTypeInput) => Promise<void>;
1229 press: (tabId: string, input: PreviewAutomationPressInput) => Promise<void>;
1230 scroll: (tabId: string, input: PreviewAutomationScrollInput) => Promise<void>;
1231 evaluate: (tabId: string, input: PreviewAutomationEvaluateInput) => Promise<unknown>;
1232 waitFor: (tabId: string, input: PreviewAutomationWaitForInput) => Promise<void>;
1233 };
1234 onStateChange: (listener: (tabId: string, state: DesktopPreviewTabState) => void) => () => void;
1235 onPointerEvent: (listener: (event: DesktopPreviewPointerEvent) => void) => () => void;
1237​
1238export type ConfirmDialogVariant = "default" | "destructive";
1239​
1240export interface ConfirmDialogOptions {
1241 readonly variant?: ConfirmDialogVariant;
1243​
1244/**
1245 * APIs bound to the local app shell, not to any particular backend environment.
1247 * These capabilities describe the desktop/browser host that the user is
1248 * currently running: dialogs, external-link opening, context menus, and
1249 * app-level settings/config access. They must not be used as a proxy for
1250 * "whatever environment the user is targeting", because in a multi-environment
1251 * world the local shell and a selected backend environment are distinct
1252 * concepts.
1253 */
1254export interface LocalApi {
1255 dialogs: {
1256 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
1257 confirm: (message: string, options?: ConfirmDialogOptions) => Promise<boolean>;
1258 };
1259 shell: {
1260 openExternal: (url: string) => Promise<void>;
1261 };
1262 contextMenu: {
1263 show: <T extends string>(
1264 items: readonly ContextMenuItem<T>[],
1265 position?: { x: number; y: number },
1266 ) => Promise<T | null>;
1267 close: () => Promise<void>;
1268 };
1269 persistence: {
1270 getClientSettings: () => Promise<ClientSettings | null>;
1271 setClientSettings: (settings: ClientSettings) => Promise<void>;
1272 };
1274​
1275/**
1276 * APIs bound to a specific backend environment connection.
1278 * These operations must always be routed with explicit environment context.
1279 * They represent remote stateful capabilities such as orchestration, terminal,
1280 * project, VCS, and provider operations. In multi-environment mode, each environment gets
1281 * its own instance of this surface, and callers should resolve it by
1282 * `environmentId` rather than reaching through the local desktop bridge.
1283 */
1284export interface EnvironmentApi {
1285 terminal: {
1286 open: (input: typeof TerminalOpenInput.Encoded) => Promise<TerminalSessionSnapshot>;
1287 attach: (
1288 input: typeof TerminalAttachInput.Encoded,
1289 callback: (event: TerminalAttachStreamEvent) => void,
1290 options?: {
1291 onResubscribe?: () => void;
1292 },
1293 ) => () => void;
1294 write: (input: typeof TerminalWriteInput.Encoded) => Promise<void>;
1295 resize: (input: typeof TerminalResizeInput.Encoded) => Promise<void>;
1296 clear: (input: typeof TerminalClearInput.Encoded) => Promise<void>;
1297 restart: (input: typeof TerminalRestartInput.Encoded) => Promise<TerminalSessionSnapshot>;
1298 close: (input: typeof TerminalCloseInput.Encoded) => Promise<void>;
1299 onMetadata: (
1300 callback: (event: TerminalMetadataStreamEvent) => void,
1301 options?: {
1302 onResubscribe?: () => void;
1303 },
1304 ) => () => void;
1305 };
1306 projects: {
1307 listEntries: (input: ProjectListEntriesInput) => Promise<ProjectListEntriesResult>;
1308 readFile: (input: ProjectReadFileInput) => Promise<ProjectReadFileResult>;
1309 searchEntries: (input: ProjectSearchEntriesInput) => Promise<ProjectSearchEntriesResult>;
1310 writeFile: (input: ProjectWriteFileInput) => Promise<ProjectWriteFileResult>;
1311 };
1312 filesystem: {
1313 browse: (input: FilesystemBrowseInput) => Promise<FilesystemBrowseResult>;
1314 };
1315 assets: {
1316 createUrl: (input: AssetCreateUrlInput) => Promise<AssetCreateUrlResult>;
1317 };
1318 sourceControl: {
1319 lookupRepository: (
1320 input: SourceControlRepositoryLookupInput,
1321 ) => Promise<SourceControlRepositoryInfo>;
1322 cloneRepository: (
1323 input: SourceControlCloneRepositoryInput,
1324 ) => Promise<SourceControlCloneRepositoryResult>;
1325 publishRepository: (
1326 input: SourceControlPublishRepositoryInput,
1327 ) => Promise<SourceControlPublishRepositoryResult>;
1328 };
1329 vcs: {
1330 listRefs: (input: VcsListRefsInput) => Promise<VcsListRefsResult>;
1331 createWorktree: (input: VcsCreateWorktreeInput) => Promise<VcsCreateWorktreeResult>;
1332 removeWorktree: (input: VcsRemoveWorktreeInput) => Promise<void>;
1333 createRef: (input: VcsCreateRefInput) => Promise<VcsCreateRefResult>;
1334 switchRef: (input: VcsSwitchRefInput) => Promise<VcsSwitchRefResult>;
1335 init: (input: VcsInitInput) => Promise<void>;
1336 pull: (input: VcsPullInput) => Promise<VcsPullResult>;
1337 refreshStatus: (input: VcsStatusInput) => Promise<VcsStatusResult>;
1338 onStatus: (
1339 input: VcsStatusInput,
1340 callback: (status: VcsStatusResult) => void,
1341 options?: {
1342 onResubscribe?: () => void;
1343 },
1344 ) => () => void;
1345 };
1346 git: {
1347 resolvePullRequest: (input: GitPullRequestRefInput) => Promise<GitResolvePullRequestResult>;
1348 preparePullRequestThread: (
1349 input: GitPreparePullRequestThreadInput,
1350 ) => Promise<GitPreparePullRequestThreadResult>;
1351 };
1352 review: {
1353 getDiffPreview: (input: ReviewDiffPreviewInput) => Promise<ReviewDiffPreviewResult>;
1354 getDiffFileContents: (
1355 input: ReviewDiffFileContentsInput,
1356 ) => Promise<ReviewDiffFileContentsResult>;
1357 };
1358 orchestration: {
1359 dispatchCommand: (command: ClientOrchestrationCommand) => Promise<{ sequence: number }>;
1360 getTurnDiff: (input: OrchestrationGetTurnDiffInput) => Promise<OrchestrationGetTurnDiffResult>;
1361 getFullThreadDiff: (
1362 input: OrchestrationGetFullThreadDiffInput,
1363 ) => Promise<OrchestrationGetFullThreadDiffResult>;
1364 getArchivedShellSnapshot: () => Promise<OrchestrationShellSnapshot>;
1365 subscribeShell: (
1366 callback: (event: OrchestrationShellStreamItem) => void,
1367 options?: {
1368 onResubscribe?: () => void;
1369 },
1370 ) => () => void;
1371 subscribeThread: (
1372 input: OrchestrationSubscribeThreadInput,
1373 callback: (event: OrchestrationThreadStreamItem) => void,
1374 options?: {
1375 onResubscribe?: () => void;
1376 },
1377 ) => () => void;
1378 };
1379 preview: {
1380 open: (input: typeof PreviewOpenInput.Encoded) => Promise<PreviewSessionSnapshot>;
1381 navigate: (input: typeof PreviewNavigateInput.Encoded) => Promise<PreviewSessionSnapshot>;
1382 resize: (input: typeof PreviewResizeInput.Encoded) => Promise<PreviewSessionSnapshot>;
1383 refresh: (input: typeof PreviewRefreshInput.Encoded) => Promise<void>;
1384 close: (input: typeof PreviewCloseInput.Encoded) => Promise<void>;
1385 list: (input: typeof PreviewListInput.Encoded) => Promise<PreviewListResult>;
1386 reportStatus: (input: typeof PreviewReportStatusInput.Encoded) => Promise<void>;
1387 automation: {
1388 connect: (
1389 input: PreviewAutomationHost,
1390 callback: (event: PreviewAutomationStreamEvent) => void,
1391 options?: { onResubscribe?: () => void },
1392 ) => () => void;
1393 respond: (response: PreviewAutomationResponse) => Promise<void>;
1394 focusHost: (input: PreviewAutomationHostFocus) => Promise<void>;
1395 };
1396 onEvent: (
1397 callback: (event: PreviewEvent) => void,
1398 options?: { onResubscribe?: () => void },
1399 ) => () => void;
1400 subscribePorts: (
1401 callback: (servers: DiscoveredLocalServerList) => void,
1402 options?: { onResubscribe?: () => void },
1403 ) => () => void;
1404 };