@farero-ai/agent-runner 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +170 -2
- package/dist/index.d.ts +1435 -0
- package/dist/index.js +69 -0
- package/package.json +27 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1435 @@
|
|
|
1
|
+
import { ChildProcessWithoutNullStreams } from 'node:child_process';
|
|
2
|
+
import { Query, SessionStore } from '@anthropic-ai/claude-agent-sdk';
|
|
3
|
+
import { Tool, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Portable shared API request/response contracts for local coding-agent applications.
|
|
7
|
+
*
|
|
8
|
+
* This module owns the DTOs that cross `/api` and have no dependency on app
|
|
9
|
+
* storage, processes, or Node runtimes: delegation, Workflow projections,
|
|
10
|
+
* attachments, provider/capability metadata, and the request inputs the Zod
|
|
11
|
+
* schemas in the host validate. Response envelopes that compose host-owned
|
|
12
|
+
* projections (workspaces, sessions, transcripts) stay in the host's wire
|
|
13
|
+
* module, which re-exports everything here for compatibility.
|
|
14
|
+
*
|
|
15
|
+
* **This module stays stdlib-free — no `node:` imports, ever.** It ships to
|
|
16
|
+
* other apps as a versioned package alongside `./routes`, and the host's
|
|
17
|
+
* boundary check (`scripts/check-imports.ts`) enforces that nothing under it
|
|
18
|
+
* reaches for Node or for host `src/` modules.
|
|
19
|
+
*
|
|
20
|
+
* Request DTOs here are structural mirrors of the host's Zod input schemas.
|
|
21
|
+
* The schemas remain the single runtime validator; `tests/http/api-contracts`
|
|
22
|
+
* asserts the inferred schema types stay assignable to these interfaces so the
|
|
23
|
+
* two spellings cannot drift apart silently.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Every native provider a host can dispatch to. The order is the model catalog's wire order.
|
|
28
|
+
* A list for a narrower question, such as providers with importable history, keeps its own
|
|
29
|
+
* members typed against `NativeProvider`, so a new provider joins it only on purpose.
|
|
30
|
+
*/
|
|
31
|
+
declare const NATIVE_PROVIDERS: readonly ["codex", "claude", "opencode", "cursor", "antigravity"];
|
|
32
|
+
/** A native provider id. Never inferred from a model label. */
|
|
33
|
+
type NativeProvider = (typeof NATIVE_PROVIDERS)[number];
|
|
34
|
+
|
|
35
|
+
/** Small transcript receipt. The immutable specification lives beside the host's other chat outputs. */
|
|
36
|
+
interface GeneratedUiReceipt {
|
|
37
|
+
kind: 'farero-ui';
|
|
38
|
+
version: 1;
|
|
39
|
+
reference: string;
|
|
40
|
+
id: string;
|
|
41
|
+
title: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type McpAppVisibility = 'model' | 'app';
|
|
45
|
+
/** A tool call whose MCP server declared a view for it, as a transcript entry carries it. */
|
|
46
|
+
interface McpAppLink {
|
|
47
|
+
/** The server as the provider names it: Claude's configured name, Codex's server key. */
|
|
48
|
+
server: string;
|
|
49
|
+
/** The `ui://` resource the tool declared. */
|
|
50
|
+
resourceUri: string;
|
|
51
|
+
/** The stored call the view renders (`mcp_app_call_<sha256>`); absent until the call completes. */
|
|
52
|
+
call?: string;
|
|
53
|
+
}
|
|
54
|
+
/** What a view is sent about the call that opened it: its arguments and its result. */
|
|
55
|
+
interface McpAppToolCall {
|
|
56
|
+
arguments: Record<string, unknown>;
|
|
57
|
+
result: McpAppToolResult;
|
|
58
|
+
}
|
|
59
|
+
/** The `CallToolResult` members a view receives in `ui/notifications/tool-result`. */
|
|
60
|
+
interface McpAppToolResult {
|
|
61
|
+
content: unknown[];
|
|
62
|
+
structuredContent?: Record<string, unknown>;
|
|
63
|
+
_meta?: Record<string, unknown>;
|
|
64
|
+
isError?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/** A server tool's MCP Apps metadata, for the host's visibility check on a view's `tools/call`. */
|
|
67
|
+
interface McpAppTool {
|
|
68
|
+
name: string;
|
|
69
|
+
resourceUri: string | null;
|
|
70
|
+
visibility: McpAppVisibility[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Sign-in for the MCP servers a chat's provider connects: claude.ai connectors, ChatGPT apps and
|
|
75
|
+
* the person's own OAuth servers. The provider holds every credential, so Farero only starts the
|
|
76
|
+
* provider's own flow and opens the page it returns; the person approves it in their browser.
|
|
77
|
+
* A Farero-owned client would ask for a second sign-in to every server (see ARCHITECTURE.md).
|
|
78
|
+
*
|
|
79
|
+
* **This module stays stdlib-free — no `node:` imports.** The browser imports its values, and
|
|
80
|
+
* `scripts/check-imports.ts` enforces that.
|
|
81
|
+
*/
|
|
82
|
+
/** Where the credential lives, which decides where the page can open and who finishes the flow. */
|
|
83
|
+
type McpSignInKind =
|
|
84
|
+
/** A claude.ai connector. claude.ai keeps the token, so a browser signed in to claude.ai on any device can approve it. */
|
|
85
|
+
'connector'
|
|
86
|
+
/** A ChatGPT app. chatgpt.com keeps the token and connects the app on its own page. */
|
|
87
|
+
| 'app'
|
|
88
|
+
/** A configured MCP server. The provider owns its credentials and any OAuth redirect on the host. */
|
|
89
|
+
| 'server';
|
|
90
|
+
type McpSignInStatus = 'needs-sign-in' | 'connecting' | 'connected' | 'failed' | 'disabled' | 'unknown';
|
|
91
|
+
/** One server's sign-in as the chat's provider reports it. */
|
|
92
|
+
interface McpSignInState {
|
|
93
|
+
/** Canonical selector. Codex qualifies identities as `server:<name>` or `app:<id>`. */
|
|
94
|
+
server: string;
|
|
95
|
+
/** The name a person reads: a claude.ai connector without its `claude.ai ` prefix. */
|
|
96
|
+
label: string;
|
|
97
|
+
/** Absent while the status is `unknown`. */
|
|
98
|
+
kind?: McpSignInKind;
|
|
99
|
+
/** `unknown` when the chat has no provider connection to ask. */
|
|
100
|
+
status: McpSignInStatus;
|
|
101
|
+
/** Browser sign-in capability, independent of connection state. Absent on older runtimes. */
|
|
102
|
+
signIn?: {
|
|
103
|
+
available: true;
|
|
104
|
+
} | {
|
|
105
|
+
available: false;
|
|
106
|
+
reason: string;
|
|
107
|
+
};
|
|
108
|
+
/** The provider's own words for a failure. */
|
|
109
|
+
error?: string;
|
|
110
|
+
}
|
|
111
|
+
/** The page that the person opens to approve a sign-in the provider started. */
|
|
112
|
+
interface McpSignInStart {
|
|
113
|
+
/** Absent when the provider needed no page, for example after it renewed a stored token. */
|
|
114
|
+
url?: string;
|
|
115
|
+
state: McpSignInState;
|
|
116
|
+
}
|
|
117
|
+
/** Servers a tool call needs signed in, stamped from provider state or the host's own tool. */
|
|
118
|
+
interface McpSignInRequest {
|
|
119
|
+
servers: string[];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** A configured fallback; an omitted account inherits the legacy provider/account policy. */
|
|
123
|
+
interface FallbackChoice<E extends string = string> {
|
|
124
|
+
model: string;
|
|
125
|
+
effort?: E;
|
|
126
|
+
fast?: boolean;
|
|
127
|
+
/** 'default' or a managed account's pa_ id. */
|
|
128
|
+
accountId?: string;
|
|
129
|
+
/** Follow the global automatic account setting. Omitted means legacy Same account. */
|
|
130
|
+
accountPolicy?: 'global';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The handful of things the relay and the phone must compute *identically*, in the
|
|
135
|
+
* one place both can import.
|
|
136
|
+
*
|
|
137
|
+
* `src/` and `web/src/` are one TypeScript project (tsconfig.json includes both), so
|
|
138
|
+
* a plain relative import crosses between them fine. What does not cross is Node: the
|
|
139
|
+
* moment this file imports `node:anything` it stops being bundleable and every web
|
|
140
|
+
* import of it becomes a build failure. **So this module stays stdlib-free — no
|
|
141
|
+
* `node:` imports, ever.** It is the only file under `src/` the web app may import a
|
|
142
|
+
* *value* from; everything else it may only `import type` (see src/wire.ts), which
|
|
143
|
+
* `verbatimModuleSyntax` erases before the bundler ever sees it.
|
|
144
|
+
*
|
|
145
|
+
* Each of these was a second copy before, and each copy was a way for two screens to
|
|
146
|
+
* disagree about the same workspace.
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
declare const CLAUDE_PERMISSION_MODES: readonly ["bypassPermissions", "acceptEdits", "default", "dontAsk"];
|
|
150
|
+
declare const CLAUDE_SETTING_SOURCES: readonly ["user", "project", "local"];
|
|
151
|
+
declare const CODEX_SANDBOX_MODES: readonly ["danger-full-access", "workspace-write", "read-only"];
|
|
152
|
+
declare const CODEX_APPROVAL_POLICIES: readonly ["never", "on-request", "untrusted"];
|
|
153
|
+
declare const CODEX_WEB_SEARCH_MODES: readonly ["disabled", "cached", "indexed", "live"];
|
|
154
|
+
declare const CODEX_PERSONALITIES: readonly ["none", "friendly", "pragmatic"];
|
|
155
|
+
declare const OPENCODE_PERMISSION_ACTIONS: readonly ["allow", "ask", "deny"];
|
|
156
|
+
declare const OPENCODE_PERMISSION_TOOLS: readonly ["edit", "shell", "webfetch", "websearch", "external_directory"];
|
|
157
|
+
declare const OPENCODE_SHARE_MODES: readonly ["manual", "auto", "disabled"];
|
|
158
|
+
/**
|
|
159
|
+
* The Approvals choices for agy. The first three are agy's own session modes, by the ids `agy acp`
|
|
160
|
+
* lists; Plan stays a per-message choice. `skip-permissions` starts agy with
|
|
161
|
+
* `--dangerously-skip-permissions`, because even Auto asks before each MCP tool call that no agy
|
|
162
|
+
* allow rule covers.
|
|
163
|
+
*/
|
|
164
|
+
declare const ANTIGRAVITY_PERMISSION_MODES: readonly ["default", "accept-edits", "auto", "skip-permissions"];
|
|
165
|
+
/**
|
|
166
|
+
* Cursor settings layers a person may add. Project, team and enterprise settings always load:
|
|
167
|
+
* Farero's instructions are a project rule, and the other two belong to the person's organization.
|
|
168
|
+
*/
|
|
169
|
+
declare const CURSOR_SETTING_SOURCES: readonly ["user", "plugins"];
|
|
170
|
+
declare const PROVIDER_RUNTIME_SOURCES: readonly ["bundled", "path", "custom"];
|
|
171
|
+
interface ProviderRuntimeSettings {
|
|
172
|
+
source: (typeof PROVIDER_RUNTIME_SOURCES)[number];
|
|
173
|
+
customPath: string;
|
|
174
|
+
}
|
|
175
|
+
interface ClaudeHarnessSettings {
|
|
176
|
+
permissionMode: (typeof CLAUDE_PERMISSION_MODES)[number];
|
|
177
|
+
/** Read at each request rather than at connect, so a change reaches open chats. See claudeCanDeclineSafetyChecks. */
|
|
178
|
+
declineSafetyChecks: boolean;
|
|
179
|
+
settingSources: (typeof CLAUDE_SETTING_SOURCES)[number][];
|
|
180
|
+
allowedTools: string[];
|
|
181
|
+
disallowedTools: string[];
|
|
182
|
+
additionalDirectories: string[];
|
|
183
|
+
maxTurns: number | null;
|
|
184
|
+
skillListingBudgetFraction: number | null;
|
|
185
|
+
skillListingMaxDescChars: number | null;
|
|
186
|
+
artifacts: boolean;
|
|
187
|
+
agentTeams: boolean;
|
|
188
|
+
taskTools: boolean;
|
|
189
|
+
promptSuggestions: boolean;
|
|
190
|
+
thinkingSummaries: boolean | null;
|
|
191
|
+
instructions: string;
|
|
192
|
+
runtime: ProviderRuntimeSettings;
|
|
193
|
+
envKeys: string[];
|
|
194
|
+
}
|
|
195
|
+
interface CodexHarnessSettings {
|
|
196
|
+
sandbox: (typeof CODEX_SANDBOX_MODES)[number];
|
|
197
|
+
approvalPolicy: (typeof CODEX_APPROVAL_POLICIES)[number];
|
|
198
|
+
networkAccess: boolean;
|
|
199
|
+
webSearch: (typeof CODEX_WEB_SEARCH_MODES)[number] | null;
|
|
200
|
+
personality: (typeof CODEX_PERSONALITIES)[number] | null;
|
|
201
|
+
instructions: string;
|
|
202
|
+
runtime: ProviderRuntimeSettings;
|
|
203
|
+
envKeys: string[];
|
|
204
|
+
}
|
|
205
|
+
interface OpenCodeHarnessSettings {
|
|
206
|
+
permission: (typeof OPENCODE_PERMISSION_ACTIONS)[number];
|
|
207
|
+
permissions: Partial<Record<(typeof OPENCODE_PERMISSION_TOOLS)[number], (typeof OPENCODE_PERMISSION_ACTIONS)[number]>>;
|
|
208
|
+
share: (typeof OPENCODE_SHARE_MODES)[number] | null;
|
|
209
|
+
instructions: string;
|
|
210
|
+
runtime: ProviderRuntimeSettings;
|
|
211
|
+
envKeys: string[];
|
|
212
|
+
}
|
|
213
|
+
/** No `runtime`: Cursor's SDK ships inside Farero, so there is no binary to locate. */
|
|
214
|
+
interface CursorHarnessSettings {
|
|
215
|
+
/** Farero's switch. Cursor's own `~/.cursor/sandbox.json` can also turn the sandbox on; see cursorSandboxed. */
|
|
216
|
+
sandbox: boolean;
|
|
217
|
+
/** Added to project, team and enterprise settings. Cursor's user layer also imports Claude Code hooks and Claude and Codex skills. */
|
|
218
|
+
settingSources: (typeof CURSOR_SETTING_SOURCES)[number][];
|
|
219
|
+
instructions: string;
|
|
220
|
+
envKeys: string[];
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* The person installs agy and signs in to it themselves; Farero never bundles it and never reads its
|
|
224
|
+
* credentials. The agent, its tools, permission rules and instructions come from agy's own settings.
|
|
225
|
+
*/
|
|
226
|
+
interface AntigravityHarnessSettings {
|
|
227
|
+
/**
|
|
228
|
+
* The agy mode a chat runs in when it is not planning. agy decides each approval in that mode
|
|
229
|
+
* itself. Null keeps the mode that agy's own settings choose, and so does `skip-permissions`,
|
|
230
|
+
* which approves every tool at launch instead.
|
|
231
|
+
*/
|
|
232
|
+
permissionMode: (typeof ANTIGRAVITY_PERMISSION_MODES)[number] | null;
|
|
233
|
+
/** `bundled` never applies: there is no agy package for Farero to ship. */
|
|
234
|
+
runtime: ProviderRuntimeSettings;
|
|
235
|
+
envKeys: string[];
|
|
236
|
+
}
|
|
237
|
+
type SessionStatus = 'disconnected' | 'connecting' | 'idle' | 'working' | 'waiting' | 'error';
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Farero stores each turn's raw Claude Code SDK stream JSON in
|
|
241
|
+
* `session_messages.content`. User-typed prompts are stored as plain text.
|
|
242
|
+
* This turns a row into compact, phone-renderable entries.
|
|
243
|
+
*
|
|
244
|
+
* Classification rule (verified against the whole DB): a JSON frame with
|
|
245
|
+
* `type:"user"` is ALWAYS tool plumbing — every one of them carries
|
|
246
|
+
* tool_result blocks, never the user's own words. Real prompts are the
|
|
247
|
+
* plain-text rows. Never render an SDK user frame as a user bubble.
|
|
248
|
+
*/
|
|
249
|
+
|
|
250
|
+
/** Evidence of a successful provider answer submission, not confirmation of delivery. */
|
|
251
|
+
interface QuestionAnswer {
|
|
252
|
+
provider: NativeProvider;
|
|
253
|
+
method: string;
|
|
254
|
+
requestId: string;
|
|
255
|
+
evidence: 'submitted';
|
|
256
|
+
decision?: string;
|
|
257
|
+
questions: {
|
|
258
|
+
id: string;
|
|
259
|
+
question: string;
|
|
260
|
+
values: (string | number | boolean)[];
|
|
261
|
+
labels?: string[];
|
|
262
|
+
redacted?: boolean;
|
|
263
|
+
}[];
|
|
264
|
+
}
|
|
265
|
+
interface TranscriptEntry {
|
|
266
|
+
id: string;
|
|
267
|
+
rowid: number;
|
|
268
|
+
/** Native item revision; rowid remains a stable search/fork anchor. */
|
|
269
|
+
revision?: number;
|
|
270
|
+
/** Abandoned provider stream item replaced by this completed item; retained for audit/replay. */
|
|
271
|
+
supersededBy?: string;
|
|
272
|
+
/** Display role: user | assistant | tool | thinking | system */
|
|
273
|
+
role: 'user' | 'assistant' | 'tool' | 'thinking' | 'system';
|
|
274
|
+
/** Human-readable text. For tool rows: the call's description, else the tool name. */
|
|
275
|
+
text: string;
|
|
276
|
+
/** Provider answer submission evidence; absent from historical entries without this receipt. */
|
|
277
|
+
questionAnswer?: QuestionAnswer;
|
|
278
|
+
/** Questions authored alongside a provider message, before any answer was submitted. */
|
|
279
|
+
questionRequest?: {
|
|
280
|
+
questions: {
|
|
281
|
+
id: string;
|
|
282
|
+
question: string;
|
|
283
|
+
options?: string[];
|
|
284
|
+
}[];
|
|
285
|
+
};
|
|
286
|
+
/** Provider-owned background work result, kept in this chat rather than a delegated Farero chat. */
|
|
287
|
+
backgroundResult?: {
|
|
288
|
+
kind: 'subagent' | 'shell';
|
|
289
|
+
description: string;
|
|
290
|
+
state: 'succeeded' | 'failed' | 'interrupted' | 'unavailable';
|
|
291
|
+
nativeID: string;
|
|
292
|
+
};
|
|
293
|
+
/** Tool name when role === 'tool'. */
|
|
294
|
+
tool?: string;
|
|
295
|
+
/** Full mono secondary detail for tool rows (command, path, pattern, …). */
|
|
296
|
+
detail?: string;
|
|
297
|
+
/**
|
|
298
|
+
* The SDK's `tool_use` id. Carried by the call and by the result answering it — the
|
|
299
|
+
* only thing that pairs the two, which sit in different `session_messages` rows.
|
|
300
|
+
*/
|
|
301
|
+
toolUseId?: string;
|
|
302
|
+
/**
|
|
303
|
+
* The agent tool call whose transcript this frame belongs to.
|
|
304
|
+
*
|
|
305
|
+
* Farero writes delegated-agent frames into the parent chat and points every one
|
|
306
|
+
* back at the spawning `tool_use`. The phone uses this durable join to nest the work
|
|
307
|
+
* under that call even when the parent keeps speaking while the subagent runs.
|
|
308
|
+
*/
|
|
309
|
+
parentToolUseId?: string;
|
|
310
|
+
/** Host-kept /btw answer. It is local context, not a provider-authored parent turn. */
|
|
311
|
+
sideQuestion?: {
|
|
312
|
+
question: string;
|
|
313
|
+
sourceSessionId: string;
|
|
314
|
+
};
|
|
315
|
+
/** Human label for a tool call that spawned a subagent. Present only on that call. */
|
|
316
|
+
subagentLabel?: string;
|
|
317
|
+
/** A tool result's output, clipped. The phone folds it onto the call row. */
|
|
318
|
+
output?: string;
|
|
319
|
+
/** The tool's stored text/detail/output exceeded the shared persistence budget. */
|
|
320
|
+
outputTruncated?: boolean;
|
|
321
|
+
/** UTF-8 bytes observed when this row first crossed the persistence budget. */
|
|
322
|
+
outputOriginalBytes?: number;
|
|
323
|
+
/** True when `output` is a unified diff (an edit's result), so the phone colours it. */
|
|
324
|
+
diff?: boolean;
|
|
325
|
+
/**
|
|
326
|
+
* True when the diff's line numbers count within the edited text, not the file. A
|
|
327
|
+
* Claude Edit names the text it replaced but not its position, so they are hidden.
|
|
328
|
+
*/
|
|
329
|
+
diffExcerpt?: boolean;
|
|
330
|
+
/**
|
|
331
|
+
* True while this row shows an edit that the provider has not applied: the call's input
|
|
332
|
+
* is still arriving, or the call is complete and its result has not come back. `output`
|
|
333
|
+
* then holds what the call will write, never a result. With `diff` it is the complete
|
|
334
|
+
* patch of a finished call. Without `diff` it is the part written so far: lines that
|
|
335
|
+
* start with `-`, `+` or a space, between patch header lines when the tool takes a patch.
|
|
336
|
+
* The last line can be incomplete, and the text only grows. The row loses the flag when
|
|
337
|
+
* the provider reports the result. A draft that was cut off or refused keeps the flag and
|
|
338
|
+
* gains `aborted`: its `output` is what it would have written. A draft outside a running
|
|
339
|
+
* turn was never applied.
|
|
340
|
+
*/
|
|
341
|
+
draft?: boolean;
|
|
342
|
+
/**
|
|
343
|
+
* The provider's execution state for this call. A running call may already have output.
|
|
344
|
+
* False when the call has returned. Older rows may omit this observation.
|
|
345
|
+
*/
|
|
346
|
+
running?: boolean;
|
|
347
|
+
/** Images the result carried, as `GET /api/tool-images/:reference` references. */
|
|
348
|
+
images?: string[];
|
|
349
|
+
/** The MCP App view the call's server declared, and its stored result once the call completes. */
|
|
350
|
+
app?: McpAppLink;
|
|
351
|
+
/** Servers this call needs signed in; the transcript offers a Connect card for each. */
|
|
352
|
+
mcpSignIn?: McpSignInRequest;
|
|
353
|
+
/** A host-owned panel receipt, retained even when a provider replay omits its tool output. */
|
|
354
|
+
generatedUi?: GeneratedUiReceipt;
|
|
355
|
+
/** Completed assistant UI fences, indexed in their original message order. */
|
|
356
|
+
generatedUiStreams?: Record<string, GeneratedUiReceipt>;
|
|
357
|
+
/** True when this row is a failed tool result. */
|
|
358
|
+
error?: boolean;
|
|
359
|
+
/**
|
|
360
|
+
* True when the call was cut off before it ran or finished: the provider dropped the
|
|
361
|
+
* model's stream mid-call, or the user stopped the turn. Its arguments may never have
|
|
362
|
+
* arrived. Distinct from `error`, which is a tool that ran and failed — an aborted
|
|
363
|
+
* call is never counted as a failure.
|
|
364
|
+
*/
|
|
365
|
+
aborted?: boolean;
|
|
366
|
+
ts: string;
|
|
367
|
+
/** True while the message is queued, from the current outbox or the legacy in-row signal. */
|
|
368
|
+
queued: boolean;
|
|
369
|
+
/**
|
|
370
|
+
* Host-recorded author for a user prompt, independent of the provider transcript's
|
|
371
|
+
* user role. Absent on provider history and on rows that predate receipts; the
|
|
372
|
+
* phone treats a missing origin as the person's own words. Agent prompts arrive
|
|
373
|
+
* through MCP send_prompt and must never read as the person.
|
|
374
|
+
*/
|
|
375
|
+
origin?: 'human' | 'agent';
|
|
376
|
+
/** Who sent this prompt for an agent. The host records it at acceptance and names a chat at read time. */
|
|
377
|
+
sender?: PromptSender;
|
|
378
|
+
}
|
|
379
|
+
interface PromptSender {
|
|
380
|
+
/** The chat on this computer whose agent sent it. */
|
|
381
|
+
chat?: PromptSenderChat;
|
|
382
|
+
/** The name a local MCP client outside this computer's chats gave itself. */
|
|
383
|
+
client?: string;
|
|
384
|
+
/** The sender's own link back to the conversation it sent from. */
|
|
385
|
+
link?: string;
|
|
386
|
+
}
|
|
387
|
+
/** A chat that sent a prompt. A chat that no longer exists keeps only its id. */
|
|
388
|
+
interface PromptSenderChat {
|
|
389
|
+
sessionId: string;
|
|
390
|
+
workspaceId?: string;
|
|
391
|
+
title?: string;
|
|
392
|
+
provider?: string;
|
|
393
|
+
model?: string;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
interface BackgroundTask {
|
|
397
|
+
taskId: string;
|
|
398
|
+
/** The `tool_use` that started it — the Bash or Agent row the phone already shows. */
|
|
399
|
+
toolUseId: string | null;
|
|
400
|
+
/** The call's own description, which is what the desktop prints beside "Waiting for task". */
|
|
401
|
+
description: string;
|
|
402
|
+
/** Provider task kind, including OpenCode child sessions and shell jobs. */
|
|
403
|
+
taskType: string;
|
|
404
|
+
/** When the task started, ISO — the elapsed timer's origin. */
|
|
405
|
+
since: string;
|
|
406
|
+
/** Latest provider-observed step or bounded output progress. */
|
|
407
|
+
progress?: string;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** How a Codex account signs in to OpenAI, as Codex's `account/read` reports it. */
|
|
411
|
+
type CodexLogin = 'chatgpt' | 'apiKey';
|
|
412
|
+
|
|
413
|
+
interface NativeImage {
|
|
414
|
+
reference: string;
|
|
415
|
+
mediaType: string;
|
|
416
|
+
data: string;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
type NativeStatus = SessionStatus;
|
|
420
|
+
interface NativeAgentOptions {
|
|
421
|
+
/** How the current model was selected; absent primary selections follow the global setting. */
|
|
422
|
+
accountFallback?: 'global' | 'fixed';
|
|
423
|
+
/** Explicit chat or delegation account choice, binding across every fallback. */
|
|
424
|
+
accountConstraint?: string;
|
|
425
|
+
model?: string;
|
|
426
|
+
/** Frozen backup for an agent role; the host consumes it, never the provider. */
|
|
427
|
+
fallbackModel?: string;
|
|
428
|
+
fallbacks?: FallbackChoice[];
|
|
429
|
+
effort?: string;
|
|
430
|
+
fast?: boolean;
|
|
431
|
+
plan?: boolean;
|
|
432
|
+
/** Set from a read-only role when a helper is configured; see readOnlyPolicy in shared. */
|
|
433
|
+
readOnly?: boolean;
|
|
434
|
+
/** Auxiliary answer-only thread; providers that expose tool policy deny every tool. */
|
|
435
|
+
toolFree?: boolean;
|
|
436
|
+
/** Side chat may only present a native user-question form. */
|
|
437
|
+
questionOnly?: boolean;
|
|
438
|
+
}
|
|
439
|
+
interface NativeCapabilities {
|
|
440
|
+
steer: boolean;
|
|
441
|
+
fork: boolean;
|
|
442
|
+
approvals: boolean;
|
|
443
|
+
questions: boolean;
|
|
444
|
+
images: boolean;
|
|
445
|
+
plan: boolean;
|
|
446
|
+
fast: boolean;
|
|
447
|
+
efforts: string[];
|
|
448
|
+
/** Replayed history carries the host's own identity for every accepted prompt, so a prompt absent after a resume never reached the provider. */
|
|
449
|
+
replayIdentity?: boolean;
|
|
450
|
+
/** Missing on older/custom drivers means unsupported; never infer liveness. */
|
|
451
|
+
liveness?: boolean;
|
|
452
|
+
}
|
|
453
|
+
interface NativeModel {
|
|
454
|
+
id: string;
|
|
455
|
+
name: string;
|
|
456
|
+
provider: NativeProvider;
|
|
457
|
+
efforts?: string[];
|
|
458
|
+
fast?: boolean;
|
|
459
|
+
plan?: boolean;
|
|
460
|
+
default?: boolean;
|
|
461
|
+
/** The model an alias row runs, such as Claude's `opus` → `claude-opus-5-5`. */
|
|
462
|
+
resolvedModel?: string;
|
|
463
|
+
contextWindow?: number;
|
|
464
|
+
/** The family the provider names, such as OpenCode's `deepseek-flash`. Versions of one model share it. */
|
|
465
|
+
family?: string;
|
|
466
|
+
/** The provider's own summary of what the model is for. */
|
|
467
|
+
description?: string;
|
|
468
|
+
/** YYYY-MM-DD, when the provider reports a release date. */
|
|
469
|
+
released?: string;
|
|
470
|
+
/** USD per million tokens, when the provider reports a price. */
|
|
471
|
+
price?: {
|
|
472
|
+
input: number;
|
|
473
|
+
output?: number;
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
interface NativeInteraction {
|
|
477
|
+
id: string;
|
|
478
|
+
kind: 'approval' | 'question';
|
|
479
|
+
/** Whether this requires the provider to wait; unknown remains blocking for compatibility. */
|
|
480
|
+
blocking?: boolean;
|
|
481
|
+
method: string;
|
|
482
|
+
title: string;
|
|
483
|
+
body: string;
|
|
484
|
+
/** The provider subagent that asked; absent when the chat's own agent asks. */
|
|
485
|
+
agent?: {
|
|
486
|
+
id: string;
|
|
487
|
+
label: string;
|
|
488
|
+
};
|
|
489
|
+
decisions?: string[];
|
|
490
|
+
decisionLabels?: Record<string, string>;
|
|
491
|
+
questions?: {
|
|
492
|
+
id: string;
|
|
493
|
+
/** The agent's short topic label for the question, such as "Scope". */
|
|
494
|
+
header?: string;
|
|
495
|
+
question: string;
|
|
496
|
+
options?: string[];
|
|
497
|
+
/** What the agent wrote to explain an option, keyed by that option's label. */
|
|
498
|
+
optionDescriptions?: Record<string, string>;
|
|
499
|
+
/** An agent-authored recommendation, when the provider exposes one explicitly. */
|
|
500
|
+
recommendedOption?: string;
|
|
501
|
+
/** Whether this asks for a decision or for information; never infer from wording or choices. */
|
|
502
|
+
purpose?: 'decision' | 'information';
|
|
503
|
+
/** Preformatted text the agent attached to an option, such as a mockup or code, keyed by label. */
|
|
504
|
+
optionPreviews?: Record<string, string>;
|
|
505
|
+
required?: boolean;
|
|
506
|
+
inputType?: 'text' | 'password' | 'number';
|
|
507
|
+
multiple?: boolean;
|
|
508
|
+
allowCustom?: boolean;
|
|
509
|
+
}[];
|
|
510
|
+
url?: string;
|
|
511
|
+
/** Private provider payload retained so capabilities aren't flattened away. */
|
|
512
|
+
providerData?: unknown;
|
|
513
|
+
}
|
|
514
|
+
interface NativeAnswer {
|
|
515
|
+
decision?: string;
|
|
516
|
+
answers?: Record<string, string[]>;
|
|
517
|
+
/** Typed OpenCode form values. Other provider answers retain their existing shape. */
|
|
518
|
+
formAnswers?: Record<string, string | number | boolean | string[]>;
|
|
519
|
+
}
|
|
520
|
+
type NativeProviderEvent = {
|
|
521
|
+
type: 'thread';
|
|
522
|
+
threadId: string;
|
|
523
|
+
} | {
|
|
524
|
+
type: 'settings';
|
|
525
|
+
agent: NativeAgentOptions;
|
|
526
|
+
} | {
|
|
527
|
+
type: 'status';
|
|
528
|
+
status: NativeStatus;
|
|
529
|
+
turnId?: string | null;
|
|
530
|
+
error?: string | null;
|
|
531
|
+
/** A provider retry is live progress, not transcript history. */
|
|
532
|
+
retrying?: string | null;
|
|
533
|
+
/** The provider refused the turn because the account's sign-in has ended. */
|
|
534
|
+
signedOut?: boolean;
|
|
535
|
+
} | {
|
|
536
|
+
type: 'entry';
|
|
537
|
+
entry: Omit<TranscriptEntry, 'rowid' | 'queued'>;
|
|
538
|
+
imageData?: NativeImage[];
|
|
539
|
+
/** The call an MCP App view renders; the store keeps it apart and links it as `entry.app.call`. */
|
|
540
|
+
appCall?: McpAppToolCall;
|
|
541
|
+
/** Read back from the provider's saved session on connect. It can correct a stored row but is not new activity. */
|
|
542
|
+
history?: true;
|
|
543
|
+
} | {
|
|
544
|
+
type: 'interaction';
|
|
545
|
+
interaction: NativeInteraction;
|
|
546
|
+
} | {
|
|
547
|
+
type: 'interaction-resolved';
|
|
548
|
+
id: string;
|
|
549
|
+
} | {
|
|
550
|
+
type: 'usage';
|
|
551
|
+
inputTokens?: number;
|
|
552
|
+
outputTokens?: number;
|
|
553
|
+
contextPercent?: number;
|
|
554
|
+
}
|
|
555
|
+
/** Null when another model provider serves the connection, so no OpenAI sign-in applies. */
|
|
556
|
+
| {
|
|
557
|
+
type: 'codex-login';
|
|
558
|
+
login: CodexLogin | null;
|
|
559
|
+
}
|
|
560
|
+
/** Sent before a Cursor connection starts its process: whether that process runs in Cursor's sandbox. */
|
|
561
|
+
| {
|
|
562
|
+
type: 'cursor-sandbox';
|
|
563
|
+
sandboxed: boolean;
|
|
564
|
+
} | {
|
|
565
|
+
type: 'background-tasks';
|
|
566
|
+
tasks: BackgroundTask[];
|
|
567
|
+
awaitsReply?: boolean;
|
|
568
|
+
}
|
|
569
|
+
/** Claude's predicted next prompt. Null clears one the provider withdrew or replaced. */
|
|
570
|
+
| {
|
|
571
|
+
type: 'prompt-suggestion';
|
|
572
|
+
suggestion: string | null;
|
|
573
|
+
}
|
|
574
|
+
/** The commands of a provider that names them only inside a session, so it has no `commands()` read. */
|
|
575
|
+
| {
|
|
576
|
+
type: 'commands';
|
|
577
|
+
commands: NativeSlashCommand[];
|
|
578
|
+
} | {
|
|
579
|
+
type: 'raw';
|
|
580
|
+
method: string;
|
|
581
|
+
payload: unknown;
|
|
582
|
+
};
|
|
583
|
+
interface NativePrompt {
|
|
584
|
+
requestId: string;
|
|
585
|
+
text: string;
|
|
586
|
+
/** Host-recorded author, independent of the provider transcript's user role. */
|
|
587
|
+
origin?: 'human' | 'agent';
|
|
588
|
+
/**
|
|
589
|
+
* Legacy: earlier releases set it on every MCP send, including sends by the agents of the
|
|
590
|
+
* person's own chats, so it is no evidence of a bot (see `BotPrompts`). A repeated send keeps
|
|
591
|
+
* it so its receipt stays the same.
|
|
592
|
+
*/
|
|
593
|
+
bot?: boolean;
|
|
594
|
+
/**
|
|
595
|
+
* Durable ownership of a result prompt, including its ended retries. A user share is checked
|
|
596
|
+
* again at dispatch against its report's current destination and Workflow ownership.
|
|
597
|
+
*/
|
|
598
|
+
reportDelivery?: {
|
|
599
|
+
kind: 'workflow' | 'user_share';
|
|
600
|
+
reportId: string;
|
|
601
|
+
};
|
|
602
|
+
/** Immutable caller intent; interruption targets are captured at durable acceptance. */
|
|
603
|
+
deliveryMode?: 'queue' | 'redirect' | 'interrupt';
|
|
604
|
+
waitForSetup?: boolean;
|
|
605
|
+
attachments?: {
|
|
606
|
+
path: string;
|
|
607
|
+
mimeType?: string;
|
|
608
|
+
}[];
|
|
609
|
+
}
|
|
610
|
+
interface NativeSlashCommand {
|
|
611
|
+
name: string;
|
|
612
|
+
description?: string;
|
|
613
|
+
argumentHint?: string;
|
|
614
|
+
aliases?: string[];
|
|
615
|
+
/** The provider says the command is a skill. Absent when the provider gives no such fact. */
|
|
616
|
+
skill?: boolean;
|
|
617
|
+
/** The plugin that carries the command, or null when the provider says none does. Absent without that fact. */
|
|
618
|
+
plugin?: string | null;
|
|
619
|
+
}
|
|
620
|
+
interface NativeHarnessOptions {
|
|
621
|
+
claude?: ClaudeHarnessSettings;
|
|
622
|
+
codex?: CodexHarnessSettings;
|
|
623
|
+
opencode?: OpenCodeHarnessSettings;
|
|
624
|
+
cursor?: CursorHarnessSettings;
|
|
625
|
+
antigravity?: AntigravityHarnessSettings;
|
|
626
|
+
}
|
|
627
|
+
interface NativeConnectOptions {
|
|
628
|
+
/** Initialize a prompt-free, non-persistent catalog reader without starting/resuming a thread. */
|
|
629
|
+
catalogOnly?: boolean;
|
|
630
|
+
spawn?: (command: string, args: string[], cwd: string, env: NodeJS.ProcessEnv) => ChildProcessWithoutNullStreams;
|
|
631
|
+
cwd: string;
|
|
632
|
+
/** Workspace context (fareroWorkspaceEnv) merged into the provider environment, so agent tools see the same paths and branch as scripts. */
|
|
633
|
+
workspaceEnv?: NodeJS.ProcessEnv;
|
|
634
|
+
/** Only a thread persisted by NativeStore for this session may be resumed. */
|
|
635
|
+
threadId?: string;
|
|
636
|
+
/**
|
|
637
|
+
* A private directory for provider config that carries credentials, such as Claude's MCP
|
|
638
|
+
* servers. Providers read it from a file so no secret rides on a command line.
|
|
639
|
+
*/
|
|
640
|
+
mcpConfigDir?: string;
|
|
641
|
+
/**
|
|
642
|
+
* The transcript already stored for `threadId`: the newest time of a stored assistant, reasoning
|
|
643
|
+
* or tool entry, and whether any entry id starts with a prefix. A provider whose history replay
|
|
644
|
+
* cannot reproduce the ids of entries recorded before it uses both to skip what is stored already.
|
|
645
|
+
*/
|
|
646
|
+
stored?: {
|
|
647
|
+
after(): string | undefined;
|
|
648
|
+
has(prefix: string): boolean;
|
|
649
|
+
/** Durable async answer acceptance survives replay even before a provider echo exists. */
|
|
650
|
+
questionAnswered?(interactionId: string, questionId: string): boolean;
|
|
651
|
+
/** A local cancellation closes the form without answering the provider. */
|
|
652
|
+
questionDismissed?(interactionId: string): boolean;
|
|
653
|
+
};
|
|
654
|
+
agent: NativeAgentOptions;
|
|
655
|
+
/**
|
|
656
|
+
* Variables every tool command of the agent must see, such as a general chat's Git ceiling.
|
|
657
|
+
* A provider that filters its tool environment adds them there as well.
|
|
658
|
+
*/
|
|
659
|
+
toolEnvironment?: Record<string, string>;
|
|
660
|
+
/** Derived by the runtime from durable helper ownership on every connection, never from UI settings. */
|
|
661
|
+
delegated?: boolean;
|
|
662
|
+
instructions?: string;
|
|
663
|
+
harness?: NativeHarnessOptions;
|
|
664
|
+
/** Claude. The person's current Decline safety checks setting; `harness` holds only its value at connect. */
|
|
665
|
+
declineSafetyChecks?: () => boolean;
|
|
666
|
+
/**
|
|
667
|
+
* Cursor. The environment variables the person lets Farero pass now; `harness` holds only those at
|
|
668
|
+
* connect, and the process keeps the environment it started with. A sign-out that stops passing
|
|
669
|
+
* CURSOR_API_KEY reaches the next turn of an open process through this.
|
|
670
|
+
*/
|
|
671
|
+
currentEnvKeys?: () => readonly string[];
|
|
672
|
+
/**
|
|
673
|
+
* The person's Code Mode setting, set only for providers Farero can switch into Code Mode
|
|
674
|
+
* (CODE_MODE_PROVIDERS) and never for a sandboxed chat: Claude Code reads its launch flag
|
|
675
|
+
* from the environment, OpenCode from its MCP server config, Codex from its app-server
|
|
676
|
+
* config. Absent means ordinary tools.
|
|
677
|
+
*/
|
|
678
|
+
codeMode?: boolean;
|
|
679
|
+
mcpServers?: Record<string, {
|
|
680
|
+
url: string;
|
|
681
|
+
headers?: Record<string, string>;
|
|
682
|
+
approvedTools?: readonly string[];
|
|
683
|
+
/**
|
|
684
|
+
* Set only on a server whose credential and tools the host limits to one sandboxed chat.
|
|
685
|
+
* A sandbox adapter refuses every other server, since it would carry host capabilities in.
|
|
686
|
+
*/
|
|
687
|
+
sandboxScoped?: true;
|
|
688
|
+
}>;
|
|
689
|
+
/**
|
|
690
|
+
* Stdio servers that the person turned on, such as Browse. A chat needs none of them: it starts
|
|
691
|
+
* without a server that fails to connect. A sandboxed chat, a question-only chat and a helper
|
|
692
|
+
* that may not ask the person never get one.
|
|
693
|
+
*/
|
|
694
|
+
localMcpServers?: Record<string, NativeLocalMcpServer>;
|
|
695
|
+
/**
|
|
696
|
+
* Prototype, Claude and Codex. A shell call that waits for the person, such as a sign-in, runs in
|
|
697
|
+
* a Farero terminal they can type into. `prepare` gives the command the agent's shell runs
|
|
698
|
+
* instead; Codex's hook asks `hookServer`, which answers for this chat only.
|
|
699
|
+
*/
|
|
700
|
+
terminalHandoff?: {
|
|
701
|
+
prepare(command: string): Promise<string | undefined>;
|
|
702
|
+
hookServer: {
|
|
703
|
+
url: string;
|
|
704
|
+
headers: Record<string, string>;
|
|
705
|
+
};
|
|
706
|
+
instructions: string;
|
|
707
|
+
};
|
|
708
|
+
/** The provider home for a managed account or Farero's isolated default Codex account. */
|
|
709
|
+
account?: {
|
|
710
|
+
id: string;
|
|
711
|
+
home: string;
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
interface NativeLocalMcpServer {
|
|
715
|
+
command: string;
|
|
716
|
+
args: string[];
|
|
717
|
+
env?: Record<string, string>;
|
|
718
|
+
/** The longest a tool call may run, for example while a person finishes a step in their browser. */
|
|
719
|
+
toolTimeoutMs?: number;
|
|
720
|
+
/** Agent guidance that the host adds only for a chat that gets this server. */
|
|
721
|
+
instructions?: string;
|
|
722
|
+
}
|
|
723
|
+
/** Queueing, delivery identity, ownership and storage are host responsibilities. */
|
|
724
|
+
interface NativeDriver {
|
|
725
|
+
readonly provider: NativeProvider;
|
|
726
|
+
readonly capabilities: NativeCapabilities;
|
|
727
|
+
connect(options: NativeConnectOptions): Promise<void>;
|
|
728
|
+
/** Refresh tool discovery while a chat sits idle; a send never waits for it, and a new turn may cut it short. */
|
|
729
|
+
refreshTools?(): Promise<void>;
|
|
730
|
+
/** Current selection at dispatch, independent of the options used to connect. */
|
|
731
|
+
send(prompt: NativePrompt, agent?: NativeAgentOptions): Promise<void>;
|
|
732
|
+
/** Providers apply selection changes at their supported response boundary. */
|
|
733
|
+
steer(prompt: NativePrompt, agent?: NativeAgentOptions): Promise<void>;
|
|
734
|
+
/** In-place provider checkpoint; the caller owns a durable operation receipt. */
|
|
735
|
+
compact?(providerInputId: string): Promise<void>;
|
|
736
|
+
/** Read durable provider facts for a claimed compact operation. Never repost it. */
|
|
737
|
+
reconcileCompaction?(): Promise<void>;
|
|
738
|
+
stop(): Promise<void>;
|
|
739
|
+
answer(id: string, answer: NativeAnswer): Promise<void>;
|
|
740
|
+
models(): Promise<NativeModel[]>;
|
|
741
|
+
commands?(): Promise<NativeSlashCommand[]>;
|
|
742
|
+
activity?(): Promise<NativeActivity>;
|
|
743
|
+
fork?(): Promise<string>;
|
|
744
|
+
/** The provider's own MCP connections, when it can serve MCP App views through them. */
|
|
745
|
+
readonly mcpApps?: NativeMcpApps;
|
|
746
|
+
/** Sign-in for the provider's own MCP connections, when the provider can start one. */
|
|
747
|
+
readonly mcpSignIn?: NativeMcpSignIn;
|
|
748
|
+
close(): Promise<void>;
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* The provider starts and finishes every MCP sign-in, because it keeps the credential. Farero only
|
|
752
|
+
* hands its page to the person; nothing here runs a model turn.
|
|
753
|
+
*/
|
|
754
|
+
interface NativeMcpSignIn {
|
|
755
|
+
/**
|
|
756
|
+
* The server's sign-in as the provider reports it now. `reconnect` asks the provider to dial a
|
|
757
|
+
* server it still reports as signed out once more, since a sign-in approved elsewhere reaches
|
|
758
|
+
* an existing connection only through a new attempt.
|
|
759
|
+
*/
|
|
760
|
+
state(server: string, options?: {
|
|
761
|
+
reconnect?: boolean;
|
|
762
|
+
}): Promise<McpSignInState>;
|
|
763
|
+
/** Start the provider's own sign-in and return the page the person approves it on. */
|
|
764
|
+
start(server: string): Promise<McpSignInStart>;
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* An MCP App view reaches its server through the chat's provider, which holds the connection
|
|
768
|
+
* and its credentials. Nothing here runs a model turn.
|
|
769
|
+
*/
|
|
770
|
+
interface NativeMcpApps {
|
|
771
|
+
/** The server's `resources/read` result for `uri`. */
|
|
772
|
+
readResource(server: string, uri: string): Promise<unknown>;
|
|
773
|
+
/** The server's tools with their MCP Apps metadata. */
|
|
774
|
+
tools(server: string): Promise<McpAppTool[]>;
|
|
775
|
+
/** Call one of the server's tools for a view. The caller has already checked its visibility. */
|
|
776
|
+
callTool(server: string, tool: string, args: Record<string, unknown>): Promise<McpAppToolResult>;
|
|
777
|
+
}
|
|
778
|
+
interface NativeActivity {
|
|
779
|
+
running: boolean;
|
|
780
|
+
providerTurnId: string | null;
|
|
781
|
+
blockedOn: 'question' | 'approval' | null;
|
|
782
|
+
/** Exact still-live requests, so a lost projection can be restored without inventing a question. */
|
|
783
|
+
interactions?: NativeInteraction[];
|
|
784
|
+
}
|
|
785
|
+
/** Opens a driver for one chat. `chat` is absent for catalog and command reads, which never open a chat's thread. */
|
|
786
|
+
type NativeDriverFactory<Chat = never> = (emit: (event: NativeProviderEvent) => void, chat?: Chat) => NativeDriver;
|
|
787
|
+
/** The providers a driver host launches from an executable. */
|
|
788
|
+
type LaunchedProvider = 'claude' | 'codex';
|
|
789
|
+
/** The part of a provider's harness settings that chooses its executable and environment. */
|
|
790
|
+
interface DriverLaunchSettings {
|
|
791
|
+
runtime?: ProviderRuntimeSettings;
|
|
792
|
+
envKeys?: string[];
|
|
793
|
+
}
|
|
794
|
+
interface DriverLaunch {
|
|
795
|
+
command: string;
|
|
796
|
+
/** Prefix arguments; the driver adds its own subcommand after them. */
|
|
797
|
+
args: string[];
|
|
798
|
+
/** The executable in use, or null when the host found none. */
|
|
799
|
+
resolved: string | null;
|
|
800
|
+
/** Why a bundled build cannot run on this computer, when that is the reason none was found. */
|
|
801
|
+
unmet?: string;
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* What a driver needs from the app that runs it. Farero passes its own host; other apps use
|
|
805
|
+
* `localHost()`, which finds the provider on this computer and passes a minimal environment.
|
|
806
|
+
*/
|
|
807
|
+
interface DriverHost {
|
|
808
|
+
/** Finds the provider's executable for the given settings. */
|
|
809
|
+
launch(provider: LaunchedProvider, settings?: DriverLaunchSettings): DriverLaunch;
|
|
810
|
+
/** The error a driver throws when `launch` found no executable. */
|
|
811
|
+
notInstalled(provider: LaunchedProvider, source: string, unmet?: string): Error;
|
|
812
|
+
/**
|
|
813
|
+
* The whole environment of the provider process. `accountHome` is the provider's account folder,
|
|
814
|
+
* when the chat runs on another account; `envKeys` name variables the person lets through.
|
|
815
|
+
*/
|
|
816
|
+
environment(input: {
|
|
817
|
+
provider: LaunchedProvider;
|
|
818
|
+
workspaceEnv?: NodeJS.ProcessEnv;
|
|
819
|
+
accountHome?: string;
|
|
820
|
+
envKeys?: string[];
|
|
821
|
+
}): NodeJS.ProcessEnv;
|
|
822
|
+
/** How long a provider may take to connect an MCP server the host injects, in milliseconds. */
|
|
823
|
+
readonly mcpStartupMs: number;
|
|
824
|
+
/** How the app names itself to a provider that asks, such as Codex's app-server. */
|
|
825
|
+
readonly clientInfo: {
|
|
826
|
+
name: string;
|
|
827
|
+
title?: string;
|
|
828
|
+
version: string;
|
|
829
|
+
};
|
|
830
|
+
/** Codex only. Text that follows the chat's own instructions in every thread's developer instructions. */
|
|
831
|
+
readonly codexInstructions?: string;
|
|
832
|
+
/**
|
|
833
|
+
* Codex only. Headers Codex sends to an injected server whose tools the host approved in advance,
|
|
834
|
+
* so that the server can tell those calls apart. Absent when the host approves no tools.
|
|
835
|
+
*/
|
|
836
|
+
approvalHeaders?(approvedTools: readonly string[]): Record<string, string> | undefined;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
interface LocalHostOptions {
|
|
840
|
+
/** Folders searched before PATH and the usual install folders. */
|
|
841
|
+
searchPaths?: string[];
|
|
842
|
+
/** How long a provider may take to connect an MCP server the app gives it, in milliseconds. */
|
|
843
|
+
mcpStartupMs?: number;
|
|
844
|
+
/** How the app names itself to a provider that asks, such as Codex's app-server. */
|
|
845
|
+
clientInfo?: {
|
|
846
|
+
name: string;
|
|
847
|
+
title?: string;
|
|
848
|
+
version: string;
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* The default host for a desktop app: finds `claude` and `codex` on PATH and in the usual install
|
|
853
|
+
* folders, and starts them with a minimal environment. The app's own variables and credentials stay
|
|
854
|
+
* out unless a harness lists them in `envKeys`.
|
|
855
|
+
*/
|
|
856
|
+
declare function localHost(options?: LocalHostOptions): DriverHost;
|
|
857
|
+
|
|
858
|
+
type Entry = Omit<TranscriptEntry, 'rowid' | 'queued'>;
|
|
859
|
+
/**
|
|
860
|
+
* MCP Apps through Claude Code's own MCP client.
|
|
861
|
+
*
|
|
862
|
+
* `mcp_status` names each tool's view (the CLI forwards `_meta.ui` once it advertises
|
|
863
|
+
* `mcp_tool_ui_meta_v1`), `mcp_read_resource` reads a `ui://` resource and `mcp_call` runs a
|
|
864
|
+
* tool without a model turn. Servers connect after the session starts and a resumed chat
|
|
865
|
+
* replays its session file before any of them report, so a result whose tool is not listed
|
|
866
|
+
* yet waits here and is emitted again once the listing names its view.
|
|
867
|
+
*/
|
|
868
|
+
declare class ClaudeMcpApps implements NativeMcpApps {
|
|
869
|
+
private readonly client;
|
|
870
|
+
private readonly emit;
|
|
871
|
+
private views;
|
|
872
|
+
private listed;
|
|
873
|
+
private known;
|
|
874
|
+
private calls;
|
|
875
|
+
private waiting;
|
|
876
|
+
private refreshing;
|
|
877
|
+
private refreshedAt;
|
|
878
|
+
private started;
|
|
879
|
+
constructor(client: () => Query, emit: (event: NativeProviderEvent) => void);
|
|
880
|
+
start(): void;
|
|
881
|
+
stop(): void;
|
|
882
|
+
/** The view an MCP tool call will render, when its server has already listed it. */
|
|
883
|
+
call(toolUseId: string, tool: string, input: Record<string, unknown>): McpAppLink | undefined;
|
|
884
|
+
/** The view and payload a tool result carries, or nothing while its tool is unlisted. */
|
|
885
|
+
result(entry: Entry, frame: Record<string, unknown>, block: Record<string, unknown>, results: number): {
|
|
886
|
+
app: McpAppLink;
|
|
887
|
+
appCall: McpAppToolCall;
|
|
888
|
+
} | undefined;
|
|
889
|
+
private refresh;
|
|
890
|
+
readResource(server: string, uri: string): Promise<unknown>;
|
|
891
|
+
tools(server: string): Promise<McpAppTool[]>;
|
|
892
|
+
refreshMetadata(): Promise<void>;
|
|
893
|
+
callTool(server: string, tool: string, args: Record<string, unknown>): Promise<McpAppToolResult>;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* Claude Code in a sandbox instead of on this computer. Farero's DockerClaudeSandbox is one.
|
|
898
|
+
*/
|
|
899
|
+
interface ClaudeSandbox {
|
|
900
|
+
/** Reads the chat's saved session for replay. The CLI in the sandbox writes it. */
|
|
901
|
+
readonly sessionStore: SessionStore;
|
|
902
|
+
/** Where the guest finds its private MCP config file, once `prepare` wrote one. */
|
|
903
|
+
readonly mcpConfigPath: string | undefined;
|
|
904
|
+
prepare(options: NativeConnectOptions): Promise<void>;
|
|
905
|
+
spawn(options: NativeConnectOptions, args: string[]): ReturnType<NonNullable<NativeConnectOptions['spawn']>>;
|
|
906
|
+
/** Refuses before a prompt reaches Claude, so a send that it stops stays certain. */
|
|
907
|
+
beforeTurn(): Promise<void>;
|
|
908
|
+
/** Proves that each injected MCP server answers from inside the sandbox. */
|
|
909
|
+
verifyMcp(servers: NonNullable<NativeConnectOptions['mcpServers']>): Promise<void>;
|
|
910
|
+
}
|
|
911
|
+
interface ClaudeDriverOptions {
|
|
912
|
+
/** The app that runs the driver: it finds Claude Code and decides its environment. */
|
|
913
|
+
host: DriverHost;
|
|
914
|
+
sandbox?: ClaudeSandbox;
|
|
915
|
+
}
|
|
916
|
+
declare class NativeClaudeDriver implements NativeDriver {
|
|
917
|
+
private backgroundTasks;
|
|
918
|
+
readonly provider: "claude";
|
|
919
|
+
readonly capabilities: NativeCapabilities;
|
|
920
|
+
private emit;
|
|
921
|
+
private liveInteractions;
|
|
922
|
+
private options;
|
|
923
|
+
/** The private config file this connection's credentials were written to, when the host wrote one. */
|
|
924
|
+
private mcpConfigFile;
|
|
925
|
+
private stream;
|
|
926
|
+
private running;
|
|
927
|
+
private loop;
|
|
928
|
+
private threadId;
|
|
929
|
+
private closing;
|
|
930
|
+
private turnId;
|
|
931
|
+
/** Prompt messages pushed into the open turn that no result has reported as consumed. */
|
|
932
|
+
private unconsumed;
|
|
933
|
+
private stopping;
|
|
934
|
+
/** Claude answers input of its own, such as a background task's notice, with no turn of ours open. */
|
|
935
|
+
private ownReply;
|
|
936
|
+
/** Stop calls that wait for the result ending the turn they interrupted. */
|
|
937
|
+
private turnEnds;
|
|
938
|
+
/** The open turn hit Claude's `authentication_failed`, so its result reports a sign-in that ended. */
|
|
939
|
+
private signedOut;
|
|
940
|
+
/** The compaction point this connection last reported; undefined until the first read. */
|
|
941
|
+
private compactLimit;
|
|
942
|
+
private requests;
|
|
943
|
+
/** Subagent names by task id; the SDK's `agentID` on a permission ask is that task id. */
|
|
944
|
+
private agentLabels;
|
|
945
|
+
/** The harness posture a Plan chat returns to when the user accepts ExitPlanMode. */
|
|
946
|
+
private harnessMode;
|
|
947
|
+
/** The reply each thread streams, keyed by the subagent call it belongs to; the main thread is ''. */
|
|
948
|
+
private replies;
|
|
949
|
+
/** Calls that write files and whose input still arrives, with the subagent call each belongs to. */
|
|
950
|
+
private writing;
|
|
951
|
+
private drafts;
|
|
952
|
+
/** Tasks that started and have not ended, by task id. */
|
|
953
|
+
private tasks;
|
|
954
|
+
/** Skill calls whose injected SKILL.md has not arrived yet, oldest first. */
|
|
955
|
+
private skillCompanions;
|
|
956
|
+
/** Complete calls that write files and wait for their result, keyed by tool use id. */
|
|
957
|
+
private edits;
|
|
958
|
+
/** Calls whose result is in the saved history or has arrived since. Claude can send a call's frame again after its result. */
|
|
959
|
+
private answered;
|
|
960
|
+
/** True while connect reads the saved session back. Those frames are history, not new activity. */
|
|
961
|
+
private replaying;
|
|
962
|
+
private blockOffsets;
|
|
963
|
+
private receipts;
|
|
964
|
+
private receiptCheckTimer;
|
|
965
|
+
private receiptCheck;
|
|
966
|
+
private receiptCheckAttempts;
|
|
967
|
+
readonly mcpApps: ClaudeMcpApps;
|
|
968
|
+
/** A sandboxed CLI would wait for an OAuth redirect inside its container. */
|
|
969
|
+
readonly mcpSignIn?: NativeMcpSignIn;
|
|
970
|
+
private readonly host;
|
|
971
|
+
private readonly sandbox?;
|
|
972
|
+
constructor(emit: (event: NativeProviderEvent) => void, { host, sandbox }: ClaudeDriverOptions);
|
|
973
|
+
connect(options: NativeConnectOptions): Promise<void>;
|
|
974
|
+
private message;
|
|
975
|
+
/** A replayed call with no result in the history was cut off: the process that ran it has ended. */
|
|
976
|
+
private trackEdit;
|
|
977
|
+
/**
|
|
978
|
+
* Ends the drafts that `ends` picks by the subagent call each belongs to: calls whose input
|
|
979
|
+
* never completed, and complete calls without a result. A result that arrives later still
|
|
980
|
+
* replaces the row.
|
|
981
|
+
*/
|
|
982
|
+
private endDrafts;
|
|
983
|
+
/** The live task whose subagent makes the calls under `parentToolUseId`, then each task above it. */
|
|
984
|
+
private taskChain;
|
|
985
|
+
/** A background subagent keeps running after the turn's result, and so do the subagents it starts. */
|
|
986
|
+
private inBackground;
|
|
987
|
+
private trackTask;
|
|
988
|
+
/** The main thread and each subagent stream their replies separately, each numbering its own blocks. */
|
|
989
|
+
private streamEvent;
|
|
990
|
+
private acknowledge;
|
|
991
|
+
/** Read the owned transcript after a missed live echo. Absence never authorizes another send. */
|
|
992
|
+
private checkPendingReceipts;
|
|
993
|
+
private failReceipts;
|
|
994
|
+
/** Claude Code's own compaction point. The summary read makes no token-count calls. */
|
|
995
|
+
private readCompactLimit;
|
|
996
|
+
private consume;
|
|
997
|
+
private client;
|
|
998
|
+
/** Claude connects MCP servers in the background after init and lists each one as pending meanwhile. */
|
|
999
|
+
private injectedMcpState;
|
|
1000
|
+
refreshTools(): Promise<void>;
|
|
1001
|
+
send(prompt: NativePrompt, agent?: NativeAgentOptions): Promise<void>;
|
|
1002
|
+
private applyAgent;
|
|
1003
|
+
private submit;
|
|
1004
|
+
steer(prompt: NativePrompt, agent?: NativeAgentOptions): Promise<void>;
|
|
1005
|
+
stop(): Promise<void>;
|
|
1006
|
+
answer(id: string, answer: NativeAnswer): Promise<void>;
|
|
1007
|
+
/** A result is still to come: a turn of ours is open, or Claude answers input of its own. */
|
|
1008
|
+
private get resultDue();
|
|
1009
|
+
activity(): Promise<NativeActivity>;
|
|
1010
|
+
private publishActivity;
|
|
1011
|
+
models(): Promise<NativeModel[]>;
|
|
1012
|
+
commands(): Promise<NativeSlashCommand[]>;
|
|
1013
|
+
/**
|
|
1014
|
+
* The CLI's own skill list. Reloading reads the skill directories again, so only a throwaway
|
|
1015
|
+
* catalog connection asks. A runtime that cannot answer leaves the commands unmarked.
|
|
1016
|
+
*/
|
|
1017
|
+
private skillNames;
|
|
1018
|
+
fork(): Promise<string>;
|
|
1019
|
+
close(): Promise<void>;
|
|
1020
|
+
/**
|
|
1021
|
+
* Closing the process would strand its background shells: Claude Code starts each one in
|
|
1022
|
+
* its own process group and never kills them when it exits, so a command stuck for an
|
|
1023
|
+
* hour outlives every restart, update and tab close. Ask the CLI to stop what it still
|
|
1024
|
+
* lists first. The wait is bounded, so a wedged stop cannot hold up shutdown.
|
|
1025
|
+
*/
|
|
1026
|
+
private stopBackgroundTasks;
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
interface RpcMessage {
|
|
1030
|
+
id?: string | number;
|
|
1031
|
+
method?: string;
|
|
1032
|
+
params?: Record<string, unknown>;
|
|
1033
|
+
result?: unknown;
|
|
1034
|
+
error?: {
|
|
1035
|
+
code: number;
|
|
1036
|
+
message: string;
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
interface RpcClient {
|
|
1040
|
+
request<T>(method: string, params: unknown, timeoutMs?: number): Promise<T>;
|
|
1041
|
+
notifyInitialized(): void;
|
|
1042
|
+
respond(id: string | number, result: unknown): void;
|
|
1043
|
+
reject(id: string | number, message: string): void;
|
|
1044
|
+
close(): Promise<void>;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
/**
|
|
1048
|
+
* Codex runs an own server's OAuth flow, and the threads of the app-server that started it
|
|
1049
|
+
* restart the server when it completes. Another app-server on the same home sees the token only
|
|
1050
|
+
* after `config/mcpServer/reload`. A ChatGPT app connects on its chatgpt.com page, which gives
|
|
1051
|
+
* Codex no completion signal. Refreshes update tool availability; a successful app call
|
|
1052
|
+
* settles a recorded authentication failure.
|
|
1053
|
+
*/
|
|
1054
|
+
declare class CodexMcpSignIn implements NativeMcpSignIn {
|
|
1055
|
+
private readonly session;
|
|
1056
|
+
private readonly managed;
|
|
1057
|
+
private readonly logins;
|
|
1058
|
+
private readonly appAuthFailures;
|
|
1059
|
+
private apps;
|
|
1060
|
+
constructor(session: () => {
|
|
1061
|
+
rpc: RpcClient;
|
|
1062
|
+
threadId: string;
|
|
1063
|
+
}, managed: () => ReadonlySet<string>);
|
|
1064
|
+
/** Replayed thread items restore this evidence; app accessibility cannot clear an auth failure. */
|
|
1065
|
+
observe(item: Record<string, unknown>): McpSignInRequest | undefined;
|
|
1066
|
+
private withAppAuthFailure;
|
|
1067
|
+
/** `mcpServer/oauthLogin/completed` for a login this connection started. */
|
|
1068
|
+
completed(params: Record<string, unknown>): void;
|
|
1069
|
+
state(name: string, options?: {
|
|
1070
|
+
reconnect?: boolean;
|
|
1071
|
+
}): Promise<McpSignInState>;
|
|
1072
|
+
start(name: string): Promise<McpSignInStart>;
|
|
1073
|
+
private server;
|
|
1074
|
+
private find;
|
|
1075
|
+
private appList;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
declare function codexHelperQuestionPolicy(guestNode?: string): {
|
|
1079
|
+
command: string;
|
|
1080
|
+
hash: string;
|
|
1081
|
+
key: string;
|
|
1082
|
+
matcher: string;
|
|
1083
|
+
config: {
|
|
1084
|
+
'hooks.PreToolUse': {
|
|
1085
|
+
matcher: string;
|
|
1086
|
+
hooks: {
|
|
1087
|
+
type: "command";
|
|
1088
|
+
command: string;
|
|
1089
|
+
timeout: number;
|
|
1090
|
+
async: boolean;
|
|
1091
|
+
}[];
|
|
1092
|
+
}[];
|
|
1093
|
+
'hooks.state': {
|
|
1094
|
+
[x: string]: {
|
|
1095
|
+
enabled: boolean;
|
|
1096
|
+
trusted_hash: string;
|
|
1097
|
+
};
|
|
1098
|
+
};
|
|
1099
|
+
};
|
|
1100
|
+
};
|
|
1101
|
+
|
|
1102
|
+
type CodexRpcFactory = (cwd: string, message: (message: RpcMessage) => void, exit: (error: Error) => void) => RpcClient;
|
|
1103
|
+
/**
|
|
1104
|
+
* Codex in a sandbox instead of on this computer. The guest owns Codex, its home and its sessions.
|
|
1105
|
+
* Farero's DockerCodexSandbox is one.
|
|
1106
|
+
*/
|
|
1107
|
+
interface CodexSandbox {
|
|
1108
|
+
prepare(options: NativeConnectOptions): Promise<void>;
|
|
1109
|
+
spawn(options: NativeConnectOptions, args: string[]): ReturnType<NonNullable<NativeConnectOptions['spawn']>>;
|
|
1110
|
+
/** The hook policy the guest's Codex enforces for a helper, or for a question-only chat. */
|
|
1111
|
+
questionPolicy(questionOnly?: boolean): ReturnType<typeof codexHelperQuestionPolicy>;
|
|
1112
|
+
/** Proves that each injected MCP server answers from inside the sandbox. */
|
|
1113
|
+
verifyMcp(servers: NonNullable<NativeConnectOptions['mcpServers']>): Promise<void>;
|
|
1114
|
+
}
|
|
1115
|
+
interface CodexDriverOptions {
|
|
1116
|
+
/** The app that runs the driver: it finds Codex and decides the app-server's environment. */
|
|
1117
|
+
host: DriverHost;
|
|
1118
|
+
/** Replaces the app-server process. */
|
|
1119
|
+
rpc?: CodexRpcFactory;
|
|
1120
|
+
sandbox?: CodexSandbox;
|
|
1121
|
+
}
|
|
1122
|
+
declare class NativeCodexDriver implements NativeDriver {
|
|
1123
|
+
readonly provider: "codex";
|
|
1124
|
+
readonly capabilities: NativeCapabilities;
|
|
1125
|
+
private emit;
|
|
1126
|
+
private liveInteractions;
|
|
1127
|
+
private factory;
|
|
1128
|
+
private rpc;
|
|
1129
|
+
private options;
|
|
1130
|
+
private threadId;
|
|
1131
|
+
private turnId;
|
|
1132
|
+
private entries;
|
|
1133
|
+
private unfinishedMessages;
|
|
1134
|
+
private retryMessages;
|
|
1135
|
+
/** The reconnect notice the chat shows now; null once any other status has replaced it. */
|
|
1136
|
+
private reconnecting;
|
|
1137
|
+
private requests;
|
|
1138
|
+
private connectionId;
|
|
1139
|
+
private closing;
|
|
1140
|
+
private model;
|
|
1141
|
+
private subagents;
|
|
1142
|
+
private foreign;
|
|
1143
|
+
private pendingThreads;
|
|
1144
|
+
private ownership;
|
|
1145
|
+
private publishedSubagents;
|
|
1146
|
+
private appsRefreshUnsupported;
|
|
1147
|
+
/** File changes that started and wait to be applied, with the thread whose turn runs each. */
|
|
1148
|
+
private waitingEdits;
|
|
1149
|
+
private readonly host;
|
|
1150
|
+
private readonly sandbox?;
|
|
1151
|
+
constructor(emit: (event: NativeProviderEvent) => void, { host, rpc: factory, sandbox }: CodexDriverOptions);
|
|
1152
|
+
/** A sandboxed app-server would wait for an OAuth redirect inside its guest. */
|
|
1153
|
+
readonly mcpSignIn?: CodexMcpSignIn;
|
|
1154
|
+
/** Codex's app-server reads resources and calls tools on the chat thread's own MCP connections. */
|
|
1155
|
+
readonly mcpApps: NativeMcpApps;
|
|
1156
|
+
private mcpRpc;
|
|
1157
|
+
/** Codex holds this answer until its own startup of the server settles, within `startup_timeout_sec`. */
|
|
1158
|
+
private injectedMcpState;
|
|
1159
|
+
/** A change still in progress when its turn has ended was cut off, so Codex never applied it. */
|
|
1160
|
+
private editPhase;
|
|
1161
|
+
/** Ends the waiting changes of one thread, or of every thread, as changes Codex never applied. */
|
|
1162
|
+
private endDrafts;
|
|
1163
|
+
private entry;
|
|
1164
|
+
private completeMessage;
|
|
1165
|
+
private subagentOf;
|
|
1166
|
+
/** Stop the turn that raised a request: the chat's own, or only the asking subagent's. */
|
|
1167
|
+
private stopTurnOf;
|
|
1168
|
+
private subagentLabel;
|
|
1169
|
+
private put;
|
|
1170
|
+
/** Codex records each subagent's start, follow-ups and end as items of the thread that started it. */
|
|
1171
|
+
private agentActivity;
|
|
1172
|
+
private adopt;
|
|
1173
|
+
/** The row a subagent's transcript nests under, inside its parent subagent's transcript when it has one. */
|
|
1174
|
+
private putAnchor;
|
|
1175
|
+
/** A subagent whose start item never arrived still needs a row once its parent's turn ends. */
|
|
1176
|
+
private anchorOrphans;
|
|
1177
|
+
/** Codex sends every thread of this app-server to this connection, including threads Farero never started. */
|
|
1178
|
+
private receiveForeign;
|
|
1179
|
+
/** A thread belongs to this chat only when Codex records a parent chain that reaches the chat's thread. */
|
|
1180
|
+
private owns;
|
|
1181
|
+
private disown;
|
|
1182
|
+
/** Requests need only ownership; notifications wait for the row their entries nest under. */
|
|
1183
|
+
private flush;
|
|
1184
|
+
private receiveSubagent;
|
|
1185
|
+
private publishSubagents;
|
|
1186
|
+
/** Bill a subagent's requests at its own model; the context meter reads only the chat's thread. */
|
|
1187
|
+
private recordSubagentUsage;
|
|
1188
|
+
/** Earlier releases dropped subagent items, so read each subagent's saved turns once when none are stored. */
|
|
1189
|
+
private hydrateSubagents;
|
|
1190
|
+
private receive;
|
|
1191
|
+
/** Show a provider request in the chat; false when it was refused instead. */
|
|
1192
|
+
private request;
|
|
1193
|
+
connect(options: NativeConnectOptions): Promise<void>;
|
|
1194
|
+
private client;
|
|
1195
|
+
private skills;
|
|
1196
|
+
commands(): Promise<NativeSlashCommand[]>;
|
|
1197
|
+
private input;
|
|
1198
|
+
/** Refresh the callable connector schemas on this thread. */
|
|
1199
|
+
refreshTools(): Promise<void>;
|
|
1200
|
+
private appConnectionContext;
|
|
1201
|
+
send(prompt: NativePrompt, agent?: NativeAgentOptions): Promise<void>;
|
|
1202
|
+
steer(prompt: NativePrompt, _agent?: NativeAgentOptions): Promise<void>;
|
|
1203
|
+
stop(): Promise<void>;
|
|
1204
|
+
answer(id: string, answer: NativeAnswer): Promise<void>;
|
|
1205
|
+
activity(): Promise<NativeActivity>;
|
|
1206
|
+
models(): Promise<NativeModel[]>;
|
|
1207
|
+
fork(): Promise<string>;
|
|
1208
|
+
close(): Promise<void>;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
type ConnectionState = 'ready' | 'missing' | 'sign-in' | 'unavailable';
|
|
1212
|
+
interface ConnectionStatus {
|
|
1213
|
+
state: ConnectionState;
|
|
1214
|
+
/** One sentence the app can show the person as it is. */
|
|
1215
|
+
message: string;
|
|
1216
|
+
/** How the provider says the person signed in, such as Claude Code's `claude.ai` or Codex's `ChatGPT`. */
|
|
1217
|
+
method?: string;
|
|
1218
|
+
}
|
|
1219
|
+
/** Whether the provider is installed and signed in, from the provider's own status command. */
|
|
1220
|
+
declare function connectionStatus(host: DriverHost, provider: LaunchedProvider, settings?: DriverLaunchSettings): Promise<ConnectionStatus>;
|
|
1221
|
+
|
|
1222
|
+
type ChatStatus = 'idle' | 'running' | 'waiting' | 'error';
|
|
1223
|
+
/** A turn runs, or waits for the person to answer a request. */
|
|
1224
|
+
declare function chatBusy(status: ChatStatus): boolean;
|
|
1225
|
+
interface AgentChat {
|
|
1226
|
+
id: string;
|
|
1227
|
+
provider: NativeProvider;
|
|
1228
|
+
title: string;
|
|
1229
|
+
cwd: string;
|
|
1230
|
+
/** The provider's thread. A new driver resumes it. */
|
|
1231
|
+
threadId: string | null;
|
|
1232
|
+
status: ChatStatus;
|
|
1233
|
+
error: string | null;
|
|
1234
|
+
agent: NativeAgentOptions;
|
|
1235
|
+
/** Approvals and questions the provider waits on. */
|
|
1236
|
+
interactions: NativeInteraction[];
|
|
1237
|
+
createdAt: string;
|
|
1238
|
+
updatedAt: string;
|
|
1239
|
+
/** The newest stamp of the chat and its entries. */
|
|
1240
|
+
revision: number;
|
|
1241
|
+
}
|
|
1242
|
+
interface TranscriptRead {
|
|
1243
|
+
chat: AgentChat;
|
|
1244
|
+
/** The rows a transcript lists, oldest first. */
|
|
1245
|
+
entries: TranscriptEntry[];
|
|
1246
|
+
revision: number;
|
|
1247
|
+
}
|
|
1248
|
+
interface TranscriptChanges {
|
|
1249
|
+
/** The chat, when it changed after the revision you passed. */
|
|
1250
|
+
chat: AgentChat | null;
|
|
1251
|
+
/** Listed rows that changed after that revision, in the order they changed. */
|
|
1252
|
+
entries: TranscriptEntry[];
|
|
1253
|
+
/** Rows that changed after that revision and are no longer listed, such as a replaced stream item. */
|
|
1254
|
+
removed: string[];
|
|
1255
|
+
revision: number;
|
|
1256
|
+
}
|
|
1257
|
+
interface TranscriptChange {
|
|
1258
|
+
chatId: string;
|
|
1259
|
+
revision: number;
|
|
1260
|
+
}
|
|
1261
|
+
type NewEntry = Omit<TranscriptEntry, 'rowid' | 'queued' | 'revision'>;
|
|
1262
|
+
type ChatPatch = Partial<Pick<AgentChat, 'threadId' | 'status' | 'error' | 'agent' | 'interactions'>>;
|
|
1263
|
+
/**
|
|
1264
|
+
* Chats and their transcripts in one SQLite file on this computer. Every write transaction takes
|
|
1265
|
+
* the next value of one store-wide counter and stamps it on each chat and entry row it changes, so
|
|
1266
|
+
* a reader that remembers a revision catches up with one `changes` call.
|
|
1267
|
+
*/
|
|
1268
|
+
declare class TranscriptStore {
|
|
1269
|
+
private readonly database;
|
|
1270
|
+
private readonly listeners;
|
|
1271
|
+
constructor(file: string);
|
|
1272
|
+
/** Called after each committed write, in commit order. A listener that throws stops nothing else. */
|
|
1273
|
+
subscribe(listener: (change: TranscriptChange) => void): () => void;
|
|
1274
|
+
/** Chats, the one with the newest activity first. */
|
|
1275
|
+
list(): AgentChat[];
|
|
1276
|
+
chat(chatId: string): AgentChat | null;
|
|
1277
|
+
read(chatId: string): TranscriptRead | null;
|
|
1278
|
+
changes(chatId: string, after: number): TranscriptChanges | null;
|
|
1279
|
+
/** The transcript a resumed provider replays into, so a driver can skip what is stored already. */
|
|
1280
|
+
stored(chatId: string): {
|
|
1281
|
+
after(): string | undefined;
|
|
1282
|
+
has(prefix: string): boolean;
|
|
1283
|
+
};
|
|
1284
|
+
/** A new chat with the person's first prompt, as one write. */
|
|
1285
|
+
create(chat: Pick<AgentChat, 'id' | 'provider' | 'title' | 'cwd' | 'agent'>, prompt: NewEntry, at?: string): AgentChat;
|
|
1286
|
+
/** The person's next prompt. The chat runs from here. */
|
|
1287
|
+
prompt(chatId: string, prompt: NewEntry): void;
|
|
1288
|
+
update(chatId: string, patch: ChatPatch): void;
|
|
1289
|
+
/**
|
|
1290
|
+
* Applies Farero's entry rules: provider bookkeeping and blank thinking stay out, tool text keeps its
|
|
1291
|
+
* budget, a replaced stream item stays replaced, and a replay that changes nothing writes nothing.
|
|
1292
|
+
*/
|
|
1293
|
+
record(chatId: string, input: NewEntry): void;
|
|
1294
|
+
close(): void;
|
|
1295
|
+
/** A chat left running, by a crash or by closing, ends interrupted. Nothing is sent again. */
|
|
1296
|
+
interrupt(): void;
|
|
1297
|
+
/** Another store's file keeps its tables as they are: this store reads them before it writes anything. */
|
|
1298
|
+
private probe;
|
|
1299
|
+
private insertEntry;
|
|
1300
|
+
private touch;
|
|
1301
|
+
/** One write transaction with the next stamp. `apply` returns false when it changed nothing. */
|
|
1302
|
+
private write;
|
|
1303
|
+
private reading;
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
/** Partial harness settings. The runtime fills in the rest, asking the person before tools run. */
|
|
1307
|
+
interface AgentHarness {
|
|
1308
|
+
claude?: Partial<ClaudeHarnessSettings>;
|
|
1309
|
+
codex?: Partial<CodexHarnessSettings>;
|
|
1310
|
+
}
|
|
1311
|
+
/** What a chat's agent can reach besides its own tools. */
|
|
1312
|
+
interface AgentConnection {
|
|
1313
|
+
/** Remote MCP servers, such as the one `serveTools` starts. */
|
|
1314
|
+
mcpServers?: NativeConnectOptions['mcpServers'];
|
|
1315
|
+
/** MCP servers the provider starts as child processes. A server that fails to start is left out. */
|
|
1316
|
+
localMcpServers?: NativeConnectOptions['localMcpServers'];
|
|
1317
|
+
/** Text added to the agent's system instructions. */
|
|
1318
|
+
instructions?: string;
|
|
1319
|
+
/** Variables every tool command of the agent sees. */
|
|
1320
|
+
toolEnvironment?: Record<string, string>;
|
|
1321
|
+
}
|
|
1322
|
+
interface AgentRuntimeOptions {
|
|
1323
|
+
/** The folder for the transcript store, and the parent of the default working folder. */
|
|
1324
|
+
directory: string;
|
|
1325
|
+
/** Finds the providers and decides their environment. The default is `localHost()`. */
|
|
1326
|
+
host?: DriverHost;
|
|
1327
|
+
harness?: AgentHarness;
|
|
1328
|
+
/**
|
|
1329
|
+
* Answers an approval or question when the app can, for example from a saved rule. Return
|
|
1330
|
+
* undefined to leave it for the person, who answers through `answer`. The signal aborts when the
|
|
1331
|
+
* request closes another way.
|
|
1332
|
+
*/
|
|
1333
|
+
decide?: (chatId: string, interaction: NativeInteraction, signal: AbortSignal) => Promise<NativeAnswer | undefined>;
|
|
1334
|
+
/** Read each time a chat's provider starts. */
|
|
1335
|
+
connection?: (chatId: string) => AgentConnection | Promise<AgentConnection>;
|
|
1336
|
+
/** Drivers by provider. The defaults run Claude Code and Codex. */
|
|
1337
|
+
drivers?: Partial<Record<NativeProvider, NativeDriverFactory<AgentChat>>>;
|
|
1338
|
+
}
|
|
1339
|
+
interface StartChat {
|
|
1340
|
+
provider: NativeProvider;
|
|
1341
|
+
title: string;
|
|
1342
|
+
prompt: string;
|
|
1343
|
+
/** The folder the agent works in. The default is a folder inside `directory`. */
|
|
1344
|
+
cwd?: string;
|
|
1345
|
+
agent?: NativeAgentOptions;
|
|
1346
|
+
}
|
|
1347
|
+
interface ChatRead extends TranscriptRead {
|
|
1348
|
+
/** Approvals and questions the provider waits on. */
|
|
1349
|
+
interactions: NativeInteraction[];
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Runs local Claude Code and Codex chats for a desktop app. Transcripts stay in `directory` on this
|
|
1353
|
+
* computer; the runtime sends them nowhere else. A prompt that the provider may have taken in is
|
|
1354
|
+
* never sent again: a chat that a crash interrupted reopens in error, and the person decides.
|
|
1355
|
+
*/
|
|
1356
|
+
declare class AgentRuntime {
|
|
1357
|
+
private readonly options;
|
|
1358
|
+
private readonly store;
|
|
1359
|
+
private readonly host;
|
|
1360
|
+
private readonly harness;
|
|
1361
|
+
private readonly drivers;
|
|
1362
|
+
private readonly connections;
|
|
1363
|
+
/** Chats whose current turn the person stopped. */
|
|
1364
|
+
private readonly stops;
|
|
1365
|
+
private readonly workspace;
|
|
1366
|
+
private readonly mcpConfigDir;
|
|
1367
|
+
private closed;
|
|
1368
|
+
private constructor();
|
|
1369
|
+
static open(options: AgentRuntimeOptions): Promise<AgentRuntime>;
|
|
1370
|
+
/** Chats, the one with the newest activity first. */
|
|
1371
|
+
list(): AgentChat[];
|
|
1372
|
+
read(chatId: string): ChatRead | null;
|
|
1373
|
+
/** What changed in a chat after `after`, a revision from `read`, `changes` or `subscribe`. */
|
|
1374
|
+
changes(chatId: string, after: number): TranscriptChanges | null;
|
|
1375
|
+
/** Called after each committed change, in commit order. A listener that throws stops nothing else. */
|
|
1376
|
+
subscribe(listener: (change: TranscriptChange) => void): () => void;
|
|
1377
|
+
/** Stores the chat with its first prompt and starts the turn. The reply arrives as changes. */
|
|
1378
|
+
start({ provider, title, prompt, cwd, agent }: StartChat): Promise<AgentChat>;
|
|
1379
|
+
/** Sends the next prompt. Refuses while a turn runs. */
|
|
1380
|
+
send(chatId: string, prompt: string): Promise<void>;
|
|
1381
|
+
stop(chatId: string): Promise<void>;
|
|
1382
|
+
/** Answers an approval or question that the chat's provider waits on. */
|
|
1383
|
+
answer(chatId: string, interactionId: string, answer: NativeAnswer): Promise<void>;
|
|
1384
|
+
/** Whether the provider is installed on this computer and signed in. */
|
|
1385
|
+
connectionStatus(provider: LaunchedProvider): Promise<ConnectionStatus>;
|
|
1386
|
+
/** Stops every provider process. A chat that was running ends interrupted. */
|
|
1387
|
+
close(): Promise<void>;
|
|
1388
|
+
private assertOpen;
|
|
1389
|
+
private request;
|
|
1390
|
+
private turn;
|
|
1391
|
+
private fail;
|
|
1392
|
+
private connect;
|
|
1393
|
+
private driver;
|
|
1394
|
+
private open;
|
|
1395
|
+
private event;
|
|
1396
|
+
private status;
|
|
1397
|
+
/** The turn ended: open requests close, and the provider process stays for a while. */
|
|
1398
|
+
private settle;
|
|
1399
|
+
private interaction;
|
|
1400
|
+
private resolved;
|
|
1401
|
+
private forceStop;
|
|
1402
|
+
private drop;
|
|
1403
|
+
private release;
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
interface ToolCall {
|
|
1407
|
+
/** The chat whose agent called the tool. */
|
|
1408
|
+
chatId: string;
|
|
1409
|
+
name: string;
|
|
1410
|
+
args: Record<string, unknown>;
|
|
1411
|
+
/** Aborts when the agent cancels the call or its connection closes. */
|
|
1412
|
+
signal: AbortSignal;
|
|
1413
|
+
}
|
|
1414
|
+
interface ToolServerOptions {
|
|
1415
|
+
/** The tools every chat sees, as MCP tool definitions. */
|
|
1416
|
+
tools: readonly Tool[];
|
|
1417
|
+
call(call: ToolCall): Promise<CallToolResult>;
|
|
1418
|
+
/** The server name an agent sees. */
|
|
1419
|
+
name?: string;
|
|
1420
|
+
}
|
|
1421
|
+
interface ToolServer {
|
|
1422
|
+
/** The loopback URL a provider connects to. */
|
|
1423
|
+
url: string;
|
|
1424
|
+
/** The headers that name one chat to the server. Give them to that chat's connection only. */
|
|
1425
|
+
headers(chatId: string): Record<string, string>;
|
|
1426
|
+
close(): Promise<void>;
|
|
1427
|
+
}
|
|
1428
|
+
/**
|
|
1429
|
+
* Serves an app's tools to its agents as a streamable-HTTP MCP server on 127.0.0.1. Each chat gets
|
|
1430
|
+
* its own bearer token, so `call` learns which chat called and one chat cannot act as another.
|
|
1431
|
+
*/
|
|
1432
|
+
declare function serveTools({ tools, call, name }: ToolServerOptions): Promise<ToolServer>;
|
|
1433
|
+
|
|
1434
|
+
export { AgentRuntime, NativeClaudeDriver, NativeCodexDriver, TranscriptStore, chatBusy, connectionStatus, localHost, serveTools };
|
|
1435
|
+
export type { AgentChat, AgentConnection, AgentHarness, AgentRuntimeOptions, ChatRead, ChatStatus, ClaudeDriverOptions, ClaudeSandbox, CodexDriverOptions, CodexSandbox, ConnectionState, ConnectionStatus, DriverHost, DriverLaunch, DriverLaunchSettings, LaunchedProvider, LocalHostOptions, NativeAgentOptions, NativeAnswer, NativeConnectOptions, NativeDriver, NativeDriverFactory, NativeInteraction, NativePrompt, NativeProvider, NativeProviderEvent, StartChat, ToolCall, ToolServer, ToolServerOptions, TranscriptChange, TranscriptChanges, TranscriptEntry, TranscriptRead };
|