@odla-ai/harness 0.1.0
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 +178 -0
- package/dist/chunk-ATKV6VTU.js +168 -0
- package/dist/chunk-ATKV6VTU.js.map +1 -0
- package/dist/chunk-GE6CCN7W.js +93 -0
- package/dist/chunk-GE6CCN7W.js.map +1 -0
- package/dist/chunk-GMVZ4LZH.js +1769 -0
- package/dist/chunk-GMVZ4LZH.js.map +1 -0
- package/dist/chunk-PHXQH4YM.js +550 -0
- package/dist/chunk-PHXQH4YM.js.map +1 -0
- package/dist/chunk-PTXZVYD4.js +81 -0
- package/dist/chunk-PTXZVYD4.js.map +1 -0
- package/dist/chunk-QTUEF2HZ.js +9 -0
- package/dist/chunk-QTUEF2HZ.js.map +1 -0
- package/dist/cli.cjs +795 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +98 -0
- package/dist/cli.js.map +1 -0
- package/dist/code-runtime-cli.cjs +2341 -0
- package/dist/code-runtime-cli.cjs.map +1 -0
- package/dist/code-runtime-cli.d.cts +1 -0
- package/dist/code-runtime-cli.d.ts +1 -0
- package/dist/code-runtime-cli.js +133 -0
- package/dist/code-runtime-cli.js.map +1 -0
- package/dist/index.cjs +228 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +44 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/node.cjs +2580 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +544 -0
- package/dist/node.d.ts +544 -0
- package/dist/node.js +71 -0
- package/dist/node.js.map +1 -0
- package/dist/testing.cjs +106 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +25 -0
- package/dist/testing.d.ts +25 -0
- package/dist/testing.js +79 -0
- package/dist/testing.js.map +1 -0
- package/dist/types-D12vK3K9.d.cts +249 -0
- package/dist/types-D12vK3K9.d.ts +249 -0
- package/package.json +84 -0
package/dist/node.d.cts
ADDED
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
import { r as HarnessTaskSpec, g as HarnessAgentOutput, f as HarnessAgentInput, H as HarnessControlPlane, u as HarnessToolBroker, a as HarnessLease, d as HarnessInferenceRequest, e as HarnessInferenceResponse, i as CodeSessionEventData, w as HarnessToolRequest, v as HarnessToolName } from './types-D12vK3K9.cjs';
|
|
2
|
+
import { CodePortableCheckpoint, CodeSourceFile, CodeVerificationReceipt, CodeCheckpointState } from '@odla-ai/camel/code';
|
|
3
|
+
import { PolicyOutcome } from '@odla-ai/camel/policy';
|
|
4
|
+
import '@odla-ai/ai';
|
|
5
|
+
|
|
6
|
+
/** Supported command-line container engines for isolated harness attempts. */
|
|
7
|
+
type ContainerEngine = "container" | "podman" | "docker";
|
|
8
|
+
/** Host facts and executable probe used while selecting a safe container engine. */
|
|
9
|
+
interface ContainerEngineSelectionOptions {
|
|
10
|
+
platform?: NodeJS.Platform;
|
|
11
|
+
arch?: string;
|
|
12
|
+
uid?: number;
|
|
13
|
+
available?: (engine: ContainerEngine) => Promise<boolean>;
|
|
14
|
+
}
|
|
15
|
+
/** Host facts and rootless probe used to verify the selected engine boundary. */
|
|
16
|
+
interface ContainerEngineVerificationOptions {
|
|
17
|
+
platform?: NodeJS.Platform;
|
|
18
|
+
arch?: string;
|
|
19
|
+
uid?: number;
|
|
20
|
+
podmanRootless?: () => Promise<boolean>;
|
|
21
|
+
}
|
|
22
|
+
/** Optional CPU, memory, process, and temporary-filesystem limits for an attempt. */
|
|
23
|
+
interface ContainerLimits {
|
|
24
|
+
cpus?: number;
|
|
25
|
+
memory?: string;
|
|
26
|
+
pids?: number;
|
|
27
|
+
tmpfsBytes?: number;
|
|
28
|
+
}
|
|
29
|
+
/** Container, task, callback, and cancellation settings for one agent attempt. */
|
|
30
|
+
interface ContainerRunOptions {
|
|
31
|
+
engine: ContainerEngine;
|
|
32
|
+
image: string;
|
|
33
|
+
workspaceDir: string;
|
|
34
|
+
workspaceAccess?: "read-write" | "read-only" | "none";
|
|
35
|
+
task: HarnessTaskSpec;
|
|
36
|
+
limits?: ContainerLimits;
|
|
37
|
+
allowUnpinnedImage?: boolean;
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
onMessage(message: HarnessAgentOutput): Promise<HarnessAgentInput | void>;
|
|
40
|
+
onStderr?(text: string): Promise<void> | void;
|
|
41
|
+
}
|
|
42
|
+
/** Terminal container outcome and bounded diagnostic output returned to the runner. */
|
|
43
|
+
interface ContainerRunResult {
|
|
44
|
+
exitCode: number;
|
|
45
|
+
status: "completed" | "failed" | "cancelled";
|
|
46
|
+
result?: unknown;
|
|
47
|
+
stderr: string;
|
|
48
|
+
}
|
|
49
|
+
/** Require an immutable OCI image reference pinned to a SHA-256 digest. */
|
|
50
|
+
declare function assertPinnedImage(image: string): void;
|
|
51
|
+
/** Choose the strongest installed local default without silently selecting a
|
|
52
|
+
* rootful Linux daemon. Apple container is a per-container VM boundary;
|
|
53
|
+
* rootless Podman is the Linux default; Docker remains explicit. */
|
|
54
|
+
declare function selectContainerEngine(requested?: ContainerEngine | "auto", options?: ContainerEngineSelectionOptions): Promise<ContainerEngine>;
|
|
55
|
+
/** Fail closed if the selected engine cannot provide the promised host
|
|
56
|
+
* boundary. This is checked for every attempt so a changed Podman connection
|
|
57
|
+
* cannot silently turn a rootless Linux runner into a rootful one. */
|
|
58
|
+
declare function verifyContainerEngineBoundary(engine: ContainerEngine, options?: ContainerEngineVerificationOptions): Promise<void>;
|
|
59
|
+
/** Build hardened, networkless engine arguments without starting the container. */
|
|
60
|
+
declare function buildContainerRunArgs(options: Omit<ContainerRunOptions, "onMessage" | "onStderr" | "signal">): string[];
|
|
61
|
+
/** Execute one JSONL agent inside a hardened Apple container, Podman, or Docker
|
|
62
|
+
* boundary. The
|
|
63
|
+
* container has no network and receives no credentials; inference requests are
|
|
64
|
+
* bridged over stdin/stdout to the trusted runner process. */
|
|
65
|
+
declare function runContainerAttempt(options: ContainerRunOptions): Promise<ContainerRunResult>;
|
|
66
|
+
|
|
67
|
+
/** Disposable, filtered materialization of one committed Git tree. */
|
|
68
|
+
interface MaterializedGitTree {
|
|
69
|
+
root: string;
|
|
70
|
+
sourceDir: string;
|
|
71
|
+
fileCount: number;
|
|
72
|
+
byteCount: number;
|
|
73
|
+
cleanup(): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
/** Materialize ordinary files from an exact commit without copying secrets,
|
|
76
|
+
* symlinks, ignored local files, or Git metadata. */
|
|
77
|
+
declare function materializeGitTree(source: string, commitSha: string, options?: Pick<StageWorkspaceOptions, "maxFiles" | "maxBytes" | "tempRoot">): Promise<MaterializedGitTree>;
|
|
78
|
+
|
|
79
|
+
/** File, byte, and temporary-directory limits applied while staging a workspace. */
|
|
80
|
+
interface StageWorkspaceOptions {
|
|
81
|
+
maxFiles?: number;
|
|
82
|
+
maxBytes?: number;
|
|
83
|
+
tempRoot?: string;
|
|
84
|
+
/** Stage tracked files plus non-ignored untracked files from a Git checkout. */
|
|
85
|
+
gitTrackedAndUnignored?: boolean;
|
|
86
|
+
}
|
|
87
|
+
/** Disposable baseline and mutable workspace copy used to generate a bounded patch. */
|
|
88
|
+
interface StagedWorkspace {
|
|
89
|
+
root: string;
|
|
90
|
+
baselineDir: string;
|
|
91
|
+
workspaceDir: string;
|
|
92
|
+
fileCount: number;
|
|
93
|
+
byteCount: number;
|
|
94
|
+
patch(maxBytes: number): Promise<string>;
|
|
95
|
+
cleanup(): Promise<void>;
|
|
96
|
+
}
|
|
97
|
+
/** Copy a bounded, secret-filtered workspace twice: one immutable baseline and
|
|
98
|
+
* one disposable directory mounted into the container. The developer checkout
|
|
99
|
+
* itself is never mounted. */
|
|
100
|
+
declare function stageWorkspace(source: string, options?: StageWorkspaceOptions): Promise<StagedWorkspace>;
|
|
101
|
+
/** Create a disposable workspace whose diff base and initial editable tree
|
|
102
|
+
* intentionally come from different already-filtered sources. */
|
|
103
|
+
declare function stageWorkspacePair(baselineSource: string, workspaceSource: string, options?: StageWorkspaceOptions): Promise<StagedWorkspace>;
|
|
104
|
+
/** Convert a path-like value into a bounded lowercase label safe for runner metadata. */
|
|
105
|
+
declare function safeWorkspaceLabel(value: string): string;
|
|
106
|
+
|
|
107
|
+
/** Digest every regular path and byte in a staged workspace under fixed bounds. */
|
|
108
|
+
declare function digestStagedWorkspace(root: string, limits: {
|
|
109
|
+
maxFiles: number;
|
|
110
|
+
maxBytes: number;
|
|
111
|
+
}): Promise<`sha256:${string}`>;
|
|
112
|
+
|
|
113
|
+
/** Control-plane, workspace, isolation, polling, and lifecycle settings for a runner. */
|
|
114
|
+
interface HarnessRunnerOptions {
|
|
115
|
+
control: HarnessControlPlane;
|
|
116
|
+
workspaces: Readonly<Record<string, string>>;
|
|
117
|
+
engine: ContainerEngine;
|
|
118
|
+
image: string;
|
|
119
|
+
limits?: ContainerLimits;
|
|
120
|
+
heartbeatMs?: number;
|
|
121
|
+
pollMs?: number;
|
|
122
|
+
once?: boolean;
|
|
123
|
+
preserveWorkspace?: boolean;
|
|
124
|
+
allowUnpinnedImage?: boolean;
|
|
125
|
+
workspaceAccess?: "read-write" | "read-only" | "none";
|
|
126
|
+
signal?: AbortSignal;
|
|
127
|
+
log?: (message: string) => void;
|
|
128
|
+
toolBroker?: HarnessToolBroker;
|
|
129
|
+
}
|
|
130
|
+
/** Execute one leased task. The registered workspace is copied before the
|
|
131
|
+
* container starts; neither the checkout nor the runner credential is mounted. */
|
|
132
|
+
declare function runLeasedAttempt(lease: HarnessLease, options: HarnessRunnerOptions): Promise<void>;
|
|
133
|
+
/** One runner executes one attempt at a time. Concurrency comes from multiple
|
|
134
|
+
* independently credentialed runner processes. */
|
|
135
|
+
declare function runHarnessRunner(options: HarnessRunnerOptions): Promise<void>;
|
|
136
|
+
|
|
137
|
+
/** Stable HTTP and transport error returned by the remote Code control plane. */
|
|
138
|
+
declare class CodeRuntimeControlError extends Error {
|
|
139
|
+
readonly status: number;
|
|
140
|
+
readonly code: string;
|
|
141
|
+
readonly name = "CodeRuntimeControlError";
|
|
142
|
+
constructor(message: string, status: number, code?: string);
|
|
143
|
+
}
|
|
144
|
+
/** Endpoint, host credential, timeout, and cancellation settings for a Code runtime client. */
|
|
145
|
+
interface CodeRuntimeClientOptions {
|
|
146
|
+
endpoint: string;
|
|
147
|
+
token: string;
|
|
148
|
+
fetch?: typeof fetch;
|
|
149
|
+
/** Timeout for short control-plane operations such as heartbeats and events. */
|
|
150
|
+
requestTimeoutMs?: number;
|
|
151
|
+
/** Timeout for provider-backed inference and review calls. */
|
|
152
|
+
modelRequestTimeoutMs?: number;
|
|
153
|
+
signal?: AbortSignal;
|
|
154
|
+
}
|
|
155
|
+
/** Create the credentialed, outbound-only Code host control client. */
|
|
156
|
+
declare function createCodeRuntimeControlClient(options: CodeRuntimeClientOptions): CodeRuntimeAgentControlPlane;
|
|
157
|
+
|
|
158
|
+
/** Version of the outbound Code host heartbeat contract. */
|
|
159
|
+
declare const CODE_RUNTIME_PROTOCOL_VERSION: 1;
|
|
160
|
+
/** Frozen, secret-filtered view of the checkout from which a terminal connected. */
|
|
161
|
+
interface CodeLocalSourceDescriptor {
|
|
162
|
+
kind: "local_checkout";
|
|
163
|
+
repository: string;
|
|
164
|
+
headCommitSha: string;
|
|
165
|
+
trustedBaseDigest: `sha256:${string}`;
|
|
166
|
+
developerPatchDigest: `sha256:${string}`;
|
|
167
|
+
snapshotDigest: `sha256:${string}`;
|
|
168
|
+
modified: boolean;
|
|
169
|
+
fileCount: number;
|
|
170
|
+
byteCount: number;
|
|
171
|
+
capturedAt: number;
|
|
172
|
+
}
|
|
173
|
+
/** Host resources and supported isolation engines advertised on heartbeat. */
|
|
174
|
+
interface CodeRuntimeCapabilities {
|
|
175
|
+
protocolVersion: typeof CODE_RUNTIME_PROTOCOL_VERSION;
|
|
176
|
+
platform: "macos" | "linux";
|
|
177
|
+
arch: string;
|
|
178
|
+
engines: Array<"container" | "podman" | "docker">;
|
|
179
|
+
cpuCount: number;
|
|
180
|
+
memoryBytes: number;
|
|
181
|
+
source?: CodeLocalSourceDescriptor;
|
|
182
|
+
images?: {
|
|
183
|
+
ready: boolean;
|
|
184
|
+
pi: string;
|
|
185
|
+
recipes: Array<{
|
|
186
|
+
id: string;
|
|
187
|
+
image: string;
|
|
188
|
+
}>;
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/** A generation-fenced assignment of one app environment to one Code host. */
|
|
192
|
+
interface CodeRuntimeBinding {
|
|
193
|
+
bindingId: string;
|
|
194
|
+
appId: string;
|
|
195
|
+
env: "dev" | "prod";
|
|
196
|
+
offerId: string;
|
|
197
|
+
hostId: string;
|
|
198
|
+
generation: number;
|
|
199
|
+
revokedAt: number | null;
|
|
200
|
+
}
|
|
201
|
+
/** Authoritative heartbeat response for a live host and its pending work. */
|
|
202
|
+
interface CodeRuntimeSnapshot {
|
|
203
|
+
host: {
|
|
204
|
+
hostId: string;
|
|
205
|
+
runtimeVersion: string;
|
|
206
|
+
lastSeenAt: number;
|
|
207
|
+
revokedAt: null;
|
|
208
|
+
};
|
|
209
|
+
bindings: CodeRuntimeBinding[];
|
|
210
|
+
commands: CodeRuntimeCommand[];
|
|
211
|
+
}
|
|
212
|
+
/** Commands accepted by the outbound Code runtime. */
|
|
213
|
+
type CodeRuntimeCommandKind = "start" | "prompt" | "checkpoint_stop" | "resume";
|
|
214
|
+
/** One sequenced command fenced to an exact host-binding generation. */
|
|
215
|
+
interface CodeRuntimeCommand {
|
|
216
|
+
commandId: string;
|
|
217
|
+
instanceId: string;
|
|
218
|
+
sessionId: string;
|
|
219
|
+
appId: string;
|
|
220
|
+
env: "dev" | "prod";
|
|
221
|
+
bindingId: string;
|
|
222
|
+
hostId: string;
|
|
223
|
+
bindingGeneration: number;
|
|
224
|
+
sequence: number;
|
|
225
|
+
kind: CodeRuntimeCommandKind;
|
|
226
|
+
payload: Record<string, unknown>;
|
|
227
|
+
createdAt: number;
|
|
228
|
+
}
|
|
229
|
+
/** Terminal or continuing state acknowledged for a runtime command. */
|
|
230
|
+
interface CodeRuntimeCommandResult {
|
|
231
|
+
status: "running" | "checkpointed" | "failed";
|
|
232
|
+
checkpoint?: CodePortableCheckpoint;
|
|
233
|
+
message?: string;
|
|
234
|
+
}
|
|
235
|
+
/** Minimal control-plane operations used by an outbound Code host. */
|
|
236
|
+
interface CodeRuntimeControlPlane {
|
|
237
|
+
heartbeat(runtimeVersion: string, capabilities: CodeRuntimeCapabilities): Promise<CodeRuntimeSnapshot>;
|
|
238
|
+
acknowledge(commandId: string, result: CodeRuntimeCommandResult): Promise<void>;
|
|
239
|
+
}
|
|
240
|
+
/** Credentialless agent operations brokered over the same outbound host identity. */
|
|
241
|
+
interface CodeRuntimeAgentControlPlane extends CodeRuntimeControlPlane {
|
|
242
|
+
source(sessionId: string): Promise<CodeRuntimeSourceSnapshot>;
|
|
243
|
+
infer(sessionId: string, request: HarnessInferenceRequest): Promise<HarnessInferenceResponse>;
|
|
244
|
+
review(sessionId: string, request: CodeRuntimeReviewRequest): Promise<CodeRuntimeReviewResponse>;
|
|
245
|
+
submitCandidate(sessionId: string, checkpointId: string, verification: CodeVerificationReceipt): Promise<CodeRuntimeCandidateResponse>;
|
|
246
|
+
appendSessionEvent(sessionId: string, eventId: string, event: CodeSessionEventData): Promise<void>;
|
|
247
|
+
reportSessionFailure(sessionId: string, message: string): Promise<void>;
|
|
248
|
+
}
|
|
249
|
+
/** Untrusted candidate material available only to the independent review route. */
|
|
250
|
+
interface CodeRuntimeReviewRequest {
|
|
251
|
+
patch: string;
|
|
252
|
+
verification: CodeVerificationReceipt;
|
|
253
|
+
}
|
|
254
|
+
/** Closed review result. Only an exact approved verdict can enter a reviewed checkpoint. */
|
|
255
|
+
interface CodeRuntimeReviewResponse {
|
|
256
|
+
verdict: "approved" | "rejected";
|
|
257
|
+
reviewDigest: `sha256:${string}`;
|
|
258
|
+
provider: string;
|
|
259
|
+
model: string;
|
|
260
|
+
policyVersion: number;
|
|
261
|
+
}
|
|
262
|
+
/** Owner-private candidate admitted after checkpoint, verifier, and review evidence agree. */
|
|
263
|
+
interface CodeRuntimeCandidateResponse {
|
|
264
|
+
candidateId: string;
|
|
265
|
+
status: "submitted" | "approved" | "published" | "failed";
|
|
266
|
+
}
|
|
267
|
+
/** Exact, attestation-matched GitHub source returned to one assigned runtime. */
|
|
268
|
+
interface CodeRuntimeSourceSnapshot {
|
|
269
|
+
repository: string;
|
|
270
|
+
commitSha: string;
|
|
271
|
+
treeDigest: `sha256:${string}`;
|
|
272
|
+
files: CodeSourceFile[];
|
|
273
|
+
references?: Array<{
|
|
274
|
+
alias: string;
|
|
275
|
+
repository: string;
|
|
276
|
+
commitSha: string;
|
|
277
|
+
treeDigest: `sha256:${string}`;
|
|
278
|
+
files: CodeSourceFile[];
|
|
279
|
+
}>;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** Presence-loop settings and an optional callback for each heartbeat snapshot. */
|
|
283
|
+
interface CodeRuntimeLoopOptions {
|
|
284
|
+
control: CodeRuntimeControlPlane;
|
|
285
|
+
runtimeVersion: string;
|
|
286
|
+
capabilities: CodeRuntimeCapabilities;
|
|
287
|
+
heartbeatMs?: number;
|
|
288
|
+
once?: boolean;
|
|
289
|
+
signal?: AbortSignal;
|
|
290
|
+
onSnapshot?(snapshot: CodeRuntimeSnapshot): Promise<void> | void;
|
|
291
|
+
onRetry?(error: unknown, delayMs: number): Promise<void> | void;
|
|
292
|
+
}
|
|
293
|
+
/** Maintain presence without opening a listener or accepting inbound traffic. */
|
|
294
|
+
declare function runCodeRuntimeHeartbeatLoop(options: CodeRuntimeLoopOptions): Promise<void>;
|
|
295
|
+
/** Executes one fenced runtime command and returns its acknowledgement payload. */
|
|
296
|
+
interface CodeRuntimeCommandEngine {
|
|
297
|
+
execute(command: CodeRuntimeCommand): Promise<CodeRuntimeCommandResult>;
|
|
298
|
+
acknowledged?(command: CodeRuntimeCommand, result: CodeRuntimeCommandResult): Promise<void> | void;
|
|
299
|
+
}
|
|
300
|
+
/** Executes each command id at most once in-process and safely retries only its
|
|
301
|
+
* acknowledgement after a transient control-plane failure. */
|
|
302
|
+
declare class CodeRuntimeReconciler {
|
|
303
|
+
private readonly control;
|
|
304
|
+
private readonly engine;
|
|
305
|
+
private readonly results;
|
|
306
|
+
constructor(control: CodeRuntimeControlPlane, engine: CodeRuntimeCommandEngine);
|
|
307
|
+
reconcile(snapshot: CodeRuntimeSnapshot): Promise<void>;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
interface FrozenCodeLocalSource {
|
|
311
|
+
descriptor: CodeLocalSourceDescriptor;
|
|
312
|
+
trustedBaseDir: string;
|
|
313
|
+
sourceDir: string;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** One control-owned regular file expected from a clean build recipe. */
|
|
317
|
+
interface CodeExpectedArtifact {
|
|
318
|
+
id: string;
|
|
319
|
+
path: string;
|
|
320
|
+
maximumBytes: number;
|
|
321
|
+
}
|
|
322
|
+
/** Fixed, app-registered command executed in a separate digest-pinned build container. */
|
|
323
|
+
interface CodeBuildRecipe {
|
|
324
|
+
id: string;
|
|
325
|
+
image: string;
|
|
326
|
+
command: readonly string[];
|
|
327
|
+
timeoutMs: number;
|
|
328
|
+
maxOutputBytes: number;
|
|
329
|
+
cpus?: number;
|
|
330
|
+
memory?: string;
|
|
331
|
+
pids?: number;
|
|
332
|
+
tmpfsBytes?: number;
|
|
333
|
+
expectedArtifacts?: readonly CodeExpectedArtifact[];
|
|
334
|
+
}
|
|
335
|
+
/** Bounded terminal result from an isolated recipe container. */
|
|
336
|
+
interface CodeRecipeResult {
|
|
337
|
+
exitCode: number;
|
|
338
|
+
stdout: string;
|
|
339
|
+
stderr: string;
|
|
340
|
+
durationMs: number;
|
|
341
|
+
outputLimitExceeded: boolean;
|
|
342
|
+
timedOut: boolean;
|
|
343
|
+
}
|
|
344
|
+
/** Injectable recipe boundary used by the policy broker and its tests. */
|
|
345
|
+
interface CodeRecipeExecutor {
|
|
346
|
+
run(input: {
|
|
347
|
+
workspaceDir: string;
|
|
348
|
+
recipe: CodeBuildRecipe;
|
|
349
|
+
signal?: AbortSignal;
|
|
350
|
+
}): Promise<CodeRecipeResult>;
|
|
351
|
+
}
|
|
352
|
+
/** Auditable CaMeL decision emitted before any requested tool effect. */
|
|
353
|
+
interface CodeToolDecision {
|
|
354
|
+
lease: HarnessLease;
|
|
355
|
+
request: HarnessToolRequest;
|
|
356
|
+
tool: HarnessToolName;
|
|
357
|
+
policy: PolicyOutcome;
|
|
358
|
+
approvalConsumed: boolean;
|
|
359
|
+
}
|
|
360
|
+
/** Bounds, recipes, authorization mode, and decision hooks for one trusted broker. */
|
|
361
|
+
interface CodeToolBrokerOptions {
|
|
362
|
+
recipes: readonly CodeBuildRecipe[];
|
|
363
|
+
recipeExecutor: CodeRecipeExecutor;
|
|
364
|
+
recipeAuthorization: "registered_recipe" | "exact_approval";
|
|
365
|
+
readerId: string;
|
|
366
|
+
maxReadBytes?: number;
|
|
367
|
+
maxReadLines?: number;
|
|
368
|
+
maxPatchBytes?: number;
|
|
369
|
+
maxRecipeWorkspaceFiles?: number;
|
|
370
|
+
maxRecipeWorkspaceBytes?: number;
|
|
371
|
+
/** Paths Pi may read but may never modify. Prefixes are relative directory names. */
|
|
372
|
+
readOnlyPrefixes?: readonly string[];
|
|
373
|
+
consumeApproval?(input: CodeToolDecision & {
|
|
374
|
+
actionDigest: string;
|
|
375
|
+
}): Promise<boolean>;
|
|
376
|
+
onDecision?(decision: CodeToolDecision): Promise<void> | void;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** Trusted control plane, isolation engine, Pi image, recipes, and resource policy for a Code runtime. */
|
|
380
|
+
interface CodePiRuntimeEngineOptions {
|
|
381
|
+
control: CodeRuntimeAgentControlPlane;
|
|
382
|
+
engine: ContainerEngine;
|
|
383
|
+
image: string;
|
|
384
|
+
/** The Code CLI may build its bundled, content-addressed Pi adapter locally. */
|
|
385
|
+
imageAuthorization?: "digest" | "cli_embedded";
|
|
386
|
+
recipes: readonly CodeBuildRecipe[];
|
|
387
|
+
recipeAuthorization?: "registered_recipe" | "exact_approval";
|
|
388
|
+
limits?: ContainerLimits;
|
|
389
|
+
runAttempt?: (options: ContainerRunOptions) => Promise<ContainerRunResult>;
|
|
390
|
+
recipeExecutor?: CodeRecipeExecutor;
|
|
391
|
+
/** Owner-visible and terminal-visible bounded runtime failures. */
|
|
392
|
+
onDiagnostic?: (message: string) => void;
|
|
393
|
+
/** Frozen checkout snapshot owned by the foreground terminal process. */
|
|
394
|
+
localSource?: FrozenCodeLocalSource;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/** Execute fenced Code commands with real Pi in a credentialless, networkless container. */
|
|
398
|
+
declare class CodePiRuntimeEngine implements CodeRuntimeCommandEngine {
|
|
399
|
+
#private;
|
|
400
|
+
private readonly options;
|
|
401
|
+
constructor(options: CodePiRuntimeEngineOptions);
|
|
402
|
+
execute(command: CodeRuntimeCommand): Promise<CodeRuntimeCommandResult>;
|
|
403
|
+
acknowledged(command: CodeRuntimeCommand, result: CodeRuntimeCommandResult): Promise<void>;
|
|
404
|
+
close(): Promise<void>;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/** Inputs for capturing one running staged workspace as a portable checkpoint. */
|
|
408
|
+
interface CreateCodeWorkspaceCheckpointInput {
|
|
409
|
+
workspace: StagedWorkspace;
|
|
410
|
+
baseCommitSha: string;
|
|
411
|
+
state: CodeCheckpointState;
|
|
412
|
+
maximumPatchBytes?: number;
|
|
413
|
+
}
|
|
414
|
+
/** Inputs for reconstructing a checkpoint on any compatible bound host. */
|
|
415
|
+
interface RestoreCodeWorkspaceCheckpointInput {
|
|
416
|
+
trustedBaseDir: string;
|
|
417
|
+
trustedBaseCommitSha: string;
|
|
418
|
+
checkpoint: unknown;
|
|
419
|
+
stage?: StageWorkspaceOptions;
|
|
420
|
+
}
|
|
421
|
+
/** Fresh staged workspace plus its verified portable checkpoint state. */
|
|
422
|
+
interface RestoredCodeWorkspaceCheckpoint {
|
|
423
|
+
workspace: StagedWorkspace;
|
|
424
|
+
checkpoint: CodePortableCheckpoint;
|
|
425
|
+
}
|
|
426
|
+
/** Capture a bounded, text-only candidate patch and closed resume state. */
|
|
427
|
+
declare function createCodeWorkspaceCheckpoint(input: CreateCodeWorkspaceCheckpointInput): Promise<CodePortableCheckpoint>;
|
|
428
|
+
/** Reconstruct a verified candidate from a fresh copy of its exact trusted base. */
|
|
429
|
+
declare function restoreCodeWorkspaceCheckpoint(input: RestoreCodeWorkspaceCheckpointInput): Promise<RestoredCodeWorkspaceCheckpoint>;
|
|
430
|
+
/** Return whether the exact effect already completed; reject an ID rebound to another action. */
|
|
431
|
+
declare function isCheckpointEffectCompleted(checkpoint: CodePortableCheckpoint, effectId: string, actionDigest: `sha256:${string}`): boolean;
|
|
432
|
+
|
|
433
|
+
/** Trusted session state, verification policy, and review callback used to stop at a portable checkpoint. */
|
|
434
|
+
interface PrepareRuntimeCheckpointInput {
|
|
435
|
+
sessionId: string;
|
|
436
|
+
role: "coding" | "review";
|
|
437
|
+
workspace: StagedWorkspace;
|
|
438
|
+
baseCommitSha: string;
|
|
439
|
+
trustedBaseDigest: `sha256:${string}`;
|
|
440
|
+
planningInputDigest: `sha256:${string}`;
|
|
441
|
+
conversationRefs: readonly string[];
|
|
442
|
+
fallbackPolicyDigest: `sha256:${string}`;
|
|
443
|
+
recipes: readonly CodeBuildRecipe[];
|
|
444
|
+
recipeExecutor: CodeRecipeExecutor;
|
|
445
|
+
review(patch: string, verification: CodeVerificationReceipt): Promise<CodeRuntimeReviewResponse>;
|
|
446
|
+
}
|
|
447
|
+
/** Portable checkpoint plus the optional clean-build and independent-review evidence that produced it. */
|
|
448
|
+
interface PreparedRuntimeCheckpoint {
|
|
449
|
+
checkpoint: Awaited<ReturnType<typeof createCodeWorkspaceCheckpoint>>;
|
|
450
|
+
verification: CodeVerificationReceipt | null;
|
|
451
|
+
review: CodeRuntimeReviewResponse | null;
|
|
452
|
+
note: string;
|
|
453
|
+
}
|
|
454
|
+
/** Verify and independently review a stopped workspace without exposing raw build output to planning. */
|
|
455
|
+
declare function prepareRuntimeCheckpoint(input: PrepareRuntimeCheckpointInput): Promise<PreparedRuntimeCheckpoint>;
|
|
456
|
+
|
|
457
|
+
/** Active isolated workspace state required to prepare and publish a Code checkpoint candidate. */
|
|
458
|
+
interface RuntimeCheckpointSession {
|
|
459
|
+
workspace: StagedWorkspace;
|
|
460
|
+
done: Promise<ContainerRunResult | null>;
|
|
461
|
+
abort: AbortController;
|
|
462
|
+
baseCommitSha: string;
|
|
463
|
+
trustedBaseDigest: `sha256:${string}`;
|
|
464
|
+
planningInputDigest: `sha256:${string}`;
|
|
465
|
+
conversationRefs: string[];
|
|
466
|
+
role: "coding" | "review";
|
|
467
|
+
}
|
|
468
|
+
interface Options {
|
|
469
|
+
control: CodeRuntimeAgentControlPlane;
|
|
470
|
+
recipes: readonly CodeBuildRecipe[];
|
|
471
|
+
recipeExecutor: CodeRecipeExecutor;
|
|
472
|
+
fallbackPolicyDigest: `sha256:${string}`;
|
|
473
|
+
event(command: CodeRuntimeCommand, event: CodeSessionEventData, refs: string[]): Promise<void>;
|
|
474
|
+
}
|
|
475
|
+
/** Own checkpoint evidence and candidate admission retries outside the Pi process lifecycle. */
|
|
476
|
+
declare class CodeRuntimeCheckpointManager {
|
|
477
|
+
#private;
|
|
478
|
+
private readonly options;
|
|
479
|
+
constructor(options: Options);
|
|
480
|
+
prepare(command: CodeRuntimeCommand, active: RuntimeCheckpointSession): Promise<CodeRuntimeCommandResult>;
|
|
481
|
+
acknowledged(command: CodeRuntimeCommand, result: CodeRuntimeCommandResult): Promise<boolean>;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/** Disposable local source tree materialized from an exact, validated Code snapshot. */
|
|
485
|
+
interface MaterializedCodeSource {
|
|
486
|
+
sourceDir: string;
|
|
487
|
+
cleanup(): Promise<void>;
|
|
488
|
+
}
|
|
489
|
+
/** Materialize only ordinary, relative snapshot files into a disposable source tree. */
|
|
490
|
+
declare function materializeCodeRuntimeSource(snapshot: CodeRuntimeSourceSnapshot, tempRoot?: string): Promise<MaterializedCodeSource>;
|
|
491
|
+
/** Add server-resolved reference trees to both sides of a staged local
|
|
492
|
+
* checkout. They remain outside the candidate diff and the tool broker denies
|
|
493
|
+
* every write beneath the reference root. */
|
|
494
|
+
declare function attachCodeRuntimeReferences(workspace: StagedWorkspace, references: NonNullable<CodeRuntimeSourceSnapshot["references"]>): Promise<void>;
|
|
495
|
+
|
|
496
|
+
/** Create the trusted CaMeL boundary for all Pi filesystem and build effects. */
|
|
497
|
+
declare function createCodeToolBroker(options: CodeToolBrokerOptions): HarnessToolBroker;
|
|
498
|
+
|
|
499
|
+
/** Build a trusted, fixed command for an isolated and networkless recipe container. */
|
|
500
|
+
declare function buildRecipeContainerArgs(engine: ContainerEngine, workspaceDir: string, recipe: CodeBuildRecipe, name?: string): string[];
|
|
501
|
+
/** Create a recipe executor that never invokes a shell and never mounts credentials. */
|
|
502
|
+
declare function createContainerRecipeExecutor(engine: ContainerEngine): CodeRecipeExecutor;
|
|
503
|
+
/** Validate immutable recipe identity, digest image, command, and resource bounds. */
|
|
504
|
+
declare function assertCodeBuildRecipe(recipe: CodeBuildRecipe): void;
|
|
505
|
+
|
|
506
|
+
/** Control-owned clean-verification policy for one app environment. */
|
|
507
|
+
interface CodeVerificationPolicy {
|
|
508
|
+
policyId: string;
|
|
509
|
+
recipes: readonly CodeBuildRecipe[];
|
|
510
|
+
testPathPrefixes?: readonly string[];
|
|
511
|
+
testPathSuffixes?: readonly string[];
|
|
512
|
+
maximumChangedTests?: number;
|
|
513
|
+
maximumPatchBytes?: number;
|
|
514
|
+
maximumFiles?: number;
|
|
515
|
+
maximumBytes?: number;
|
|
516
|
+
}
|
|
517
|
+
/** Trusted base, candidate patch, policy, and isolated executor for one clean run. */
|
|
518
|
+
interface VerifyCodeCandidateInput {
|
|
519
|
+
verificationId?: string;
|
|
520
|
+
trustedBaseDir: string;
|
|
521
|
+
trustedBaseCommitSha: string;
|
|
522
|
+
trustedBaseDigest: `sha256:${string}`;
|
|
523
|
+
candidatePatch: string;
|
|
524
|
+
policy: CodeVerificationPolicy;
|
|
525
|
+
recipeExecutor: CodeRecipeExecutor;
|
|
526
|
+
signal?: AbortSignal;
|
|
527
|
+
}
|
|
528
|
+
/** Bounded raw recipe output retained for coding, review, and owner display only. */
|
|
529
|
+
interface CodeVerificationLog {
|
|
530
|
+
recipeId: string;
|
|
531
|
+
stdout: string;
|
|
532
|
+
stderr: string;
|
|
533
|
+
}
|
|
534
|
+
/** Closed receipt plus quarantined evidence that must never be passed to planning. */
|
|
535
|
+
interface CodeVerificationEvidence {
|
|
536
|
+
receipt: CodeVerificationReceipt;
|
|
537
|
+
changedTests: readonly string[];
|
|
538
|
+
logs: readonly CodeVerificationLog[];
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/** Rebuild a candidate from an exact trusted base and emit a prose-free clean-verifier receipt. */
|
|
542
|
+
declare function verifyCodeCandidate(input: VerifyCodeCandidateInput): Promise<CodeVerificationEvidence>;
|
|
543
|
+
|
|
544
|
+
export { CODE_RUNTIME_PROTOCOL_VERSION, type CodeBuildRecipe, type CodeExpectedArtifact, type CodeLocalSourceDescriptor, CodePiRuntimeEngine, type CodePiRuntimeEngineOptions, type CodeRecipeExecutor, type CodeRecipeResult, type CodeRuntimeAgentControlPlane, type CodeRuntimeBinding, type CodeRuntimeCandidateResponse, type CodeRuntimeCapabilities, CodeRuntimeCheckpointManager, type CodeRuntimeClientOptions, type CodeRuntimeCommand, type CodeRuntimeCommandEngine, type CodeRuntimeCommandKind, type CodeRuntimeCommandResult, CodeRuntimeControlError, type CodeRuntimeControlPlane, type CodeRuntimeLoopOptions, CodeRuntimeReconciler, type CodeRuntimeReviewRequest, type CodeRuntimeReviewResponse, type CodeRuntimeSnapshot, type CodeRuntimeSourceSnapshot, type CodeToolBrokerOptions, type CodeToolDecision, type CodeVerificationEvidence, type CodeVerificationLog, type CodeVerificationPolicy, type ContainerEngine, type ContainerEngineSelectionOptions, type ContainerEngineVerificationOptions, type ContainerLimits, type ContainerRunOptions, type ContainerRunResult, type CreateCodeWorkspaceCheckpointInput, type HarnessRunnerOptions, type MaterializedCodeSource, type MaterializedGitTree, type PrepareRuntimeCheckpointInput, type PreparedRuntimeCheckpoint, type RestoreCodeWorkspaceCheckpointInput, type RestoredCodeWorkspaceCheckpoint, type RuntimeCheckpointSession, type StageWorkspaceOptions, type StagedWorkspace, type VerifyCodeCandidateInput, assertCodeBuildRecipe, assertPinnedImage, attachCodeRuntimeReferences, buildContainerRunArgs, buildRecipeContainerArgs, createCodeRuntimeControlClient, createCodeToolBroker, createCodeWorkspaceCheckpoint, createContainerRecipeExecutor, digestStagedWorkspace, isCheckpointEffectCompleted, materializeCodeRuntimeSource, materializeGitTree, prepareRuntimeCheckpoint, restoreCodeWorkspaceCheckpoint, runCodeRuntimeHeartbeatLoop, runContainerAttempt, runHarnessRunner, runLeasedAttempt, safeWorkspaceLabel, selectContainerEngine, stageWorkspace, stageWorkspacePair, verifyCodeCandidate, verifyContainerEngineBoundary };
|