Oregami
Repositories/oxedyne/daimond

oxedyne/daimond/dev/wf_diamonds.mjs

3.2 KiB, 1 run

created by r2519314175:841, 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 2 — the Diamonds crystal -> steer -> fold loop with a REAL model.
2import fs from 'node:fs';
3import { open, connectReal, spend, errors } from './harness.mjs';
4
5const s = await open({ name: 'wf-diamonds', connect: false });
6const model = await connectReal(s, 'value');
7const t0 = Date.now();
8
9// Create a Diamond.
10await s.page.click('#new-diamond-btn', { force: true });
11await s.page.waitForSelector('.dlg-input', { timeout: 10000 });
12await s.page.fill('.dlg-input', 'Ship a CSV parser');
13await s.page.click('.dlg-ok', { force: true });
14await s.page.waitForTimeout(1200);
15
16// Steer: ask the crystal agent to record the goal and open threads into crystal.json.
17async function steer(text, wait = 60000) {
18 await s.page.fill('#steer-input', text);
19 await s.page.keyboard.press('Enter');
20 const t = Date.now();
21 while (Date.now() - t < wait) {
22 const busy = await s.page.evaluate(() => (document.getElementById('steer-send')||{}).disabled);
23 if (!busy) break;
24 await s.page.waitForTimeout(400);
25 }
26 await s.page.waitForTimeout(400);
27}
28await steer('Set the crystal for this Diamond: goal is a small Rust CSV parser. Record the goal, and list three open threads: parse a line, handle quoted fields, and write tests. Edit crystal.json to contain this.');
29
30/// The crystal as it stands, read from the store rather than off the panel: the
31/// data is drawn by the Diamond's own page inside a sandboxed frame, so there is
32/// no text in `.crystal-body` for `innerText` to return.
33const crystalNow = () => s.page.evaluate(async () => {
34 const m = await import('/pkg/oxedyne_daimond.js');
35 const app = new m.DaimondApp('http://127.0.0.1/v1/chat/completions', '', 'none', 4096, '', true);
36 const row = JSON.parse(await app.list_diamonds()).find(r => r.name === 'Ship a CSV parser');
37 return row ? await app.read_crystal_data(row.id) : '';
38});
39const crystalV1 = await crystalNow();
40
41// Fold a delta in (a finished piece of work) and accept it.
42await s.page.fill('#fold-delta', 'Decision: use a hand-written state machine, not a regex. The quoted-field thread is now the priority.');
43await s.page.click('#fold-propose', { force: true });
44await s.page.waitForTimeout(1500);
45// wait for the propose (reducer) turn
46for (let i=0;i<40;i++){ if (await s.page.$('.diff-accept')) break; await s.page.waitForTimeout(500); }
47const accept = await s.page.$('.diff-accept');
48let folded = false;
49if (accept && !(await accept.isDisabled())) { await accept.click({ force: true }); await s.page.waitForTimeout(2500); folded = true; }
50const crystalV2 = await crystalNow();
51
52const result = {
53 workflow: 'diamonds', model, elapsedS: ((Date.now()-t0)/1000).toFixed(1),
54 crystalWritten: /csv|parser|thread/i.test(crystalV1),
55 crystalV1_len: crystalV1.length,
56 foldAccepted: folded,
57 crystalChangedAfterFold: crystalV2.length > 0 && crystalV2 !== crystalV1,
58 crystalMentionsDecision: /state machine|regex|quoted/i.test(crystalV2),
59 spendUsd: +(await spend(s)).toFixed(4),
60 consoleErrors: errors(s),
61};
62fs.writeFileSync('dev/results/diamonds.json', JSON.stringify(result, null, 2));
63console.log(JSON.stringify(result, null, 2));
64console.log('--- crystal after fold (first 400) ---\n' + crystalV2.slice(0, 400));
65await s.close();