Open History to see the last commit
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>[];
117}
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[];
128}
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;
179}
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;
191}
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;
215}
216
217export interface DesktopUpdateReleaseNote {
218 version: string;
219 items: ReadonlyArray<string>;
220}
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;
249}
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;
260}
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;
286}
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;
310}
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";
327}
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;
344}
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;
423}
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;
441}
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;
457}
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;
469}
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;
496}
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;
539}
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;
581}
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;
631}
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;
664}
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;
691}
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;
720}
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;
738}
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;
757}
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;
779}
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;
815}
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;
835}
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;
847}
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;
858}
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;
870}
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;
884}
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;
901}
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;
917}
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;
943}
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;
967}
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;
994}
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 // One bootstrap per pool instance currently registered with bootstrap
1074 // info (omits instances whose backend hasn't produced a config yet).
1075 // The primary backend is identified by id === PRIMARY_LOCAL_ENVIRONMENT_ID.
1076 getLocalEnvironmentBootstraps: () => readonly DesktopEnvironmentBootstrap[];
1077 getLocalEnvironmentBearerToken: () => Promise<string>;
1078 getClientSettings: () => Promise<ClientSettings | null>;
1079 setClientSettings: (settings: ClientSettings) => Promise<void>;
1080 getConnectionCatalog?: () => Promise<string | null>;
1081 setConnectionCatalog?: (catalog: string) => Promise<boolean>;
1082 clearConnectionCatalog?: () => Promise<void>;
1083 discoverSshHosts: () => Promise<readonly DesktopDiscoveredSshHost[]>;
1084 ensureSshEnvironment: (
1085 target: DesktopSshEnvironmentTarget,
1086 options?: { issuePairingToken?: boolean },
1087 ) => Promise<DesktopSshEnvironmentBootstrap>;
1088 disconnectSshEnvironment: (target: DesktopSshEnvironmentTarget) => Promise<void>;
1089 fetchSshEnvironmentDescriptor: (httpBaseUrl: string) => Promise<ExecutionEnvironmentDescriptor>;
1090 bootstrapSshBearerSession: (
1091 httpBaseUrl: string,
1092 credential: string,
1093 ) => Promise<AuthAccessTokenResult>;
1094 fetchSshSessionState: (httpBaseUrl: string, bearerToken: string) => Promise<AuthSessionState>;
1095 issueSshWebSocketTicket: (
1096 httpBaseUrl: string,
1097 bearerToken: string,
1098 ) => Promise<AuthWebSocketTicketResult>;
1099 onSshPasswordPrompt: (listener: (request: DesktopSshPasswordPromptRequest) => void) => () => void;
1100 resolveSshPasswordPrompt: (requestId: string, password: string | null) => Promise<void>;
1101 getServerExposureState: () => Promise<DesktopServerExposureState>;
1102 setServerExposureMode: (mode: DesktopServerExposureMode) => Promise<DesktopServerExposureState>;
1103 setTailscaleServeEnabled: (input: {
1104 readonly enabled: boolean;
1105 readonly port?: number;
1106 }) => Promise<DesktopServerExposureState>;
1107 getAdvertisedEndpoints: () => Promise<readonly AdvertisedEndpoint[]>;
1108 getWslState: () => Promise<DesktopWslState>;
1109 setWslBackendEnabled: (enabled: boolean) => Promise<DesktopWslState>;
1110 setWslDistro: (distro: string | null) => Promise<DesktopWslState>;
1111 setWslOnly: (enabled: boolean) => Promise<DesktopWslState>;
1112 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
1113 /** Optional while older desktop shells can host a newer web client. */
1114 pickProjectFavicon?: (initialPath?: string) => Promise<string | null>;
1115 /**
1116 * Multi-select JSON file picker that opens in the VS Code extensions
1117 * directory when one exists. Optional: older desktop builds lack it, and
1118 * web callers fall back to a plain file input.
1119 */
1120 pickThemeFiles?: () => Promise<readonly PickedThemeFile[] | null>;
1121 setTheme: (theme: DesktopTheme) => Promise<void>;
1122 showContextMenu: <T extends string>(
1123 items: readonly ContextMenuItem<T>[],
1124 position?: { x: number; y: number },
1125 ) => Promise<T | null>;
1126 openExternal: (url: string) => Promise<boolean>;
1127 /**
1128 * Probe this desktop machine for installed remote-capable editor CLIs
1129 * (used for remote open-in-editor deep links). Optional: older desktop
1130 * builds lack it; callers fall back to VS Code only.
1131 */
1132 probeRemoteEditors?: () => Promise<readonly EditorId[]>;
1133 onMenuAction: (listener: (action: string) => void) => () => void;
1134 /**
1135 * Hold-to-quit hint pushes: "down" when the quit shortcut is first pressed,
1136 * "up" when it is released before the hold completes. Optional: older
1137 * desktop builds never emit it.
1138 */
1139 onQuitShortcut?: (listener: (state: "down" | "up") => void) => () => void;
1140 getWindowFullscreenState: () => boolean;
1141 onWindowFullscreenStateChange: (listener: (fullscreen: boolean) => void) => () => void;
1142 getUpdateState: () => Promise<DesktopUpdateState>;
1143 setUpdateChannel: (channel: DesktopUpdateChannel) => Promise<DesktopUpdateState>;
1144 checkForUpdate: () => Promise<DesktopUpdateCheckResult>;
1145 downloadUpdate: () => Promise<DesktopUpdateActionResult>;
1146 installUpdate: () => Promise<DesktopUpdateActionResult>;
1147 onUpdateState: (listener: (state: DesktopUpdateState) => void) => () => void;
1148 /**
1149 * Desktop-only preview surface. Present iff the renderer is hosted by the
1150 * Electron desktop build; web builds have `preview === undefined`.
1151 */
1152 preview?: DesktopPreviewBridge;
1153}
1154
1155export interface DesktopPreviewBridge {
1156 createTab: (tabId: string, defaults?: DesktopPreviewTabDefaults) => Promise<void>;
1157 closeTab: (tabId: string) => Promise<void>;
1158 registerWebview: (tabId: string, webContentsId: number) => Promise<void>;
1159 navigate: (tabId: string, url: string) => Promise<void>;
1160 goBack: (tabId: string) => Promise<void>;
1161 goForward: (tabId: string) => Promise<void>;
1162 refresh: (tabId: string) => Promise<void>;
1163 zoomIn: (tabId: string) => Promise<void>;
1164 zoomOut: (tabId: string) => Promise<void>;
1165 resetZoom: (tabId: string) => Promise<void>;
1166 /** Reload bypassing the HTTP cache. */
1167 hardReload: (tabId: string) => Promise<void>;
1168 /**
1169 * Emulate `prefers-color-scheme` on the guest page ("system" clears the
1170 * override). Persists per tab and is re-applied across webview swaps.
1171 */
1172 setColorScheme: (tabId: string, colorScheme: DesktopPreviewColorScheme) => Promise<void>;
1173 /**
1174 * Silence the tab's audio output. Persists per tab and is re-applied across
1175 * webview swaps, but is dropped when the tab closes. Muting a silent tab is
1176 * allowed; it simply takes effect once the page plays something.
1177 */
1178 setAudioMuted: (tabId: string, audioMuted: boolean) => Promise<void>;
1179 /** Open the guest webview's DevTools (detached). */
1180 openDevTools: (tabId: string) => Promise<void>;
1181 /** Drop cookies + storage data for the preview partition (all tabs). */
1182 clearCookies: () => Promise<void>;
1183 /** Drop the HTTP cache for the preview partition (all tabs). */
1184 clearCache: () => Promise<void>;
1185 /**
1186 * One-shot config for mounting a preview `<webview>`. Replaces three
1187 * earlier round-trip calls (`getBrowserPartition`, `getWebviewPreferences`,
1188 * `getPickPreloadPath`) so adding a new field here only requires touching
1189 * the contract + main, not the renderer's mount logic.
1190 */
1191 getPreviewConfig: (environmentId: EnvironmentId) => Promise<DesktopPreviewWebviewConfig>;
1192 setAnnotationTheme: (theme: DesktopPreviewAnnotationTheme) => Promise<void>;
1193 /**
1194 * Activate the in-page element picker for the given tab. Resolves with
1195 * the picked annotation and its attach/send intent, or `null` when the
1196 * user cancels (Escape / nav). The promise rejects if the picker can't be
1197 * activated (no webview, etc.).
1198 */
1199 pickElement: (tabId: string) => Promise<PreviewAnnotationSubmissionResult | null>;
1200 /** Cancel an in-flight preview annotation session. */
1201 cancelPickElement: (tabId: string) => Promise<void>;
1202 captureScreenshot: (tabId: string) => Promise<DesktopPreviewScreenshotArtifact>;
1203 revealArtifact: (path: string) => Promise<void>;
1204 copyArtifactToClipboard: (path: string) => Promise<void>;
1205 pictureInPicture: {
1206 open: (tabId: string) => Promise<void>;
1207 close: (tabId: string) => Promise<void>;
1208 };
1209 recording: {
1210 startScreencast: (tabId: string) => Promise<void>;
1211 stopScreencast: (tabId: string) => Promise<void>;
1212 save: (
1213 tabId: string,
1214 mimeType: string,
1215 data: Uint8Array,
1216 ) => Promise<DesktopPreviewRecordingArtifact>;
1217 onFrame: (listener: (frame: DesktopPreviewRecordingFrame) => void) => () => void;
1218 };
1219 automation: {
1220 status: (tabId: string) => Promise<PreviewAutomationStatus>;
1221 snapshot: (tabId: string) => Promise<PreviewAutomationSnapshot>;
1222 click: (tabId: string, input: PreviewAutomationClickInput) => Promise<void>;
1223 type: (tabId: string, input: PreviewAutomationTypeInput) => Promise<void>;
1224 press: (tabId: string, input: PreviewAutomationPressInput) => Promise<void>;
1225 scroll: (tabId: string, input: PreviewAutomationScrollInput) => Promise<void>;
1226 evaluate: (tabId: string, input: PreviewAutomationEvaluateInput) => Promise<unknown>;
1227 waitFor: (tabId: string, input: PreviewAutomationWaitForInput) => Promise<void>;
1228 };
1229 onStateChange: (listener: (tabId: string, state: DesktopPreviewTabState) => void) => () => void;
1230 onPointerEvent: (listener: (event: DesktopPreviewPointerEvent) => void) => () => void;
1231}
1232
1233export type ConfirmDialogVariant = "default" | "destructive";
1234
1235export interface ConfirmDialogOptions {
1236 readonly variant?: ConfirmDialogVariant;
1237}
1238
1239/**
1240 * APIs bound to the local app shell, not to any particular backend environment.
1241 *
1242 * These capabilities describe the desktop/browser host that the user is
1243 * currently running: dialogs, external-link opening, context menus, and
1244 * app-level settings/config access. They must not be used as a proxy for
1245 * "whatever environment the user is targeting", because in a multi-environment
1246 * world the local shell and a selected backend environment are distinct
1247 * concepts.
1248 */
1249export interface LocalApi {
1250 dialogs: {
1251 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
1252 confirm: (message: string, options?: ConfirmDialogOptions) => Promise<boolean>;
1253 };
1254 shell: {
1255 openExternal: (url: string) => Promise<void>;
1256 };
1257 contextMenu: {
1258 show: <T extends string>(
1259 items: readonly ContextMenuItem<T>[],
1260 position?: { x: number; y: number },
1261 ) => Promise<T | null>;
1262 close: () => Promise<void>;
1263 };
1264 persistence: {
1265 getClientSettings: () => Promise<ClientSettings | null>;
1266 setClientSettings: (settings: ClientSettings) => Promise<void>;
1267 };
1268}
1269
1270/**
1271 * APIs bound to a specific backend environment connection.
1272 *
1273 * These operations must always be routed with explicit environment context.
1274 * They represent remote stateful capabilities such as orchestration, terminal,
1275 * project, VCS, and provider operations. In multi-environment mode, each environment gets
1276 * its own instance of this surface, and callers should resolve it by
1277 * `environmentId` rather than reaching through the local desktop bridge.
1278 */
1279export interface EnvironmentApi {
1280 terminal: {
1281 open: (input: typeof TerminalOpenInput.Encoded) => Promise<TerminalSessionSnapshot>;
1282 attach: (
1283 input: typeof TerminalAttachInput.Encoded,
1284 callback: (event: TerminalAttachStreamEvent) => void,
1285 options?: {
1286 onResubscribe?: () => void;
1287 },
1288 ) => () => void;
1289 write: (input: typeof TerminalWriteInput.Encoded) => Promise<void>;
1290 resize: (input: typeof TerminalResizeInput.Encoded) => Promise<void>;
1291 clear: (input: typeof TerminalClearInput.Encoded) => Promise<void>;
1292 restart: (input: typeof TerminalRestartInput.Encoded) => Promise<TerminalSessionSnapshot>;
1293 close: (input: typeof TerminalCloseInput.Encoded) => Promise<void>;
1294 onMetadata: (
1295 callback: (event: TerminalMetadataStreamEvent) => void,
1296 options?: {
1297 onResubscribe?: () => void;
1298 },
1299 ) => () => void;
1300 };
1301 projects: {
1302 listEntries: (input: ProjectListEntriesInput) => Promise<ProjectListEntriesResult>;
1303 readFile: (input: ProjectReadFileInput) => Promise<ProjectReadFileResult>;
1304 searchEntries: (input: ProjectSearchEntriesInput) => Promise<ProjectSearchEntriesResult>;
1305 writeFile: (input: ProjectWriteFileInput) => Promise<ProjectWriteFileResult>;
1306 };
1307 filesystem: {
1308 browse: (input: FilesystemBrowseInput) => Promise<FilesystemBrowseResult>;
1309 };
1310 assets: {
1311 createUrl: (input: AssetCreateUrlInput) => Promise<AssetCreateUrlResult>;
1312 };
1313 sourceControl: {
1314 lookupRepository: (
1315 input: SourceControlRepositoryLookupInput,
1316 ) => Promise<SourceControlRepositoryInfo>;
1317 cloneRepository: (
1318 input: SourceControlCloneRepositoryInput,
1319 ) => Promise<SourceControlCloneRepositoryResult>;
1320 publishRepository: (
1321 input: SourceControlPublishRepositoryInput,
1322 ) => Promise<SourceControlPublishRepositoryResult>;
1323 };
1324 vcs: {
1325 listRefs: (input: VcsListRefsInput) => Promise<VcsListRefsResult>;
1326 createWorktree: (input: VcsCreateWorktreeInput) => Promise<VcsCreateWorktreeResult>;
1327 removeWorktree: (input: VcsRemoveWorktreeInput) => Promise<void>;
1328 createRef: (input: VcsCreateRefInput) => Promise<VcsCreateRefResult>;
1329 switchRef: (input: VcsSwitchRefInput) => Promise<VcsSwitchRefResult>;
1330 init: (input: VcsInitInput) => Promise<void>;
1331 pull: (input: VcsPullInput) => Promise<VcsPullResult>;
1332 refreshStatus: (input: VcsStatusInput) => Promise<VcsStatusResult>;
1333 onStatus: (
1334 input: VcsStatusInput,
1335 callback: (status: VcsStatusResult) => void,
1336 options?: {
1337 onResubscribe?: () => void;
1338 },
1339 ) => () => void;
1340 };
1341 git: {
1342 resolvePullRequest: (input: GitPullRequestRefInput) => Promise<GitResolvePullRequestResult>;
1343 preparePullRequestThread: (
1344 input: GitPreparePullRequestThreadInput,
1345 ) => Promise<GitPreparePullRequestThreadResult>;
1346 };
1347 review: {
1348 getDiffPreview: (input: ReviewDiffPreviewInput) => Promise<ReviewDiffPreviewResult>;
1349 getDiffFileContents: (
1350 input: ReviewDiffFileContentsInput,
1351 ) => Promise<ReviewDiffFileContentsResult>;
1352 };
1353 orchestration: {
1354 dispatchCommand: (command: ClientOrchestrationCommand) => Promise<{ sequence: number }>;
1355 getTurnDiff: (input: OrchestrationGetTurnDiffInput) => Promise<OrchestrationGetTurnDiffResult>;
1356 getFullThreadDiff: (
1357 input: OrchestrationGetFullThreadDiffInput,
1358 ) => Promise<OrchestrationGetFullThreadDiffResult>;
1359 getArchivedShellSnapshot: () => Promise<OrchestrationShellSnapshot>;
1360 subscribeShell: (
1361 callback: (event: OrchestrationShellStreamItem) => void,
1362 options?: {
1363 onResubscribe?: () => void;
1364 },
1365 ) => () => void;
1366 subscribeThread: (
1367 input: OrchestrationSubscribeThreadInput,
1368 callback: (event: OrchestrationThreadStreamItem) => void,
1369 options?: {
1370 onResubscribe?: () => void;
1371 },
1372 ) => () => void;
1373 };
1374 preview: {
1375 open: (input: typeof PreviewOpenInput.Encoded) => Promise<PreviewSessionSnapshot>;
1376 navigate: (input: typeof PreviewNavigateInput.Encoded) => Promise<PreviewSessionSnapshot>;
1377 resize: (input: typeof PreviewResizeInput.Encoded) => Promise<PreviewSessionSnapshot>;
1378 refresh: (input: typeof PreviewRefreshInput.Encoded) => Promise<void>;
1379 close: (input: typeof PreviewCloseInput.Encoded) => Promise<void>;
1380 list: (input: typeof PreviewListInput.Encoded) => Promise<PreviewListResult>;
1381 reportStatus: (input: typeof PreviewReportStatusInput.Encoded) => Promise<void>;
1382 automation: {
1383 connect: (
1384 input: PreviewAutomationHost,
1385 callback: (event: PreviewAutomationStreamEvent) => void,
1386 options?: { onResubscribe?: () => void },
1387 ) => () => void;
1388 respond: (response: PreviewAutomationResponse) => Promise<void>;
1389 focusHost: (input: PreviewAutomationHostFocus) => Promise<void>;
1390 };
1391 onEvent: (
1392 callback: (event: PreviewEvent) => void,
1393 options?: { onResubscribe?: () => void },
1394 ) => () => void;
1395 subscribePorts: (
1396 callback: (servers: DiscoveredLocalServerList) => void,
1397 options?: { onResubscribe?: () => void },
1398 ) => () => void;
1399 };
1400}