Open History to see the last commit
1import type {
2 GitCheckoutInput,
3 GitCheckoutResult,
4 GitCreateBranchInput,
5 GitPreparePullRequestThreadInput,
6 GitPreparePullRequestThreadResult,
7 GitPullRequestRefInput,
8 GitCreateWorktreeInput,
9 GitCreateWorktreeResult,
10 GitInitInput,
11 GitListBranchesInput,
12 GitListBranchesResult,
13 GitPullInput,
14 GitPullResult,
15 GitRemoveWorktreeInput,
16 GitResolvePullRequestResult,
17 GitStatusInput,
18 GitStatusResult,
19 GitCreateBranchResult,
20} from "./git";
21import type { FilesystemBrowseInput, FilesystemBrowseResult } from "./filesystem";
22import type {
23 ProjectSearchEntriesInput,
24 ProjectSearchEntriesResult,
25 ProjectWriteFileInput,
26 ProjectWriteFileResult,
27} from "./project";
28import type {
29 ServerConfig,
30 ServerProviderUpdatedPayload,
31 ServerUpsertKeybindingResult,
32} from "./server";
33import type {
34 TerminalClearInput,
35 TerminalCloseInput,
36 TerminalEvent,
37 TerminalOpenInput,
38 TerminalResizeInput,
39 TerminalRestartInput,
40 TerminalSessionSnapshot,
41 TerminalWriteInput,
42} from "./terminal";
43import type { ServerUpsertKeybindingInput } from "./server";
44import type {
45 ClientOrchestrationCommand,
46 OrchestrationGetFullThreadDiffInput,
47 OrchestrationGetFullThreadDiffResult,
48 OrchestrationGetTurnDiffInput,
49 OrchestrationGetTurnDiffResult,
50 OrchestrationShellStreamItem,
51 OrchestrationSubscribeThreadInput,
52 OrchestrationThreadStreamItem,
53} from "./orchestration";
54import type { EnvironmentId } from "./baseSchemas";
55import { EditorId } from "./editor";
56import { ClientSettings, ServerSettings, ServerSettingsPatch } from "./settings";
57
58export interface ContextMenuItem<T extends string = string> {
59 id: T;
60 label: string;
61 destructive?: boolean;
62 disabled?: boolean;
63 children?: readonly ContextMenuItem<T>[];
64}
65
66export type DesktopUpdateStatus =
67 | "disabled"
68 | "idle"
69 | "checking"
70 | "up-to-date"
71 | "available"
72 | "downloading"
73 | "downloaded"
74 | "error";
75
76export type DesktopRuntimeArch = "arm64" | "x64" | "other";
77export type DesktopTheme = "light" | "dark" | "system";
78export type DesktopUpdateChannel = "latest" | "nightly";
79export type DesktopAppStageLabel = "Alpha" | "Dev" | "Nightly";
80
81export interface DesktopAppBranding {
82 baseName: string;
83 stageLabel: DesktopAppStageLabel;
84 displayName: string;
85}
86
87export interface DesktopRuntimeInfo {
88 hostArch: DesktopRuntimeArch;
89 appArch: DesktopRuntimeArch;
90 runningUnderArm64Translation: boolean;
91}
92
93export interface DesktopUpdateState {
94 enabled: boolean;
95 status: DesktopUpdateStatus;
96 channel: DesktopUpdateChannel;
97 currentVersion: string;
98 hostArch: DesktopRuntimeArch;
99 appArch: DesktopRuntimeArch;
100 runningUnderArm64Translation: boolean;
101 availableVersion: string | null;
102 downloadedVersion: string | null;
103 downloadPercent: number | null;
104 checkedAt: string | null;
105 message: string | null;
106 errorContext: "check" | "download" | "install" | null;
107 canRetry: boolean;
108}
109
110export interface DesktopUpdateActionResult {
111 accepted: boolean;
112 completed: boolean;
113 state: DesktopUpdateState;
114}
115
116export interface DesktopUpdateCheckResult {
117 checked: boolean;
118 state: DesktopUpdateState;
119}
120
121export interface DesktopEnvironmentBootstrap {
122 label: string;
123 httpBaseUrl: string | null;
124 wsBaseUrl: string | null;
125 bootstrapToken?: string;
126}
127
128export interface PersistedSavedEnvironmentRecord {
129 environmentId: EnvironmentId;
130 label: string;
131 wsBaseUrl: string;
132 httpBaseUrl: string;
133 createdAt: string;
134 lastConnectedAt: string | null;
135}
136
137export type DesktopServerExposureMode = "local-only" | "network-accessible";
138
139export interface DesktopServerExposureState {
140 mode: DesktopServerExposureMode;
141 endpointUrl: string | null;
142 advertisedHost: string | null;
143}
144
145export interface PickFolderOptions {
146 initialPath?: string | null;
147}
148
149export interface DesktopBridge {
150 getAppBranding: () => DesktopAppBranding | null;
151 getLocalEnvironmentBootstrap: () => DesktopEnvironmentBootstrap | null;
152 getClientSettings: () => Promise<ClientSettings | null>;
153 setClientSettings: (settings: ClientSettings) => Promise<void>;
154 getSavedEnvironmentRegistry: () => Promise<readonly PersistedSavedEnvironmentRecord[]>;
155 setSavedEnvironmentRegistry: (
156 records: readonly PersistedSavedEnvironmentRecord[],
157 ) => Promise<void>;
158 getSavedEnvironmentSecret: (environmentId: EnvironmentId) => Promise<string | null>;
159 setSavedEnvironmentSecret: (environmentId: EnvironmentId, secret: string) => Promise<boolean>;
160 removeSavedEnvironmentSecret: (environmentId: EnvironmentId) => Promise<void>;
161 getServerExposureState: () => Promise<DesktopServerExposureState>;
162 setServerExposureMode: (mode: DesktopServerExposureMode) => Promise<DesktopServerExposureState>;
163 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
164 confirm: (message: string) => Promise<boolean>;
165 setTheme: (theme: DesktopTheme) => Promise<void>;
166 showContextMenu: <T extends string>(
167 items: readonly ContextMenuItem<T>[],
168 position?: { x: number; y: number },
169 ) => Promise<T | null>;
170 openExternal: (url: string) => Promise<boolean>;
171 onMenuAction: (listener: (action: string) => void) => () => void;
172 getUpdateState: () => Promise<DesktopUpdateState>;
173 setUpdateChannel: (channel: DesktopUpdateChannel) => Promise<DesktopUpdateState>;
174 checkForUpdate: () => Promise<DesktopUpdateCheckResult>;
175 downloadUpdate: () => Promise<DesktopUpdateActionResult>;
176 installUpdate: () => Promise<DesktopUpdateActionResult>;
177 onUpdateState: (listener: (state: DesktopUpdateState) => void) => () => void;
178}
179
180/**
181 * APIs bound to the local app shell, not to any particular backend environment.
182 *
183 * These capabilities describe the desktop/browser host that the user is
184 * currently running: dialogs, editor/external-link opening, context menus, and
185 * app-level settings/config access. They must not be used as a proxy for
186 * "whatever environment the user is targeting", because in a multi-environment
187 * world the local shell and a selected backend environment are distinct
188 * concepts.
189 */
190export interface LocalApi {
191 dialogs: {
192 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
193 confirm: (message: string) => Promise<boolean>;
194 };
195 shell: {
196 openInEditor: (cwd: string, editor: EditorId) => Promise<void>;
197 openExternal: (url: string) => Promise<void>;
198 };
199 contextMenu: {
200 show: <T extends string>(
201 items: readonly ContextMenuItem<T>[],
202 position?: { x: number; y: number },
203 ) => Promise<T | null>;
204 };
205 persistence: {
206 getClientSettings: () => Promise<ClientSettings | null>;
207 setClientSettings: (settings: ClientSettings) => Promise<void>;
208 getSavedEnvironmentRegistry: () => Promise<readonly PersistedSavedEnvironmentRecord[]>;
209 setSavedEnvironmentRegistry: (
210 records: readonly PersistedSavedEnvironmentRecord[],
211 ) => Promise<void>;
212 getSavedEnvironmentSecret: (environmentId: EnvironmentId) => Promise<string | null>;
213 setSavedEnvironmentSecret: (environmentId: EnvironmentId, secret: string) => Promise<boolean>;
214 removeSavedEnvironmentSecret: (environmentId: EnvironmentId) => Promise<void>;
215 };
216 server: {
217 getConfig: () => Promise<ServerConfig>;
218 refreshProviders: () => Promise<ServerProviderUpdatedPayload>;
219 upsertKeybinding: (input: ServerUpsertKeybindingInput) => Promise<ServerUpsertKeybindingResult>;
220 getSettings: () => Promise<ServerSettings>;
221 updateSettings: (patch: ServerSettingsPatch) => Promise<ServerSettings>;
222 };
223}
224
225/**
226 * APIs bound to a specific backend environment connection.
227 *
228 * These operations must always be routed with explicit environment context.
229 * They represent remote stateful capabilities such as orchestration, terminal,
230 * project, and git operations. In multi-environment mode, each environment gets
231 * its own instance of this surface, and callers should resolve it by
232 * `environmentId` rather than reaching through the local desktop bridge.
233 */
234export interface EnvironmentApi {
235 terminal: {
236 open: (input: typeof TerminalOpenInput.Encoded) => Promise<TerminalSessionSnapshot>;
237 write: (input: typeof TerminalWriteInput.Encoded) => Promise<void>;
238 resize: (input: typeof TerminalResizeInput.Encoded) => Promise<void>;
239 clear: (input: typeof TerminalClearInput.Encoded) => Promise<void>;
240 restart: (input: typeof TerminalRestartInput.Encoded) => Promise<TerminalSessionSnapshot>;
241 close: (input: typeof TerminalCloseInput.Encoded) => Promise<void>;
242 onEvent: (callback: (event: TerminalEvent) => void) => () => void;
243 };
244 projects: {
245 searchEntries: (input: ProjectSearchEntriesInput) => Promise<ProjectSearchEntriesResult>;
246 writeFile: (input: ProjectWriteFileInput) => Promise<ProjectWriteFileResult>;
247 };
248 filesystem: {
249 browse: (input: FilesystemBrowseInput) => Promise<FilesystemBrowseResult>;
250 };
251 git: {
252 listBranches: (input: GitListBranchesInput) => Promise<GitListBranchesResult>;
253 createWorktree: (input: GitCreateWorktreeInput) => Promise<GitCreateWorktreeResult>;
254 removeWorktree: (input: GitRemoveWorktreeInput) => Promise<void>;
255 createBranch: (input: GitCreateBranchInput) => Promise<GitCreateBranchResult>;
256 checkout: (input: GitCheckoutInput) => Promise<GitCheckoutResult>;
257 init: (input: GitInitInput) => Promise<void>;
258 resolvePullRequest: (input: GitPullRequestRefInput) => Promise<GitResolvePullRequestResult>;
259 preparePullRequestThread: (
260 input: GitPreparePullRequestThreadInput,
261 ) => Promise<GitPreparePullRequestThreadResult>;
262 pull: (input: GitPullInput) => Promise<GitPullResult>;
263 refreshStatus: (input: GitStatusInput) => Promise<GitStatusResult>;
264 onStatus: (
265 input: GitStatusInput,
266 callback: (status: GitStatusResult) => void,
267 options?: {
268 onResubscribe?: () => void;
269 },
270 ) => () => void;
271 };
272 orchestration: {
273 dispatchCommand: (command: ClientOrchestrationCommand) => Promise<{ sequence: number }>;
274 getTurnDiff: (input: OrchestrationGetTurnDiffInput) => Promise<OrchestrationGetTurnDiffResult>;
275 getFullThreadDiff: (
276 input: OrchestrationGetFullThreadDiffInput,
277 ) => Promise<OrchestrationGetFullThreadDiffResult>;
278 subscribeShell: (
279 callback: (event: OrchestrationShellStreamItem) => void,
280 options?: {
281 onResubscribe?: () => void;
282 },
283 ) => () => void;
284 subscribeThread: (
285 input: OrchestrationSubscribeThreadInput,
286 callback: (event: OrchestrationThreadStreamItem) => void,
287 options?: {
288 onResubscribe?: () => void;
289 },
290 ) => () => void;
291 };
292}