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,validateProject,clone} from './project.mjs';
export const esc=s=>String(s??'').replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
export const slug=s=>s.toLowerCase().replace(/[^a-z0-9]+/g,'-').replace(/^-|-$/g,'').slice(0,70)||'game';
const wrap=(s,width)=>{const lines=[];for(const paragraph of String(s).split('\n')){let row='';for(const word of paragraph.split(/\s+/)){if(!word)continue;if(word.length>width){if(row)lines.push(row);for(let i=0;i<word.length;i+=width)lines.push(word.slice(i,i+width));row='';}else if((row+' '+word).trim().length>width){lines.push(row);row=word;}else row=(row+' '+word).trim();}lines.push(row);}return lines;};
const linesSVG=(lines,x,y,size,fill)=>lines.map((s,i)=>`<text x="${x}" y="${y+i*size*1.35}" font-size="${size}" fill="${fill}">${esc(s)}</text>`).join('');
export function componentInner(c,{back=false}={}){
const w=c.widthMm,h=c.heightMm,pad=Math.min(5,w*.08),round=c.kind==='card'?3:c.kind==='token'?Math.min(w,h)/2:1;
if(back)return`<rect width="${w}" height="${h}" rx="${round}" fill="#203a34"/><path d="M${w*.2} ${h*.5}h${w*.6}M${w*.5} ${h*.2}v${h*.6}" stroke="#e2bd74" stroke-width="1"/><text x="${w/2}" y="${h*.84}" text-anchor="middle" font-size="${Math.min(4,w*.1)}" fill="#fff7e7">RELAY</text>`;
if(c.face)return`<rect width="${w}" height="${h}" fill="${c.color}"/><image width="${w}" height="${h}" preserveAspectRatio="xMidYMid meet" href="${esc(c.face)}"/>`;
const textW=w-pad*2,headSize=Math.min(5,w*.075),headLines=wrap(c.name,Math.floor(textW/(headSize*.57))),foot=Object.entries(c.values).map(([k,v])=>k.replace(/_/g,' ')+': '+v).join(' · ');
const bodySize=Math.min(3.1,w*.048),bodyLines=wrap(c.body,Math.floor(textW/(bodySize*.56))),footSize=Math.min(3,w*.05),footLines=wrap(foot,Math.floor(textW/(footSize*.56)));
const titleY=pad+headSize,artY=Math.max(h*.30,titleY+headLines.length*headSize*1.35+2),bodyY=artY+Math.min(h*.13,12)+bodySize+2,footY=h-pad-footLines.length*footSize*1.35+footSize;
assert(bodyY+Math.max(0,bodyLines.length-1)*bodySize*1.35+2<footY||c.kind!=='card','Text does not fit '+c.name+'. Shorten it or enlarge the card.');
let symbol=`<text x="${w/2}" y="${artY+Math.min(h*.1,9)}" text-anchor="middle" font-size="${Math.min(h*.23,22)}" fill="${c.ink}">${esc(c.symbol)}</text>`;
if(c.kind==='tile'&&typeof c.values.ports==='string'){
const cx=w/2,cy=h/2;symbol='<g stroke="'+c.ink+'" stroke-width="'+Math.min(w,h)*.14+'" stroke-linecap="round">'+[...c.values.ports].map(d=>{const v={N:[cx,0],E:[w,cy],S:[cx,h],W:[0,cy]}[d];return v?`<path d="M${cx} ${cy}L${v[0]} ${v[1]}"/>`:'';}).join('')+'</g>';
return`<rect width="${w}" height="${h}" rx="1" fill="${c.color}"/>${symbol}<text x="3" y="${h-3}" font-size="2.5" fill="${c.ink}">${esc(c.name)}</text>`;
}
if(c.kind==='token')return`<rect width="${w}" height="${h}" rx="${round}" fill="${c.color}"/>${symbol}<text x="${w/2}" y="${h*.85}" text-anchor="middle" font-size="${Math.min(3,w*.07)}" fill="${c.ink}">${esc(c.name)}</text>`;
return`<rect width="${w}" height="${h}" rx="${round}" fill="${c.color}"/><rect x="1.5" y="1.5" width="${w-3}" height="${h-3}" rx="${Math.max(0,round-1)}" fill="none" stroke="${c.ink}" stroke-opacity=".3" stroke-width=".25"/>${linesSVG(headLines,pad,titleY,headSize,c.ink)}${symbol}${linesSVG(bodyLines,pad,bodyY,bodySize,c.ink)}${linesSVG(footLines,pad,footY,footSize,c.ink)}`;
}
export function componentSVG(c,options={}){return`<svg xmlns="http://www.w3.org/2000/svg" width="${c.widthMm}mm" height="${c.heightMm}mm" viewBox="0 0 ${c.widthMm} ${c.heightMm}" font-family="Arial, sans-serif" role="img" aria-label="${esc(options.back?'Card back':c.name)}">${componentInner(c,options)}</svg>`;}
function cuts(x,y,w,h){const g=1.2,l=2.2;return[[x,y],[x+w,y],[x,y+h],[x+w,y+h]].map(([cx,cy])=>`<path d="M${cx-l-g} ${cy}h${l}M${cx+g} ${cy}h${l}M${cx} ${cy-l-g}v${l}M${cx} ${cy+g}v${l}"/>`).join('');}
export function sheets(project){validateProject(project);const pages=[];let items=[],x=10,y=14,row=0;const flush=()=>{if(items.length)pages.push(items);items=[];x=10;y=14;row=0;};for(const c of project.components)for(let n=0;n<c.quantity;n++){if(x+c.widthMm>200){x=10;y+=row+6;row=0;}if(y+c.heightMm>287){flush();}assert(y+c.heightMm<=287,'Component too tall for the print sheet.');items.push({id:c.id,copy:n+1,x,y,width:c.widthMm,height:c.heightMm});x+=c.widthMm+6;row=Math.max(row,c.heightMm);}flush();return pages;}
export function sheetSVG(p,items,index,{back=false}={}){return`<svg xmlns="http://www.w3.org/2000/svg" width="210mm" height="297mm" viewBox="0 0 210 297" font-family="Arial, sans-serif"><rect width="210" height="297" fill="white"/><text x="10" y="7" font-size="2.6">${esc(p.title)} · ${back?'optional backs':'components'} · sheet ${index+1} · actual size</text>${items.map(i=>{const c=p.components.find(c=>c.id===i.id);const clip='clip-'+p.id+'-'+index+'-'+i.id+'-'+i.copy+'-'+back;return`<defs><clipPath id="${clip}"><rect width="${i.width}" height="${i.height}"/></clipPath></defs><g transform="translate(${i.x} ${i.y})" clip-path="url(#${clip})">${componentInner(c,{back})}</g>`;}).join('')}<g fill="none" stroke="#333" stroke-width=".15">${items.map(i=>cuts(i.x,i.y,i.width,i.height)).join('')}</g><path d="M10 293h50m-50-1v2m50-2v2" stroke="#333" stroke-width=".2"/><text x="65" y="294" font-size="2.2">50 mm calibration · cut along component edges</text></svg>`;}
export function boardSVG(b){const w=b.widthMm,h=b.heightMm,cw=w/b.cols,ch=(h-12)/b.rows;return`<svg xmlns="http://www.w3.org/2000/svg" width="${w}mm" height="${h}mm" viewBox="0 0 ${w} ${h}" font-family="Arial, sans-serif"><rect width="${w}" height="${h}" fill="#f5eedf"/><text x="4" y="8" font-size="4">${esc(b.name)}</text>${b.cells.map((c,i)=>`<g transform="translate(${i%b.cols*cw} ${12+Math.floor(i/b.cols)*ch})"><rect x=".2" y=".2" width="${cw-.4}" height="${ch-.4}" fill="${c.color}" stroke="#637669" stroke-width=".3"/><text x="${cw/2}" y="${ch/2}" text-anchor="middle" font-size="${Math.min(3.5,cw/8)}" fill="#203a34">${esc(c.label)}</text></g>`).join('')}</svg>`;}
export function printHTML(p){const pages=sheets(p);return`<!doctype html><html><head><meta charset="utf-8"><title>${esc(p.title)} — print components</title><style>@page{size:A4;margin:0}body{margin:0;font-family:Arial,sans-serif}.screen{padding:20px;background:#f4efe4}.page{width:210mm;height:297mm;break-after:page;overflow:hidden}.page:last-child{break-after:auto}.page>svg{display:block;width:210mm;height:297mm}@media print{.screen{display:none}}</style></head><body><div class="screen"><h1>${esc(p.title)}</h1><p>Print at 100% / actual size on A4. Disable browser headers and footers. Check the 50 mm calibration line. Print card backs separately and glue them to fronts or use opaque sleeves; duplex alignment is not assumed. The separate SVG files keep exact physical dimensions.</p><button onclick="print()">Print components / save PDF</button></div>${pages.map((items,i)=>`<section class="page">${sheetSVG(p,items,i)}</section>`).join('')}</body></html>`;}
export function rulebookHTML(p){return`<!doctype html><html lang="en"><head><meta charset="utf-8"><title>${esc(p.title)} — rulebook</title><style>@page{size:A4;margin:17mm;@bottom-center{content:counter(page);font-size:9pt}}body{font:11pt/1.5 Arial,sans-serif;color:#203a34;max-width:760px;margin:35px auto}h1{font-size:28pt;line-height:1.1}h2{font-size:15pt;break-after:avoid}p{white-space:pre-line;orphans:3;widows:3}table{border-collapse:collapse;width:100%;font-size:10pt}td,th{padding:6px;border-bottom:1px solid #b6c8b8;text-align:left;vertical-align:top}tr,li{break-inside:avoid}.settings{break-inside:avoid}.print{background:#edf3e7;padding:15px}@media print{body{margin:0;max-width:none}.print{display:none}}</style></head><body><div class="print"><button onclick="print()">Print rulebook / save PDF</button></div><h1>${esc(p.title)}</h1><p>${esc(p.subtitle)}</p><p>${p.players} player${p.players===1?'':'s'} · ${p.components.reduce((n,c)=>n+c.quantity,0)} physical components</p>${p.rulebook.map(s=>`<h2>${esc(s.heading)}</h2><p>${esc(s.body)}</p>`).join('')}<section class="settings"><h2>This edition’s rule settings</h2><table>${p.settings.map(s=>`<tr><th>${esc(s.label)}</th><td>${s.value}</td></tr>`).join('')}</table></section><h2>Component inventory and values</h2><table><thead><tr><th>Component</th><th>Copies / size</th><th>Rules values</th></tr></thead><tbody>${p.components.map(c=>`<tr><td>${esc(c.name)}</td><td>${c.quantity} × ${c.widthMm} × ${c.heightMm} mm</td><td>${Object.entries(c.values).map(([k,v])=>esc(k)+': '+esc(v)).join('<br>')}</td></tr>`).join('')}</tbody></table><h2>Print and keep</h2><p>Print components at actual size on A4 and check the 50 mm calibration line. Cut at the component edges. Optional backs can be printed separately and glued on or used in opaque sleeves; duplex alignment is not assumed. Board SVGs preserve their dimensions. The kit includes the editable JSON project and complete rules module, plus a playable offline HTML file. Rule or component revisions create a new edition: recheck the physical rulebook when mechanics change.</p></body></html>`;}
export function kitFiles(project,html,replay=null,report=null){const p=validateProject(project),source=clone(p);delete source.rules;const files={'game.html':html,'project.relay.json':JSON.stringify(p,null,2),'source/project.json':JSON.stringify(source,null,2),'source/rules.mjs':p.rules,'print/components.html':printHTML(p),'print/rulebook.html':rulebookHTML(p),'README.txt':`${p.title}\n\nOpen game.html in a modern desktop browser to play and edit without a server. Open project.relay.json within Relay to restore its source. The source/rules.mjs file defines this game’s mechanics. Project files contain gameplay JavaScript; open work you intend to run.\n\nPrint print/components.html at 100% / actual size on A4, no browser headers or footers. Check the 50 mm calibration line. Board SVGs have explicit physical sizes. Optional card backs are separate for gluing or opaque sleeves; no duplex alignment is assumed.\n\nPass-and-play conceals private views from casual observation, not from browser inspection or saved source/replays. Simulations measure the named policy and seeds, not fun or human balance. No online multiplayer or native game-engine importer is claimed.\n\nRelay source and original artwork: Autonomous, MIT license.\n`,'LICENSE.txt':'MIT License\n\nCopyright (c) 2026 Autonomous\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n'};sheets(p).forEach((items,i)=>{files[`print/sheet-${i+1}.svg`]=sheetSVG(p,items,i);files[`print/backs-${i+1}.svg`]=sheetSVG(p,items,i,{back:true});});for(const c of p.components)files[`components/${c.id}.svg`]=componentSVG(c);for(const b of p.boards)files[`boards/${b.id}.svg`]=boardSVG(b);if(replay)files['playtest/replay.json']=JSON.stringify(replay,null,2);if(report)files['playtest/simulation.json']=JSON.stringify(report,null,2);return files;}