@tangle-network/sdk-provider-cli-base 0.13.17 → 0.13.18
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/dist/adapters/amp/index.d.mts +250 -0
- package/dist/adapters/amp/index.mjs +233 -0
- package/dist/adapters/factory-droids/index.d.mts +200 -0
- package/dist/adapters/factory-droids/index.mjs +356 -0
- package/dist/adapters/grok/index.d.mts +27 -0
- package/dist/adapters/grok/index.mjs +56 -0
- package/dist/adapters/hermes/index.d.mts +148 -0
- package/dist/adapters/hermes/index.mjs +244 -0
- package/dist/adapters/nanoclaw/index.d.mts +50 -0
- package/dist/adapters/nanoclaw/index.mjs +116 -0
- package/dist/adapters/openclaw/index.d.mts +68 -0
- package/dist/adapters/openclaw/index.mjs +240 -0
- package/dist/adapters/prime/index.d.mts +126 -0
- package/dist/adapters/prime/index.mjs +446 -0
- package/dist/conformance/index.d.mts +1 -1
- package/dist/index-BpO3fvbf.d.mts +1254 -0
- package/dist/index.d.mts +3 -1254
- package/dist/index.mjs +1 -4585
- package/dist/{prompt-input-BHn_1z69.d.mts → prompt-input-CD7okX8T.d.mts} +1 -1
- package/dist/src-Fn8Pu1xq.mjs +4586 -0
- package/package.json +35 -6
|
@@ -0,0 +1,1254 @@
|
|
|
1
|
+
import { i as PreparedAttachment, o as preparePromptInputParts } from "./prompt-input-CD7okX8T.mjs";
|
|
2
|
+
import { AskUserBridge, DEFAULT_INTERACTION_DECISION_TIMEOUT_MS as PERMISSION_DECISION_TIMEOUT_MS, InteractionBroker, InteractionBroker as InteractionBroker$1, InteractionHttpBridge, PermissionPromptBridge, RequestPermissionBridge, RequestPlanBridge, brokerInteractionTools as brokerInteractionTools$1 } from "@tangle-network/agent-core/interactions";
|
|
3
|
+
import * as _$_tangle_network_agent_profile_materialize0 from "@tangle-network/agent-profile-materialize";
|
|
4
|
+
import { BindableLaunchControl, CODEX_DISABLED_FEATURE_ARGS, HarnessId, HarnessId as HarnessId$1, WorkspacePlan, WorkspacePlanApplication, WorkspacePlanApplication as WorkspacePlanApplication$1, WorkspacePlanReceipt, codexDeveloperInstructionArgs } from "@tangle-network/agent-profile-materialize";
|
|
5
|
+
import { CliExecResult, CliExitResult, CliLauncher, CliProcess, CliSpawnConfig, InvalidAttachmentError, JsonRpcError, RpcBridge, StreamParserConfig } from "@tangle-network/sdk-cli-runner";
|
|
6
|
+
import { AgentExecutionInput, AgentExecutionOutcome, AgentExecutionResult, AgentProfile, AgentProfileSecretProvider, AgentRuntimeAttachments, BackendCapabilities, BackendMessage, CliAuthFile, DurablePlan, GetMessagesOptions, HarnessType, InputPart, InteractionExecutionBinding, InteractionResponse, LocalMcpConfig, McpConfig, McpStatusResponse, PlanProviderState, ProviderConfig, ReasoningEffort, RequestedInteractions, SdkHostServices, SdkPlanHost, SdkProviderAdapter, StreamEvent, TokenUsage, ToolPart } from "@tangle-network/agent-interface";
|
|
7
|
+
import { HarnessSessionContract } from "@tangle-network/cli-agent-registry/session-contract";
|
|
8
|
+
import * as _$_tangle_network_sdk_session_persistence0 from "@tangle-network/sdk-session-persistence";
|
|
9
|
+
import { MessagePart, MessageStore, PersistedMessage, PersistedSession, SessionStore, readProviderMessageIds } from "@tangle-network/sdk-session-persistence";
|
|
10
|
+
import { ProviderLogger } from "@tangle-network/cli-agent-registry";
|
|
11
|
+
import { NATIVE_SESSION_CONTRACTS as NATIVE_SESSION_CONTRACTS$1 } from "@tangle-network/cli-agent-registry/native-session-contracts";
|
|
12
|
+
import { DEFAULT_INTERACTION_MCP_SERVER_NAME, InteractionMcpServer, InteractionMcpServerConfig, interactionMcpToolName } from "@tangle-network/agent-core/interactions/mcp";
|
|
13
|
+
import { isRecord as isPlainRecord } from "@tangle-network/agent-core";
|
|
14
|
+
|
|
15
|
+
//#region src/acp-process-launch.d.ts
|
|
16
|
+
/** How to start the agent process for a session. */
|
|
17
|
+
interface AcpProcessSpec {
|
|
18
|
+
command: string;
|
|
19
|
+
args: string[];
|
|
20
|
+
env?: Record<string, string>;
|
|
21
|
+
/** Status detail shown while the process starts. */
|
|
22
|
+
statusDetail: string;
|
|
23
|
+
}
|
|
24
|
+
/** The spawn request a bridge factory receives. */
|
|
25
|
+
interface AcpBridgeSpawn {
|
|
26
|
+
command: string;
|
|
27
|
+
args: string[];
|
|
28
|
+
cwd: string;
|
|
29
|
+
env?: Record<string, string>;
|
|
30
|
+
rawCapturePath?: string;
|
|
31
|
+
uid?: number;
|
|
32
|
+
gid?: number;
|
|
33
|
+
}
|
|
34
|
+
/** Spawn an ACP agent over NDJSON stdio from `env` alone, never the sidecar's own environment. The adapter owns abort, so no signal. */
|
|
35
|
+
declare function spawnAcpBridge(request: AcpBridgeSpawn): RpcBridge;
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/secret-profile-mcp.d.ts
|
|
38
|
+
/** Executor-held MCP credentials shared by native private-profile adapters. */
|
|
39
|
+
declare const SECRET_REFERENCE_PREFIX = "TANGLE_PROFILE_SECRET_";
|
|
40
|
+
declare const SECRET_REFERENCE: RegExp;
|
|
41
|
+
declare function requireRecord(raw: unknown, message: string): Record<string, unknown>;
|
|
42
|
+
/** One MCP server the executor serves for a secret launch. */
|
|
43
|
+
type SecretProfileMcpServer = {
|
|
44
|
+
name: string; /** The server's own upstream URL. */
|
|
45
|
+
url: string; /** Every header the upstream needs, credentials included. */
|
|
46
|
+
headers: Readonly<Record<string, string>>;
|
|
47
|
+
} | {
|
|
48
|
+
name: string; /** A stdio server whose environment names a secret: the executor runs this command outside the session's UID and serves it over loopback. */
|
|
49
|
+
command: readonly string[]; /** Its environment with every secret reference resolved. */
|
|
50
|
+
environment: Readonly<Record<string, string>>; /** Every secret value its environment references, whatever its length. */
|
|
51
|
+
secrets: readonly string[];
|
|
52
|
+
};
|
|
53
|
+
/** The executor's loopback proxy for a secret launch's MCP servers. */
|
|
54
|
+
type SecretProfileMcpCredentialProxy = {
|
|
55
|
+
/** The scope's placeholder and one loopback URL per server name. */endpoint(scope: string, names: readonly string[]): Promise<{
|
|
56
|
+
placeholder: string;
|
|
57
|
+
urls: Readonly<Record<string, string>>;
|
|
58
|
+
}>; /** Serve `servers` before resolving; release acknowledges lease termination before the turn settles or its scope is reused. */
|
|
59
|
+
lease(scope: string, servers: ReadonlyArray<SecretProfileMcpServer>): Promise<() => void | Promise<void>>; /** The scope's session ended: its placeholder is refused from now on and its stdio servers are stopped. */
|
|
60
|
+
forget(scope: string): Promise<void>;
|
|
61
|
+
};
|
|
62
|
+
/** A config value with its secret references resolved, or undefined. */
|
|
63
|
+
declare function resolveReferences(value: string, references: Readonly<Record<string, string>>): string | undefined;
|
|
64
|
+
/** A stdio server the executor can run: its command and its environment with every secret reference resolved. */
|
|
65
|
+
declare function servableStdioServer(name: string, entry: Record<string, unknown>, references: Readonly<Record<string, string>>): SecretProfileMcpServer | string;
|
|
66
|
+
/** A remote server the executor can serve: its fixed upstream URL and every header with its secret references resolved. */
|
|
67
|
+
declare function servableMcpServer(name: string, entry: Record<string, unknown>, references: Readonly<Record<string, string>>): SecretProfileMcpServer | string;
|
|
68
|
+
/** Join the queue at `key`; `previous` settles when earlier holders release. */
|
|
69
|
+
declare function joinQueue(queues: Map<string, Promise<void>>, key: string): {
|
|
70
|
+
previous: Promise<void>;
|
|
71
|
+
release: () => void;
|
|
72
|
+
};
|
|
73
|
+
declare function untilSettledOrAborted(previous: Promise<void>, signal: AbortSignal): Promise<void>;
|
|
74
|
+
/** Every native discovery ancestor is sealed and free of ambient configuration. */
|
|
75
|
+
declare function assertSealedNativeSearchPath(cwd: string, configNames: readonly string[]): void;
|
|
76
|
+
declare function secretSessionTurnQueue(view: string): {
|
|
77
|
+
previous: Promise<void>;
|
|
78
|
+
release: () => void;
|
|
79
|
+
};
|
|
80
|
+
/** An HTTP URL on loopback with an explicit port and no URL credentials. */
|
|
81
|
+
declare function isLoopbackEndpoint(value: unknown): boolean;
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/types.d.ts
|
|
84
|
+
type InteractionToggleKind = keyof RequestedInteractions;
|
|
85
|
+
type InteractionToggleConfig = boolean | RequestedInteractions;
|
|
86
|
+
declare function interactionToggleEnabled(config: InteractionToggleConfig | undefined, kind: InteractionToggleKind): boolean;
|
|
87
|
+
declare function enabledInteractionKinds<TKind extends InteractionToggleKind>(config: InteractionToggleConfig | undefined, supported: readonly TKind[]): TKind[];
|
|
88
|
+
/** Per-turn interaction toggle carried on the execution input. */
|
|
89
|
+
type PerTurnInteractionInput = Pick<AgentExecutionInput, "interactions">;
|
|
90
|
+
/** Host-composed context for THIS turn only (e.g. */
|
|
91
|
+
type EphemeralContextInput = {
|
|
92
|
+
ephemeralContext?: string;
|
|
93
|
+
systemPrompt?: unknown;
|
|
94
|
+
};
|
|
95
|
+
declare function readEphemeralContext(input: EphemeralContextInput): string | undefined;
|
|
96
|
+
/** Compose the model-facing prompt for a turn: the caller's own text, then this turn's ephemeral context. */
|
|
97
|
+
declare function withEphemeralContext(promptText: string, input: EphemeralContextInput): string;
|
|
98
|
+
declare function turnInteractionEnabled(input: PerTurnInteractionInput, latched: InteractionToggleConfig | undefined, kind: InteractionToggleKind): boolean;
|
|
99
|
+
/** Overlay this turn's interactions onto a latched config, returning a NEW object (no shared mutation — safe when. */
|
|
100
|
+
declare function withTurnInteractions<TConfig extends {
|
|
101
|
+
interactions?: InteractionToggleConfig;
|
|
102
|
+
}>(config: TConfig, input: PerTurnInteractionInput): TConfig;
|
|
103
|
+
interface CliProviderLogger {
|
|
104
|
+
observePhase?: ProviderLogger["observePhase"];
|
|
105
|
+
debug(message: string, meta?: Record<string, unknown>): void;
|
|
106
|
+
info(message: string, meta?: Record<string, unknown>): void;
|
|
107
|
+
warn(message: string, meta?: Record<string, unknown>): void;
|
|
108
|
+
error(message: string, meta?: Record<string, unknown>): void;
|
|
109
|
+
}
|
|
110
|
+
interface CliProviderConfig {
|
|
111
|
+
/** Trusted native auth projection resolved by the owning execution host. */
|
|
112
|
+
nativeAuthEnv?: Record<string, string>;
|
|
113
|
+
nativeAuthSecretEnv?: string;
|
|
114
|
+
runtimeHome?: string;
|
|
115
|
+
/** Shared, persistent agent HOME. */
|
|
116
|
+
agentHome?: string;
|
|
117
|
+
/** Trusted, adapter-wide native process identity supplied by the executor. */
|
|
118
|
+
subprocessUser?: {
|
|
119
|
+
uid: number;
|
|
120
|
+
gid: number;
|
|
121
|
+
};
|
|
122
|
+
/** The executor keeps this subprocess identity for later backends of the same session, principal and profile authority: the. */
|
|
123
|
+
stableIsolatedIdentity?: boolean;
|
|
124
|
+
publicProfileRevisionRoot?: string;
|
|
125
|
+
/** Executor-owned base for UID-restricted secret profile revisions. */
|
|
126
|
+
secretProfileRevisionRoot?: string;
|
|
127
|
+
/** Root-only 32-byte HMAC key; never copied into a turn result. */
|
|
128
|
+
secretProfileNamingKeyPath?: string;
|
|
129
|
+
sandboxedRuntime?: boolean;
|
|
130
|
+
profile?: AgentProfile;
|
|
131
|
+
runtimeAttachments?: AgentRuntimeAttachments;
|
|
132
|
+
/** Per-turn credential values resolved by secret references in this execution's runtime MCP attachments. */
|
|
133
|
+
runtimeSecrets?: Record<string, string>;
|
|
134
|
+
cliPath?: string;
|
|
135
|
+
model?: string;
|
|
136
|
+
provider?: string;
|
|
137
|
+
apiKey?: string;
|
|
138
|
+
baseUrl?: string;
|
|
139
|
+
authFiles?: Array<{
|
|
140
|
+
path: string;
|
|
141
|
+
content: string;
|
|
142
|
+
mode?: number;
|
|
143
|
+
}>;
|
|
144
|
+
extraFlags?: string[];
|
|
145
|
+
bypassPermissions?: boolean;
|
|
146
|
+
interactions?: InteractionToggleConfig;
|
|
147
|
+
}
|
|
148
|
+
interface CliProviderOptions<TConfig extends CliProviderConfig = CliProviderConfig> {
|
|
149
|
+
config?: TConfig;
|
|
150
|
+
logger?: CliProviderLogger;
|
|
151
|
+
storagePath?: string;
|
|
152
|
+
storageDir?: string;
|
|
153
|
+
/** Resolve opaque AgentProfile secret references at the private spawn boundary. */
|
|
154
|
+
profileSecretProvider?: AgentProfileSecretProvider;
|
|
155
|
+
/** For a secret profile revision: the keys the runtime itself manages (the box's TANGLE_API_KEY), which a turn may not deliver as runtimeSecrets. */
|
|
156
|
+
secretProfileRuntimeKeyProvider?: AgentProfileSecretProvider;
|
|
157
|
+
/** Serves native private-profile MCP servers without giving their keys to the CLI. */
|
|
158
|
+
mcpCredentialProxy?: SecretProfileMcpCredentialProxy;
|
|
159
|
+
/** Environment every CLI child gets in place of the inherited one for these keys: in a sandbox, the. */
|
|
160
|
+
agentEnvironment?: (launch: {
|
|
161
|
+
secretProfile: boolean;
|
|
162
|
+
}) => Record<string, string | undefined>;
|
|
163
|
+
launcher?: CliLauncher;
|
|
164
|
+
ownProcessGroup?: boolean;
|
|
165
|
+
}
|
|
166
|
+
/** Per-turn input a CLI adapter reads beyond AgentExecutionInput: text added after the harness's own system prompt (a chat. */
|
|
167
|
+
type CliExecutionInput = AgentExecutionInput & {
|
|
168
|
+
appendSystemPrompt?: string;
|
|
169
|
+
};
|
|
170
|
+
interface CliExecArgs {
|
|
171
|
+
command: string;
|
|
172
|
+
args: string[];
|
|
173
|
+
useStdin: boolean;
|
|
174
|
+
stdin?: string;
|
|
175
|
+
/** Working directory for the spawned process. */
|
|
176
|
+
cwd?: string;
|
|
177
|
+
}
|
|
178
|
+
interface ToolCallState {
|
|
179
|
+
id: string;
|
|
180
|
+
name: string;
|
|
181
|
+
input: unknown;
|
|
182
|
+
startTime: number;
|
|
183
|
+
status: "pending" | "running" | "completed" | "failed";
|
|
184
|
+
output?: unknown;
|
|
185
|
+
}
|
|
186
|
+
/** How a turn ended: the closed set every harness names its end in (#16404). */
|
|
187
|
+
type TurnEndReason = "success" | "abort" | "timeout" | "gateway_disconnect" | "harness_exit" | "memory_limit" | "repeated_tool_failure" | "failed";
|
|
188
|
+
/**
|
|
189
|
+
* The one precedence every engine names a failed turn's end with (#16404): an
|
|
190
|
+
* end the abort, the timeout or the harness named is theirs; only an
|
|
191
|
+
* unexplained death is the link's, the memory limit's or the harness's.
|
|
192
|
+
*/
|
|
193
|
+
declare function turnEndReason(end: {
|
|
194
|
+
aborted?: boolean;
|
|
195
|
+
timedOut?: boolean;
|
|
196
|
+
harnessFailed?: boolean;
|
|
197
|
+
linkLost?: boolean;
|
|
198
|
+
memoryKilled?: boolean;
|
|
199
|
+
signal?: string | null;
|
|
200
|
+
}): TurnEndReason;
|
|
201
|
+
interface ExecutionState {
|
|
202
|
+
sessionId?: string;
|
|
203
|
+
messageId?: string;
|
|
204
|
+
workspaceRoot?: string;
|
|
205
|
+
textPartId?: string;
|
|
206
|
+
toolCalls: Map<string, ToolCallState>;
|
|
207
|
+
textBuffer: string;
|
|
208
|
+
reasoningBuffer: string[];
|
|
209
|
+
reasoningParts?: Array<{
|
|
210
|
+
id: string;
|
|
211
|
+
text: string;
|
|
212
|
+
}>;
|
|
213
|
+
fileParts?: Array<{
|
|
214
|
+
id: string;
|
|
215
|
+
key: string;
|
|
216
|
+
filename?: string;
|
|
217
|
+
mediaType?: string;
|
|
218
|
+
url: string;
|
|
219
|
+
}>;
|
|
220
|
+
failure?: {
|
|
221
|
+
message: string;
|
|
222
|
+
code?: string;
|
|
223
|
+
statusCode?: number;
|
|
224
|
+
resetAt?: string;
|
|
225
|
+
};
|
|
226
|
+
lastDiagnostic?: string;
|
|
227
|
+
terminalStatus?: "completed" | "failed";
|
|
228
|
+
endReason?: TurnEndReason;
|
|
229
|
+
/** The sandbox's OOM-kill count when the turn started; a later count is this turn's kill. */
|
|
230
|
+
oomKillsAtStart?: number;
|
|
231
|
+
tokenUsage?: Partial<TokenUsage>;
|
|
232
|
+
}
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region src/acp-protocol.d.ts
|
|
235
|
+
/** The ACP protocol version this client speaks, and the oldest it accepts. */
|
|
236
|
+
declare const ACP_PROTOCOL_VERSION = 1;
|
|
237
|
+
declare const ACP_MIN_PROTOCOL_VERSION = 1;
|
|
238
|
+
/** Settings every ACP agent process takes. */
|
|
239
|
+
interface AcpBridgeConfig extends CliProviderConfig {
|
|
240
|
+
/** Protocol version requested in `initialize` (default 1). */
|
|
241
|
+
protocolVersion?: number;
|
|
242
|
+
/** Timeout for one `session/prompt` turn (default 10 min). */
|
|
243
|
+
promptTimeoutMs?: number;
|
|
244
|
+
/** Timeout for `initialize` and `session/new|load` (default 2 min). */
|
|
245
|
+
bootstrapTimeoutMs?: number;
|
|
246
|
+
/**
|
|
247
|
+
* How long an idle session keeps its agent process (default 5 min).
|
|
248
|
+
* 0 closes the process after every turn.
|
|
249
|
+
*/
|
|
250
|
+
bridgeIdleMs?: number;
|
|
251
|
+
}
|
|
252
|
+
/** ACP content blocks this client reads or sends. */
|
|
253
|
+
type AcpContentBlock = {
|
|
254
|
+
type: "text";
|
|
255
|
+
text: string;
|
|
256
|
+
} | {
|
|
257
|
+
type: "image";
|
|
258
|
+
data?: string;
|
|
259
|
+
mimeType?: string;
|
|
260
|
+
uri?: string;
|
|
261
|
+
} | {
|
|
262
|
+
type: "resource";
|
|
263
|
+
uri: string;
|
|
264
|
+
mimeType?: string;
|
|
265
|
+
} /** Tool-call content: one content block wrapped one level deeper. */ | {
|
|
266
|
+
type: "content";
|
|
267
|
+
content: {
|
|
268
|
+
type: "text";
|
|
269
|
+
text: string;
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
interface AcpInitializeParams {
|
|
273
|
+
protocolVersion: number;
|
|
274
|
+
clientCapabilities: {
|
|
275
|
+
fs?: {
|
|
276
|
+
readTextFile?: boolean;
|
|
277
|
+
writeTextFile?: boolean;
|
|
278
|
+
};
|
|
279
|
+
terminal?: boolean;
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
interface AcpInitializeResult {
|
|
283
|
+
protocolVersion: number;
|
|
284
|
+
agentCapabilities?: Record<string, unknown>;
|
|
285
|
+
agentInfo?: {
|
|
286
|
+
name?: string;
|
|
287
|
+
title?: string;
|
|
288
|
+
version?: string;
|
|
289
|
+
};
|
|
290
|
+
authMethods?: Array<{
|
|
291
|
+
id: string;
|
|
292
|
+
name?: string;
|
|
293
|
+
description?: string;
|
|
294
|
+
}>;
|
|
295
|
+
}
|
|
296
|
+
interface AcpNewSessionResult {
|
|
297
|
+
sessionId: string;
|
|
298
|
+
}
|
|
299
|
+
interface AcpPromptResult {
|
|
300
|
+
stopReason: "end_turn" | "max_tokens" | "max_turn_requests" | "refusal" | "cancelled" | string;
|
|
301
|
+
}
|
|
302
|
+
/** `session/update` notification params; only the mapped kinds are typed. */
|
|
303
|
+
interface AcpSessionUpdateParams {
|
|
304
|
+
sessionId: string;
|
|
305
|
+
update: {
|
|
306
|
+
sessionUpdate: "agent_message_chunk" | "agent_thought_chunk";
|
|
307
|
+
content: AcpContentBlock | AcpContentBlock[];
|
|
308
|
+
} | {
|
|
309
|
+
sessionUpdate: "tool_call";
|
|
310
|
+
toolCallId: string;
|
|
311
|
+
title?: string;
|
|
312
|
+
kind?: string;
|
|
313
|
+
status?: "pending" | "in_progress" | "completed" | "failed";
|
|
314
|
+
rawInput?: unknown;
|
|
315
|
+
} | {
|
|
316
|
+
sessionUpdate: "tool_call_update";
|
|
317
|
+
toolCallId: string;
|
|
318
|
+
status?: "pending" | "in_progress" | "completed" | "failed";
|
|
319
|
+
content?: AcpContentBlock[];
|
|
320
|
+
rawOutput?: unknown;
|
|
321
|
+
} | {
|
|
322
|
+
sessionUpdate: "plan";
|
|
323
|
+
entries: Array<{
|
|
324
|
+
content: string;
|
|
325
|
+
priority?: string;
|
|
326
|
+
status?: string;
|
|
327
|
+
}>;
|
|
328
|
+
} | {
|
|
329
|
+
sessionUpdate: string;
|
|
330
|
+
[key: string]: unknown;
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
/** One turn's inputs, resolved before any session or process work. */
|
|
334
|
+
interface AcpTurn<TConfig extends AcpBridgeConfig> {
|
|
335
|
+
readonly config: TConfig;
|
|
336
|
+
/**
|
|
337
|
+
* The process configuration a cached session was started with. A turn
|
|
338
|
+
* with a different key gets a new process: an ACP agent reads its model
|
|
339
|
+
* and backing agent once, at startup.
|
|
340
|
+
*/
|
|
341
|
+
readonly processKey: string;
|
|
342
|
+
}
|
|
343
|
+
/** Text carried by ACP content blocks, including tool-call content. */
|
|
344
|
+
declare function acpContentText(content: AcpContentBlock | AcpContentBlock[] | undefined): string;
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region src/turn-process.d.ts
|
|
347
|
+
/** A turn transport may finish while its provider server remains alive. */
|
|
348
|
+
type CliTurnProcess = Pick<CliProcess, "pid" | "write" | "closeInput" | "kill" | "exitPromise" | "beginRawCapture"> & {
|
|
349
|
+
stderr?: NodeJS.ReadableStream;
|
|
350
|
+
};
|
|
351
|
+
type CliTurnSpawn<TConfig, TEvent> = {
|
|
352
|
+
input: AgentExecutionInput;
|
|
353
|
+
sessionId: string;
|
|
354
|
+
providerSessionId?: string;
|
|
355
|
+
config: TConfig;
|
|
356
|
+
execArgs: CliExecArgs;
|
|
357
|
+
workspaceRoot: string;
|
|
358
|
+
env: Record<string, string | undefined>;
|
|
359
|
+
signal: AbortSignal;
|
|
360
|
+
timeoutMs?: number;
|
|
361
|
+
parser: StreamParserConfig<TEvent>;
|
|
362
|
+
/**
|
|
363
|
+
* A process started before the turn it serves (a held spare): its raw
|
|
364
|
+
* capture opens when a turn adopts it (`beginRawCapture`), inside that
|
|
365
|
+
* turn's attempt, not at spawn.
|
|
366
|
+
*/
|
|
367
|
+
deferRawCapture?: boolean;
|
|
368
|
+
};
|
|
369
|
+
/** One turn's launch, prepared for a caller that runs the process itself. */
|
|
370
|
+
type PreparedCliLaunch = {
|
|
371
|
+
/** Pass to `execCli` or `launchCliProcess`, adding `signal` and `timeoutMs`. */spawn: CliSpawnConfig; /** Write to the child's stdin and close it; absent when the prompt is in argv. */
|
|
372
|
+
stdin?: string; /** The native session id the argv names, for a harness that pre-mints it. */
|
|
373
|
+
nativeSessionId?: string; /** The profile's workspace files and spawn inputs that were applied. */
|
|
374
|
+
workspacePlan?: WorkspacePlanReceipt;
|
|
375
|
+
};
|
|
376
|
+
//#endregion
|
|
377
|
+
//#region src/adapter-lifecycle.d.ts
|
|
378
|
+
/** Owns configuration, initialization, cancellation, and subprocess identity. */
|
|
379
|
+
declare abstract class CliAdapterLifecycle<TConfig extends CliProviderConfig = CliProviderConfig> {
|
|
380
|
+
abstract readonly provider: string;
|
|
381
|
+
protected abstract readonly defaultCliPath: string;
|
|
382
|
+
/** The message log directory when the caller names none. */
|
|
383
|
+
protected readonly defaultStorageDir?: string;
|
|
384
|
+
protected readonly inheritProcessEnv: boolean;
|
|
385
|
+
protected config: TConfig;
|
|
386
|
+
private readonly initialConfig;
|
|
387
|
+
protected logger: CliProviderLogger;
|
|
388
|
+
protected sessionStore: SessionStore | null;
|
|
389
|
+
protected messageStore: MessageStore | null;
|
|
390
|
+
protected storagePath: string;
|
|
391
|
+
private _storageDir;
|
|
392
|
+
private readonly agentEnvironment;
|
|
393
|
+
/** The consumer's executor for turn processes; a local spawn when absent. */
|
|
394
|
+
protected readonly launcher: CliLauncher | undefined;
|
|
395
|
+
/** Whether a turn's leftover process-group members are stopped at exit. */
|
|
396
|
+
protected readonly ownProcessGroup: boolean;
|
|
397
|
+
protected initialized: boolean;
|
|
398
|
+
protected readonly activeProcesses: Set<CliTurnProcess>;
|
|
399
|
+
private readonly initialization;
|
|
400
|
+
constructor(options?: CliProviderOptions<TConfig>);
|
|
401
|
+
protected get storageDir(): string;
|
|
402
|
+
/** Bind a live interaction to the exact provider execution that originated it. */
|
|
403
|
+
protected interactionExecutionBinding(input: AgentExecutionInput, sessionId: string): InteractionExecutionBinding;
|
|
404
|
+
/** The uid/gid every CLI process this adapter spawns runs as, or undefined when the host process is already unprivileged. */
|
|
405
|
+
protected subprocessIdentity(): {
|
|
406
|
+
uid: number;
|
|
407
|
+
gid: number;
|
|
408
|
+
} | undefined;
|
|
409
|
+
/** `subprocessIdentity` shaped for `spawn`'s options bag. */
|
|
410
|
+
protected subprocessSpawnOptions(): {
|
|
411
|
+
uid?: number;
|
|
412
|
+
gid?: number;
|
|
413
|
+
};
|
|
414
|
+
/** Run a one-shot CLI command under this adapter's subprocess identity. */
|
|
415
|
+
protected runCli(config: Omit<CliSpawnConfig, "rawCapturePath">): Promise<CliExecResult<unknown>>;
|
|
416
|
+
/** Run a builtin-only Node script under this adapter's subprocess identity and return its stdout. */
|
|
417
|
+
protected runNodeAsSubprocess(script: string, args: readonly string[], input?: string): Promise<string>;
|
|
418
|
+
getCapabilities(): BackendCapabilities;
|
|
419
|
+
initialize(config: ProviderConfig & Pick<CliProviderConfig, "runtimeAttachments">): Promise<void>;
|
|
420
|
+
private initializeAtGeneration;
|
|
421
|
+
/** Auth/config files the adapter needs on disk that do NOT arrive through `config.model.authFiles` — e.g. */
|
|
422
|
+
getManagedAuthFiles(): CliAuthFile[];
|
|
423
|
+
/** Provider-specific initialization runs inside the tracked lifecycle. */
|
|
424
|
+
protected afterInitialize(_config: ProviderConfig): Promise<void>;
|
|
425
|
+
/** The harness session contract this adapter honours (cli-agent-registry NATIVE_SESSION_CONTRACTS), or null for a provider that declares none. */
|
|
426
|
+
protected sessionContract(): HarnessSessionContract | null;
|
|
427
|
+
protected withExecution<T>(signal: AbortSignal | undefined, run: (signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
428
|
+
shutdown(): Promise<void>;
|
|
429
|
+
healthCheck(): Promise<boolean>;
|
|
430
|
+
/** Run this CLI's own one-shot command (version, MCP) in the workspace. */
|
|
431
|
+
protected runAuxiliaryCli(args: string[], timeoutMs: number): Promise<CliExecResult<unknown>>;
|
|
432
|
+
updateConfig(config: Partial<TConfig>): Promise<TConfig>;
|
|
433
|
+
/** Build environment variables for CLI execution. */
|
|
434
|
+
protected abstract buildExecEnv(config: TConfig): Record<string, string | undefined>;
|
|
435
|
+
/** Apply private native credentials to every CLI subprocess through one path. */
|
|
436
|
+
protected buildNativeExecutionEnvironment(config: TConfig): Record<string, string | undefined>;
|
|
437
|
+
protected getCliPath(): string;
|
|
438
|
+
protected ensureInitialized(): void;
|
|
439
|
+
protected getSessionStore(): SessionStore;
|
|
440
|
+
protected getMessageStore(): MessageStore;
|
|
441
|
+
/** The agent environment the host supplied (CliProviderOptions.agentEnvironment). */
|
|
442
|
+
protected agentEnvironmentValues(): Record<string, string | undefined>;
|
|
443
|
+
protected applyWritableHomeDefaults(adapterEnv: Record<string, string | undefined>, workspaceRoot: string): Record<string, string | undefined>;
|
|
444
|
+
}
|
|
445
|
+
//#endregion
|
|
446
|
+
//#region src/adapter-profile.d.ts
|
|
447
|
+
/** Owns native profile revisions, launch controls, and prompt composition. */
|
|
448
|
+
declare abstract class CliAdapterProfile<TConfig extends CliProviderConfig = CliProviderConfig> extends CliAdapterLifecycle<TConfig> {
|
|
449
|
+
/** Native profile lowering explicitly owned by this adapter, never inferred from a path. */
|
|
450
|
+
protected readonly profileHarness: HarnessId | undefined;
|
|
451
|
+
/** Trusted implementation capabilities; never read from caller-owned configuration. */
|
|
452
|
+
protected readonly supportsSecretProfileRevisions: boolean;
|
|
453
|
+
private readonly profileSecretProvider;
|
|
454
|
+
private readonly secretProfileRuntimeKeyProvider;
|
|
455
|
+
/** Private native preparation state; never part of a returned receipt. */
|
|
456
|
+
private readonly secretProfileRevisions;
|
|
457
|
+
constructor(options?: CliProviderOptions<TConfig>);
|
|
458
|
+
/** The exact child environment a turn uses; shared with prewarm paths. */
|
|
459
|
+
protected buildTurnEnvironment(executionConfig: TConfig, profilePlan: WorkspacePlanApplication | undefined, workspaceRoot: string, correlationHeaders: Readonly<Record<string, string>> | undefined): Record<string, string | undefined>;
|
|
460
|
+
/** A profile's declared executable tools, sealed in its revision, stand in for the app's own tool dirs on this launch's PATH tail. */
|
|
461
|
+
private bindProfileToolBinDirs;
|
|
462
|
+
protected bindExecutionCorrelation(environment: Record<string, string | undefined>, correlationHeaders: Readonly<Record<string, string>> | undefined): Record<string, string | undefined>;
|
|
463
|
+
/** Launcher controls this adapter OWNS on the spawn it starts; the pre-box verdict reads the same table. */
|
|
464
|
+
protected profileMaterializationBinds(): readonly BindableLaunchControl[];
|
|
465
|
+
/** Optional native instruction root. */
|
|
466
|
+
protected profileAgentDirectory(_workspaceRoot: string): string | undefined;
|
|
467
|
+
/** Provider transport bound into the private immutable revision and receipt. */
|
|
468
|
+
protected secretProfileProviderConfig(): Record<string, unknown> | undefined;
|
|
469
|
+
/** The values behind a secret revision's `{env:NAME}` config references, for an executor that serves those references itself. */
|
|
470
|
+
protected secretProfileReferences(application: WorkspacePlanApplication | undefined): Readonly<Record<string, string>> | undefined;
|
|
471
|
+
/** The one sealed session view repointed only while its native turn owns the queue. */
|
|
472
|
+
protected secretProfileSessionView(sessionId: string): {
|
|
473
|
+
launchRoot: string;
|
|
474
|
+
view: string;
|
|
475
|
+
subprocessUid: number;
|
|
476
|
+
};
|
|
477
|
+
/** Bind the private revision into the session's stable native cwd. */
|
|
478
|
+
protected bindSecretProfileSessionView(revisionWorkspaceDir: string, sessionId: string): string;
|
|
479
|
+
protected materializeProfileResources(inputProfile: AgentProfile | undefined, workspaceRoot: string, ownerId?: string, sessionId?: string, scope?: "turn" | "prewarm"): Promise<WorkspacePlanApplication | undefined>;
|
|
480
|
+
/** This spawn's plan: a strict refusal throws, a best-effort one is logged. */
|
|
481
|
+
protected planProfile(profile: AgentProfile, harness: HarnessId, agentInstructions?: boolean): WorkspacePlan;
|
|
482
|
+
private applyProfileResources;
|
|
483
|
+
/** Publish the profile as an executor-sealed revision for this session's subprocess identity, and record the receipt that binds it to the turn. */
|
|
484
|
+
private applySecretProfileRevision;
|
|
485
|
+
/** Prepare the same provider-composed native plan that execute() will check. */
|
|
486
|
+
preparePublicProfileRevision(input: AgentExecutionInput): Promise<Pick<_$_tangle_network_agent_profile_materialize0.ManagedWorkspaceManifest, "workspacePlanDigest" | "materializedDigest" | "conflicts"> & {
|
|
487
|
+
launchDigest: string;
|
|
488
|
+
}>;
|
|
489
|
+
/** Prepare the private native plan and return only an opaque executor receipt. */
|
|
490
|
+
prepareSecretProfileRevision(input: AgentExecutionInput): Promise<Omit<Pick<_$_tangle_network_agent_profile_materialize0.ManagedWorkspaceManifest, "workspacePlanDigest" | "materializedDigest" | "conflicts"> & {
|
|
491
|
+
launchDigest: string;
|
|
492
|
+
}, "materializedDigest" | "launchDigest"> & {
|
|
493
|
+
executorReceipt: string;
|
|
494
|
+
}>;
|
|
495
|
+
/** What the native health check's verdict depends on besides a revision's bytes: the executable that loads them. */
|
|
496
|
+
protected secretProfileVerificationScope(): string;
|
|
497
|
+
/** A secret receipt is issued only after the provider can load this revision. */
|
|
498
|
+
protected verifyPreparedSecretProfileRevision(_input: AgentExecutionInput, _application: WorkspacePlanApplication): Promise<void>;
|
|
499
|
+
/** Resolve the canonical profile used for this execution. */
|
|
500
|
+
protected resolveExecutionProfile(requestPrompt: string | undefined): AgentProfile | undefined;
|
|
501
|
+
/** Select the profile materialized for this exact turn. */
|
|
502
|
+
protected resolveExecutionProfileForInput(input: AgentExecutionInput): AgentProfile | undefined;
|
|
503
|
+
/** Compose the provider's user-message channel for this exact turn. */
|
|
504
|
+
protected composePromptText(promptText: string, input: AgentExecutionInput): string;
|
|
505
|
+
protected withProfilePlan(config: TConfig, profilePlan: WorkspacePlanApplication | undefined): TConfig;
|
|
506
|
+
/** A profile's addition precedes host context while preserving its harness prompt. */
|
|
507
|
+
protected resolveProfilePrompts(input: CliExecutionInput, plan: WorkspacePlanApplication | undefined, profile?: AgentProfile | undefined): {
|
|
508
|
+
systemPrompt: string | undefined;
|
|
509
|
+
appendSystemPrompt: string | undefined;
|
|
510
|
+
};
|
|
511
|
+
protected resolveProfileSystemPrompt(requestPrompt: string | undefined, profilePlan: WorkspacePlanApplication | undefined): string | undefined;
|
|
512
|
+
protected resolveProfileModel(requestModel: string | undefined): string | undefined;
|
|
513
|
+
protected mergeProfilePlanEnvironment(environment: Record<string, string | undefined>, profilePlan: WorkspacePlanApplication | undefined, preserveClearedVariables?: boolean): Record<string, string | undefined>;
|
|
514
|
+
/** Provider-owned allowlist for a generated revision control after env scrub. */
|
|
515
|
+
protected profilePlanMayFillClearedEnvironmentVariable(_name: string, _value: string): boolean;
|
|
516
|
+
protected preparePromptInput(parts: InputPart[], workspaceRoot: string, sessionId: string, options?: Parameters<typeof preparePromptInputParts>[3]): Promise<{
|
|
517
|
+
promptText: string;
|
|
518
|
+
persistedParts: _$_tangle_network_sdk_session_persistence0.MessagePart[];
|
|
519
|
+
attachments: PreparedAttachment[];
|
|
520
|
+
}>;
|
|
521
|
+
/** Attachment kinds this adapter forwards natively via buildExecArgs (argv flag / stdin content block) instead of the `[Image: ...]` / `[File: ...]` text marker. */
|
|
522
|
+
protected nativeAttachmentKinds(): ReadonlyArray<"image" | "file">;
|
|
523
|
+
}
|
|
524
|
+
//#endregion
|
|
525
|
+
//#region src/adapter-sessions.d.ts
|
|
526
|
+
/** Owns durable transcripts, provider-native session bindings and the turn hooks providers override. */
|
|
527
|
+
declare abstract class CliAdapterSessions<TConfig extends CliProviderConfig = CliProviderConfig> extends CliAdapterProfile<TConfig> {
|
|
528
|
+
createSession(options?: {
|
|
529
|
+
workspaceRoot?: string;
|
|
530
|
+
}): Promise<string>;
|
|
531
|
+
deleteSession(sessionId: string): Promise<boolean>;
|
|
532
|
+
/**
|
|
533
|
+
* Choose the native ID before its argv check, durable binding, and
|
|
534
|
+
* reservation. `input` and `timeoutMs` are the turn's, for a harness that
|
|
535
|
+
* decides here whether a process started earlier can serve it.
|
|
536
|
+
*/
|
|
537
|
+
protected mintNativeSessionId(_context: {
|
|
538
|
+
sessionId: string;
|
|
539
|
+
workspaceRoot: string;
|
|
540
|
+
config: TConfig;
|
|
541
|
+
model?: string;
|
|
542
|
+
env: Record<string, string | undefined>;
|
|
543
|
+
signal: AbortSignal;
|
|
544
|
+
buildExecArgs: (nativeSessionId: string) => CliExecArgs;
|
|
545
|
+
input: AgentExecutionInput;
|
|
546
|
+
timeoutMs?: number;
|
|
547
|
+
}): string | Promise<string>;
|
|
548
|
+
/**
|
|
549
|
+
* Make a pre-minted native session durable before the CLI starts, for a
|
|
550
|
+
* harness that would otherwise write nothing until its first model reply
|
|
551
|
+
* (Pi). Called after the argv check and before spawn.
|
|
552
|
+
*/
|
|
553
|
+
protected reserveNativeSession(_nativeSessionId: string, _context: {
|
|
554
|
+
workspaceRoot: string;
|
|
555
|
+
}): void | Promise<void>;
|
|
556
|
+
/**
|
|
557
|
+
* Verify that the provider can resume the native session binding. By
|
|
558
|
+
* default a session in a per-session store is resumable only when one of
|
|
559
|
+
* its declared files exists under the runtime HOME; a pre-minted id whose
|
|
560
|
+
* first turn died before the CLI wrote anything is not.
|
|
561
|
+
*/
|
|
562
|
+
protected providerSessionIsResumable(runtimeHome: string, providerSessionId: string): boolean | Promise<boolean>;
|
|
563
|
+
/**
|
|
564
|
+
* Resolve the provider-native session id the next turn can resume, or
|
|
565
|
+
* undefined when no usable binding exists. Provider session data lives
|
|
566
|
+
* under the runtime home that minted it. A different home or missing
|
|
567
|
+
* provider storage cannot resume that session. A record without a home
|
|
568
|
+
* stamp predates the field, so treat it as same-home.
|
|
569
|
+
*/
|
|
570
|
+
protected resumableProviderSessionId(session: PersistedSession): Promise<string | undefined>;
|
|
571
|
+
/** Bind a checkpoint-proven native session to this provider identity before execution. */
|
|
572
|
+
protected seedNativeSessionForResume(input: AgentExecutionInput, nativeSessionId: string): Promise<void>;
|
|
573
|
+
/**
|
|
574
|
+
* Forks the persisted session and copies its messages up to `messageId`.
|
|
575
|
+
* The forked record carries no provider session id, so its first turn
|
|
576
|
+
* starts a fresh CLI session and receives the copied transcript as
|
|
577
|
+
* execution-only context. Callers that address turns by their own session
|
|
578
|
+
* id (the sidecar) pass that id as `targetSessionId` so later turns find
|
|
579
|
+
* the forked record.
|
|
580
|
+
*/
|
|
581
|
+
forkSession(options: {
|
|
582
|
+
sessionId: string;
|
|
583
|
+
messageId?: string;
|
|
584
|
+
workspaceRoot?: string;
|
|
585
|
+
targetSessionId?: string;
|
|
586
|
+
}): Promise<string>;
|
|
587
|
+
getMessages(options: GetMessagesOptions): Promise<BackendMessage[]>;
|
|
588
|
+
protected toBackendMessage(msg: PersistedMessage): BackendMessage;
|
|
589
|
+
protected buildAssistantParts(state: ExecutionState): MessagePart[];
|
|
590
|
+
protected extractToolInvocations(state: ExecutionState): AgentExecutionResult["toolInvocations"];
|
|
591
|
+
/**
|
|
592
|
+
* Names of tools this provider substitutes for a model tool call it could
|
|
593
|
+
* not parse into any real tool.
|
|
594
|
+
*
|
|
595
|
+
* Default: none. A provider that has one must say so, because these calls
|
|
596
|
+
* do not present as failures. OpenCode's `invalid` reports the parse error
|
|
597
|
+
* as its output and completes, so the repeated-failure guard reads a run of
|
|
598
|
+
* them as progress and clears its count on every one.
|
|
599
|
+
*/
|
|
600
|
+
protected toolCallRepairToolNames(): ReadonlySet<string>;
|
|
601
|
+
/**
|
|
602
|
+
* Decide whether a non-zero exit should be treated as success.
|
|
603
|
+
*
|
|
604
|
+
* Default: no — any non-zero exit is a failure.
|
|
605
|
+
*
|
|
606
|
+
* Providers override this when their CLI has a known "exits non-zero
|
|
607
|
+
* on a successful run" quirk (e.g. kimi writes its resume trailer to
|
|
608
|
+
* stderr and exits non-zero even when the task completed cleanly).
|
|
609
|
+
*
|
|
610
|
+
* The decision is made AFTER the stream has drained and the exit
|
|
611
|
+
* code is known, so `state` reflects the full set of events the
|
|
612
|
+
* parser emitted (including any terminal `result` / `done` event).
|
|
613
|
+
* A safe heuristic is: "non-zero exit + stderr matches known trailer
|
|
614
|
+
* pattern + at least one assistant part was recorded".
|
|
615
|
+
*/
|
|
616
|
+
protected isBenignNonZeroExit(_params: {
|
|
617
|
+
exitCode: number | null;
|
|
618
|
+
stderr: string;
|
|
619
|
+
state: ExecutionState;
|
|
620
|
+
}): boolean;
|
|
621
|
+
/** Observe settled process output before success/failure classification. */
|
|
622
|
+
protected afterCliProcessExit(_params: {
|
|
623
|
+
state: ExecutionState;
|
|
624
|
+
stderr: string;
|
|
625
|
+
exit: CliExitResult;
|
|
626
|
+
workspaceRoot: string;
|
|
627
|
+
env: Record<string, string | undefined>;
|
|
628
|
+
onEvent?: (event: StreamEvent) => void;
|
|
629
|
+
}): Promise<void>;
|
|
630
|
+
protected executionOutcome(_state: ExecutionState, _input: AgentExecutionInput): AgentExecutionOutcome | Promise<AgentExecutionOutcome>;
|
|
631
|
+
/**
|
|
632
|
+
* Format a message for stdin input.
|
|
633
|
+
*/
|
|
634
|
+
protected formatStdinMessage(message: string): string;
|
|
635
|
+
}
|
|
636
|
+
//#endregion
|
|
637
|
+
//#region src/adapter-mcp.d.ts
|
|
638
|
+
/** Owns serialized MCP mutations and provider-native MCP status commands. */
|
|
639
|
+
declare abstract class CliAdapterMcp<TConfig extends CliProviderConfig = CliProviderConfig> extends CliAdapterSessions<TConfig> {
|
|
640
|
+
/** Budget for one `mcp list` run, CLI startup and every server's handshake. */
|
|
641
|
+
protected readonly mcpStatusTimeoutMs: number;
|
|
642
|
+
private mcpMutationChain;
|
|
643
|
+
addMcp(name: string, config: McpConfig): Promise<void>;
|
|
644
|
+
private addMcpSerialized;
|
|
645
|
+
getMcpStatus(): Promise<McpStatusResponse>;
|
|
646
|
+
ensureMcps(required: Record<string, McpConfig>): Promise<void>;
|
|
647
|
+
/** Build MCP add command arguments. Override for CLI-specific syntax. */
|
|
648
|
+
protected buildMcpAddArgs(name: string, config: McpConfig): string[];
|
|
649
|
+
/**
|
|
650
|
+
* Build MCP list command arguments. Return null if not supported.
|
|
651
|
+
*/
|
|
652
|
+
protected buildMcpListArgs(): string[] | null;
|
|
653
|
+
/** Parse MCP list output. Override for CLI-specific output format. */
|
|
654
|
+
protected parseMcpListOutput(output: string): McpStatusResponse;
|
|
655
|
+
}
|
|
656
|
+
//#endregion
|
|
657
|
+
//#region src/turn-observer.d.ts
|
|
658
|
+
interface TurnObserverOptions {
|
|
659
|
+
provider: string;
|
|
660
|
+
state: ExecutionState;
|
|
661
|
+
sessionId: string;
|
|
662
|
+
getRuntimeHome: () => string | undefined;
|
|
663
|
+
recorder: SdkHostServices["recorder"];
|
|
664
|
+
getSessionStore: () => SessionStore;
|
|
665
|
+
logger: CliProviderLogger;
|
|
666
|
+
repairToolNames: ReadonlySet<string>;
|
|
667
|
+
onEvent: ((event: StreamEvent) => void) | undefined;
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Observes one turn's provider stream: keeps the execution state current,
|
|
671
|
+
* persists parts and the provider session id as they arrive, stops a turn
|
|
672
|
+
* that repeats a rejected tool call, and pings while the stream is quiet.
|
|
673
|
+
*/
|
|
674
|
+
declare class TurnObserver {
|
|
675
|
+
private readonly options;
|
|
676
|
+
providerSessionPersistence: Promise<void>;
|
|
677
|
+
providerSessionPersistenceError: unknown;
|
|
678
|
+
nativeSessionObserved: boolean;
|
|
679
|
+
private readonly partUpdates;
|
|
680
|
+
private readonly liveness;
|
|
681
|
+
private readonly repeatedToolFailureGuard;
|
|
682
|
+
private killForRepeatedToolFailure;
|
|
683
|
+
constructor(options: TurnObserverOptions);
|
|
684
|
+
flushPartUpdates(): Promise<void>;
|
|
685
|
+
attachProcess(process: CliTurnProcess): void;
|
|
686
|
+
startLiveness(executionSignal: AbortSignal, startTime: number): NodeJS.Timeout;
|
|
687
|
+
readonly onEvent: (event: StreamEvent) => void;
|
|
688
|
+
private observeToolPart;
|
|
689
|
+
private persistProviderSession;
|
|
690
|
+
}
|
|
691
|
+
//#endregion
|
|
692
|
+
//#region src/execution-state.d.ts
|
|
693
|
+
/** Creates a new execution state. */
|
|
694
|
+
declare function createExecutionState(sessionId?: string, messageId?: string, workspaceRoot?: string): ExecutionState;
|
|
695
|
+
//#endregion
|
|
696
|
+
//#region src/profile-config.d.ts
|
|
697
|
+
/**
|
|
698
|
+
* Per-turn credential delivery wins over host-env resolution; the host box
|
|
699
|
+
* environment stays the fallback for references the turn did not deliver.
|
|
700
|
+
* With no turn secrets the host provider is returned unchanged, so the
|
|
701
|
+
* overlay adds no behavior to executions that never asked for it.
|
|
702
|
+
*/
|
|
703
|
+
declare function runtimeSecretsOverlay(runtimeSecrets: Record<string, string> | undefined, fallback: AgentProfileSecretProvider): AgentProfileSecretProvider;
|
|
704
|
+
//#endregion
|
|
705
|
+
//#region src/base-adapter.d.ts
|
|
706
|
+
/** Base adapter for CLI-based AI agent providers. */
|
|
707
|
+
declare abstract class CliProviderAdapterBase<TConfig extends CliProviderConfig = CliProviderConfig, TEvent = unknown> extends CliAdapterMcp<TConfig> implements SdkProviderAdapter {
|
|
708
|
+
protected readonly supportsManagedQuote: boolean;
|
|
709
|
+
execute(input: AgentExecutionInput, services: SdkHostServices, onEvent?: (event: StreamEvent) => void): Promise<AgentExecutionResult>;
|
|
710
|
+
private executeInternal;
|
|
711
|
+
protected completeTurn(params: {
|
|
712
|
+
input: AgentExecutionInput;
|
|
713
|
+
sessionId: string;
|
|
714
|
+
state: ExecutionState; /** The CLI turn's observer, whose coalesced part updates drain first. */
|
|
715
|
+
observer?: TurnObserver;
|
|
716
|
+
recorder: SdkHostServices["recorder"];
|
|
717
|
+
providerMessageIds: ReturnType<typeof readProviderMessageIds>;
|
|
718
|
+
profilePlan?: WorkspacePlanApplication;
|
|
719
|
+
startTime: number;
|
|
720
|
+
endTime: number;
|
|
721
|
+
}): Promise<AgentExecutionResult>;
|
|
722
|
+
/** Report and record a failed turn, then throw its error. */
|
|
723
|
+
private failCliTurn;
|
|
724
|
+
protected openTurnSession(input: AgentExecutionInput, recorder: SdkHostServices["recorder"], onEvent: ((event: StreamEvent) => void) | undefined): Promise<{
|
|
725
|
+
providerMessageIds: _$_tangle_network_sdk_session_persistence0.ProviderMessageIds | undefined;
|
|
726
|
+
cached: AgentExecutionResult;
|
|
727
|
+
sessionId: string;
|
|
728
|
+
providerSessionId: string | undefined;
|
|
729
|
+
transcriptReplay: "fork" | "restored" | undefined;
|
|
730
|
+
} | {
|
|
731
|
+
providerMessageIds: _$_tangle_network_sdk_session_persistence0.ProviderMessageIds | undefined;
|
|
732
|
+
cached: undefined;
|
|
733
|
+
sessionId: string;
|
|
734
|
+
providerSessionId: string | undefined;
|
|
735
|
+
transcriptReplay: "fork" | "restored" | undefined;
|
|
736
|
+
}>;
|
|
737
|
+
protected materializeTurnProfile(input: AgentExecutionInput, sessionId: string): Promise<{
|
|
738
|
+
executionProfile: AgentProfile | undefined;
|
|
739
|
+
profilePlan: WorkspacePlanApplication | undefined;
|
|
740
|
+
}>;
|
|
741
|
+
protected recordTurnPrompt(input: AgentExecutionInput, session: {
|
|
742
|
+
sessionId: string;
|
|
743
|
+
transcriptReplay: "fork" | "restored" | undefined;
|
|
744
|
+
providerMessageIds: ReturnType<typeof readProviderMessageIds>;
|
|
745
|
+
}, recorder: SdkHostServices["recorder"], attachmentOptions?: {
|
|
746
|
+
nativeAttachmentKinds?: ReadonlyArray<"image" | "file">;
|
|
747
|
+
inlineImageBudgetBytes?: number;
|
|
748
|
+
}): Promise<{
|
|
749
|
+
preparedInput: {
|
|
750
|
+
promptText: string;
|
|
751
|
+
persistedParts: _$_tangle_network_sdk_session_persistence0.MessagePart[];
|
|
752
|
+
attachments: PreparedAttachment[];
|
|
753
|
+
};
|
|
754
|
+
promptText: string;
|
|
755
|
+
}>;
|
|
756
|
+
/** Resolve this turn's config, environment and argv, and check them against the session contract. */
|
|
757
|
+
private planLaunch;
|
|
758
|
+
/** Reserve and announce the native session id a pre-minted harness already has. */
|
|
759
|
+
private bindNativeSession;
|
|
760
|
+
private runCliTurn;
|
|
761
|
+
protected abstract buildExecArgs(params: {
|
|
762
|
+
message: string;
|
|
763
|
+
config: TConfig; /** Canonical identity for providers whose native config binds HTTP headers. */
|
|
764
|
+
correlationHeaders?: Readonly<Record<string, string>>;
|
|
765
|
+
model?: string;
|
|
766
|
+
sessionId?: string; /** Set on a new session of a harness whose contract pre-mints its id: the adapter MUST start the native session under this id with the contract's identity args (e.g. */
|
|
767
|
+
mintedSessionId?: string;
|
|
768
|
+
workspaceRoot: string;
|
|
769
|
+
systemPrompt?: string; /** The plan's ADDITIVE prompt intent: the harness's own prompt stays in force and this text is added after it. */
|
|
770
|
+
appendSystemPrompt?: string;
|
|
771
|
+
attachments?: PreparedAttachment[]; /** Preserve the origin of launch flags when a CLI needs one selected agent. */
|
|
772
|
+
profilePlan?: WorkspacePlanApplication;
|
|
773
|
+
}): CliExecArgs;
|
|
774
|
+
protected abstract createEventParser(state: ExecutionState, onEvent?: (event: StreamEvent) => void): StreamParserConfig<TEvent>;
|
|
775
|
+
/** How one turn's argv runs: cwd, environment, identity or launcher, stdio. */
|
|
776
|
+
private turnSpawnConfig;
|
|
777
|
+
/** The launch one turn would make, without starting it: the spawn config (argv, cwd, environment, identity or launcher). */
|
|
778
|
+
prepareLaunch(input: CliExecutionInput, options?: {
|
|
779
|
+
providerSessionId?: string;
|
|
780
|
+
}): Promise<PreparedCliLaunch>;
|
|
781
|
+
protected spawnExecutionProcess(request: CliTurnSpawn<TConfig, TEvent>): CliTurnProcess | Promise<CliTurnProcess>;
|
|
782
|
+
}
|
|
783
|
+
//#endregion
|
|
784
|
+
//#region src/acp-session-adapter.d.ts
|
|
785
|
+
declare abstract class AcpProviderAdapterBase<TConfig extends AcpBridgeConfig, TTurn extends AcpTurn<TConfig> = AcpTurn<TConfig>> extends CliProviderAdapterBase<TConfig> {
|
|
786
|
+
protected abstract readonly loadsNativeSessions: boolean;
|
|
787
|
+
private readonly acpSessions;
|
|
788
|
+
protected abstract resolveTurn(input: AgentExecutionInput): TTurn;
|
|
789
|
+
protected abstract processSpec(turn: TTurn, context: {
|
|
790
|
+
sessionId: string;
|
|
791
|
+
workspaceRoot: string;
|
|
792
|
+
}): AcpProcessSpec | Promise<AcpProcessSpec>;
|
|
793
|
+
protected abstract spawnFailureMessage(failure: {
|
|
794
|
+
message: string;
|
|
795
|
+
missingBinary: boolean;
|
|
796
|
+
}, turn: TTurn): string;
|
|
797
|
+
protected abstract promptBlocks(input: AgentExecutionInput, prepared: {
|
|
798
|
+
promptText: string;
|
|
799
|
+
persistedParts: MessagePart[];
|
|
800
|
+
attachments: PreparedAttachment[];
|
|
801
|
+
}, turn: TTurn): AcpContentBlock[];
|
|
802
|
+
protected spawnBridge(request: AcpBridgeSpawn): RpcBridge;
|
|
803
|
+
protected checkAgentProtocolVersion(_advertised: number, _turn: TTurn): void;
|
|
804
|
+
protected resumeSessionId(): string | undefined;
|
|
805
|
+
protected onSessionOpened(_bridge: RpcBridge, _acpSessionId: string, _turn: TTurn, _options: {
|
|
806
|
+
timeoutMs: number;
|
|
807
|
+
}): Promise<void>;
|
|
808
|
+
protected onBridgeSpawned(_bridge: RpcBridge, _sessionId: string, _turn: TTurn): void;
|
|
809
|
+
protected beginTurn(_sessionId: string, _input: AgentExecutionInput, _onEvent: ((event: StreamEvent) => void) | undefined): () => void;
|
|
810
|
+
protected onToolFailed(_sessionId: string, _failureText: string | undefined): StreamEvent[];
|
|
811
|
+
protected takeTurnFailure(_sessionId: string): Error | undefined;
|
|
812
|
+
protected onSessionEvicted(_sessionId: string): void;
|
|
813
|
+
protected turnLogContext(_turn: TTurn): Record<string, unknown>;
|
|
814
|
+
execute(input: AgentExecutionInput, services: SdkHostServices, onEvent?: (event: StreamEvent) => void): Promise<AgentExecutionResult>;
|
|
815
|
+
protected interruptStuckTurn(): void;
|
|
816
|
+
protected acknowledgeLostTurn(_detail: string): Promise<boolean>;
|
|
817
|
+
private acquireAcpSession;
|
|
818
|
+
private checkProtocolVersion;
|
|
819
|
+
private openNativeSession;
|
|
820
|
+
private promptAcpSession;
|
|
821
|
+
private scheduleIdleReap;
|
|
822
|
+
private cancelIdleReap;
|
|
823
|
+
protected evictAcpSession(sessionId: string, reason: string): void;
|
|
824
|
+
protected evictAcpSessionsWhere(matches: (processKey: string) => boolean, reason: string): void;
|
|
825
|
+
private mapAcpUpdate;
|
|
826
|
+
private mapToolStatus;
|
|
827
|
+
private formatBridgeError;
|
|
828
|
+
private sessionSetupError;
|
|
829
|
+
healthCheck(): Promise<boolean>;
|
|
830
|
+
shutdown(): Promise<void>;
|
|
831
|
+
addMcp(_name: string, _config: McpConfig): Promise<void>;
|
|
832
|
+
getMcpStatus(): Promise<McpStatusResponse>;
|
|
833
|
+
protected buildExecArgs(): never;
|
|
834
|
+
protected buildExecEnv(_config: TConfig): Record<string, string | undefined>;
|
|
835
|
+
protected createEventParser(): never;
|
|
836
|
+
protected buildMcpAddArgs(_name: string, _config: McpConfig | LocalMcpConfig): string[];
|
|
837
|
+
}
|
|
838
|
+
//#endregion
|
|
839
|
+
//#region src/errors.d.ts
|
|
840
|
+
/**
|
|
841
|
+
* A session's persisted transcript exists but could not be read for replay
|
|
842
|
+
* into the fresh provider session this turn starts. The turn fails instead
|
|
843
|
+
* of serving an empty conversation under the same session id. The sidecar's
|
|
844
|
+
* client-visible whitelist matches on `code`; the wire contract is the
|
|
845
|
+
* duck-typed field, not class identity.
|
|
846
|
+
*/
|
|
847
|
+
declare class SessionRehydrationError extends Error {
|
|
848
|
+
readonly code = "session_rehydration_failed";
|
|
849
|
+
constructor(message: string, cause: unknown);
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* Marks a turn failure the adapter raised before it planned the launch:
|
|
853
|
+
* session preparation or profile materialization refused, so no native
|
|
854
|
+
* process received this turn and it left no native transcript to copy.
|
|
855
|
+
* Only the adapter marks, on the error object it caught; error text never
|
|
856
|
+
* does, so a provider message that reads the same is not marked.
|
|
857
|
+
*/
|
|
858
|
+
declare function rejectNotLaunched<E>(error: E): never;
|
|
859
|
+
/** Whether this error is one the adapter raised before launching anything. */
|
|
860
|
+
declare function wasNeverLaunched(error: Error): boolean;
|
|
861
|
+
//#endregion
|
|
862
|
+
//#region src/event-parsers.d.ts
|
|
863
|
+
/**
|
|
864
|
+
* Parser for harnesses that print one JSON event per line (claude-code,
|
|
865
|
+
* codex, amp, factory-droids). Values that fail `accept` are logged and
|
|
866
|
+
* dropped; unparseable lines become a `PARSE_ERROR` warning. The first event
|
|
867
|
+
* `isReady` accepts reports the CLI's own start time as `cli_initialize`,
|
|
868
|
+
* measured from parser creation, which immediately precedes the spawn.
|
|
869
|
+
*/
|
|
870
|
+
declare function jsonEventParser<TEvent>(logger: CliProviderLogger, onEvent: ((event: StreamEvent) => void) | undefined, spec: {
|
|
871
|
+
/** Names the harness in the "Received non-<label> event" warning. */label: string;
|
|
872
|
+
accept(raw: unknown): raw is TEvent;
|
|
873
|
+
map(event: TEvent): StreamEvent[];
|
|
874
|
+
isReady?(event: TEvent): boolean;
|
|
875
|
+
}): StreamParserConfig<TEvent>;
|
|
876
|
+
/** What a plaintext harness's line mapper records about the response. */
|
|
877
|
+
interface PlaintextResponse {
|
|
878
|
+
/** Appends one line of the assistant's reply. */
|
|
879
|
+
text(line: string): void;
|
|
880
|
+
/** Records an error line; a turn with errors and no reply fails with the last one. */
|
|
881
|
+
error(message: string): void;
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* Parser for harnesses that print their reply as plain stdout lines (hermes,
|
|
885
|
+
* nanoclaw). Lines classify into provider events; the reply is
|
|
886
|
+
* emitted as one text part when stdout closes. A turn that printed errors
|
|
887
|
+
* but no reply ends `failed` with the last error instead of an empty
|
|
888
|
+
* `completed`.
|
|
889
|
+
*/
|
|
890
|
+
declare function plaintextResponseParser<TEvent>(state: ExecutionState, onEvent: ((event: StreamEvent) => void) | undefined, spec: {
|
|
891
|
+
classify(line: string): TEvent | null;
|
|
892
|
+
map(event: TEvent, response: PlaintextResponse): StreamEvent[]; /** Failure detail when errors were seen but none carried a message. */
|
|
893
|
+
emptyFailureDetail: string;
|
|
894
|
+
}): StreamParserConfig<TEvent>;
|
|
895
|
+
//#endregion
|
|
896
|
+
//#region src/execution-request-headers.d.ts
|
|
897
|
+
declare const EXECUTION_ID_HEADER = "X-Tangle-Execution-ID";
|
|
898
|
+
/** Router column that joins a model request to the turn trace that caused it. */
|
|
899
|
+
declare const EXECUTION_TRACE_HEADER = "X-Tangle-Trace-ID";
|
|
900
|
+
declare const MANAGED_QUOTE_VERSION_HEADER = "X-Tangle-Managed-Quote-Version";
|
|
901
|
+
/** Every header a turn's correlation may set, lowercased. */
|
|
902
|
+
declare const EXECUTION_CORRELATION_HEADERS: string[];
|
|
903
|
+
/**
|
|
904
|
+
* Capture diagnostic identity without forwarding caller-supplied transport headers.
|
|
905
|
+
* `traceId` is the turn's trace id; a value no header can carry is omitted,
|
|
906
|
+
* because a trace is diagnostic and must never refuse the run.
|
|
907
|
+
*/
|
|
908
|
+
declare function executionCorrelationHeaders(binding: InteractionExecutionBinding | undefined, traceId?: string, quoteVersion?: string): Readonly<Record<string, string>> | undefined;
|
|
909
|
+
//#endregion
|
|
910
|
+
//#region src/file-parts.d.ts
|
|
911
|
+
/** Infers a MIME type from a filename's extension. Unknown/no extension → undefined. */
|
|
912
|
+
declare function inferMediaType(filename: string): string | undefined;
|
|
913
|
+
/**
|
|
914
|
+
* Builds the canonical URL for a file part. A data URI passes through
|
|
915
|
+
* verbatim; a path is returned unchanged if it already carries a recognized
|
|
916
|
+
* scheme, else converted to a percent-encoded `file://` URL.
|
|
917
|
+
*
|
|
918
|
+
* Callers must pass an already-resolved absolute path — `trackFilePart`
|
|
919
|
+
* resolves relative paths (or drops the observation when it can't) before
|
|
920
|
+
* ever reaching here, so a relative path arriving at this layer means a
|
|
921
|
+
* caller bypassed that resolution. We throw rather than mint a malformed
|
|
922
|
+
* `file://` URL (e.g. `file://./chart.png`, whose authority is `.`).
|
|
923
|
+
*/
|
|
924
|
+
declare function buildFileUrl(input: {
|
|
925
|
+
path?: string;
|
|
926
|
+
dataUri?: string;
|
|
927
|
+
}): string;
|
|
928
|
+
/** Deterministic, stable part id for a file announced within one message. */
|
|
929
|
+
declare function deterministicFilePartId(messageId: string, key: string): string;
|
|
930
|
+
declare function deriveFilePart(input: {
|
|
931
|
+
path: string;
|
|
932
|
+
messageId: string;
|
|
933
|
+
workspaceRoot?: string;
|
|
934
|
+
}): {
|
|
935
|
+
id: string;
|
|
936
|
+
key: string;
|
|
937
|
+
filename: string;
|
|
938
|
+
mediaType?: string;
|
|
939
|
+
url: string;
|
|
940
|
+
} | null;
|
|
941
|
+
declare function trackFilePart(state: ExecutionState, args: {
|
|
942
|
+
path?: string;
|
|
943
|
+
dataUri?: string;
|
|
944
|
+
filename?: string;
|
|
945
|
+
mediaType?: string;
|
|
946
|
+
changeKind?: "add" | "update" | "delete";
|
|
947
|
+
}): {
|
|
948
|
+
id: string;
|
|
949
|
+
filename?: string;
|
|
950
|
+
mediaType?: string;
|
|
951
|
+
url: string;
|
|
952
|
+
} | null;
|
|
953
|
+
//#endregion
|
|
954
|
+
//#region src/interaction-mcp-server.d.ts
|
|
955
|
+
/**
|
|
956
|
+
* Compatibility adapter for callers that used the old optional `onStop` field.
|
|
957
|
+
* Agent Core owns the MCP server, retry-safe transport, and teardown lifecycle.
|
|
958
|
+
*/
|
|
959
|
+
type InteractionMcpServerConfig$1 = Omit<InteractionMcpServerConfig, "onStop"> & {
|
|
960
|
+
onStop?: InteractionMcpServerConfig["onStop"];
|
|
961
|
+
};
|
|
962
|
+
declare class InteractionMcpServer$1 extends InteractionMcpServer {
|
|
963
|
+
constructor(config: InteractionMcpServerConfig$1);
|
|
964
|
+
}
|
|
965
|
+
//#endregion
|
|
966
|
+
//#region src/interaction-support.d.ts
|
|
967
|
+
declare class McpInteractionSupport {
|
|
968
|
+
/** MCP server name; tool names become `mcp__<name>__<tool>`. */
|
|
969
|
+
private readonly serverName;
|
|
970
|
+
/**
|
|
971
|
+
* The {@link InteractionKind} values this harness wires (e.g.
|
|
972
|
+
* `[InteractionKind.Question, InteractionKind.Plan]`). Passed as the literal
|
|
973
|
+
* `InteractionKind.*` values so the coverage/live-e2e CI gates that grep
|
|
974
|
+
* `adapter.ts` see the declaration.
|
|
975
|
+
*/
|
|
976
|
+
private readonly kinds;
|
|
977
|
+
/** The shared emit → block → respond → fail-closed round-trip. */
|
|
978
|
+
readonly broker: InteractionBroker;
|
|
979
|
+
private activeServer?;
|
|
980
|
+
private terminalPlan?;
|
|
981
|
+
constructor(/** MCP server name; tool names become `mcp__<name>__<tool>`. */
|
|
982
|
+
|
|
983
|
+
serverName: string,
|
|
984
|
+
/**
|
|
985
|
+
* The {@link InteractionKind} values this harness wires (e.g.
|
|
986
|
+
* `[InteractionKind.Question, InteractionKind.Plan]`). Passed as the literal
|
|
987
|
+
* `InteractionKind.*` values so the coverage/live-e2e CI gates that grep
|
|
988
|
+
* `adapter.ts` see the declaration.
|
|
989
|
+
*/
|
|
990
|
+
|
|
991
|
+
kinds: readonly string[]);
|
|
992
|
+
/** The interaction kinds to advertise from `getCapabilities().interactions`. */
|
|
993
|
+
capabilityKinds(): string[];
|
|
994
|
+
/** The active per-execution server (its `url`/`token`), once started. */
|
|
995
|
+
get server(): InteractionMcpServer | undefined;
|
|
996
|
+
/**
|
|
997
|
+
* Start a per-execution server bound to 127.0.0.1 with an ephemeral bearer
|
|
998
|
+
* token, registering only the enabled tools. `emit` is the live event sink;
|
|
999
|
+
* broker-backed tools block on an answer, while plans emit only after their
|
|
1000
|
+
* terminal confirmation. Returns the server for CLI injection.
|
|
1001
|
+
*/
|
|
1002
|
+
start(sessionId: string, binding: InteractionExecutionBinding, emit?: (event: StreamEvent) => void, plan?: {
|
|
1003
|
+
planHost: SdkPlanHost;
|
|
1004
|
+
providerState: () => PlanProviderState;
|
|
1005
|
+
onCommitted?: (submitted: DurablePlan) => void | Promise<void>;
|
|
1006
|
+
}): Promise<InteractionMcpServer>;
|
|
1007
|
+
confirmSubmittedPlan(): Promise<DurablePlan>;
|
|
1008
|
+
withdrawSubmittedPlan(reason: string): Promise<void>;
|
|
1009
|
+
/** Close the request boundary before inspecting or withdrawing its plan. */
|
|
1010
|
+
drainSubmittedPlan(sessionId: string): Promise<void>;
|
|
1011
|
+
/**
|
|
1012
|
+
* Fail-closed every pending interaction for the session, then stop the server.
|
|
1013
|
+
* `failSession` runs FIRST so any request still blocked in the server resolves
|
|
1014
|
+
* (deny) before close, and the whole thing swallows errors — it runs in adapter
|
|
1015
|
+
* `finally` blocks and must never mask the turn's real error.
|
|
1016
|
+
*/
|
|
1017
|
+
stop(sessionId: string): Promise<void>;
|
|
1018
|
+
/**
|
|
1019
|
+
* Route an inbound live `/interactions` response for permission or question.
|
|
1020
|
+
* Plans are durable records and never enter this response channel.
|
|
1021
|
+
*/
|
|
1022
|
+
respond(response: InteractionResponse): boolean;
|
|
1023
|
+
}
|
|
1024
|
+
//#endregion
|
|
1025
|
+
//#region src/mcp-commands.d.ts
|
|
1026
|
+
/** A local MCP server's argv: the `command` array, or `command` then `args`. */
|
|
1027
|
+
declare function localMcpArgv(config: McpConfig): string[];
|
|
1028
|
+
/**
|
|
1029
|
+
* A local MCP server's environment, from `environment` (agent-backend-types)
|
|
1030
|
+
* or `env` (agent-interface): reading one drops the other family's variables.
|
|
1031
|
+
*/
|
|
1032
|
+
declare function localMcpEnv(config: McpConfig): Record<string, string> | undefined;
|
|
1033
|
+
declare const isLocalMcpConfig: (c: McpConfig) => c is LocalMcpConfig;
|
|
1034
|
+
//#endregion
|
|
1035
|
+
//#region src/metering.d.ts
|
|
1036
|
+
type CliTokenUsage = NonNullable<ExecutionState["tokenUsage"]>;
|
|
1037
|
+
declare function readCliTokenUsage(raw: unknown): CliTokenUsage | undefined;
|
|
1038
|
+
declare function recordCliTokenUsage(state: ExecutionState, ...sources: unknown[]): boolean;
|
|
1039
|
+
/**
|
|
1040
|
+
* Adds one usage report to the running total instead of replacing it.
|
|
1041
|
+
*
|
|
1042
|
+
* For a CLI that reports usage PER TURN (pi) rather than once per run,
|
|
1043
|
+
* `recordCliTokenUsage` would leave the execution billed as its final turn
|
|
1044
|
+
* alone. Use this wherever a single execution can produce more than one usage
|
|
1045
|
+
* report; use `recordCliTokenUsage` when the CLI emits one cumulative total.
|
|
1046
|
+
*
|
|
1047
|
+
* Returns true when a usage report was found in `sources` and folded in.
|
|
1048
|
+
*/
|
|
1049
|
+
declare function accumulateCliTokenUsage(state: ExecutionState, ...sources: unknown[]): boolean;
|
|
1050
|
+
declare function parseCliUsageLine(line: string): Record<string, unknown> | undefined;
|
|
1051
|
+
//#endregion
|
|
1052
|
+
//#region src/secret-native-proof.d.ts
|
|
1053
|
+
type BinaryLaunch = Pick<CliSpawnConfig, "command" | "cwd" | "env" | "signal" | "isolatedIdentity"> & {
|
|
1054
|
+
inheritEnv: boolean;
|
|
1055
|
+
};
|
|
1056
|
+
/** Prove an immutable executable, under the launch's own identity and environment. */
|
|
1057
|
+
declare function provenStoreBinary(expected: string, config: BinaryLaunch): Promise<string>;
|
|
1058
|
+
/** A reported version alone cannot establish an immutable executable. */
|
|
1059
|
+
declare function isTrustedStoreBinary(realpath: string): boolean;
|
|
1060
|
+
/** The real file a launch of `command` executes under `pathEnv`. */
|
|
1061
|
+
declare function resolveExecutableRealpath(command: string, pathEnv: string | undefined): string | undefined;
|
|
1062
|
+
type SealedEntry = readonly [relative: string, mode: number, directory: boolean];
|
|
1063
|
+
declare const SEALED_NATIVE_HOME_LAYOUT: {
|
|
1064
|
+
readonly codex: readonly [readonly [".", 1016, true], readonly [".codex", 1016, true], readonly [".agents", 360, true], readonly [".codex/skills", 360, true], readonly [".codex/rules", 360, true], readonly [".codex/config.toml", 288, false], readonly [".codex/AGENTS.md", 288, false], readonly [".codex/AGENTS.override.md", 288, false], readonly [".codex/hooks.json", 288, false]];
|
|
1065
|
+
readonly opencode: readonly [readonly [".", 456, true], readonly [".opencode", 360, true]];
|
|
1066
|
+
};
|
|
1067
|
+
declare function assertSealedNativeHome(home: string, gid: number, layout: readonly SealedEntry[]): void;
|
|
1068
|
+
type RefusalDetail = {
|
|
1069
|
+
path?: string;
|
|
1070
|
+
exitCode?: number | null;
|
|
1071
|
+
} & Partial<Record<"expected" | "actual", string | number | boolean>>;
|
|
1072
|
+
/** Only selected structural facts enter a refusal; payloads and causes never do. */
|
|
1073
|
+
declare function refuseSecretLaunch(reason: string, {
|
|
1074
|
+
path,
|
|
1075
|
+
expected,
|
|
1076
|
+
actual,
|
|
1077
|
+
exitCode
|
|
1078
|
+
}?: RefusalDetail): never;
|
|
1079
|
+
//#endregion
|
|
1080
|
+
//#region src/reasoning-effort.d.ts
|
|
1081
|
+
/** The argv carrying `nativeReasoningControl` for a profile effort, or none. */
|
|
1082
|
+
declare function nativeEffortArgs(harness: HarnessType, effort: ReasoningEffort | undefined): string[];
|
|
1083
|
+
/**
|
|
1084
|
+
* Kimi stays local until #14839: the sandbox ships kimi-cli 1.49.0 as
|
|
1085
|
+
* `kimi-code` (binary `--thinking`/`--no-thinking`) while other paths run
|
|
1086
|
+
* kimi-code 2.x. A model whose name has "thinking" or "reason" always thinks
|
|
1087
|
+
* (kimi-cli `derive_model_capabilities`), so `off` throws there.
|
|
1088
|
+
*/
|
|
1089
|
+
declare function kimiThinkingArgs(level: ReasoningEffort | undefined, modelId?: string | null): string[];
|
|
1090
|
+
//#endregion
|
|
1091
|
+
//#region src/reasoning-parts.d.ts
|
|
1092
|
+
/**
|
|
1093
|
+
* Assigns a stable part id and an append-only delta to a reasoning block
|
|
1094
|
+
* emission, absorbing provider replay/growth patterns:
|
|
1095
|
+
*
|
|
1096
|
+
* - text exactly matches an already-tracked block → `null` (duplicate
|
|
1097
|
+
* delivery, e.g. a final assistant message replaying streamed content —
|
|
1098
|
+
* emit nothing). Byte-identical distinct blocks therefore dedupe to one
|
|
1099
|
+
* part; safer than duplicate-part spam.
|
|
1100
|
+
* - text extends the most recent block → same part id, delta = the suffix
|
|
1101
|
+
* (cumulative re-emission of a growing block).
|
|
1102
|
+
* - otherwise → a new block: fresh part id, delta = the full text, so
|
|
1103
|
+
* consumers can be pure appenders (prev text for a fresh id is empty).
|
|
1104
|
+
*/
|
|
1105
|
+
declare function trackReasoningBlock(state: ExecutionState, blockText: string): {
|
|
1106
|
+
partId: string;
|
|
1107
|
+
text: string;
|
|
1108
|
+
delta: string;
|
|
1109
|
+
isNewBlock: boolean;
|
|
1110
|
+
} | null;
|
|
1111
|
+
//#endregion
|
|
1112
|
+
//#region src/repeated-tool-failure.d.ts
|
|
1113
|
+
/** What a tripped guard reports to the caller. */
|
|
1114
|
+
interface RepeatedToolFailure {
|
|
1115
|
+
/** The tool the model meant to call. */
|
|
1116
|
+
tool: string;
|
|
1117
|
+
/** Why the call was rejected, in the tool's own words. */
|
|
1118
|
+
detail: string;
|
|
1119
|
+
/** How many times in a row this exact rejection came back. */
|
|
1120
|
+
count: number;
|
|
1121
|
+
}
|
|
1122
|
+
interface RepeatedToolFailureGuardOptions {
|
|
1123
|
+
/** Identical failures in a row that trip the guard. At least 1. */
|
|
1124
|
+
limit: number;
|
|
1125
|
+
/**
|
|
1126
|
+
* Tool names a provider substitutes for a model call it could not parse
|
|
1127
|
+
* into any real tool.
|
|
1128
|
+
*
|
|
1129
|
+
* These do not present as failures. OpenCode rewrites an unparseable call to
|
|
1130
|
+
* a tool named `invalid` that carries the parse error as its OUTPUT and
|
|
1131
|
+
* completes. A guard that reads only `status` scores a run of them as
|
|
1132
|
+
* progress and clears its count on every one.
|
|
1133
|
+
*/
|
|
1134
|
+
repairToolNames?: ReadonlySet<string>;
|
|
1135
|
+
}
|
|
1136
|
+
declare function createRepeatedToolFailureGuard(options: RepeatedToolFailureGuardOptions): {
|
|
1137
|
+
/**
|
|
1138
|
+
* Feed one tool part. Returns the trip on the call that reaches the limit,
|
|
1139
|
+
* and `undefined` every other time. A tripped guard stays tripped and
|
|
1140
|
+
* reports once, so a caller can kill the turn without racing the events
|
|
1141
|
+
* still in flight behind it.
|
|
1142
|
+
*/
|
|
1143
|
+
observe(part: Pick<ToolPart, "id" | "tool" | "state">): {
|
|
1144
|
+
count: number;
|
|
1145
|
+
tool: string;
|
|
1146
|
+
detail: string;
|
|
1147
|
+
} | undefined;
|
|
1148
|
+
};
|
|
1149
|
+
//#endregion
|
|
1150
|
+
//#region src/secret-profile-scope.d.ts
|
|
1151
|
+
type ScopeOwner = {
|
|
1152
|
+
readonly proxy?: SecretProfileMcpCredentialProxy;
|
|
1153
|
+
};
|
|
1154
|
+
declare function secretMcpScope(sessionId: string, uid: number | undefined, owner?: ScopeOwner): string;
|
|
1155
|
+
declare function forgetSessionScopes(target: {
|
|
1156
|
+
sessionId: string;
|
|
1157
|
+
} | {
|
|
1158
|
+
owner: ScopeOwner;
|
|
1159
|
+
}): Promise<void>;
|
|
1160
|
+
//#endregion
|
|
1161
|
+
//#region src/stream-parts.d.ts
|
|
1162
|
+
/**
|
|
1163
|
+
* The text, reasoning and tool part emissions every stream-json harness
|
|
1164
|
+
* shares. A provider's event mapper decodes its own wire shape, then calls
|
|
1165
|
+
* these so part ids, buffers, tool timing and processing phases stay one
|
|
1166
|
+
* implementation across claude-code, codex, kimi, amp and factory-droids.
|
|
1167
|
+
*/
|
|
1168
|
+
/**
|
|
1169
|
+
* Records the CLI's native session id on the turn and announces it: the
|
|
1170
|
+
* generic `session.updated` plus the provider-attributed observation the
|
|
1171
|
+
* turn observer keys evidence on.
|
|
1172
|
+
*/
|
|
1173
|
+
declare function sessionObservedEvents(state: ExecutionState, provider: string, sessionId: string): StreamEvent[];
|
|
1174
|
+
/** Correlation fields every emitted part carries. */
|
|
1175
|
+
declare function streamPartBase(state: ExecutionState, partId?: string): {
|
|
1176
|
+
id: string;
|
|
1177
|
+
sessionID: string;
|
|
1178
|
+
messageID: string;
|
|
1179
|
+
};
|
|
1180
|
+
/**
|
|
1181
|
+
* Appends a text delta to the turn's single text part. The first text of a
|
|
1182
|
+
* turn also signals the `generating` phase.
|
|
1183
|
+
*/
|
|
1184
|
+
declare function textDeltaEvents(state: ExecutionState, delta: string): StreamEvent[];
|
|
1185
|
+
/** The whole reply as one text part, for harnesses that do not stream. */
|
|
1186
|
+
declare function finalTextEvent(state: ExecutionState, text: string): StreamEvent;
|
|
1187
|
+
/**
|
|
1188
|
+
* Applies a cumulative text frame (the whole assistant text so far). Only the
|
|
1189
|
+
* suffix past the buffer is emitted; a frame that does not extend the buffer
|
|
1190
|
+
* replaces it and is emitted whole.
|
|
1191
|
+
*/
|
|
1192
|
+
declare function textSnapshotEvents(state: ExecutionState, text: string): StreamEvent[];
|
|
1193
|
+
/**
|
|
1194
|
+
* Records a thinking block under a stable part id (see trackReasoningBlock).
|
|
1195
|
+
* With `signalPhase`, the turn's first block also signals `thinking`.
|
|
1196
|
+
*/
|
|
1197
|
+
declare function reasoningEvents(state: ExecutionState, thinking: string, options: {
|
|
1198
|
+
signalPhase: boolean;
|
|
1199
|
+
}): StreamEvent[];
|
|
1200
|
+
/** Registers a running tool call and emits its running part. */
|
|
1201
|
+
declare function toolStartEvents(state: ExecutionState, call: {
|
|
1202
|
+
id: string;
|
|
1203
|
+
name: string;
|
|
1204
|
+
input: unknown;
|
|
1205
|
+
}): StreamEvent[];
|
|
1206
|
+
/**
|
|
1207
|
+
* Completes a tracked tool call. A successful result emits `afterSuccess`
|
|
1208
|
+
* (file parts the provider detected) and then the `tool-result` phase. A
|
|
1209
|
+
* result for an untracked call is a warning.
|
|
1210
|
+
*/
|
|
1211
|
+
declare function toolResultEvents(state: ExecutionState, result: {
|
|
1212
|
+
id: string;
|
|
1213
|
+
content: unknown;
|
|
1214
|
+
isError: boolean;
|
|
1215
|
+
metadata?: Record<string, unknown>;
|
|
1216
|
+
afterSuccess?: (toolCall: ToolCallState) => StreamEvent[];
|
|
1217
|
+
}): StreamEvent[];
|
|
1218
|
+
//#endregion
|
|
1219
|
+
//#region src/terminal-plan-support.d.ts
|
|
1220
|
+
type TerminalPlanSupportOptions = {
|
|
1221
|
+
planHost: SdkPlanHost;
|
|
1222
|
+
providerState: () => PlanProviderState;
|
|
1223
|
+
emit?: (event: StreamEvent) => void;
|
|
1224
|
+
onCommitted?: (plan: DurablePlan) => void | Promise<void>;
|
|
1225
|
+
};
|
|
1226
|
+
/** One-shot durable plan submission for a single provider turn. */
|
|
1227
|
+
declare class TerminalPlanSupport {
|
|
1228
|
+
private readonly options;
|
|
1229
|
+
private committed?;
|
|
1230
|
+
private submittedBody?;
|
|
1231
|
+
private inFlight?;
|
|
1232
|
+
private confirmInFlight?;
|
|
1233
|
+
private confirmed;
|
|
1234
|
+
constructor(options: TerminalPlanSupportOptions);
|
|
1235
|
+
get plan(): DurablePlan | undefined;
|
|
1236
|
+
/** Wait for a submission already accepted by this turn before failure cleanup. */
|
|
1237
|
+
settleSubmission(): Promise<void>;
|
|
1238
|
+
submit(body: string, sourceToolCallId: string): Promise<DurablePlan>;
|
|
1239
|
+
confirm(): Promise<DurablePlan>;
|
|
1240
|
+
withdraw(reason: string): Promise<void>;
|
|
1241
|
+
}
|
|
1242
|
+
//#endregion
|
|
1243
|
+
//#region src/writable-home.d.ts
|
|
1244
|
+
/** HOME and the XDG base directories a CLI resolves under it. */
|
|
1245
|
+
declare function homeXdgEnv(home: string): {
|
|
1246
|
+
HOME: string;
|
|
1247
|
+
XDG_CONFIG_HOME: string;
|
|
1248
|
+
XDG_CACHE_HOME: string;
|
|
1249
|
+
XDG_DATA_HOME: string;
|
|
1250
|
+
XDG_STATE_HOME: string;
|
|
1251
|
+
};
|
|
1252
|
+
//#endregion
|
|
1253
|
+
export { deterministicFilePartId as $, SecretProfileMcpCredentialProxy as $t, isTrustedStoreBinary as A, AcpTurn as At, localMcpEnv as B, InteractionToggleKind as Bt, createRepeatedToolFailureGuard as C, AcpBridgeConfig as Ct, NATIVE_SESSION_CONTRACTS$1 as D, AcpNewSessionResult as Dt, nativeEffortArgs as E, AcpInitializeResult as Et, parseCliUsageLine as F, CliProviderLogger as Ft, InteractionMcpServerConfig$1 as G, interactionToggleEnabled as Gt, AskUserBridge as H, ToolCallState as Ht, readCliTokenUsage as I, CliProviderOptions as It, RequestPlanBridge as J, turnInteractionEnabled as Jt, PermissionPromptBridge as K, readEphemeralContext as Kt, recordCliTokenUsage as L, EphemeralContextInput as Lt, refuseSecretLaunch as M, CliExecArgs as Mt, resolveExecutableRealpath as N, CliExecutionInput as Nt, SEALED_NATIVE_HOME_LAYOUT as O, AcpPromptResult as Ot, accumulateCliTokenUsage as P, CliProviderConfig as Pt, deriveFilePart as Q, SECRET_REFERENCE_PREFIX as Qt, isLocalMcpConfig as R, ExecutionState as Rt, RepeatedToolFailureGuardOptions as S, ACP_PROTOCOL_VERSION as St, kimiThinkingArgs as T, AcpInitializeParams as Tt, DEFAULT_INTERACTION_MCP_SERVER_NAME as U, TurnEndReason as Ut, McpInteractionSupport as V, PerTurnInteractionInput as Vt, InteractionMcpServer$1 as W, enabledInteractionKinds as Wt, interactionMcpToolName as X, withTurnInteractions as Xt, brokerInteractionTools$1 as Y, withEphemeralContext as Yt, buildFileUrl as Z, SECRET_REFERENCE as Zt, toolResultEvents as _, createExecutionState as _t, PERMISSION_DECISION_TIMEOUT_MS as a, requireRecord as an, MANAGED_QUOTE_VERSION_HEADER as at, secretMcpScope as b, PreparedCliLaunch as bt, homeXdgEnv as c, servableMcpServer as cn, jsonEventParser as ct, finalTextEvent as d, AcpBridgeSpawn as dn, SessionRehydrationError as dt, SecretProfileMcpServer as en, inferMediaType as et, reasoningEvents as f, AcpProcessSpec as fn, rejectNotLaunched as ft, textSnapshotEvents as g, runtimeSecretsOverlay as gt, textDeltaEvents as h, CliProviderAdapterBase as ht, InteractionHttpBridge as i, joinQueue as in, EXECUTION_TRACE_HEADER as it, provenStoreBinary as j, acpContentText as jt, assertSealedNativeHome as k, AcpSessionUpdateParams as kt, TerminalPlanSupport as l, servableStdioServer as ln, plaintextResponseParser as lt, streamPartBase as m, AcpProviderAdapterBase as mt, HarnessId$1 as n, isLoopbackEndpoint as nn, EXECUTION_CORRELATION_HEADERS as nt, WorkspacePlanApplication$1 as o, resolveReferences as on, executionCorrelationHeaders as ot, sessionObservedEvents as p, spawnAcpBridge as pn, wasNeverLaunched as pt, RequestPermissionBridge as q, turnEndReason as qt, InteractionBroker$1 as r, isPlainRecord as rn, EXECUTION_ID_HEADER as rt, codexDeveloperInstructionArgs as s, secretSessionTurnQueue as sn, PlaintextResponse as st, CODEX_DISABLED_FEATURE_ARGS as t, assertSealedNativeSearchPath as tn, trackFilePart as tt, TerminalPlanSupportOptions as u, untilSettledOrAborted as un, InvalidAttachmentError as ut, toolStartEvents as v, CliTurnProcess as vt, trackReasoningBlock as w, AcpContentBlock as wt, RepeatedToolFailure as x, ACP_MIN_PROTOCOL_VERSION as xt, forgetSessionScopes as y, CliTurnSpawn as yt, localMcpArgv as z, InteractionToggleConfig as zt };
|
|
1254
|
+
//# sourceMappingURL=index-BpO3fvbf.d.mts.map
|