The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
import assert from 'node:assert/strict';import {mkdtemp,mkdir,cp,readFile,writeFile,readdir} from 'node:fs/promises';import {tmpdir} from 'node:os';import {join,resolve} from 'node:path';import {fileURLToPath,pathToFileURL} from 'node:url';
import {createGameViewer} from '../viewer/viewer.mjs';import {buildGame,readProject} from '../template/tools/build.mjs';import {browserPath} from '../toolchain/browser.mjs';import {chromium} from '../toolchain/node_modules/playwright-core/index.mjs';
const pkg=fileURLToPath(new URL('..',import.meta.url)),out=resolve(process.env.GAME_QA_ROOT??'work/experience-evidence/relay-browser');await mkdir(out,{recursive:true});const root=await mkdtemp(join(tmpdir(),'relay-browser-'));await cp(join(pkg,'template'),root,{recursive:true});process.env.GAME_DSH_DIR=pkg;await buildGame(root);const server=await createGameViewer(root);await new Promise(r=>server.listen(0,'127.0.0.1',r));const browser=await chromium.launch({executablePath:await browserPath(),headless:true}),context=await browser.newContext({viewport:{width:1512,height:1080},acceptDownloads:true}),page=await context.newPage(),errors=[],checks=[];page.on('pageerror',e=>errors.push(e.message));page.on('console',m=>{if(m.type()==='error'&&!m.text().includes('409'))errors.push(m.text());});const origin='http://127.0.0.1:'+server.address().port;
async function record(name,fn){await fn();checks.push({name,ok:true});console.log('ok '+name);}
async function reveal(){await page.waitForFunction(()=>document.querySelector('#turn-title').textContent.length>0);if(await page.locator('#curtain').isVisible())await page.locator('#reveal').click();}
async function download(click,name){const result=page.waitForEvent('download');await click();const d=await result;await d.saveAs(join(out,name));return join(out,name);}
async function notice(text){await page.waitForFunction(t=>document.querySelector('#notice').textContent.includes(t),text);}
try{
await page.goto(origin);await page.waitForFunction(()=>document.querySelector('#source-state').textContent.includes('Workspace source'));
await record('private view curtain and real human legal choices',async()=>{assert.equal(await page.locator('#curtain').isVisible(),true);assert.equal(await page.locator('#actions').evaluate(e=>e.inert),true);await reveal();await page.locator('#zones details').first().locator('summary').click();assert.ok((await page.locator('#zones details').first().textContent()).includes('A little'));await page.locator('#actions button').first().click();await page.waitForFunction(()=>document.querySelector('#turn-count').textContent==='Turn 1');assert.equal(await page.locator('#curtain').isVisible(),true);await reveal();await page.locator('#actions button').first().click();await page.waitForFunction(()=>document.querySelector('#turn-count').textContent==='Turn 2');await reveal();await page.screenshot({path:join(out,'play.png'),fullPage:true});});
await record('component changes, locks, undo and redo preserve the playing edition',async()=>{await page.locator('#component-form input[name=name]').fill('Silver fern revised');await page.locator('#component-form input[name=name]').blur();assert.equal(await page.locator('#edition-notice').isVisible(),true);await page.locator('#undo-edit').click();assert.equal(await page.locator('#component-form input[name=name]').inputValue(),'Silver fern');await page.locator('#redo-edit').click();assert.equal(await page.locator('#component-form input[name=name]').inputValue(),'Silver fern revised');await page.locator('#lock-component').click();assert.equal(await page.locator('#component-form input[name=name]').isDisabled(),true);await page.locator('#lock-component').click();});
await record('original SVG face import stays editable and embedded',async()=>{const artwork='<svg xmlns="http://www.w3.org/2000/svg" width="630" height="880" viewBox="0 0 630 880"><rect width="630" height="880" fill="#183e42"/><circle cx="315" cy="380" r="210" fill="#d8c992"/><path d="M315 580V200M315 280L200 200M315 350L440 270M315 430L180 340" stroke="#183e42" stroke-width="20" fill="none"/><text x="45" y="75" fill="#f9edcd" font-size="40">SILVER FERN</text><text x="45" y="800" fill="#f9edcd" font-size="28">2 points · leaf</text></svg>';await writeFile(join(out,'original-face.svg'),artwork);await page.locator('#face-file').setInputFiles(join(out,'original-face.svg'));await page.locator('#reset-face').waitFor();assert.equal(await page.locator('#component-preview image').count(),1);});
await record('applying an edition keeps the previous playable game and replay',async()=>{await download(()=>page.locator('#apply-edition').click(),'previous-playtest.zip');await notice('Previous game and replay');await reveal();assert.equal(await page.locator('#turn-count').textContent(),'Turn 0');await page.locator('#save-source').click();await notice('Source saved');const p=await readProject(root);assert.equal(p.components[0].name,'Silver fern revised');assert.match(p.components[0].face,/^data:image\/svg/);assert.ok((await readdir(join(root,'.harness/history'))).length>0);});
await record('concurrent source changes keep both editions',async()=>{await page.locator('#component-form input[name=quantity]').fill('5');await page.locator('#component-form input[name=quantity]').blur();const raw=JSON.parse(await readFile(join(root,'game/project.json'),'utf8'));raw.title='Agent revision';await writeFile(join(root,'game/project.json'),JSON.stringify(raw));await page.locator('#save-source').click();await notice('changed the source');assert.equal(await page.locator('#source-notice').isVisible(),true);await download(()=>page.locator('#keep-draft').click(),'browser-draft.relay.json');await download(()=>page.locator('#load-source').click(),'before-source.relay.json');assert.equal((await readProject(root)).title,'Agent revision');await download(()=>page.locator('#apply-edition').click(),'before-agent.zip');await notice('Previous game and replay');await reveal();assert.equal(await page.locator('#game-title').textContent(),'Agent revision');});
await record('simulation exports contain actual policy outcomes and replays',async()=>{await page.locator('#simulation-count').fill('20');await page.locator('#simulate').click();await page.locator('#save-simulation').waitFor();await download(()=>page.locator('#save-simulation').click(),'simulation.json');const data=JSON.parse(await readFile(join(out,'simulation.json'),'utf8'));assert.equal(data.completed,20);assert.equal(data.errors,0);assert.equal(data.games[0].replay.actions.length,12);assert.match(data.scope,/do not establish/);});
await record('replay verifies actions, rejects tampering and survives reload',async()=>{await page.locator('#actions button').first().click();await page.waitForFunction(()=>document.querySelector('#turn-count').textContent==='Turn 1');await reveal();await download(()=>page.locator('#save-replay').click(),'replay.json');const replay=JSON.parse(await readFile(join(out,'replay.json'),'utf8'));const bad={...replay,state:'{}'};await writeFile(join(out,'bad-replay.json'),JSON.stringify(bad));await page.locator('#replay-file').setInputFiles(join(out,'bad-replay.json'));await notice('does not match');assert.equal(await page.locator('#turn-count').textContent(),'Turn 1');await page.reload();await page.waitForFunction(()=>document.querySelector('#turn-count').textContent==='Turn 1');await reveal();});
await record('complete kit and offline game reopen with real input',async()=>{await download(()=>page.locator('#export-kit').click(),'complete-kit.zip');await page.locator('[data-tab=print]').click();await download(()=>page.locator('#export-html').click(),'offline.html');await page.goto(pathToFileURL(join(out,'offline.html')).href);await reveal();await page.locator('#actions button').first().click();await page.waitForFunction(()=>document.querySelector('#turn-count').textContent==='Turn 1');assert.equal(await page.locator('#save-source').isDisabled(),true);await page.setViewportSize({width:390,height:844});await reveal();await page.screenshot({path:join(out,'mobile.png'),fullPage:true});assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false);});
await record('invalid rule modules keep source editable and a new module recovers',async()=>{await page.setViewportSize({width:1512,height:1080});await page.locator('#edit-rules').click();const old=await page.locator('#rules-code').inputValue();await page.locator('#rules-code').fill('export const incomplete = true;');await page.locator('#editor-apply').click();await download(()=>page.locator('#apply-edition').click(),'before-invalid.zip');await notice('Rules must export');await page.locator('#edit-rules').click();await page.locator('#rules-code').fill(old);await page.locator('#editor-apply').click();await download(()=>page.locator('#apply-edition').click(),'before-recovery.zip');await notice('Previous game and replay');await reveal();assert.equal(await page.locator('#actions button').count(),6);});
await record('a nonterminating module stops without freezing the editor',async()=>{await page.locator('#edit-rules').click();const old=await page.locator('#rules-code').inputValue();await page.locator('#rules-code').fill('export function initial(){while(true){}}; export function legal(){}; export function apply(){}; export function observe(){}; export function outcome(){}; export function validate(){}');await page.locator('#editor-apply').click();await download(()=>page.locator('#apply-edition').click(),'before-timeout.zip');await notice('exceeded the time limit');await page.locator('#edit-rules').click();await page.locator('#rules-code').fill(old);await page.locator('#editor-apply').click();await download(()=>page.locator('#apply-edition').click(),'before-timeout-recovery.zip');await notice('Previous game and replay');await reveal();assert.equal(await page.locator('#actions button').count(),6);});
await page.screenshot({path:join(out,'final.png'),fullPage:true});assert.deepEqual(errors,[]);await writeFile(join(out,'report.json'),JSON.stringify({checks,errors},null,2));console.log(JSON.stringify({out,checks:checks.length,errors}));
}finally{await browser.close();server.closeAllConnections();await new Promise(r=>server.close(r));}