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