@ai-hero/sandcastle 0.6.5 → 0.7.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/README.md +137 -62
- package/dist/{MountConfig.d.ts → MountConfig-CmXclHA5.d.ts} +3 -2
- package/dist/{SandboxProvider.d.ts → SandboxProvider-EkSMuBp8.d.ts} +25 -39
- package/dist/chunk-52CIJF45.js +25569 -0
- package/dist/chunk-52CIJF45.js.map +1 -0
- package/dist/chunk-5VM5QZ26.js +26988 -0
- package/dist/chunk-5VM5QZ26.js.map +1 -0
- package/dist/chunk-72UVAC7B.js +99 -0
- package/dist/chunk-72UVAC7B.js.map +1 -0
- package/dist/chunk-BIWNFKGV.js +22 -0
- package/dist/chunk-BIWNFKGV.js.map +1 -0
- package/dist/chunk-NGBM7T3E.js +76 -0
- package/dist/chunk-NGBM7T3E.js.map +1 -0
- package/dist/chunk-NSFQW6ML.js +362 -0
- package/dist/chunk-NSFQW6ML.js.map +1 -0
- package/dist/index.d.ts +920 -22
- package/dist/index.js +3212 -9
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +0 -2
- package/dist/main.js +19349 -13
- package/dist/main.js.map +1 -1
- package/dist/mountUtils-CCA-bbpK.d.ts +25 -0
- package/dist/sandboxes/daytona.d.ts +8 -5
- package/dist/sandboxes/daytona.js +118 -124
- package/dist/sandboxes/daytona.js.map +1 -1
- package/dist/sandboxes/docker.d.ts +10 -8
- package/dist/sandboxes/docker.js +8 -255
- package/dist/sandboxes/docker.js.map +1 -1
- package/dist/sandboxes/no-sandbox.d.ts +7 -4
- package/dist/sandboxes/no-sandbox.js +6 -114
- package/dist/sandboxes/no-sandbox.js.map +1 -1
- package/dist/sandboxes/podman.d.ts +10 -8
- package/dist/sandboxes/podman.js +287 -297
- package/dist/sandboxes/podman.js.map +1 -1
- package/dist/sandboxes/vercel.d.ts +7 -4
- package/dist/sandboxes/vercel.js +144 -165
- package/dist/sandboxes/vercel.js.map +1 -1
- package/dist/templates/sequential-reviewer/implement-prompt.md +2 -2
- package/dist/templates/simple-loop/prompt.md +2 -2
- package/package.json +15 -14
- package/dist/AgentProvider.d.ts +0 -134
- package/dist/AgentProvider.d.ts.map +0 -1
- package/dist/AgentProvider.js +0 -647
- package/dist/AgentProvider.js.map +0 -1
- package/dist/AgentStreamEmitter.d.ts +0 -36
- package/dist/AgentStreamEmitter.d.ts.map +0 -1
- package/dist/AgentStreamEmitter.js +0 -21
- package/dist/AgentStreamEmitter.js.map +0 -1
- package/dist/CopyToWorktree.d.ts +0 -15
- package/dist/CopyToWorktree.d.ts.map +0 -1
- package/dist/CopyToWorktree.js +0 -60
- package/dist/CopyToWorktree.js.map +0 -1
- package/dist/Display.d.ts +0 -58
- package/dist/Display.d.ts.map +0 -1
- package/dist/Display.js +0 -142
- package/dist/Display.js.map +0 -1
- package/dist/DockerLifecycle.d.ts +0 -54
- package/dist/DockerLifecycle.d.ts.map +0 -1
- package/dist/DockerLifecycle.js +0 -123
- package/dist/DockerLifecycle.js.map +0 -1
- package/dist/EnvResolver.d.ts +0 -11
- package/dist/EnvResolver.d.ts.map +0 -1
- package/dist/EnvResolver.js +0 -63
- package/dist/EnvResolver.js.map +0 -1
- package/dist/ErrorHandler.d.ts +0 -15
- package/dist/ErrorHandler.d.ts.map +0 -1
- package/dist/ErrorHandler.js +0 -85
- package/dist/ErrorHandler.js.map +0 -1
- package/dist/InitService.d.ts +0 -92
- package/dist/InitService.d.ts.map +0 -1
- package/dist/InitService.js +0 -836
- package/dist/InitService.js.map +0 -1
- package/dist/MountConfig.d.ts.map +0 -1
- package/dist/MountConfig.js +0 -7
- package/dist/MountConfig.js.map +0 -1
- package/dist/Orchestrator.d.ts +0 -56
- package/dist/Orchestrator.d.ts.map +0 -1
- package/dist/Orchestrator.js +0 -293
- package/dist/Orchestrator.js.map +0 -1
- package/dist/Output.d.ts +0 -107
- package/dist/Output.d.ts.map +0 -1
- package/dist/Output.js +0 -95
- package/dist/Output.js.map +0 -1
- package/dist/PodmanLifecycle.d.ts +0 -17
- package/dist/PodmanLifecycle.d.ts.map +0 -1
- package/dist/PodmanLifecycle.js +0 -45
- package/dist/PodmanLifecycle.js.map +0 -1
- package/dist/PromptArgumentSubstitution.d.ts +0 -32
- package/dist/PromptArgumentSubstitution.d.ts.map +0 -1
- package/dist/PromptArgumentSubstitution.js +0 -104
- package/dist/PromptArgumentSubstitution.js.map +0 -1
- package/dist/PromptPreprocessor.d.ts +0 -15
- package/dist/PromptPreprocessor.d.ts.map +0 -1
- package/dist/PromptPreprocessor.js +0 -55
- package/dist/PromptPreprocessor.js.map +0 -1
- package/dist/PromptResolver.d.ts +0 -21
- package/dist/PromptResolver.d.ts.map +0 -1
- package/dist/PromptResolver.js +0 -27
- package/dist/PromptResolver.js.map +0 -1
- package/dist/RecoveryMessage.d.ts +0 -15
- package/dist/RecoveryMessage.d.ts.map +0 -1
- package/dist/RecoveryMessage.js +0 -81
- package/dist/RecoveryMessage.js.map +0 -1
- package/dist/SandboxFactory.d.ts +0 -90
- package/dist/SandboxFactory.d.ts.map +0 -1
- package/dist/SandboxFactory.js +0 -324
- package/dist/SandboxFactory.js.map +0 -1
- package/dist/SandboxLifecycle.d.ts +0 -65
- package/dist/SandboxLifecycle.d.ts.map +0 -1
- package/dist/SandboxLifecycle.js +0 -296
- package/dist/SandboxLifecycle.js.map +0 -1
- package/dist/SandboxProvider.d.ts.map +0 -1
- package/dist/SandboxProvider.js +0 -28
- package/dist/SandboxProvider.js.map +0 -1
- package/dist/SessionStore.d.ts +0 -110
- package/dist/SessionStore.d.ts.map +0 -1
- package/dist/SessionStore.js +0 -330
- package/dist/SessionStore.js.map +0 -1
- package/dist/TextDeltaBuffer.d.ts +0 -24
- package/dist/TextDeltaBuffer.d.ts.map +0 -1
- package/dist/TextDeltaBuffer.js +0 -68
- package/dist/TextDeltaBuffer.js.map +0 -1
- package/dist/WorktreeManager.d.ts +0 -79
- package/dist/WorktreeManager.d.ts.map +0 -1
- package/dist/WorktreeManager.js +0 -283
- package/dist/WorktreeManager.js.map +0 -1
- package/dist/boundedTail.d.ts +0 -48
- package/dist/boundedTail.d.ts.map +0 -1
- package/dist/boundedTail.js +0 -64
- package/dist/boundedTail.js.map +0 -1
- package/dist/cli.d.ts +0 -30
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -340
- package/dist/cli.js.map +0 -1
- package/dist/createSandbox.d.ts +0 -154
- package/dist/createSandbox.d.ts.map +0 -1
- package/dist/createSandbox.js +0 -476
- package/dist/createSandbox.js.map +0 -1
- package/dist/createWorktree.d.ts +0 -154
- package/dist/createWorktree.d.ts.map +0 -1
- package/dist/createWorktree.js +0 -391
- package/dist/createWorktree.js.map +0 -1
- package/dist/errors.d.ts +0 -227
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -81
- package/dist/errors.js.map +0 -1
- package/dist/extractStructuredOutput.d.ts +0 -23
- package/dist/extractStructuredOutput.d.ts.map +0 -1
- package/dist/extractStructuredOutput.js +0 -102
- package/dist/extractStructuredOutput.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/interactive.d.ts +0 -74
- package/dist/interactive.d.ts.map +0 -1
- package/dist/interactive.js +0 -279
- package/dist/interactive.js.map +0 -1
- package/dist/main.d.ts.map +0 -1
- package/dist/mergeProviderEnv.d.ts +0 -13
- package/dist/mergeProviderEnv.d.ts.map +0 -1
- package/dist/mergeProviderEnv.js +0 -23
- package/dist/mergeProviderEnv.js.map +0 -1
- package/dist/mountUtils.d.ts +0 -146
- package/dist/mountUtils.d.ts.map +0 -1
- package/dist/mountUtils.js +0 -301
- package/dist/mountUtils.js.map +0 -1
- package/dist/raceAbortSignal.d.ts +0 -18
- package/dist/raceAbortSignal.d.ts.map +0 -1
- package/dist/raceAbortSignal.js +0 -32
- package/dist/raceAbortSignal.js.map +0 -1
- package/dist/resolveCwd.d.ts +0 -24
- package/dist/resolveCwd.d.ts.map +0 -1
- package/dist/resolveCwd.js +0 -32
- package/dist/resolveCwd.js.map +0 -1
- package/dist/resumePrecheck.d.ts +0 -26
- package/dist/resumePrecheck.d.ts.map +0 -1
- package/dist/resumePrecheck.js +0 -40
- package/dist/resumePrecheck.js.map +0 -1
- package/dist/run.d.ts +0 -216
- package/dist/run.d.ts.map +0 -1
- package/dist/run.js +0 -313
- package/dist/run.js.map +0 -1
- package/dist/sandboxExec.d.ts +0 -12
- package/dist/sandboxExec.d.ts.map +0 -1
- package/dist/sandboxExec.js +0 -26
- package/dist/sandboxExec.js.map +0 -1
- package/dist/sandboxes/daytona.d.ts.map +0 -1
- package/dist/sandboxes/docker.d.ts.map +0 -1
- package/dist/sandboxes/no-sandbox.d.ts.map +0 -1
- package/dist/sandboxes/podman.d.ts.map +0 -1
- package/dist/sandboxes/test-bind-mount.d.ts +0 -17
- package/dist/sandboxes/test-bind-mount.d.ts.map +0 -1
- package/dist/sandboxes/test-bind-mount.js +0 -92
- package/dist/sandboxes/test-bind-mount.js.map +0 -1
- package/dist/sandboxes/test-isolated.d.ts +0 -17
- package/dist/sandboxes/test-isolated.d.ts.map +0 -1
- package/dist/sandboxes/test-isolated.js +0 -98
- package/dist/sandboxes/test-isolated.js.map +0 -1
- package/dist/sandboxes/vercel.d.ts.map +0 -1
- package/dist/shutdownRegistry.d.ts +0 -30
- package/dist/shutdownRegistry.d.ts.map +0 -1
- package/dist/shutdownRegistry.js +0 -73
- package/dist/shutdownRegistry.js.map +0 -1
- package/dist/startSandbox.d.ts +0 -50
- package/dist/startSandbox.d.ts.map +0 -1
- package/dist/startSandbox.js +0 -117
- package/dist/startSandbox.js.map +0 -1
- package/dist/syncIn.d.ts +0 -24
- package/dist/syncIn.d.ts.map +0 -1
- package/dist/syncIn.js +0 -107
- package/dist/syncIn.js.map +0 -1
- package/dist/syncOut.d.ts +0 -27
- package/dist/syncOut.d.ts.map +0 -1
- package/dist/syncOut.js +0 -271
- package/dist/syncOut.js.map +0 -1
- package/dist/templates.d.ts +0 -2
- package/dist/templates.d.ts.map +0 -1
- package/dist/templates.js +0 -26
- package/dist/templates.js.map +0 -1
- package/dist/terminalCleanup.d.ts +0 -30
- package/dist/terminalCleanup.d.ts.map +0 -1
- package/dist/terminalCleanup.js +0 -37
- package/dist/terminalCleanup.js.map +0 -1
- package/dist/testSandbox.d.ts +0 -8
- package/dist/testSandbox.d.ts.map +0 -1
- package/dist/testSandbox.js +0 -109
- package/dist/testSandbox.js.map +0 -1
- package/dist/testSetup.d.ts +0 -2
- package/dist/testSetup.d.ts.map +0 -1
- package/dist/testSetup.js +0 -29
- package/dist/testSetup.js.map +0 -1
package/dist/resumePrecheck.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fail-fast validation that a resumable agent session exists on the host before
|
|
3
|
-
* launching the agent. Throws a descriptive error when the session is missing.
|
|
4
|
-
*
|
|
5
|
-
* The lookup strategy depends on the sandbox:
|
|
6
|
-
*
|
|
7
|
-
* - **No-sandbox**: the agent runs directly on the host and writes its session
|
|
8
|
-
* in place under a cwd-derived directory; Sandcastle never moves it. The
|
|
9
|
-
* agent's own path encoding (realpath canonicalisation plus
|
|
10
|
-
* non-alphanumeric → hyphen) is fragile and platform-specific to reconstruct,
|
|
11
|
-
* so we locate the file by its globally-unique session id instead.
|
|
12
|
-
* - **Sandboxed (bind-mount)**: Sandcastle's capture transfers the session into
|
|
13
|
-
* the host store keyed on the host repo dir, so for a resumable run the file
|
|
14
|
-
* lives at that exact encoded location — check it directly rather than
|
|
15
|
-
* scanning. (Isolated sandboxes fall here too, but neither capture nor resume
|
|
16
|
-
* transfer is wired for them today, so this is the host-repo-dir check by
|
|
17
|
-
* default.)
|
|
18
|
-
*/
|
|
19
|
-
export const assertResumeSessionExists = async (params) => {
|
|
20
|
-
const { provider, sandboxTag, hostRepoDir, resumeSession } = params;
|
|
21
|
-
if (!provider.sessionStorage) {
|
|
22
|
-
throw new Error(`${provider.name} does not support resumeSession`);
|
|
23
|
-
}
|
|
24
|
-
if (sandboxTag === "none") {
|
|
25
|
-
const found = await provider.sessionStorage.findByIdOnHost(resumeSession);
|
|
26
|
-
if (!found.path) {
|
|
27
|
-
throw new Error(`resumeSession "${resumeSession}" not found under ${found.searchedRoot}`);
|
|
28
|
-
}
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const hostStore = provider.sessionStorage.hostStore(hostRepoDir);
|
|
32
|
-
const exists = await hostStore.exists(resumeSession);
|
|
33
|
-
if (!exists) {
|
|
34
|
-
const sessionPath = hostStore.sessionFilePath(resumeSession);
|
|
35
|
-
throw new Error(sessionPath
|
|
36
|
-
? `resumeSession "${resumeSession}" not found: expected session file at ${sessionPath}`
|
|
37
|
-
: `resumeSession "${resumeSession}" not found`);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=resumePrecheck.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resumePrecheck.js","sourceRoot":"","sources":["../src/resumePrecheck.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,EAAE,MAK/C,EAAiB,EAAE;IAClB,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC;IAEpE,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,CAAC,IAAI,iCAAiC,CAAC,CAAC;IACrE,CAAC;IAED,IAAI,UAAU,KAAK,MAAM,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,cAAc,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAC1E,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CACb,kBAAkB,aAAa,qBAAqB,KAAK,CAAC,YAAY,EAAE,CACzE,CAAC;QACJ,CAAC;QACD,OAAO;IACT,CAAC;IAED,MAAM,SAAS,GAAG,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACjE,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IACrD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,WAAW,GAAG,SAAS,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;QAC7D,MAAM,IAAI,KAAK,CACb,WAAW;YACT,CAAC,CAAC,kBAAkB,aAAa,yCAAyC,WAAW,EAAE;YACvF,CAAC,CAAC,kBAAkB,aAAa,aAAa,CACjD,CAAC;IACJ,CAAC;AACH,CAAC,CAAC"}
|
package/dist/run.d.ts
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import type { AgentProvider } from "./AgentProvider.js";
|
|
2
|
-
import { type Severity } from "./Display.js";
|
|
3
|
-
import { type IterationResult, type IterationUsage } from "./Orchestrator.js";
|
|
4
|
-
import type { SandboxProvider, BranchStrategy } from "./SandboxProvider.js";
|
|
5
|
-
import { type AgentStreamEvent } from "./AgentStreamEmitter.js";
|
|
6
|
-
import type { SandboxHooks } from "./SandboxLifecycle.js";
|
|
7
|
-
import { type PromptArgs } from "./PromptArgumentSubstitution.js";
|
|
8
|
-
import type { OutputDefinition, OutputObjectDefinition, OutputStringDefinition } from "./Output.js";
|
|
9
|
-
/** Default maximum number of iterations for a run. */
|
|
10
|
-
export declare const DEFAULT_MAX_ITERATIONS = 1;
|
|
11
|
-
/** Replace characters that are invalid or problematic in file paths with dashes. */
|
|
12
|
-
export declare const sanitizeBranchForFilename: (branch: string) => string;
|
|
13
|
-
export interface FileDisplayStartupOptions {
|
|
14
|
-
readonly logPath: string;
|
|
15
|
-
readonly agentName?: string;
|
|
16
|
-
readonly branch?: string;
|
|
17
|
-
/** Resolved host repo directory. When it differs from `process.cwd()`, the
|
|
18
|
-
* log-file hint is printed as an absolute path so it can be pasted into any
|
|
19
|
-
* terminal. When it equals `process.cwd()` (or is omitted), a relative path
|
|
20
|
-
* is printed instead. */
|
|
21
|
-
readonly hostRepoDir?: string;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Print the startup message to the terminal when using file-based logging.
|
|
25
|
-
* Uses styleText for lightweight bold/dim styling — does not use Clack.
|
|
26
|
-
*/
|
|
27
|
-
export declare const printFileDisplayStartup: (options: FileDisplayStartupOptions) => void;
|
|
28
|
-
/**
|
|
29
|
-
* Build the log filename for a run.
|
|
30
|
-
* When a targetBranch is provided (temp branch mode), prefixes the filename
|
|
31
|
-
* with the sanitized target branch name so developers can identify which
|
|
32
|
-
* branch the run was targeting: `<targetBranch>-<resolvedBranch>.log`
|
|
33
|
-
* When no targetBranch, uses just the resolved branch: `<resolvedBranch>.log`
|
|
34
|
-
* When a name is provided, appends it to avoid collisions in multi-agent workflows.
|
|
35
|
-
*/
|
|
36
|
-
export declare const buildLogFilename: (resolvedBranch: string, targetBranch?: string | undefined, name?: string | undefined) => string;
|
|
37
|
-
export interface RunSummaryRowsOptions {
|
|
38
|
-
readonly name?: string;
|
|
39
|
-
readonly agentName: string;
|
|
40
|
-
readonly sandboxName: string;
|
|
41
|
-
readonly maxIterations: number;
|
|
42
|
-
readonly branch: string;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Build the summary rows for a run, used in both terminal mode and
|
|
46
|
-
* log-to-file mode. When a custom name is provided it appears as the
|
|
47
|
-
* Agent value instead of the internal provider name.
|
|
48
|
-
*/
|
|
49
|
-
export declare const buildRunSummaryRows: (options: RunSummaryRowsOptions) => Record<string, string>;
|
|
50
|
-
/**
|
|
51
|
-
* Build the completion status message for a run, used in both terminal mode
|
|
52
|
-
* and log-to-file mode to record the final outcome.
|
|
53
|
-
*/
|
|
54
|
-
export declare const buildCompletionMessage: (completionSignal: string | undefined, iterationsRun: number) => {
|
|
55
|
-
readonly message: string;
|
|
56
|
-
readonly severity: Severity;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Format the context window size from an iteration's usage data.
|
|
60
|
-
* Returns a string like "103k" representing the total input-side tokens
|
|
61
|
-
* (inputTokens + cacheCreationInputTokens + cacheReadInputTokens)
|
|
62
|
-
* rounded up to the nearest 1000.
|
|
63
|
-
*/
|
|
64
|
-
export declare const formatContextWindowSize: (usage: IterationUsage) => string;
|
|
65
|
-
/**
|
|
66
|
-
* Build "Context window: NNNk" lines for iterations that have usage data.
|
|
67
|
-
* Returns an empty array when no iterations carry usage.
|
|
68
|
-
*/
|
|
69
|
-
export declare const buildContextWindowLines: (iterations: readonly Pick<IterationResult, "usage">[]) => string[];
|
|
70
|
-
/**
|
|
71
|
-
* Controls where Sandcastle writes iteration progress and agent output.
|
|
72
|
-
* Use `"file"` (log-to-file mode) to write to a log file on disk, or
|
|
73
|
-
* `"stdout"` (terminal mode) to render an interactive UI in the terminal.
|
|
74
|
-
*/
|
|
75
|
-
export type LoggingOption =
|
|
76
|
-
/** Write progress and agent output to a log file at the given path (log-to-file mode). */
|
|
77
|
-
{
|
|
78
|
-
readonly type: "file";
|
|
79
|
-
readonly path: string;
|
|
80
|
-
/**
|
|
81
|
-
* Optional callback invoked for each agent stream event (text chunk or
|
|
82
|
-
* tool call) in addition to being written to the log file. Intended for
|
|
83
|
-
* forwarding the agent's output stream to external observability
|
|
84
|
-
* systems. Errors thrown by the callback are swallowed.
|
|
85
|
-
*/
|
|
86
|
-
readonly onAgentStreamEvent?: (event: AgentStreamEvent) => void;
|
|
87
|
-
}
|
|
88
|
-
/** Render progress and agent output as an interactive UI in the terminal (terminal mode). */
|
|
89
|
-
| {
|
|
90
|
-
readonly type: "stdout";
|
|
91
|
-
};
|
|
92
|
-
/** Override default timeouts for built-in lifecycle steps. Unset keys keep their defaults. */
|
|
93
|
-
export interface Timeouts {
|
|
94
|
-
/** Timeout (ms) for the host-side copy of `copyToWorktree` paths into the worktree. Default: 60_000. */
|
|
95
|
-
readonly copyToWorktreeMs?: number;
|
|
96
|
-
/** Timeout (ms) for each in-sandbox git setup command (safe.directory, user.name/email, branch discovery). Default: 10_000. */
|
|
97
|
-
readonly gitSetupMs?: number;
|
|
98
|
-
/** Timeout (ms) for collecting the commits produced during the run. Default: 30_000. */
|
|
99
|
-
readonly commitCollectionMs?: number;
|
|
100
|
-
/** Timeout (ms) for merging the temp branch back to the host branch (merge-to-head strategy). Default: 30_000. */
|
|
101
|
-
readonly mergeToHostMs?: number;
|
|
102
|
-
}
|
|
103
|
-
export interface RunOptions<A extends AgentProvider = AgentProvider> {
|
|
104
|
-
/** Agent provider to use (e.g. claudeCode("claude-opus-4-7")) */
|
|
105
|
-
readonly agent: A;
|
|
106
|
-
/** Sandbox provider (e.g. docker({ imageName: "sandcastle:myrepo" })). */
|
|
107
|
-
readonly sandbox: SandboxProvider;
|
|
108
|
-
/**
|
|
109
|
-
* Host repo directory. Replaces `process.cwd()` as the anchor for
|
|
110
|
-
* `.sandcastle/worktrees/`, `.sandcastle/.env`, `.sandcastle/logs/`,
|
|
111
|
-
* `.sandcastle/patches/`, and git operations.
|
|
112
|
-
*
|
|
113
|
-
* - Relative paths are resolved against `process.cwd()`.
|
|
114
|
-
* - Absolute paths are used as-is.
|
|
115
|
-
* - Defaults to `process.cwd()` when omitted.
|
|
116
|
-
*/
|
|
117
|
-
readonly cwd?: string;
|
|
118
|
-
/** Inline prompt string (mutually exclusive with promptFile) */
|
|
119
|
-
readonly prompt?: string;
|
|
120
|
-
/**
|
|
121
|
-
* Path to a prompt file (mutually exclusive with prompt).
|
|
122
|
-
*
|
|
123
|
-
* **Note:** `promptFile` is always resolved against `process.cwd()`, not
|
|
124
|
-
* against the `cwd` option. If you set a custom `cwd`, pass an absolute
|
|
125
|
-
* `promptFile` to avoid ambiguity.
|
|
126
|
-
*/
|
|
127
|
-
readonly promptFile?: string;
|
|
128
|
-
/** Maximum iterations to run (default: 1) */
|
|
129
|
-
readonly maxIterations?: number;
|
|
130
|
-
/** Lifecycle hooks grouped by execution location (host or sandbox). */
|
|
131
|
-
readonly hooks?: SandboxHooks;
|
|
132
|
-
/** Key-value map for {{KEY}} placeholder substitution in prompts */
|
|
133
|
-
readonly promptArgs?: PromptArgs;
|
|
134
|
-
/** Logging mode (default: { type: 'file' } with auto-generated path under .sandcastle/logs/) */
|
|
135
|
-
readonly logging?: LoggingOption;
|
|
136
|
-
/** Substring(s) the agent emits to stop the iteration loop early. Matched via `includes` against agent output. (default: `"<promise>COMPLETE</promise>"`) */
|
|
137
|
-
readonly completionSignal?: string | string[];
|
|
138
|
-
/** Idle timeout in seconds. If the agent produces no output for this long, it fails. Default: 600 (10 minutes) */
|
|
139
|
-
readonly idleTimeoutSeconds?: number;
|
|
140
|
-
/** Optional name for the run, shown as a prefix in log output */
|
|
141
|
-
readonly name?: string;
|
|
142
|
-
/** Paths relative to the host repo root to copy into the worktree before sandbox start. */
|
|
143
|
-
readonly copyToWorktree?: string[];
|
|
144
|
-
/** Branch strategy — controls how the agent's changes relate to branches.
|
|
145
|
-
* Defaults to { type: "head" } for bind-mount providers and { type: "merge-to-head" } for isolated providers. */
|
|
146
|
-
readonly branchStrategy?: BranchStrategy;
|
|
147
|
-
/** Resume a prior Claude Code session by ID. The session JSONL must exist on the host. Incompatible with maxIterations > 1. */
|
|
148
|
-
readonly resumeSession?: string;
|
|
149
|
-
/**
|
|
150
|
-
* An `AbortSignal` that cancels the run when aborted.
|
|
151
|
-
*
|
|
152
|
-
* - If `signal.aborted` is already `true` at entry, `run()` rejects
|
|
153
|
-
* immediately without doing any setup work.
|
|
154
|
-
* - Aborting mid-iteration kills the in-flight agent subprocess.
|
|
155
|
-
* - Phase boundaries (between iterations) also check the signal.
|
|
156
|
-
* - The rejected promise surfaces `signal.reason` via
|
|
157
|
-
* `signal.throwIfAborted()` — no Sandcastle-specific wrapping.
|
|
158
|
-
* - The worktree is preserved on disk after abort (error-path behavior).
|
|
159
|
-
*/
|
|
160
|
-
readonly signal?: AbortSignal;
|
|
161
|
-
/** Override default timeouts for built-in lifecycle steps. Unset keys keep their defaults. */
|
|
162
|
-
readonly timeouts?: Timeouts;
|
|
163
|
-
/**
|
|
164
|
-
* Structured output definition. When provided, the agent's stdout is
|
|
165
|
-
* scanned for the configured XML tag after the iteration completes, and the
|
|
166
|
-
* result is parsed/validated and returned on `RunResult.output`.
|
|
167
|
-
*
|
|
168
|
-
* Use `Output.object({ tag, schema })` for JSON+schema or
|
|
169
|
-
* `Output.string({ tag })` for raw string extraction.
|
|
170
|
-
*
|
|
171
|
-
* Constraints:
|
|
172
|
-
* - `maxIterations` must be `1` (the default).
|
|
173
|
-
* - The resolved prompt must contain the configured opening tag literal.
|
|
174
|
-
*
|
|
175
|
-
* See ADR 0010 for design rationale.
|
|
176
|
-
*/
|
|
177
|
-
readonly output?: OutputDefinition;
|
|
178
|
-
}
|
|
179
|
-
export type { IterationResult, IterationUsage } from "./Orchestrator.js";
|
|
180
|
-
export type ResumeRunResultOptions = Omit<RunOptions, "agent" | "sandbox" | "prompt" | "promptFile" | "resumeSession" | "maxIterations">;
|
|
181
|
-
export interface RunResult {
|
|
182
|
-
/** Per-iteration results (use `iterations.length` for the count). */
|
|
183
|
-
readonly iterations: IterationResult[];
|
|
184
|
-
/** The matched completion signal string, or undefined if no signal fired before the iteration limit. */
|
|
185
|
-
readonly completionSignal?: string;
|
|
186
|
-
/** Combined stdout output from all agent iterations. */
|
|
187
|
-
readonly stdout: string;
|
|
188
|
-
/** List of commits made by the agent during the run, each identified by its SHA. */
|
|
189
|
-
readonly commits: {
|
|
190
|
-
sha: string;
|
|
191
|
-
}[];
|
|
192
|
-
/** The branch name the agent worked on inside the sandbox. */
|
|
193
|
-
readonly branch: string;
|
|
194
|
-
/** Path to the log file, if logging was drained to a file. */
|
|
195
|
-
readonly logFilePath?: string;
|
|
196
|
-
/** Host path to the preserved worktree, set when the run succeeded but the worktree had uncommitted changes. */
|
|
197
|
-
readonly preservedWorktreePath?: string;
|
|
198
|
-
/** Continue the last captured agent session for exactly one iteration.
|
|
199
|
-
* Present only when the provider supports resume (`sessionStorage` populated). */
|
|
200
|
-
readonly resume?: (prompt: string, options?: ResumeRunResultOptions) => Promise<RunResult>;
|
|
201
|
-
}
|
|
202
|
-
/** Overload: with `Output.object`, returns `RunResult` with typed `output: T`. */
|
|
203
|
-
export declare function run<T, A extends AgentProvider>(options: RunOptions<A> & {
|
|
204
|
-
output: OutputObjectDefinition<T>;
|
|
205
|
-
}): Promise<RunResult & {
|
|
206
|
-
output: T;
|
|
207
|
-
}>;
|
|
208
|
-
/** Overload: with `Output.string`, returns `RunResult` with `output: string`. */
|
|
209
|
-
export declare function run<A extends AgentProvider>(options: RunOptions<A> & {
|
|
210
|
-
output: OutputStringDefinition;
|
|
211
|
-
}): Promise<RunResult & {
|
|
212
|
-
output: string;
|
|
213
|
-
}>;
|
|
214
|
-
/** Overload: without `output`, returns the standard `RunResult`. */
|
|
215
|
-
export declare function run<A extends AgentProvider>(options: RunOptions<A>): Promise<RunResult>;
|
|
216
|
-
//# sourceMappingURL=run.d.ts.map
|
package/dist/run.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAIL,KAAK,QAAQ,EACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,cAAc,EAEpB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAI5E,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAG1D,OAAO,EACL,KAAK,UAAU,EAKhB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EACV,gBAAgB,EAChB,sBAAsB,EACtB,sBAAsB,E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AAC,CAAC;CACzB;AAED,kFAAkF;AAClF,wBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,SAAS,aAAa,EAC5C,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG;IAAE,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAA;CAAE,GAC7D,OAAO,CAAC,SAAS,GAAG;IAAE,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AACtC,iFAAiF;AACjF,wBAAgB,GAAG,CAAC,CAAC,SAAS,aAAa,EACzC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG;IAAE,MAAM,EAAE,sBAAsB,CAAA;CAAE,GAC1D,OAAO,CAAC,SAAS,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAC3C,oEAAoE;AACpE,wBAAgB,GAAG,CAAC,CAAC,SAAS,aAAa,EACzC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,SAAS,CAAC,CAAC"}
|
package/dist/run.js
DELETED
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
import { NodeContext, NodeFileSystem } from "@effect/platform-node";
|
|
2
|
-
import path, { join } from "node:path";
|
|
3
|
-
import { styleText } from "node:util";
|
|
4
|
-
import { Effect, Layer } from "effect";
|
|
5
|
-
import { resolveCwd } from "./resolveCwd.js";
|
|
6
|
-
import { assertResumeSessionExists } from "./resumePrecheck.js";
|
|
7
|
-
import { ClackDisplay, Display, FileDisplay, } from "./Display.js";
|
|
8
|
-
import { orchestrate, } from "./Orchestrator.js";
|
|
9
|
-
import { resolvePrompt } from "./PromptResolver.js";
|
|
10
|
-
import { WorktreeDockerSandboxFactory, SandboxConfig, } from "./SandboxFactory.js";
|
|
11
|
-
import { resolveEnv } from "./EnvResolver.js";
|
|
12
|
-
import { formatErrorMessage } from "./ErrorHandler.js";
|
|
13
|
-
import { callbackAgentStreamEmitterLayer, noopAgentStreamEmitterLayer, } from "./AgentStreamEmitter.js";
|
|
14
|
-
import { mergeProviderEnv } from "./mergeProviderEnv.js";
|
|
15
|
-
import { generateTempBranchName, getCurrentBranch } from "./WorktreeManager.js";
|
|
16
|
-
import { substitutePromptArgs, validateNoArgsWithInlinePrompt, validateNoBuiltInArgOverride, BUILT_IN_PROMPT_ARG_KEYS, } from "./PromptArgumentSubstitution.js";
|
|
17
|
-
import { extractStructuredOutput } from "./extractStructuredOutput.js";
|
|
18
|
-
/** Default maximum number of iterations for a run. */
|
|
19
|
-
export const DEFAULT_MAX_ITERATIONS = 1;
|
|
20
|
-
/** Replace characters that are invalid or problematic in file paths with dashes. */
|
|
21
|
-
export const sanitizeBranchForFilename = (branch) => branch.replace(/[/\\:*?"<>|]/g, "-");
|
|
22
|
-
/**
|
|
23
|
-
* Print the startup message to the terminal when using file-based logging.
|
|
24
|
-
* Uses styleText for lightweight bold/dim styling — does not use Clack.
|
|
25
|
-
*/
|
|
26
|
-
export const printFileDisplayStartup = (options) => {
|
|
27
|
-
const name = options.agentName ?? "Agent";
|
|
28
|
-
const label = styleText("bold", `[${name}]`);
|
|
29
|
-
const branchPart = options.branch ? ` on branch ${options.branch}` : "";
|
|
30
|
-
const hostRepoDir = options.hostRepoDir ?? process.cwd();
|
|
31
|
-
const displayLogPath = hostRepoDir === process.cwd()
|
|
32
|
-
? path.relative(process.cwd(), options.logPath)
|
|
33
|
-
: options.logPath;
|
|
34
|
-
console.log(`${label} Started${branchPart}`);
|
|
35
|
-
console.log(styleText("dim", ` tail -f ${displayLogPath}`));
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Build the log filename for a run.
|
|
39
|
-
* When a targetBranch is provided (temp branch mode), prefixes the filename
|
|
40
|
-
* with the sanitized target branch name so developers can identify which
|
|
41
|
-
* branch the run was targeting: `<targetBranch>-<resolvedBranch>.log`
|
|
42
|
-
* When no targetBranch, uses just the resolved branch: `<resolvedBranch>.log`
|
|
43
|
-
* When a name is provided, appends it to avoid collisions in multi-agent workflows.
|
|
44
|
-
*/
|
|
45
|
-
export const buildLogFilename = (resolvedBranch, targetBranch, name) => {
|
|
46
|
-
const sanitized = sanitizeBranchForFilename(resolvedBranch);
|
|
47
|
-
const nameSuffix = name
|
|
48
|
-
? `-${name.toLowerCase().replace(/[^a-z0-9_.-]/g, "-")}`
|
|
49
|
-
: "";
|
|
50
|
-
if (targetBranch) {
|
|
51
|
-
return `${sanitizeBranchForFilename(targetBranch)}-${sanitized}${nameSuffix}.log`;
|
|
52
|
-
}
|
|
53
|
-
return `${sanitized}${nameSuffix}.log`;
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* Build the summary rows for a run, used in both terminal mode and
|
|
57
|
-
* log-to-file mode. When a custom name is provided it appears as the
|
|
58
|
-
* Agent value instead of the internal provider name.
|
|
59
|
-
*/
|
|
60
|
-
export const buildRunSummaryRows = (options) => ({
|
|
61
|
-
Agent: options.name ?? options.agentName,
|
|
62
|
-
Sandbox: options.sandboxName,
|
|
63
|
-
"Max iterations": String(options.maxIterations),
|
|
64
|
-
Branch: options.branch,
|
|
65
|
-
});
|
|
66
|
-
/**
|
|
67
|
-
* Build the completion status message for a run, used in both terminal mode
|
|
68
|
-
* and log-to-file mode to record the final outcome.
|
|
69
|
-
*/
|
|
70
|
-
export const buildCompletionMessage = (completionSignal, iterationsRun) => {
|
|
71
|
-
if (completionSignal !== undefined) {
|
|
72
|
-
return {
|
|
73
|
-
message: `Run complete: agent finished after ${iterationsRun} iteration(s).`,
|
|
74
|
-
severity: "success",
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
message: `Run complete: reached ${iterationsRun} iteration(s) without completion signal.`,
|
|
79
|
-
severity: "warn",
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
/**
|
|
83
|
-
* Format the context window size from an iteration's usage data.
|
|
84
|
-
* Returns a string like "103k" representing the total input-side tokens
|
|
85
|
-
* (inputTokens + cacheCreationInputTokens + cacheReadInputTokens)
|
|
86
|
-
* rounded up to the nearest 1000.
|
|
87
|
-
*/
|
|
88
|
-
export const formatContextWindowSize = (usage) => {
|
|
89
|
-
const total = usage.inputTokens +
|
|
90
|
-
usage.cacheCreationInputTokens +
|
|
91
|
-
usage.cacheReadInputTokens;
|
|
92
|
-
return `${Math.ceil(total / 1000)}k`;
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* Build "Context window: NNNk" lines for iterations that have usage data.
|
|
96
|
-
* Returns an empty array when no iterations carry usage.
|
|
97
|
-
*/
|
|
98
|
-
export const buildContextWindowLines = (iterations) => iterations
|
|
99
|
-
.filter((it) => it.usage !== undefined)
|
|
100
|
-
.map((it) => `Context window: ${formatContextWindowSize(it.usage)}`);
|
|
101
|
-
export async function run(options) {
|
|
102
|
-
// If signal is already aborted, reject immediately without any setup
|
|
103
|
-
options.signal?.throwIfAborted();
|
|
104
|
-
const { prompt, promptFile, maxIterations = DEFAULT_MAX_ITERATIONS, hooks, agent: provider, } = options;
|
|
105
|
-
// Derive branch strategy: explicit option > default based on provider tag
|
|
106
|
-
const branchStrategy = options.branchStrategy ??
|
|
107
|
-
(options.sandbox.tag === "isolated"
|
|
108
|
-
? { type: "merge-to-head" }
|
|
109
|
-
: { type: "head" });
|
|
110
|
-
const effectiveBranchType = branchStrategy.type;
|
|
111
|
-
// Validate: head strategy is not supported with isolated providers
|
|
112
|
-
if (effectiveBranchType === "head" && options.sandbox.tag === "isolated") {
|
|
113
|
-
throw new Error("head branch strategy is not supported with isolated providers");
|
|
114
|
-
}
|
|
115
|
-
// Validate: copyToWorktree is incompatible with head strategy
|
|
116
|
-
if (effectiveBranchType === "head" &&
|
|
117
|
-
options.copyToWorktree &&
|
|
118
|
-
options.copyToWorktree.length > 0) {
|
|
119
|
-
throw new Error("copyToWorktree is not supported with head branch strategy. " +
|
|
120
|
-
"In head mode the host working directory is bind-mounted directly.");
|
|
121
|
-
}
|
|
122
|
-
// Validate: resumeSession + maxIterations > 1 is not allowed
|
|
123
|
-
if (options.resumeSession && maxIterations > 1) {
|
|
124
|
-
throw new Error("resumeSession cannot be combined with maxIterations > 1. " +
|
|
125
|
-
"Resume applies to iteration 1 only; multi-iteration resume semantics are not supported.");
|
|
126
|
-
}
|
|
127
|
-
// Validate: output requires maxIterations === 1
|
|
128
|
-
if (options.output && maxIterations !== 1) {
|
|
129
|
-
throw new Error("output requires maxIterations to be 1. " +
|
|
130
|
-
"Structured output is only supported for single-iteration runs.");
|
|
131
|
-
}
|
|
132
|
-
// Extract explicit branch when in branch mode
|
|
133
|
-
const branch = branchStrategy.type === "branch" ? branchStrategy.branch : undefined;
|
|
134
|
-
const hostRepoDir = await Effect.runPromise(resolveCwd(options.cwd).pipe(Effect.provide(NodeContext.layer)));
|
|
135
|
-
// Validate: resumeSession file must exist on the host
|
|
136
|
-
if (options.resumeSession) {
|
|
137
|
-
await assertResumeSessionExists({
|
|
138
|
-
provider,
|
|
139
|
-
sandboxTag: options.sandbox.tag,
|
|
140
|
-
hostRepoDir,
|
|
141
|
-
resumeSession: options.resumeSession,
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
// Resolve prompt
|
|
145
|
-
const resolved = await Effect.runPromise(resolvePrompt({ prompt, promptFile }).pipe(Effect.provide(NodeContext.layer)));
|
|
146
|
-
const rawPrompt = resolved.text;
|
|
147
|
-
const isInlinePrompt = resolved.source === "inline";
|
|
148
|
-
// Validate: output tag must appear in the resolved prompt
|
|
149
|
-
if (options.output) {
|
|
150
|
-
const openTag = `<${options.output.tag}>`;
|
|
151
|
-
if (!rawPrompt.includes(openTag)) {
|
|
152
|
-
throw new Error(`output tag <${options.output.tag}> not found in the resolved prompt. ` +
|
|
153
|
-
"The caller must instruct the agent to emit the configured tag.");
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
const agentName = provider.name;
|
|
157
|
-
// Resolve env vars and merge with provider env
|
|
158
|
-
const resolvedEnv = await Effect.runPromise(resolveEnv(hostRepoDir).pipe(Effect.provide(NodeContext.layer)));
|
|
159
|
-
const env = mergeProviderEnv({
|
|
160
|
-
resolvedEnv,
|
|
161
|
-
agentProviderEnv: provider.env,
|
|
162
|
-
sandboxProviderEnv: options.sandbox.env,
|
|
163
|
-
});
|
|
164
|
-
// Always capture the host's current branch for the TARGET_BRANCH built-in
|
|
165
|
-
// prompt argument. When using a temp branch, it also prefixes the log filename.
|
|
166
|
-
const currentHostBranch = await Effect.runPromise(getCurrentBranch(hostRepoDir));
|
|
167
|
-
// When in merge-to-head mode, generate a temporary branch name.
|
|
168
|
-
// In head mode, use the host's current branch directly (no worktree).
|
|
169
|
-
const resolvedBranch = effectiveBranchType === "head"
|
|
170
|
-
? currentHostBranch
|
|
171
|
-
: (branch ?? generateTempBranchName(options.name));
|
|
172
|
-
// When using a temp branch, prefix the log filename with the target branch
|
|
173
|
-
// (the host's current branch) so developers can tell which branch was targeted.
|
|
174
|
-
const targetBranch = effectiveBranchType === "merge-to-head" ? currentHostBranch : undefined;
|
|
175
|
-
// Resolve logging option
|
|
176
|
-
const resolvedLogging = options.logging ?? {
|
|
177
|
-
type: "file",
|
|
178
|
-
path: join(hostRepoDir, ".sandcastle", "logs", buildLogFilename(resolvedBranch, targetBranch, options.name)),
|
|
179
|
-
};
|
|
180
|
-
const displayLayer = resolvedLogging.type === "file"
|
|
181
|
-
? (() => {
|
|
182
|
-
printFileDisplayStartup({
|
|
183
|
-
logPath: resolvedLogging.path,
|
|
184
|
-
agentName: options.name,
|
|
185
|
-
branch: resolvedBranch,
|
|
186
|
-
hostRepoDir,
|
|
187
|
-
});
|
|
188
|
-
return Layer.provide(FileDisplay.layer(resolvedLogging.path), NodeFileSystem.layer);
|
|
189
|
-
})()
|
|
190
|
-
: ClackDisplay.layer;
|
|
191
|
-
const factoryLayer = Layer.provide(WorktreeDockerSandboxFactory.layer, Layer.mergeAll(Layer.succeed(SandboxConfig, {
|
|
192
|
-
env,
|
|
193
|
-
hostRepoDir,
|
|
194
|
-
copyToWorktree: options.copyToWorktree,
|
|
195
|
-
name: options.name,
|
|
196
|
-
sandboxProvider: options.sandbox,
|
|
197
|
-
branchStrategy,
|
|
198
|
-
hooks,
|
|
199
|
-
signal: options.signal,
|
|
200
|
-
timeouts: options.timeouts,
|
|
201
|
-
}), NodeFileSystem.layer, displayLayer));
|
|
202
|
-
const agentStreamEmitterLayer = resolvedLogging.type === "file" && resolvedLogging.onAgentStreamEvent
|
|
203
|
-
? callbackAgentStreamEmitterLayer(resolvedLogging.onAgentStreamEvent)
|
|
204
|
-
: noopAgentStreamEmitterLayer;
|
|
205
|
-
const runLayer = Layer.mergeAll(factoryLayer, displayLayer, agentStreamEmitterLayer);
|
|
206
|
-
const baseEffect = Effect.gen(function* () {
|
|
207
|
-
const d = yield* Display;
|
|
208
|
-
yield* d.intro(options.name ?? "sandcastle");
|
|
209
|
-
const rows = buildRunSummaryRows({
|
|
210
|
-
name: options.name,
|
|
211
|
-
agentName,
|
|
212
|
-
sandboxName: options.sandbox.name,
|
|
213
|
-
maxIterations,
|
|
214
|
-
branch: resolvedBranch,
|
|
215
|
-
});
|
|
216
|
-
yield* d.summary("Sandcastle Run", rows);
|
|
217
|
-
const userArgs = options.promptArgs ?? {};
|
|
218
|
-
// Inline prompts pass through to the agent literally — no substitution,
|
|
219
|
-
// no built-in arg injection. Guard against silently ignoring promptArgs.
|
|
220
|
-
let resolvedPrompt;
|
|
221
|
-
if (isInlinePrompt) {
|
|
222
|
-
yield* validateNoArgsWithInlinePrompt(userArgs);
|
|
223
|
-
resolvedPrompt = rawPrompt;
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
yield* validateNoBuiltInArgOverride(userArgs);
|
|
227
|
-
const effectiveArgs = {
|
|
228
|
-
SOURCE_BRANCH: resolvedBranch,
|
|
229
|
-
TARGET_BRANCH: currentHostBranch,
|
|
230
|
-
...userArgs,
|
|
231
|
-
};
|
|
232
|
-
const builtInArgKeysSet = new Set(BUILT_IN_PROMPT_ARG_KEYS);
|
|
233
|
-
resolvedPrompt = yield* substitutePromptArgs(rawPrompt, effectiveArgs, builtInArgKeysSet);
|
|
234
|
-
}
|
|
235
|
-
// In head mode, pass the host branch so SandboxLifecycle skips the merge step.
|
|
236
|
-
// In merge-to-head mode, branch is undefined (triggers merge). In branch mode, it's the explicit branch.
|
|
237
|
-
const orchestrateBranch = effectiveBranchType === "head" ? currentHostBranch : branch;
|
|
238
|
-
const orchestrateResult = yield* orchestrate({
|
|
239
|
-
hostRepoDir,
|
|
240
|
-
iterations: maxIterations,
|
|
241
|
-
hooks,
|
|
242
|
-
prompt: resolvedPrompt,
|
|
243
|
-
branch: orchestrateBranch,
|
|
244
|
-
provider,
|
|
245
|
-
completionSignal: options.completionSignal,
|
|
246
|
-
idleTimeoutSeconds: options.idleTimeoutSeconds,
|
|
247
|
-
name: options.name,
|
|
248
|
-
resumeSession: options.resumeSession,
|
|
249
|
-
signal: options.signal,
|
|
250
|
-
skipPromptExpansion: isInlinePrompt,
|
|
251
|
-
timeouts: options.timeouts,
|
|
252
|
-
});
|
|
253
|
-
const completion = buildCompletionMessage(orchestrateResult.completionSignal, orchestrateResult.iterations.length);
|
|
254
|
-
yield* d.status(completion.message, completion.severity);
|
|
255
|
-
for (const line of buildContextWindowLines(orchestrateResult.iterations)) {
|
|
256
|
-
yield* d.text(line);
|
|
257
|
-
}
|
|
258
|
-
return orchestrateResult;
|
|
259
|
-
});
|
|
260
|
-
// In file-logging mode, write errors to the log before they propagate.
|
|
261
|
-
// In stdout mode (ClackDisplay), errors are already shown by withFriendlyErrors
|
|
262
|
-
// in main.ts, so we skip to avoid duplicate terminal output.
|
|
263
|
-
const withErrorLog = resolvedLogging.type === "file"
|
|
264
|
-
? baseEffect.pipe(Effect.tapError((error) => Effect.gen(function* () {
|
|
265
|
-
const d = yield* Display;
|
|
266
|
-
yield* d.status(formatErrorMessage(error), "error");
|
|
267
|
-
})))
|
|
268
|
-
: baseEffect;
|
|
269
|
-
let result;
|
|
270
|
-
try {
|
|
271
|
-
result = await Effect.runPromise(withErrorLog.pipe(Effect.provide(runLayer)));
|
|
272
|
-
}
|
|
273
|
-
catch (error) {
|
|
274
|
-
// If the signal was aborted, surface its reason verbatim (no wrapping)
|
|
275
|
-
options.signal?.throwIfAborted();
|
|
276
|
-
throw error;
|
|
277
|
-
}
|
|
278
|
-
const baseResult = {
|
|
279
|
-
...result,
|
|
280
|
-
logFilePath: resolvedLogging.type === "file" ? resolvedLogging.path : undefined,
|
|
281
|
-
resume: async (prompt, resumeOptions) => {
|
|
282
|
-
const lastIteration = result.iterations.at(-1);
|
|
283
|
-
if (!lastIteration?.sessionId) {
|
|
284
|
-
throw new Error("Cannot resume: no sessionId was captured");
|
|
285
|
-
}
|
|
286
|
-
return run({
|
|
287
|
-
...options,
|
|
288
|
-
...resumeOptions,
|
|
289
|
-
prompt,
|
|
290
|
-
promptFile: undefined,
|
|
291
|
-
maxIterations: 1,
|
|
292
|
-
resumeSession: lastIteration.sessionId,
|
|
293
|
-
});
|
|
294
|
-
},
|
|
295
|
-
};
|
|
296
|
-
// Extract structured output after the iteration completes (separate pass from completion signal)
|
|
297
|
-
if (options.output) {
|
|
298
|
-
// Structured output runs are single-iteration, so the last iteration is the
|
|
299
|
-
// one that produced this stdout. Carry its session id onto the error so a
|
|
300
|
-
// caller can resume the same session to re-emit corrected output.
|
|
301
|
-
const lastIteration = baseResult.iterations.at(-1);
|
|
302
|
-
const output = await extractStructuredOutput(baseResult.stdout, options.output, {
|
|
303
|
-
commits: baseResult.commits,
|
|
304
|
-
branch: baseResult.branch,
|
|
305
|
-
preservedWorktreePath: baseResult.preservedWorktreePath,
|
|
306
|
-
sessionId: lastIteration?.sessionId,
|
|
307
|
-
sessionFilePath: lastIteration?.sessionFilePath,
|
|
308
|
-
});
|
|
309
|
-
return { ...baseResult, output };
|
|
310
|
-
}
|
|
311
|
-
return baseResult;
|
|
312
|
-
}
|
|
313
|
-
//# sourceMappingURL=run.js.map
|
package/dist/run.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
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AM,EAAE,CAAC;IACnC,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
package/dist/sandboxExec.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { IsolatedSandboxHandle } from "./SandboxProvider.js";
|
|
2
|
-
/** Execute a command on the host side, returning stdout. Throws on non-zero exit. */
|
|
3
|
-
export declare const execHost: (command: string, cwd: string) => Promise<string>;
|
|
4
|
-
/** Execute a command in the sandbox, throwing if it fails. */
|
|
5
|
-
export declare const execOk: (handle: IsolatedSandboxHandle, command: string, options?: {
|
|
6
|
-
cwd?: string | undefined;
|
|
7
|
-
} | undefined) => Promise<{
|
|
8
|
-
stdout: string;
|
|
9
|
-
stderr: string;
|
|
10
|
-
exitCode: number;
|
|
11
|
-
}>;
|
|
12
|
-
//# sourceMappingURL=sandboxExec.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sandboxExec.d.ts","sourceRoot":"","sources":["../src/sandboxExec.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAIlE,qFAAqF;AACrF,eAAO,MAAM,QAAQ,mDAcpB,CAAC;AAEF,8DAA8D;AAC9D,eAAO,MAAM,MAAM;;;;;;EAYlB,CAAC"}
|
package/dist/sandboxExec.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { exec } from "node:child_process";
|
|
2
|
-
import { promisify } from "node:util";
|
|
3
|
-
const execAsync = promisify(exec);
|
|
4
|
-
/** Execute a command on the host side, returning stdout. Throws on non-zero exit. */
|
|
5
|
-
export const execHost = async (command, cwd) => {
|
|
6
|
-
try {
|
|
7
|
-
const { stdout } = await execAsync(command, {
|
|
8
|
-
cwd,
|
|
9
|
-
maxBuffer: 10 * 1024 * 1024,
|
|
10
|
-
});
|
|
11
|
-
return stdout;
|
|
12
|
-
}
|
|
13
|
-
catch (error) {
|
|
14
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
15
|
-
throw new Error(`Host command failed: ${command}\n${message}`);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
/** Execute a command in the sandbox, throwing if it fails. */
|
|
19
|
-
export const execOk = async (handle, command, options) => {
|
|
20
|
-
const result = await handle.exec(command, options);
|
|
21
|
-
if (result.exitCode !== 0) {
|
|
22
|
-
throw new Error(`Sandbox command failed (exit ${result.exitCode}): ${command}\n${result.stderr}`);
|
|
23
|
-
}
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=sandboxExec.js.map
|
package/dist/sandboxExec.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sandboxExec.js","sourceRoot":"","sources":["../src/sandboxExec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAElC,qFAAqF;AACrF,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAC3B,OAAe,EACf,GAAW,EACM,EAAE;IACnB,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,SAAS,CAAC,OAAO,EAAE;YAC1C,GAAG;YACH,SAAS,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;SAC5B,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,KAAK,OAAO,EAAE,CAAC,CAAC;IACjE,CAAC;AACH,CAAC,CAAC;AAEF,8DAA8D;AAC9D,MAAM,CAAC,M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