| 45 | const agent = await Agent.create(CONFIG); |
| 46 | |
| 47 | async function once(i) { |
| 48 | const session = agent.session('.', { |
| 49 | guidelines: GUIDELINES, |
| 50 | autoDelegation: { enabled: true, parallel: true }, |
| 51 | maxParallelTasks: 8, |
| 52 | confirmationPolicy: { enabled: true, yoloLanes: ['control', 'query', 'execute', 'generate'], timeoutAction: 'auto_approve' }, |
| 53 | }); |
| 54 | let inProgram = false, progArgs = '', scriptForm = false, directParallel = false, programOk = false, errorSeen = null; |
| 55 | const t0 = Date.now(); |
| 56 | const stream = await session.stream(TASK); |
| 57 | while (true) { |
| 58 | const { value: ev, done } = await stream.next(); |
| 59 | if (done) break; |
| 60 | if (!ev) continue; |
| 61 | const ty = ev.type || ''; |
| 62 | if (ty === 'tool_start' && ev.toolName === 'program') inProgram = true; |
| 63 | if (ty === 'tool_start' && ev.toolName === 'parallel_task') directParallel = true; |
| 64 | if (ty === 'tool_input_delta' && inProgram) progArgs += (ev.text || ''); |
| 65 | if (ty === 'tool_end' && ev.toolName === 'program') { |
| 66 | inProgram = false; |
| 67 | scriptForm = /parallel_task/.test(progArgs); |
| 68 | programOk = /exit_code=0/.test(String(ev.toolOutput || '')) && /parallel_task \(ok/.test(String(ev.toolOutput || '')); |
| 69 | } |
| 70 | if (ty === 'permission_denied') errorSeen = 'permission_denied:' + (ev.toolName || ''); |
| 71 | } |
| 72 | log(`#${i} ${Date.now() - t0}ms scriptForm=${scriptForm} programOk=${programOk} directParallel=${directParallel} err=${errorSeen || 'no'}`); |
| 73 | if (scriptForm && i === 0) { |
| 74 | // Show the actual generated workflow script once, as evidence. |
| 75 | const m = progArgs.match(/"source"\s*:\s*"((?:[^"\\]|\\.)*)"/); |
| 76 | if (m) log(' --- generated workflow script ---\n' + JSON.parse('"' + m[1] + '"').split('\n').map((l) => ' | ' + l).join('\n')); |
| 77 | } |
| 78 | return { i, scriptForm, programOk, directParallel, errorSeen }; |
| 79 | } |
| 80 | |
| 81 | log(`\n=== autonomous ultracode test (strengthened guideline, ${ITERS} iters) ===`); |
| 82 | const rows = []; |