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