Skip to content

Commit 363faca

Browse files
fix: batch session initialization commands (#207)
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9b2f3f6 commit 363faca

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

src/Sandbox.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ export class Sandbox {
136136
this.tracer
137137
);
138138

139+
const commands: string[] = [];
140+
141+
// Ensure .private directory exists if env or git is configured
142+
if (customSession.env || customSession.git) {
143+
commands.push(`mkdir -p "$HOME/.private"`);
144+
}
145+
139146
if (customSession.env) {
140147
const envStrings = Object.entries(customSession.env)
141148
.map(([key, value]) => {
@@ -144,31 +151,34 @@ export class Sandbox {
144151
return `export ${key}='${safe}'`;
145152
})
146153
.join("\n");
147-
const cmd = [
148-
`cat << 'EOF' > "$HOME/.private/.env"`,
149-
envStrings,
150-
`EOF`,
151-
].join("\n");
152-
await client.commands.run(cmd);
154+
commands.push(
155+
[
156+
`cat << 'EOF' > "$HOME/.private/.env"`,
157+
envStrings,
158+
`EOF`,
159+
].join("\n")
160+
);
153161
}
154162

155163
if (customSession.git) {
156-
await Promise.all([
157-
client.commands.run(
158-
`echo "https://${customSession.git.username || "x-access-token"}:${
159-
customSession.git.accessToken
160-
}@${customSession.git.provider}" > $HOME/.private/.gitcredentials`
161-
),
162-
client.commands.run(
163-
`echo "[user]
164+
commands.push(
165+
`echo "https://${customSession.git.username || "x-access-token"}:${
166+
customSession.git.accessToken
167+
}@${customSession.git.provider}" > $HOME/.private/.gitcredentials`
168+
);
169+
commands.push(
170+
`echo "[user]
164171
name = ${customSession.git.name || customSession.id}
165172
email = ${customSession.git.email}
166173
[init]
167174
defaultBranch = main
168175
[credential]
169176
helper = store --file ~/.private/.gitcredentials" > $HOME/.gitconfig`
170-
),
171-
]);
177+
);
178+
}
179+
180+
if (commands.length > 0) {
181+
await client.commands.run(commands.join("\n"));
172182
}
173183

174184
return client;

0 commit comments

Comments
 (0)