archik 0.12.21 → 0.12.22

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.
@@ -219,5 +219,5 @@ ${VZn(p)}
219
219
  `}function WZn(h){return new Blob([n0n(h)],{type:"image/svg+xml;charset=utf-8"})}function YZn(h){return new Promise((g,p)=>{const y=n0n(h),T=new Blob([y],{type:"image/svg+xml;charset=utf-8"}),C=URL.createObjectURL(T);let j=parseFloat(h.getAttribute("width")??"0"),P=parseFloat(h.getAttribute("height")??"0");if(!Number.isFinite(j)||j<=0){const U=h.viewBox?.baseVal;j=U?U.width:h.clientWidth}if(!Number.isFinite(P)||P<=0){const U=h.viewBox?.baseVal;P=U?U.height:h.clientHeight}const q=new Image;q.onload=()=>{try{const U=document.createElement("canvas");U.width=Math.max(1,Math.round(j*n1n)),U.height=Math.max(1,Math.round(P*n1n));const oe=U.getContext("2d");if(!oe)throw new Error("2D canvas context unavailable");const ie=getComputedStyle(document.documentElement).getPropertyValue("--archik-canvas").trim();ie!==""&&(oe.fillStyle=ie,oe.fillRect(0,0,U.width,U.height)),oe.drawImage(q,0,0,U.width,U.height),U.toBlob(le=>{if(URL.revokeObjectURL(C),!le){p(new Error("canvas.toBlob returned null"));return}g(le)},"image/png")}catch(U){URL.revokeObjectURL(C),p(U instanceof Error?U:new Error(String(U)))}},q.onerror=()=>{URL.revokeObjectURL(C),p(new Error("Failed to rasterise SVG — image failed to load"))},q.src=C})}function t1n(h,g){if(typeof document>"u")return;const p=URL.createObjectURL(g),y=document.createElement("a");y.href=p,y.download=h,y.style.display="none",document.body.appendChild(y),y.click(),document.body.removeChild(y),setTimeout(()=>URL.revokeObjectURL(p),1e3)}function i1n(h,g){return`${(h.split("/").pop()??h).replace(/\.ya?ml$/i,"").replace(/^\./,"")}.${g}`}function QZn(h){const g=[];if(g.push(`### ${h.name} (${h.kind})`),h.id!==void 0&&g.push(`- **id**: \`${h.id}\``),h.status&&h.status!=="active"&&g.push(`- **status**: ${h.status}`),h.stack!==void 0&&g.push(`- **stack**: ${h.stack}`),h.description!==void 0&&g.push(`- **description**: ${h.description}`),h.parentId!==void 0&&g.push(`- **parent**: \`${h.parentId}\``),h.responsibilities&&h.responsibilities.length>0){g.push("- **responsibilities**:");for(const y of h.responsibilities)g.push(` - ${y}`)}if(h.interfaces&&h.interfaces.length>0){g.push("- **interfaces**:");for(const y of h.interfaces){const T=y.description!==void 0?` — ${y.description}`:"";g.push(` - \`${y.name}\` (${y.protocol})${T}`)}}const p=h.notes?.filter(y=>y.trim().length>0)??[];if(p.length>0){g.push("- **notes**:");for(const y of p)g.push(` - ${y}`)}return g.join(`
220
220
  `)}function eXn(h,g){const p=g.get(h.from)?.name??h.from,y=g.get(h.to)?.name??h.to,T=h.label!==void 0?`: ${h.label}`:"",C=h.status&&h.status!=="active"?` _(${h.status})_`:"";return`- ${p} **${h.relationship}** ${y}${T}${C}`}function nXn(h){const g=new Map;for(const y of h.nodes)g.set(y.id,y);const p=[];if(p.push(`# ${h.name}`),h.description!==void 0&&p.push("",h.description),p.push("","## Components"),h.nodes.length===0)p.push("","_No components yet._");else for(const y of h.nodes)p.push("",QZn(y));if(p.push("","## Connections"),h.edges.length===0)p.push("","_No connections yet._");else{p.push("");for(const y of h.edges)p.push(eXn(y,g))}return`${p.join(`
221
221
  `)}
222
- `}const tXn={name:"yaml",label:"YAML",extension:".yaml",mime:"application/yaml",export:O7e},iXn={name:"json",label:"JSON",extension:".json",mime:"application/json",export:Vdn},rXn={name:"markdown",label:"Markdown",extension:".md",mime:"text/markdown",export:nXn},cXn=[tXn,iXn,rXn];function t0n({document:h,filename:g,getSvg:p}){const y=async j=>{try{await navigator.clipboard.writeText(j)}catch{}},T=()=>{const j=p?.();j&&t1n(i1n(g,"svg"),WZn(j))},C=async()=>{const j=p?.();if(j)try{const P=await YZn(j);t1n(i1n(g,"png"),P)}catch(P){console.error("PNG export failed:",P)}};return J.jsx(TT,{trigger:j=>J.jsxs("button",{type:"button",className:"archik-btn",children:["Export",J.jsx("span",{style:{opacity:.6},children:j?"▴":"▾"})]}),children:j=>J.jsxs(J.Fragment,{children:[h&&cXn.map(P=>J.jsxs("button",{type:"button",className:"archik-menu-item",onClick:()=>{y(P.export(h)),j()},children:[J.jsx("span",{style:{minWidth:60,color:"var(--archik-fg-dim)"},children:"Copy"}),J.jsx("span",{children:P.label})]},P.name)),h&&J.jsxs(J.Fragment,{children:[J.jsx("hr",{style:{border:0,borderTop:"1px solid var(--archik-border)",margin:"4px 0"}}),J.jsxs("button",{type:"button",className:"archik-menu-item",onClick:()=>{fZn(g,h),j()},children:[J.jsx("span",{style:{minWidth:60,color:"var(--archik-fg-dim)"},children:"Download"}),J.jsx("span",{children:"YAML"})]})]}),p&&J.jsxs(J.Fragment,{children:[J.jsxs("button",{type:"button",className:"archik-menu-item",onClick:()=>{T(),j()},children:[J.jsx("span",{style:{minWidth:60,color:"var(--archik-fg-dim)"},children:"Download"}),J.jsx("span",{children:"SVG"})]}),J.jsxs("button",{type:"button",className:"archik-menu-item",onClick:()=>{C(),j()},children:[J.jsx("span",{style:{minWidth:60,color:"var(--archik-fg-dim)"},children:"Download"}),J.jsx("span",{children:"PNG"})]})]})]})})}const i0n="archik-density",r0n="archik-view-mode",aI=1,O8e="detailed";function uXn(){if(typeof localStorage>"u")return O8e;try{return localStorage.getItem(r0n)==="compact"?"compact":O8e}catch{return O8e}}function sXn(h){if(!(typeof localStorage>"u"))try{localStorage.setItem(r0n,h)}catch{}}function oXn(){if(typeof localStorage>"u")return aI;try{const h=localStorage.getItem(i0n);if(!h)return aI;const g=Number.parseFloat(h);return Number.isFinite(g)?N7e(g):aI}catch{return aI}}function lXn(h){if(!(typeof localStorage>"u"))try{localStorage.setItem(i0n,String(N7e(h)))}catch{}}function N7e(h){return Math.max(.3,Math.min(4,h))}function fXn(h){const g=N7e(h);return{nodeSpacing:Math.round(60*g),layerSpacing:Math.round(100*g),padding:Math.round(40*g)}}function aXn({density:h,onChange:g}){const p=Math.round(h*100);return J.jsx(TT,{align:"end",trigger:y=>J.jsxs("button",{type:"button",className:"archik-btn","aria-expanded":y,title:"Layout density",children:["Spacing",J.jsxs("span",{style:{opacity:.6},children:[p,"%"]})]}),children:()=>J.jsxs("div",{style:{minWidth:240,padding:8},children:[J.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",marginBottom:6},children:[J.jsx("span",{className:"archik-label",style:{margin:0},children:"Node spacing"}),J.jsxs("span",{className:"archik-mono",style:{fontSize:11,color:"var(--archik-fg-dim)"},children:[p,"%"]})]}),J.jsx("input",{type:"range",min:.3,max:4,step:.1,value:h,onChange:y=>g(Number.parseFloat(y.target.value)),style:{width:"100%",accentColor:"var(--archik-accent)"}}),J.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:10,color:"var(--archik-fg-muted)",marginTop:4},children:[J.jsx("span",{children:"tight"}),J.jsx("span",{children:"roomy"})]}),J.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:10},children:J.jsx("button",{type:"button",className:"archik-btn",onClick:()=>g(aI),disabled:h===aI,children:"Reset"})})]})})}function hXn(){return J.jsx(TT,{align:"end",trigger:h=>J.jsxs("button",{type:"button",className:"archik-btn","aria-expanded":h,children:["Legend",J.jsx("span",{style:{opacity:.6},children:h?"▴":"▾"})]}),children:()=>J.jsxs("div",{style:{minWidth:320,maxHeight:"min(70vh, 520px)",overflowY:"auto",padding:6},children:[J.jsx("div",{style:{position:"sticky",top:0,background:"var(--archik-panel)",fontSize:10,letterSpacing:"0.12em",textTransform:"uppercase",color:"var(--archik-fg-muted)",padding:"4px 6px 8px",zIndex:1},children:"Node kinds"}),x7e.map(h=>{const g=Qm[h],p=g.icon;return J.jsxs("div",{style:{display:"grid",gridTemplateColumns:"20px 80px 1fr",alignItems:"center",gap:8,padding:"5px 6px",fontSize:12},children:[J.jsx("span",{"aria-hidden":"true",style:{display:"flex",alignItems:"center",justifyContent:"center",color:g.color},children:J.jsx(p,{size:14,strokeWidth:1.8})}),J.jsx("code",{style:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",color:"var(--archik-fg)",fontSize:11},children:h}),J.jsx("span",{style:{color:"var(--archik-fg-dim)"},children:g.description})]},h)}),J.jsx(bXn,{})]})})}const dXn=[{id:"boundary",varName:"--archik-stereotype-boundary",description:"talks to actors / external systems (UIs, adapters)"},{id:"control",varName:"--archik-stereotype-control",description:"orchestration logic between boundaries and entities"},{id:"entity",varName:"--archik-stereotype-entity",description:"long-lived domain state (modules, databases)"}];function bXn(){return J.jsxs(J.Fragment,{children:[J.jsx("div",{style:{position:"sticky",top:0,background:"var(--archik-panel)",fontSize:10,letterSpacing:"0.12em",textTransform:"uppercase",color:"var(--archik-fg-muted)",padding:"12px 6px 8px",marginTop:6,borderTop:"1px solid var(--archik-border)"},children:"Stereotype (ECB)"}),dXn.map(h=>J.jsxs("div",{style:{display:"grid",gridTemplateColumns:"20px 80px 1fr",alignItems:"center",gap:8,padding:"5px 6px",fontSize:12},children:[J.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:12,height:12,borderRadius:3,background:`var(${h.varName})`}}),J.jsx("code",{style:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",color:"var(--archik-fg)",fontSize:11},children:h.id}),J.jsx("span",{style:{color:"var(--archik-fg-dim)"},children:h.description})]},h.id))]})}function gXn({size:h=22}){return J.jsxs("svg",{width:h,height:h,viewBox:"0 0 24 24",fill:"none",role:"img","aria-label":"Archik",style:{display:"block"},children:[J.jsx("path",{d:"M 12 5 L 5 18",stroke:"var(--archik-accent)",strokeWidth:"1.4",strokeLinecap:"round"}),J.jsx("path",{d:"M 12 5 L 19 18",stroke:"var(--archik-accent-bright)",strokeWidth:"1.4",strokeLinecap:"round"}),J.jsx("path",{d:"M 5 18 L 19 18",stroke:"var(--archik-magenta)",strokeWidth:"1.2",strokeLinecap:"round",strokeDasharray:"2.5 2.5"}),J.jsx("circle",{cx:"12",cy:"5",r:"2.6",fill:"var(--archik-accent)"}),J.jsx("circle",{cx:"5",cy:"18",r:"2.6",fill:"var(--archik-accent-bright)"}),J.jsx("circle",{cx:"19",cy:"18",r:"2.6",fill:"var(--archik-magenta)"})]})}const wXn="archik-theme";function Q8e(){return typeof document>"u"?"dark":document.documentElement.getAttribute("data-theme")==="light"?"light":"dark"}function pXn(h){if(!(typeof document>"u")){document.documentElement.setAttribute("data-theme",h);try{localStorage.setItem(wXn,h)}catch{}}}function mXn(){const h=Q8e()==="dark"?"light":"dark";return pXn(h),h}function vXn(){const[h,g]=Lt.useState(()=>Q8e());Lt.useEffect(()=>{g(Q8e())},[]);const p=()=>{g(mXn())},y=h==="dark"?"Light theme":"Dark theme",T=h==="dark"?"☀":"☾";return J.jsx("button",{type:"button",onClick:p,title:y,"aria-label":y,className:"archik-btn",style:{minWidth:30,justifyContent:"center"},children:J.jsx("span",{"aria-hidden":"true",children:T})})}const yXn="/__archik/usecases",kXn="/__archik/trace";async function r1n(h,g){const p=await fetch(h,{cache:"no-store",signal:g});if(!p.ok)throw new Error(`HTTP ${p.status} ${p.statusText}`);return await p.json()}function jXn(){return J.jsx(TT,{align:"end",trigger:h=>J.jsxs("button",{type:"button",className:"archik-btn","aria-expanded":h,children:["Use cases",J.jsx("span",{style:{opacity:.6},children:h?"▴":"▾"})]}),children:()=>J.jsx(SXn,{})})}function SXn(){const[h,g]=Lt.useState({status:"loading"});return Lt.useEffect(()=>{let p=!1;const y=new AbortController;return Promise.all([r1n(yXn,y.signal),r1n(kXn,y.signal)]).then(([T,C])=>{p||g({status:"ready",useCases:T.useCases??[],trace:C.rows??[]})}).catch(T=>{p||y.signal.aborted||g({status:"error",message:T instanceof Error?T.message:String(T)})}),()=>{p=!0,y.abort()}},[]),J.jsxs("div",{style:{minWidth:360,maxHeight:"min(70vh, 560px)",overflowY:"auto",padding:6},children:[J.jsx(xXn,{label:"Use cases"}),h.status==="loading"&&J.jsx(_8e,{children:"Loading…"}),h.status==="error"&&J.jsxs(_8e,{tone:"error",children:["Couldn't load: ",h.message]}),h.status==="ready"&&h.useCases.length===0&&J.jsxs(_8e,{children:["No use cases defined. Add a ",J.jsx("code",{children:"*.archik.uc.yaml"})," file under"," ",J.jsx("code",{children:".archik/usecases/"}),"."]}),h.status==="ready"&&h.useCases.length>0&&J.jsx(EXn,{useCases:h.useCases,trace:h.trace})]})}function EXn({useCases:h,trace:g}){const p=Lt.useMemo(()=>{const y=new Map;for(const T of g)y.set(`${T.useCase}/${T.slice}`,T.level);return y},[g]);return J.jsx("div",{children:h.map(y=>J.jsx(AXn,{uc:y,traceByKey:p},y.id))})}function AXn({uc:h,traceByKey:g}){return J.jsxs("div",{style:{padding:"8px 8px 6px",borderTop:"1px solid var(--archik-border)"},children:[J.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:6,marginBottom:2},children:[J.jsx("code",{style:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:12,color:"var(--archik-fg)"},children:h.id}),J.jsx("span",{style:{color:"var(--archik-fg-dim)",fontSize:11},children:h.name}),h.status&&h.status!=="active"&&J.jsx("span",{className:"archik-pill",style:{fontSize:9,marginLeft:"auto"},children:h.status})]}),J.jsxs("div",{style:{color:"var(--archik-fg-muted)",fontSize:11},children:["primary ",J.jsx("code",{children:h.primaryActor}),h.secondaryActors&&h.secondaryActors.length>0&&J.jsxs(J.Fragment,{children:[" ","· secondary"," ",h.secondaryActors.map((p,y)=>J.jsxs("span",{children:[y>0&&", ",J.jsx("code",{children:p})]},p))]})]}),J.jsx("ul",{style:{marginTop:6,listStyle:"none",padding:0},children:h.slices.map(p=>{const y=g.get(`${h.id}/${p.id}`);return J.jsx(TXn,{slice:p,level:y},p.id)})})]})}function TXn({slice:h,level:g}){const[p,y]=Lt.useState(!1);return J.jsxs("li",{style:{padding:"3px 0"},children:[J.jsxs("button",{type:"button",onClick:()=>y(T=>!T),className:"archik-btn",style:{display:"grid",gridTemplateColumns:"16px 1fr",alignItems:"center",gap:8,width:"100%",padding:"4px 6px",background:"transparent",border:"none",textAlign:"left",cursor:"pointer"},"aria-expanded":p,children:[J.jsx(CXn,{level:g}),J.jsxs("span",{style:{fontSize:12,color:"var(--archik-fg)",display:"flex",alignItems:"baseline",gap:6},children:[J.jsx("code",{children:h.id}),h.status&&h.status!=="active"&&J.jsxs("span",{style:{color:"var(--archik-fg-dim)",fontSize:10},children:["[",h.status,"]"]}),J.jsxs("span",{style:{color:"var(--archik-fg-dim)",fontSize:11,marginLeft:"auto"},children:[h.tests?.length??0,"t ",h.realization?"✓ rz":"— rz"]})]})]}),p&&J.jsxs("div",{style:{paddingLeft:24,color:"var(--archik-fg-dim)",fontSize:11,paddingBottom:4},children:[J.jsx("div",{style:{color:"var(--archik-fg)",marginBottom:4,lineHeight:1.4},children:h.description}),h.tests&&h.tests.length>0&&J.jsxs("div",{children:["tests:"," ",h.tests.map((T,C)=>J.jsxs("code",{children:[C>0&&", ",T]},T))]}),h.realization&&J.jsxs("div",{children:["realises: ",J.jsx("code",{children:h.realization.seqFile})]}),!h.tests?.length&&!h.realization&&J.jsx("div",{children:"(no tests, no realisation)"})]})]})}const MXn={full:{glyph:"✓",tone:"var(--archik-status-active, #4ade80)",title:"fully traced"},partial:{glyph:"~",tone:"var(--archik-status-proposed, #fbbf24)",title:"partially traced"},none:{glyph:"✗",tone:"var(--archik-status-deprecated, #f87171)",title:"untraced"},missing:{glyph:"·",tone:"var(--archik-fg-dim)",title:"no trace data"}};function CXn({level:h}){const g=MXn[h??"missing"];return J.jsx("span",{title:g.title,"aria-label":g.title,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:14,height:14,fontSize:11,fontWeight:600,color:g.tone},children:g.glyph})}function xXn({label:h}){return J.jsx("div",{style:{position:"sticky",top:0,background:"var(--archik-panel)",fontSize:10,letterSpacing:"0.12em",textTransform:"uppercase",color:"var(--archik-fg-muted)",padding:"4px 6px 8px",zIndex:1},children:h})}function _8e({children:h,tone:g}){return J.jsx("div",{style:{padding:"8px 8px 12px",fontSize:12,color:g==="error"?"var(--archik-status-deprecated, #f87171)":"var(--archik-fg-dim)"},children:h})}const OXn={idle:"",saving:"archik-pill archik-pill--info",saved:"archik-pill archik-pill--success",error:"archik-pill archik-pill--danger"},_Xn={idle:null,saving:"Saving…",saved:"Saved",error:"Save failed"};function NXn({document:h,filename:g="architecture.archik.yaml",commandError:p,reloadError:y,saveStatus:T="idle",saveError:C,isDirty:j=!1,onSave:P,onAddNode:q,connectingFromName:U,onCancelConnect:oe,density:ie,onDensityChange:le,viewMode:Te,onViewModeChange:Qe,canUndo:re=!1,canRedo:rn=!1,onUndo:vn,onRedo:Dn,getSvg:Pn,seqHighlight:Wn,onToggleSeqHighlight:Ot,seqNodeCount:$t}){const Pt=_Xn[T],Tt=typeof navigator<"u"&&/Mac/i.test(navigator.platform)?"⌘S":"Ctrl+S";return J.jsxs("header",{className:"flex items-center gap-3 px-4 py-2.5",style:{background:"var(--archik-panel)",borderBottom:"1px solid var(--archik-border)"},children:[J.jsxs("div",{className:"flex items-center gap-2",children:[J.jsx(gXn,{}),J.jsx("span",{className:"text-sm font-semibold tracking-tight",style:{color:"var(--archik-fg)",letterSpacing:"0.02em"},children:"Archik"})]}),J.jsx("span",{className:"archik-mono",style:{color:"var(--archik-fg-dim)",fontSize:11,opacity:.85},children:h.name}),U!==void 0&&J.jsxs("span",{className:"archik-pill archik-pill--info",children:["Connecting from ",J.jsx("strong",{children:U}),J.jsx("button",{type:"button",onClick:oe,className:"underline hover:no-underline",style:{color:"var(--archik-accent)"},children:"cancel (Esc)"})]}),p!==void 0&&J.jsx("span",{className:"archik-pill archik-pill--danger",children:p}),y!==void 0&&J.jsx("span",{className:"archik-pill archik-pill--warning",title:y,children:"File reload error"}),Pt!==null&&J.jsx("span",{className:OXn[T],...T==="error"&&C!==void 0?{title:C}:{},children:Pt}),T==="error"&&C!==void 0&&J.jsx("span",{className:"archik-pill archik-pill--danger",style:{maxWidth:480,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontFamily:"ui-monospace, monospace",fontSize:11},title:C,children:IXn(C)}),J.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[vn!==void 0&&J.jsx("button",{type:"button",onClick:vn,disabled:!re,title:`Undo (${Tt.replace("S","Z")})`,"aria-label":"Undo",className:"archik-btn",style:{padding:"5px 8px"},children:J.jsx(nFn,{size:14,strokeWidth:1.8})}),Dn!==void 0&&J.jsx("button",{type:"button",onClick:Dn,disabled:!rn,title:`Redo (${Tt.replace("S","⇧Z").replace("Ctrl+","Ctrl+Shift+")})`,"aria-label":"Redo",className:"archik-btn",style:{padding:"5px 8px"},children:J.jsx(zBn,{size:14,strokeWidth:1.8})}),q!==void 0&&J.jsx(RZn,{onAdd:q}),Te!==void 0&&Qe!==void 0&&J.jsx("button",{type:"button",onClick:()=>Qe(Te==="compact"?"detailed":"compact"),title:Te==="compact"?"Switch to detailed view":"Switch to compact view","aria-label":"Toggle view mode",className:"archik-btn",style:{padding:"5px 8px"},children:Te==="compact"?J.jsx(ABn,{size:14,strokeWidth:1.8}):J.jsx(GBn,{size:14,strokeWidth:1.8})}),ie!==void 0&&le!==void 0&&J.jsx(aXn,{density:ie,onChange:le}),Ot!==void 0&&($t??0)>0&&J.jsx("button",{type:"button",onClick:Ot,title:Wn?"Hide sequence diagram highlights":`Show ${$t} node${$t===1?"":"s"} with sequence diagrams`,"aria-label":"Toggle sequence diagram highlights","aria-pressed":Wn,className:"archik-btn",style:{padding:"5px 8px",...Wn?{background:"var(--archik-status-proposed)",borderColor:"var(--archik-status-proposed)",color:"white"}:{}},children:J.jsx(gBn,{size:14,strokeWidth:1.8})}),J.jsx(jXn,{}),J.jsx(qZn,{}),J.jsx(hXn,{}),J.jsx(t0n,{document:h,filename:g,...Pn!==void 0?{getSvg:Pn}:{}}),J.jsx("button",{type:"button",onClick:P,disabled:!j||T==="saving",title:`Save to ${g} (${Tt})`,className:"archik-btn archik-btn-primary",children:j?"Save •":"Save"}),J.jsx(vXn,{})]})]})}function IXn(h){const g=h.indexOf(`
222
+ `}const tXn={name:"yaml",label:"YAML",extension:".yaml",mime:"application/yaml",export:O7e},iXn={name:"json",label:"JSON",extension:".json",mime:"application/json",export:Vdn},rXn={name:"markdown",label:"Markdown",extension:".md",mime:"text/markdown",export:nXn},cXn=[tXn,iXn,rXn];function t0n({document:h,filename:g,getSvg:p}){const y=async j=>{try{await navigator.clipboard.writeText(j)}catch{}},T=()=>{const j=p?.();j&&t1n(i1n(g,"svg"),WZn(j))},C=async()=>{const j=p?.();if(j)try{const P=await YZn(j);t1n(i1n(g,"png"),P)}catch(P){console.error("PNG export failed:",P)}};return J.jsx(TT,{trigger:j=>J.jsxs("button",{type:"button",className:"archik-btn",children:["Export",J.jsx("span",{style:{opacity:.6},children:j?"▴":"▾"})]}),children:j=>J.jsxs(J.Fragment,{children:[h&&cXn.map(P=>J.jsxs("button",{type:"button",className:"archik-menu-item",onClick:()=>{y(P.export(h)),j()},children:[J.jsx("span",{style:{minWidth:60,color:"var(--archik-fg-dim)"},children:"Copy"}),J.jsx("span",{children:P.label})]},P.name)),h&&J.jsxs(J.Fragment,{children:[J.jsx("hr",{style:{border:0,borderTop:"1px solid var(--archik-border)",margin:"4px 0"}}),J.jsxs("button",{type:"button",className:"archik-menu-item",onClick:()=>{fZn(g,h),j()},children:[J.jsx("span",{style:{minWidth:60,color:"var(--archik-fg-dim)"},children:"Download"}),J.jsx("span",{children:"YAML"})]})]}),p&&J.jsxs(J.Fragment,{children:[J.jsxs("button",{type:"button",className:"archik-menu-item",onClick:()=>{T(),j()},children:[J.jsx("span",{style:{minWidth:60,color:"var(--archik-fg-dim)"},children:"Download"}),J.jsx("span",{children:"SVG"})]}),J.jsxs("button",{type:"button",className:"archik-menu-item",onClick:()=>{C(),j()},children:[J.jsx("span",{style:{minWidth:60,color:"var(--archik-fg-dim)"},children:"Download"}),J.jsx("span",{children:"PNG"})]})]})]})})}const i0n="archik-density",r0n="archik-view-mode",aI=1,O8e="detailed";function uXn(){if(typeof localStorage>"u")return O8e;try{return localStorage.getItem(r0n)==="compact"?"compact":O8e}catch{return O8e}}function sXn(h){if(!(typeof localStorage>"u"))try{localStorage.setItem(r0n,h)}catch{}}function oXn(){if(typeof localStorage>"u")return aI;try{const h=localStorage.getItem(i0n);if(!h)return aI;const g=Number.parseFloat(h);return Number.isFinite(g)?N7e(g):aI}catch{return aI}}function lXn(h){if(!(typeof localStorage>"u"))try{localStorage.setItem(i0n,String(N7e(h)))}catch{}}function N7e(h){return Math.max(.3,Math.min(4,h))}function fXn(h){const g=N7e(h);return{nodeSpacing:Math.round(60*g),layerSpacing:Math.round(100*g),padding:Math.round(40*g)}}function aXn({density:h,onChange:g}){const p=Math.round(h*100);return J.jsx(TT,{align:"end",trigger:y=>J.jsxs("button",{type:"button",className:"archik-btn","aria-expanded":y,title:"Layout density",children:["Spacing",J.jsxs("span",{style:{opacity:.6},children:[p,"%"]})]}),children:()=>J.jsxs("div",{style:{minWidth:240,padding:8},children:[J.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",marginBottom:6},children:[J.jsx("span",{className:"archik-label",style:{margin:0},children:"Node spacing"}),J.jsxs("span",{className:"archik-mono",style:{fontSize:11,color:"var(--archik-fg-dim)"},children:[p,"%"]})]}),J.jsx("input",{type:"range",min:.3,max:4,step:.1,value:h,onChange:y=>g(Number.parseFloat(y.target.value)),style:{width:"100%",accentColor:"var(--archik-accent)"}}),J.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:10,color:"var(--archik-fg-muted)",marginTop:4},children:[J.jsx("span",{children:"tight"}),J.jsx("span",{children:"roomy"})]}),J.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:10},children:J.jsx("button",{type:"button",className:"archik-btn",onClick:()=>g(aI),disabled:h===aI,children:"Reset"})})]})})}function hXn(){return J.jsx(TT,{align:"end",trigger:h=>J.jsxs("button",{type:"button",className:"archik-btn","aria-expanded":h,children:["Legend",J.jsx("span",{style:{opacity:.6},children:h?"▴":"▾"})]}),children:()=>J.jsxs("div",{style:{minWidth:320,maxHeight:"min(70vh, 520px)",overflowY:"auto",padding:6},children:[J.jsx("div",{style:{position:"sticky",top:0,background:"var(--archik-panel)",fontSize:10,letterSpacing:"0.12em",textTransform:"uppercase",color:"var(--archik-fg-muted)",padding:"4px 6px 8px",zIndex:1},children:"Node kinds"}),x7e.map(h=>{const g=Qm[h],p=g.icon;return J.jsxs("div",{style:{display:"grid",gridTemplateColumns:"20px 80px 1fr",alignItems:"center",gap:8,padding:"5px 6px",fontSize:12},children:[J.jsx("span",{"aria-hidden":"true",style:{display:"flex",alignItems:"center",justifyContent:"center",color:g.color},children:J.jsx(p,{size:14,strokeWidth:1.8})}),J.jsx("code",{style:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",color:"var(--archik-fg)",fontSize:11},children:h}),J.jsx("span",{style:{color:"var(--archik-fg-dim)"},children:g.description})]},h)}),J.jsx(bXn,{})]})})}const dXn=[{id:"boundary",varName:"--archik-stereotype-boundary",description:"talks to actors / external systems (UIs, adapters)"},{id:"control",varName:"--archik-stereotype-control",description:"orchestration logic between boundaries and entities"},{id:"entity",varName:"--archik-stereotype-entity",description:"long-lived domain state (modules, databases)"}];function bXn(){return J.jsxs(J.Fragment,{children:[J.jsx("div",{style:{position:"sticky",top:0,background:"var(--archik-panel)",fontSize:10,letterSpacing:"0.12em",textTransform:"uppercase",color:"var(--archik-fg-muted)",padding:"12px 6px 8px",marginTop:6,borderTop:"1px solid var(--archik-border)"},children:"Stereotype (ECB)"}),dXn.map(h=>J.jsxs("div",{style:{display:"grid",gridTemplateColumns:"20px 80px 1fr",alignItems:"center",gap:8,padding:"5px 6px",fontSize:12},children:[J.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:12,height:12,borderRadius:3,background:`var(${h.varName})`}}),J.jsx("code",{style:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",color:"var(--archik-fg)",fontSize:11},children:h.id}),J.jsx("span",{style:{color:"var(--archik-fg-dim)"},children:h.description})]},h.id))]})}function gXn({size:h=22}){return J.jsxs("svg",{width:h,height:h,viewBox:"0 0 24 24",fill:"none",role:"img","aria-label":"Archik",style:{display:"block"},children:[J.jsx("path",{d:"M 12 5 L 5 18",stroke:"var(--archik-accent)",strokeWidth:"1.4",strokeLinecap:"round"}),J.jsx("path",{d:"M 12 5 L 19 18",stroke:"var(--archik-accent-bright)",strokeWidth:"1.4",strokeLinecap:"round"}),J.jsx("path",{d:"M 5 18 L 19 18",stroke:"var(--archik-magenta)",strokeWidth:"1.2",strokeLinecap:"round",strokeDasharray:"2.5 2.5"}),J.jsx("circle",{cx:"12",cy:"5",r:"2.6",fill:"var(--archik-accent)"}),J.jsx("circle",{cx:"5",cy:"18",r:"2.6",fill:"var(--archik-accent-bright)"}),J.jsx("circle",{cx:"19",cy:"18",r:"2.6",fill:"var(--archik-magenta)"})]})}const wXn="archik-theme";function Q8e(){return typeof document>"u"?"dark":document.documentElement.getAttribute("data-theme")==="light"?"light":"dark"}function pXn(h){if(!(typeof document>"u")){document.documentElement.setAttribute("data-theme",h);try{localStorage.setItem(wXn,h)}catch{}}}function mXn(){const h=Q8e()==="dark"?"light":"dark";return pXn(h),h}function vXn(){const[h,g]=Lt.useState(()=>Q8e());Lt.useEffect(()=>{g(Q8e())},[]);const p=()=>{g(mXn())},y=h==="dark"?"Light theme":"Dark theme",T=h==="dark"?"☀":"☾";return J.jsx("button",{type:"button",onClick:p,title:y,"aria-label":y,className:"archik-btn",style:{minWidth:30,justifyContent:"center"},children:J.jsx("span",{"aria-hidden":"true",children:T})})}const yXn="/__archik/usecases",kXn="/__archik/trace";async function r1n(h,g){const p=await fetch(h,{cache:"no-store",signal:g});if(!p.ok)throw new Error(`HTTP ${p.status} ${p.statusText}`);return await p.json()}function jXn(){return J.jsx(TT,{align:"end",trigger:h=>J.jsxs("button",{type:"button",className:"archik-btn","aria-expanded":h,children:["Use cases",J.jsx("span",{style:{opacity:.6},children:h?"▴":"▾"})]}),children:()=>J.jsx(SXn,{})})}function SXn(){const[h,g]=Lt.useState({status:"loading"});return Lt.useEffect(()=>{let p=!1;const y=new AbortController;return Promise.all([r1n(yXn,y.signal),r1n(kXn,y.signal)]).then(([T,C])=>{p||g({status:"ready",useCases:T.useCases??[],trace:C.rows??[]})}).catch(T=>{p||y.signal.aborted||g({status:"error",message:T instanceof Error?T.message:String(T)})}),()=>{p=!0,y.abort()}},[]),J.jsxs("div",{style:{minWidth:360,maxHeight:"min(70vh, 560px)",overflowY:"auto",padding:6},children:[J.jsx(xXn,{label:"Use cases"}),h.status==="loading"&&J.jsx(_8e,{children:"Loading…"}),h.status==="error"&&J.jsxs(_8e,{tone:"error",children:["Couldn't load: ",h.message]}),h.status==="ready"&&h.useCases.length===0&&J.jsxs(_8e,{children:["No use cases defined. Add a ",J.jsx("code",{children:"*.archik.uc.yaml"})," file under"," ",J.jsx("code",{children:".archik/usecases/"}),"."]}),h.status==="ready"&&h.useCases.length>0&&J.jsx(EXn,{useCases:h.useCases,trace:h.trace})]})}function EXn({useCases:h,trace:g}){const p=Lt.useMemo(()=>{const y=new Map;for(const T of g)y.set(`${T.useCase}/${T.slice}`,T.level);return y},[g]);return J.jsx("div",{children:h.map(y=>J.jsx(AXn,{uc:y,traceByKey:p},y.id))})}function AXn({uc:h,traceByKey:g}){return J.jsxs("div",{style:{padding:"8px 8px 6px",borderTop:"1px solid var(--archik-border)"},children:[J.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:6,marginBottom:2},children:[J.jsx("code",{style:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:12,color:"var(--archik-fg)"},children:h.id}),J.jsx("span",{style:{color:"var(--archik-fg-dim)",fontSize:11},children:h.name}),h.status&&h.status!=="active"&&J.jsx("span",{className:"archik-pill",style:{fontSize:9,marginLeft:"auto"},children:h.status})]}),J.jsxs("div",{style:{color:"var(--archik-fg-muted)",fontSize:11},children:["primary ",J.jsx("code",{children:h.primaryActor}),h.secondaryActors&&h.secondaryActors.length>0&&J.jsxs(J.Fragment,{children:[" ","· secondary"," ",h.secondaryActors.map((p,y)=>J.jsxs("span",{children:[y>0&&", ",J.jsx("code",{children:p})]},p))]})]}),J.jsx("ul",{style:{marginTop:6,listStyle:"none",padding:0},children:h.slices.map(p=>{const y=g.get(`${h.id}/${p.id}`);return J.jsx(TXn,{slice:p,level:y},p.id)})})]})}function TXn({slice:h,level:g}){const[p,y]=Lt.useState(!1);return J.jsxs("li",{style:{padding:"3px 0"},children:[J.jsxs("button",{type:"button",onClick:()=>y(T=>!T),className:"archik-btn",style:{display:"grid",gridTemplateColumns:"16px 1fr",alignItems:"center",gap:8,width:"100%",padding:"4px 6px",background:"transparent",border:"none",textAlign:"left",cursor:"pointer"},"aria-expanded":p,children:[J.jsx(CXn,{level:g}),J.jsxs("span",{style:{fontSize:12,color:"var(--archik-fg)",display:"flex",alignItems:"baseline",gap:6},children:[J.jsx("code",{children:h.id}),h.status&&h.status!=="active"&&J.jsxs("span",{style:{color:"var(--archik-fg-dim)",fontSize:10},children:["[",h.status,"]"]}),J.jsx("span",{style:{color:"var(--archik-fg-dim)",fontSize:11,marginLeft:"auto"},children:(()=>{const T=h.tests?.length??0,C=`${T} ${T===1?"test":"tests"}`,j=h.realization?"realized":"no seq";return`${C} • ${j}`})()})]})]}),p&&J.jsxs("div",{style:{paddingLeft:24,color:"var(--archik-fg-dim)",fontSize:11,paddingBottom:4},children:[J.jsx("div",{style:{color:"var(--archik-fg)",marginBottom:4,lineHeight:1.4},children:h.description}),h.tests&&h.tests.length>0&&J.jsxs("div",{children:["tests:"," ",h.tests.map((T,C)=>J.jsxs("code",{children:[C>0&&", ",T]},T))]}),h.realization&&J.jsxs("div",{children:["realises: ",J.jsx("code",{children:h.realization.seqFile})]}),!h.tests?.length&&!h.realization&&J.jsx("div",{children:"(no tests, no realisation)"})]})]})}const MXn={full:{glyph:"✓",tone:"var(--archik-status-active, #4ade80)",title:"fully traced"},partial:{glyph:"~",tone:"var(--archik-status-proposed, #fbbf24)",title:"partially traced"},none:{glyph:"✗",tone:"var(--archik-status-deprecated, #f87171)",title:"untraced"},missing:{glyph:"·",tone:"var(--archik-fg-dim)",title:"no trace data"}};function CXn({level:h}){const g=MXn[h??"missing"];return J.jsx("span",{title:g.title,"aria-label":g.title,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:14,height:14,fontSize:11,fontWeight:600,color:g.tone},children:g.glyph})}function xXn({label:h}){return J.jsx("div",{style:{position:"sticky",top:0,background:"var(--archik-panel)",fontSize:10,letterSpacing:"0.12em",textTransform:"uppercase",color:"var(--archik-fg-muted)",padding:"4px 6px 8px",zIndex:1},children:h})}function _8e({children:h,tone:g}){return J.jsx("div",{style:{padding:"8px 8px 12px",fontSize:12,color:g==="error"?"var(--archik-status-deprecated, #f87171)":"var(--archik-fg-dim)"},children:h})}const OXn={idle:"",saving:"archik-pill archik-pill--info",saved:"archik-pill archik-pill--success",error:"archik-pill archik-pill--danger"},_Xn={idle:null,saving:"Saving…",saved:"Saved",error:"Save failed"};function NXn({document:h,filename:g="architecture.archik.yaml",commandError:p,reloadError:y,saveStatus:T="idle",saveError:C,isDirty:j=!1,onSave:P,onAddNode:q,connectingFromName:U,onCancelConnect:oe,density:ie,onDensityChange:le,viewMode:Te,onViewModeChange:Qe,canUndo:re=!1,canRedo:rn=!1,onUndo:vn,onRedo:Dn,getSvg:Pn,seqHighlight:Wn,onToggleSeqHighlight:Ot,seqNodeCount:$t}){const Pt=_Xn[T],Tt=typeof navigator<"u"&&/Mac/i.test(navigator.platform)?"⌘S":"Ctrl+S";return J.jsxs("header",{className:"flex items-center gap-3 px-4 py-2.5",style:{background:"var(--archik-panel)",borderBottom:"1px solid var(--archik-border)"},children:[J.jsxs("div",{className:"flex items-center gap-2",children:[J.jsx(gXn,{}),J.jsx("span",{className:"text-sm font-semibold tracking-tight",style:{color:"var(--archik-fg)",letterSpacing:"0.02em"},children:"Archik"})]}),J.jsx("span",{className:"archik-mono",style:{color:"var(--archik-fg-dim)",fontSize:11,opacity:.85},children:h.name}),U!==void 0&&J.jsxs("span",{className:"archik-pill archik-pill--info",children:["Connecting from ",J.jsx("strong",{children:U}),J.jsx("button",{type:"button",onClick:oe,className:"underline hover:no-underline",style:{color:"var(--archik-accent)"},children:"cancel (Esc)"})]}),p!==void 0&&J.jsx("span",{className:"archik-pill archik-pill--danger",children:p}),y!==void 0&&J.jsx("span",{className:"archik-pill archik-pill--warning",title:y,children:"File reload error"}),Pt!==null&&J.jsx("span",{className:OXn[T],...T==="error"&&C!==void 0?{title:C}:{},children:Pt}),T==="error"&&C!==void 0&&J.jsx("span",{className:"archik-pill archik-pill--danger",style:{maxWidth:480,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontFamily:"ui-monospace, monospace",fontSize:11},title:C,children:IXn(C)}),J.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[vn!==void 0&&J.jsx("button",{type:"button",onClick:vn,disabled:!re,title:`Undo (${Tt.replace("S","Z")})`,"aria-label":"Undo",className:"archik-btn",style:{padding:"5px 8px"},children:J.jsx(nFn,{size:14,strokeWidth:1.8})}),Dn!==void 0&&J.jsx("button",{type:"button",onClick:Dn,disabled:!rn,title:`Redo (${Tt.replace("S","⇧Z").replace("Ctrl+","Ctrl+Shift+")})`,"aria-label":"Redo",className:"archik-btn",style:{padding:"5px 8px"},children:J.jsx(zBn,{size:14,strokeWidth:1.8})}),q!==void 0&&J.jsx(RZn,{onAdd:q}),Te!==void 0&&Qe!==void 0&&J.jsx("button",{type:"button",onClick:()=>Qe(Te==="compact"?"detailed":"compact"),title:Te==="compact"?"Switch to detailed view":"Switch to compact view","aria-label":"Toggle view mode",className:"archik-btn",style:{padding:"5px 8px"},children:Te==="compact"?J.jsx(ABn,{size:14,strokeWidth:1.8}):J.jsx(GBn,{size:14,strokeWidth:1.8})}),ie!==void 0&&le!==void 0&&J.jsx(aXn,{density:ie,onChange:le}),Ot!==void 0&&($t??0)>0&&J.jsx("button",{type:"button",onClick:Ot,title:Wn?"Hide sequence diagram highlights":`Show ${$t} node${$t===1?"":"s"} with sequence diagrams`,"aria-label":"Toggle sequence diagram highlights","aria-pressed":Wn,className:"archik-btn",style:{padding:"5px 8px",...Wn?{background:"var(--archik-status-proposed)",borderColor:"var(--archik-status-proposed)",color:"white"}:{}},children:J.jsx(gBn,{size:14,strokeWidth:1.8})}),J.jsx(jXn,{}),J.jsx(qZn,{}),J.jsx(hXn,{}),J.jsx(t0n,{document:h,filename:g,...Pn!==void 0?{getSvg:Pn}:{}}),J.jsx("button",{type:"button",onClick:P,disabled:!j||T==="saving",title:`Save to ${g} (${Tt})`,className:"archik-btn archik-btn-primary",children:j?"Save •":"Save"}),J.jsx(vXn,{})]})]})}function IXn(h){const g=h.indexOf(`
223
223
  `);return g===-1?h:h.slice(0,g)}function DXn({files:h,currentPath:g,onSwitchFile:p}){const y=h.some(C=>C.hasSuggestion||C.isOrphanSuggestion);if(h.length<=1&&!y)return null;const T=h.find(C=>C.path===g)??h[0];return J.jsx(TT,{align:"start",trigger:C=>J.jsxs("button",{type:"button","aria-label":"Switch architecture file","aria-expanded":C,className:"archik-btn",style:{display:"flex",alignItems:"center",gap:6,padding:"4px 10px",fontSize:12,background:"transparent",color:"var(--archik-fg)"},children:[J.jsx(dBn,{size:13,strokeWidth:1.8}),J.jsx("span",{style:{fontWeight:600},children:T.name}),T.hasSuggestion&&J.jsx(aue,{}),J.jsx(m1n,{size:12,strokeWidth:2,style:{opacity:.6}})]}),children:C=>J.jsxs("div",{style:{minWidth:220,padding:4},children:[J.jsx("div",{style:{fontSize:10,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--archik-fg-muted)",padding:"6px 10px 4px"},children:"Architecture files"}),h.map(j=>{const P=j.path===T.path,q=j.isOrphanSuggestion===!0;return J.jsxs("button",{type:"button",title:q?`Pending sub-architecture (sidecar only — no main file yet). Click to view; accept via \`npx archik suggest accept ${j.path.replace(/\.archik\.suggested\.yaml$/,".archik.yaml")}\` to promote it, or /archik:accept.`:void 0,onClick:()=>{C(),!P&&p(j)},className:"archik-menu-item",style:{display:"flex",alignItems:"center",gap:8,width:"100%",textAlign:"left",padding:"6px 10px",fontSize:12,background:P?"var(--archik-surface-hover)":void 0,borderLeft:q?"2px dashed var(--archik-accent)":void 0,paddingLeft:q?8:void 0},children:[J.jsxs("span",{style:{fontWeight:P?600:400,color:"var(--archik-fg)"},children:[j.name,q&&J.jsx("span",{style:{marginLeft:6,fontSize:10,fontWeight:500,color:"var(--archik-accent)",letterSpacing:"0.04em"},children:"(pending)"})]}),j.hasSuggestion&&!q&&J.jsx(aue,{}),J.jsx("span",{style:{flex:1,fontSize:10,fontFamily:"ui-monospace, monospace",color:"var(--archik-fg-muted)",textAlign:"right"},children:j.path})]},j.path)})]})})}function aue(){return J.jsx("span",{"aria-label":"pending suggestion",title:"Pending suggestion",style:{width:6,height:6,borderRadius:3,background:"var(--archik-accent)",flexShrink:0}})}function $Xn({stack:h,onGoToFrame:g,suggestionsByPath:p}){return h.length<=1?null:J.jsx("nav",{"aria-label":"Architecture file navigation",style:{display:"flex",alignItems:"center",gap:6,fontSize:12,color:"var(--archik-fg-muted)"},children:h.map((y,T)=>{const C=T===h.length-1,j=y.archikFile!==null&&p!==void 0&&p.has(y.archikFile);return J.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[C?J.jsxs("span",{style:{color:"var(--archik-fg)",fontWeight:600,display:"inline-flex",alignItems:"center",gap:6},"aria-current":"page",children:[y.label,j&&J.jsx(aue,{})]}):J.jsxs("button",{type:"button",onClick:()=>g(T),className:"archik-btn",style:{padding:"2px 6px",fontSize:12,color:"var(--archik-fg-muted)",background:"transparent",display:"inline-flex",alignItems:"center",gap:6},title:`Back to ${y.label}`,children:[y.label,j&&J.jsx(aue,{})]}),!C&&J.jsx("span",{"aria-hidden":"true",style:{opacity:.5},children:"›"})]},`${T}-${y.archikFile??"root"}`)})})}const LXn="/architecture.archik.yaml",PXn="/architecture.archik.suggested.yaml",RXn="/__archik/accept-suggestion",zXn=1500,e7e={label:"main",docUrl:LXn,sidecarUrl:PXn,acceptUrl:RXn,archikFile:null};function c0n(h,g){const p=h.replace(/\.archik\.yaml$/,".archik.suggested.yaml"),y=encodeURIComponent(h),T=encodeURIComponent(p);return{label:g,docUrl:`/__archik/file?path=${y}`,sidecarUrl:`/__archik/file?path=${T}`,acceptUrl:`/__archik/file-accept?path=${y}`,archikFile:h}}function BXn(){if(typeof window>"u")return null;const h=new URLSearchParams(window.location.search).get("file");return h!==null&&h.length>0?h:null}function FXn(h){if(typeof window>"u")return;const g=new URL(window.location.href);h===null||h.length===0?g.searchParams.delete("file"):g.searchParams.set("file",h),window.history.replaceState(null,"",g.toString())}function c1n(){const h=BXn();if(h===null)return[e7e];const p=(h.split("/").pop()??h).replace(/\.archik\.yaml$/i,"")||"main";return[c0n(h,p)]}function qXn(){const[h,g]=Lt.useState({status:"loading"}),[p,y]=Lt.useState(c1n),T=p[p.length-1],[C,j]=Lt.useState([]),P=Lt.useMemo(()=>new Set(C.filter(Nn=>Nn.hasSuggestion).map(Nn=>Nn.path)),[C]),q=Lt.useMemo(()=>C.find(Nn=>Nn.isRoot)??null,[C]),U=T.archikFile===null?q?.path??null:T.archikFile,[oe,ie]=Lt.useState(void 0),[le,Te]=Lt.useState(void 0),[Qe,re]=Lt.useState("idle"),[rn,vn]=Lt.useState(null),[Dn,Pn]=Lt.useState(!1),[Wn,Ot]=Lt.useState(!1),[$t,Pt]=Lt.useState({status:"none"}),[Tt,vr]=Lt.useState(!1),[Pu,ru]=Lt.useState([]),[cr,Q]=Lt.useState([]),Tf=100,[kl,wn]=Lt.useState(()=>oXn()),Gt=Nn=>{wn(Nn),lXn(Nn)},[ki,$c]=Lt.useState(()=>uXn()),wu=Nn=>{$c(Nn),sXn(Nn)},Ke=Lt.useMemo(()=>({...fXn(kl),viewMode:ki}),[kl,ki]),Vn=Lt.useMemo(()=>h.status==="ready"?new Set(h.document.nodes.filter(Nn=>(Nn.seqFiles?.length??0)>0).map(Nn=>Nn.id)):new Set,[h]),ni=Lt.useRef(!1),bi=Lt.useRef(null),gr=Lt.useRef(null),Qr=Lt.useCallback(()=>gr.current,[]),Jr=Lt.useRef(null),Lc=oy(Nn=>Nn.selection),vc=oy(Nn=>Nn.connectFrom),Fh=oy(Nn=>Nn.selectNode),E1=oy(Nn=>Nn.selectEdge),hy=oy(Nn=>Nn.toggleNode),c5=oy(Nn=>Nn.toggleEdge),Mf=oy(Nn=>Nn.clearSelection),u5=oy(Nn=>Nn.startConnect),gd=oy(Nn=>Nn.cancelConnect),y0=Lc.length>0?Lc.at(-1)??null:null,r7=Lt.useMemo(()=>new Set(Lc.filter(Nn=>Nn.type==="node").map(Nn=>Nn.id)),[Lc]),ls=Lt.useMemo(()=>new Set(Lc.filter(Nn=>Nn.type==="edge").map(Nn=>Nn.id)),[Lc]);Lt.useEffect(()=>{const Nn=p[p.length-1];FXn(Nn.archikFile)},[p]),Lt.useEffect(()=>{if(typeof window>"u")return;const Nn=()=>y(c1n());return window.addEventListener("popstate",Nn),()=>window.removeEventListener("popstate",Nn)},[]),Lt.useEffect(()=>{let Nn=!1;bi.current="",ni.current=!1;const _t=()=>{oZn(T.docUrl).then(({document:Mi,text:Dr})=>{if(Nn||Dr===bi.current)return;bi.current=Dr,ni.current=!0,g({status:"ready",document:Mi}),Pn(!1),typeof window<"u"&&Mi.name&&(window.document.title=`${Mi.name} — Archik`),Te(void 0),ru([]),Q([]);const jl=new Set(Mi.nodes.map(as=>as.id)),Ls=new Set(Mi.edges.map(as=>as.id));oy.setState(as=>({selection:as.selection.filter(Lo=>Lo.type==="node"?jl.has(Lo.id):Ls.has(Lo.id)),connectFrom:as.connectFrom!==null&&jl.has(as.connectFrom)?as.connectFrom:null}))},Mi=>{if(Nn)return;const Dr=Mi instanceof Error?Mi.message:String(Mi);ni.current?Te(Dr):g({status:"error",error:Dr})})};g({status:"loading"}),_t();const Ki=Zhn(_t);return()=>{Nn=!0,Ki()}},[T.docUrl]),Lt.useEffect(()=>()=>{Jr.current&&clearTimeout(Jr.current)},[]),Lt.useEffect(()=>{let Nn=!1;const _t=async()=>{try{const Dr=await fetch("/__archik/files",{cache:"no-store"});if(Nn||!Dr.ok)return;const jl=await Dr.json();if(Nn)return;Array.isArray(jl.files)&&j(jl.files)}catch{}};_t();const Ki=Zhn(()=>{_t()}),Mi=Xhn(()=>{_t()});return()=>{Nn=!0,Ki(),Mi()}},[]),Lt.useEffect(()=>{if(h.status!=="ready")return;const Nn=h.document;let _t=!1;const Ki=async()=>{if(U!==null&&C.length>0&&C.some(Dr=>Dr.path===U)&&!P.has(U)){Pt({status:"none"});return}try{const Dr=await fetch(T.sidecarUrl,{cache:"no-store"});if(_t)return;if(Dr.status===404){Pt({status:"none"});return}if(!Dr.ok){Pt({status:"error",message:`Sidecar fetch failed: HTTP ${Dr.status}`});return}const jl=await Dr.text();let Ls;try{Ls=Xdn(jl)}catch(Lo){Pt({status:"error",message:Lo instanceof Error?Lo.message:String(Lo)});return}const as=W8e(Nn,Ls);Pt({status:"pending",added:as.nodes.added.length+as.edges.added.length,removed:as.nodes.removed.length+as.edges.removed.length,changed:as.nodes.changed.length+as.edges.changed.length,doc:Ls,...Ls.metadata?.suggestion?.note!==void 0?{note:Ls.metadata.suggestion.note}:{}})}catch(Dr){if(_t)return;Pt({status:"error",message:Dr instanceof Error?Dr.message:String(Dr)})}};Ki();const Mi=Xhn(Ki);return()=>{_t=!0,Mi()}},[h,T.sidecarUrl,U,C,P]);const fs=Lt.useCallback(async()=>{try{const Nn=await fetch(T.acceptUrl,{method:"POST"});if(!Nn.ok){const _t=await Nn.text();Pt({status:"error",message:`Accept failed: ${_t||`HTTP ${Nn.status}`}`});return}Pt({status:"none"}),vr(!1)}catch(Nn){Pt({status:"error",message:Nn instanceof Error?Nn.message:String(Nn)})}},[T.acceptUrl]),s5=Lt.useCallback(async()=>{try{const Nn=await fetch(T.sidecarUrl,{method:"DELETE"});if(!Nn.ok&&Nn.status!==404){const _t=await Nn.text();Pt({status:"error",message:`Reject failed: ${_t||`HTTP ${Nn.status}`}`});return}Pt({status:"none"}),vr(!1)}catch(Nn){Pt({status:"error",message:Nn instanceof Error?Nn.message:String(Nn)})}},[T.sidecarUrl]),$s=Lt.useCallback(()=>{vr(Nn=>!Nn)},[]),o5=Lt.useCallback(async()=>{let Nn=null;if(g(Ki=>(Ki.status==="ready"&&(Nn=Ki.document),Ki)),!Nn)return;const _t=O7e(Nn);bi.current=_t,re("saving"),vn(null);try{await lZn(T.docUrl,Nn),re("saved");let Ki=!1;g(Mi=>(Mi.status==="ready"&&Mi.document===Nn&&(Ki=!0),Mi)),Ki&&Pn(!1),Jr.current&&clearTimeout(Jr.current),Jr.current=setTimeout(()=>re("idle"),zXn)}catch(Ki){re("error"),vn(Ki instanceof Error?Ki.message:String(Ki))}},[T.docUrl]),Cf=q?.path??null,dy=Lt.useCallback((Nn,_t)=>Cf===Nn?e7e:c0n(Nn,_t),[Cf]),n3=Lt.useCallback((Nn,_t)=>Nn.archikFile===_t?!0:Nn.archikFile===null&&Cf===_t,[Cf]),c7=Lt.useCallback((Nn,_t)=>{y(Ki=>{const Mi=Ki.findIndex(Dr=>n3(Dr,Nn));return Mi>=0?Mi===Ki.length-1?Ki:Ki.slice(0,Mi+1):[...Ki,dy(Nn,_t)]})},[dy,n3]),Dp=Lt.useCallback((Nn,_t)=>{y(Ki=>{const Mi=Ki[Ki.length-1];return n3(Mi,Nn)?Ki:[dy(Nn,_t)]})},[dy,n3]),MT=Lt.useCallback(Nn=>{y(_t=>Nn<0||Nn>=_t.length-1?_t:_t.slice(0,Nn+1))},[]),u7=Lt.useCallback(Nn=>{Nn.isRoot?y([e7e]):Dp(Nn.path,Nn.name)},[Dp]),CT=Lt.useCallback((Nn,_t)=>{if(vc===null){_t&&(_t.metaKey||_t.ctrlKey||_t.shiftKey)?hy(Nn):Fh(Nn);return}if(Nn===vc){gd();return}let Ki=null;g(Mi=>{if(Mi.status!=="ready"||!Mi.document.nodes.find(Lo=>Lo.id===vc))return Mi;const jl=new Set(Mi.document.edges.map(Lo=>Lo.id)),Ls=C8e(M8e(`${vc}-${Nn}`),jl,"edge"),as={id:Ls,from:vc,to:Nn,relationship:"http_call"};try{const Lo=nI(Mi.document,{type:"connect",edge:as});return ie(void 0),Pn(!0),ru(xf=>[...xf.slice(-(Tf-1)),Mi.document]),Q([]),Ki=Ls,{status:"ready",document:Lo}}catch(Lo){const xf=Lo instanceof Error?Lo.message:String(Lo);return ie(xf),Mi}}),gd(),Ki&&E1(Ki)},[vc,gd,Fh,hy,E1]),xT=Lt.useCallback((Nn,_t)=>{_t&&(_t.metaKey||_t.ctrlKey||_t.shiftKey)?c5(Nn):E1(Nn)},[E1,c5]),t3=Lt.useCallback((Nn,_t)=>{let Ki=null;g(Mi=>{if(Mi.status!=="ready")return Mi;const Dr=Mi.document.nodes.find(xf=>xf.id===Nn),jl=Mi.document.nodes.find(xf=>xf.id===_t);if(!Dr||!jl)return Mi;const Ls=new Set(Mi.document.edges.map(xf=>xf.id)),as=C8e(M8e(`${Nn}-${_t}`),Ls,"edge"),Lo={id:as,from:Nn,to:_t,relationship:"http_call"};try{const xf=nI(Mi.document,{type:"connect",edge:Lo});return ie(void 0),Pn(!0),ru(A1=>[...A1.slice(-(Tf-1)),Mi.document]),Q([]),Ki=as,{status:"ready",document:xf}}catch(xf){const A1=xf instanceof Error?xf.message:String(xf);return ie(A1),Mi}}),Ki&&E1(Ki)},[E1]),oh=Lt.useCallback((Nn,_t,Ki)=>{g(Mi=>{if(Mi.status!=="ready")return Mi;const Dr=new Set(Mi.document.nodes.map(Ls=>Ls.id)),jl=C8e(M8e(_t),Dr,Nn);try{const Ls=nI(Mi.document,{type:"add_node",node:{id:jl,kind:Nn,name:_t,description:Ki}});return ie(void 0),Pn(!0),ru(as=>[...as.slice(-(Tf-1)),Mi.document]),Q([]),{status:"ready",document:Ls}}catch(Ls){const as=Ls instanceof Error?Ls.message:String(Ls);return ie(as),Mi}})},[]),k0=Lt.useCallback(Nn=>{g(_t=>{if(_t.status!=="ready")return _t;try{const Ki=nI(_t.document,Nn);return ie(void 0),Pn(!0),ru(Mi=>[...Mi.slice(-(Tf-1)),_t.document]),Q([]),{status:"ready",document:Ki}}catch(Ki){const Mi=Ki instanceof Error?Ki.message:String(Ki);return ie(Mi),_t}})},[]),la=Lt.useCallback(()=>{Lc.length!==0&&(g(Nn=>{if(Nn.status!=="ready")return Nn;let _t=Nn.document;try{const Ki=Lc.filter(Dr=>Dr.type==="edge").map(Dr=>Dr.id);for(const Dr of Ki)_t.edges.some(jl=>jl.id===Dr)&&(_t=nI(_t,{type:"disconnect",id:Dr}));const Mi=Lc.filter(Dr=>Dr.type==="node").map(Dr=>Dr.id);for(const Dr of Mi)_t.nodes.some(jl=>jl.id===Dr)&&(_t=nI(_t,{type:"remove_node",id:Dr}));return _t===Nn.document?Nn:(ie(void 0),Pn(!0),ru(Dr=>[...Dr.slice(-(Tf-1)),Nn.document]),Q([]),{status:"ready",document:_t})}catch(Ki){const Mi=Ki instanceof Error?Ki.message:String(Ki);return ie(Mi),Nn}}),Mf())},[Lc,Mf]),l5=Lt.useCallback(()=>{if(h.status!=="ready"||Pu.length===0)return;const Nn=Pu[Pu.length-1];ru(_t=>_t.slice(0,-1)),Q(_t=>[..._t,h.document]),g({status:"ready",document:Nn}),Pn(!0),ie(void 0),Mf()},[h,Pu,Mf]),by=Lt.useCallback(()=>{if(h.status!=="ready"||cr.length===0)return;const Nn=cr[cr.length-1];Q(_t=>_t.slice(0,-1)),ru(_t=>[..._t,h.document]),g({status:"ready",document:Nn}),Pn(!0),ie(void 0),Mf()},[h,cr,Mf]);if(Lt.useEffect(()=>{const Nn=_t=>{if((_t.metaKey||_t.ctrlKey)&&_t.key==="s"){_t.preventDefault(),Dn&&o5();return}if((_t.metaKey||_t.ctrlKey)&&(_t.key==="z"||_t.key==="Z")){_t.preventDefault(),_t.shiftKey?by():l5();return}if((_t.metaKey||_t.ctrlKey)&&_t.key==="y"){_t.preventDefault(),by();return}if(_t.key==="Escape"){vc&&gd();return}if(_t.key==="Delete"||_t.key==="Backspace"){const Ki=_t.target;if(Ki instanceof HTMLInputElement||Ki instanceof HTMLTextAreaElement||Ki instanceof HTMLSelectElement||Ki instanceof HTMLElement&&Ki.isContentEditable||Lc.length===0)return;_t.preventDefault(),la()}};return window.addEventListener("keydown",Nn),()=>window.removeEventListener("keydown",Nn)},[Dn,o5,vc,gd,Lc,la,l5,by]),h.status==="loading")return J.jsxs(u1n,{children:["Loading ",T.docUrl,"…"]});if(h.status==="error")return J.jsx(u1n,{children:J.jsx("pre",{className:"max-w-3xl whitespace-pre-wrap text-xs text-rose-700",children:h.error})});const i3=h.document,Ob=Tt&&$t.status==="pending",gy=Ob&&$t.status==="pending"?pZn(i3,$t.doc):null,r3=Ob&&$t.status==="pending"?Qdn(W8e(i3,$t.doc)):null,wd=gy??i3,wy=y0?.type==="node"?wd.nodes.find(Nn=>Nn.id===y0.id):void 0,c3=y0?.type==="edge"?wd.edges.find(Nn=>Nn.id===y0.id):void 0,s7=vc!==null?i3.nodes.find(Nn=>Nn.id===vc):void 0,f5=Lc.length>1;return J.jsxs("div",{className:"flex h-full flex-col",style:{background:"var(--archik-canvas)",color:"var(--archik-fg)"},children:[J.jsx(NXn,{document:i3,commandError:oe,saveStatus:Qe,...rn!==null?{saveError:rn}:{},isDirty:Dn,onSave:()=>{o5()},onAddNode:oh,density:kl,onDensityChange:Gt,viewMode:ki,onViewModeChange:wu,canUndo:Pu.length>0,canRedo:cr.length>0,onUndo:l5,onRedo:by,getSvg:Qr,seqHighlight:Wn,onToggleSeqHighlight:()=>Ot(Nn=>!Nn),seqNodeCount:Vn.size,...le!==void 0?{reloadError:le}:{},...s7!==void 0?{connectingFromName:s7.name,onCancelConnect:gd}:{}}),$t.status==="pending"&&J.jsx(JXn,{added:$t.added,removed:$t.removed,changed:$t.changed,note:$t.note,reviewing:Ob,onReview:$s,onAccept:()=>{fs()},onReject:()=>{s5()}}),$t.status==="error"&&J.jsxs("div",{role:"alert",style:{background:"rgba(217, 119, 6, 0.12)",borderBottom:"1px solid rgba(217, 119, 6, 0.45)",color:"var(--archik-warning)",padding:"8px 16px",fontSize:12,display:"flex",alignItems:"center",gap:12},children:[J.jsx("span",{style:{fontWeight:700},children:"SUGGESTION ERROR —"}),J.jsx("span",{style:{flex:1,color:"var(--archik-fg)"},children:$t.message}),J.jsx("button",{type:"button",onClick:()=>Pt({status:"none"}),"aria-label":"Dismiss",style:{background:"transparent",border:"none",color:"var(--archik-fg-dim)",cursor:"pointer",fontSize:16,lineHeight:1},children:"×"})]}),le!==void 0&&J.jsxs("div",{role:"alert",style:{background:"rgba(225, 29, 72, 0.12)",borderBottom:"1px solid rgba(225, 29, 72, 0.45)",color:"var(--archik-danger)",padding:"10px 16px",display:"flex",alignItems:"flex-start",gap:12,fontSize:12,lineHeight:1.5},children:[J.jsx("span",{style:{fontWeight:700,letterSpacing:"0.04em"},children:"FILE INVALID —"}),J.jsx("pre",{style:{margin:0,flex:1,whiteSpace:"pre-wrap",fontFamily:"inherit",color:"var(--archik-fg)"},children:le}),J.jsx("button",{type:"button",onClick:()=>Te(void 0),"aria-label":"Dismiss error",style:{background:"transparent",border:"none",color:"var(--archik-fg-dim)",cursor:"pointer",padding:"0 4px",fontSize:16,lineHeight:1},children:"×"})]}),J.jsxs("main",{className:"flex min-h-0 flex-1 p-4",style:{gap:0},children:[J.jsx("div",{className:"archik-panel",style:{flex:1,minWidth:0,overflow:"hidden"},children:J.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",width:"100%"},children:[(C.length>1||p.length>1)&&J.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 10px",background:"var(--archik-surface)",borderBottom:"1px solid var(--archik-border)"},children:[J.jsx(DXn,{files:C,currentPath:U,onSwitchFile:u7}),J.jsx($Xn,{stack:p,onGoToFrame:MT,suggestionsByPath:P})]}),J.jsx(oqn,{document:wd,className:"flex-1 archik-grid",layoutOptions:Ke,viewMode:ki,selectedNodeIds:r7,selectedEdgeIds:ls,onSelectNode:CT,onSelectEdge:xT,onSelectNothing:vc===null?Mf:gd,onConnectDrag:t3,onOpenSubFile:c7,onCrossFileNavigate:Dp,viewKey:T.docUrl,svgRef:gr,...r3?{diffStatuses:r3}:{},...Wn&&Vn.size>0?{glowNodeIds:Vn}:{}})]})}),J.jsx("aside",{"aria-hidden":Lc.length===0,className:`archik-drawer-shell ${Lc.length>0?"archik-drawer-shell--open":"archik-drawer-shell--closed"}`,children:J.jsx("div",{className:"archik-panel archik-drawer-content archik-drawer-fade",style:{overflow:"hidden"},children:f5?J.jsx(GXn,{count:Lc.length,onDelete:la,onClear:Mf}):y0?.type==="edge"?J.jsx(LZn,{edge:c3,dispatch:k0,readOnly:Ob}):y0?.type==="node"?J.jsx(OZn,{node:wy,dispatch:k0,onStartConnect:u5,allNodes:wd.nodes,readOnly:Ob,viewKey:T.archikFile??void 0}):null},f5?`multi:${Lc.length}`:y0?`${y0.type}:${y0.id}`:"empty")})]})]})}function GXn({count:h,onDelete:g,onClear:p}){return J.jsxs("div",{className:"flex h-full flex-col gap-4 overflow-y-auto p-4 text-sm",children:[J.jsxs("div",{children:[J.jsx("div",{className:"archik-label",children:"Selection"}),J.jsxs("div",{style:{fontSize:18,fontWeight:600,color:"var(--archik-fg)",letterSpacing:"0.01em"},children:[h," items"]}),J.jsx("div",{style:{fontSize:11,color:"var(--archik-fg-dim)",marginTop:4},children:"Hold ⌘ / Ctrl while clicking to add or remove items."})]}),J.jsx("div",{className:"archik-divider"}),J.jsxs("div",{className:"mt-auto flex flex-col gap-2 pt-4",children:[J.jsx("button",{type:"button",onClick:p,className:"archik-btn",style:{justifyContent:"center",padding:"8px 12px"},children:"Clear selection"}),J.jsxs("button",{type:"button",onClick:g,className:"archik-btn archik-btn-danger",style:{justifyContent:"center",padding:"8px 12px"},children:["Delete ",h," items"]})]})]})}function u1n({children:h}){return J.jsx("div",{className:"flex h-full items-center justify-center p-6 text-sm",style:{background:"var(--archik-canvas)",color:"var(--archik-fg-dim)"},children:h})}function JXn({added:h,removed:g,changed:p,note:y,reviewing:T,onReview:C,onAccept:j,onReject:P}){const q=h+g+p;return J.jsxs("div",{role:"region","aria-label":"Pending suggestion",style:{background:"rgba(168, 85, 247, 0.12)",borderBottom:"1px solid rgba(168, 85, 247, 0.45)",padding:"10px 16px",display:"flex",alignItems:"center",gap:14,fontSize:12,lineHeight:1.4},children:[J.jsx("span",{style:{fontWeight:700,letterSpacing:"0.04em",color:"#c4b5fd"},children:"📝 SUGGESTION PENDING"}),J.jsxs("span",{style:{color:"var(--archik-fg)"},children:[q===0?"(identical to current — nothing to apply)":J.jsxs(J.Fragment,{children:[J.jsxs("span",{style:{color:"var(--archik-success)"},children:["+",h]})," ",J.jsxs("span",{style:{color:"var(--archik-danger)"},children:["−",g]})," ",J.jsxs("span",{style:{color:"var(--archik-warning)"},children:["~",p]})]}),y?J.jsxs("span",{style:{marginLeft:10,color:"var(--archik-fg-dim)",fontStyle:"italic"},children:['"',y,'"']}):null]}),J.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:8},children:[J.jsx("button",{type:"button",onClick:C,className:"archik-btn",style:{padding:"5px 12px",fontSize:12,...T?{background:"#a855f7",color:"white",borderColor:"#a855f7"}:{}},children:T?"Hide diff":"Review"}),J.jsx("button",{type:"button",onClick:j,className:"archik-btn",title:q===0?"Suggestion already matches the current file — Accept just clears the sidecar.":"Apply the suggestion to the main file.",style:{padding:"5px 12px",fontSize:12,background:"var(--archik-success)",color:"white",borderColor:"var(--archik-success)"},children:"Accept"}),J.jsx("button",{type:"button",onClick:P,className:"archik-btn",style:{padding:"5px 12px",fontSize:12,color:"var(--archik-danger)",borderColor:"var(--archik-danger)"},children:"Reject"})]})]})}const UXn=i7(["sync","async","return","create","destroy"]),HXn=i7(["over","left_of","right_of"]),KXn=i7(["alt","opt","loop","par","break","ref"]),ZXn=Xg({id:bd,nodeId:bd,label:os().min(1).optional(),status:TI.optional()}),XXn=Xg({type:iU("message"),id:bd,from:bd,to:bd,label:os().min(1),arrow:UXn,activate:mKn().optional(),status:TI.optional()}),VXn=Xg({type:iU("note"),id:bd,position:HXn,participants:Kg(bd).min(1),text:os().min(1),status:TI.optional()}),WXn=C7e(()=>Xg({label:os().optional(),steps:Kg(u0n)})),YXn=C7e(()=>Xg({type:iU("group"),id:bd,kind:KXn,condition:os().optional(),label:os().optional(),branches:Kg(WXn).optional(),seqFile:Udn.optional(),participants:Kg(bd).optional(),status:TI.optional()})),u0n=C7e(()=>Fdn([XXn,VXn,YXn]));function s0n(h,g){const p=[];for(const y of h)if(g.has(y.id)?p.push(y.id):g.add(y.id),y.type==="group"&&y.branches)for(const T of y.branches)p.push(...s0n(T.steps,g));return p}const QXn=Xg({useCase:bd,slice:bd}),eVn=Xg({version:iU("1.0"),name:os().min(1),description:os().optional(),realizes:QXn.optional(),participants:Kg(ZXn).min(1),steps:Kg(u0n)}).superRefine((h,g)=>{const p=new Set;for(let C=0;C<h.participants.length;C++){const j=h.participants[C];p.has(j.id)&&g.addIssue({code:Mb.custom,path:["participants",C,"id"],message:`duplicate participant id "${j.id}"`}),p.add(j.id)}const y=new Set,T=s0n(h.steps,y);for(const C of T)g.addIssue({code:Mb.custom,path:["steps"],message:`duplicate step id "${C}"`})}),rU=56,nVn=160,tVn=40,n7e=56,iVn=24,N8e=12,s1n=64,Vce=32,o1n=24,l1n=8,o0n="seq-arrow-filled",l0n="seq-arrow-open";function rVn(h){return Math.max(nVn,h.length*8+tVn*2)}function f0n(h,g,p,y,T){let C=p;const j=[];for(const P of h)if(P.type==="message"){const q=g.get(P.from),U=g.get(P.to),oe=q?.cx??y,ie=U?.cx??y;j.push({type:"message",id:P.id,fromCx:oe,toCx:ie,y:C,label:P.label,arrow:P.arrow,activate:P.activate??!1,isSelf:P.from===P.to,...P.status!==void 0?{status:P.status}:{}}),C+=P.from===P.to?n7e*1.5:n7e}else if(P.type==="note"){const q=P.participants.map(Te=>g.get(Te)?.cx).filter(Te=>Te!==void 0).sort((Te,Qe)=>Te-Qe),U=q[0]??y,oe=q[q.length-1]??T,ie=Math.min(Math.max(P.text.length*7.5+24,oe-U+16,80),400);let le;P.position==="left_of"?le=U-ie-8:P.position==="right_of"?le=oe+8:le=(U+oe)/2-ie/2,le=Math.max(0,le),j.push({type:"note",id:P.id,x:le,y:C,width:ie,height:s1n,text:P.text,...P.status!==void 0?{status:P.status}:{}}),C+=s1n+8}else if(P.type==="group"){C+=8;const q=y-N8e,U=T-y+N8e*2,oe=C;C+=iVn;const ie=[];if(P.branches)for(let le=0;le<P.branches.length;le++){const Te=P.branches[le],Qe=C,{items:re,endY:rn}=f0n(Te.steps,g,C,y,T);C=rn,ie.push({...Te.label!==void 0?{label:Te.label}:{},startY:Qe,...le<P.branches.length-1?{dividerY:C}:{},steps:re}),le<P.branches.length-1&&(C+=4)}C+=N8e,j.push({type:"group",id:P.id,kind:P.kind,...P.condition!==void 0?{condition:P.condition}:{},...P.label!==void 0?{label:P.label}:{},...P.seqFile!==void 0?{seqFile:P.seqFile}:{},x:q,y:oe,width:U,height:C-oe,branches:ie,...P.status!==void 0?{status:P.status}:{}})}return{items:j,endY:C}}function a0n(h){const g=new Map;for(const p of h)if(p.type==="message"&&p.arrow==="destroy"&&g.set(p.toCx,p.y+rU+20),p.type==="group")for(const y of p.branches)for(const[T,C]of a0n(y.steps))g.set(T,C);return g}function cVn(h){const g=[],p=new Map;function y(T){for(const C of T)if(C.type==="message"){if(C.activate&&C.arrow==="sync"&&!C.isSelf){const j=p.get(C.toCx)??[];j.push(C.y),p.set(C.toCx,j)}if(C.arrow==="return"&&!C.isSelf){const j=p.get(C.fromCx);if(j&&j.length>0){const P=j.pop();g.push({cx:C.fromCx,startY:P,endY:C.y}),j.length===0&&p.delete(C.fromCx)}}}else if(C.type==="group")for(const j of C.branches)y(j.steps)}y(h);for(const[T,C]of p)for(const j of C)g.push({cx:T,startY:j,endY:j+n7e/2});return g}function uVn(h,g){const p=h.participants.map(rn=>rVn(rn.label??rn.nodeId));let y=Vce;const T=h.participants.map((rn,vn)=>{const Dn=p[vn],Pn=y+Dn/2;y+=Dn;const Wn=g?.get(rn.nodeId);return{id:rn.id,nodeId:rn.nodeId,label:rn.label??rn.nodeId,cx:Pn,colWidth:Dn,...Wn!==void 0?{kind:Wn}:{},...rn.status!==void 0?{status:rn.status}:{},lifelineEndY:0}}),C=y+Vce,j=new Map(T.map(rn=>[rn.id,rn])),P=T[0]?.cx??Vce,q=T[T.length-1]?.cx??C-Vce,U=o1n,{items:oe,endY:ie}=f0n(h.steps,j,U,P,q),le=rU+ie+o1n,Te=a0n(oe),Qe=T.map(rn=>({...rn,lifelineEndY:Te.get(rn.cx)??le})),re=cVn(oe);return{participants:Qe,steps:oe,activations:re,totalWidth:C,totalHeight:le}}const Wce=36,sVn=128,oVn=7,f1n=20,a1n=24;function lVn({participant:h,nodeKind:g}){const p=g?Qm[g]:void 0,y=p?.color??"var(--archik-fg-muted)",T=(rU-Wce)/2,C=p?.icon,j=Math.max(sVn,h.label.length*oVn+a1n+(C?f1n:0)),P=j/2,q=C?P+f1n/2:P,U=h.status,oe=U==="proposed"?.55:U==="deprecated"?.35:1,ie=U==="proposed"||U==="deprecated"?"4 3":void 0;return J.jsxs("g",{transform:`translate(${h.cx-P}, ${T})`,opacity:oe,children:[J.jsx("rect",{width:j,height:Wce,rx:8,fill:"var(--archik-node-fill)",stroke:y,strokeWidth:1.4,...ie!==void 0?{strokeDasharray:ie}:{}}),C&&J.jsx("g",{transform:`translate(${a1n/2}, ${(Wce-14)/2})`,children:J.jsx(C,{size:14,color:y,strokeWidth:1.5})}),J.jsx("text",{x:q,y:Wce/2+4,textAnchor:"middle",fontSize:12,fontWeight:500,fill:"var(--archik-fg)",fontFamily:"inherit",children:h.label})]})}function fVn({participant:h}){const g=h.status,p=g==="proposed"?.3:g==="deprecated"?.2:.5;return J.jsx("line",{x1:h.cx,y1:rU,x2:h.cx,y2:h.lifelineEndY,stroke:"var(--archik-node-stroke)",strokeWidth:1,strokeDasharray:"4 4",opacity:p})}const I8e=32,D8e=20,aVn=-6;function hVn({msg:h}){const g=h.arrow==="return",p=h.arrow==="async",y=h.arrow==="create",T=g||y,C=h.arrow==="destroy",j=g||p?l0n:o0n,P=h.status==="proposed"?.5:h.status==="deprecated"?.35:1;if(h.isSelf){const ie=h.fromCx,le=h.y,Te=`M ${ie} ${le} L ${ie+I8e} ${le} L ${ie+I8e} ${le+D8e} L ${ie} ${le+D8e}`;return J.jsxs("g",{opacity:P,children:[J.jsx("path",{d:Te,fill:"none",stroke:"var(--archik-edge-filled)",strokeWidth:1.4,markerEnd:`url(#${j})`}),J.jsx("text",{x:ie+I8e+6,y:le+D8e/2+4,fontSize:11,fill:"var(--archik-fg)",fontFamily:"inherit",children:h.label})]})}const U=h.fromCx<h.toCx?h.toCx-6:h.toCx+6,oe=(h.fromCx+h.toCx)/2;return J.jsxs("g",{opacity:P,children:[J.jsx("line",{x1:h.fromCx,y1:h.y,x2:U,y2:h.y,stroke:"var(--archik-edge-filled)",strokeWidth:1.4,strokeDasharray:T?"4 4":void 0,markerEnd:C?void 0:`url(#${j})`}),J.jsxs("text",{x:oe,y:h.y+aVn,textAnchor:"middle",fontSize:11,fill:"var(--archik-fg)",fontFamily:"inherit",children:[y&&"«create» ",h.label]}),h.arrow==="destroy"&&J.jsxs("g",{transform:`translate(${h.toCx-6}, ${h.y-6})`,children:[J.jsx("line",{x1:0,y1:0,x2:12,y2:12,stroke:"var(--archik-fg-muted)",strokeWidth:1.5}),J.jsx("line",{x1:12,y1:0,x2:0,y2:12,stroke:"var(--archik-fg-muted)",strokeWidth:1.5})]})]})}const dVn={alt:"#6366f1",opt:"#0ea5e9",loop:"#10b981",par:"#f59e0b",break:"#ef4444",ref:"#8b5cf6"},h1n=36,$8e=18;function bVn({group:h,renderStep:g,onRefClick:p}){const y=dVn[h.kind]??"var(--archik-fg-muted)",T=h.status==="proposed"?.55:h.status==="deprecated"?.35:1,C=h.kind==="ref"&&h.seqFile!==void 0&&p!==void 0;return J.jsxs("g",{opacity:T,onClick:C?()=>p(h.seqFile):void 0,style:C?{cursor:"pointer"}:void 0,children:[J.jsx("rect",{x:h.x,y:h.y,width:h.width,height:h.height,rx:4,fill:"none",stroke:y,strokeWidth:1.2,opacity:.6}),J.jsx("rect",{x:h.x,y:h.y,width:h1n,height:$8e,rx:4,fill:y,opacity:.8}),J.jsx("text",{x:h.x+6,y:h.y+$8e-5,fontSize:10,fontWeight:600,fill:"#fff",fontFamily:"inherit",children:h.kind}),(h.condition??h.label)&&J.jsx("text",{x:h.x+h1n+6,y:h.y+$8e-5,fontSize:10,fill:y,fontFamily:"inherit",children:h.condition??h.label}),h.branches.map((j,P)=>J.jsxs("g",{children:[j.label&&J.jsx("text",{x:h.x+6,y:j.startY+12,fontSize:10,fill:y,fontFamily:"inherit",children:j.label}),j.steps.map(q=>g(q)),j.dividerY!==void 0&&J.jsx("line",{x1:h.x,y1:j.dividerY,x2:h.x+h.width,y2:j.dividerY,stroke:y,strokeWidth:1,strokeDasharray:"4 2",opacity:.5})]},P))]})}const iI=10;function gVn(h,g){const p=Math.max(10,Math.floor(g/6.5));if(h.length<=p)return[h];const y=h.split(" "),T=[];let C="";for(const j of y)(C+(C?" ":"")+j).length>p&&C?(T.push(C),C=j):C=C?C+" "+j:j;return C&&T.push(C),T.slice(0,3)}function wVn({note:h}){const{x:g,y:p,width:y,height:T,text:C}=h,j=h.status==="proposed"?.55:h.status==="deprecated"?.35:1;return J.jsxs("g",{opacity:j,children:[J.jsx("path",{d:`M ${g} ${p} L ${g+y-iI} ${p} L ${g+y} ${p+iI} L ${g+y} ${p+T} L ${g} ${p+T} Z`,fill:"var(--archik-node-fill)",stroke:"var(--archik-node-stroke)",strokeWidth:1.2}),J.jsx("path",{d:`M ${g+y-iI} ${p} L ${g+y-iI} ${p+iI} L ${g+y} ${p+iI}`,fill:"none",stroke:"var(--archik-node-stroke)",strokeWidth:1.2}),gVn(C,y-16).map((P,q)=>J.jsx("text",{x:g+8,y:p+8+11+q*13,fontSize:11,fill:"var(--archik-fg)",fontFamily:"inherit",children:P},q))]})}function pVn({id:h}){return J.jsx("marker",{id:h,viewBox:"0 0 10 10",refX:"10",refY:"5",markerWidth:"6",markerHeight:"6",orient:"auto-start-reverse",children:J.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"context-stroke"})})}function mVn({id:h}){return J.jsx("marker",{id:h,viewBox:"0 0 12 12",refX:"11",refY:"6",markerWidth:"7",markerHeight:"7",orient:"auto-start-reverse",children:J.jsx("path",{d:"M 1 1 L 11 6 L 1 11",fill:"none",stroke:"context-stroke",strokeWidth:"1.5",strokeLinejoin:"round"})})}function h0n({step:h,onRefClick:g}){return h.type==="message"?J.jsx(hVn,{msg:h}):h.type==="note"?J.jsx(wVn,{note:h}):h.type==="group"?J.jsx(bVn,{group:h,...g!==void 0?{onRefClick:g}:{},renderStep:p=>J.jsx(h0n,{step:p,...g!==void 0?{onRefClick:g}:{}},p.id)}):null}function vVn({laid:h,svgRef:g,onRefClick:p}){const{participants:y,steps:T,activations:C,totalWidth:j,totalHeight:P}=h;return J.jsxs("svg",{ref:g,width:j,height:P,viewBox:`0 0 ${j} ${P}`,xmlns:"http://www.w3.org/2000/svg",style:{fontFamily:"var(--archik-font, system-ui)"},children:[J.jsxs("defs",{children:[J.jsx(pVn,{id:o0n}),J.jsx(mVn,{id:l0n})]}),y.map(q=>J.jsx(fVn,{participant:q},q.id)),y.map(q=>J.jsx(lVn,{participant:q,...q.kind!==void 0?{nodeKind:q.kind}:{}},q.id)),J.jsxs("g",{transform:`translate(0, ${rU})`,children:[C.map(q=>J.jsx("rect",{x:q.cx-l1n/2,y:q.startY,width:l1n,height:q.endY-q.startY,fill:"var(--archik-node-fill)",stroke:"var(--archik-node-stroke)",strokeWidth:1,rx:2},`${q.cx}-${q.startY}`)),T.map(q=>J.jsx(h0n,{step:q,...p!==void 0?{onRefClick:p}:{}},q.id))]})]})}function yVn({path:h,fromViewKey:g}){const[p,y]=Lt.useState({status:"loading"}),[T,C]=Lt.useState(void 0),j=Lt.useRef(null);Lt.useEffect(()=>{fetch("/__archik/node-kinds").then(ie=>ie.ok?ie.json():null).then(ie=>{ie&&C(new Map(Object.entries(ie)))}).catch(()=>{})},[]),Lt.useEffect(()=>{y({status:"loading"});const ie=encodeURIComponent(h);fetch(`/__archik/seq-file?path=${ie}`).then(async le=>{if(!le.ok)throw new Error(`${le.status} ${le.statusText}`);return le.text()}).then(le=>{const Te=y7e.parse(le),Qe=eVn.safeParse(Te);if(!Qe.success)throw new Error(Qe.error.issues.map(re=>re.message).join("; "));y({status:"ready",doc:Qe.data})}).catch(le=>{y({status:"error",message:le instanceof Error?le.message:String(le)})})},[h]);const P=g?`/?file=${encodeURIComponent(g)}`:"/";if(p.status==="loading")return J.jsx("div",{className:"flex h-screen items-center justify-center",style:{color:"var(--archik-fg-muted)"},children:"Loading sequence diagram…"});if(p.status==="error")return J.jsxs("div",{className:"flex h-screen flex-col items-center justify-center gap-4",children:[J.jsx("div",{style:{color:"var(--archik-fg-error, #ef4444)"},children:p.message}),J.jsx("a",{href:P,style:{color:"var(--archik-fg-muted)",fontSize:13},children:"← Architecture"})]});const q=uVn(p.doc,T),U=h.replace(/^.*\//,"").replace(/\.archik\.seq\.yaml$/,""),oe=ie=>{const le=`?path=${encodeURIComponent(ie)}&from=${encodeURIComponent(h)}`;window.location.href=`/seq${le}`};return J.jsxs("div",{className:"flex h-screen flex-col",style:{background:"var(--archik-bg)"},children:[J.jsxs("div",{className:"flex items-center gap-3 px-4",style:{height:48,borderBottom:"1px solid var(--archik-node-stroke)",background:"var(--archik-toolbar-bg, var(--archik-node-fill))"},children:[J.jsx("a",{href:P,style:{color:"var(--archik-fg-muted)",fontSize:13,textDecoration:"none"},children:"← Architecture"}),J.jsx("span",{style:{color:"var(--archik-node-stroke)"},children:"|"}),J.jsx("span",{style:{fontWeight:500,fontSize:14,color:"var(--archik-fg)"},children:p.doc.name}),J.jsx("div",{className:"ml-auto",children:J.jsx(t0n,{filename:U,getSvg:()=>j.current})})]}),J.jsx("div",{className:"flex-1 overflow-auto p-6",children:J.jsx(vVn,{laid:q,svgRef:j,onRefClick:oe})})]})}const d0n=document.getElementById("root");if(!d0n)throw new Error("#root not found");const d1n=new URLSearchParams(window.location.search),kVn=window.location.pathname==="/__archik/seq"||window.location.pathname.startsWith("/__archik/seq/"),b1n=szn.createRoot(d0n);if(kVn){const h=d1n.get("path")??"",g=d1n.get("from");b1n.render(J.jsx(Lt.StrictMode,{children:J.jsx(yVn,{path:h,fromViewKey:g})}))}else b1n.render(J.jsx(Lt.StrictMode,{children:J.jsx(qXn,{})}));
@@ -14,7 +14,7 @@
14
14
  }
15
15
  } catch {}
16
16
  </script>
17
- <script type="module" crossorigin src="/assets/index-__Qls1IU.js"></script>
17
+ <script type="module" crossorigin src="/assets/index-7D_S7MHt.js"></script>
18
18
  <link rel="stylesheet" crossorigin href="/assets/index-D2nrAfzh.css">
19
19
  </head>
20
20
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "archik",
3
- "version": "0.12.21",
3
+ "version": "0.12.22",
4
4
  "description": "The shared vocabulary between you and Claude Code, at the engineering level. Plain-YAML architecture diagrams with a live browser canvas, headless SVG render in CI, and an installable Claude skill so the model treats the diagram as the spec.",
5
5
  "keywords": [
6
6
  "architecture",