@ai-hero/sandcastle 0.10.0 → 0.12.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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as BindMountSandboxHandle, S as SandboxProvider, a as BranchStrategy, A as AnySandboxProvider, M as MergeToHeadBranchStrategy, b as NamedBranchStrategy } from './SandboxProvider-EkSMuBp8.js';
2
- export { c as BindMountBranchStrategy, d as BindMountCreateOptions, e as BindMountSandboxProvider, f as BindMountSandboxProviderConfig, E as ExecResult, H as HeadBranchStrategy, g as InteractiveExecOptions, h as IsolatedBranchStrategy, i as IsolatedCreateOptions, j as IsolatedSandboxHandle, I as IsolatedSandboxProvider, k as IsolatedSandboxProviderConfig, l as NoSandboxBranchStrategy, m as NoSandboxHandle, N as NoSandboxProvider, n as createBindMountSandboxProvider, o as createIsolatedSandboxProvider } from './SandboxProvider-EkSMuBp8.js';
1
+ import { B as BindMountSandboxHandle, S as SandboxProvider, a as BranchStrategy, A as AnySandboxProvider, E as ExecResult, M as MergeToHeadBranchStrategy, b as NamedBranchStrategy } from './SandboxProvider-EkSMuBp8.js';
2
+ export { c as BindMountBranchStrategy, d as BindMountCreateOptions, e as BindMountSandboxProvider, f as BindMountSandboxProviderConfig, H as HeadBranchStrategy, g as InteractiveExecOptions, h as IsolatedBranchStrategy, i as IsolatedCreateOptions, j as IsolatedSandboxHandle, I as IsolatedSandboxProvider, k as IsolatedSandboxProviderConfig, l as NoSandboxBranchStrategy, m as NoSandboxHandle, N as NoSandboxProvider, n as createBindMountSandboxProvider, o as createIsolatedSandboxProvider } from './SandboxProvider-EkSMuBp8.js';
3
3
  import { StandardSchemaV1 } from '@standard-schema/spec';
4
4
  export { M as MountConfig } from './MountConfig-CmXclHA5.js';
5
5
 
@@ -313,11 +313,35 @@ interface OutputObjectDefinition<T> {
313
313
  readonly _tag: "object";
314
314
  readonly tag: string;
315
315
  readonly schema: StandardSchemaV1<unknown, T>;
316
+ /**
317
+ * Maximum number of additional attempts after the first if structured output
318
+ * extraction or validation fails. Each retry resumes the failed run's agent
319
+ * session and feeds back a token-efficient description of the error so the
320
+ * agent can re-emit a corrected tag. Default: `0` (no retries).
321
+ *
322
+ * Retries require the agent provider to support session resumption (i.e.
323
+ * `provider.sessionStorage` is populated — Claude Code, Codex, Pi). `run()`
324
+ * fails at entry with a clear error when retries are requested but the
325
+ * provider cannot resume.
326
+ */
327
+ readonly maxRetries?: number;
316
328
  }
317
329
  /** Branded output definition for `Output.string({ tag })`. */
318
330
  interface OutputStringDefinition {
319
331
  readonly _tag: "string";
320
332
  readonly tag: string;
333
+ /**
334
+ * Maximum number of additional attempts after the first if structured output
335
+ * extraction fails. Each retry resumes the failed run's agent session and
336
+ * feeds back a token-efficient description of the error so the agent can
337
+ * re-emit a corrected tag. Default: `0` (no retries).
338
+ *
339
+ * Retries require the agent provider to support session resumption (i.e.
340
+ * `provider.sessionStorage` is populated — Claude Code, Codex, Pi). `run()`
341
+ * fails at entry with a clear error when retries are requested but the
342
+ * provider cannot resume.
343
+ */
344
+ readonly maxRetries?: number;
321
345
  }
322
346
  /** Union of all output definition shapes accepted by `run()`. */
323
347
  type OutputDefinition = OutputObjectDefinition<any> | OutputStringDefinition;
@@ -340,18 +364,28 @@ declare const Output: {
340
364
  * Declare an object-typed structured output extracted from an XML tag in
341
365
  * the agent's stdout. The tag contents are JSON-parsed (with fence-aware
342
366
  * unwrapping) and validated against the provided Standard Schema validator.
367
+ *
368
+ * Set `maxRetries` to have `run()` automatically resume the failed session
369
+ * and ask the agent to re-emit corrected output when extraction or
370
+ * validation fails. Default: `0` (no retries).
343
371
  */
344
372
  readonly object: <Schema extends StandardSchemaV1>(opts: {
345
373
  tag: string;
346
374
  schema: Schema;
375
+ maxRetries?: number;
347
376
  }) => OutputObjectDefinition<StandardSchemaV1.InferOutput<Schema>>;
348
377
  /**
349
378
  * Declare a string-typed structured output extracted from an XML tag in
350
379
  * the agent's stdout. The tag contents are whitespace-trimmed and returned
351
380
  * as a plain string — no JSON parsing, no schema validation.
381
+ *
382
+ * Set `maxRetries` to have `run()` automatically resume the failed session
383
+ * and ask the agent to re-emit corrected output when extraction fails.
384
+ * Default: `0` (no retries).
352
385
  */
353
386
  readonly string: (opts: {
354
387
  tag: string;
388
+ maxRetries?: number;
355
389
  }) => OutputStringDefinition;
356
390
  };
357
391
  interface StructuredOutputErrorOptions {
@@ -466,7 +500,7 @@ interface Timeouts {
466
500
  readonly mergeToHostMs?: number;
467
501
  }
468
502
  interface RunOptions<A extends AgentProvider = AgentProvider> {
469
- /** Agent provider to use (e.g. claudeCode("claude-opus-4-7")) */
503
+ /** Agent provider to use (e.g. claudeCode("claude-opus-4-8")) */
470
504
  readonly agent: A;
471
505
  /** Sandbox provider (e.g. docker({ imageName: "sandcastle:myrepo" })). */
472
506
  readonly sandbox: SandboxProvider;
@@ -604,7 +638,7 @@ declare function run<A extends AgentProvider>(options: RunOptions<A> & {
604
638
  declare function run<A extends AgentProvider>(options: RunOptions<A>): Promise<RunResult>;
605
639
 
606
640
  interface InteractiveOptions {
607
- /** Agent provider to use (e.g. claudeCode("claude-opus-4-7")) */
641
+ /** Agent provider to use (e.g. claudeCode("claude-opus-4-8")) */
608
642
  readonly agent: AgentProvider;
609
643
  /** Sandbox provider (e.g. docker(), noSandbox()). */
610
644
  readonly sandbox?: AnySandboxProvider;
@@ -698,17 +732,19 @@ interface CreateSandboxOptions {
698
732
  /** Override default timeouts for built-in lifecycle steps. Unset keys keep their defaults. */
699
733
  readonly timeouts?: Timeouts;
700
734
  }
701
- interface SandboxRunOptions {
702
- /** Agent provider to use (e.g. claudeCode("claude-opus-4-7")). */
703
- readonly agent: AgentProvider;
704
- /** Inline prompt string (mutually exclusive with promptFile). */
705
- readonly prompt?: string;
706
- /** Path to a prompt file (mutually exclusive with prompt). */
707
- readonly promptFile?: string;
735
+ /**
736
+ * Options accepted by `SandboxRunResult.resume()` / `.fork()`. Mirrors
737
+ * `ResumeRunResultOptions` in `run.ts` — drops the fields owned by the
738
+ * captured run (prompt, iteration count, resumeSession/forkSession bookkeeping).
739
+ *
740
+ * Defined as the base interface that `SandboxRunOptions` extends — the
741
+ * interface-extends shape is cheaper for the TS checker than
742
+ * `Omit<SandboxRunOptions, ...>` (which forces a mapped-type computation
743
+ * on every reference).
744
+ */
745
+ interface ResumeSandboxRunResultOptions {
708
746
  /** Key-value map for {{KEY}} placeholder substitution in prompts. */
709
747
  readonly promptArgs?: PromptArgs;
710
- /** Maximum iterations to run (default: 1). */
711
- readonly maxIterations?: number;
712
748
  /** Substring(s) the agent emits to stop the iteration loop early. */
713
749
  readonly completionSignal?: string | string[];
714
750
  /** Idle timeout in seconds. Default: 600. */
@@ -730,6 +766,18 @@ interface SandboxRunOptions {
730
766
  */
731
767
  readonly signal?: AbortSignal;
732
768
  }
769
+ interface SandboxRunOptions extends ResumeSandboxRunResultOptions {
770
+ /** Agent provider to use (e.g. claudeCode("claude-opus-4-8")). */
771
+ readonly agent: AgentProvider;
772
+ /** Inline prompt string (mutually exclusive with promptFile). */
773
+ readonly prompt?: string;
774
+ /** Path to a prompt file (mutually exclusive with prompt). */
775
+ readonly promptFile?: string;
776
+ /** Maximum iterations to run (default: 1). */
777
+ readonly maxIterations?: number;
778
+ /** Resume a prior agent session by id. The session JSONL must exist on the host (captured by a prior `sandbox.run()`). Incompatible with `maxIterations > 1`. */
779
+ readonly resumeSession?: string;
780
+ }
733
781
  interface SandboxRunResult {
734
782
  /** Per-iteration results (use `iterations.length` for the count). */
735
783
  readonly iterations: IterationResult[];
@@ -743,9 +791,23 @@ interface SandboxRunResult {
743
791
  }[];
744
792
  /** Path to the log file, if logging was drained to a file. */
745
793
  readonly logFilePath?: string;
794
+ /**
795
+ * Continue the last captured agent session for exactly one iteration inside
796
+ * the same long-lived sandbox. Present only when the provider supports
797
+ * resume (`sessionStorage` populated) and a session id was captured.
798
+ */
799
+ readonly resume?: (prompt: string, options?: ResumeSandboxRunResultOptions) => Promise<SandboxRunResult>;
800
+ /**
801
+ * Fork the last captured agent session for exactly one iteration inside the
802
+ * same long-lived sandbox: the parent session JSONL is left intact and the
803
+ * child run gets its own session id. Present only when the provider
804
+ * supports resume (`sessionStorage` populated) and a session id was
805
+ * captured. See ADR 0018 for fork semantics.
806
+ */
807
+ readonly fork?: (prompt: string, options?: ResumeSandboxRunResultOptions) => Promise<SandboxRunResult>;
746
808
  }
747
809
  interface SandboxInteractiveOptions {
748
- /** Agent provider to use (e.g. claudeCode("claude-opus-4-7")). */
810
+ /** Agent provider to use (e.g. claudeCode("claude-opus-4-8")). */
749
811
  readonly agent: AgentProvider;
750
812
  /** Inline prompt string (mutually exclusive with promptFile). */
751
813
  readonly prompt?: string;
@@ -785,11 +847,34 @@ interface Sandbox {
785
847
  run(options: SandboxRunOptions): Promise<SandboxRunResult>;
786
848
  /** Launch an interactive agent session inside the existing sandbox. */
787
849
  interactive(options: SandboxInteractiveOptions): Promise<SandboxInteractiveResult>;
850
+ /**
851
+ * Execute a command inside the existing sandbox.
852
+ *
853
+ * `cwd` defaults to the sandbox repo path (same default `interactive()`
854
+ * uses), so callers get the same working directory across providers. Pass
855
+ * `cwd` to override.
856
+ *
857
+ * Returns the full `ExecResult` — non-zero `exitCode` is surfaced, not
858
+ * thrown. Callers that want strict semantics should check `result.exitCode`
859
+ * themselves (matching the contract of `BindMountSandboxHandle.exec`).
860
+ */
861
+ exec(command: string, options?: SandboxExecOptions): Promise<ExecResult>;
788
862
  /** Tear down the sandbox and worktree. */
789
863
  close(): Promise<CloseResult>;
790
864
  /** Auto teardown via `await using`. */
791
865
  [Symbol.asyncDispose](): Promise<void>;
792
866
  }
867
+ /** Options accepted by `Sandbox.exec()`. Mirrors the provider handle's `exec` options. */
868
+ interface SandboxExecOptions {
869
+ /** Per-line stdout callback for streaming output. */
870
+ readonly onLine?: (line: string) => void;
871
+ /** Working directory for the command. Defaults to the sandbox repo path. */
872
+ readonly cwd?: string;
873
+ /** Run the command with sudo, when the provider supports it. */
874
+ readonly sudo?: boolean;
875
+ /** Stdin payload — piped to the child process and then closed. Avoids the Linux 128 KB per-arg limit. */
876
+ readonly stdin?: string;
877
+ }
793
878
  /**
794
879
  * Eagerly creates a git worktree on the provided explicit branch and starts
795
880
  * a sandbox with the worktree bind-mounted. Returns a Sandbox handle that
@@ -821,7 +906,7 @@ interface CreateWorktreeOptions {
821
906
  readonly timeouts?: Timeouts;
822
907
  }
823
908
  interface WorktreeInteractiveOptions {
824
- /** Agent provider to use (e.g. claudeCode("claude-opus-4-7")) */
909
+ /** Agent provider to use (e.g. claudeCode("claude-opus-4-8")) */
825
910
  readonly agent: AgentProvider;
826
911
  /** Sandbox provider (e.g. docker(), noSandbox()). Defaults to noSandbox(). */
827
912
  readonly sandbox?: AnySandboxProvider;
@@ -850,7 +935,7 @@ interface WorktreeInteractiveOptions {
850
935
  readonly signal?: AbortSignal;
851
936
  }
852
937
  interface WorktreeRunOptions {
853
- /** Agent provider to use (e.g. claudeCode("claude-opus-4-7")) */
938
+ /** Agent provider to use (e.g. claudeCode("claude-opus-4-8")) */
854
939
  readonly agent: AgentProvider;
855
940
  /** Sandbox provider (e.g. docker()). Required — AFK agents should always be sandboxed. */
856
941
  readonly sandbox: SandboxProvider;
@@ -963,4 +1048,4 @@ interface CwdError extends Error {
963
1048
  /** The provided `cwd` path does not exist or is not a directory. */
964
1049
  declare const CwdError: CwdErrorConstructor;
965
1050
 
966
- export { type AgentCommandOptions, type AgentProvider, type AgentStreamEvent, AnySandboxProvider, BindMountSandboxHandle, BranchStrategy, type ClaudeCodeOptions, type CloseResult, type CodexOptions, type CopilotOptions, type CreateSandboxOptions, type CreateWorktreeOptions, type CursorOptions, CwdError, type HostSessionLookup, type InteractiveOptions, type InteractiveResult, type IterationResult, type IterationUsage, type LoggingOption, MergeToHeadBranchStrategy, NamedBranchStrategy, type OpenCodeOptions, Output, type OutputDefinition, type OutputObjectDefinition, type OutputStringDefinition, type PiOptions, type PrintCommand, type PromptArgs, type RunOptions, type RunResult, type Sandbox, type SandboxHooks, type SandboxInteractiveOptions, type SandboxInteractiveResult, SandboxProvider, type SandboxRunOptions, type SandboxRunResult, StructuredOutputError, type Timeouts, type Worktree, type WorktreeBranchStrategy, type WorktreeCreateSandboxOptions, type WorktreeInteractiveOptions, type WorktreeRunOptions, type WorktreeRunResult, claudeCode, claudeHostSessionPath, claudeSandboxSessionPath, codex, copilot, createSandbox, createWorktree, cursor, encodeProjectPath, findClaudeSessionOnHost, findCodexSessionOnHost, interactive, opencode, pi, run, transferClaudeSession, transferCodexSession };
1051
+ export { type AgentCommandOptions, type AgentProvider, type AgentStreamEvent, AnySandboxProvider, BindMountSandboxHandle, BranchStrategy, type ClaudeCodeOptions, type CloseResult, type CodexOptions, type CopilotOptions, type CreateSandboxOptions, type CreateWorktreeOptions, type CursorOptions, CwdError, ExecResult, type HostSessionLookup, type InteractiveOptions, type InteractiveResult, type IterationResult, type IterationUsage, type LoggingOption, MergeToHeadBranchStrategy, NamedBranchStrategy, type OpenCodeOptions, Output, type OutputDefinition, type OutputObjectDefinition, type OutputStringDefinition, type PiOptions, type PrintCommand, type PromptArgs, type ResumeSandboxRunResultOptions, type RunOptions, type RunResult, type Sandbox, type SandboxExecOptions, type SandboxHooks, type SandboxInteractiveOptions, type SandboxInteractiveResult, SandboxProvider, type SandboxRunOptions, type SandboxRunResult, StructuredOutputError, type Timeouts, type Worktree, type WorktreeBranchStrategy, type WorktreeCreateSandboxOptions, type WorktreeInteractiveOptions, type WorktreeRunOptions, type WorktreeRunResult, claudeCode, claudeHostSessionPath, claudeSandboxSessionPath, codex, copilot, createSandbox, createWorktree, cursor, encodeProjectPath, findClaudeSessionOnHost, findCodexSessionOnHost, interactive, opencode, pi, run, transferClaudeSession, transferCodexSession };