diacode 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ *{box-sizing:border-box}html{background:var(--paper)}body{margin:0;font:13px/1.45 var(--sans);color:var(--ink);background:var(--paper);-webkit-text-size-adjust:100%}main{padding:12px 12px 18px;max-width:520px;margin:0 auto;overflow-wrap:anywhere}h1,h2{margin:0;font-weight:600}h1{font-size:15px;line-height:1.3}h2{font-size:11.5px;letter-spacing:.04em;text-transform:uppercase;color:var(--slate);margin:0 0 6px;display:flex;align-items:center;gap:6px}section{margin:0 0 16px}b{font-weight:600}code{font:12px var(--mono)}a{color:var(--ember-deep)}button{font:inherit;font-size:12.5px;padding:5px 11px;border-radius:7px;border:1px solid var(--line);background:var(--surface);color:var(--ink);cursor:pointer;min-height:28px}button:hover:not(:disabled){border-color:var(--ink)}button:disabled{opacity:.42;cursor:default}button:focus-visible,a:focus-visible,select:focus-visible,input:focus-visible{outline:3px solid var(--ember);outline-offset:1px}button.primary{background:var(--ember);border-color:var(--ember);color:var(--ink);font-weight:560}button.primary:hover:not(:disabled){filter:brightness(1.06);border-color:var(--ember)}button.danger,button.danger:hover{background:var(--st-failed);border-color:var(--st-failed);color:#fff}button.plain{background:transparent;border-radius:999px;font-size:12px;padding:3px 10px;min-height:0}button.plain.small{font-size:11.5px;padding:1px 9px}button.plain:hover:not(:disabled){background:var(--ground)}button.link{border:0;padding:0;text-align:left;border-radius:4px;font-weight:560;font-size:13px}button.link:hover:not(:disabled){text-decoration:underline;background:transparent}.row{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-top:8px}.row button{white-space:nowrap}.lede{margin:6px 0 0;font-size:12px;line-height:1.5;color:var(--slate)}.lede code{color:var(--ink)}.calm{margin:0;font-size:12.5px;color:var(--slate)}.count{font-size:11px;font-weight:600;letter-spacing:0;padding:0 6px;min-width:18px;text-align:center;border-radius:999px;background:var(--ember);color:var(--ink)}.notice{margin:0 0 10px;padding:7px 10px;border-radius:6px;font-size:12.5px;background:var(--surface);border:1px solid var(--line)}.notice.error{border-color:var(--ember-deep);color:var(--ember-deep)}.head{margin-bottom:14px}.picker{width:100%;margin:0 0 8px;font:inherit;font-size:12px;padding:4px 6px;border:1px solid var(--line);border-radius:6px;background:var(--surface);color:var(--ink)}.phaseline{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin:4px 0 8px;font-size:12px;color:var(--slate)}.phase-pill{display:inline-flex;align-items:center;gap:6px;padding:1px 9px 1px 7px;border:1px solid var(--line);border-radius:999px;background:var(--surface);color:var(--ink);font-weight:560}.phase-pill i{width:8px;height:8px;border-radius:50%}.progress{display:flex;height:8px;border-radius:4px;overflow:hidden;background:var(--line);margin:2px 0 6px}.progress i{display:block}.counts{margin-top:0}.needs{padding:8px 10px 10px;background:var(--ember-tint);border-left:3px solid var(--ember);border-radius:0 8px 8px 0}.needs:has(>.calm){background:transparent;border-left-color:var(--line);padding-left:10px}.inbox{list-style:none;margin:0;padding:0}.inbox-item{padding:9px 0;border-top:1px solid rgb(25 18 15 / .12)}.inbox-item:first-child{border-top:0;padding-top:2px}.inbox-what{display:flex;flex-direction:column;gap:1px}.inbox-detail{font-size:12px;color:var(--slate)}.inbox-item .row input{flex:1 1 130px;min-width:0;font:inherit;font-size:12px;padding:5px 8px;border:1px solid var(--line);border-radius:6px;background:var(--surface);color:var(--ink)}.inbox-item .lede,.inbox-item .err{margin:6px 0 0;font-size:12px}.inbox-item[data-kind=failure]{border-left:3px solid var(--st-failed);padding-left:9px;margin-left:-10px}.agents{display:flex;flex-wrap:wrap;gap:6px;margin:0 0 8px}.agent{display:inline-flex;align-items:center;gap:5px;font-size:11.5px;padding:2px 8px;border:1px solid var(--line);border-radius:999px;color:var(--slate);background:var(--surface)}.agent b{color:var(--ink);font-weight:560}.agent i{width:7px;height:7px;border-radius:50%;background:var(--wire-soft);flex:none}.agent.working i{background:var(--st-working);box-shadow:0 0 0 3px color-mix(in srgb,var(--st-working) 22%,transparent)}.agent.error{border-color:var(--ember-deep);color:var(--ember-deep)}.agent.error i,.agent.quiet i{background:var(--ember-deep)}.agent.gone{opacity:.6}.agent.asking{border-color:var(--st-waiting);color:var(--ink)}.agent.asking i{background:var(--st-waiting);box-shadow:0 0 0 3px color-mix(in srgb,var(--st-waiting) 22%,transparent)}.steplist{list-style:none;margin:0;padding:0}.steplist li{padding:5px 0;border-bottom:1px solid var(--line-soft)}.steplist li:last-child{border-bottom:0}.who{font-size:12px;color:var(--slate);white-space:nowrap}.risk{display:block;font-size:12px;color:var(--ember-deep)}.thumb{display:block;margin:0 0 16px;padding:6px;border:1px solid var(--line);border-radius:8px;background:var(--ground);line-height:0}.thumb:hover{border-color:var(--ink)}.thumb svg{width:100%;height:auto;max-height:150px}.fp{list-style:none;margin:0;padding:0;font-size:12.5px}.fp li{padding:2px 0}.plan-note{display:block;font-weight:560}.plan-note span{font-weight:560}.plan-note b{font-weight:400;color:var(--ink)}.plan-note.new{color:var(--st-done)}.plan-note.changed{color:var(--st-waiting)}.plan-note.removed{color:var(--st-failed)}.plan-note .glyph{vertical-align:-2px}.more{margin:6px 0 0}.foot{padding-top:4px;border-top:1px solid var(--line)}a.open{display:inline-block;margin-top:10px;padding:6px 12px;border:1px solid var(--ink);border-radius:7px;color:var(--ink);text-decoration:none;font-weight:560;font-size:12.5px}a.open:hover{background:var(--ground)}a.open.primary{background:var(--ember);border-color:var(--ember)}.empty h1{margin-bottom:6px}
@@ -0,0 +1,36 @@
1
+ import{a as se,b as K,i as oe,c as J,p as Q,d as re,s as D,S as P,e as ye,f as ke,n as Se,h as ie,w as xe,g as Ae,j as Te,E as Ee,G as Oe,k as Le,l as je,F as X,m as Pe,o as Z,q as Re,r as Ce,t as Ie,u as Ne,v as He,x as Me,y as qe,z as De,A as We,B as _e,C as ce,D as Be,H as Fe,I as Ue,J as Ge,K as ze,L as Ve}from"./fonts-C71K6yRy.js";const i=n=>String(n).replace(/[&<>"]/g,a=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[a]),R={executing:0,paused:1,planning:2};function Ye(n){const a=s=>(s.done??0)/(s.steps||1);return n.filter(s=>s.title!==void 0&&(s.phase??"")in R).sort((s,e)=>R[s.phase]-R[e.phase]||a(s)-a(e))}function Ke(n,a){const s=n.filter(e=>e.title!==void 0);return s.find(e=>e.id===a)??Ye(n)[0]??s[0]}function Je(n){const a=n?.plan;if(!a||a.phase!=="planning")return null;const s=Object.values(a.nodes??{}).filter(r=>r.kind!=="context");if(!s.length)return null;const e=(n?.recent??[]).find(r=>r.actor!=="you"&&(r.ops??[]).some(c=>c.op==="node.add"))?.actor;return e?{key:"approve",kind:"approve",title:`${D(String(e))} drafted this plan: ${s.length} step${s.length===1?"":"s"}`,detail:"Look it over, then approve it: the agent carries it out, and after that its changes to steps and arrows arrive as proposals."}:null}function le(n,a){const s=oe(n),e=a?.exists?se(a.arch,{by:[...a.recent??[]].reverse().find(c=>c.actor!=="you")?.actor}):[],r=Je(n);return{approve:r,plan:s,arch:e,total:Se(n).total+e.length+(r?1:0),shown:s.length+e.length+(r?1:0)}}function Qe(n){const a=n?.plan?.nodes??{},s=new Map((n?.presence??[]).filter(e=>e?.state==="asking").map(e=>[e.actor,e]));return Object.entries(a).filter(([,e])=>e.kind!=="context"&&e.status==="in_progress").map(([e,r])=>{const c=r,l=xe(c),k=n?.derived?.stalled?.[e],u=k?`stalled: ${Ae(k)}`:c.owner&&s.has(c.owner)?Te(s.get(c.owner)):void 0;return{id:e,label:c.label,...l?{who:D(l.who),mark:Oe[l.from],how:Ee[l.from]}:{},...u?{trouble:u}:{}}})}function Xe(n,a){const s=Le(n,a),e=r=>n.nodes[r]?.label??r;return{new:[...s.added].map(e),changed:[...s.changed.keys()].map(e),removed:[...s.removed].map(e),arrows:s.addedArrows.size+s.removedArrows.size}}function ee(n){switch(n){case"planning":return"Planning: an agent's changes land at once.";case"paused":return"Paused: agents finish the step they are on and start nothing new.";case"done":return"This plan is finished.";case"abandoned":return"This plan was abandoned.";default:return""}}const Ze={planning:"Planning",executing:"Executing",paused:"Paused",done:"Done",abandoned:"Abandoned"},et={executing:P.in_progress,paused:P.waiting,done:P.done},y=(n,a="Open in full view")=>`title="${i(n)}">${i(a)}`;function tt({plans:n,id:a,view:s,arch:e,presence:r=[],thumb:c="",now:l=Date.now(),armed:k,notice:u=null,down:A=!1}){const L=o=>i(ie(o)),W=n.filter(o=>o.title!==void 0),_=A?'<p class="notice error" role="alert">The plan server is not answering. What you see may be out of date, and a click will not land until it is back.</p>':"",B=u?`<p class="notice ${u.kind}" role="${u.kind==="error"?"alert":"status"}">${i(u.text)}</p>`:"";if(!s?.plan){const o=s?.error?`<p class="notice error">The plan file has a problem: ${i(s.error)}</p>`:"",g=e?.exists?se(e.arch,{by:[...e.recent??[]].reverse().find(S=>S.actor!=="you")?.actor}):[],b=g.length?`
2
+ <section class="needs" aria-labelledby="h-needs">
3
+ <h2 id="h-needs">Waiting for you <span class="count">${g.length}</span></h2>
4
+ <ul class="inbox">${K(g,{show:S=>`<button class="plain small" data-open-arch="${i(S)}" ${y(S?"Opens the architecture with this proposal on the diagram":"Opens the architecture")}</button>`})}</ul>
5
+ </section>`:"",w=r.filter(S=>S.state!=="gone"),O=oe({presence:w}),be=w.length?`
6
+ <section class="working" aria-labelledby="h-working">
7
+ <h2 id="h-working">Agents</h2>
8
+ ${O.length?`<ul class="inbox">${J(O,{})}</ul>`:Q(w,l,[])}
9
+ </section>`:"";return`${_}${o}${B}${b}${be}<section class="empty"><h1>No plan yet</h1>
10
+ <p class="lede">Ask your agent to draft one with the dcursed tools (“Draft a plan for … with the dcursed tools.”), or start one in the full editor. It shows here as it goes.</p>
11
+ <p><a class="open primary" href="${L({})}" data-open>Open full screen</a></p></section>`}const d=s.plan,E=s.derived?.progress??{done:0,total:0,active:0,waiting:0,failed:0,left:0},f=le(s,e),j=re(d.phase,E,s.listening??[]),fe=!!f.approve&&d.phase==="planning"||f.plan.some(o=>o.kind==="finish"),F=(o,g)=>{const b=!!o.confirm&&k===o.label;return`<button class="${o.primary?"primary":""}${b?" danger":""}" data-phase="${g}" title="${i(o.hint)}">${i(b?o.confirm??o.label:o.label)}</button>`},U=[fe?"":F(j,"first"),j.second?F(j.second,"second"):""].filter(Boolean).join(""),ge=s.stopping?.length?`<p class="lede"><b>Stopping ${i(s.stopping.map(D).join(", "))}:</b> at the next tool call, and the turn ends there.</p>`:"",we=`
12
+ <header class="head">
13
+ ${W.length>1?`<select class="picker" data-pick aria-label="Which plan">${W.map(o=>`<option value="${i(o.id)}"${o.id===a?" selected":""}>${i(o.title??o.id)} · ${i(o.phase??"")}${o.steps?` · ${o.done??0}/${o.steps}`:""}</option>`).join("")}</select>`:""}
14
+ <h1 class="title">${i(d.title)}</h1>
15
+ <p class="phaseline"><span class="phase-pill" data-phase-name="${i(d.phase)}"><i style="background:${et[d.phase]??"var(--wire)"}"></i>${i(Ze[d.phase]??d.phase)}</span> <span class="rev">rev ${i(s.rev)}</span></p>
16
+ ${E.total?`${ye(E)}<p class="lede counts">${i(ke(E))}</p>`:'<p class="lede">No steps yet.</p>'}
17
+ ${U?`<div class="row controls">${U}</div>`:""}
18
+ ${ee(d.phase)?`<p class="lede">${i(ee(d.phase))}</p>`:""}
19
+ ${ge}
20
+ </header>`,G=[f.approve?`<li class="inbox-item" data-kind="approve"><div class="inbox-what"><b>${i(f.approve.title)}</b><span class="inbox-detail">${i(f.approve.detail)}</span></div><div class="row actions"><button class="primary" data-phase="first">Approve plan</button><button class="plain small" data-open ${y("Look at the plan in the full editor")}</button></div></li>`:"",J(f.plan,s,{showStep:o=>`<button class="plain small" data-open-step="${i(o)}" ${y("Opens the full editor at this step")}</button>`,showProposal:o=>`<button class="plain small" data-open-proposal="${i(o)}" ${y("Opens the full editor with this proposal on the diagram")}</button>`}),K(f.arch,{show:o=>`<button class="plain small" data-open-arch="${i(o)}" ${y(o?"Opens the architecture with this proposal on the diagram":"Opens the architecture")}</button>`})].join(""),me=`
21
+ <section class="needs" aria-labelledby="h-needs">
22
+ <h2 id="h-needs">Waiting for you${f.shown?` <span class="count">${f.shown}</span>`:""}</h2>
23
+ ${G?`<ul class="inbox">${G}</ul>`:'<p class="calm">Nothing waits on you.</p>'}
24
+ </section>`,z=Qe(s),V=(s.derived?.ready??[]).slice(0,2).map(o=>d.nodes[o]?.label??o),$e=`
25
+ <section class="working" aria-labelledby="h-working">
26
+ <h2 id="h-working">Working now</h2>
27
+ ${Q(s.presence??[],l,[])}
28
+ ${z.length?`<ul class="steplist">${z.map(o=>`<li data-step="${i(o.id)}"><button class="plain link" data-open-step="${i(o.id)}" ${y("Opens the full editor at this step",o.label)}</button>${o.who?` <span class="who" title="${i(o.how??"")}">${i(o.mark??"")} ${i(o.who)}</span>`:""}${o.trouble?` <span class="risk">${i(o.trouble)}</span>`:""}</li>`).join("")}</ul>`:`<p class="calm">${d.phase==="executing"?"No step is in progress.":"Nothing is in progress."}${d.phase==="executing"&&V.length?` Ready: ${i(V.join(", "))}.`:""}</p>`}
29
+ </section>`,ve=c?`<a class="thumb" href="${L({plan:d.id})}" data-open aria-label="The diagram of ${i(d.title)}: open it in the full editor">${c}</a>`:"";let Y="";if(e?.exists){const o=Xe(e.arch,d),g=w=>o[w].length?`<li class="plan-note ${w}">${je(X[w].icon,{size:12})} <span>${i(X[w].word)}</span> ${o[w].map(O=>`<b>${i(O)}</b>`).join(", ")}</li>`:"",b=[g("new"),g("changed"),g("removed")].join("");Y=`
30
+ <section class="footprint" aria-labelledby="h-arch">
31
+ <h2 id="h-arch">On the architecture</h2>
32
+ ${b?`<ul class="fp">${b}</ul>`:'<p class="calm">This plan changes no box of it yet.</p>'}
33
+ <p class="more"><button class="plain small" data-open-arch="" ${y("Opens the architecture in the full editor","Open the architecture")}</button></p>
34
+ </section>`}return`${_}${B}${we}${me}${$e}${ve}${Y}
35
+ <footer class="foot"><a class="open" href="${L({plan:d.id})}" data-open>Open full screen</a></footer>`}const p=document.getElementById("root"),te=document.title,nt=3e3,t={plans:[],id:void 0,pinned:null,view:null,arch:null,presence:[],notice:null,armed:void 0,down:!1,noServer:!1,unfollow:null,followed:void 0},de="dcursed.compact.plan";try{t.pinned=new URLSearchParams(location.search).get("plan")||decodeURIComponent(location.hash.slice(1))||localStorage.getItem(de)}catch{}function at(n){const a=n?.plan;if(!a||!Object.keys(a.nodes).length)return"";const s=n.layout??{canvas:{width:640,height:240},direction:"LR",nodes:{}},e=Ge({plan:a,layout:s});return ze({...e,canvas:s.canvas??{width:640,height:240},direction:s.direction,title:a.title},{labels:!1,title:`The diagram of ${a.title}`,edge:r=>{const c=Ve[a.nodes[r]?.status??"not_started"];return c?.edge?c.colour:void 0}})}let M="",q=!1;const ne=n=>n.dataset.answer?`a:${n.dataset.answer}`:`g:${n.dataset.from}>${n.dataset.to}`;function $(){if(t.noServer)return;const n=tt({plans:t.plans,id:t.id,view:t.view,arch:t.arch,presence:t.presence,thumb:at(t.view),now:Date.now(),armed:t.armed,notice:t.notice,down:t.down}),a=n.replace(/ah\d+/g,"ah");if(a===M)return;const s=document.activeElement;if(p.contains(s)&&(s instanceof HTMLInputElement||s instanceof HTMLSelectElement)){q=!0;return}q=!1,M=a;const e=[...p.querySelectorAll("input[data-answer], input[data-gate-text]")].map(l=>l).filter(l=>l.value).map(l=>[ne(l),l.value]);p.innerHTML=n;for(const[l,k]of e){const u=[...p.querySelectorAll("input[data-answer], input[data-gate-text]")].map(A=>A).find(A=>ne(A)===l);u&&(u.value=k)}const r=t.view?.plan?le(t.view,t.arch).total:0;document.title=Fe(t.view?.plan?`${t.view.plan.title} · ${te}`:te,r),document.querySelector('link[rel="icon"]')?.setAttribute("href",r>0?"/favicon-needs.svg":"/favicon.svg"),window.parent!==window&&window.parent.postMessage({dcursed:"needs",total:r},"*")}p.addEventListener("focusout",()=>{q&&setTimeout(()=>{p.contains(document.activeElement)||$()},0)});let C=!1,I=!1,ae;async function h(){if(C){I=!0;return}C=!0;try{if(t.plans=await qe(),t.id=Ke(t.plans,t.pinned)?.id,t.view=t.id?await De(t.id):null,t.arch=await We().catch(()=>t.arch),t.presence=t.view?[]:await _e().catch(()=>t.presence),t.down=!1,t.noServer=!1,st(t.id),t.notice?.call){const n=[...t.view?.calls??[],...t.arch?.calls??[]].find(s=>s.id===t.notice?.call),a=n&&ce(n);a&&(t.notice={text:a.text,kind:a.kind,call:n.id})}$()}catch{if(!t.noServer&&!t.down&&(t.down=!0,$()),!t.view&&!t.plans.length){const a=t.noServer;await pe(),a&&!t.noServer&&v(0)}}finally{C=!1,I&&(I=!1,v(0))}}const v=(n=120)=>{clearTimeout(ae),ae=setTimeout(h,n)};function st(n){n!==t.followed&&(t.unfollow?.(),t.followed=n,t.unfollow=n?Ue(n,{change:()=>v(),problem:()=>v(),reconcile:()=>v(),presence:()=>v(),call:a=>{t.notice?.call===a.id&&v(0)},open:a=>{t.down&&(t.down=!1,$()),a&&v(0)},down:()=>{t.down=!0,$()}}):null)}async function pe(){if(await Be()){t.noServer=!1;return}t.noServer=!0,M="",p.innerHTML=`<section class="empty"><h1>No plan server</h1>
36
+ <p class="lede">This view shows the plans of a repository, and needs that repository's plan server. Run <code>npx diacode serve</code> in it, or open the folder in VS Code with the DiaCode extension.</p></section>`}function m(n){t.notice=n,$();const a=n;n.call||setTimeout(()=>{t.notice===a&&(t.notice=null,$())},9e3)}function he(n){const a=n?.[0],s=a&&ce(a);a&&s&&m({text:s.text,kind:s.kind,call:a.id})}function ue(){const n=document.activeElement;p.contains(n)&&n instanceof HTMLInputElement&&n.blur()}async function x(n,a,s){if(!t.view?.plan||!t.id)return!1;const{status:e,body:r}=await Me(t.id,t.view.rev,n,s);return ue(),e===200?(m({text:a,kind:"info"}),he(r.calls)):m({text:`Not done: ${r.why??r.error}`,kind:"error"}),await h(),e===200}async function N(n,a,s){if(!t.arch?.exists)return!1;const{status:e,body:r}=await He(t.arch.rev,n,s);return ue(),e===200?(m({text:a,kind:"info"}),he(r.calls)):m({text:`Not done: ${r.why??r.error}`,kind:"error"}),await h(),e===200}function T(n){if(window.parent!==window){window.parent.postMessage({dcursed:"open",hash:Ne(n)},"*");return}location.assign(ie(n))}async function ot(n){const a=t.view;if(!a?.plan)return;const s=re(a.plan.phase,a.derived?.progress,a.listening??[]),e=n==="second"?s.second:s;if(!e)return;if(e.confirm&&t.armed!==e.label){t.armed=e.label,$(),setTimeout(()=>{t.armed===e.label&&(t.armed=void 0,$())},4e3);return}t.armed=void 0,await x(e.ops,e.message,e.reason)&&e.ops[0]?.op==="plan.stop"&&t.view?.stopping?.length&&!t.notice?.call&&m({text:`Stopped. ${t.view.stopping.map(c=>c.replace(/^opencode:/,"")).join(", ")} stops at the next tool call; the plan is back in planning.`,kind:"info"})}const H=n=>p.querySelector(n);p.addEventListener("click",async n=>{const s=n.target.closest("button, a[data-open]");if(!(s instanceof HTMLElement))return;const e=s.dataset;if(s.tagName==="A"){window.parent!==window&&(n.preventDefault(),T({plan:t.id}));return}if(e.phase)return void ot(e.phase);if(e.open!==void 0)return T({plan:t.id});if(e.openStep)return T({plan:t.id,step:e.openStep});if(e.openProposal)return T({plan:t.id,proposal:e.openProposal});if(e.openArch!==void 0)return T(e.openArch?{architecture:!0,proposal:e.openArch}:{architecture:!0});if(e.archAcceptDraft!==void 0)return void N([{op:"arch.set",phase:"accepted"}],"Accepted. From now on an agent’s changes arrive as proposals.","you accepted the architecture");if(e.archAccept)return void N([{op:"proposal.accept",id:e.archAccept}],`Accepted ${e.archAccept}.`);if(e.archReject){const r=document.querySelector(`[data-arch-why="${CSS.escape(e.archReject)}"]`)?.value.trim();return void N([{op:"proposal.reject",id:e.archReject}],`Rejected ${e.archReject}.`,r||void 0)}if(e.accept)return void x([{op:"proposal.accept",id:e.accept}],`Accepted ${e.accept}.`);if(e.finish!==void 0)return void x([{op:"plan.set",phase:"done"}],"Plan marked done.","you marked the plan done");if(e.permit||e.deny){const r=e.permit??e.deny,c=document.querySelector(`[data-permit-why="${CSS.escape(r)}"]`)?.value.trim(),{status:l}=await Pe(r,e.permit?"allow":"deny",e.deny?c:void 0);return m({text:l===200?e.permit?"Allowed: the agent carries on.":"Denied: the agent is told why.":"That prompt was already answered in the agent's window.",kind:l===200?"info":"error"}),void h()}if(e.reject)return void x([{op:"proposal.reject",id:e.reject}],`Rejected ${e.reject}.`);if(e.reconcile!==void 0){try{await Z(t.id??""),await h()}catch(r){m({text:`The re-planner was not asked: ${r.message}.`,kind:"error"})}return}if(e.gate){const r=`[data-from="${CSS.escape(e.from??"")}"][data-to="${CSS.escape(e.to??"")}"]`,c=Re(e.gate,e.from??"",e.to??"",H(`[data-gate-text]${r}`)?.value??"");if(!c){H(`[data-gate-text]${r}`)?.focus();return}return void x(c.ops,c.message,c.reason)}if(e.act){if(e.act==="replan"){try{await Z(t.id??"",{kind:"failure",step:e.step??""}),await h()}catch(l){m({text:`The re-planner was not asked: ${l.message}.`,kind:"error"})}return}const r=H(`[data-answer="${CSS.escape(e.step??"")}"]`),c=Ce(e.act,e.step??"",r?.value??"");c?x(c.ops,c.message,c.reason):e.act==="answer"&&r?.focus()}});p.addEventListener("keydown",n=>{const a=n.target;if(!(n.key!=="Enter"||!(a instanceof HTMLInputElement))){if(a.dataset.answer)p.querySelector(`[data-act="answer"][data-step="${CSS.escape(a.dataset.answer)}"]`)?.dispatchEvent(new MouseEvent("click",{bubbles:!0}));else if(a.dataset.gateText!==void 0){const s=`[data-from="${CSS.escape(a.dataset.from??"")}"][data-to="${CSS.escape(a.dataset.to??"")}"]`;(p.querySelector(`[data-gate="give"]${s}`)??p.querySelector(`[data-gate="pass"]${s}`))?.dispatchEvent(new MouseEvent("click",{bubbles:!0}))}}});p.addEventListener("change",n=>{const a=n.target;if(!(!(a instanceof HTMLSelectElement)||a.dataset.pick===void 0)){t.pinned=a.value;try{localStorage.setItem(de,a.value)}catch{}a.blur(),h()}});await Ie();await pe();t.noServer||await h();setInterval(()=>{document.hidden||h()},nt);document.addEventListener("visibilitychange",()=>{document.hidden||h()});addEventListener("focus",()=>h());Object.assign(window,{compact:t});
@@ -0,0 +1,153 @@
1
+ (function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))s(i);new MutationObserver(i=>{for(const o of i)if(o.type==="childList")for(const l of o.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&s(l)}).observe(document,{childList:!0,subtree:!0});function n(i){const o={};return i.integrity&&(o.integrity=i.integrity),i.referrerPolicy&&(o.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?o.credentials="include":i.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function s(i){if(i.ep)return;i.ep=!0;const o=n(i);fetch(i.href,o)}})();const Lt=/^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/,Dt=/^(you|[a-z0-9][a-z0-9-]*:\S{1,80})$/,C=e=>typeof e=="string"&&Lt.test(e),Pt=e=>typeof e=="string"&&Dt.test(e),Ft=e=>String(e).normalize("NFKD").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,56).replace(/-+$/,"")||"step";function ut(e,t){const n=t instanceof Set?i=>t.has(i):i=>i in t,s=Ft(e);if(!n(s))return s;for(let i=2;;i++)if(!n(`${s}-${i}`))return`${s}-${i}`}const It=(e,t)=>e.edges.filter(n=>n.to===t).map(n=>n.from),ft=(e,t,n=!1)=>e.edges.filter(s=>s.from===t&&!(n&&s.kind==="after")).map(s=>s.to);function Bt(e,t,n=!1){const s=new Map;let i=[t];for(let o=1;i.length;o++){const l=[];for(const a of i)for(const r of ft(e,a,n))r===t||s.has(r)||(s.set(r,o),l.push(r));i=l}return s}const Cs=(e,t,n)=>t===n||Bt(e,t).has(n);function pt(e,t){return!e?.length||!t?.length?!1:e.some(n=>t.some(s=>n===s||ze(n,s)||ze(s,n)))}function Wt(e){const t=[],n=s=>{const i=t[t.length-1];i&&(i.k==="deep"||i.k==="star")?s==="deep"&&(i.k="deep"):t.push({k:s})};for(let s=0;s<e.length;s++){const i=e[s];i==="*"&&e[s+1]==="*"?(n("deep"),s++,e[s+1]==="/"&&s++):i==="*"?n("star"):i==="?"?t.push({k:"any"}):t.push({k:"lit",ch:i})}return t}function ze(e,t){if(!/[*?]/.test(e))return!1;const n=Wt(e),s=t.length;let i=new Uint8Array(s+1),o=new Uint8Array(s+1);i[s]=1;for(let l=n.length-1;l>=0;l--){const a=n[l];for(let r=s;r>=0;r--)a.k==="deep"?o[r]=i[r]||r<s&&o[r+1]?1:0:a.k==="star"?o[r]=i[r]||r<s&&t[r]!=="/"&&o[r+1]?1:0:r===s?o[r]=0:o[r]=(a.k==="any"?t[r]!=="/":t[r]===a.ch)&&i[r+1]?1:0;[i,o]=[o,i]}return i[0]===1}const Ge=["not_started","in_progress","waiting","done","failed","cancelled"],Je=["planning","executing","paused","done","abandoned"],Ht=["task","context"],Ye=["needs","after","approve","ask","input"],Rs=new Set(["approve","ask","input"]),F=(e,t=0,n=1/0)=>typeof e=="string"&&e.length>=t&&e.length<=n,se=64,Ne=256,G=4e3,te=2e3,Le=e=>Array.isArray(e)&&e.length<=se&&e.every(t=>F(t,1,Ne)),Ut=`files is a list of paths or globs (at most ${se}, each 1-${Ne} characters)`,ht=64,Kt=e=>Array.isArray(e)&&e.length<=ht&&e.every(t=>C(t)),zt=`touches is a list of box ids from the architecture (at most ${ht})`,Gt=e=>e!=null&&typeof e=="object"&&!Array.isArray(e);function Jt(e,t,n,s){for(const i of Object.keys(e))t.includes(i)||s.push(`${n}: unknown field "${i}"`)}const Yt={"node.add":{required:["label"],optional:["id","kind","detail","group","files","touches","after"],ids:["id"]},"node.set":{required:["id"],optional:["label","kind","detail","group","files","touches"],ids:["id"],oneOf:["label","kind","detail","group","files","touches"]},"node.remove":{required:["id"],ids:["id"]},"edge.add":{required:["from","to"],optional:["label","kind"],ids:["from","to"]},"edge.remove":{required:["from","to"],ids:["from","to"]},"edge.rewire":{required:["from","to"],optional:["newFrom","newTo"],ids:["from","to","newFrom","newTo"],oneOf:["newFrom","newTo"]},"edge.reverse":{required:["from","to"],ids:["from","to"]},"edge.set":{required:["from","to"],optional:["label","kind"],ids:["from","to"],oneOf:["label","kind"]},"gate.pass":{required:["from","to"],optional:["answer"],ids:["from","to"]},"gate.ask":{required:["from","to","question"],ids:["from","to"]},"gate.reject":{required:["from","to"],optional:["reason"],ids:["from","to"]},"status.set":{required:["id","status"],optional:["note"],ids:["id"]},claim:{required:["id"],ids:["id"]},release:{required:["id"],ids:["id"]},"group.rename":{required:["from","to"]},"plan.set":{optional:["title","goal","phase"],oneOf:["title","goal","phase"]},"plan.stop":{},"layout.place":{required:["id","x","y"],ids:["id"]},"proposal.accept":{required:["id"]},"proposal.reject":{required:["id"],optional:["reason"]},review:{required:["ids"]}},Ns=new Set(["node.add","node.set","node.remove","edge.add","edge.remove","edge.rewire","edge.reverse","edge.set","group.rename"]);function Ls(e){if(!Gt(e)||typeof e.op!="string")return['an op is an object with an "op" name'];const t=Yt[e.op];if(!t)return[`"${e.op}" is not an op`];const n=[],s=["op",...t.required??[],...t.optional??[]];Jt(e,s,e.op,n);for(const i of t.required??[])e[i]===void 0&&n.push(`${e.op}: needs "${i}"`);t.oneOf&&!t.oneOf.some(i=>e[i]!==void 0)&&n.push(`${e.op}: needs one of ${t.oneOf.join(", ")}`);for(const i of t.ids??[])e[i]!==void 0&&!C(e[i])&&n.push(`${e.op}: "${e[i]}" is not a valid id`);return e.label!==void 0&&!F(e.label,e.op==="edge.set"||e.op==="edge.add"?0:1,120)&&n.push(`${e.op}: label is at most 120 characters`),e.detail!==void 0&&!F(e.detail,0,G)&&n.push(`${e.op}: detail is text of at most ${G} characters`),e.kind!==void 0&&(e.op.startsWith("edge.")?Ye.includes(e.kind)||n.push(`${e.op}: kind is one of ${Ye.join(", ")}`):Ht.includes(e.kind)||n.push(`${e.op}: kind is task or context`)),e.question!==void 0&&!F(e.question,1,te)&&n.push(`${e.op}: question is 1-${te} characters`),e.answer!==void 0&&!F(e.answer,0,te)&&n.push(`${e.op}: answer is at most ${te} characters`),e.files!==void 0&&!Le(e.files)&&n.push(`${e.op}: ${Ut}`),e.touches!==void 0&&!Kt(e.touches)&&n.push(`${e.op}: ${zt}`),e.group!==void 0&&!(e.op==="node.set"&&e.group===null)&&!F(e.group,1,80)&&n.push(`${e.op}: group is 1-80 characters`),e.after!==void 0&&!(Array.isArray(e.after)&&e.after.every(C))&&n.push(`${e.op}: after is a list of step ids`),e.op==="status.set"&&!Ge.includes(e.status)&&n.push(`status.set: "${e.status}" is not a status (${Ge.join(", ")})`),e.note!==void 0&&!F(e.note,0,te)&&n.push(`${e.op}: note is at most ${te} characters`),e.op==="group.rename"&&(!F(e.from,1,80)||!F(e.to,1,80))&&n.push("group.rename: from and to are group names of 1-80 characters"),e.title!==void 0&&!F(e.title,1,200)&&n.push("plan.set: title is 1-200 characters"),e.goal!==void 0&&!F(e.goal)&&n.push("plan.set: goal is text"),e.phase!==void 0&&!Je.includes(e.phase)&&n.push(`plan.set: phase is one of ${Je.join(", ")}`),e.op==="layout.place"&&!(Number.isFinite(e.x)&&Number.isFinite(e.y))&&n.push("layout.place: x and y are numbers"),(e.op==="proposal.accept"||e.op==="proposal.reject")&&!F(e.id,1,64)&&n.push(`${e.op}: needs a proposal id`),e.reason!==void 0&&!F(e.reason,0,1e3)&&n.push(`${e.op}: reason is at most 1000 characters`),e.op==="review"&&!(Array.isArray(e.ids)&&e.ids.length&&e.ids.every(C))&&n.push("review: ids is a non-empty list of step ids"),n}const Ve=(e,t)=>JSON.stringify(e)===JSON.stringify(t),Se=e=>`${e.from}\0${e.to}`,re=e=>e.kind??"needs";function Ae(e,t){const n=(e.label??"")!==(t.label??"")?t.label??"":void 0,s=re(e)!==re(t)?re(t):void 0;return n===void 0&&s===void 0?null:ne({op:"edge.set",from:t.from,to:t.to,label:n,kind:s})}function Vt(e,t,{bridge:n=!1}={}){const s=[],i=[],o={};for(const d of["title","goal","phase"])e[d]!==t[d]&&t[d]!==void 0&&(o[d]=t[d]);Object.keys(o).length&&s.push({op:"plan.set",...o}),t.rev!==e.rev&&i.push("rev (the server counts revisions)"),Ve(e.proposals??[],t.proposals??[])||i.push("proposals (accept or reject them instead)");const l=Object.keys(t.nodes).filter(d=>!(d in e.nodes)),a=Object.keys(e.nodes).filter(d=>!(d in t.nodes)),r=Object.keys(t.nodes).filter(d=>d in e.nodes);for(const d of l){const c=t.nodes[d];s.push(ne({op:"node.add",id:d,label:c.label,kind:c.kind,detail:c.detail,group:c.group,files:c.files,touches:c.touches}))}for(const d of r){const c=e.nodes[d],$=t.nodes[d],m={};for(const S of["label","kind","detail","files","touches"])!Ve(c[S],$[S])&&$[S]!==void 0&&(m[S]=$[S]);c.kind==="context"&&$.kind===void 0&&(m.kind="task"),c.detail!==void 0&&$.detail===void 0&&(m.detail=""),c.files!==void 0&&$.files===void 0&&(m.files=[]),c.touches!==void 0&&$.touches===void 0&&(m.touches=[]),c.group!==$.group&&(m.group=$.group??null),Object.keys(m).length&&s.push({op:"node.set",id:d,...m})}const u=new Map(e.edges.map(d=>[Se(d),d])),f=new Map(t.edges.map(d=>[Se(d),d])),g=[...u].filter(([d,c])=>!f.has(d)&&c.from in t.nodes&&c.to in t.nodes).map(([,d])=>d),p=[...f].filter(([d])=>!u.has(d)).map(([,d])=>d);for(const d of[...g]){const c=p.find(m=>m.from===d.to&&m.to===d.from);if(!c)continue;s.push({op:"edge.reverse",from:d.from,to:d.to});const $=Ae(d,c);$&&s.push($),g.splice(g.indexOf(d),1),p.splice(p.indexOf(c),1)}for(const d of[...g]){const c=p.find(m=>m.from===d.from||m.to===d.to);if(!c)continue;s.push(ne({op:"edge.rewire",from:d.from,to:d.to,newFrom:c.from!==d.from?c.from:void 0,newTo:c.to!==d.to?c.to:void 0}));const $=Ae(d,c);$&&s.push($),g.splice(g.indexOf(d),1),p.splice(p.indexOf(c),1)}for(const d of g)s.push({op:"edge.remove",from:d.from,to:d.to});for(const d of a)s.push({op:"node.remove",id:d});if(n&&a.length){const d=new Set(a),c=(m,S)=>e.edges.filter(O=>O.to===m).flatMap(O=>d.has(O.from)?S.has(O.from)?[]:(S.add(O.from),c(O.from,S)):[O.from]),$=new Set;for(const m of e.edges)if(!(!d.has(m.from)||d.has(m.to)||!(m.to in t.nodes)||t.nodes[m.to].status==="done"))for(const S of c(m.from,new Set([m.from]))){const O=Se({from:S,to:m.to});S===m.to||!(S in t.nodes)||f.has(O)||$.has(O)||($.add(O),s.push({op:"edge.add",from:S,to:m.to}))}}for(const d of p)s.push(ne({op:"edge.add",from:d.from,to:d.to,label:d.label,kind:d.kind}));for(const[d,c]of f){const $=u.get(d),m=$&&Ae($,c);m&&s.push(m)}for(const d of[...r,...l]){const c=e.nodes[d]??{},$=t.nodes[d];if($.kind==="context")continue;const m=c.status??"not_started",S=$.status??"not_started";(m!==S||(c.note??"")!==($.note??""))&&s.push(ne({op:"status.set",id:d,status:S,note:$.note})),(c.statusFrom!==$.statusFrom||c.statusBy!==$.statusBy)&&m===S&&i.push(`${d}: statusFrom/statusBy (the server stamps them)`),c.owner!==$.owner&&($.owner===void 0?s.push({op:"release",id:d}):i.push(`${d}: owner (a step is owned by claiming it)`))}for(const[d,c]of f){const $=u.get(d)??{from:c.from,to:c.to},m=re($)!==re(c);c.question!==void 0&&(m||c.question!==$.question)&&!c.passed&&s.push({op:"gate.ask",from:c.from,to:c.to,question:c.question}),c.passed&&(m||!$.passed)?s.push(ne({op:"gate.pass",from:c.from,to:c.to,answer:c.answer})):!c.passed&&$.passed&&!m&&i.push(`${c.from} → ${c.to}: passed (a checkpoint is not taken back; change the arrow's kind to reset it)`)}return{ops:s,ignored:i}}function ne(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}const N=(e,t=120)=>{const n=String(e).replace(/\s+/g," ").trim();return`"${n.length>t?`${n.slice(0,t-1)}…`:n}"`},Xt={not_started:"not started",in_progress:"in progress",waiting:"waiting for you",done:"done",failed:"failed",cancelled:"cancelled"},Zt=e=>Xt[e]??e,Xe={after:"order only",approve:"checkpoint: the person approves its result first",ask:"checkpoint: ask the person first",input:"checkpoint: needs input from the person"};function Qt(e){switch(e.op){case"node.add":return`add step ${e.id??""}${e.id?" ":""}${N(e.label)}${e.kind==="context"?" (context)":""}${e.group?` in ${N(e.group)}`:""}${e.after?.length?`, after ${e.after.join(", ")}`:""}`;case"node.set":{const t=[];return e.label!==void 0&&t.push(`label → ${N(e.label)}`),e.kind!==void 0&&t.push(`kind → ${e.kind}`),e.detail!==void 0&&t.push(e.detail===""?"detail cleared":"detail rewritten"),e.files!==void 0&&t.push(`files → ${e.files.length?e.files.join(", "):"none"}`),e.touches!==void 0&&t.push(`changes boxes → ${e.touches.length?e.touches.join(", "):"none named"}`),e.group!==void 0&&t.push(e.group===null?"out of its group":`group → ${N(e.group)}`),`change ${e.id}: ${t.join("; ")}`}case"node.remove":return`remove step ${e.id}`;case"edge.add":return`${e.to} now depends on ${e.from}${e.kind&&e.kind!=="needs"?`, ${Xe[e.kind]}`:""}${e.label?` (${N(e.label,40)})`:""}`;case"edge.remove":return`${e.to} no longer depends on ${e.from}`;case"edge.rewire":return`arrow ${e.from} → ${e.to} is now ${e.newFrom??e.from} → ${e.newTo??e.to}`;case"edge.reverse":return`arrow ${e.from} → ${e.to} flipped to ${e.to} → ${e.from}`;case"edge.set":{const t=[];return e.kind!==void 0&&t.push(e.kind==="needs"?"a plain dependency":Xe[e.kind]),e.label!==void 0&&t.push(`label ${N(e.label,40)}`),`arrow ${e.from} → ${e.to}: ${t.join("; ")}`}case"gate.pass":return`the checkpoint ${e.from} → ${e.to} is passed${e.answer?`: ${N(e.answer,300)}`:""}; ${e.to} may start`;case"gate.ask":return`asked the person before ${e.to}: ${N(e.question,300)}`;case"gate.reject":return`${e.from} was sent back, not approved${e.reason?` (${N(e.reason,300)})`:""}: it is to be done again`;case"status.set":return`${e.id} is ${Zt(e.status)}${e.note?` (${N(e.note,160)})`:""}`;case"claim":return`take ${e.id}`;case"release":return`let go of ${e.id}`;case"group.rename":return`rename group ${N(e.from)} to ${N(e.to)}`;case"plan.set":{const t=[];return e.title!==void 0&&t.push(`title → ${N(e.title)}`),e.goal!==void 0&&t.push(`goal → ${N(e.goal,200)}`),e.phase!==void 0&&t.push(`phase → ${e.phase}`),`set the plan's ${t.join("; ")}`}case"plan.stop":return"stop the plan: the agents stop now, it is back in planning, and the steps in progress are put back";case"layout.place":return`place ${e.id}`;case"proposal.accept":return`accept proposal ${e.id}`;case"proposal.reject":return`reject proposal ${e.id}${e.reason?` (${N(e.reason,160)})`:""}`;case"review":return`${e.ids.join(", ")} reviewed: no change needed`;default:return String(e.op)}}const en=[/^classDef\s+\S+\s+\S/,/^class\s+[\p{L}\p{N}_,\-\s]+\s+[\w-]+\s*$/u,/^style\s+[\p{L}\p{N}_-]+\s+[^\s\-=.~<]/u,/^linkStyle\s+(default|[\d,\s]+)\s/,/^click\s+[\p{L}\p{N}_-]+\s/u,/^acc(Title|Descr)\s*[:{]/,/^direction\s+(LR|RL|TD|TB|BT)\s*$/],pe=[["(((",")))"],["((","))"],["([","])"],["[[","]]"],["[(",")]"],["[/","/]"],["[/","\\]"],["[\\","\\]"],["[\\","/]"],["{{","}}"],["(",")"],["[","]"],["{","}"],[">","]"]],tn=/^(<?)(-{2,}|={2,}|-\.+-|~{3,})([>ox]?)/,nn=/^(--|==|-\.)\s+([^|]+?)\s+(-{2,}>|={2,}>|\.-+>|-{3,}|={3,}|\.-+)/,sn=/^[\p{L}\p{N}_]+(?:-[\p{L}\p{N}_]+)*/u,le=e=>e.replace(/#quot;/g,'"').replace(/#amp;/g,"&").replace(/#lt;/g,"<").replace(/#gt;/g,">").replace(/#(\d+);/g,(t,n)=>String.fromCodePoint(Number(n)));function $t(e,{rich:t=!1}={}){const n={direction:"TD",nodes:new Map,edges:[],warnings:[],...t?{subgraphs:[]}:{}},s=[],i=[];let o=!1;if(e.replace(/\r\n?/g,`
2
+ `).split(`
3
+ `).forEach((a,r)=>{const u=`line ${r+1}`;for(const f of on(a.replace(/%%.*$/,""))){const g=f.trim();if(!g)continue;if(!o){const c=/^(flowchart|graph)(?:\s+(LR|RL|TD|TB|BT))?\s*$/.exec(g);if(!c)throw new Error(`${u}: a plan diagram starts with "flowchart" or "graph", not "${g.slice(0,30)}"`);n.direction=c[2]==="LR"||c[2]==="RL"?"LR":"TD",o=!0;continue}if(g==="end"){if(!s.length)throw new Error(`${u}: "end" with no subgraph open`);s.pop(),i.pop();continue}const p=/^subgraph\s+(.+)$/.exec(g);if(p){if(s.push(an(p[1])),n.subgraphs){const c=/^([\p{L}\p{N}_-]+)\s*(?:\[|$)/u.exec(p[1])?.[1];i.push(n.subgraphs.push({...c?{id:c}:{},title:s.at(-1),...i.length?{parent:i.at(-1)}:{}})-1)}continue}const d=t?/^class\s+([\p{L}\p{N}_,\-\s]+?)\s+([\w-]+)\s*$/u.exec(g):null;if(d){for(const c of d[1].split(",").map($=>$.trim()).filter(Boolean)){const $=n.nodes.get(c);$&&($.cls=d[2])}continue}en.some(c=>c.test(g))||rn(g,u,s.at(-1),n,t?i.at(-1)??-1:void 0)}}),!o)throw new Error('this is not a Mermaid flowchart: it has no "flowchart" or "graph" line');return s.length&&n.warnings.push(`${s.length} subgraph${s.length===1?" was":"s were"} never closed with "end"`),n}function on(e){const t=[];let n=0,s=!1,i=0;for(let o=0;o<e.length;o++){const l=e[o];l==='"'?s=!s:!s&&"[({".includes(l)?n++:!s&&"])}".includes(l)?n=Math.max(0,n-1):!s&&n===0&&l===";"&&(t.push(e.slice(i,o)),i=o+1)}return t.push(e.slice(i)),t}function an(e){const t=/^[\p{L}\p{N}_-]+\s*\[\s*"?(.*?)"?\s*\]\s*$/u.exec(e);if(t)return le(t[1]);const n=/^"(.*)"$/.exec(e.trim());return n?le(n[1]):e.trim()}function rn(e,t,n,s,i){let o=0;const l=()=>e.slice(o),a=()=>{for(;o<e.length&&/\s/.test(e[o]);)o++},r=()=>{a();const p=sn.exec(l());if(!p)throw new Error(`${t}: expected a node id at "${l().slice(0,30)}"`);const d=p[0];o+=d.length;let c,$;const m=pe.find(([E])=>l().startsWith(E));if(m){o+=m[0].length;const E=l();if(E.startsWith('"')){const T=E.indexOf('"',1);if(T<0)throw new Error(`${t}: an unclosed quote in ${d}'s label`);c=E.slice(1,T),o+=T+1,a();const x=pe.find(([A,M])=>A===m[0]&&l().startsWith(M))??pe.find(([,A])=>l().startsWith(A));if(!x)throw new Error(`${t}: ${d}'s label is not closed`);o+=x[1].length}else{const T=pe.filter(([A])=>A===m[0]).map(([,A])=>A),x=Math.min(...T.map(A=>E.indexOf(A)).filter(A=>A>=0));if(!Number.isFinite(x))throw new Error(`${t}: ${d}'s label is not closed`);c=E.slice(0,x).trim(),o+=x+(T.find(A=>E.startsWith(A,x))??T[0]).length}$=le(c).replace(/^`|`$/g,"").trim(),c=$.replace(/<br\s*\/?>/gi," ").trim()}const S=/^:::([\w-]+)/.exec(l());S&&(o+=S[0].length);const O=s.nodes.get(d),R=i!==void 0?{...m?{shape:m[0]}:{},...$?{raw:$}:{},...S?{cls:S[1]}:{}}:{};return O?(c&&(O.label=c),Object.assign(O,R)):s.nodes.set(d,{label:c||d,...n?{group:n}:{},...i!==void 0&&i>=0?{frame:i}:{},...R}),d},u=()=>{const p=[r()];for(a();l().startsWith("&");)o++,p.push(r()),a();return p},f=()=>{a();const p=nn.exec(l());if(p)return o+=p[0].length,{...Qe(p[1],le(p[2].trim())),twoWay:!1};const d=tn.exec(l());if(!d)return null;o+=d[0].length,a();let c;const $=/^\|([^|]*)\|/.exec(l());return $&&(o+=$[0].length,c=le($[1].trim().replace(/^"(.*)"$/,"$1"))),{...Qe(d[2],c),twoWay:d[1]==="<"}};let g=u();for(;;){const p=f();if(!p)break;const d=u();for(const c of g)for(const $ of d)s.edges.push({from:c,to:$,...p.kind?{kind:p.kind}:{},...p.label?{label:p.label}:{}}),p.twoWay&&s.warnings.push(`${t}: ${c} <--> ${$} points both ways; kept as ${c} → ${$}`);g=d}if(a(),o<e.length)throw new Error(`${t}: could not read "${l().slice(0,40)}"`)}function ln(e){e=e.replace(/\r\n?/g,`
4
+ `);const t=/^---\n([\s\S]*?)\n---/.exec(e)?.[1]??"",n=i=>{const o=new RegExp(`^${i}:\\s*(.*)$`,"m").exec(t);return o&&o[1].trim().replace(/^(['"])(.*)\1$/,"$2")||void 0},s=/```mermaid\s*\n([\s\S]*?)```/.exec(e);return{title:n("name"),goal:n("overview"),mermaid:s?s[1]:null}}const dn=/^(unchanged|existing|untouched|context)\b/i;function cn(e){const t=[],n=[...e.warnings];for(const[o,l]of e.nodes)t.push({op:"node.add",id:o,label:l.label.slice(0,120),...l.group?{group:l.group.slice(0,80)}:{},...l.group&&dn.test(l.group)?{kind:"context"}:{}});const s=new Map,i=(o,l)=>{const a=new Set([o]),r=[o];for(;r.length;){const u=r.pop();if(u===l)return!0;for(const f of s.get(u)??[])a.has(f)||(a.add(f),r.push(f))}return!1};for(const o of e.edges){if(o.from===o.to){n.push(`left out ${o.from} → ${o.to}: a step cannot depend on itself`);continue}if(!s.get(o.from)?.has(o.to)){if(i(o.to,o.from)){n.push(`left out ${o.from} → ${o.to}: it closes a loop, and a plan cannot loop`);continue}s.has(o.from)||s.set(o.from,new Set),s.get(o.from).add(o.to),t.push({op:"edge.add",from:o.from,to:o.to,...o.label?{label:o.label.slice(0,120)}:{},...o.kind?{kind:o.kind}:{}})}}return{ops:t,warnings:n}}const un=/[^A-Za-z0-9 _.\-/]/,Ze=e=>un.test(e)?`["${e.replace(/"/g,"#quot;")}"]`:`[${e}]`,fn=(e,t)=>{const n=String(e??"").trim(),s=t==="approve"||t==="ask"||t==="input",i=s?n?`${t}: ${n}`:t:n,o=t==="after"?"-.->":s?"==>":"-->";return i?`${o}|"${i.replace(/"/g,"#quot;")}"|`:o},pn=/^(approve|ask|input)\s*(?::\s*([\s\S]*))?$/i;function Qe(e,t){if(e.startsWith("-."))return{kind:"after",...t?{label:t}:{}};const n=e.startsWith("==")&&t?pn.exec(t):null;return n?{kind:n[1].toLowerCase(),...n[2]?.trim()?{label:n[2].trim()}:{}}:t?{label:t}:{}}const hn=(e,t)=>e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_|_$/g,"")||`group${t}`;function Ds(e,t="LR"){const n=[`flowchart ${t==="TD"?"TD":"LR"}`],s=Object.keys(e.nodes),i=[];for(const o of s){const l=e.nodes[o].group;i.includes(l)||i.push(l)}i.forEach((o,l)=>{const a=s.filter(r=>e.nodes[r].group===o);if(o===void 0){for(const r of a)n.push(` ${r}${Ze(e.nodes[r].label)}`);return}n.push(` subgraph ${hn(o,l)} ["${o.replace(/"/g,"#quot;")}"]`);for(const r of a)n.push(` ${r}${Ze(e.nodes[r].label)}`);n.push(" end")});for(const o of e.edges)!(o.from in e.nodes)||!(o.to in e.nodes)||n.push(` ${o.from} ${fn(o.label,o.kind)} ${o.to}`);return n.join(`
5
+ `)}function $n(e,t=""){const n=/\.(md|markdown)$/i.test(t)||/```mermaid/.test(e);let s=e,i,o,l="mermaid";if(n){const g=ln(e);if(!g.mermaid)throw new Error("there is no ```mermaid block in this file");({mermaid:s,title:i,goal:o}=g),l=/\.plan\.md$/i.test(t)||g.title?"cursor-plan":"markdown"}const a=$t(s),{ops:r,warnings:u}=cn(a),f=(t.split(/[\\/]/).pop()??"").replace(/\.(plan\.)?(md|markdown|mmd|mermaid|txt)$/i,"").replace(/_[0-9a-f]{8}$/i,"").replace(/[_-]+/g," ").trim();return{title:(i??(f?f[0].toUpperCase()+f.slice(1):"Imported plan")).slice(0,200),goal:o,direction:a.direction,source:{kind:l,...t?{path:t}:{}},ops:r,warnings:u}}const _e=["service","group"],X=(e,t)=>Object.keys(e.nodes).filter(n=>e.nodes[n].in===t),de=(e,t)=>Object.values(e.nodes).some(n=>n.in===t);function gn(e,t){const n=[];for(let s=e.nodes[t]?.in;s&&!n.includes(s)&&s!==t;s=e.nodes[s]?.in)n.push(s);return n}function gt(e,t){const n=[],s=[t];for(;s.length;)for(const i of X(e,s.pop()))i===t||n.includes(i)||(n.push(i),s.push(i));return n}function mn(e){for(const t of Object.keys(e.nodes)){const n=[t];for(let s=e.nodes[t].in;s&&e.nodes[s];s=e.nodes[s].in){if(s===t)return[...n,t];if(n.includes(s))break;n.push(s)}}return null}const wn=(e,t)=>e.edges.filter(n=>n.to===t).map(n=>n.from);function Ps(e,t,n){const s=n instanceof Set?n:new Set(n);return gn(e,t).reverse().find(o=>s.has(o))??t}const qe="dcursed.arch/0",ge=["person","service","component","store","queue","group"],me=["draft","accepted"],et=["dcursed","mermaid","c4","markdown","cursor-plan"],Z=120,tt=40,we=60,_=(e,t=0,n=1/0)=>typeof e=="string"&&e.length>=t&&e.length<=n,B=e=>e!=null&&typeof e=="object"&&!Array.isArray(e),mt=`files is a list of paths or globs (at most ${se}, each 1-${Ne} characters)`;function K(e,t,n,s){for(const i of Object.keys(e))t.includes(i)||s.push(`${n}: unknown field "${i}"`)}const bn=["label","kind","external","in","tech","detail","files","planned","retiring"],yn=["from","to","label","tech","async","via","planned","retiring"];function kn(e,t,n){const s=`box ${t}`;if(!B(e)){n.push(`${s}: not an object`);return}K(e,bn,s,n),_(e.label,1,120)||n.push(`${s}: needs a label of 1-120 characters`),ge.includes(e.kind)||n.push(`${s}: kind is one of ${ge.join(", ")}`),e.external!==void 0&&e.external!==!0&&n.push(`${s}: external is true (leave it out for a box you run)`),e.in!==void 0&&!C(e.in)&&n.push(`${s}: in is the id of the service or group it sits in`),e.tech!==void 0&&!_(e.tech,1,Z)&&n.push(`${s}: tech is 1-${Z} characters`),e.detail!==void 0&&!_(e.detail,0,G)&&n.push(`${s}: detail is text of at most ${G} characters`),e.files!==void 0&&!Le(e.files)&&n.push(`${s}: ${mt}`),e.planned!==void 0&&!C(e.planned)&&n.push(`${s}: planned is the id of the plan that adds it`),e.retiring!==void 0&&!C(e.retiring)&&n.push(`${s}: retiring is the id of the plan that removes it`),e.planned!==void 0&&e.retiring!==void 0&&n.push(`${s}: a box is planned or retiring, not both`)}function xn(e,t,n,s){if(!B(e)){s.push(`${t}: not an object`);return}K(e,["from","to","label"],t,s),e.label!==void 0&&!_(e.label,0,120)&&s.push(`${t}: label is at most 120 characters`);for(const i of["from","to"])e[i]in n?n[e[i]].kind==="group"&&s.push(`${t}: ${e[i]} is a group, a frame and not something that is called`):s.push(`${t}: "${e[i]}" is not a box`)}function vn(e){const t=[];if(!B(e))return["an architecture is a JSON object"];if(K(e,["schema","title","goal","rev","phase","source","nodes","edges","flows","proposals"],"architecture",t),e.schema!==qe&&t.push(`architecture: schema is "${qe}"`),_(e.title,1,200)||t.push("architecture: needs a title of 1-200 characters"),e.goal!==void 0&&!_(e.goal)&&t.push("architecture: goal is text"),(!Number.isInteger(e.rev)||e.rev<0)&&t.push("architecture: rev is a whole number from 0"),me.includes(e.phase)||t.push(`architecture: phase is one of ${me.join(", ")}`),e.source!==void 0&&(!B(e.source)||!et.includes(e.source.kind)?t.push(`architecture: source.kind is one of ${et.join(", ")}`):K(e.source,["kind","url","path","importedAt"],"architecture.source",t)),!B(e.nodes))return[...t,"architecture: nodes is an object keyed by box id"];for(const[o,l]of Object.entries(e.nodes))C(o)||t.push(`box "${o}": not a valid id`),kn(l,o,t);const n=e.nodes;for(const[o,l]of Object.entries(n)){if(!B(l)||l.in===void 0||!C(l.in))continue;const a=n[l.in];a?_e.includes(a.kind)||t.push(`box ${o}: sits in ${l.in}, which is a ${a.kind}; only a service or a group holds other boxes`):t.push(`box ${o}: sits in "${l.in}", which is not a box`)}if(!t.some(o=>o.includes("sits in"))){const o=mn(e);o&&t.push(`boxes sit inside each other in a loop: ${o.join(" → ")}`)}if(!Array.isArray(e.edges))return[...t,"architecture: edges is a list"];const s=new Set;if(e.edges.forEach((o,l)=>{const a=`arrow ${l+1}`;if(!B(o)){t.push(`${a}: not an object`);return}K(o,yn,a,t),o.label!==void 0&&!_(o.label,0,120)&&t.push(`${a}: label is at most 120 characters`),o.tech!==void 0&&!_(o.tech,1,Z)&&t.push(`${a}: tech is 1-${Z} characters`),o.async!==void 0&&o.async!==!0&&t.push(`${a}: async is true (leave it out for an arrow that waits for the answer)`),o.planned!==void 0&&!C(o.planned)&&t.push(`${a}: planned is the id of the plan that adds it`),o.retiring!==void 0&&!C(o.retiring)&&t.push(`${a}: retiring is the id of the plan that removes it`),o.planned!==void 0&&o.retiring!==void 0&&t.push(`${a}: an arrow is planned or retiring, not both`),o.from in n||t.push(`${a}: "${o.from}" is not a box`),o.to in n||t.push(`${a}: "${o.to}" is not a box`),o.from===o.to&&t.push(`${a}: ${o.from} cannot use itself`),o.via!==void 0&&(o.via in n?n[o.via].kind!=="queue"&&t.push(`${a}: via ${o.via} is a ${n[o.via].kind}; it names the queue that carries the arrow`):t.push(`${a}: via "${o.via}" is not a box`));const r=`${o.from}\0${o.to}`;s.has(r)&&t.push(`${a}: ${o.from} → ${o.to} is there twice`),s.add(r);for(const u of[o.from,o.to])u in n&&(n[u].kind==="group"?t.push(`${a}: ${u} is a group, a frame round other boxes; it takes no arrows`):de(e,u)&&t.push(`${a}: ${u} has boxes inside it, so it is a frame and takes no arrows; the arrows belong to the boxes inside`))}),!Array.isArray(e.flows))return[...t,"architecture: flows is a list (empty if there are none)"];e.flows.length>tt&&t.push(`architecture: at most ${tt} flows`);const i=new Set;return e.flows.forEach((o,l)=>{const a=`flow ${o?.id??l+1}`;if(!B(o)){t.push(`${a}: not an object`);return}K(o,["id","title","steps"],a,t),C(o.id)?i.has(o.id)&&t.push(`${a}: two flows are called ${o.id}`):t.push(`${a}: needs an id (letters, digits, "-", "_" or ".")`),i.add(o.id),_(o.title,1,120)||t.push(`${a}: needs a title of 1-120 characters`),!Array.isArray(o.steps)||!o.steps.length||o.steps.length>we?t.push(`${a}: steps is a list of 1-${we} steps`):o.steps.forEach((r,u)=>xn(r,`${a}, step ${u+1}`,n,t))}),e.proposals!==void 0&&(Array.isArray(e.proposals)?e.proposals.forEach((o,l)=>{const a=`proposal ${o?.id??l+1}`;if(!B(o)){t.push(`${a}: not an object`);return}K(o,["id","by","at","reason","ops"],a,t),_(o.id,1,64)||t.push(`${a}: needs an id`),Pt(o.by)||t.push(`${a}: by is not an actor`),o.reason!==void 0&&!_(o.reason,0,1e3)&&t.push(`${a}: reason is at most 1000 characters`),!Array.isArray(o.ops)||!o.ops.length?t.push(`${a}: needs at least one op`):o.ops.forEach((r,u)=>t.push(...wt(r).map(f=>`${a}, op ${u+1}: ${f}`)))}):t.push("architecture: proposals is a list")),t}const Sn={"box.add":{required:["label","kind"],optional:["id","in","tech","detail","files","external","planned","retiring"],ids:["id","in"]},"box.set":{required:["id"],optional:["label","kind","in","tech","detail","files","external","planned","retiring"],ids:["id","in"],oneOf:["label","kind","in","tech","detail","files","external","planned","retiring"]},"box.remove":{required:["id"],ids:["id"]},"arrow.add":{required:["from","to"],optional:["label","tech","async","via","planned","retiring"],ids:["from","to","via"]},"arrow.remove":{required:["from","to"],ids:["from","to"]},"arrow.rewire":{required:["from","to"],optional:["newFrom","newTo"],ids:["from","to","newFrom","newTo"],oneOf:["newFrom","newTo"]},"arrow.reverse":{required:["from","to"],ids:["from","to"]},"arrow.set":{required:["from","to"],optional:["label","tech","async","via","planned","retiring"],ids:["from","to","via"],oneOf:["label","tech","async","via","planned","retiring"]},"flow.add":{required:["id","title","steps"],ids:["id"]},"flow.set":{required:["id"],optional:["title","steps"],ids:["id"],oneOf:["title","steps"]},"flow.remove":{required:["id"],ids:["id"]},"arch.set":{optional:["title","goal","phase"],oneOf:["title","goal","phase"]},"layout.place":{required:["id","x","y"],ids:["id"]},"layout.fold":{required:["id","folded"],ids:["id"]},"proposal.accept":{required:["id"]},"proposal.reject":{required:["id"],optional:["reason"]}},An=new Set(["box.add","box.set","box.remove","arrow.add","arrow.remove","arrow.rewire","arrow.reverse","arrow.set","flow.add","flow.set","flow.remove"]),jn={"box.set":["in","planned","retiring"],"arrow.set":["via","planned","retiring"]};function wt(e){if(!B(e)||typeof e.op!="string")return['an op is an object with an "op" name'];const t=Sn[e.op];if(!t)return[`"${e.op}" is not an op`];const n=[],s=["op",...t.required??[],...t.optional??[]];K(e,s,e.op,n);for(const l of t.required??[])e[l]===void 0&&n.push(`${e.op}: needs "${l}"`);t.oneOf&&!t.oneOf.some(l=>e[l]!==void 0)&&n.push(`${e.op}: needs one of ${t.oneOf.join(", ")}`);const i=jn[e.op]??[];for(const l of t.ids??[])e[l]!==void 0&&!(e[l]===null&&i.includes(l))&&!C(e[l])&&n.push(`${e.op}: "${e[l]}" is not a valid id`);const o=e.op==="box.add"||e.op==="box.set";e.label!==void 0&&!_(e.label,e.op==="arrow.add"||e.op==="arrow.set"?0:1,120)&&n.push(`${e.op}: label is at most 120 characters`),e.tech!==void 0&&!_(e.tech,0,Z)&&n.push(`${e.op}: tech is at most ${Z} characters`),e.detail!==void 0&&!_(e.detail,0,G)&&n.push(`${e.op}: detail is text of at most ${G} characters`),e.kind!==void 0&&!ge.includes(e.kind)&&n.push(`${e.op}: kind is one of ${ge.join(", ")}`),e.files!==void 0&&!Le(e.files)&&n.push(`${e.op}: ${mt}`),e.external!==void 0&&typeof e.external!="boolean"&&n.push(`${e.op}: external is true or false`),e.async!==void 0&&typeof e.async!="boolean"&&n.push(`${e.op}: async is true or false`);for(const l of["planned","retiring"])e[l]!==void 0&&e[l]!==null&&!C(e[l])&&n.push(`${e.op}: ${l} is a plan id${o||e.op.startsWith("arrow")?" (null clears it)":""}`);return e.planned&&e.retiring&&n.push(`${e.op}: a box or arrow is planned or retiring, not both`),e.title!==void 0&&!_(e.title,1,e.op==="flow.add"||e.op==="flow.set"?120:200)&&n.push(`${e.op}: title is a name of 1-${e.op.startsWith("flow")?120:200} characters`),e.goal!==void 0&&!_(e.goal)&&n.push("arch.set: goal is text"),e.phase!==void 0&&!me.includes(e.phase)&&n.push(`arch.set: phase is one of ${me.join(", ")}`),e.steps!==void 0&&(!Array.isArray(e.steps)||!e.steps.length||e.steps.length>we?n.push(`${e.op}: steps is a list of 1-${we} steps`):e.steps.forEach((l,a)=>{if(!B(l)){n.push(`${e.op}: step ${a+1} is not an object`);return}K(l,["from","to","label"],`${e.op}: step ${a+1}`,n),(!C(l.from)||!C(l.to))&&n.push(`${e.op}: step ${a+1} needs from and to, box ids`),l.label!==void 0&&!_(l.label,0,120)&&n.push(`${e.op}: step ${a+1}: label is at most 120 characters`)})),e.op==="layout.place"&&!(Number.isFinite(e.x)&&Number.isFinite(e.y))&&n.push("layout.place: x and y are numbers"),e.op==="layout.fold"&&typeof e.folded!="boolean"&&n.push("layout.fold: folded is true or false"),(e.op==="proposal.accept"||e.op==="proposal.reject")&&!_(e.id,1,64)&&n.push(`${e.op}: needs a proposal id`),e.reason!==void 0&&!_(e.reason,0,1e3)&&n.push(`${e.op}: reason is at most 1000 characters`),n}class De extends Error{}const j=e=>{throw new De(e)},je=e=>An.has(e.op)||e.op==="arch.set"&&(e.title!==void 0||e.goal!==void 0);function nt(e,t,n){for(let s=0;s<t.length;s++){const i=wt(t[s]);if(i.length)return{kind:"rejected",index:s,op:t[s],why:i.join("; ")}}if((e.phase==="accepted"||n.propose)&&n.actor!=="you"&&t.some(je)){const s=t.filter(je),i=t.filter(u=>!je(u)),o=Oe(e,s,{...n,actor:"you"});if(o.kind==="rejected")return{...o,index:t.indexOf(s[o.index])};const l={id:n.proposalId??`p${e.rev+1}`,by:n.actor,...n.at?{at:n.at}:{},...n.reason?{reason:n.reason}:{},ops:o.ops},a={...structuredClone(e),proposals:[...e.proposals??[],l]};if(!i.length)return{kind:"proposed",arch:{...a,rev:e.rev+1},proposal:l};const r=Oe({...a,rev:e.rev},i,n);return r.kind==="rejected"?{...r,index:t.indexOf(i[r.index])}:{...r,proposal:l}}return Oe(e,t,n)}function Oe(e,t,n){const s=structuredClone(e),i={who:n,you:n.actor==="you",impact:new Map,touched:new Set,placements:[],folds:[]},o=[];for(let a=0;a<t.length;a++)try{o.push(bt(s,t[a],i));const r=vn(s);r.length&&j(r[0])}catch(r){if(r instanceof De)return{kind:"rejected",index:a,op:t[a],why:r.message};throw r}s.rev=e.rev+1,s.proposals&&!s.proposals.length&&delete s.proposals;const l=[...i.impact].filter(([a])=>s.nodes[a]&&!i.touched.has(a)).map(([a,r])=>({id:a,reasons:[...r]})).sort((a,r)=>a.id.localeCompare(r.id));return{kind:"applied",arch:s,ops:o,impact:l,touched:[...i.touched].filter(a=>s.nodes[a]),placements:i.placements,folds:i.folds}}const Y=(e,t)=>e.nodes[t]??j(`there is no box ${t}`);function z(e,t,n){n!==void 0&&(n===""||n===null?delete e[t]:e[t]=n)}function bt(e,t,n){const{you:s}=n,i=(a,r)=>{const u=n.impact.get(a);u?u.add(r):n.impact.set(a,new Set([r]))},o=(a,r)=>{for(const u of wn(e,a))i(u,`${a} ${r}`)},l=(a,r)=>{const u=Y(e,r);_e.includes(u.kind)||j(`${r} is a ${u.kind}; only a service or a group holds other boxes`),(r===a||gt(e,a).includes(r))&&j(`${a} cannot sit inside ${r}: that would put it inside itself`),e.edges.some(f=>f.from===r||f.to===r)&&j(`${r} has arrows of its own, and a box with boxes inside it is a frame, which takes none: move them to the boxes that will be inside it first`)};switch(t.op){case"box.add":{const a=t.id??ut(t.label,e.nodes);e.nodes[a]&&j(`box ${a} exists`);const r={label:t.label,kind:t.kind};return t.external&&(r.external=!0),t.in!==void 0&&(e.nodes[a]=r,l(a,t.in),r.in=t.in),z(r,"tech",t.tech),z(r,"detail",t.detail),t.files?.length&&(r.files=t.files),t.planned&&(r.planned=t.planned),t.retiring&&(r.retiring=t.retiring),e.nodes[a]=r,n.touched.add(a),{...t,id:a}}case"box.set":{const a=Y(e,t.id),r={label:a.label,kind:a.kind,tech:a.tech,detail:a.detail,files:JSON.stringify(a.files),external:a.external};if(t.label!==void 0&&(a.label=t.label),t.kind!==void 0&&t.kind!==a.kind){const f=X(e,t.id);f.length&&!_e.includes(t.kind)&&j(`${t.id} has ${f.join(", ")} inside it: take them out before it becomes a ${t.kind}`),t.kind==="group"&&e.edges.some(g=>g.from===t.id||g.to===t.id)&&j(`${t.id} has arrows, and a group is a frame round other boxes, which takes none`),a.kind==="queue"&&e.edges.some(g=>g.via===t.id)&&j(`${t.id} carries arrows (via): they name a queue`),a.kind=t.kind}return t.in===null?delete a.in:t.in!==void 0&&(l(t.id,t.in),a.in=t.in),z(a,"tech",t.tech),z(a,"detail",t.detail),Array.isArray(t.files)&&!t.files.length?delete a.files:t.files!==void 0&&(a.files=t.files),t.external===!1?delete a.external:t.external===!0&&(a.external=!0),t.planned!==void 0&&(t.planned&&a.retiring&&j(`${t.id} is retiring: clear that first (retiring: null)`),t.planned?a.planned=t.planned:delete a.planned),t.retiring!==void 0&&(t.retiring&&a.planned&&j(`${t.id} is planned: clear that first (planned: null)`),t.retiring?a.retiring=t.retiring:delete a.retiring),n.touched.add(t.id),(a.label!==r.label||a.kind!==r.kind||a.tech!==r.tech||a.detail!==r.detail||JSON.stringify(a.files)!==r.files||a.external!==r.external)&&o(t.id,"changed"),t}case"box.remove":{const a=Y(e,t.id);o(t.id,"was removed");for(const r of X(e,t.id))a.in?e.nodes[r].in=a.in:delete e.nodes[r].in;delete e.nodes[t.id],e.edges=e.edges.filter(r=>r.from!==t.id&&r.to!==t.id);for(const r of e.edges)r.via===t.id&&delete r.via;for(const r of e.flows)r.steps=r.steps.filter(u=>u.from!==t.id&&u.to!==t.id);return e.flows=e.flows.filter(r=>r.steps.length),t}case"arrow.add":return On(e,t),t;case"arrow.remove":{const a=Te(e,t.from,t.to);return e.edges.splice(e.edges.indexOf(a),1),t}case"arrow.rewire":case"arrow.reverse":{const a=Te(e,t.from,t.to),r=t.op==="arrow.reverse"?a.to:t.newFrom??a.from,u=t.op==="arrow.reverse"?a.from:t.newTo??a.to;return yt(e,r,u,a),a.from=r,a.to=u,t}case"arrow.set":{const a=Te(e,t.from,t.to);return z(a,"label",t.label),z(a,"tech",t.tech),t.async===!1?delete a.async:t.async===!0&&(a.async=!0),t.via===null?delete a.via:t.via!==void 0&&(a.via=t.via),t.planned!==void 0&&(t.planned&&a.retiring&&j(`${t.from} → ${t.to} is retiring: clear that first (retiring: null)`),t.planned?a.planned=t.planned:delete a.planned),t.retiring!==void 0&&(t.retiring&&a.planned&&j(`${t.from} → ${t.to} is planned: clear that first (planned: null)`),t.retiring?a.retiring=t.retiring:delete a.retiring),t}case"flow.add":return e.flows.some(a=>a.id===t.id)&&j(`there is already a flow ${t.id}`),e.flows.push({id:t.id,title:t.title,steps:t.steps.map(st)}),t;case"flow.set":{const a=e.flows.find(r=>r.id===t.id)??j(`there is no flow ${t.id}`);return t.title!==void 0&&(a.title=t.title),t.steps!==void 0&&(a.steps=t.steps.map(st)),t}case"flow.remove":return e.flows.some(a=>a.id===t.id)||j(`there is no flow ${t.id}`),e.flows=e.flows.filter(a=>a.id!==t.id),t;case"arch.set":return t.phase!==void 0&&t.phase!==e.phase&&!s&&j("only you accept the architecture, or take it back to a draft"),t.title!==void 0&&(e.title=t.title),t.goal!==void 0&&(t.goal?e.goal=t.goal:delete e.goal),t.phase!==void 0&&(e.phase=t.phase),t;case"layout.place":return s||j("only you place a box: the layout is yours"),Y(e,t.id),de(e,t.id)&&j(`${t.id} is a frame round other boxes: place the boxes inside it`),n.placements.push({id:t.id,x:t.x,y:t.y}),t;case"layout.fold":return s||j("only you fold a frame: the layout is yours"),Y(e,t.id),t.folded&&!de(e,t.id)&&j(`${t.id} has nothing inside it to fold`),n.folds.push({id:t.id,folded:t.folded}),t;case"proposal.accept":{s||j("only you accept a proposal");const a=(e.proposals??[]).find(r=>r.id===t.id)??j(`there is no proposal ${t.id}`);e.proposals=(e.proposals??[]).filter(r=>r!==a);for(const r of a.ops)try{bt(e,r,n)}catch(u){throw u instanceof De&&j(`proposal ${t.id} no longer applies: ${u.message}`),u}return t}case"proposal.reject":return s||j("only you reject a proposal"),(e.proposals??[]).some(a=>a.id===t.id)||j(`there is no proposal ${t.id}`),e.proposals=(e.proposals??[]).filter(a=>a.id!==t.id),t;default:return j(`"${t.op}" is not an op`)}}const st=e=>({from:e.from,to:e.to,...e.label?{label:e.label}:{}});function Te(e,t,n){return e.edges.find(s=>s.from===t&&s.to===n)??j(`there is no arrow ${t} → ${n}`)}function yt(e,t,n,s){const i=Y(e,t),o=Y(e,n);t===n&&j(`${t} cannot use itself`),e.edges.some(l=>l!==s&&l.from===t&&l.to===n)&&j(`${t} → ${n} is there already`);for(const[l,a]of[[t,i],[n,o]])a.kind==="group"&&j(`${l} is a group, a frame round other boxes; it takes no arrows`),de(e,l)&&j(`${l} has boxes inside it, so it is a frame and takes no arrows: draw the arrow to one of the boxes inside (fold it to see them as one)`)}function On(e,t){yt(e,t.from,t.to);const n={from:t.from,to:t.to};z(n,"label",t.label),z(n,"tech",t.tech),t.async&&(n.async=!0),t.via&&(n.via=t.via),t.planned&&(n.planned=t.planned),t.retiring&&(n.retiring=t.retiring),e.edges.push(n)}function Tn({title:e,goal:t,phase:n="accepted",source:s}){return{schema:qe,title:e,...t?{goal:t}:{},rev:0,phase:n,source:s??{kind:"dcursed"},nodes:{},edges:[],flows:[]}}const U=(e,t=120)=>{const n=String(e).replace(/\s+/g," ").trim();return`"${n.length>t?`${n.slice(0,t-1)}…`:n}"`};function ke(e){switch(e.op){case"box.add":return`add ${e.external?"external ":""}${e.kind} ${e.id??""}${e.id?" ":""}${U(e.label)}${e.in?` in ${e.in}`:""}${e.tech?` (${e.tech})`:""}${e.planned?`, planned by ${e.planned}`:""}`;case"box.set":{const t=[];return e.label!==void 0&&t.push(`label → ${U(e.label)}`),e.kind!==void 0&&t.push(`kind → ${e.kind}`),e.in!==void 0&&t.push(e.in===null?"out of what it sat in":`in → ${e.in}`),e.tech!==void 0&&t.push(e.tech===""?"tech cleared":`tech → ${e.tech}`),e.detail!==void 0&&t.push(e.detail===""?"detail cleared":"detail rewritten"),e.files!==void 0&&t.push(`files → ${e.files.length?e.files.join(", "):"none"}`),e.external!==void 0&&t.push(e.external?"external":"no longer external"),e.planned!==void 0&&t.push(e.planned===null?"no longer planned":`planned by ${e.planned}`),e.retiring!==void 0&&t.push(e.retiring===null?"no longer retiring":`retiring (${e.retiring} removes it)`),`change ${e.id}: ${t.join("; ")}`}case"box.remove":return`remove box ${e.id}`;case"arrow.add":return`${e.from} now uses ${e.to}${e.label?` (${U(e.label,40)})`:""}${e.async?", async":""}`;case"arrow.remove":return`${e.from} no longer uses ${e.to}`;case"arrow.rewire":return`arrow ${e.from} → ${e.to} is now ${e.newFrom??e.from} → ${e.newTo??e.to}`;case"arrow.reverse":return`arrow ${e.from} → ${e.to} flipped to ${e.to} → ${e.from}`;case"arrow.set":{const t=[];return e.label!==void 0&&t.push(`label ${U(e.label,40)}`),e.tech!==void 0&&t.push(e.tech===""?"tech cleared":`tech ${e.tech}`),e.async!==void 0&&t.push(e.async?"async: does not wait for the answer":"waits for the answer"),e.via!==void 0&&t.push(e.via===null?"no queue":`via ${e.via}`),e.planned!==void 0&&t.push(e.planned===null?"no longer planned":`planned by ${e.planned}`),e.retiring!==void 0&&t.push(e.retiring===null?"no longer retiring":`retiring (${e.retiring} removes it)`),`arrow ${e.from} → ${e.to}: ${t.join("; ")}`}case"flow.add":return`add flow ${e.id} ${U(e.title)} (${e.steps.length} step${e.steps.length===1?"":"s"})`;case"flow.set":return`change flow ${e.id}: ${[e.title!==void 0?`title → ${U(e.title)}`:"",e.steps!==void 0?`${e.steps.length} step${e.steps.length===1?"":"s"}`:""].filter(Boolean).join("; ")}`;case"flow.remove":return`remove flow ${e.id}`;case"arch.set":{const t=[];return e.title!==void 0&&t.push(`title → ${U(e.title)}`),e.goal!==void 0&&t.push(`goal → ${U(e.goal,200)}`),e.phase!==void 0&&t.push(e.phase==="accepted"?"accepted":"back to a draft"),`the architecture: ${t.join("; ")}`}case"layout.place":return`place ${e.id}`;case"layout.fold":return`${e.folded?"fold":"unfold"} ${e.id}`;case"proposal.accept":return`accept proposal ${e.id}`;case"proposal.reject":return`reject proposal ${e.id}${e.reason?` (${U(e.reason,160)})`:""}`;default:return String(e.op)}}function Mn(e,t){return e.edges.some(n=>n.from===t.from&&n.to===t.to)?"call":e.edges.some(n=>n.from===t.to&&n.to===t.from)?"reply":"gap"}const ot=e=>`${e.from}\0${e.to}`;function Fs(e,t){const n={plan:t.id,added:new Set,removed:new Set,changed:new Map,addedArrows:new Set,removedArrows:new Set};for(const[s,i]of Object.entries(e.nodes))i.planned===t.id&&n.added.add(s),i.retiring===t.id&&n.removed.add(s);for(const s of e.edges)s.planned===t.id&&n.addedArrows.add(ot(s)),(s.retiring===t.id||n.removed.has(s.from)||n.removed.has(s.to))&&n.removedArrows.add(ot(s));for(const[s,i]of Object.entries(t.nodes)){if(i.kind==="context"||i.status==="cancelled")continue;const o=new Set((i.touches??[]).filter(l=>l in e.nodes));for(const[l,a]of Object.entries(e.nodes))a.files?.length&&pt(i.files,a.files)&&o.add(l);for(const l of o){if(n.added.has(l)||n.removed.has(l))continue;const a=n.changed.get(l);a?a.includes(s)||a.push(s):n.changed.set(l,[s])}}return n}function kt(e,t,n){return t.added.has(n)?"new":t.removed.has(n)?"removed":t.changed.has(n)||de(e,n)&&gt(e,n).some(s=>t.added.has(s)||t.removed.has(s)||t.changed.has(s))?"changed":"untouched"}function En(e,t){const n=(t.touches??[]).map(s=>({id:s,by:"hand"}));for(const[s,i]of Object.entries(e.nodes))i.files?.length&&pt(t.files,i.files)&&!n.some(o=>o.id===s)&&n.push({id:s,by:"files"});return n}const _n={"(((":"person","((":"person","[(":"store","([":"queue",">":"queue","(":"service","{{":"service"},qn={person:["((","))"],service:["(",")"],component:["[","]"],store:["[(",")]"],queue:["([","])"],group:["[","]"]};function at(e){const t=/^([\s\S]*?)\s*(?:<br\s*\/?>|\n)\s*\[([^\]]+)\]\s*$/.exec(e);return t?{label:t[1].replace(/<br\s*\/?>/gi," ").trim(),tech:t[2].trim()}:{label:e.replace(/<br\s*\/?>/gi," ").trim()}}function Cn(e){const t=$t(e,{rich:!0}),n={direction:t.direction,boxes:new Map,arrows:[],warnings:[...t.warnings]},s=t.subgraphs??[],i=new Set([...t.nodes.keys(),...s.flatMap(l=>l.id?[l.id]:[])]),o=s.map(l=>l.id??(()=>{const a=ut(l.title,i);return i.add(a),a})());s.forEach((l,a)=>n.boxes.set(o[a],{label:l.title.slice(0,120),kind:"group",...l.parent!==void 0?{in:o[l.parent]}:{}}));for(const[l,a]of t.nodes){if(o.includes(l)&&a.shape===void 0&&a.raw===void 0)continue;const{label:r,tech:u}=at(a.raw??a.label);n.boxes.set(l,{label:(r||l).slice(0,120),kind:a.shape&&_n[a.shape]||"component",...a.cls==="external"?{external:!0}:{},...u?{tech:u.slice(0,120)}:{},...a.frame!==void 0?{in:o[a.frame]}:{}})}for(const l of t.edges){const a=l.kind&&l.kind!=="after"?`${l.kind}${l.label?`: ${l.label}`:""}`:l.label,{label:r,tech:u}=at(a??"");n.arrows.push({from:l.from,to:l.to,...r?{label:r.slice(0,120)}:{},...u?{tech:u.slice(0,120)}:{},...l.kind==="after"?{async:!0}:{}})}return n}const Rn=/^(Person|System|Container|Component)(Db|Queue)?(_Ext)?$/,Nn=/^(Boundary|Enterprise_Boundary|System_Boundary|Container_Boundary|Deployment_Node|Node|Node_L|Node_R)$/,Ln=/^(Rel|BiRel|Rel_[UDLR]|Rel_Back|Rel_Neighbor|Rel_Back_Neighbor|BiRel_[UDLR])$/,xt=/^C4(Context|Container|Component|Dynamic|Deployment)\b/;function Dn(e){const t=[];let n="",s=!1;for(const i of e)i==='"'?(s=!s,n+=i):i===","&&!s?(t.push(n),n=""):n+=i;return t.push(n),t.map(i=>i.trim()).filter(i=>!i.startsWith("$")).map(i=>i.replace(/^"([\s\S]*)"$/,"$1").trim())}function Pn(e){const t={direction:"TD",boxes:new Map,arrows:[],warnings:[]},n=[];let s=!1;if(e.replace(/\r\n?/g,`
6
+ `).split(`
7
+ `).forEach((i,o)=>{const l=`line ${o+1}`,a=i.replace(/%%.*$/,"").trim();if(!a)return;if(!s){if(!xt.test(a))throw new Error(`${l}: a C4 diagram starts with C4Context, C4Container, C4Component, C4Dynamic or C4Deployment, not "${a.slice(0,30)}"`);s=!0;return}if(a==="}"){n.pop();return}const r=/^title\s+(.+)$/.exec(a);if(r){t.title=r[1].trim();return}const u=/^([A-Za-z_]+)\s*\(([\s\S]*?)\)\s*(\{)?\s*$/.exec(a);if(!u){if(/^(UpdateElementStyle|UpdateRelStyle|UpdateLayoutConfig|UpdateBoundaryStyle|LAYOUT_|SHOW_|HIDE_)/.test(a))return;throw new Error(`${l}: could not read "${a.slice(0,40)}"`)}const[,f,g,p]=u,d=Dn(g);if(Ln.test(f)){const[ee,h,v,W]=d;if(!ee||!h)throw new Error(`${l}: ${f} needs two aliases`);f.startsWith("BiRel")&&t.warnings.push(`${l}: ${ee} <--> ${h} points both ways; kept as ${ee} → ${h}`),t.arrows.push({from:ee,to:h,...v?{label:v.slice(0,120)}:{},...W?{tech:W.slice(0,120)}:{}});return}const c=n.at(-1),$=Nn.test(f),m=Rn.exec(f);if(!$&&!m){t.warnings.push(`${l}: ${f} is not drawn here, and was left out`);return}const[S,O,R,E]=d;if(!S||!O)throw new Error(`${l}: ${f} needs an alias and a label`);if($){t.boxes.set(S,{label:O.slice(0,120),kind:"group",...c?{in:c}:{}}),p&&n.push(S);return}const[,T,x,A]=m,M=T==="Container"||T==="Component",P=M?R:void 0,ue=M?E:R,xe=x==="Db"?"store":x==="Queue"?"queue":T==="Person"?"person":T==="Component"?"component":"service";t.boxes.set(S,{label:O.slice(0,120),kind:xe,...A?{external:!0}:{},...P?{tech:P.slice(0,120)}:{},...ue?{detail:ue.slice(0,4e3)}:{},...c?{in:c}:{}})}),!s)throw new Error("this is not a Mermaid C4 diagram: it has no C4Context, C4Container… line");return n.length&&t.warnings.push(`${n.length} boundar${n.length===1?"y was":"ies were"} never closed with "}"`),t}function Fn(e){const t=[...e.warnings],n=[],s=[...e.boxes.keys()],i=new Set,o=r=>{if(i.has(r))return;i.add(r);const u=e.boxes.get(r);u.in&&e.boxes.has(u.in)&&o(u.in),n.push({op:"box.add",id:r,label:u.label,kind:u.kind,...u.external?{external:!0}:{},...u.tech?{tech:u.tech}:{},...u.detail?{detail:u.detail}:{},...u.in&&e.boxes.has(u.in)?{in:u.in}:{}})};for(const r of s)o(r);let l=Tn({title:"import",phase:"accepted"});const a=[];for(const r of n){const u=nt(l,[r],{actor:"you",via:"file"});u.kind==="applied"?(l=u.arch,a.push(r)):u.kind==="rejected"&&t.push(`left out box ${r.id}: ${u.why}`)}for(const r of e.arrows){const u={op:"arrow.add",from:r.from,to:r.to,...r.label?{label:r.label}:{},...r.tech?{tech:r.tech}:{},...r.async?{async:!0}:{}},f=nt(l,[u],{actor:"you",via:"file"});f.kind==="applied"?(l=f.arch,a.push(u)):f.kind==="rejected"&&!/is there already/.test(f.why)&&t.push(`left out ${r.from} → ${r.to}: ${f.why}`)}return{ops:a,warnings:t}}const Pe=e=>`"${e.replace(/"/g,"#quot;")}"`,In=e=>Pe(e.tech?`${e.label}<br/>[${e.tech}]`:e.label);function Bn(e){const t=e.tech?`${e.label??""}<br/>[${e.tech}]`:e.label??"",n=e.async?"-.->":"-->";return t?`${n}|${Pe(t)}|`:n}function Is(e,t="LR"){const n=[`flowchart ${t==="TD"?"TD":"LR"}`],s=e;let i=!1;const o=(r,u)=>{const f=e.nodes[r],[g,p]=qn[f.kind];f.external&&(i=!0),n.push(`${u}${r}${g}${In(f)}${p}${f.external?":::external":""}`)},l=(r,u)=>{n.push(`${u}subgraph ${r} [${Pe(e.nodes[r].label)}]`);for(const f of X(s,r))a(f,`${u} `);n.push(`${u}end`)},a=(r,u)=>{X(s,r).length||e.nodes[r].kind==="group"?l(r,u):o(r,u)};for(const r of Object.keys(e.nodes))e.nodes[r].in||a(r," ");for(const r of e.edges)r.from in e.nodes&&r.to in e.nodes&&n.push(` ${r.from} ${Bn(r)} ${r.to}`);return i&&n.push(" classDef external fill:#eeeeee,stroke:#999999,color:#333333"),n.join(`
8
+ `)}function Wn(e,t=""){let n=e;if(/\.(md|markdown)$/i.test(t)||/```mermaid/.test(e)){const u=/```mermaid\s*\n([\s\S]*?)```/.exec(e);if(!u)throw new Error("there is no ```mermaid block in this file");n=u[1]}const s=n.split(`
9
+ `).map(u=>u.replace(/%%.*$/,"").trim()).find(Boolean)??"",i=xt.test(s),o=i?Pn(n):Cn(n),{ops:l,warnings:a}=Fn(o),r=(t.split(/[\\/]/).pop()??"").replace(/\.(md|markdown|mmd|mermaid|txt)$/i,"").replace(/[_-]+/g," ").trim();return{title:(o.title??(r?r[0].toUpperCase()+r.slice(1):"Imported architecture")).slice(0,200),direction:o.direction,source:{kind:i?"c4":/\.(md|markdown)$/i.test(t)?"markdown":"mermaid",...t?{path:t}:{}},ops:l,warnings:a}}const ce="top level",Bs=e=>{const t=[];for(const n of e.steps)n.group&&!t.includes(n.group)&&t.push(n.group);return[...t.filter(n=>n!==ce),...t.filter(n=>n===ce)]},Fe={observed:"●",reported:"○",you:"◆"},Ce={observed:"seen editing its files",reported:"said by the agent",you:"set by you"},Hn={"claude-code":"Claude Code",cursor:"Cursor",antigravity:"Antigravity"},q=e=>{if(e.startsWith("opencode:"))return e.slice(9);if(e.startsWith("server:"))return"DiaCode";const t=e.indexOf(":"),n=t>0?Hn[e.slice(0,t)]:void 0;if(!n)return e;const s=e.slice(t+1);return s==="main"||s==="agent"?n:`${n} (${s})`};function Ie(e){if(!e||e.kind==="context")return null;const t=e.status&&e.status!=="not_started",n=e.owner??(t?e.statusBy:void 0);return n?{who:n,from:e.statusFrom??"reported"}:null}function Un(e,t){const n=Ie(e);return n?`${Fe[n.from]} ${q(n.who)}${t?` · ${t}`:""}`:""}const V={in_progress:"working",waiting:"waiting",done:"done",failed:"failed",cancelled:"cancelled"},vt=e=>`waits on ${e.slice(0,2).join(", ")}${e.length>2?` +${e.length-2}`:""}`,Kn=e=>`checkpoint after ${e.slice(0,2).join(", ")}${e.length>2?` +${e.length-2}`:""}`;function Ws(e,{stalled:t,blockedOn:n,held:s}={}){const i=[];e&&e.kind!=="context"&&(V[e.status]?i.push(V[e.status]):e.status==="not_started"&&!n?.length&&!s?.length&&i.push("not started"),n?.length?i.push(vt(n)):s?.length&&i.push(Kn(s)));const o=Un(e,t);return o&&i.push(o),i.join(" · ")}const L={in_progress:"#2F6FB0",waiting:"#9A6700",done:"#2E7D32",failed:"#B3261E",cancelled:"#69625B"},zn="#69625B",Hs={not_started:{colour:zn,icon:"ring",word:"not started",edge:!1,strike:!1},in_progress:{colour:L.in_progress,icon:"half",word:V.in_progress,edge:!0,strike:!1},waiting:{colour:L.waiting,icon:"hourglass",word:V.waiting,edge:!0,strike:!1},done:{colour:L.done,icon:"check",word:V.done,edge:!0,strike:!1},failed:{colour:L.failed,icon:"cross",word:V.failed,edge:!0,strike:!1},cancelled:{colour:L.cancelled,icon:"slash",word:V.cancelled,edge:!0,strike:!0}},Us=["not_started","in_progress","waiting","done","failed","cancelled"],Re={new:{colour:L.done,icon:"plus",word:"new"},changed:{colour:L.waiting,icon:"pencil",word:"changed"},removed:{colour:L.failed,icon:"cross",word:"removed"}},it={width:300,height:180};async function Q(e){let t;try{t=await e.json()}catch{throw new Error(e.status>=500?"the plan server is not reachable":`the plan server answered ${e.status}`)}return t}async function oe(e){const t=await fetch(e),n=await Q(t);if(!t.ok)throw new Error(n.error??`${t.status}`);return n}const Ks=(e,t=12)=>oe(`/api/files?q=${encodeURIComponent(e)}&limit=${t}`);async function zs(e){return e.length?(await oe(`/api/files?${e.map(t=>`check=${encodeURIComponent(t)}`).join("&")}`)).results:[]}async function Gs(){try{const e=await fetch("/api/health");if(!e.ok)return null;const t=await e.json();return t.ok?t:null}catch{return null}}const Js=async()=>(await oe("/api/plans")).plans,Ys=e=>oe(`/api/plans/${encodeURIComponent(e)}`);async function Gn(e){const t=await fetch("/api/plans",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(e)}),n=await Q(t);if(!t.ok)throw new Error(n.error??`${t.status}`);return n}async function Jn(e,t,n,s){const i=await fetch(`/api/plans/${encodeURIComponent(e)}/batches`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({plan:e,baseRev:t,ops:n,...s?{reason:s}:{}})});return{status:i.status,body:await Q(i)}}async function Vs(e,t={}){const n=await fetch(`/api/plans/${encodeURIComponent(e)}/reconcile`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t)}),s=await Q(n);if(!n.ok)throw new Error(s.error??`${n.status}`);return s.job}function Be(e,t,n){let s=null,i,o=!1,l=1e3,a=!1;const r=()=>{s=new EventSource(e),s.addEventListener("open",()=>{l=1e3,n.open(a),a=!0}),s.addEventListener("error",()=>{n.down(),!(o||s?.readyState!==EventSource.CLOSED)&&(s=null,i=setTimeout(r,l),l=Math.min(l*2,1e4))});for(const[u,f]of Object.entries(t))f&&s.addEventListener(u,g=>f(JSON.parse(g.data)))};return r(),()=>{o=!0,clearTimeout(i),s?.close()}}const Xs=(e,t)=>Be(`/api/plans/${encodeURIComponent(e)}/events`,{change:t.change,problem:t.problem,reconcile:t.reconcile,presence:t.presence,call:t.call},t),Zs=e=>Be("/api/events",{plans:e.plans},{open:e.open,down:()=>{}}),Qs=()=>oe("/api/architecture");async function eo(e,t,n){const s=await fetch(`/api/permissions/${encodeURIComponent(e)}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({decision:t,...n?{reason:n}:{}})});return{status:s.status,body:await Q(s)}}const to=()=>oe("/api/presence").then(e=>e.agents??[]);async function Yn(e){const t=await fetch("/api/architecture",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(e)}),n=await Q(t);if(!t.ok)throw new Error(n.error??`${t.status}`);return n}async function Vn(e,t,n){const s=await fetch("/api/architecture/batches",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({baseRev:e,ops:t,...n?{reason:n}:{}})});return{status:s.status,body:await Q(s)}}const no=e=>Be("/api/architecture/events",{change:e.change,problem:e.problem,call:e.call},e);async function so(e){const t=Wn(await e.text(),e.name);await Yn({title:t.title,source:t.source,direction:t.direction});const{status:n,body:s}=await Vn(0,t.ops,`imported from ${e.name}`);if(n!==200)throw new Error(s.why??s.error);return{warnings:t.warnings}}function oo(e){const{plan:t,layout:n}=e,s=n.canvas??{width:640,height:240};return{id:t.id,title:t.title,plan:t.title,repo:"",source:t.source?.url??"",direction:n.direction,note:t.goal??"",canvas:{width:s.width+it.width,height:s.height+it.height},...Xn(e)}}function Xn({plan:e,layout:t}){return{steps:Object.entries(e.nodes).map(([n,s])=>({id:n,label:s.label,group:s.group??ce,x:t.nodes[n]?.x??0,y:t.nodes[n]?.y??0})),depends:e.edges.map(n=>({source:n.from,target:n.to,label:n.label??"",kind:n.kind??"needs"}))}}function ao(e,t){const n={...e.plan,nodes:{},edges:[]};for(const o of t.steps){const a={...e.plan.nodes[o.id]??{},label:o.label};o.group&&o.group!==ce?a.group=o.group:delete a.group,n.nodes[o.id]=a}const s=new Map(e.plan.edges.map(o=>[`${o.from}\0${o.to}`,o]));n.edges=t.depends.map(o=>{const l=o.kind&&o.kind!=="needs"?o.kind:void 0,a=s.get(`${o.source}\0${o.target}`),r=a&&a.kind===l?{question:a.question,passed:a.passed,answer:a.answer}:{};return Object.fromEntries(Object.entries({from:o.source,to:o.target,label:o.label||void 0,kind:l,...r}).filter(([,u])=>u!==void 0))});const{ops:i}=Vt(e.plan,n,{bridge:!0});for(const o of t.steps){const l=e.layout.nodes[o.id],a=Math.round(o.x),r=Math.round(o.y);(!l||Math.round(l.x)!==a||Math.round(l.y)!==r)&&i.push({op:"layout.place",id:o.id,x:a,y:r})}return i}async function io(e){const t=$n(await e.text(),e.name),n=await Gn({title:t.title,goal:t.goal,source:t.source,direction:t.direction}),{status:s,body:i}=await Jn(n.id,0,t.ops,`imported from ${e.name}`);if(s!==200)throw new Error(i.why??i.error);return{id:n.id,warnings:t.warnings}}const b=e=>String(e).replace(/[&<>"]/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[t]);function be(e,t){const n=e?Date.parse(e):NaN;if(!Number.isFinite(n))return"";const s=Math.max(0,Math.round((t-n)/1e3));return s<45?"just now":s<3600?`${Math.max(1,Math.round(s/60))} min`:s<86400?`${Math.round(s/3600)} h`:`${Math.round(s/86400)} d`}function Zn(e,t){for(let n=e.length-1;n>=0;n--){const s=e[n];if((s.ops??[]).some(i=>i.id===t&&/^(status\.set|claim|release)$/.test(i.op)))return s.at}}function ro(e,t,n=""){switch(e){case"start":return{ops:[{op:"claim",id:t},{op:"status.set",id:t,status:"in_progress",note:"started by you"}],reason:`you started ${t}`,message:`Started ${t}.`};case"done":return{ops:[{op:"status.set",id:t,status:"done",note:"marked done by you"},{op:"release",id:t}],reason:`you marked ${t} done`,message:`Marked ${t} done.`};case"failed":return{ops:[{op:"status.set",id:t,status:"failed",note:"marked failed by you"}],reason:`you marked ${t} failed`,message:`Marked ${t} failed.`};case"release":return{ops:[{op:"release",id:t}],reason:`you took ${t} off its owner`,message:`Released ${t}.`};case"reopen":return{ops:[{op:"status.set",id:t,status:"not_started"},{op:"release",id:t}],reason:`you reopened ${t}`,message:`Reopened ${t}.`};case"cancel":return{ops:[{op:"status.set",id:t,status:"cancelled",note:"cancelled by you"},{op:"release",id:t}],reason:`you cancelled ${t}`,message:`Cancelled ${t}.`};case"answer":{const s=n.trim();return s?{ops:[{op:"status.set",id:t,status:"in_progress",note:`you answered: ${s}`}],reason:`Answer to ${t}: ${s}`,message:`Answered ${t}.`}:null}default:return null}}function lo(e,t,n,s=""){const i=s.trim();return e==="back"?{ops:[{op:"gate.reject",from:t,to:n,...i?{reason:i}:{}}],reason:`you sent ${t} back`,message:`Sent ${t} back to be done again.`}:e==="give"&&!i?null:{ops:[{op:"gate.pass",from:t,to:n,...i?{answer:i}:{}}],reason:`you passed the checkpoint before ${n}${i?`: ${i}`:""}`,message:`Passed the checkpoint before ${n}.`}}const ie="Carry out the plan with the dcursed tools, one step at a time: start a step, do it, mark it done. Stop and ask me if a step is unclear.",co=["planning","executing","done"],$e="Carry on with the plan with the dcursed tools: read it first, then take the next step.",St=e=>{const t=e.map(q);return t.length<2?t[0]??"":`${t.slice(0,-1).join(", ")} and ${t.at(-1)}`};function uo(e,t,n=[]){const s=o=>[{op:"plan.set",phase:o}];if(e==="planning")return{label:"Approve plan",primary:!0,ops:s("executing"),reason:"you approved the plan",message:"Plan approved: an agent's changes to steps and arrows are proposals now.",tell:ie,line:n.length?`Agents' edits land at once. This approves the plan and tells ${St(n)} to carry it out; after it, their edits to steps and arrows arrive as proposals.`:"Agents' edits land at once. This approves the plan. No agent is listening for the editor right now, so you may have to tell yours to begin. After it, their edits to steps and arrows arrive as proposals.",hint:"Approve the plan, and tell the agent that drafted it to carry it out. From now on an agent's changes to its steps and arrows arrive as proposals for you to accept; reports of progress land as before."};const i={label:"Stop",confirm:"Stop the agents now?",primary:!1,ops:[{op:"plan.stop"}],reason:"you stopped the plan",message:"Stopped: the agents stop now, and the plan is back in planning.",line:"",hint:"Stop the agents now, even mid-step, and go back to planning: what they were doing is put back, what they finished stays. Approve the plan again to carry on."};return e==="executing"?t?.total&&t.done===t.total?{label:"Mark plan done",primary:!0,ops:s("done"),reason:"you marked the plan done",message:"Plan marked done.",hint:"Every step is finished.",line:"Every step is finished."}:{label:"Pause",primary:!1,ops:s("paused"),reason:"you paused the plan",message:"Paused: agents finish the step they are on and start nothing new.",line:"Agents' edits to steps and arrows arrive as proposals for you to accept or reject. Pause: they finish the step they are on and start nothing new. Stop: they stop now, and the plan goes back to planning.",hint:"Agents finish the step they are on, then start nothing new until you resume.",second:i}:e==="paused"?{label:"Resume",primary:!0,ops:s("executing"),reason:"you resumed the plan",message:"Resumed.",tell:$e,line:"Paused: agents finish the step they are on and start nothing new. Resume to carry on, or Stop to halt them now and change the plan.",hint:"Carry on with the plan, and tell the agent that was at work on it.",second:i}:{label:"Reopen",primary:!1,ops:s("planning"),reason:"you reopened the plan",message:"Reopened: back to planning.",hint:"Plan again.",line:"This plan is finished. Reopen it to change it."}}function fo(e){const t=e.to?q(e.to):"the agent";if(e.kind==="approved")switch(e.state){case"sent":return{text:`Plan approved. Telling ${t} to carry it out…`,kind:"info"};case"delivered":return{text:`Plan approved, and ${t} was told to carry it out: the Steps panel shows it working.`,kind:"info"};case"queued":return{text:`Plan approved. ${t} is not listening yet (in the middle of a turn, or not running): it is told when it is, or tell it yourself.`,kind:"info",copy:ie};case"failed":return{text:`Plan approved, but ${t} could not be started${e.detail?` (${e.detail})`:""}. Tell it to carry the plan out.`,kind:"error",copy:ie};case"expired":return{text:`Plan approved. ${t} did not come back to take it: tell it to carry the plan out.`,kind:"info",copy:ie};case"none":return{text:"Plan approved. No agent is listening for the editor, so none was started: tell yours to carry it out.",kind:"info",copy:ie};default:return null}if(e.kind==="resumed")switch(e.state){case"sent":return{text:`Resumed. Telling ${t} to carry on…`,kind:"info"};case"delivered":return{text:`Resumed, and ${t} was told to carry on.`,kind:"info"};case"queued":return{text:`Resumed. ${t} is told when it is listening, or tell it yourself.`,kind:"info",copy:$e};case"none":return{text:"Resumed. No agent is listening for the editor: tell yours to carry on.",kind:"info",copy:$e};case"failed":case"expired":return{text:`Resumed, but ${t} could not be told${e.detail?` (${e.detail})`:""}: tell it to carry on.`,kind:"info",copy:$e};default:return null}if(e.kind==="stopped")switch(e.state){case"sent":return{text:`Stopping ${t}…`,kind:"info"};case"delivered":return{text:`Stopped: ${t}'s turn was cut off. The plan is back in planning.`,kind:"info"};case"failed":case"expired":return{text:`${t} could not be stopped from here${e.detail?` (${e.detail})`:""}: stop it in its own window. Its next dcursed tool tells it to stop.`,kind:"error"};default:return null}if(e.kind==="passed"||e.kind==="sentBack"){const i=e.kind==="passed"?"Checkpoint passed":`Sent ${e.step??"the step"} back`,o=e.text.replace(/^\[DiaCode\] /,"");switch(e.state){case"sent":return{text:`${i}. Telling ${t}…`,kind:"info"};case"delivered":return{text:`${i}, and ${t} was told.`,kind:"info"};case"queued":return{text:`${i}. ${t} hears it when its turn ends, or at its next step.`,kind:"info"};case"failed":case"expired":return{text:`${i}. ${t} could not be woken: tell it yourself.`,kind:"info",copy:o};default:return null}}if(e.kind==="archAccepted")switch(e.state){case"sent":return{text:`Accepted. Telling ${t} that its changes are proposals now…`,kind:"info"};case"delivered":return{text:`Accepted, and ${t} was told: its changes to the architecture are proposals now.`,kind:"info"};case"queued":return{text:`Accepted. ${t} hears it when its turn ends, or at its next architecture tool.`,kind:"info"};case"failed":case"expired":return{text:`Accepted. ${t} could not be woken${e.detail?` (${e.detail})`:""}: it reads it at its next architecture tool.`,kind:"info"};default:return null}if(e.kind==="archSettled")switch(e.state){case"sent":return{text:`Decided. Telling ${t}…`,kind:"info"};case"delivered":return{text:`Decided, and ${t} was told what you did with its proposal.`,kind:"info"};case"queued":return{text:`Decided. ${t} hears it when its turn ends, or at its next architecture tool.`,kind:"info"};case"failed":case"expired":return{text:`Decided. ${t} could not be woken${e.detail?` (${e.detail})`:""}: it reads it at its next architecture tool.`,kind:"info"};default:return null}if(e.kind==="changed")return e.state==="delivered"?{text:`${t} had stopped, so it was told what you changed and is carrying on.`,kind:"info"}:e.state==="failed"?{text:`${t} could not be told what you changed${e.detail?` (${e.detail})`:""}: it reads it at its next step, or tell it to carry on.`,kind:"info"}:null;const n=e.step??"the step",s=e.text.replace(/^\[DiaCode\] /,"");switch(e.state){case"sent":return{text:`Answered ${n}. Telling ${t}…`,kind:"info"};case"delivered":return{text:`Answered ${n}: ${t} has your answer and is carrying on.`,kind:"info"};case"queued":return{text:`Answered ${n}. ${t} reads it at its next step, or when its turn ends.`,kind:"info"};case"failed":case"expired":return{text:`Answered ${n}. ${t} could not be woken: it reads the answer at its next step, or tell it to carry on.`,kind:"info",copy:s};default:return null}}const Qn={working:"working",idle:"idle",error:"hit an error",asking:"waiting for you",quiet:"gone quiet",gone:"gone"};function At(e){return e.permission?.what?`${q(e.actor)} asks your permission to ${e.permission.what}`:`${q(e.actor)} is waiting for you in its own window${e.detail?`: ${e.detail}`:""}`}function jt(e){const t=q(e.owner);switch(e.state){case"idle":return`${t} went idle with this unfinished`;case"error":return`${t} hit an error${e.detail?`: ${e.detail}`:""}`;case"quiet":return`${t} has not been heard from for a while`;default:return`${t} is gone`}}function es(e){return e?e.behind>0?`has not seen the last ${e.behind} change${e.behind===1?"":"s"} (read to rev ${e.rev})`:`has seen everything (rev ${e.rev})`:""}function ts(e,t,n=[]){const s=new Set((e??[]).map(a=>a.actor)),i=a=>n.find(r=>r.actor===a),o=a=>a?`<span class="receipt">${b(es(a))}</span>`:"",l=(e??[]).map(a=>{const r=a.state==="working"?"":be(a.state==="gone"?a.seen:a.since,t),u=(a.state==="error"||a.state==="asking")&&a.detail?`: ${b(a.detail)}`:"",f=i(a.actor);return`<span class="${`agent ${b(a.state)}${f?" has-receipt":""}${f&&f.behind>0?" behind":""}`}"><i></i><span class="who"><b>${b(q(a.actor))}</b> ${b(Qn[a.state]??a.state)}${r?` · ${b(r)}${r==="just now"?"":" ago"}`:""}${u}</span>${o(f)}</span>`});for(const a of n)s.has(a.actor)||l.push(`<span class="agent has-receipt${a.behind>0?" behind":""}"><i></i><span class="who"><b>${b(q(a.actor))}</b></span>${o(a)}</span>`);return l.length?`<div class="agents">${l.join("")}</div>`:""}function Ot(e){if(!e)return"";const t="The re-planner",n=e.kind==="drift"?(e.files??[]).map(b).join(", "):(e.steps??[]).map(b).join(", ");return e.state==="running"?`<p class="lede">${t} is reading ${n||"the plan"}…</p>`:e.state==="failed"?`<p class="err">${t} could not answer: ${b(e.message??"no reason given")}</p>`:`<p class="lede">${t}: ${b(e.message??"done")}.</p>`}function Tt(e){const t=`data-from="${b(e.from)}" data-to="${b(e.to)}"`,n=(i,o,l=!1)=>`<button${l?' class="primary"':""} data-gate="${i}" ${t}>${o}</button>`,s=i=>`<input data-gate-text ${t} placeholder="${b(i)}" aria-label="${b(i)}">`;return e.kind==="approve"?`${n("pass","Approve",!0)}${s("or why it is not right")}${n("back","Send back")}`:e.kind==="input"?`${s("what it needs")}${n("give","Give",!0)}`:e.turn==="you"?`${s("your answer")}${n("give","Answer",!0)}`:n("pass","Let it start without asking")}const Mt=e=>`<input data-answer="${b(e)}" placeholder="your answer" aria-label="Answer ${b(e)}">${D("answer",e,"Answer",!0)}`;function ns(e,t){const n=o=>`<b>${b(t.nodes[o]?.label??o)}</b> <code>${b(o)}</code>`;let s;e.kind==="approve"?s=`Approve the result of ${n(e.from)} before ${n(e.to)} starts`:e.kind==="input"?s=`${n(e.to)} needs input from you${e.label?`: ${b(e.label)}`:""}`:e.turn==="you"?s=`Asked before ${n(e.to)}: <q>${b(e.question??"")}</q>`:s=`Before ${n(e.to)}, the agent is to ask you something. It has not asked yet.`;const i=e.kind==="approve"?t.nodes[e.from]?.note:void 0;return`<li class="step gate" data-step="${b(e.to)}" tabindex="0"><div class="head"><span>${s}</span></div>${i?`<div class="note">${b(i)}</div>`:""}<div class="row actions">${Tt(e)}</div></li>`}const D=(e,t,n,s=!1)=>`<button${s?' class="primary"':""} data-act="${e}" data-step="${b(t)}">${n}</button>`;function ss(e,t,{showStep:n=i=>`<button class="plain small" data-show-step="${b(i)}">Show</button>`,showProposal:s=i=>`<button class="plain small" data-show-proposal="${b(i)}">Show on the board</button>`}={}){const i=t.reconcile?.state==="running",o=(a,r,u,f=!1)=>`<button${f?' class="primary" ':" "}data-act="${a}" data-step="${b(r)}">${u}</button>`,l=a=>{const r=a.step;switch(a.kind){case"question":return`${Mt(r)}${n(r)}`;case"asking":return a.permission?`<button class="primary" data-permit="${b(a.permission.id)}">Allow</button><input data-permit-why="${b(a.permission.id)}" placeholder="why not (optional)" aria-label="Why you deny it"><button data-deny="${b(a.permission.id)}">Deny</button>`:"";case"checkpoint":return`${Tt({...a.gate,turn:"you"})}${n(r)}`;case"failure":return`<button class="primary" data-act="replan" data-step="${b(r)}"${i?" disabled":""}>Re-plan from this</button>${o("reopen",r,"Try again")}${n(r)}`;case"stalled":return`${o("release",r,"Release")}${n(r)}`;case"proposal":return`<button class="primary" data-accept="${b(a.proposal)}">Accept</button><button data-reject="${b(a.proposal)}">Reject</button>${s(a.proposal)}`;case"review":return`<button class="primary" data-reconcile ${i?"disabled":""}>${i?"Looking…":"Ask the re-planner"}</button>${n(r)}`;case"finish":return'<button class="primary" data-finish>Mark plan done</button>';default:return""}};return e.map(a=>`
10
+ <li class="inbox-item" data-kind="${a.kind}">
11
+ <div class="inbox-what"><b>${b(a.title)}</b>${a.detail?`<span class="inbox-detail">${b(a.detail)}</span>`:""}</div>
12
+ ${l(a)?`<div class="row actions">${l(a)}</div>`:""}
13
+ ${a.kind==="review"?Ot(t.reconcile):""}
14
+ </li>`).join("")}const po=(e,t,n)=>`<ul class="inbox">${ss(e,t,n)}</ul>`;function os(e,t,n){return e?.length?`<h4>Outside the plan</h4><p class="lede">Agents edited these files, and no step lists them.</p>
15
+ <ul class="items steps">${e.map(s=>`<li class="step"><code>${b(s.file)}</code><div class="meta"><span class="who">${b(q(s.by))}</span> · ${s.count}× · ${b(be(s.at,t))}${be(s.at,t)==="just now"?"":" ago"}</div></li>`).join("")}</ul>
16
+ <div class="row"><button class="primary" data-act="drift" data-step=""${n?" disabled":""}>Should the plan cover this?</button></div>`:""}function as(e){const t=(n,s)=>n?`<i style="flex:${n};background:${s}"></i>`:"";return`<div class="progress" role="img" aria-label="${e.done} of ${e.total} done">${t(e.done,L.done)}${t(e.active,L.in_progress)}${t(e.waiting,L.waiting)}${t(e.failed,L.failed)}${t(e.left,"var(--line)")}</div>`}function is(e){return[`${e.done} of ${e.total} done`,e.active?`${e.active} working`:"",e.waiting?`${e.waiting} waiting for you`:"",e.failed?`${e.failed} failed`:"",e.atRisk?`${e.atRisk} at risk`:"",e.cancelled?`${e.cancelled} cancelled`:""].filter(Boolean).join(" · ")}function ho(e,{now:t=Date.now()}={}){const n=e.plan,{derived:s,review:i={},recent:o=[]}=e,l=s.progress,a=new Map((e.presence??[]).filter(h=>h.state==="asking").map(h=>[h.actor,h])),r=Object.entries(n.nodes).filter(([,h])=>h.kind!=="context"),u=new Set((s.gates??[]).filter(h=>h.turn==="agent").map(h=>h.to));if(!r.length)return'<p class="lede">No steps yet. Double-click the board to add one, or ask your agent to draft the plan: “Draft a plan for … with the dcursed tools.” What it writes appears here as it goes.</p>';const f=(h,v,W,Nt={})=>{const ae=Ie(v),fe=v.status??"not_started",We=s.atRisk?.[h],He=s.stalled?.[h],Ue=s.blocked?.[h],Ke=s.held?.[h],ve=be(Zn(o,h),t),H=[];return ae&&H.push(`<span class="who" title="${b(Ce[ae.from])}">${Fe[ae.from]} ${b(q(ae.who))}</span> <span class="how">${b(Ce[ae.from])}</span>`),ve&&fe!=="not_started"&&H.push(`<span class="how">${b(ve)}${ve==="just now"?"":" ago"}</span>`),Ue&&fe!=="not_started"&&H.push(`<span class="how">blocked by ${Ue.map(b).join(", ")}</span>`),Ke&&H.push(u.has(h)?'<span class="how">the agent asks you something before it starts</span>':`<span class="how">waits at a checkpoint after ${Ke.map(b).join(", ")}</span>`),He&&H.push(`<span class="risk">stalled: ${b(jt(He))}</span>`),fe==="in_progress"&&v.owner&&a.has(v.owner)&&H.push(`<span class="risk">${b(At(a.get(v.owner)))}</span>`),We&&H.push(`<span class="risk">at risk: ${We.map(b).join(", ")} failed</span>`),h in i&&H.push('<span class="how">needs review</span>'),`
17
+ <li class="step" data-step="${b(h)}" tabindex="0">
18
+ <div class="head"><span><i class="dot" style="background:${L[fe]??"var(--wire-soft)"}"></i><b>${b(v.label)}</b> <code>${b(h)}</code></span><button class="plain small" data-inspect="${b(h)}" aria-label="Details of ${b(v.label)}">Details</button></div>
19
+ ${H.length?`<div class="meta">${H.join(" · ")}</div>`:""}
20
+ ${v.note?`<div class="note">${b(v.note)}</div>`:""}
21
+ ${Nt.showQuestion?`<div class="row">${Mt(h)}</div>`:""}
22
+ ${W.length?`<div class="row actions">${W.join("")}</div>`:""}
23
+ </li>`},g=(h,v,W="")=>v.length?`<h4>${h}</h4>${W?`<p class="lede">${W}</p>`:""}<ul class="items steps">${v.join("")}</ul>`:"",p=h=>r.filter(([v,W])=>h(W,v)),d=h=>h.status??"not_started",c=e.reconcile?.state==="running",$=(s.gates??[]).filter(h=>h.turn==="you"),m=p(h=>d(h)==="waiting"),S=p(h=>d(h)==="failed"),O=p((h,v)=>d(h)==="in_progress"&&v in(s.stalled??{})),R=p((h,v)=>d(h)==="in_progress"&&!(v in(s.stalled??{}))),E=p((h,v)=>d(h)==="not_started"&&s.ready.includes(v)),T=p((h,v)=>d(h)==="not_started"&&!s.ready.includes(v)),x=p(h=>d(h)==="done"),A=p(h=>d(h)==="cancelled"),M=new Set(e.listening??[]),ue=m.length>0&&m.every(([,h])=>h.owner&&M.has(h.owner))?"An agent stopped to ask. Your answer is sent to it, and it carries on.":"An agent stopped to ask. An agent listening for the editor is woken with your answer; any other reads it at its next step, so tell it to carry on.",xe=h=>h.owner==="you",ee=n.phase==="planning"?"Nothing is in front of these: the agent starts here once you approve the plan.":"Nothing is in front of these: an agent takes them next. To do one yourself, open its Details.";return`
24
+ ${as(l)}
25
+ <p class="lede">${is(l)}</p>
26
+ ${n.phase==="planning"?`<p class="lede">Planning: agents' changes land at once. When the plan looks right, press <b>Approve plan</b> in the plan header above the chart; after that, an agent's changes to steps and arrows arrive as proposals for you to accept.</p>`:""}
27
+ ${n.phase==="paused"?'<p class="lede"><b>Paused.</b> Agents finish the step they are on and start nothing new. Press <b>Resume</b> in the plan header to carry on.</p>':""}
28
+ ${e.stopping?.length?`<p class="lede"><b>Stopping ${b(St(e.stopping))}:</b> ${e.stopping.length===1?"it stops":"they stop"} at the next tool call, and the turn ends there.</p>`:""}
29
+ ${ts(e.presence,t,e.reads)}
30
+ ${Ot(e.reconcile)}
31
+ ${n.proposals?.length?`<p class="lede"><button data-show-proposal="${b(n.proposals[0].id)}">${n.proposals.length===1?"A proposal is":`${n.proposals.length} proposals are`} waiting for you: show ${n.proposals.length===1?"it":"them"} on the board</button></p>`:""}
32
+ ${g("At a checkpoint",$.map(h=>ns(h,n)),"The plan waits for you here before the next step starts. What you say goes to the agent with it.")}
33
+ ${g("Waiting for you",m.map(([h,v])=>f(h,v,[D("cancel",h,"Cancel step")],{showQuestion:!0})),ue)}
34
+ ${g("Stalled",O.map(([h,v])=>f(h,v,[D("done",h,"Mark done"),D("failed",h,"Mark failed"),D("release",h,"Release")])),"The agent holding these has stopped, and the plan still says in progress.")}
35
+ ${g("Failed",S.map(([h,v])=>f(h,v,[`<button class="primary" data-act="replan" data-step="${b(h)}"${c?" disabled":""}>Re-plan from this</button>`,D("reopen",h,"Try again"),D("cancel",h,"Cancel step")])))}
36
+ ${os(e.drift,t,c)}
37
+ ${g("Working now",R.map(([h,v])=>f(h,v,xe(v)?[D("done",h,"Mark done"),D("failed",h,"Mark failed"),D("release",h,"Release")]:[])))}
38
+ ${g(n.phase==="planning"?"First up":"Ready",E.map(([h,v])=>f(h,v,[D("cancel",h,"Cancel step")])),ee)}
39
+ ${g("Blocked",T.map(([h,v])=>f(h,v,[D("cancel",h,"Cancel step")])))}
40
+ ${g("Done",x.map(([h,v])=>f(h,v,[D("reopen",h,"Reopen")])),"Finished steps are locked on the chart: reopen one to change it.")}
41
+ ${g("Cancelled",A.map(([h,v])=>f(h,v,[D("reopen",h,"Reopen")])))}`}function rs(e){const t=e?.plan?.nodes??{},n=Object.entries(t).filter(([,p])=>p&&p.kind!=="context"),s=(e?.presence??[]).filter(p=>p?.state==="asking").map(p=>String(p.actor)),i=n.filter(([,p])=>p.status==="waiting").map(([p])=>p),o=n.filter(([,p])=>p.status==="failed").map(([p])=>p),l=Object.keys(e?.derived?.stalled??{}).filter(p=>t[p]?.status==="in_progress"),a=(e?.plan?.proposals??[]).length,r=(e?.derived?.gates??[]).filter(p=>p.turn==="you").map(p=>({from:p.from,to:p.to})),u=e?.derived?.proposed??{},f=Object.keys(e?.review??{}).filter(p=>t[p]&&t[p].kind!=="context"&&!(p in u)),g=e?.plan?.phase==="executing"&&n.length>0&&n.every(([,p])=>p.status==="done"||p.status==="cancelled");return{asking:s,questions:i,failures:o,stalled:l,proposals:a,gates:r,reviews:f,finish:g,total:s.length+i.length+o.length+l.length+a+r.length+(g?1:0)}}const J=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`;function $o(e){const t=[e.asking.length?`${J(e.asking.length,"agent")} asking you in ${e.asking.length===1?"its window":"their windows"}`:"",e.questions.length?J(e.questions.length,"question"):"",e.gates?.length?J(e.gates.length,"checkpoint"):"",e.failures.length?J(e.failures.length,"failure"):"",e.stalled.length?`${e.stalled.length} stalled`:"",e.proposals?J(e.proposals,"proposal")+" to review":"",e.reviews?.length?`${J(e.reviews.length,"step")} to review`:"",e.finish?"the finished plan to close":""].filter(Boolean);return t.length?`Waiting on you: ${t.join(", ")}.`:""}function go(e){const t=rs(e),n=e?.plan?.nodes??{},s=o=>n[o]?.label??o,i=[];for(const o of(e?.presence??[]).filter(l=>l?.state==="asking"))i.push({key:`asking:${o.actor}:${o.permission?.id??""}`,kind:"asking",title:At(o),...o.permission?{permission:o.permission}:{}});for(const o of t.questions)i.push({key:`question:${o}`,kind:"question",step:o,title:`${s(o)} asks you`,...n[o]?.note?{detail:n[o].note}:{}});for(const o of(e?.derived?.gates??[]).filter(l=>l.turn==="you")){const l=o.kind==="approve"?`Approve the result of ${s(o.from)} before ${s(o.to)} starts`:o.kind==="input"?`${s(o.to)} needs input from you${o.label?`: ${o.label}`:""}`:`Before ${s(o.to)}, the agent asks: ${o.question??""}`,a=o.kind==="approve"?n[o.from]?.note:void 0;i.push({key:`gate:${o.from}>${o.to}`,kind:"checkpoint",step:o.to,title:l,...a?{detail:a}:{},gate:{from:o.from,to:o.to,kind:o.kind,label:o.label,question:o.question}})}for(const o of t.failures)i.push({key:`failure:${o}`,kind:"failure",step:o,title:`${s(o)} failed`,...n[o]?.note?{detail:n[o].note}:{}});for(const o of t.stalled)i.push({key:`stalled:${o}`,kind:"stalled",step:o,title:`${s(o)} has stalled`,detail:jt(e?.derived?.stalled?.[o])});for(const o of e?.plan?.proposals??[])i.push({key:`proposal:${o.id}`,kind:"proposal",proposal:o.id,title:`Proposal ${o.id} from ${q(String(o.by))}`,...o.reason?{detail:o.reason}:{}});if(t.reviews.length){const o=t.reviews.slice(0,3).map(s).join(", ");i.push({key:"review",kind:"review",steps:t.reviews,step:t.reviews[0],title:`Review ${J(t.reviews.length,"step")}`,detail:`${o}${t.reviews.length>3?` and ${t.reviews.length-3} more`:""}: a change upstream of ${t.reviews.length===1?"it":"them"} may have made ${t.reviews.length===1?"it":"them"} wrong`})}return t.finish&&i.push({key:"finish",kind:"finish",title:"Every step is done",detail:"Mark the plan done to close it. What it planned in the architecture is then put to you to make real."}),i}const mo=(e,t)=>t>0?`(${t}) ${e}`:e,ls=e=>/[*?]/.test(e);function Et(e){let t=String(e??"").trim().replace(/^(\.\/)+/,"");return t?(t.endsWith("/")&&!ls(t)&&(t=`${t}**`),t):""}function wo(e,t){const n=Et(t);return!n||e.includes(n)||e.length>=se?e:[...e,n]}const bo=(e,t)=>e.filter(n=>n!==t);function ds(e){if(!e)return{note:"",warn:!1};switch(e.kind){case"pattern":{const t=e.matches??0;return t===0?{note:"matches no files",warn:!0}:{note:`matches ${t} file${t===1?"":"s"}`,warn:!1}}case"new":return{note:"new file",warn:!1};case"folder":return{note:"a folder: add folder/** to watch what is in it",warn:!0};case"withheld":return{note:"private or ignored by git",warn:!1};default:return{note:"",warn:!1}}}function yo(e,t,n,s){const i=t.filter(l=>!s.includes(l)).map(l=>({kind:"file",path:l,note:""})),o=Et(e);if(!o||!n)return i;if(n.kind==="pattern"&&!s.includes(o)){const l=n.matches??0;i.push({kind:"pattern",path:o,note:l===0?"a pattern: matches no files":`a pattern: matches ${l} file${l===1?"":"s"}`})}else if(n.kind==="folder"){const l=`${o.replace(/\/+$/,"")}/**`;s.includes(l)||i.push({kind:"folder",path:l,note:"everything in this folder"})}else n.kind==="new"&&!s.includes(o)&&/[./]/.test(o)&&i.push({kind:"new",path:o,note:"a file this step will create"});return i}const k=e=>String(e).replace(/[&<>"]/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[t]),rt={not_started:"not started",in_progress:"in progress",waiting:"waiting for you",done:"done",failed:"failed",cancelled:"cancelled"},cs=(e,t=150)=>e.length>t?`${e.slice(0,t-1)}…`:e;function ko(e,t,n){if(t==="detail")return{op:"node.set",id:e,detail:n.replace(/\s+$/,"")};if(t==="files")return{op:"node.set",id:e,files:[...new Set(n.split(`
42
+ `).map(s=>s.trim()).filter(Boolean))]};throw new Error(`a step has no field "${t}" to edit here`)}function _t(e,t,n={}){return t.length?t.map(s=>{const{note:i,warn:o}=ds(n[s]);return`<li class="file-chip${o?" warn":""}" data-path="${k(s)}"><code>${k(s)}</code>${i?`<span class="chip-note">${k(i)}</span>`:""}<button type="button" class="chip-x" data-remove-file="${k(s)}" data-step="${k(e)}" aria-label="Stop listing ${k(s)}">×</button></li>`}).join(""):'<li class="chips-none">None yet.</li>'}const us=(e,t)=>e.id===t||e.from===t||e.to===t||Array.isArray(e.ids)&&e.ids.includes(t);function fs(e,t,n=6){return[...e??[]].reverse().map(s=>({line:s,ops:(s.ops??[]).filter(i=>us(i,t))})).filter(s=>s.ops.length).slice(0,n).map(({line:s,ops:i})=>({rev:s.rev,actor:s.actor,text:i.map(o=>Qt(o)).join("; "),...s.proposed?{proposed:s.proposed}:{}}))}function xo({plan:e,id:t,derived:n={},review:s={},recent:i=[],drafts:o={},fileInfo:l={},arch:a=null}){const r=e?.nodes?.[t];if(!r)return"";const u=r.kind==="context"?"context":r.status??"not_started",f=L[u]??"var(--wire-soft)",g=Ie(r),p=n.blocked?.[t],d=n.stalled?.[t],c=n.atRisk?.[t],$=n.proposed?.[t],m=[`<b>${k(r.kind==="context"?"context, not work":rt[u]??u)}</b>`];g&&m.push(`${k(Fe[g.from])} ${k(q(g.who))}, ${k(Ce[g.from])}`),p?.length&&m.push(k(vt(p))),d&&m.push(`<span class="risk">stalled: ${k(q(d.owner))} is ${k(d.state)}</span>`),c?.length&&m.push(`<span class="risk">at risk: ${c.map(k).join(", ")} failed</span>`),s[t]&&m.push(`needs review: ${s[t].because.map(k).join("; ")} <button class="plain small" data-review="${k(t)}" title="I looked: no change is needed">Looks fine</button>`),$?.length&&m.push(`${$.length===1?"a proposal waits":`${$.length} proposals wait`} to change it (${$.map(k).join(", ")}): shown on the board`);const S=(T,x)=>T.length?`<ul class="rel">${T.map(A=>{const M=e.nodes[A],P=M.kind==="context"?"context":M.status??"not_started";return`<li><i class="dot" style="background:${L[P]??"var(--wire-soft)"}"></i>${k(M.label)} <code>${k(A)}</code> <span class="how">${k(rt[P]??P)}</span></li>`}).join("")}</ul>`:`<p class="help">${x}</p>`,O=fs(i,t),R=o.detail??r.detail??"",E=T=>T?' <b class="unsaved">Not saved yet.</b>':"";return`
43
+ <section class="inspector" aria-label="Step: ${k(r.label)}">
44
+ <header>
45
+ <div><i class="dot" style="background:${f}"></i><b class="name">${k(r.label)}</b> <code>${k(t)}</code></div>
46
+ <button class="plain" data-close-inspector aria-label="Close the details of ${k(r.label)}">Close</button>
47
+ </header>
48
+ <p class="facts">${m.join(" · ")}</p>
49
+
50
+ <label for="insp-detail">What done means</label>
51
+ <textarea id="insp-detail" data-field="detail" data-step="${k(t)}" rows="5" maxlength="${G}" placeholder="Not written yet. Say what is true when this step is finished: the tests that pass, the behaviour that works.">${k(R)}</textarea>
52
+ <p class="help">An agent is given this with the step. Saved when you leave the box.${E(o.detail!==void 0&&o.detail!==(r.detail??""))}</p>
53
+ <div class="row"><button class="primary" data-save-field="detail" data-step="${k(t)}">Save</button></div>
54
+
55
+ <label for="insp-files">Files this step changes</label>
56
+ <div class="files" data-files-for="${k(t)}">
57
+ <ul class="chips" aria-label="Files this step lists">${_t(t,r.files??[],l)}</ul>
58
+ <div class="files-add">
59
+ <input id="insp-files" type="text" role="combobox" aria-expanded="false" aria-autocomplete="list" aria-controls="insp-files-list" autocomplete="off" spellcheck="false" data-files-input="${k(t)}" placeholder="Search the repository, or type a path or a pattern">
60
+ <ul class="files-menu" id="insp-files-list" role="listbox" aria-label="Files to add" hidden></ul>
61
+ </div>
62
+ </div>
63
+ <p class="help">At most ${se}. A pattern such as <code>src/**/*.js</code> says how many files it matches. A file this step will create can be named before it exists. When an agent edits a file only this step lists, the step is marked started: that is how a start is <em>seen</em>.</p>
64
+
65
+ ${hs(a,t,r)}
66
+ ${ps(e,t,r,n)}
67
+ <h5>Depends on</h5>
68
+ ${S(It(e,t),"Nothing: it can start.")}
69
+ <h5>Waited on by</h5>
70
+ ${S(ft(e,t),"Nothing depends on it.")}
71
+ <h5>History</h5>
72
+ ${O.length?`<ul class="hist">${O.map(T=>`<li><span class="how">rev ${k(T.rev)} · ${k(q(T.actor))}${T.proposed?" (a proposal)":""}</span> ${k(cs(T.text))}</li>`).join("")}</ul>`:'<p class="help">Nothing done to it lately.</p>'}
73
+ </section>`}function ps(e,t,n,s){if(n.kind==="context")return"";const i=n.status??"not_started",o=(f,g)=>`<button data-act="${f}" data-step="${k(t)}">${g}</button>`,l=[],a=Array.isArray(s.ready)&&s.ready.includes(t);i==="not_started"&&a&&l.push(o("start","Start it myself"),o("done","Mark done")),i==="in_progress"&&l.push(o("done","Mark done"),o("failed","Mark failed"),...n.owner?[o("release",n.owner==="you"?"Release":"Take it back from the agent")]:[]);const r=(s.gates??[]).filter(f=>f.to===t&&f.turn==="agent");for(const f of r)l.push(`<button data-gate="pass" data-from="${k(f.from)}" data-to="${k(f.to)}">Let it start without asking</button>`);return l.length?`<h5>Do it yourself</h5><p class="help">${n.owner&&n.owner!=="you"?`${k(q(n.owner))} has this step. `:""}These change the plan for the agent: it is told at its next step.</p><div class="row actions">${l.join("")}</div>`:""}function hs(e,t,n){if(!e)return'<h5>Boxes it changes</h5><p class="help">This repository has no architecture yet, so there is no box to name. Draw one in the Architecture view, or ask your agent to.</p>';const s=En(e,n),i=new Set(n.touches??[]),o=a=>{const r=e.nodes[a.id],u=r?r.label:a.id;return a.by==="hand"?`<li class="file-chip${r?"":" warn"}" data-box="${k(a.id)}"><span>${k(u)}</span>${r?"":'<span class="chip-note">not in the architecture</span>'}<button type="button" class="chip-x" data-remove-touch="${k(a.id)}" data-step="${k(t)}" aria-label="Stop saying it changes ${k(u)}">×</button></li>`:`<li class="file-chip" data-box="${k(a.id)}"><span>${k(u)}</span><span class="chip-note">from its files</span></li>`},l=Object.entries(e.nodes).filter(([a])=>!i.has(a));return`
74
+ <h5>Boxes it changes</h5>
75
+ <ul class="chips touches" aria-label="Boxes of the architecture this step changes">${s.length?s.map(o).join(""):'<li class="chips-none">None named.</li>'}</ul>
76
+ <select data-touch-add="${k(t)}" aria-label="Add a box this step changes"><option value="">Add a box…</option>${l.map(([a,r])=>`<option value="${k(a)}">${k(r.label)} (${k(r.kind)})</option>`).join("")}</select>
77
+ <p class="help">What a plan does to the architecture: the Architecture view shows these boxes as changed. The ones this step's files fall in are included without being named.</p>`}const lt={person:"Person",service:"Service",component:"Component",store:"Store",queue:"Queue",group:"Group"},$s={person:"a user or a role",service:"something that runs: an app, an API, a worker",component:"a part inside a service: a package, a folder, a file",store:"where data lives: a database, a cache, a bucket",queue:"a message channel: a queue, a topic, an event bus",group:"a frame round other boxes"},y=e=>Math.round(e*100)/100;function vo(e,{x:t,y:n,w:s,h:i},{folded:o=!1}={}){const l=t-s/2,a=t+s/2,r=n-i/2,u=n+i/2,f=[],g=(d,c,$={})=>f.push({tag:"path",role:c,attrs:{d,...$}}),p=(d,c=0,$=0)=>`M${y(l+c+d)} ${y(r+$)}H${y(a+c-d)}A${d} ${d} 0 0 1 ${y(a+c)} ${y(r+$+d)}V${y(u+$-d)}A${d} ${d} 0 0 1 ${y(a+c-d)} ${y(u+$)}H${y(l+c+d)}A${d} ${d} 0 0 1 ${y(l+c)} ${y(u+$-d)}V${y(r+$+d)}A${d} ${d} 0 0 1 ${y(l+c+d)} ${y(r+$)}Z`;switch(e){case"store":{const d=s/2,c=Math.min(9,Math.max(5,i*.18));g(`M${y(l)} ${y(r+c)}A${y(d)} ${y(c)} 0 0 1 ${y(a)} ${y(r+c)}V${y(u-c)}A${y(d)} ${y(c)} 0 0 1 ${y(l)} ${y(u-c)}Z`,"fill"),g(`M${y(l)} ${y(r+c)}A${y(d)} ${y(c)} 0 0 0 ${y(a)} ${y(r+c)}`,"line");break}case"queue":{const d=Math.min(12,s/5),c=i/2;g(`M${y(l+d)} ${y(r)}H${y(a-d)}A${y(d)} ${y(c)} 0 0 1 ${y(a-d)} ${y(u)}H${y(l+d)}A${y(d)} ${y(c)} 0 0 1 ${y(l+d)} ${y(r)}Z`,"fill"),g(`M${y(l+d)} ${y(r)}A${y(d)} ${y(c)} 0 0 0 ${y(l+d)} ${y(u)}`,"line");break}case"person":{f.push({tag:"circle",role:"fill",attrs:{cx:y(t),cy:y(r-4),r:7.5}}),g(p(Math.min(i/2,13)),"fill");break}case"component":o&&g(p(3,5,-5),"back"),g(p(3),"fill");break;case"group":{o&&g(p(10,5,-5),"back",{dashed:1}),g(p(10),"fill",{dashed:1});break}default:{const d=Math.min(14,i/2);o&&g(p(d,5,-5),"back"),g(p(d),"fill")}}return f}const gs={ring:'<circle cx="6" cy="6" r="3.2"/>',half:'<circle cx="6" cy="6" r="3.6"/><path d="M6 2.4a3.6 3.6 0 0 1 0 7.2z" fill="currentColor" stroke="none"/>',hourglass:'<path d="M3.5 2.5h5L6 6zM3.5 9.5h5L6 6z" fill="currentColor"/>',check:'<path d="M3 6.3l2.2 2.2L9 3.9"/>',cross:'<path d="M3.6 3.6l4.8 4.8M8.4 3.6L3.6 8.4"/>',slash:'<circle cx="6" cy="6" r="3.6"/><path d="M3.5 8.5l5-5"/>',question:'<path d="M4.4 4.6c0-1 .7-1.8 1.7-1.8s1.7.7 1.7 1.6c0 1.4-1.7 1.4-1.7 2.8"/><path d="M6.1 9.2v.1"/>',pencil:'<path d="M3 9l.5-2.1 4.3-4.3 1.6 1.6L5.1 8.5z"/><path d="M7 3.5l1.6 1.6"/>',exclaim:'<path d="M6 2.8v4"/><path d="M6 9.2v.1"/>',plus:'<path d="M6 3v6M3 6h6"/>',async:'<path d="M2 6h1.6M5.2 6h1.6M8.4 6h1.6"/>',fold:'<path d="M3.2 4.2L6 7l2.8-2.8"/>',unfold:'<path d="M3.2 7.8L6 5l2.8 2.8"/>'},So={approve:"check",ask:"question",input:"pencil"},Ao={approve:"approve",ask:"ask first",input:"needs input"},ms=e=>`<g fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">${gs[e]??""}</g>`,ws=(e,{size:t=14,colour:n}={})=>`<svg class="glyph" viewBox="0 0 12 12" width="${t}" height="${t}" aria-hidden="true"${n?` style="color:${n}"`:""}>${ms(e)}</svg>`,w=e=>String(e).replace(/[&<>"]/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[t]),bs=(e,t=150)=>e.length>t?`${e.slice(0,t-1)}…`:e,ys=e=>`${e.external?"an outside":"a"} ${e.kind}`;function jo({arch:e,id:t,footprint:n=null,steps:s={},drafts:i={},fileInfo:o={},recent:l=[],editable:a=!0}){const r=e.nodes[t];if(!r)return"";const u=X(e,t),f=r.in?e.nodes[r.in]:void 0,g=n?kt(e,n,t):null,p=[`<b>${w(ys(r))}</b>`];f&&p.push(`in <button class="plain small" data-inspect="${w(r.in)}">${w(f.label)}</button>`),u.length&&p.push(`a frame: it holds ${u.length} box${u.length===1?"":"es"}, and takes no arrows of its own`),r.planned&&p.push(`<span class="plan-note new">planned by <code>${w(r.planned)}</code>: it does not exist yet</span>`),r.retiring&&p.push(`<span class="plan-note removed">retiring: <code>${w(r.retiring)}</code> removes it</span>`),g&&g!=="untouched"&&p.push(`<span class="plan-note ${g}">${ws(Re[g].icon,{size:12})} ${w(Re[g].word)} by ${w(n?.plan??"")}</span>`);const d=n?.changed.get(t)??[],c=i.detail??r.detail??"",$=i.tech??r.tech??"",m=a?"":" disabled",S=(x,A)=>x.length?`<ul class="rel">${x.map(M=>{const P=e.nodes[M];return`<li><button class="plain small" data-inspect="${w(M)}">${w(P.label)}</button> <span class="how">${w(P.kind)}</span></li>`}).join("")}</ul>`:`<p class="help">${A}</p>`,O=e.edges.filter(x=>x.from===t),R=e.edges.filter(x=>x.to===t),E=(x,A)=>`<ul class="rel">${x.map(M=>{const P=e.nodes[M[A]];return`<li><button class="plain small" data-inspect="${w(M[A])}">${w(P.label)}</button> <span class="how">${w([M.label,M.tech,M.async?"async":""].filter(Boolean).join(" · ")||P.kind)}</span></li>`}).join("")}</ul>`,T=[...l].reverse().map(x=>({l:x,ops:(x.ops??[]).filter(A=>A.id===t||A.from===t||A.to===t)})).filter(x=>x.ops.length).slice(0,6);return`
78
+ <section class="inspector box-card" aria-label="Box: ${w(r.label)}" data-box="${w(t)}">
79
+ <header>
80
+ <div><i class="dot kind-${w(r.kind)}"></i><b class="name">${w(r.label)}</b> <code>${w(t)}</code></div>
81
+ <button class="plain" data-close-inspector aria-label="Close the details of ${w(r.label)}">Close</button>
82
+ </header>
83
+ <p class="facts">${p.join(" · ")}</p>
84
+ ${d.length?`<p class="facts">Changed by ${d.map(x=>w(s[x]?.label??x)).join(", ")}.</p>`:""}
85
+ <p class="help">${w($s[r.kind]??"")}. Double-click the box to rename it.</p>
86
+
87
+ <div class="row fields">
88
+ <label>What it is <select data-box-field="kind" data-box="${w(t)}"${m} aria-label="What ${w(r.label)} is">${Object.keys(lt).map(x=>`<option value="${x}"${x===r.kind?" selected":""}${u.length&&x!=="service"&&x!=="group"?" disabled":""}>${w(lt[x])}</option>`).join("")}</select></label>
89
+ <label class="check"><input type="checkbox" data-box-field="external" data-box="${w(t)}"${r.external?" checked":""}${m}> Someone else runs it</label>
90
+ </div>
91
+
92
+ <label for="insp-tech">What it runs on</label>
93
+ <input id="insp-tech" type="text" data-box-field="tech" data-box="${w(t)}" maxlength="${Z}" value="${w($)}" placeholder="Python, FastAPI"${m}>
94
+
95
+ <label for="insp-detail">What it is for</label>
96
+ <textarea id="insp-detail" data-box-field="detail" data-box="${w(t)}" rows="4" maxlength="${G}" placeholder="Not written yet. Say what this box is for, and what it is not."${m}>${w(c)}</textarea>
97
+ <p class="help">An agent reads this with the architecture. Saved when you leave the box.${i.detail!==void 0&&i.detail!==(r.detail??"")?' <b class="unsaved">Not saved yet.</b>':""}</p>
98
+
99
+ ${a?`<label for="insp-files">The files that are its</label>
100
+ <div class="files" data-files-for="${w(t)}">
101
+ <ul class="chips" aria-label="Files this box owns">${_t(t,r.files??[],o)}</ul>
102
+ <div class="files-add">
103
+ <input id="insp-files" type="text" role="combobox" aria-expanded="false" aria-autocomplete="list" aria-controls="insp-files-list" autocomplete="off" spellcheck="false" data-files-input="${w(t)}" placeholder="Search the repository, or type a path or a pattern">
104
+ <ul class="files-menu" id="insp-files-list" role="listbox" aria-label="Files to add" hidden></ul>
105
+ </div>
106
+ </div>
107
+ <p class="help">At most ${se}. A plan whose step lists a file one of these covers is shown as changing this box.</p>`:""}
108
+
109
+ <h5>Uses</h5>
110
+ ${O.length?E(O,"to"):'<p class="help">Nothing.</p>'}
111
+ <h5>Used by</h5>
112
+ ${R.length?E(R,"from"):'<p class="help">Nothing.</p>'}
113
+ ${u.length?`<h5>Holds</h5>${S(u,"")}`:""}
114
+ <h5>History</h5>
115
+ ${T.length?`<ul class="hist">${T.map(({l:x,ops:A})=>`<li><span class="how">rev ${w(x.rev)} · ${w(q(x.actor))}${x.proposed?" (a proposal)":""}</span> ${w(bs(A.map(M=>ke(M)).join("; ")))}</li>`).join("")}</ul>`:'<p class="help">Nothing done to it lately.</p>'}
116
+ </section>`}function Oo({arch:e,selected:t=null,folded:n=[],footprint:s=null,foldable:i=!0}){const o=Object.keys(e.nodes);if(!o.length)return'<p class="lede">Nothing is drawn yet. Double-click the board to add a box, or ask your agent to draw the architecture.</p>';const l=a=>{const r=e.nodes[a],u=X(e,a),f=s?kt(e,s,a):null,g=f&&f!=="untouched"?` <span class="plan-note ${f}">${w(Re[f].word)}</span>`:r.planned?' <span class="plan-note new">planned</span>':r.retiring?' <span class="plan-note removed">retiring</span>':"",p=n.includes(a);return`<li class="box-item" data-box="${w(a)}">
117
+ <button class="plain box-row" data-inspect="${w(a)}"${a===t?' aria-current="true"':""}><i class="dot kind-${w(r.kind)}"></i><span class="box-name">${w(r.label)}</span> <span class="how">${w(r.external?`outside ${r.kind}`:r.kind)}${r.tech?` · ${w(r.tech)}`:""}</span>${g}</button>
118
+ ${u.length&&i?`<button class="plain small fold" data-fold="${w(a)}" aria-pressed="${p}" title="${p?"Unfold: show what is inside":"Fold: hide what is inside"}">${p?"Unfold":"Fold"}</button>`:""}
119
+ ${u.length?`<ul class="box-children">${u.map(l).join("")}</ul>`:""}
120
+ </li>`};return`<ul class="boxlist" aria-label="Boxes">${o.filter(a=>!e.nodes[a].in).map(l).join("")}</ul>`}function To({arch:e,flowId:t=null,at:n=null,playing:s=!1}){if(!e.flows.length)return`<p class="lede">A flow is what happens, in order, when someone does something: the steps run along the arrows the diagram already has, and you play them here.</p>
121
+ <p class="lede">None yet. Ask your agent to draw one (<code>flow.add</code>), or add one in the Data tab of the Source drawer.</p>`;const i=e.flows.find(r=>r.id===t)??null,o=`<ul class="flowlist" aria-label="Flows">${e.flows.map(r=>`
122
+ <li><button class="plain flow-row" data-flow="${w(r.id)}"${r.id===i?.id?' aria-current="true"':""}><b>${w(r.title)}</b> <span class="how">${r.steps.length} step${r.steps.length===1?"":"s"}</span></button></li>`).join("")}</ul>`;if(!i)return`${o}<p class="help">Pick one to light its steps, one at a time, on the diagram.</p>`;const l=r=>w(e.nodes[r]?.label??r),a=i.steps.map((r,u)=>{const f=Mn(e,r),g=f==="reply"?' <span class="how">a reply</span>':f==="gap"?' <span class="how gap" title="The diagram does not draw this call: either an arrow is missing, or the flow is wrong.">no arrow for it</span>':"";return`<li data-flow-step="${u}"${u===n?' aria-current="step"':""}><button class="plain" data-flow-at="${u}"><span class="n">${u+1}</span> ${l(r.from)} <span aria-hidden="true">→</span> ${l(r.to)}${r.label?` <span class="how">${w(r.label)}</span>`:""}${g}</button></li>`}).join("");return`${o}
123
+ <section class="flow-open" aria-label="${w(i.title)}">
124
+ <header><b>${w(i.title)}</b></header>
125
+ <div class="row">
126
+ <button data-flow-prev aria-label="Previous step"${n===null||n<=0?" disabled":""}>&lsaquo; Back</button>
127
+ <button class="primary" data-flow-play>${s?"Pause":n===null?"Play":n>=i.steps.length-1?"Play again":"Play"}</button>
128
+ <button data-flow-next aria-label="Next step"${n!==null&&n>=i.steps.length-1?" disabled":""}>Next &rsaquo;</button>
129
+ <button class="plain" data-flow-clear>Show everything</button>
130
+ </div>
131
+ <ol class="flow-steps">${a}</ol>
132
+ </section>`}function Mo(e){const t=[...e].reverse();return t.length?`
133
+ <p class="lede">The architecture's log, newest first. It is committed with the architecture, so a pull request shows who did what.</p>
134
+ <ul class="log">${t.map(n=>`
135
+ <li><span class="rev">rev ${n.rev}</span> <code>${w(n.actor)}</code> <span class="via">via ${w(n.via)}</span>
136
+ ${n.proposed?`<span class="via">→ proposal ${w(n.proposed)}</span>`:""}
137
+ <div>${(n.ops??[]).map(s=>w(ke(s))).join(" · ")}</div></li>`).join("")}</ul>`:'<p class="lede">No changes yet. Everything you do here is logged, with who did it.</p>'}function Eo(e,t={}){const n=[];e.phase==="draft"&&n.push({kind:"draft",title:"This architecture is a draft",detail:`${t.by?`${q(t.by)} drew it. `:""}Look it over, then accept it. After that, an agent's changes arrive as proposals for you to accept.`});for(const s of e.proposals??[])n.push({kind:"proposal",title:`${q(s.by)} proposes ${s.ops.length} change${s.ops.length===1?"":"s"} to the architecture`,detail:s.reason??s.ops.map(i=>ke(i)).join("; "),proposal:s.id});return n}function ks(e,{show:t=n=>`<button class="plain small" data-arch-show="${w(n)}">Show on the board</button>`}={}){return e.map(n=>`
138
+ <li class="inbox-item" data-kind="${n.kind}">
139
+ <div class="inbox-what"><b>${w(n.title)}</b>${n.detail?`<span class="inbox-detail">${w(n.detail)}</span>`:""}</div>
140
+ <div class="row actions">${n.kind==="draft"?'<button class="primary" data-arch-accept-draft>Accept the architecture</button>':`<button class="primary" data-arch-accept="${w(n.proposal??"")}">Accept</button>${qt(n.proposal??"")}<button data-arch-reject="${w(n.proposal??"")}">Reject</button>${t(n.proposal??"")}`}</div>
141
+ </li>`).join("")}const _o=(e,t)=>`<ul class="inbox">${ks(e,t)}</ul>`;function qo(e,{at:t,of:n,applies:s,why:i,arch:o}){const l=a=>xs(ke(a),o);return`
142
+ <header><b>${w(q(e.by))} proposes</b>${n>1?` <span class="how">${t} of ${n}</span>`:""}</header>
143
+ ${e.reason?`<p class="reason">${w(e.reason)}</p>`:""}
144
+ <ul class="ops">${e.ops.map(a=>`<li>${w(l(a))}</li>`).join("")}</ul>
145
+ ${s?"":`<p class="risk">It no longer applies: ${w(i??"the architecture changed under it")}.</p>`}
146
+ <div class="row actions"><button class="primary" data-arch-accept="${w(e.id)}"${s?"":" disabled"}>Accept</button>${qt(e.id)}<button data-arch-reject="${w(e.id)}">Reject</button>${n>1?'<button class="plain small" data-arch-next>Next</button>':""}</div>`}const qt=e=>`<input data-arch-why="${w(e)}" placeholder="why not (optional)" aria-label="Why you reject ${w(e)}">`;function xs(e,t){if(!t)return e;const n=Object.keys(t.nodes).sort((i,o)=>o.length-i.length);if(!n.length)return e;const s=new RegExp(`(?<![\\w-])(${n.map(i=>i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|")})(?![\\w-])`,"g");return e.replace(s,i=>t.nodes[i]?.label??i)}function vs({plan:e,step:t,proposal:n,architecture:s,sample:i}={}){const o=l=>encodeURIComponent(l);return s?n?`architecture/proposal/${o(n)}`:i?`architecture/${o(i)}`:"architecture":e?[o(e),...t?["step",o(t)]:n?["proposal",o(n)]:[]].join("/"):""}const Co=e=>`/app/#${vs(e)}`;function Ro(e){const t=e.replace(/^#/,"").split("/").filter(Boolean).map(n=>{try{return decodeURIComponent(n)}catch{return n}});return t.length?t[0]==="architecture"?t[1]==="proposal"&&t[2]?{architecture:!0,proposal:t[2]}:t[1]?{architecture:!0,sample:t[1]}:{architecture:!0}:t[1]==="step"&&t[2]?{plan:t[0],step:t[2]}:t[1]==="proposal"&&t[2]?{plan:t[0],proposal:t[2]}:{plan:t[0]}:{}}const I={padding:9,maxWidth:168,minWidth:66,minHeight:34,fontSize:12.5},Ct=Math.round(I.fontSize*1.35),Ss=e=>Math.max(I.minHeight,e*Ct+I.padding*2),As=16,dt=6,ct={x:Math.ceil(I.maxWidth/2+dt),y:Math.ceil(Ss(3)/2+As+dt/2)},No=e=>({width:e.canvas.width+ct.x*2,height:e.canvas.height+ct.y*2}),he={left:16,right:16,top:32,bottom:14},js=e=>!!e&&e!==ce;function Os(e){const t=new Map;for(const n of e){if(!js(n.group))continue;const s=t.get(n.group);s?s.push(n):t.set(n.group,[n])}return[...t].map(([n,s])=>{const i=Math.min(...s.map(r=>r.x-r.w/2))-he.left,o=Math.max(...s.map(r=>r.x+r.w/2))+he.right,l=Math.min(...s.map(r=>r.y-r.h/2))-he.top,a=Math.max(...s.map(r=>r.y+r.h/2))+he.bottom;return{group:n,x:i,y:l,w:o-i,h:a-l,members:s.map(r=>r.id)}})}const Lo=(e,t,n)=>e.filter(s=>t>=s.x&&t<=s.x+s.w&&n>=s.y&&n<=s.y+s.h).sort((s,i)=>s.w*s.h-i.w*i.h)[0];function Ts(e,t,n=6.6){const s=Math.max(3,Math.floor((t-20)/n));return e.length<=s?e:`${e.slice(0,Math.max(1,s-1))}…`}const Ms={x:14,y:14};let Me;function Rt(e){Me||=document.createElement("canvas").getContext("2d");const t=getComputedStyle(document.documentElement).getPropertyValue("--sans").trim()||"sans-serif";return Me.font=`normal ${I.fontSize}px ${t}`,Me.measureText(e).width}function Es(e){const t=I.maxWidth-I.padding*2,n=String(e??"").split(/\s+/).filter(Boolean),s=[];let i="";for(const o of n){const l=i?`${i} ${o}`:o;i&&Rt(l)>t?(s.push(i),i=o):i=l}return i&&s.push(i),s.length?s:[""]}function ye(e){const t=Es(e),n=Math.max(...t.map(Rt)),s=Ct;return{width:Math.max(I.minWidth,Math.min(I.maxWidth,n+I.padding*2)),height:Math.max(I.minHeight,t.length*s+I.padding*2),lines:t,step:s}}const Ee=e=>String(e).replace(/[&<>"]/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[t]);function _s(e,t,n){const s={...e,...ye(e.label)},i={...t,...ye(t.label)};if(n==="TD"){const f=s.x,g=s.y+s.height/2,p=i.x,d=i.y-i.height/2;if(d<=g)return`M${s.x} ${s.y} L${i.x} ${i.y}`;const c=(g+d)/2;return Math.abs(f-p)<1?`M${f} ${g} V${d}`:`M${f} ${g} V${c} H${p} V${d}`}const o=s.x+s.width/2,l=s.y,a=i.x-i.width/2,r=i.y;if(a<=o)return`M${s.x} ${s.y} L${i.x} ${i.y}`;const u=(o+a)/2;return Math.abs(l-r)<1?`M${o} ${l} H${a}`:`M${o} ${l} H${u} V${r} H${a}`}let qs=0;function Do(e,{labels:t=!1,className:n="",title:s="",margin:i=Ms,edge:o}={}){const l=e.canvas.width+i.x*2,a=e.canvas.height+i.y*2,r=new Map(e.steps.map(c=>[c.id,c])),u=e.direction==="TD"?"TD":"LR",f=`ah${++qs}`,g=e.depends.filter(c=>r.has(c.source)&&r.has(c.target)).map(c=>`<path d="${_s(r.get(c.source),r.get(c.target),u)}" marker-end="url(#${f})"/>`).join(""),p=Os(e.steps.map(c=>{const $=ye(c.label);return{id:c.id,group:c.group,x:c.x,y:c.y,w:$.width,h:$.height}})).map(c=>`<rect x="${c.x.toFixed(1)}" y="${c.y.toFixed(1)}" width="${c.w.toFixed(1)}" height="${c.h.toFixed(1)}" rx="10" fill="var(--frame)" stroke="var(--frame-edge)" stroke-width="1.2"/>`+(t?`<text class="frame-name" x="${(c.x+12).toFixed(1)}" y="${(c.y+19).toFixed(1)}" font-size="11.5" font-weight="600" fill="var(--slate)">${Ee(Ts(c.group,c.w))}</text>`:"")).join(""),d=e.steps.map(c=>{const $=ye(c.label),m=c.x-$.width/2,S=c.y-$.height/2,O=o?.(c.id);let R=`<rect x="${m.toFixed(1)}" y="${S.toFixed(1)}" width="${$.width.toFixed(1)}" height="${$.height.toFixed(1)}" rx="7" fill="var(--surface)" stroke="${O??"var(--wire)"}" stroke-width="${O?3:1.5}"/>`;if(t){const E=$.step,T=c.y-($.lines.length-1)*E/2;R+=$.lines.map((x,A)=>`<text x="${c.x}" y="${(T+A*E).toFixed(1)}" dy=".35em" text-anchor="middle">${Ee(x)}</text>`).join("")}return R}).join("");return`<svg class="${n}" viewBox="0 0 ${l} ${a}" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="${Ee(s||e.title)}" preserveAspectRatio="xMidYMid meet">
147
+ <defs><marker id="${f}" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path d="M0 0 L10 5 L0 10 z" fill="var(--wire)"/></marker></defs>
148
+ <g transform="translate(${i.x} ${i.y})">
149
+ <g class="frames">${p}</g>
150
+ <g fill="none" stroke="var(--wire)" stroke-width="1.4">${g}</g>
151
+ <g class="boxes" font-size="${I.fontSize}" fill="var(--ink)" font-family="var(--sans)">${d}</g>
152
+ </g>
153
+ </svg>`}const Po=()=>(document.fonts?.load('400 12.5px "Geist Variable"',"generator.js drawMaze")??Promise.resolve()).catch(()=>{});export{ct as $,Qs as A,to as B,fo as C,Gs as D,Ce as E,Re as F,Fe as G,mo as H,Xs as I,Xn as J,Do as K,Hs as L,Ls as M,Ns as N,It as O,Bt as P,ft as Q,ut as R,L as S,Rs as T,Cs as U,pt as V,gn as W,de as X,nt as Y,Ws as Z,ce as _,Eo as a,I as a0,No as a1,Bs as a2,gt as a3,he as a4,Ps as a5,vn as a6,kt as a7,Os as a8,Ts as a9,co as aA,$o as aB,Us as aC,_t as aD,bo as aE,ao as aF,po as aG,Ao as aH,Qt as aI,Ks as aJ,Et as aK,yo as aL,wo as aM,ms as aa,So as ab,vo as ac,lt as ad,Is as ae,_o as af,zs as ag,jo as ah,Oo as ai,To as aj,Mo as ak,no as al,Yn as am,so as an,qo as ao,Ds as ap,Lo as aq,Zs as ar,Ro as as,ko as at,St as au,Gn as av,io as aw,oo as ax,xo as ay,ho as az,ks as b,ss as c,uo as d,as as e,is as f,jt as g,Co as h,go as i,At as j,Fs as k,ws as l,eo as m,rs as n,Vs as o,ts as p,lo as q,ro as r,q as s,Po as t,vs as u,Vn as v,Ie as w,Jn as x,Js as y,Ys as z};
@@ -0,0 +1 @@
1
+ @font-face{font-family:Geist Variable;font-style:normal;font-display:swap;font-weight:100 900;src:url(/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2) format("woff2-variations");unicode-range:U+0460-052F,U+1C80-1C8A,U+20B4,U+2DE0-2DFF,U+A640-A69F,U+FE2E-FE2F}@font-face{font-family:Geist Variable;font-style:normal;font-display:swap;font-weight:100 900;src:url(/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2) format("woff2-variations");unicode-range:U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116}@font-face{font-family:Geist Variable;font-style:normal;font-display:swap;font-weight:100 900;src:url(/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2) format("woff2-variations");unicode-range:U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB}@font-face{font-family:Geist Variable;font-style:normal;font-display:swap;font-weight:100 900;src:url(/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2) format("woff2-variations");unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF}@font-face{font-family:Geist Variable;font-style:normal;font-display:swap;font-weight:100 900;src:url(/assets/geist-latin-wght-normal-BgDaEnEv.woff2) format("woff2-variations");unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}@font-face{font-family:Geist Mono Variable;font-style:normal;font-display:swap;font-weight:100 900;src:url(/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2) format("woff2-variations");unicode-range:U+0460-052F,U+1C80-1C8A,U+20B4,U+2DE0-2DFF,U+A640-A69F,U+FE2E-FE2F}@font-face{font-family:Geist Mono Variable;font-style:normal;font-display:swap;font-weight:100 900;src:url(/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2) format("woff2-variations");unicode-range:U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116}@font-face{font-family:Geist Mono Variable;font-style:normal;font-display:swap;font-weight:100 900;src:url(/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2) format("woff2-variations");unicode-range:U+2000-2001,U+2004-2008,U+200A,U+23B8-23BD,U+2500-259F}@font-face{font-family:Geist Mono Variable;font-style:normal;font-display:swap;font-weight:100 900;src:url(/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2) format("woff2-variations");unicode-range:U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB}@font-face{font-family:Geist Mono Variable;font-style:normal;font-display:swap;font-weight:100 900;src:url(/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2) format("woff2-variations");unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF}@font-face{font-family:Geist Mono Variable;font-style:normal;font-display:swap;font-weight:100 900;src:url(/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2) format("woff2-variations");unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}:root{color-scheme:light;--ember: #EA5202;--ember-deep: #B53700;--ink: #19120F;--paper: #FBFAF8;--slate: #69625B;--ground: #F4F2EF;--surface: #FFFFFF;--line: #DDDAD6;--line-soft: #ECEAE6;--ember-tint: #FFEBDA;--ink-raised: #261F1B;--on-ink: #EAE7E3;--on-ink-soft: #AAA39D;--wire: #8F8881;--wire-soft: #C9C3BD;--st-working: #2F6FB0;--st-waiting: #9A6700;--st-done: #2E7D32;--st-failed: #B3261E;--st-grey: #69625B;--frame: #F8F6F3;--frame-edge: #C9C3BD;--ext-fill: #ECE9E5;--family-leaf: #59C666;--family-indigo: #8D9BFF;--family-indigo-deep: #3F51D8;--sans: "Geist Variable", "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;--mono: "Geist Mono Variable", "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace}.wm{color:var(--ember-deep)}.on-ink .wm,.wordmark.on-ink .wm{color:var(--ember)}