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