mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-18 09:00:36 +00:00
wip (#256)
This commit is contained in:
parent
99abb9d42e
commit
57a07f6a0a
11 changed files with 206 additions and 113 deletions
|
|
@ -386,11 +386,24 @@ async function getTaskSandboxRuntime(
|
|||
};
|
||||
}
|
||||
|
||||
async function ensureSandboxRepo(c: any, sandbox: any, record: any): Promise<void> {
|
||||
/**
|
||||
* Track whether the sandbox repo has been fully prepared (cloned + fetched + checked out)
|
||||
* for the current actor lifecycle. Subsequent calls can skip the expensive `git fetch`
|
||||
* when `skipFetch` is true (used by sendWorkbenchMessage to avoid blocking on every prompt).
|
||||
*/
|
||||
let sandboxRepoPrepared = false;
|
||||
|
||||
async function ensureSandboxRepo(c: any, sandbox: any, record: any, opts?: { skipFetchIfPrepared?: boolean }): Promise<void> {
|
||||
if (!record.branchName) {
|
||||
throw new Error("cannot prepare a sandbox repo before the task branch exists");
|
||||
}
|
||||
|
||||
// If the repo was already prepared and the caller allows skipping fetch, just return.
|
||||
// The clone, fetch, and checkout already happened on a prior call.
|
||||
if (opts?.skipFetchIfPrepared && sandboxRepoPrepared) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auth = await resolveOrganizationGithubAuth(c, c.state.organizationId);
|
||||
const repository = await getOrCreateRepository(c, c.state.organizationId, c.state.repoId, c.state.repoRemote);
|
||||
const metadata = await repository.getRepositoryMetadata({});
|
||||
|
|
@ -426,6 +439,8 @@ async function ensureSandboxRepo(c: any, sandbox: any, record: any): Promise<voi
|
|||
if ((result.exitCode ?? 0) !== 0) {
|
||||
throw new Error(`sandbox repo preparation failed (${result.exitCode ?? 1}): ${[result.stdout, result.stderr].filter(Boolean).join("")}`);
|
||||
}
|
||||
|
||||
sandboxRepoPrepared = true;
|
||||
}
|
||||
|
||||
async function executeInSandbox(
|
||||
|
|
@ -1191,7 +1206,9 @@ export async function sendWorkbenchMessage(c: any, sessionId: string, text: stri
|
|||
const meta = requireSendableSessionMeta(await readSessionMeta(c, sessionId), sessionId);
|
||||
const record = await ensureWorkbenchSeeded(c);
|
||||
const runtime = await getTaskSandboxRuntime(c, record);
|
||||
await ensureSandboxRepo(c, runtime.sandbox, record);
|
||||
// Skip git fetch on subsequent messages — the repo was already prepared during session
|
||||
// creation. This avoids a 5-30s network round-trip to GitHub on every prompt.
|
||||
await ensureSandboxRepo(c, runtime.sandbox, record, { skipFetchIfPrepared: true });
|
||||
const prompt = [text.trim(), ...attachments.map((attachment: any) => `@ ${attachment.filePath}:${attachment.lineNumber}\n${attachment.lineContent}`)].filter(
|
||||
Boolean,
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue