oxedyne/daimond/dev/wf_multiagent.mjs
2.6 KiB, 1 run
created by r2519314175:843, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | // Workflow 3 — real conductor dispatches parallel workers on partitioned files. |
| 2 | import fs from 'node:fs'; |
| 3 | import { open, connectReal, spend, errors } from './harness.mjs'; |
| 4 | |
| 5 | const s = await open({ name: 'wf-multi', connect: false }); |
| 6 | const model = await connectReal(s, 'value'); |
| 7 | const t0 = Date.now(); |
| 8 | |
| 9 | await s.page.click('#new-diamond-btn', { force: true }); |
| 10 | await s.page.waitForSelector('.dlg-input', { timeout: 10000 }); |
| 11 | await s.page.fill('.dlg-input', 'Three files'); |
| 12 | await s.page.click('.dlg-ok', { force: true }); |
| 13 | await s.page.waitForTimeout(1200); |
| 14 | |
| 15 | // Natural-language instruction — the REAL model must decide to call spawn_agent |
| 16 | // three times (no @tools directive; that is mock-only). |
| 17 | await s.page.fill('#steer-input', |
| 18 | 'Dispatch three separate worker agents to run in parallel. Worker one: use file_write to create alpha.txt containing exactly the word ALPHA. Worker two: create beta.txt containing exactly BETA. Worker three: create gamma.txt containing exactly GAMMA. Give each worker only its own single-file task.'); |
| 19 | await s.page.keyboard.press('Enter'); |
| 20 | |
| 21 | // Wait for the conductor turn to finish dispatching. |
| 22 | await s.page.waitForTimeout(2000); |
| 23 | for (let i=0;i<30;i++){ const busy = await s.page.evaluate(()=>(document.getElementById('steer-send')||{}).disabled); if(!busy)break; await s.page.waitForTimeout(500); } |
| 24 | |
| 25 | // Open the Agents panel and wait for workers to finish. |
| 26 | await s.page.evaluate(() => window.DaimondPanels && DaimondPanels.show('agents')); |
| 27 | await s.page.waitForTimeout(1000); |
| 28 | let tiles = 0; |
| 29 | for (let i=0;i<40;i++){ |
| 30 | const st = await s.page.evaluate(() => { |
| 31 | const cards=[...document.querySelectorAll('#panel-agents .acard')]; |
| 32 | return { n: cards.length, running: cards.filter(c=>/running|queued/.test((c.querySelector('.pill')||{}).textContent||'')).length }; |
| 33 | }); |
| 34 | tiles = st.n; |
| 35 | if (st.n >= 1 && st.running === 0) break; |
| 36 | await s.page.waitForTimeout(1000); |
| 37 | } |
| 38 | |
| 39 | // Check the files landed in OPFS. |
| 40 | const files = await s.page.evaluate(async () => { |
| 41 | const root = await navigator.storage.getDirectory(); |
| 42 | const got = {}; |
| 43 | for (const nm of ['alpha.txt','beta.txt','gamma.txt']) { |
| 44 | try { const fh = await root.getFileHandle(nm); got[nm] = (await (await fh.getFile()).text()).trim(); } |
| 45 | catch { got[nm] = null; } |
| 46 | } |
| 47 | return got; |
| 48 | }); |
| 49 | |
| 50 | const result = { |
| 51 | workflow: 'multi-agent', model, elapsedS: ((Date.now()-t0)/1000).toFixed(1), |
| 52 | workerTiles: tiles, |
| 53 | files, |
| 54 | filesCreated: Object.values(files).filter(Boolean).length, |
| 55 | spendUsd: +(await spend(s)).toFixed(4), |
| 56 | consoleErrors: errors(s), |
| 57 | }; |
| 58 | fs.writeFileSync('dev/results/multiagent.json', JSON.stringify(result, null, 2)); |
| 59 | console.log(JSON.stringify(result, null, 2)); |
| 60 | await s.close(); |