This commit is contained in:
Raven Scott
2026-04-26 15:49:55 -04:00
parent 4cdd1569af
commit 2dc388ffd0
26 changed files with 473 additions and 38 deletions
+9 -1
View File
@@ -3931,13 +3931,21 @@ async function bareAgentDispatchTool(o) {
async function captureExec(line, timeoutMs, captureOpts) {
const outPath = paths.cmdOut
const captureExit = Boolean(captureOpts && captureOpts.captureExit)
const trimmed = String(line || '').trim()
const compoundShell =
/\n/.test(trimmed) ||
/(^|[;\s])(for|if|while|until|case|function)\b/.test(trimmed) ||
/\b(do|done|then|else|fi|esac)\b/.test(trimmed) ||
/&&|\|\||\(\(|\{|\}/.test(trimmed)
/**
* Do not wrap with `{ cmd ; }` — Bare OS `splitTokensBySemicolon` splits on every `;`
* at depth 0 and does not treat `{ … }` as a compound, so `{` became argv[0]
* (`unknown command: {`). Redirect only; read exit from env after `execLine`.
*/
const wrapped =
line +
(compoundShell
? 'sh -c ' + bareAgentShellQuote(trimmed)
: line) +
' > ' +
bareAgentShellQuote(outPath) +
' 2>&1'
+23 -2
View File
@@ -153,10 +153,31 @@ async function run(ctx, argv) {
text = nl === -1 ? '' : text.slice(nl + 1)
}
const lines = text.split(/\r?\n/)
const blocks = []
let cur = ''
let depth = 0
for (let i = 0; i < lines.length; i++) {
const trimmed = lines[i].trim()
const raw = lines[i]
const trimmed = raw.trim()
if (!trimmed || trimmed.startsWith('#')) continue
await ctx.execLine(trimmed)
cur += (cur ? '\n' : '') + raw
const words = trimmed
.replace(/[;(){}]/g, ' ')
.split(/\s+/)
.filter(Boolean)
for (const w of words) {
if (w === 'if' || w === 'for' || w === 'while' || w === 'until' || w === 'case')
depth++
else if (w === 'fi' || w === 'done' || w === 'esac') depth = Math.max(0, depth - 1)
}
if (depth === 0) {
blocks.push(cur)
cur = ''
}
}
if (cur.trim()) blocks.push(cur)
for (const block of blocks) {
await ctx.execLine(block)
if ((Number(ctx.exitCode) || 0) !== 0) return
}
ctx.exitCode = 0