Open History to see the last commit
1// Capability tokens + accessors (sandbox-owned only).
2// LockStore / withLocks / defineLock: import from @tanstack/ai/locks.
3export {
4 SandboxCapability,
5 SandboxPolicyCapability,
6 ToolBridgeProvisionerCapability,
7 getSandbox,
8 provideSandbox,
9 getSandboxPolicy,
10 provideSandboxPolicy,
11 getToolBridgeProvisioner,
12 provideToolBridgeProvisioner,
13} from './capabilities'
14
15// Durable instance map (resume-or-create across processes).
16// Pass a store to `withSandbox(sandbox, { instances })`; the capability is the
17// ambient alternative for platform-level wiring.
18export {
19 SandboxInstanceStoreCapability,
20 getSandboxInstanceStore,
21 provideSandboxInstanceStore,
22 InMemorySandboxInstanceStore,
23 defineSandboxInstanceStore,
24} from './instance-store'
25export type {
26 SandboxInstanceStore,
27 SandboxInstanceRecord,
28} from './instance-store'
29
30// Portable immutable sandbox checkpoint metadata.
31export {
32 SandboxCheckpointError,
33 SandboxCheckpointConflictError,
34 SandboxCheckpointDuplicateIdError,
35 SandboxCheckpointInvalidIdError,
36 SandboxCheckpointInvalidEntryError,
37 SandboxCheckpointParentMismatchError,
38 SandboxCheckpointNotHeadError,
39 SandboxCheckpointWriterConflictError,
40 SandboxCheckpointWriterLostError,
41 isForkCapableSandboxCheckpointStore,
42 InMemorySandboxCheckpointStore,
43 defineSandboxCheckpointStore,
44} from './checkpoint-store'
45
46export type {
47 SandboxCheckpoint,
48 SandboxCheckpointStore,
49 SandboxSnapshotEntry,
50 SandboxSnapshotFileEntry,
51 SandboxSnapshotDirectoryEntry,
52 SandboxSnapshotArtifact,
53 SandboxCheckpointErrorCode,
54 SandboxCheckpointWriter,
55 SandboxCheckpointWriterLease,
56 SandboxCheckpointStoreOptions,
57 SandboxCheckpointForkInput,
58 SandboxCheckpointForkCapability,
59 ForkCapableSandboxCheckpointStore,
60} from './checkpoint-store'
61
62// File snapshot policy used by provider snapshot create/restore inputs.
63export { SandboxSnapshotError, defaultSandboxSnapshotPolicy } from './snapshots'
64export type {
65 SandboxSnapshotErrorCode,
66 SandboxSnapshotPolicy,
67} from './snapshots'
68export { memorySandboxSnapshots } from './memory-snapshots'
69export type {
70 MemorySandboxSnapshots,
71 MemorySandboxSnapshotsOptions,
72} from './memory-snapshots'
73export { createSandboxSnapshots } from './snapshot-operations'
74export type {
75 CreateSandboxSnapshotsInput,
76 ForkSandboxSnapshotInput,
77 ReadSandboxSnapshotArtifactInput,
78 SandboxSnapshots,
79 SaveSandboxSnapshotInput,
80 SnapshotPersistence,
81} from './snapshot-operations'
82export { createSnapshotTools } from './snapshot-tools'
83export type { CreateSnapshotToolsOptions } from './snapshot-tools'
84
85// Workspace projection capability (provided by withSandbox, consumed by harness adapters)
86export {
87 ProjectionCapability,
88 getWorkspaceProjection,
89 provideWorkspaceProjection,
90} from './projection'
91export type { WorkspaceProjection } from './projection'
92
93// Middleware
94export { withSandbox } from './middleware'
95export type { SandboxMiddlewareOptions } from './middleware'
96
97// Harness tool history: `withSandbox` records the tool calls a harness ran INSIDE the
98// sandbox into the transcript, so a finished run restores its tool cards. This is how
99// an app recognises them — e.g. in its own `MessageStore.saveThread`, to cap or drop
100// what it does not want to store.
101export { isSandboxToolCall } from './tool-history'
102
103// Sandbox definition + lifecycle
104export { defineSandbox } from './sandbox'
105export type {
106 SandboxConfig,
107 SandboxDefinition,
108 SandboxEnsureContext,
109 SandboxLifecycle,
110 SandboxHooks,
111 ReuseStrategy,
112 SnapshotStrategy,
113} from './sandbox'
114
115// Workspace
116export {
117 defineWorkspace,
118 gitSource,
119 githubRepo,
120 localSource,
121 fileSkill,
122 agentSkill,
123 mcpSkill,
124 gitSkill,
125} from './workspace'
126export type {
127 WorkspaceDefinition,
128 WorkspaceSource,
129 WorkspaceSkill,
130 PackageManager,
131 McpConfig,
132} from './workspace'
133
134// Secrets
135export {
136 createSecrets,
137 bearer,
138 isSecretRef,
139 resolveSecret,
140 resolveBearer,
141 resolveAllSecrets,
142} from './secrets'
143export type { SecretRef, Secrets, BearerRef } from './secrets'
144
145// Policy
146export { defineSandboxPolicy, evaluateCommand, commandAliases } from './policy'
147export type {
148 SandboxPolicy,
149 PolicyDecision,
150 CommandRules,
151 CapabilityRules,
152} from './policy'
153
154// Provider + handle contracts
155export type {
156 SandboxProvider,
157 SandboxHandle,
158 SandboxCapabilities,
159 SandboxFs,
160 SandboxFsStat,
161 SandboxGit,
162 SandboxProcess,
163 SandboxPorts,
164 SandboxEnv,
165 SandboxChannel,
166 SpawnHandle,
167 ExecResult,
168 ProcessOptions,
169 SnapshotRef,
170 SandboxCreateInput,
171 SandboxResumeInput,
172 SandboxRestoreInput,
173 SandboxDestroyInput,
174} from './contracts'
175
176// Bootstrap engine (exported for provider/adapter authors + tests)
177export {
178 bootstrapWorkspace,
179 detectPackageManager,
180 DEFAULT_WORKSPACE_ROOT,
181} from './bootstrap'
182export { resolveHarnessCwd } from './harness-cwd'
183export type { BootstrapResult } from './bootstrap'
184
185// AGENTS.md writer + gitSkill path helper (used by bootstrap + harness adapters)
186export {
187 writeAgentsFile,
188 resolveGitSkillDir,
189 discoverSkillDirs,
190 formatWorkspaceScriptsSection,
191 mergeAgentsContent,
192} from './agents-file'
193export type { DiscoveredSkillDir } from './agents-file'
194
195// Exec-backed git helper (for providers without native git)
196export { createExecBackedGit } from './git-exec'
197
198// Harness runner: spawn an agent CLI in a sandbox + stream NDJSON stdout
199export {
200 spawnNdjson,
201 toLines,
202 startJournaledAgent,
203 readJournalNdjson,
204} from './runner'
205export type { SpawnNdjsonOptions, JournalOptions } from './runner'
206
207// The agent output journal: the durability boundary for a sandboxed run.
208//
209// journalListCommand/journalMtimeListCommand/parseJournalMtimeListing back the
210// journal-directory sweep (`journal-sweep.ts`); journalExitProbeCommand/
211// parseJournalExit/parseExitSentinel back the reaper's out-of-band exit probe
212// (`reap.ts`) and the streaming reader, which must agree on what "the run
213// ended" means; EXIT_SENTINEL_NONCE_KEY/exitSentinelLine are what make that
214// sentinel unforgeable by the agent's own stdout and are needed by anything
215// that seeds a journal by hand (a fake host, a test); the
216// mechanism that lets a sweep learn a detached run finished WITHOUT driving
217// it; decodeJournalRunId recovers the runId a listed filename encodes, fail
218// closed. `encodeRunId` is exported for adapters that derive their OWN
219// in-sandbox paths from a caller-supplied `runId` (prompt files, MCP bridge
220// configs) and must not hand-roll a second, divergent encoder.
221// `normalizeJournalDir` is intentionally NOT exported: it is a path
222// formatting detail of this module's own commands, not something a caller
223// composes with.
224export {
225 DEFAULT_JOURNAL_DIR,
226 encodeRunId,
227 EXIT_SENTINEL_KEY,
228 EXIT_SENTINEL_NONCE_KEY,
229 exitSentinelLine,
230 parseExitSentinel,
231 journalPaths,
232 journaledCommand,
233 journalFollowCommand,
234 journalReadCommand,
235 journalExistsCommand,
236 journalListCommand,
237 journalMtimeListCommand,
238 parseJournalMtimeListing,
239 journalExitProbeCommand,
240 parseJournalExit,
241 decodeJournalRunId,
242} from './journal'
243export type {
244 JournalPaths,
245 JournalMtimeListing,
246 JournalDirEntry,
247 DecodedJournalRunId,
248} from './journal'
249
250// Journal-directory sweep: bound the journals a detached run's sentinel never
251// got OBSERVED for (see `journal-sweep.ts`'s module doc for why almost every
252// branch keeps rather than deletes — deleting a live run's journal makes it
253// unresumable, with no undo).
254export {
255 pruneJournals,
256 DEFAULT_ORPHAN_TTL_MS,
257 DEFAULT_MAX_DELETES,
258} from './journal-sweep'
259export type {
260 PruneJournalsOptions,
261 PruneJournalsResult,
262 KeptJournal,
263 KeptJournalReason,
264 PruneJournalsFailure,
265} from './journal-sweep'
266
267// Detached-run reaper: sweep a `RunStore`'s reclaimable runs, driving a run to
268// terminal ONLY once the out-of-band journal probe (`probeRunExit`) already
269// knows the agent exited, or once its TTL has expired — never to find out
270// whether it finished (see `reap.ts`'s module doc for why that design was
271// rejected).
272export {
273 reapDetachedRuns,
274 probeRunExit,
275 DEFAULT_RUN_BUDGET_MS,
276 DEFAULT_MAX_RUNS,
277 DEFAULT_EXIT_PROBE_BYTES,
278} from './reap'
279export type {
280 RunExitProbe,
281 ReapRunOutcome,
282 ReapRunEntry,
283 ReapResult,
284 ReapOptions,
285} from './reap'
286
287// Sandbox reclaim: tear down the sandbox behind a terminal run.
288// `sandboxReclaimer` adapts `reclaimSandbox` to `ReapOptions.reclaim`.
289export {
290 reclaimSandbox,
291 sandboxReclaimer,
292 SandboxReclaimFailedError,
293} from './reclaim'
294export type { ReclaimOutcome, ReclaimSandboxOptions } from './reclaim'
295export {
296 DEFAULT_JOURNAL_POLL_MS,
297 journalReadStrategy,
298 readJournal,
299} from './journal-reader'
300export type { ReadJournalOptions } from './journal-reader'
301export { decodeBase64Stream, toJournalLines } from './journal-bytes'
302export type { JournalLine } from './journal-bytes'
303export {
304 createRunScopedIdGen,
305 chunkFingerprint,
306 chunkFingerprintIgnoringThreadId,
307 chunkThreadId,
308} from './chunk-identity'
309export {
310 alignToStoredLog,
311 isBridgeCustomChunk,
312 JournalReplayDivergedError,
313 JournalReplayThreadIdMismatchError,
314 DEFAULT_MAX_OUT_OF_BAND_SKIP,
315} from './align'
316export type { AlignToStoredLogOptions } from './align'
317
318// Attach preflight: the gate that makes a hopeless attach fail instead of
319// tailing an empty journal forever. `JournalAttachUnavailableError` and its
320// `reason` are the branchable surface (404 / 410 / 504 at an attach route), and
321// the bounded-wait default is exported because it bounds an attach REQUEST.
322export {
323 awaitAttachableJournal,
324 JournalAttachUnavailableError,
325 DEFAULT_ATTACH_JOURNAL_WAIT_MS,
326 DEFAULT_ATTACH_PROBE_INTERVAL_MS,
327} from './attach-preflight'
328export type {
329 AttachUnavailableReason,
330 AwaitAttachableJournalOptions,
331} from './attach-preflight'
332
333// Durability seam: the `withSandbox(sandbox, { runs, durability })` option
334// shape, the capability harness adapters read back via `getSandboxDurability`,
335// and the two helpers that turn a resolved durability into the pieces a
336// harness adapter actually drives with — a `journalOptionsFor` journal option
337// and an attach-only `alignedIfAttaching` alignment transform.
338//
339// `resolveSandboxDurability` is deliberately NOT exported: it is
340// `withSandbox`'s own path from raw options to the capability payload (see
341// `middleware.ts`), and a harness adapter only ever needs the ALREADY-RESOLVED
342// value read back off the capability bus, never to re-run that resolution
343// itself.
344export {
345 SandboxDurabilityCapability,
346 getSandboxDurability,
347 provideSandboxDurability,
348 DurableAttachNotSupportedError,
349 DurableRunIdRequiredError,
350 DurableThreadIdRequiredError,
351 resolveDurableRunId,
352 resolveDurableThreadId,
353 journalOptionsFor,
354 alignedIfAttaching,
355} from './durability'
356export type {
357 SandboxDurabilityOptions,
358 SandboxDurabilityLog,
359 SandboxRunDurability,
360} from './durability'
361
362// Run driver: fills in core's injected takeover seams (`claim`/`pipe`) with
363// this package's single-writer claim (`claim.ts`) and run log (`run.ts`), so
364// an application wires `request`/`runs`/`locks`/`durability`/`drive` instead of
365// hand-rolling the claim/fence dance itself.
366//
367// `claim.ts`'s own primitives — `withRunClaim`, `fenceDurability`,
368// `awaitLogQuiescence`, `runDriverLockKey`, and their `RunClaim` /
369// `WithRunClaimOptions` types — are deliberately NOT exported. They are
370// exactly the "easy to get wrong" seam `sandboxRunDriver` exists to make
371// impossible (see `driver.ts`'s module doc, points 1-3), and publishing them
372// would invite the same hand-rolled fencing bugs as a supported path. The two
373// error classes below ARE exported despite that: both can surface through
374// `sandboxRunDriver` itself, so a caller needs `instanceof` to branch on them,
375// and `DEFAULT_FENCE_QUIET_MS` is exported because it is the documented
376// default for `sandboxRunDriver`'s own `fenceQuietMs` option.
377export { sandboxRunDriver, RunDriverPipeOutsideClaimError } from './driver'
378export type { SandboxRunDriverOptions } from './driver'
379export {
380 RunClaimNotAcquiredError,
381 RunClaimLostError,
382 DEFAULT_FENCE_QUIET_MS,
383} from './claim'
384
385// MCP tool-proxy bridge (shared by harness adapters): transport-agnostic core
386// + the node:http host transport + a fetch-friendly JSON-RPC dispatcher.
387export {
388 startHostToolBridge,
389 hostForSandbox,
390 createToolBridgeCore,
391 handleBridgeJsonRpc,
392 timingSafeBearerEqual,
393 nodeHttpBridgeProvisioner,
394 BRIDGED_MCP_SERVER_NAME,
395} from './tool-bridge'
396export type {
397 HostToolBridge,
398 StartBridgeOptions,
399 ToolBridgeCore,
400 ToolBridgeCoreOptions,
401 ToolDescriptor,
402 ToolCallResult,
403 BridgePermission,
404 PermissionToolResult,
405 ToolBridgeProvisioner,
406 ToolBridgeProvisionOptions,
407 ProvisionedBridge,
408} from './tool-bridge'
409
410// Surface bridged-tool custom events (e.g. code mode console logs) on a harness
411// adapter's live output stream.
412export { createBridgeEventChannel, mergeChunkStreams } from './bridge-events'
413export type { BridgeEventChannel } from './bridge-events'
414
415// Host-tool delegation for the co-located ("combined") model: harness + bridge
416// run in-container; only chat()-tool EXECUTION crosses back to the orchestrator.
417export {
418 remoteToolStubs,
419 toolDescriptors,
420 httpRemoteToolExecutor,
421 executeHostTool,
422 isToolExecRequest,
423} from './remote-tools'
424export type {
425 RemoteToolExecutor,
426 RemoteToolExecuteOptions,
427 ToolExecRequest,
428} from './remote-tools'
429
430// Run driver — pumps a chat() stream into core's `StreamDurability` and
431// records run status/lifecycle in core's `RunStore`, so a trigger returns
432// immediately while a durable orchestrator drives the run and clients tail it.
433export { pipeToRunLog, RunController } from './run'
434export type {
435 RunDeps,
436 PipeToRunLogOptions,
437 RunControllerStartInput,
438 RunHandle,
439} from './run'
440
441// Interactive approvals (shared by harness adapters)
442export {
443 resolveApproval,
444 approvalId,
445 buildApprovalRequestedEvent,
446 APPROVAL_REQUESTED_EVENT,
447} from './approvals'
448export type { ResolveApprovalInput, ApprovalOutcome } from './approvals'
449
450// File-event watch (low-level workspace observer)
451export { watchWorkspace, diffSnapshots } from './watch'
452export type {
453 SandboxFileEvent,
454 FileEvent,
455 FileEventType,
456 WatchOptions,
457 SandboxWatchHandle,
458} from './watch'
459
460// Keying
461export { computeSandboxKey, computeWorkspaceHash } from './key'
462export type { SandboxKeyInput } from './key'
463
464// Errors
465export { UnsupportedCapabilityError, MissingSandboxError } from './errors'