@ai-hero/sandcastle 0.14.0 → 0.14.1
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/{SandboxProvider-Chsi-Zs6.d.ts → SandboxProvider-CwRLxIXZ.d.ts} +2 -39
- package/dist/{chunk-BVZWLFFT.js → chunk-4BB7DNPW.js} +3 -3
- package/dist/chunk-4BB7DNPW.js.map +1 -0
- package/dist/chunk-4GZMUHVO.js +60 -0
- package/dist/chunk-4GZMUHVO.js.map +1 -0
- package/dist/{chunk-S6UHPTRG.js → chunk-7JUTKCHL.js} +4 -4
- package/dist/{chunk-S6UHPTRG.js.map → chunk-7JUTKCHL.js.map} +1 -1
- package/dist/chunk-7PHPLDVS.js +284 -0
- package/dist/chunk-7PHPLDVS.js.map +1 -0
- package/dist/{chunk-HSXPRZKG.js → chunk-BXLS4HRY.js} +15 -6
- package/dist/chunk-BXLS4HRY.js.map +1 -0
- package/dist/{chunk-G2R53CVZ.js → chunk-EM4QNWKF.js} +695 -706
- package/dist/chunk-EM4QNWKF.js.map +1 -0
- package/dist/{chunk-STB2U7BB.js → chunk-JEQ4IVQM.js} +384 -264
- package/dist/chunk-JEQ4IVQM.js.map +1 -0
- package/dist/{chunk-VRXR2T3S.js → chunk-L3BU47F6.js} +3 -3
- package/dist/{chunk-VRXR2T3S.js.map → chunk-L3BU47F6.js.map} +1 -1
- package/dist/{chunk-7N7AMUYA.js → chunk-PTJEKJPQ.js} +7 -5
- package/dist/chunk-PTJEKJPQ.js.map +1 -0
- package/dist/{chunk-H2PEFS4W.js → chunk-SAQXFLO2.js} +30 -6
- package/dist/chunk-SAQXFLO2.js.map +1 -0
- package/dist/{chunk-ATA2V2TC.js → chunk-TBVRAXYF.js} +3 -3
- package/dist/{chunk-ATA2V2TC.js.map → chunk-TBVRAXYF.js.map} +1 -1
- package/dist/{chunk-IBK2XNSS.js → chunk-VUOXFCWO.js} +3 -3
- package/dist/{chunk-IBK2XNSS.js.map → chunk-VUOXFCWO.js.map} +1 -1
- package/dist/{chunk-GCLEXPXG.js → chunk-WYOGXC72.js} +46 -84
- package/dist/chunk-WYOGXC72.js.map +1 -0
- package/dist/{chunk-RDW7FNN6.js → chunk-YDQW5IOY.js} +11 -4
- package/dist/chunk-YDQW5IOY.js.map +1 -0
- package/dist/index.d.ts +47 -4
- package/dist/index.js +536 -445
- package/dist/index.js.map +1 -1
- package/dist/main.js +72 -16
- package/dist/main.js.map +1 -1
- package/dist/sandboxes/bwrap.d.ts +1 -1
- package/dist/sandboxes/bwrap.js +9 -17
- package/dist/sandboxes/bwrap.js.map +1 -1
- package/dist/sandboxes/daytona.d.ts +1 -1
- package/dist/sandboxes/daytona.js +82 -79
- package/dist/sandboxes/daytona.js.map +1 -1
- package/dist/sandboxes/docker.d.ts +23 -1
- package/dist/sandboxes/docker.js +6 -5
- package/dist/sandboxes/e2b.d.ts +1 -1
- package/dist/sandboxes/e2b.js +4 -4
- package/dist/sandboxes/modal.d.ts +1 -1
- package/dist/sandboxes/modal.js +1 -1
- package/dist/sandboxes/no-sandbox.d.ts +1 -1
- package/dist/sandboxes/no-sandbox.js +1 -1
- package/dist/sandboxes/podman.d.ts +27 -4
- package/dist/sandboxes/podman.js +18 -45
- package/dist/sandboxes/podman.js.map +1 -1
- package/dist/sandboxes/seatbelt.d.ts +2 -2
- package/dist/sandboxes/seatbelt.js +10 -10
- package/dist/sandboxes/seatbelt.js.map +1 -1
- package/dist/sandboxes/sprites.d.ts +1 -1
- package/dist/sandboxes/sprites.js +25 -4
- package/dist/sandboxes/sprites.js.map +1 -1
- package/dist/sandboxes/vercel.d.ts +10 -1
- package/dist/sandboxes/vercel.js +74 -46
- package/dist/sandboxes/vercel.js.map +1 -1
- package/dist/templates/parallel-planner/main.mts +43 -21
- package/dist/templates/parallel-planner-with-review/main.mts +55 -27
- package/dist/templates/sequential-reviewer/main.mts +1 -1
- package/package.json +7 -3
- package/dist/chunk-7N7AMUYA.js.map +0 -1
- package/dist/chunk-BIF2X6QB.js +0 -94
- package/dist/chunk-BIF2X6QB.js.map +0 -1
- package/dist/chunk-BVZWLFFT.js.map +0 -1
- package/dist/chunk-G2R53CVZ.js.map +0 -1
- package/dist/chunk-GCLEXPXG.js.map +0 -1
- package/dist/chunk-H2PEFS4W.js.map +0 -1
- package/dist/chunk-HSXPRZKG.js.map +0 -1
- package/dist/chunk-RDW7FNN6.js.map +0 -1
- package/dist/chunk-STB2U7BB.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
import { noSandbox } from './chunk-
|
|
3
|
-
import { assertInteractiveSupported } from './chunk-
|
|
4
|
-
export { NativeInteractiveNotSupportedError } from './chunk-
|
|
5
|
-
import { formatErrorMessage } from './chunk-
|
|
6
|
-
import { NodeContext_exports, NodeFileSystem_exports } from './chunk-
|
|
7
|
-
export { NativeSandboxUnavailableError } from './chunk-
|
|
8
|
-
import {
|
|
2
|
+
import { noSandbox } from './chunk-PTJEKJPQ.js';
|
|
3
|
+
import { assertInteractiveSupported } from './chunk-L3BU47F6.js';
|
|
4
|
+
export { NativeInteractiveNotSupportedError } from './chunk-L3BU47F6.js';
|
|
5
|
+
import { Display, getCurrentBranch, generateTempBranchName, pruneStale, create, copyToWorktree, runHostHooks, startSandbox, resolveGitMounts, remove, syncOut, withSandboxLifecycle, hasUncommittedChanges, ClackDisplay, deleteTempBranchIfUnused, startIsolatedSandbox, formatErrorMessage, startBindMountSandbox, FileDisplay, reuseSandboxFactoryLayer, SandboxFactory, WorktreeDockerSandboxFactory, SandboxConfig, execOk, SilentDisplay } from './chunk-EM4QNWKF.js';
|
|
6
|
+
import { NodeContext_exports, NodeFileSystem_exports } from './chunk-7JUTKCHL.js';
|
|
7
|
+
export { NativeSandboxUnavailableError } from './chunk-7JUTKCHL.js';
|
|
8
|
+
import { patchGitMountsForWindows, SANDBOX_REPO_DIR, removeMountTempDirs, makeSandboxFromHandle } from './chunk-7PHPLDVS.js';
|
|
9
9
|
import { registerShutdown } from './chunk-EXYXBRCX.js';
|
|
10
|
-
import { shellEscape } from './chunk-
|
|
11
|
-
export { claudeCode, claudeHostSessionPath, claudeSandboxSessionPath, codex, copilot, cursor, encodeProjectPath, findClaudeSessionOnHost, findCodexSessionOnHost, opencode, pi, transferClaudeSession, transferCodexSession } from './chunk-
|
|
12
|
-
import { CwdError, SyncOutPathError, resolveCwd, PromptError, FileSystem_exports, SessionCaptureError, ForkNotSupportedError, PromptExpansionTimeoutError, AgentError, AgentIdleTimeoutError } from './chunk-
|
|
13
|
-
import { Context_exports, Effect_exports, Layer_exports, Deferred_exports, Runtime_exports, Clock_exports, Duration_exports, Option_exports, Ref_exports
|
|
14
|
-
export { createBindMountSandboxProvider, createIsolatedSandboxProvider } from './chunk-
|
|
10
|
+
import { shellEscape } from './chunk-SAQXFLO2.js';
|
|
11
|
+
export { claudeCode, claudeHostSessionPath, claudeSandboxSessionPath, codex, copilot, cursor, encodeProjectPath, findClaudeSessionOnHost, findCodexSessionOnHost, opencode, pi, transferClaudeSession, transferCodexSession } from './chunk-SAQXFLO2.js';
|
|
12
|
+
import { CwdError, SyncOutPathError, resolveCwd, PromptError, FileSystem_exports, SessionCaptureError, ForkNotSupportedError, PromptExpansionTimeoutError, AgentError, AgentIdleTimeoutError } from './chunk-YDQW5IOY.js';
|
|
13
|
+
import { Context_exports, Effect_exports, Layer_exports, Deferred_exports, Runtime_exports, Fiber_exports, Clock_exports, Duration_exports, Option_exports, Ref_exports } from './chunk-JEQ4IVQM.js';
|
|
14
|
+
export { createBindMountSandboxProvider, createIsolatedSandboxProvider } from './chunk-4BB7DNPW.js';
|
|
15
15
|
import './chunk-6NQPCXSG.js';
|
|
16
16
|
import { mkdirSync, appendFileSync, openSync, fstatSync, readSync, closeSync } from 'fs';
|
|
17
17
|
import path, { join } from 'path';
|
|
18
|
-
import {
|
|
18
|
+
import { inspect, styleText } from 'util';
|
|
19
19
|
import * as clack from '@clack/prompts';
|
|
20
20
|
|
|
21
21
|
createRequire(import.meta.url);
|
|
@@ -220,6 +220,12 @@ var invokeAgent = (sandbox, sandboxRepoDir, prompt, provider, idleTimeoutMs, com
|
|
|
220
220
|
let sessionId;
|
|
221
221
|
let usage;
|
|
222
222
|
let accumulatedOutput = "";
|
|
223
|
+
const getResult = (fallback) => {
|
|
224
|
+
if (resultText !== "" && accumulatedOutput.endsWith(resultText)) {
|
|
225
|
+
return accumulatedOutput;
|
|
226
|
+
}
|
|
227
|
+
return resultText === "" ? fallback : resultText;
|
|
228
|
+
};
|
|
223
229
|
const timeoutSignal = yield* Deferred_exports.make();
|
|
224
230
|
const completionTimeoutDeferred = yield* Deferred_exports.make();
|
|
225
231
|
const runFork = Runtime_exports.runFork(yield* Effect_exports.runtime());
|
|
@@ -254,7 +260,7 @@ var invokeAgent = (sandbox, sandboxRepoDir, prompt, provider, idleTimeoutMs, com
|
|
|
254
260
|
yield* Effect_exports.sleep(Duration_exports.millis(completionTimeoutMs));
|
|
255
261
|
onCompletionTimeout(completionTimeoutMs);
|
|
256
262
|
yield* Deferred_exports.succeed(completionTimeoutDeferred, {
|
|
257
|
-
result:
|
|
263
|
+
result: getResult(accumulatedOutput),
|
|
258
264
|
sessionId,
|
|
259
265
|
usage
|
|
260
266
|
});
|
|
@@ -315,7 +321,6 @@ var invokeAgent = (sandbox, sandboxRepoDir, prompt, provider, idleTimeoutMs, com
|
|
|
315
321
|
onContextWindow(parsed.contextWindow);
|
|
316
322
|
} else if (parsed.type === "result") {
|
|
317
323
|
resultText = parsed.result;
|
|
318
|
-
accumulatedOutput += parsed.result;
|
|
319
324
|
} else if (parsed.type === "tool_call") {
|
|
320
325
|
onToolCall(parsed.name, parsed.args);
|
|
321
326
|
} else if (parsed.type === "session_id") {
|
|
@@ -326,7 +331,9 @@ var invokeAgent = (sandbox, sandboxRepoDir, prompt, provider, idleTimeoutMs, com
|
|
|
326
331
|
streamError = parsed.message;
|
|
327
332
|
}
|
|
328
333
|
}
|
|
329
|
-
if (!completionDetected && completionSignals.some(
|
|
334
|
+
if (!completionDetected && completionSignals.some(
|
|
335
|
+
(sig) => accumulatedOutput.includes(sig) || resultText.includes(sig)
|
|
336
|
+
)) {
|
|
330
337
|
completionDetected = true;
|
|
331
338
|
interruptFiber(warningFiber);
|
|
332
339
|
warningFiber = null;
|
|
@@ -359,7 +366,7 @@ ${errorDetail}`
|
|
|
359
366
|
${streamError}`
|
|
360
367
|
});
|
|
361
368
|
}
|
|
362
|
-
return { result:
|
|
369
|
+
return { result: getResult(execResult.stdout), sessionId, usage };
|
|
363
370
|
}).pipe(
|
|
364
371
|
Effect_exports.ensuring(
|
|
365
372
|
Effect_exports.sync(() => {
|
|
@@ -457,9 +464,17 @@ var orchestrate = (options) => {
|
|
|
457
464
|
ctx.sandboxRepoDir
|
|
458
465
|
);
|
|
459
466
|
yield* display.status(label("Agent started"), "success");
|
|
467
|
+
const pendingOutput = /* @__PURE__ */ new Set();
|
|
468
|
+
const forkOutput = (effect) => {
|
|
469
|
+
const fiber = runFork(effect);
|
|
470
|
+
pendingOutput.add(fiber);
|
|
471
|
+
fiber.addObserver(() => {
|
|
472
|
+
pendingOutput.delete(fiber);
|
|
473
|
+
});
|
|
474
|
+
};
|
|
460
475
|
const textBuffer = new TextDeltaBuffer((chunk) => {
|
|
461
|
-
|
|
462
|
-
|
|
476
|
+
forkOutput(display.textChunk(chunk));
|
|
477
|
+
forkOutput(
|
|
463
478
|
streamEmitter.emit({
|
|
464
479
|
type: "text",
|
|
465
480
|
message: chunk,
|
|
@@ -473,8 +488,8 @@ var orchestrate = (options) => {
|
|
|
473
488
|
};
|
|
474
489
|
const onToolCall = (name, formattedArgs) => {
|
|
475
490
|
textBuffer.flush();
|
|
476
|
-
|
|
477
|
-
|
|
491
|
+
forkOutput(display.toolCall(name, formattedArgs));
|
|
492
|
+
forkOutput(
|
|
478
493
|
streamEmitter.emit({
|
|
479
494
|
type: "toolCall",
|
|
480
495
|
name,
|
|
@@ -485,7 +500,7 @@ var orchestrate = (options) => {
|
|
|
485
500
|
);
|
|
486
501
|
};
|
|
487
502
|
const onRawLine = (line) => {
|
|
488
|
-
|
|
503
|
+
forkOutput(
|
|
489
504
|
streamEmitter.emit({
|
|
490
505
|
type: "raw",
|
|
491
506
|
line,
|
|
@@ -496,10 +511,10 @@ var orchestrate = (options) => {
|
|
|
496
511
|
};
|
|
497
512
|
const onIdleWarning = (minutes) => {
|
|
498
513
|
const msg = minutes === 1 ? "Agent idle for 1 minute" : `Agent idle for ${minutes} minutes`;
|
|
499
|
-
|
|
514
|
+
forkOutput(display.status(label(msg), "warn"));
|
|
500
515
|
};
|
|
501
516
|
const onCompletionTimeout = (timeoutMs) => {
|
|
502
|
-
|
|
517
|
+
forkOutput(
|
|
503
518
|
display.status(
|
|
504
519
|
label(
|
|
505
520
|
`Completion signal seen but agent process is hanging \u2014 force-completing after ${timeoutMs / 1e3}s grace window.`
|
|
@@ -534,8 +549,16 @@ var orchestrate = (options) => {
|
|
|
534
549
|
iterationResumeSession,
|
|
535
550
|
iterationForkSession,
|
|
536
551
|
options.signal
|
|
552
|
+
).pipe(
|
|
553
|
+
// On every exit, abort included: flush the buffered text
|
|
554
|
+
// deltas, then wait for the output forked so far.
|
|
555
|
+
Effect_exports.ensuring(
|
|
556
|
+
Effect_exports.suspend(() => {
|
|
557
|
+
textBuffer.dispose();
|
|
558
|
+
return Fiber_exports.awaitAll([...pendingOutput]);
|
|
559
|
+
})
|
|
560
|
+
)
|
|
537
561
|
);
|
|
538
|
-
textBuffer.dispose();
|
|
539
562
|
yield* display.status(label("Agent stopped"), "info");
|
|
540
563
|
let sessionFilePath;
|
|
541
564
|
let usage = streamUsage;
|
|
@@ -1807,6 +1830,34 @@ var interactive = async (options) => {
|
|
|
1807
1830
|
}
|
|
1808
1831
|
return result;
|
|
1809
1832
|
};
|
|
1833
|
+
|
|
1834
|
+
// src/resolveSandboxPrompt.ts
|
|
1835
|
+
var resolveSandboxPrompt = (options) => Effect_exports.gen(function* () {
|
|
1836
|
+
const resolved = yield* resolvePrompt({
|
|
1837
|
+
prompt: options.prompt,
|
|
1838
|
+
promptFile: options.promptFile
|
|
1839
|
+
});
|
|
1840
|
+
const isInline = resolved.source === "inline";
|
|
1841
|
+
const userArgs = options.promptArgs ?? {};
|
|
1842
|
+
const currentHostBranch = yield* getCurrentBranch(options.hostRepoDir);
|
|
1843
|
+
if (isInline) {
|
|
1844
|
+
yield* validateNoArgsWithInlinePrompt(userArgs);
|
|
1845
|
+
return { text: resolved.text, isInline };
|
|
1846
|
+
}
|
|
1847
|
+
yield* validateNoBuiltInArgOverride(userArgs);
|
|
1848
|
+
const text2 = yield* substitutePromptArgs(
|
|
1849
|
+
resolved.text,
|
|
1850
|
+
{
|
|
1851
|
+
SOURCE_BRANCH: options.branch,
|
|
1852
|
+
TARGET_BRANCH: currentHostBranch,
|
|
1853
|
+
...userArgs
|
|
1854
|
+
},
|
|
1855
|
+
new Set(BUILT_IN_PROMPT_ARG_KEYS)
|
|
1856
|
+
);
|
|
1857
|
+
return { text: text2, isInline };
|
|
1858
|
+
});
|
|
1859
|
+
|
|
1860
|
+
// src/createSandbox.ts
|
|
1810
1861
|
var withAgentEnv = (agent, sandboxProviderEnv) => {
|
|
1811
1862
|
const entries = Object.entries(agent.env);
|
|
1812
1863
|
if (entries.length === 0) {
|
|
@@ -1832,6 +1883,178 @@ var withAgentEnv = (agent, sandboxProviderEnv) => {
|
|
|
1832
1883
|
}
|
|
1833
1884
|
};
|
|
1834
1885
|
};
|
|
1886
|
+
var assertRunOptionsValid = async (runOptions, provider, ctx) => {
|
|
1887
|
+
validateTimeoutOptions(runOptions);
|
|
1888
|
+
const isResuming = runOptions.resumeSession !== void 0 && runOptions.resumeSession !== "";
|
|
1889
|
+
if (isResuming && (runOptions.maxIterations ?? 1) > 1) {
|
|
1890
|
+
throw new Error(
|
|
1891
|
+
"resumeSession cannot be combined with maxIterations > 1. Resume applies to iteration 1 only; multi-iteration resume semantics are not supported."
|
|
1892
|
+
);
|
|
1893
|
+
}
|
|
1894
|
+
if (runOptions.forkSession === true && !isResuming) {
|
|
1895
|
+
throw new Error(
|
|
1896
|
+
"forkSession requires resumeSession. Use sandboxRunResult.fork(prompt) to fork the most recent captured session."
|
|
1897
|
+
);
|
|
1898
|
+
}
|
|
1899
|
+
if (runOptions.forkSession === true) {
|
|
1900
|
+
assertForkSupported(provider);
|
|
1901
|
+
}
|
|
1902
|
+
if (isResuming) {
|
|
1903
|
+
await assertResumeSessionExists({
|
|
1904
|
+
provider,
|
|
1905
|
+
sandboxTag: ctx.providerTag,
|
|
1906
|
+
hostRepoDir: ctx.hostRepoDir,
|
|
1907
|
+
resumeSession: runOptions.resumeSession
|
|
1908
|
+
});
|
|
1909
|
+
}
|
|
1910
|
+
};
|
|
1911
|
+
var resolveRunLogging2 = (runOptions, hostRepoDir, branch) => runOptions.logging ?? {
|
|
1912
|
+
type: "file",
|
|
1913
|
+
path: join(
|
|
1914
|
+
hostRepoDir,
|
|
1915
|
+
".sandcastle",
|
|
1916
|
+
"logs",
|
|
1917
|
+
buildLogFilename(branch, void 0, runOptions.name)
|
|
1918
|
+
)
|
|
1919
|
+
};
|
|
1920
|
+
var buildRunDisplayLayer = (logging, banner) => {
|
|
1921
|
+
if (logging.type !== "file") {
|
|
1922
|
+
return ClackDisplay.layer;
|
|
1923
|
+
}
|
|
1924
|
+
printFileDisplayStartup({ logPath: logging.path, ...banner });
|
|
1925
|
+
return Layer_exports.provide(FileDisplay.layer(logging.path), NodeFileSystem_exports.layer);
|
|
1926
|
+
};
|
|
1927
|
+
var withResumeAndFork = (baseResult, provider, rerun) => {
|
|
1928
|
+
const lastIteration = baseResult.iterations.at(-1);
|
|
1929
|
+
if (!provider.sessionStorage || lastIteration?.sessionId === void 0 || lastIteration.sessionId === "") {
|
|
1930
|
+
return baseResult;
|
|
1931
|
+
}
|
|
1932
|
+
const capturedSessionId = lastIteration.sessionId;
|
|
1933
|
+
return {
|
|
1934
|
+
...baseResult,
|
|
1935
|
+
resume: async (nextPrompt, resumeOptions) => rerun({
|
|
1936
|
+
// The follow-up prompt is inline: drop the template's arguments.
|
|
1937
|
+
promptArgs: void 0,
|
|
1938
|
+
...resumeOptions,
|
|
1939
|
+
prompt: nextPrompt,
|
|
1940
|
+
promptFile: void 0,
|
|
1941
|
+
maxIterations: 1,
|
|
1942
|
+
resumeSession: capturedSessionId
|
|
1943
|
+
}),
|
|
1944
|
+
fork: async (nextPrompt, forkOptions) => rerun({
|
|
1945
|
+
// The follow-up prompt is inline: drop the template's arguments.
|
|
1946
|
+
promptArgs: void 0,
|
|
1947
|
+
...forkOptions,
|
|
1948
|
+
prompt: nextPrompt,
|
|
1949
|
+
promptFile: void 0,
|
|
1950
|
+
maxIterations: 1,
|
|
1951
|
+
resumeSession: capturedSessionId,
|
|
1952
|
+
forkSession: true
|
|
1953
|
+
})
|
|
1954
|
+
};
|
|
1955
|
+
};
|
|
1956
|
+
var resolveRunPrompt2 = (ctx, runOptions) => {
|
|
1957
|
+
const displayRef = Ref_exports.unsafeMake([]);
|
|
1958
|
+
const silentDisplayLayer = SilentDisplay.layer(displayRef);
|
|
1959
|
+
return Effect_exports.runPromise(
|
|
1960
|
+
resolveSandboxPrompt({
|
|
1961
|
+
prompt: runOptions.prompt,
|
|
1962
|
+
promptFile: runOptions.promptFile,
|
|
1963
|
+
promptArgs: runOptions.promptArgs,
|
|
1964
|
+
branch: ctx.branch,
|
|
1965
|
+
hostRepoDir: ctx.hostRepoDir
|
|
1966
|
+
}).pipe(
|
|
1967
|
+
Effect_exports.provide(Layer_exports.mergeAll(NodeContext_exports.layer, silentDisplayLayer))
|
|
1968
|
+
)
|
|
1969
|
+
);
|
|
1970
|
+
};
|
|
1971
|
+
var buildRunLayer2 = (ctx, runOptions, resolvedLogging) => {
|
|
1972
|
+
const runDisplayLayer = buildRunDisplayLayer(resolvedLogging, {
|
|
1973
|
+
agentName: runOptions.name,
|
|
1974
|
+
branch: ctx.branch
|
|
1975
|
+
});
|
|
1976
|
+
const reuseFactoryLayer = reuseSandboxFactoryLayer(
|
|
1977
|
+
{
|
|
1978
|
+
hostWorktreePath: ctx.worktreePath,
|
|
1979
|
+
sandboxRepoPath: ctx.sandboxRepoDir,
|
|
1980
|
+
applyToHost: ctx.applyToHost,
|
|
1981
|
+
bindMountHandle: ctx.bindMountHandle
|
|
1982
|
+
},
|
|
1983
|
+
ctx.sandbox
|
|
1984
|
+
);
|
|
1985
|
+
const streamEmitterLayer = agentStreamEmitterLayer(
|
|
1986
|
+
buildAgentStreamHandler(resolvedLogging)
|
|
1987
|
+
);
|
|
1988
|
+
return Layer_exports.mergeAll(reuseFactoryLayer, runDisplayLayer, streamEmitterLayer);
|
|
1989
|
+
};
|
|
1990
|
+
var orchestrateOnSandbox = (ctx, runOptions, {
|
|
1991
|
+
provider,
|
|
1992
|
+
resolvedPrompt
|
|
1993
|
+
}) => Effect_exports.gen(function* () {
|
|
1994
|
+
const mergeToHead = ctx.branchStrategy?.type === "merge-to-head";
|
|
1995
|
+
const display = yield* Display;
|
|
1996
|
+
yield* display.intro(runOptions.name ?? "sandcastle");
|
|
1997
|
+
const orchestrateResult = yield* orchestrate({
|
|
1998
|
+
hostRepoDir: ctx.hostRepoDir,
|
|
1999
|
+
iterations: runOptions.maxIterations ?? 1,
|
|
2000
|
+
prompt: resolvedPrompt.text,
|
|
2001
|
+
branch: mergeToHead ? void 0 : ctx.branch,
|
|
2002
|
+
provider,
|
|
2003
|
+
completionSignal: runOptions.completionSignal,
|
|
2004
|
+
idleTimeoutSeconds: runOptions.idleTimeoutSeconds,
|
|
2005
|
+
completionTimeoutSeconds: runOptions.completionTimeoutSeconds,
|
|
2006
|
+
name: runOptions.name,
|
|
2007
|
+
resumeSession: runOptions.resumeSession,
|
|
2008
|
+
forkSession: runOptions.forkSession,
|
|
2009
|
+
signal: runOptions.signal,
|
|
2010
|
+
skipPromptExpansion: resolvedPrompt.isInline,
|
|
2011
|
+
timeouts: ctx.timeouts,
|
|
2012
|
+
keepSourceBranch: mergeToHead
|
|
2013
|
+
});
|
|
2014
|
+
const completion = buildCompletionMessage(
|
|
2015
|
+
orchestrateResult.completionSignal,
|
|
2016
|
+
orchestrateResult.iterations.length
|
|
2017
|
+
);
|
|
2018
|
+
yield* display.status(completion.message, completion.severity);
|
|
2019
|
+
for (const line of buildContextWindowLines(orchestrateResult.iterations)) {
|
|
2020
|
+
yield* display.text(line);
|
|
2021
|
+
}
|
|
2022
|
+
return orchestrateResult;
|
|
2023
|
+
});
|
|
2024
|
+
var runOnSandbox = async (ctx, runOptions, rerun) => {
|
|
2025
|
+
runOptions.signal?.throwIfAborted();
|
|
2026
|
+
const provider = withAgentEnv(runOptions.agent, ctx.sandboxProviderEnv);
|
|
2027
|
+
await assertRunOptionsValid(runOptions, provider, ctx);
|
|
2028
|
+
const resolvedPrompt = await resolveRunPrompt2(ctx, runOptions);
|
|
2029
|
+
const resolvedLogging = resolveRunLogging2(
|
|
2030
|
+
runOptions,
|
|
2031
|
+
ctx.hostRepoDir,
|
|
2032
|
+
ctx.branch
|
|
2033
|
+
);
|
|
2034
|
+
const runLayer = buildRunLayer2(ctx, runOptions, resolvedLogging);
|
|
2035
|
+
let result;
|
|
2036
|
+
try {
|
|
2037
|
+
result = await Effect_exports.runPromise(
|
|
2038
|
+
orchestrateOnSandbox(ctx, runOptions, { provider, resolvedPrompt }).pipe(
|
|
2039
|
+
Effect_exports.provide(runLayer)
|
|
2040
|
+
)
|
|
2041
|
+
);
|
|
2042
|
+
} catch (error) {
|
|
2043
|
+
runOptions.signal?.throwIfAborted();
|
|
2044
|
+
throw error;
|
|
2045
|
+
}
|
|
2046
|
+
return withResumeAndFork(
|
|
2047
|
+
{
|
|
2048
|
+
iterations: result.iterations,
|
|
2049
|
+
completionSignal: result.completionSignal,
|
|
2050
|
+
stdout: result.stdout,
|
|
2051
|
+
commits: result.commits,
|
|
2052
|
+
logFilePath: resolvedLogging.type === "file" ? resolvedLogging.path : void 0
|
|
2053
|
+
},
|
|
2054
|
+
provider,
|
|
2055
|
+
async (overrides) => rerun({ ...runOptions, ...overrides })
|
|
2056
|
+
);
|
|
2057
|
+
};
|
|
1835
2058
|
var buildSandboxHandle = (ctx, close) => {
|
|
1836
2059
|
const {
|
|
1837
2060
|
branch,
|
|
@@ -1840,7 +2063,6 @@ var buildSandboxHandle = (ctx, close) => {
|
|
|
1840
2063
|
sandboxRepoDir,
|
|
1841
2064
|
sandbox,
|
|
1842
2065
|
providerHandle,
|
|
1843
|
-
bindMountHandle,
|
|
1844
2066
|
applyToHost,
|
|
1845
2067
|
timeouts,
|
|
1846
2068
|
branchStrategy
|
|
@@ -1850,180 +2072,11 @@ var buildSandboxHandle = (ctx, close) => {
|
|
|
1850
2072
|
branch,
|
|
1851
2073
|
worktreePath,
|
|
1852
2074
|
sandboxId: providerHandle !== void 0 && "sandboxId" in providerHandle ? providerHandle.sandboxId : void 0,
|
|
1853
|
-
run: async (runOptions) =>
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
const isResuming = runOptions.resumeSession !== void 0 && runOptions.resumeSession !== "";
|
|
1859
|
-
if (isResuming && maxIterations > 1) {
|
|
1860
|
-
throw new Error(
|
|
1861
|
-
"resumeSession cannot be combined with maxIterations > 1. Resume applies to iteration 1 only; multi-iteration resume semantics are not supported."
|
|
1862
|
-
);
|
|
1863
|
-
}
|
|
1864
|
-
if (runOptions.forkSession === true && !isResuming) {
|
|
1865
|
-
throw new Error(
|
|
1866
|
-
"forkSession requires resumeSession. Use sandboxRunResult.fork(prompt) to fork the most recent captured session."
|
|
1867
|
-
);
|
|
1868
|
-
}
|
|
1869
|
-
if (runOptions.forkSession === true) {
|
|
1870
|
-
assertForkSupported(provider);
|
|
1871
|
-
}
|
|
1872
|
-
if (isResuming) {
|
|
1873
|
-
await assertResumeSessionExists({
|
|
1874
|
-
provider,
|
|
1875
|
-
sandboxTag: ctx.providerTag,
|
|
1876
|
-
hostRepoDir,
|
|
1877
|
-
resumeSession: runOptions.resumeSession
|
|
1878
|
-
});
|
|
1879
|
-
}
|
|
1880
|
-
const resolved = await Effect_exports.runPromise(
|
|
1881
|
-
resolvePrompt({ prompt, promptFile }).pipe(
|
|
1882
|
-
Effect_exports.provide(NodeContext_exports.layer)
|
|
1883
|
-
)
|
|
1884
|
-
);
|
|
1885
|
-
const rawPrompt = resolved.text;
|
|
1886
|
-
const isInlinePrompt = resolved.source === "inline";
|
|
1887
|
-
const userArgs = runOptions.promptArgs ?? {};
|
|
1888
|
-
const currentHostBranch = await Effect_exports.runPromise(
|
|
1889
|
-
getCurrentBranch(hostRepoDir)
|
|
1890
|
-
);
|
|
1891
|
-
const displayRef = Ref_exports.unsafeMake([]);
|
|
1892
|
-
const silentDisplayLayer = SilentDisplay.layer(displayRef);
|
|
1893
|
-
const resolvedPrompt = await Effect_exports.runPromise(
|
|
1894
|
-
Effect_exports.gen(function* () {
|
|
1895
|
-
if (isInlinePrompt) {
|
|
1896
|
-
yield* validateNoArgsWithInlinePrompt(userArgs);
|
|
1897
|
-
return rawPrompt;
|
|
1898
|
-
}
|
|
1899
|
-
yield* validateNoBuiltInArgOverride(userArgs);
|
|
1900
|
-
const effectiveArgs = {
|
|
1901
|
-
SOURCE_BRANCH: branch,
|
|
1902
|
-
TARGET_BRANCH: currentHostBranch,
|
|
1903
|
-
...userArgs
|
|
1904
|
-
};
|
|
1905
|
-
const builtInArgKeysSet = new Set(BUILT_IN_PROMPT_ARG_KEYS);
|
|
1906
|
-
return yield* substitutePromptArgs(
|
|
1907
|
-
rawPrompt,
|
|
1908
|
-
effectiveArgs,
|
|
1909
|
-
builtInArgKeysSet
|
|
1910
|
-
);
|
|
1911
|
-
}).pipe(Effect_exports.provide(silentDisplayLayer))
|
|
1912
|
-
);
|
|
1913
|
-
const resolvedLogging = runOptions.logging ?? {
|
|
1914
|
-
type: "file",
|
|
1915
|
-
path: join(
|
|
1916
|
-
hostRepoDir,
|
|
1917
|
-
".sandcastle",
|
|
1918
|
-
"logs",
|
|
1919
|
-
buildLogFilename(branch, void 0, runOptions.name)
|
|
1920
|
-
)
|
|
1921
|
-
};
|
|
1922
|
-
const runDisplayLayer = resolvedLogging.type === "file" ? (() => {
|
|
1923
|
-
printFileDisplayStartup({
|
|
1924
|
-
logPath: resolvedLogging.path,
|
|
1925
|
-
agentName: runOptions.name,
|
|
1926
|
-
branch
|
|
1927
|
-
});
|
|
1928
|
-
return Layer_exports.provide(
|
|
1929
|
-
FileDisplay.layer(resolvedLogging.path),
|
|
1930
|
-
NodeFileSystem_exports.layer
|
|
1931
|
-
);
|
|
1932
|
-
})() : silentDisplayLayer;
|
|
1933
|
-
const reuseFactoryLayer = reuseSandboxFactoryLayer(
|
|
1934
|
-
{
|
|
1935
|
-
hostWorktreePath: worktreePath,
|
|
1936
|
-
sandboxRepoPath: sandboxRepoDir,
|
|
1937
|
-
applyToHost,
|
|
1938
|
-
bindMountHandle
|
|
1939
|
-
},
|
|
1940
|
-
sandbox
|
|
1941
|
-
);
|
|
1942
|
-
const streamEmitterLayer = agentStreamEmitterLayer(
|
|
1943
|
-
buildAgentStreamHandler(resolvedLogging)
|
|
1944
|
-
);
|
|
1945
|
-
const runLayer = Layer_exports.mergeAll(
|
|
1946
|
-
reuseFactoryLayer,
|
|
1947
|
-
runDisplayLayer,
|
|
1948
|
-
streamEmitterLayer
|
|
1949
|
-
);
|
|
1950
|
-
let result;
|
|
1951
|
-
try {
|
|
1952
|
-
result = await Effect_exports.runPromise(
|
|
1953
|
-
Effect_exports.gen(function* () {
|
|
1954
|
-
const display = yield* Display;
|
|
1955
|
-
yield* display.intro(runOptions.name ?? "sandcastle");
|
|
1956
|
-
const orchestrateResult = yield* orchestrate({
|
|
1957
|
-
hostRepoDir,
|
|
1958
|
-
iterations: maxIterations,
|
|
1959
|
-
prompt: resolvedPrompt,
|
|
1960
|
-
branch: mergeToHead ? void 0 : branch,
|
|
1961
|
-
provider,
|
|
1962
|
-
completionSignal: runOptions.completionSignal,
|
|
1963
|
-
idleTimeoutSeconds: runOptions.idleTimeoutSeconds,
|
|
1964
|
-
completionTimeoutSeconds: runOptions.completionTimeoutSeconds,
|
|
1965
|
-
name: runOptions.name,
|
|
1966
|
-
resumeSession: runOptions.resumeSession,
|
|
1967
|
-
forkSession: runOptions.forkSession,
|
|
1968
|
-
signal: runOptions.signal,
|
|
1969
|
-
skipPromptExpansion: isInlinePrompt,
|
|
1970
|
-
timeouts,
|
|
1971
|
-
keepSourceBranch: mergeToHead
|
|
1972
|
-
});
|
|
1973
|
-
const completion = buildCompletionMessage(
|
|
1974
|
-
orchestrateResult.completionSignal,
|
|
1975
|
-
orchestrateResult.iterations.length
|
|
1976
|
-
);
|
|
1977
|
-
yield* display.status(completion.message, completion.severity);
|
|
1978
|
-
for (const line of buildContextWindowLines(
|
|
1979
|
-
orchestrateResult.iterations
|
|
1980
|
-
)) {
|
|
1981
|
-
yield* display.text(line);
|
|
1982
|
-
}
|
|
1983
|
-
return orchestrateResult;
|
|
1984
|
-
}).pipe(Effect_exports.provide(runLayer))
|
|
1985
|
-
);
|
|
1986
|
-
} catch (error) {
|
|
1987
|
-
runOptions.signal?.throwIfAborted();
|
|
1988
|
-
throw error;
|
|
1989
|
-
}
|
|
1990
|
-
const baseResult = {
|
|
1991
|
-
iterations: result.iterations,
|
|
1992
|
-
completionSignal: result.completionSignal,
|
|
1993
|
-
stdout: result.stdout,
|
|
1994
|
-
commits: result.commits,
|
|
1995
|
-
logFilePath: resolvedLogging.type === "file" ? resolvedLogging.path : void 0
|
|
1996
|
-
};
|
|
1997
|
-
const lastIteration = result.iterations.at(-1);
|
|
1998
|
-
if (provider.sessionStorage && lastIteration?.sessionId !== void 0 && lastIteration.sessionId !== "") {
|
|
1999
|
-
const capturedSessionId = lastIteration.sessionId;
|
|
2000
|
-
return {
|
|
2001
|
-
...baseResult,
|
|
2002
|
-
resume: (nextPrompt, resumeOptions) => sandboxHandle.run({
|
|
2003
|
-
...runOptions,
|
|
2004
|
-
// The follow-up prompt is inline: drop the template's arguments.
|
|
2005
|
-
promptArgs: void 0,
|
|
2006
|
-
...resumeOptions,
|
|
2007
|
-
prompt: nextPrompt,
|
|
2008
|
-
promptFile: void 0,
|
|
2009
|
-
maxIterations: 1,
|
|
2010
|
-
resumeSession: capturedSessionId
|
|
2011
|
-
}),
|
|
2012
|
-
fork: (nextPrompt, forkOptions) => sandboxHandle.run({
|
|
2013
|
-
...runOptions,
|
|
2014
|
-
// The follow-up prompt is inline: drop the template's arguments.
|
|
2015
|
-
promptArgs: void 0,
|
|
2016
|
-
...forkOptions,
|
|
2017
|
-
prompt: nextPrompt,
|
|
2018
|
-
promptFile: void 0,
|
|
2019
|
-
maxIterations: 1,
|
|
2020
|
-
resumeSession: capturedSessionId,
|
|
2021
|
-
forkSession: true
|
|
2022
|
-
})
|
|
2023
|
-
};
|
|
2024
|
-
}
|
|
2025
|
-
return baseResult;
|
|
2026
|
-
},
|
|
2075
|
+
run: async (runOptions) => runOnSandbox(
|
|
2076
|
+
ctx,
|
|
2077
|
+
runOptions,
|
|
2078
|
+
async (options) => sandboxHandle.run(options)
|
|
2079
|
+
),
|
|
2027
2080
|
interactive: async (interactiveOptions) => {
|
|
2028
2081
|
interactiveOptions.signal?.throwIfAborted();
|
|
2029
2082
|
assertInteractiveSupported(ctx.sandboxProvider);
|
|
@@ -2044,31 +2097,13 @@ var buildSandboxHandle = (ctx, close) => {
|
|
|
2044
2097
|
try {
|
|
2045
2098
|
lifecycleResult = await Effect_exports.runPromise(
|
|
2046
2099
|
Effect_exports.gen(function* () {
|
|
2047
|
-
const
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
yield* validateNoArgsWithInlinePrompt(userArgs);
|
|
2055
|
-
resolvedPrompt = rawPrompt;
|
|
2056
|
-
} else {
|
|
2057
|
-
yield* validateNoBuiltInArgOverride(userArgs);
|
|
2058
|
-
const effectiveArgs = {
|
|
2059
|
-
SOURCE_BRANCH: branch,
|
|
2060
|
-
TARGET_BRANCH: currentHostBranch,
|
|
2061
|
-
...userArgs
|
|
2062
|
-
};
|
|
2063
|
-
const builtInArgKeysSet = new Set(
|
|
2064
|
-
BUILT_IN_PROMPT_ARG_KEYS
|
|
2065
|
-
);
|
|
2066
|
-
resolvedPrompt = yield* substitutePromptArgs(
|
|
2067
|
-
rawPrompt,
|
|
2068
|
-
effectiveArgs,
|
|
2069
|
-
builtInArgKeysSet
|
|
2070
|
-
);
|
|
2071
|
-
}
|
|
2100
|
+
const resolvedPrompt = yield* resolveSandboxPrompt({
|
|
2101
|
+
prompt,
|
|
2102
|
+
promptFile,
|
|
2103
|
+
promptArgs: interactiveOptions.promptArgs,
|
|
2104
|
+
branch,
|
|
2105
|
+
hostRepoDir
|
|
2106
|
+
});
|
|
2072
2107
|
return yield* withSandboxLifecycle(
|
|
2073
2108
|
{
|
|
2074
2109
|
hostRepoDir,
|
|
@@ -2080,11 +2115,11 @@ var buildSandboxHandle = (ctx, close) => {
|
|
|
2080
2115
|
keepSourceBranch: mergeToHead
|
|
2081
2116
|
},
|
|
2082
2117
|
sandbox,
|
|
2083
|
-
(
|
|
2084
|
-
const fullPrompt =
|
|
2085
|
-
resolvedPrompt,
|
|
2086
|
-
|
|
2087
|
-
|
|
2118
|
+
(sandboxCtx) => Effect_exports.gen(function* () {
|
|
2119
|
+
const fullPrompt = resolvedPrompt.isInline ? resolvedPrompt.text : yield* preprocessPrompt(
|
|
2120
|
+
resolvedPrompt.text,
|
|
2121
|
+
sandboxCtx.sandbox,
|
|
2122
|
+
sandboxCtx.sandboxRepoDir
|
|
2088
2123
|
);
|
|
2089
2124
|
const interactiveArgs = buildInteractiveArgs({
|
|
2090
2125
|
prompt: fullPrompt,
|
|
@@ -2247,7 +2282,7 @@ var runOnSandboxReadyHooks = ({
|
|
|
2247
2282
|
`git config --global --add safe.directory "${sandboxRepoDir}"`
|
|
2248
2283
|
);
|
|
2249
2284
|
const sandboxEffects = sandboxOnReady.map(
|
|
2250
|
-
(hook) => sandbox
|
|
2285
|
+
(hook) => execOk(sandbox, hook.command, {
|
|
2251
2286
|
cwd: sandboxRepoDir,
|
|
2252
2287
|
sudo: hook.sudo
|
|
2253
2288
|
})
|
|
@@ -2259,6 +2294,7 @@ var runOnSandboxReadyHooks = ({
|
|
|
2259
2294
|
yield* Effect_exports.all(allEffects, { concurrency: "unbounded" });
|
|
2260
2295
|
});
|
|
2261
2296
|
};
|
|
2297
|
+
var tearDownStartedSandbox = (providerHandle, mountsToClean) => (providerHandle ? Effect_exports.promise(() => providerHandle.close().catch(() => void 0)) : Effect_exports.void).pipe(Effect_exports.andThen(removeMountTempDirs(mountsToClean)));
|
|
2262
2298
|
var closeContainerOnly = (providerHandle, mountsToClean) => {
|
|
2263
2299
|
let closed = false;
|
|
2264
2300
|
return async () => {
|
|
@@ -2273,29 +2309,36 @@ var closeContainerOnly = (providerHandle, mountsToClean) => {
|
|
|
2273
2309
|
return { preservedWorktreePath: void 0 };
|
|
2274
2310
|
};
|
|
2275
2311
|
};
|
|
2312
|
+
var startSandboxWithReadyHooks = (options, mountsToClean) => Effect_exports.gen(function* () {
|
|
2313
|
+
const { hostRepoDir, worktreePath } = options;
|
|
2314
|
+
const started = yield* startSandboxOnWorktree({
|
|
2315
|
+
options,
|
|
2316
|
+
hostRepoDir,
|
|
2317
|
+
worktreePath,
|
|
2318
|
+
mountsToClean
|
|
2319
|
+
}).pipe(
|
|
2320
|
+
Effect_exports.onError(() => removeMountTempDirs(mountsToClean)),
|
|
2321
|
+
Effect_exports.provide(NodeContext_exports.layer)
|
|
2322
|
+
);
|
|
2323
|
+
yield* runOnSandboxReadyHooks({
|
|
2324
|
+
sandbox: started.sandbox,
|
|
2325
|
+
sandboxRepoDir: started.sandboxRepoDir,
|
|
2326
|
+
worktreePath,
|
|
2327
|
+
hooks: options.hooks
|
|
2328
|
+
}).pipe(
|
|
2329
|
+
Effect_exports.onError(
|
|
2330
|
+
() => tearDownStartedSandbox(started.providerHandle, mountsToClean)
|
|
2331
|
+
)
|
|
2332
|
+
);
|
|
2333
|
+
return started;
|
|
2334
|
+
});
|
|
2276
2335
|
var createSandboxFromWorktree = async (options) => {
|
|
2277
2336
|
const { branch, worktreePath, hostRepoDir } = options;
|
|
2278
2337
|
validateTimeoutOptions(options);
|
|
2279
2338
|
await Effect_exports.runPromise(copyIntoWorktree(options, hostRepoDir, worktreePath));
|
|
2280
2339
|
const mountsToClean = [];
|
|
2281
2340
|
const { providerHandle, sandbox, sandboxRepoDir } = await Effect_exports.runPromise(
|
|
2282
|
-
|
|
2283
|
-
options,
|
|
2284
|
-
hostRepoDir,
|
|
2285
|
-
worktreePath,
|
|
2286
|
-
mountsToClean
|
|
2287
|
-
}).pipe(
|
|
2288
|
-
Effect_exports.onError(() => removeMountTempDirs(mountsToClean)),
|
|
2289
|
-
Effect_exports.provide(NodeContext_exports.layer)
|
|
2290
|
-
)
|
|
2291
|
-
);
|
|
2292
|
-
await Effect_exports.runPromise(
|
|
2293
|
-
runOnSandboxReadyHooks({
|
|
2294
|
-
sandbox,
|
|
2295
|
-
sandboxRepoDir,
|
|
2296
|
-
worktreePath,
|
|
2297
|
-
hooks: options.hooks
|
|
2298
|
-
})
|
|
2341
|
+
startSandboxWithReadyHooks(options, mountsToClean)
|
|
2299
2342
|
);
|
|
2300
2343
|
return buildSandboxHandle(
|
|
2301
2344
|
{
|
|
@@ -2311,85 +2354,97 @@ var createSandboxFromWorktree = async (options) => {
|
|
|
2311
2354
|
closeContainerOnly(providerHandle, mountsToClean)
|
|
2312
2355
|
);
|
|
2313
2356
|
};
|
|
2357
|
+
var prepareSandboxOnWorktree = (options, target) => Effect_exports.gen(function* () {
|
|
2358
|
+
const { hostRepoDir, worktreePath, mountsToClean } = target;
|
|
2359
|
+
yield* copyIntoWorktree(options, hostRepoDir, worktreePath);
|
|
2360
|
+
const onWorktreeReady = options.hooks?.host?.onWorktreeReady;
|
|
2361
|
+
if (onWorktreeReady !== void 0 && onWorktreeReady.length > 0) {
|
|
2362
|
+
yield* runHostHooks(onWorktreeReady, worktreePath);
|
|
2363
|
+
}
|
|
2364
|
+
const { providerHandle, sandbox, sandboxRepoDir } = yield* startSandboxOnWorktree({
|
|
2365
|
+
options,
|
|
2366
|
+
hostRepoDir,
|
|
2367
|
+
worktreePath,
|
|
2368
|
+
mountsToClean
|
|
2369
|
+
});
|
|
2370
|
+
yield* runOnSandboxReadyHooks({
|
|
2371
|
+
sandbox,
|
|
2372
|
+
sandboxRepoDir,
|
|
2373
|
+
worktreePath,
|
|
2374
|
+
hooks: options.hooks
|
|
2375
|
+
}).pipe(
|
|
2376
|
+
Effect_exports.onError(
|
|
2377
|
+
() => tearDownStartedSandbox(providerHandle, mountsToClean)
|
|
2378
|
+
)
|
|
2379
|
+
);
|
|
2380
|
+
return { providerHandle, sandbox, sandboxRepoDir };
|
|
2381
|
+
});
|
|
2382
|
+
var setUpWorktreeSandbox = (options, mountsToClean) => Effect_exports.gen(function* () {
|
|
2383
|
+
const hostRepoDir = yield* resolveCwd(options.cwd);
|
|
2384
|
+
yield* pruneStale(hostRepoDir).pipe(
|
|
2385
|
+
Effect_exports.catchAll(() => Effect_exports.void)
|
|
2386
|
+
);
|
|
2387
|
+
const { path: worktreePath } = yield* create(hostRepoDir, {
|
|
2388
|
+
branch: options.branch,
|
|
2389
|
+
baseBranch: options.baseBranch
|
|
2390
|
+
});
|
|
2391
|
+
const prepared = yield* prepareSandboxOnWorktree(options, {
|
|
2392
|
+
hostRepoDir,
|
|
2393
|
+
worktreePath,
|
|
2394
|
+
mountsToClean
|
|
2395
|
+
}).pipe(
|
|
2396
|
+
Effect_exports.onError(
|
|
2397
|
+
() => remove(worktreePath).pipe(
|
|
2398
|
+
Effect_exports.catchAll(() => Effect_exports.void),
|
|
2399
|
+
Effect_exports.andThen(removeMountTempDirs(mountsToClean))
|
|
2400
|
+
)
|
|
2401
|
+
)
|
|
2402
|
+
);
|
|
2403
|
+
return { hostRepoDir, worktreePath, ...prepared };
|
|
2404
|
+
});
|
|
2405
|
+
var printWorktreePreserved = (worktreePath) => {
|
|
2406
|
+
console.error(`
|
|
2407
|
+
Worktree preserved at ${worktreePath}`);
|
|
2408
|
+
console.error(` To review: cd ${worktreePath}`);
|
|
2409
|
+
console.error(` To clean up: git worktree remove --force ${worktreePath}`);
|
|
2410
|
+
};
|
|
2411
|
+
var closeSandboxAndWorktree = (target) => Effect_exports.gen(function* () {
|
|
2412
|
+
const { providerHandle, mountsToClean, worktreePath } = target;
|
|
2413
|
+
if (providerHandle) {
|
|
2414
|
+
yield* Effect_exports.promise(() => providerHandle.close());
|
|
2415
|
+
}
|
|
2416
|
+
yield* removeMountTempDirs(mountsToClean);
|
|
2417
|
+
const isDirty = yield* hasUncommittedChanges(
|
|
2418
|
+
worktreePath
|
|
2419
|
+
).pipe(Effect_exports.catchAll(() => Effect_exports.succeed(false)));
|
|
2420
|
+
if (isDirty) {
|
|
2421
|
+
return { preservedWorktreePath: worktreePath };
|
|
2422
|
+
}
|
|
2423
|
+
yield* remove(worktreePath).pipe(
|
|
2424
|
+
Effect_exports.catchAll(() => Effect_exports.void)
|
|
2425
|
+
);
|
|
2426
|
+
return { preservedWorktreePath: void 0 };
|
|
2427
|
+
});
|
|
2314
2428
|
var createSandbox = async (options) => {
|
|
2315
2429
|
const { branch } = options;
|
|
2316
2430
|
validateTimeoutOptions(options);
|
|
2317
2431
|
const mountsToClean = [];
|
|
2318
2432
|
const { hostRepoDir, worktreePath, providerHandle, sandbox, sandboxRepoDir } = await Effect_exports.runPromise(
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
Effect_exports.catchAll(() => Effect_exports.void)
|
|
2323
|
-
);
|
|
2324
|
-
const { path: worktreePath2 } = yield* create(
|
|
2325
|
-
hostRepoDir2,
|
|
2326
|
-
{ branch, baseBranch: options.baseBranch }
|
|
2327
|
-
);
|
|
2328
|
-
const prepared = yield* Effect_exports.gen(function* () {
|
|
2329
|
-
yield* copyIntoWorktree(options, hostRepoDir2, worktreePath2);
|
|
2330
|
-
const onWorktreeReady = options.hooks?.host?.onWorktreeReady;
|
|
2331
|
-
if (onWorktreeReady !== void 0 && onWorktreeReady.length > 0) {
|
|
2332
|
-
yield* runHostHooks(onWorktreeReady, worktreePath2);
|
|
2333
|
-
}
|
|
2334
|
-
const { providerHandle: providerHandle2, sandbox: sandbox2, sandboxRepoDir: sandboxRepoDir2 } = yield* startSandboxOnWorktree({
|
|
2335
|
-
options,
|
|
2336
|
-
hostRepoDir: hostRepoDir2,
|
|
2337
|
-
worktreePath: worktreePath2,
|
|
2338
|
-
mountsToClean
|
|
2339
|
-
});
|
|
2340
|
-
yield* runOnSandboxReadyHooks({
|
|
2341
|
-
sandbox: sandbox2,
|
|
2342
|
-
sandboxRepoDir: sandboxRepoDir2,
|
|
2343
|
-
worktreePath: worktreePath2,
|
|
2344
|
-
hooks: options.hooks
|
|
2345
|
-
}).pipe(
|
|
2346
|
-
Effect_exports.onError(
|
|
2347
|
-
() => (providerHandle2 ? Effect_exports.promise(() => providerHandle2.close().catch(() => {
|
|
2348
|
-
})) : Effect_exports.void).pipe(Effect_exports.andThen(removeMountTempDirs(mountsToClean)))
|
|
2349
|
-
)
|
|
2350
|
-
);
|
|
2351
|
-
return { providerHandle: providerHandle2, sandbox: sandbox2, sandboxRepoDir: sandboxRepoDir2 };
|
|
2352
|
-
}).pipe(
|
|
2353
|
-
Effect_exports.onError(
|
|
2354
|
-
() => remove(worktreePath2).pipe(
|
|
2355
|
-
Effect_exports.catchAll(() => Effect_exports.void),
|
|
2356
|
-
Effect_exports.andThen(removeMountTempDirs(mountsToClean))
|
|
2357
|
-
)
|
|
2358
|
-
)
|
|
2359
|
-
);
|
|
2360
|
-
return { hostRepoDir: hostRepoDir2, worktreePath: worktreePath2, ...prepared };
|
|
2361
|
-
}).pipe(Effect_exports.provide(NodeContext_exports.layer))
|
|
2433
|
+
setUpWorktreeSandbox(options, mountsToClean).pipe(
|
|
2434
|
+
Effect_exports.provide(NodeContext_exports.layer)
|
|
2435
|
+
)
|
|
2362
2436
|
);
|
|
2437
|
+
const unregisterShutdown = registerShutdown(() => {
|
|
2438
|
+
printWorktreePreserved(worktreePath);
|
|
2439
|
+
});
|
|
2363
2440
|
let closed = false;
|
|
2364
|
-
const forceCleanup = () => {
|
|
2365
|
-
console.error(`
|
|
2366
|
-
Worktree preserved at ${worktreePath}`);
|
|
2367
|
-
console.error(` To review: cd ${worktreePath}`);
|
|
2368
|
-
console.error(` To clean up: git worktree remove --force ${worktreePath}`);
|
|
2369
|
-
};
|
|
2370
|
-
const unregisterShutdown = registerShutdown(forceCleanup);
|
|
2371
2441
|
const doClose = async () => {
|
|
2372
2442
|
if (closed) {
|
|
2373
2443
|
return { preservedWorktreePath: void 0 };
|
|
2374
2444
|
}
|
|
2375
2445
|
closed = true;
|
|
2376
2446
|
return Effect_exports.runPromise(
|
|
2377
|
-
|
|
2378
|
-
if (providerHandle) {
|
|
2379
|
-
yield* Effect_exports.promise(() => providerHandle.close());
|
|
2380
|
-
}
|
|
2381
|
-
yield* removeMountTempDirs(mountsToClean);
|
|
2382
|
-
const isDirty = yield* hasUncommittedChanges(
|
|
2383
|
-
worktreePath
|
|
2384
|
-
).pipe(Effect_exports.catchAll(() => Effect_exports.succeed(false)));
|
|
2385
|
-
if (isDirty) {
|
|
2386
|
-
return { preservedWorktreePath: worktreePath };
|
|
2387
|
-
}
|
|
2388
|
-
yield* remove(worktreePath).pipe(
|
|
2389
|
-
Effect_exports.catchAll(() => Effect_exports.void)
|
|
2390
|
-
);
|
|
2391
|
-
return { preservedWorktreePath: void 0 };
|
|
2392
|
-
})
|
|
2447
|
+
closeSandboxAndWorktree({ providerHandle, mountsToClean, worktreePath })
|
|
2393
2448
|
);
|
|
2394
2449
|
};
|
|
2395
2450
|
return buildSandboxHandle(
|
|
@@ -2409,6 +2464,122 @@ Worktree preserved at ${worktreePath}`);
|
|
|
2409
2464
|
}
|
|
2410
2465
|
);
|
|
2411
2466
|
};
|
|
2467
|
+
var substituteInteractivePromptArgs = (resolved, args) => Effect_exports.gen(function* () {
|
|
2468
|
+
const rawPrompt = resolved?.text ?? "";
|
|
2469
|
+
if (resolved?.source === "inline") {
|
|
2470
|
+
yield* validateNoArgsWithInlinePrompt(args.promptArgs ?? {});
|
|
2471
|
+
return rawPrompt;
|
|
2472
|
+
}
|
|
2473
|
+
if (resolved === void 0) {
|
|
2474
|
+
return rawPrompt;
|
|
2475
|
+
}
|
|
2476
|
+
const userArgs = args.promptArgs ?? {};
|
|
2477
|
+
yield* validateNoBuiltInArgOverride(userArgs);
|
|
2478
|
+
const currentHostBranch = yield* getCurrentBranch(
|
|
2479
|
+
args.hostRepoDir
|
|
2480
|
+
);
|
|
2481
|
+
return yield* substitutePromptArgs(
|
|
2482
|
+
rawPrompt,
|
|
2483
|
+
{
|
|
2484
|
+
SOURCE_BRANCH: args.sourceBranch,
|
|
2485
|
+
TARGET_BRANCH: currentHostBranch,
|
|
2486
|
+
...userArgs
|
|
2487
|
+
},
|
|
2488
|
+
new Set(BUILT_IN_PROMPT_ARG_KEYS)
|
|
2489
|
+
);
|
|
2490
|
+
});
|
|
2491
|
+
var resolveWorktreeEnv = (hostRepoDir, sources) => resolveEnv(hostRepoDir).pipe(
|
|
2492
|
+
Effect_exports.map((resolvedEnv) => ({
|
|
2493
|
+
...mergeProviderEnv({
|
|
2494
|
+
resolvedEnv,
|
|
2495
|
+
agentProviderEnv: sources.agentProviderEnv,
|
|
2496
|
+
sandboxProviderEnv: sources.sandboxProviderEnv
|
|
2497
|
+
}),
|
|
2498
|
+
...sources.overrides
|
|
2499
|
+
}))
|
|
2500
|
+
);
|
|
2501
|
+
var resolveWorktreeGitMounts = (hostRepoDir, worktreePath) => resolveGitMounts(join(hostRepoDir, ".git")).pipe(
|
|
2502
|
+
Effect_exports.flatMap(
|
|
2503
|
+
(rawGitMounts) => patchGitMountsForWindows(rawGitMounts, worktreePath, SANDBOX_REPO_DIR)
|
|
2504
|
+
)
|
|
2505
|
+
);
|
|
2506
|
+
var startWorktreeRunSandbox = (sandboxProvider, target) => Effect_exports.gen(function* () {
|
|
2507
|
+
const { hostRepoDir, worktreePath, env } = target;
|
|
2508
|
+
const noMounts = [];
|
|
2509
|
+
if (sandboxProvider.tag === "isolated") {
|
|
2510
|
+
const startResult2 = yield* startIsolatedSandbox({
|
|
2511
|
+
provider: sandboxProvider,
|
|
2512
|
+
hostRepoDir: worktreePath,
|
|
2513
|
+
env,
|
|
2514
|
+
copyPaths: target.copyPaths,
|
|
2515
|
+
copySourceDir: hostRepoDir
|
|
2516
|
+
});
|
|
2517
|
+
const hostLink2 = {
|
|
2518
|
+
applyToHost: () => syncOut(worktreePath, startResult2.handle)
|
|
2519
|
+
};
|
|
2520
|
+
return { ...toStarted(startResult2), gitMounts: noMounts, hostLink: hostLink2 };
|
|
2521
|
+
}
|
|
2522
|
+
if (sandboxProvider.tag === "none") {
|
|
2523
|
+
const startResult2 = yield* startSandbox({
|
|
2524
|
+
provider: sandboxProvider,
|
|
2525
|
+
hostRepoDir,
|
|
2526
|
+
env,
|
|
2527
|
+
worktreeOrRepoPath: worktreePath
|
|
2528
|
+
});
|
|
2529
|
+
const hostLink2 = {};
|
|
2530
|
+
return { ...toStarted(startResult2), gitMounts: noMounts, hostLink: hostLink2 };
|
|
2531
|
+
}
|
|
2532
|
+
const gitMounts = yield* resolveWorktreeGitMounts(
|
|
2533
|
+
hostRepoDir,
|
|
2534
|
+
worktreePath
|
|
2535
|
+
);
|
|
2536
|
+
const startResult = yield* startBindMountSandbox({
|
|
2537
|
+
provider: sandboxProvider,
|
|
2538
|
+
hostRepoDir,
|
|
2539
|
+
env,
|
|
2540
|
+
worktreeOrRepoPath: worktreePath,
|
|
2541
|
+
gitMounts,
|
|
2542
|
+
repoDir: SANDBOX_REPO_DIR
|
|
2543
|
+
});
|
|
2544
|
+
const hostLink = { bindMountHandle: startResult.handle };
|
|
2545
|
+
return { ...toStarted(startResult), gitMounts, hostLink };
|
|
2546
|
+
});
|
|
2547
|
+
var skipHostSync = () => Effect_exports.void;
|
|
2548
|
+
var toStarted = (startResult) => ({ handle: startResult.handle, sandboxRepoDir: startResult.worktreePath });
|
|
2549
|
+
var reuseStartedSandboxLayer = (handle, hostLink, paths) => reuseSandboxFactoryLayer(
|
|
2550
|
+
{
|
|
2551
|
+
...paths,
|
|
2552
|
+
applyToHost: hostLink.applyToHost ?? skipHostSync,
|
|
2553
|
+
bindMountHandle: hostLink.bindMountHandle
|
|
2554
|
+
},
|
|
2555
|
+
makeSandboxFromHandle(handle)
|
|
2556
|
+
);
|
|
2557
|
+
var resolveWorktreeRunDisplay = (opts, hostRepoDir, branch) => {
|
|
2558
|
+
const resolvedLogging = opts.logging ?? {
|
|
2559
|
+
type: "file",
|
|
2560
|
+
path: join(
|
|
2561
|
+
hostRepoDir,
|
|
2562
|
+
".sandcastle",
|
|
2563
|
+
"logs",
|
|
2564
|
+
buildLogFilename(branch, void 0, opts.name)
|
|
2565
|
+
)
|
|
2566
|
+
};
|
|
2567
|
+
if (resolvedLogging.type !== "file") {
|
|
2568
|
+
return { resolvedLogging, runDisplayLayer: ClackDisplay.layer };
|
|
2569
|
+
}
|
|
2570
|
+
printFileDisplayStartup({
|
|
2571
|
+
logPath: resolvedLogging.path,
|
|
2572
|
+
agentName: opts.name,
|
|
2573
|
+
branch
|
|
2574
|
+
});
|
|
2575
|
+
return {
|
|
2576
|
+
resolvedLogging,
|
|
2577
|
+
runDisplayLayer: Layer_exports.provide(
|
|
2578
|
+
FileDisplay.layer(resolvedLogging.path),
|
|
2579
|
+
NodeFileSystem_exports.layer
|
|
2580
|
+
)
|
|
2581
|
+
};
|
|
2582
|
+
};
|
|
2412
2583
|
var createWorktree = async (options) => {
|
|
2413
2584
|
validateTimeoutOptions(options);
|
|
2414
2585
|
const branch = options.branchStrategy.type === "branch" ? options.branchStrategy.branch : void 0;
|
|
@@ -2475,36 +2646,20 @@ var createWorktree = async (options) => {
|
|
|
2475
2646
|
}
|
|
2476
2647
|
const inner = Effect_exports.gen(function* () {
|
|
2477
2648
|
const d = yield* Display;
|
|
2478
|
-
const
|
|
2479
|
-
const
|
|
2480
|
-
const rawPrompt = resolved?.text ?? "";
|
|
2481
|
-
const isInlinePrompt = resolved?.source === "inline";
|
|
2482
|
-
const resolvedEnv = yield* resolveEnv(hostRepoDir);
|
|
2483
|
-
const env = mergeProviderEnv({
|
|
2484
|
-
resolvedEnv,
|
|
2649
|
+
const resolved = prompt !== void 0 || promptFile !== void 0 ? yield* resolvePrompt({ prompt, promptFile }) : void 0;
|
|
2650
|
+
const effectiveEnv = yield* resolveWorktreeEnv(hostRepoDir, {
|
|
2485
2651
|
agentProviderEnv: provider.env,
|
|
2486
|
-
sandboxProviderEnv: resolvedSandbox.env
|
|
2652
|
+
sandboxProviderEnv: resolvedSandbox.env,
|
|
2653
|
+
overrides: opts.env
|
|
2487
2654
|
});
|
|
2488
|
-
const
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
TARGET_BRANCH: currentHostBranch,
|
|
2497
|
-
...userArgs
|
|
2498
|
-
};
|
|
2499
|
-
const builtInArgKeysSet = new Set(BUILT_IN_PROMPT_ARG_KEYS);
|
|
2500
|
-
substitutedPrompt = yield* substitutePromptArgs(
|
|
2501
|
-
rawPrompt,
|
|
2502
|
-
effectiveArgs,
|
|
2503
|
-
builtInArgKeysSet
|
|
2504
|
-
);
|
|
2505
|
-
} else if (isInlinePrompt) {
|
|
2506
|
-
yield* validateNoArgsWithInlinePrompt(opts.promptArgs ?? {});
|
|
2507
|
-
}
|
|
2655
|
+
const substitutedPrompt = yield* substituteInteractivePromptArgs(
|
|
2656
|
+
resolved,
|
|
2657
|
+
{
|
|
2658
|
+
promptArgs: opts.promptArgs,
|
|
2659
|
+
hostRepoDir,
|
|
2660
|
+
sourceBranch: worktreeInfo.branch
|
|
2661
|
+
}
|
|
2662
|
+
);
|
|
2508
2663
|
yield* d.intro(opts.name ?? "sandcastle interactive");
|
|
2509
2664
|
yield* d.summary("Interactive Session", {
|
|
2510
2665
|
Agent: opts.name ?? provider.name,
|
|
@@ -2513,6 +2668,7 @@ var createWorktree = async (options) => {
|
|
|
2513
2668
|
});
|
|
2514
2669
|
const mountsToClean = [];
|
|
2515
2670
|
let handle;
|
|
2671
|
+
let applyToHost = skipHostSync;
|
|
2516
2672
|
if (resolvedSandbox.tag === "none") {
|
|
2517
2673
|
handle = yield* Effect_exports.promise(
|
|
2518
2674
|
async () => resolvedSandbox.create({
|
|
@@ -2523,7 +2679,7 @@ var createWorktree = async (options) => {
|
|
|
2523
2679
|
} else if (resolvedSandbox.tag === "isolated") {
|
|
2524
2680
|
const startResult = yield* d.taskLog(
|
|
2525
2681
|
"Starting sandbox",
|
|
2526
|
-
() =>
|
|
2682
|
+
() => startIsolatedSandbox({
|
|
2527
2683
|
provider: resolvedSandbox,
|
|
2528
2684
|
hostRepoDir: worktreeInfo.path,
|
|
2529
2685
|
env: effectiveEnv,
|
|
@@ -2531,14 +2687,12 @@ var createWorktree = async (options) => {
|
|
|
2531
2687
|
copySourceDir: hostRepoDir
|
|
2532
2688
|
})
|
|
2533
2689
|
);
|
|
2534
|
-
handle = startResult
|
|
2690
|
+
({ handle } = startResult);
|
|
2691
|
+
applyToHost = () => syncOut(worktreeInfo.path, startResult.handle);
|
|
2535
2692
|
} else {
|
|
2536
|
-
const
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
rawGitMounts,
|
|
2540
|
-
worktreeInfo.path,
|
|
2541
|
-
SANDBOX_REPO_DIR
|
|
2693
|
+
const gitMounts = yield* resolveWorktreeGitMounts(
|
|
2694
|
+
hostRepoDir,
|
|
2695
|
+
worktreeInfo.path
|
|
2542
2696
|
);
|
|
2543
2697
|
mountsToClean.push(...gitMounts);
|
|
2544
2698
|
const startResult = yield* d.taskLog(
|
|
@@ -2552,7 +2706,7 @@ var createWorktree = async (options) => {
|
|
|
2552
2706
|
repoDir: SANDBOX_REPO_DIR
|
|
2553
2707
|
})
|
|
2554
2708
|
);
|
|
2555
|
-
handle = startResult
|
|
2709
|
+
({ handle } = startResult);
|
|
2556
2710
|
}
|
|
2557
2711
|
return yield* Effect_exports.gen(function* () {
|
|
2558
2712
|
if (!handle.interactiveExec) {
|
|
@@ -2563,7 +2717,6 @@ var createWorktree = async (options) => {
|
|
|
2563
2717
|
const interactiveExecFn = handle.interactiveExec.bind(handle);
|
|
2564
2718
|
const sandbox = makeSandboxFromHandle(handle);
|
|
2565
2719
|
const { worktreePath } = handle;
|
|
2566
|
-
const applyToHost = resolvedSandbox.tag === "isolated" ? () => syncOut(worktreeInfo.path, handle) : () => Effect_exports.void;
|
|
2567
2720
|
const lifecycleEffect = withSandboxLifecycle(
|
|
2568
2721
|
{
|
|
2569
2722
|
hostRepoDir,
|
|
@@ -2580,11 +2733,11 @@ var createWorktree = async (options) => {
|
|
|
2580
2733
|
},
|
|
2581
2734
|
sandbox,
|
|
2582
2735
|
(ctx) => Effect_exports.gen(function* () {
|
|
2583
|
-
const fullPrompt =
|
|
2736
|
+
const fullPrompt = resolved?.source === "template" ? yield* preprocessPrompt(
|
|
2584
2737
|
substitutedPrompt,
|
|
2585
2738
|
ctx.sandbox,
|
|
2586
2739
|
ctx.sandboxRepoDir
|
|
2587
|
-
);
|
|
2740
|
+
) : substitutedPrompt;
|
|
2588
2741
|
const interactiveArgs = buildInteractiveArgs({
|
|
2589
2742
|
prompt: fullPrompt,
|
|
2590
2743
|
dangerouslySkipPermissions: resolvedSandbox.tag !== "none"
|
|
@@ -2619,10 +2772,9 @@ var createWorktree = async (options) => {
|
|
|
2619
2772
|
}).pipe(
|
|
2620
2773
|
// Always close sandbox handle
|
|
2621
2774
|
Effect_exports.ensuring(
|
|
2622
|
-
Effect_exports.promise(
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
)
|
|
2775
|
+
Effect_exports.promise(
|
|
2776
|
+
async () => handle.close().catch(() => void 0)
|
|
2777
|
+
).pipe(Effect_exports.andThen(removeMountTempDirs(mountsToClean)))
|
|
2626
2778
|
)
|
|
2627
2779
|
);
|
|
2628
2780
|
});
|
|
@@ -2667,13 +2819,11 @@ var createWorktree = async (options) => {
|
|
|
2667
2819
|
const resolved = yield* resolvePrompt({ prompt, promptFile });
|
|
2668
2820
|
const rawPrompt = resolved.text;
|
|
2669
2821
|
const isInlinePrompt = resolved.source === "inline";
|
|
2670
|
-
const
|
|
2671
|
-
const env = mergeProviderEnv({
|
|
2672
|
-
resolvedEnv,
|
|
2822
|
+
const effectiveEnv = yield* resolveWorktreeEnv(hostRepoDir, {
|
|
2673
2823
|
agentProviderEnv: provider.env,
|
|
2674
|
-
sandboxProviderEnv: sandboxProvider.env
|
|
2824
|
+
sandboxProviderEnv: sandboxProvider.env,
|
|
2825
|
+
overrides: opts.env
|
|
2675
2826
|
});
|
|
2676
|
-
const effectiveEnv = { ...env, ...opts.env };
|
|
2677
2827
|
const userArgs = opts.promptArgs ?? {};
|
|
2678
2828
|
let resolvedPrompt;
|
|
2679
2829
|
if (isInlinePrompt) {
|
|
@@ -2694,87 +2844,29 @@ var createWorktree = async (options) => {
|
|
|
2694
2844
|
builtInArgKeysSet
|
|
2695
2845
|
);
|
|
2696
2846
|
}
|
|
2697
|
-
const
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
provider: sandboxProvider,
|
|
2713
|
-
hostRepoDir,
|
|
2714
|
-
env: effectiveEnv,
|
|
2715
|
-
worktreeOrRepoPath: worktreeInfo.path
|
|
2716
|
-
});
|
|
2717
|
-
handle = startResult.handle;
|
|
2718
|
-
sandboxRepoDir = startResult.worktreePath;
|
|
2719
|
-
} else {
|
|
2720
|
-
const gitPath = join(hostRepoDir, ".git");
|
|
2721
|
-
const rawGitMounts = yield* resolveGitMounts(gitPath);
|
|
2722
|
-
const gitMounts = yield* patchGitMountsForWindows(
|
|
2723
|
-
rawGitMounts,
|
|
2724
|
-
worktreeInfo.path,
|
|
2725
|
-
SANDBOX_REPO_DIR
|
|
2726
|
-
);
|
|
2727
|
-
mountsToClean.push(...gitMounts);
|
|
2728
|
-
const startResult = yield* startSandbox({
|
|
2729
|
-
provider: sandboxProvider,
|
|
2730
|
-
hostRepoDir,
|
|
2731
|
-
env: effectiveEnv,
|
|
2732
|
-
worktreeOrRepoPath: worktreeInfo.path,
|
|
2733
|
-
gitMounts,
|
|
2734
|
-
repoDir: SANDBOX_REPO_DIR
|
|
2735
|
-
});
|
|
2736
|
-
handle = startResult.handle;
|
|
2737
|
-
sandboxRepoDir = startResult.worktreePath;
|
|
2738
|
-
}
|
|
2739
|
-
const sandbox = makeSandboxFromHandle(handle);
|
|
2740
|
-
const applyToHost = sandboxProvider.tag === "isolated" ? () => syncOut(worktreeInfo.path, handle) : () => Effect_exports.void;
|
|
2741
|
-
const resolvedLogging = opts.logging ?? {
|
|
2742
|
-
type: "file",
|
|
2743
|
-
path: join(
|
|
2744
|
-
hostRepoDir,
|
|
2745
|
-
".sandcastle",
|
|
2746
|
-
"logs",
|
|
2747
|
-
buildLogFilename(worktreeInfo.branch, void 0, opts.name)
|
|
2748
|
-
)
|
|
2749
|
-
};
|
|
2750
|
-
const runDisplayLayer = resolvedLogging.type === "file" ? (() => {
|
|
2751
|
-
printFileDisplayStartup({
|
|
2752
|
-
logPath: resolvedLogging.path,
|
|
2753
|
-
agentName: opts.name,
|
|
2754
|
-
branch: worktreeInfo.branch
|
|
2755
|
-
});
|
|
2756
|
-
return Layer_exports.provide(
|
|
2757
|
-
FileDisplay.layer(resolvedLogging.path),
|
|
2758
|
-
NodeFileSystem_exports.layer
|
|
2759
|
-
);
|
|
2760
|
-
})() : ClackDisplay.layer;
|
|
2761
|
-
const bindMountHandle = sandboxProvider.tag === "bind-mount" ? handle : void 0;
|
|
2762
|
-
const reuseFactoryLayer = reuseSandboxFactoryLayer(
|
|
2763
|
-
{
|
|
2764
|
-
hostWorktreePath: worktreeInfo.path,
|
|
2765
|
-
sandboxRepoPath: sandboxRepoDir,
|
|
2766
|
-
applyToHost,
|
|
2767
|
-
bindMountHandle
|
|
2768
|
-
},
|
|
2769
|
-
sandbox
|
|
2770
|
-
);
|
|
2771
|
-
const streamEmitterLayer = agentStreamEmitterLayer(
|
|
2772
|
-
buildAgentStreamHandler(resolvedLogging)
|
|
2847
|
+
const {
|
|
2848
|
+
handle,
|
|
2849
|
+
sandboxRepoDir,
|
|
2850
|
+
gitMounts: mountsToClean,
|
|
2851
|
+
hostLink
|
|
2852
|
+
} = yield* startWorktreeRunSandbox(sandboxProvider, {
|
|
2853
|
+
hostRepoDir,
|
|
2854
|
+
worktreePath: worktreeInfo.path,
|
|
2855
|
+
env: effectiveEnv,
|
|
2856
|
+
copyPaths: options.copyToWorktree
|
|
2857
|
+
});
|
|
2858
|
+
const { resolvedLogging, runDisplayLayer } = resolveWorktreeRunDisplay(
|
|
2859
|
+
opts,
|
|
2860
|
+
hostRepoDir,
|
|
2861
|
+
worktreeInfo.branch
|
|
2773
2862
|
);
|
|
2774
2863
|
const runLayer = Layer_exports.mergeAll(
|
|
2775
|
-
|
|
2864
|
+
reuseStartedSandboxLayer(handle, hostLink, {
|
|
2865
|
+
hostWorktreePath: worktreeInfo.path,
|
|
2866
|
+
sandboxRepoPath: sandboxRepoDir
|
|
2867
|
+
}),
|
|
2776
2868
|
runDisplayLayer,
|
|
2777
|
-
|
|
2869
|
+
agentStreamEmitterLayer(buildAgentStreamHandler(resolvedLogging))
|
|
2778
2870
|
);
|
|
2779
2871
|
const result = yield* Effect_exports.gen(function* () {
|
|
2780
2872
|
const display = yield* Display;
|
|
@@ -2814,10 +2906,9 @@ var createWorktree = async (options) => {
|
|
|
2814
2906
|
Effect_exports.provide(runLayer),
|
|
2815
2907
|
// Always close sandbox handle
|
|
2816
2908
|
Effect_exports.ensuring(
|
|
2817
|
-
Effect_exports.promise(
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
)
|
|
2909
|
+
Effect_exports.promise(
|
|
2910
|
+
async () => handle.close().catch(() => void 0)
|
|
2911
|
+
).pipe(Effect_exports.andThen(removeMountTempDirs(mountsToClean)))
|
|
2821
2912
|
)
|
|
2822
2913
|
);
|
|
2823
2914
|
return {
|