Oregami
Repositories/oxedyne/daimond

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.
2import fs from 'node:fs';
3import { open, connectReal, spend, errors } from './harness.mjs';
4
5const s = await open({ name: 'wf-multi', connect: false });
6const model = await connectReal(s, 'value');
7const t0 = Date.now();
8
9await s.page.click('#new-diamond-btn', { force: true });
10await s.page.waitForSelector('.dlg-input', { timeout: 10000 });
11await s.page.fill('.dlg-input', 'Three files');
12await s.page.click('.dlg-ok', { force: true });
13await 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).
17await 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.');
19await s.page.keyboard.press('Enter');
20
21// Wait for the conductor turn to finish dispatching.
22await s.page.waitForTimeout(2000);
23for (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.
26await s.page.evaluate(() => window.DaimondPanels && DaimondPanels.show('agents'));
27await s.page.waitForTimeout(1000);
28let tiles = 0;
29for (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.
40const 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
50const 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};
58fs.writeFileSync('dev/results/multiagent.json', JSON.stringify(result, null, 2));
59console.log(JSON.stringify(result, null, 2));
60await s.close();