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