archik 0.12.31 → 0.12.32

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.
@@ -223,4 +223,4 @@ ${oXn(p)}
223
223
  `)}function hXn(h,g){const p=g.get(h.from)?.name??h.from,v=g.get(h.to)?.name??h.to,T=h.label!==void 0?`: ${h.label}`:"",M=h.status&&h.status!=="active"?` _(${h.status})_`:"";return`- ${p} **${h.relationship}** ${v}${T}${M}`}function dXn(h){const g=new Map;for(const v of h.nodes)g.set(v.id,v);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 v of h.nodes)p.push("",aXn(v));if(p.push("","## Connections"),h.edges.length===0)p.push("","_No connections yet._");else{p.push("");for(const v of h.edges)p.push(hXn(v,g))}return`${p.join(`
224
224
  `)}
225
225
  `}const bXn={name:"yaml",label:"YAML",extension:".yaml",mime:"application/yaml",export:P7e},gXn={name:"json",label:"JSON",extension:".json",mime:"application/json",export:u0n},wXn={name:"markdown",label:"Markdown",extension:".md",mime:"text/markdown",export:dXn},pXn=[bXn,gXn,wXn];function h0n({document:h,filename:g,getSvg:p}){const v=async j=>{try{await navigator.clipboard.writeText(j)}catch{}},T=()=>{const j=p?.();j&&f1n(a1n(g,"svg"),lXn(j))},M=async()=>{const j=p?.();if(j)try{const R=await fXn(j);f1n(a1n(g,"png"),R)}catch(R){console.error("PNG export failed:",R)}};return P.jsx(TT,{trigger:j=>P.jsxs("button",{type:"button",className:"archik-btn",children:["Export",P.jsx("span",{style:{opacity:.6},children:j?"▴":"▾"})]}),children:j=>P.jsxs(P.Fragment,{children:[h&&pXn.map(R=>P.jsxs("button",{type:"button",className:"archik-menu-item",onClick:()=>{v(R.export(h)),j()},children:[P.jsx("span",{style:{minWidth:60,color:"var(--archik-fg-dim)"},children:"Copy"}),P.jsx("span",{children:R.label})]},R.name)),h&&P.jsxs(P.Fragment,{children:[P.jsx("hr",{style:{border:0,borderTop:"1px solid var(--archik-border)",margin:"4px 0"}}),P.jsxs("button",{type:"button",className:"archik-menu-item",onClick:()=>{jZn(g,h),j()},children:[P.jsx("span",{style:{minWidth:60,color:"var(--archik-fg-dim)"},children:"Download"}),P.jsx("span",{children:"YAML"})]})]}),p&&P.jsxs(P.Fragment,{children:[P.jsxs("button",{type:"button",className:"archik-menu-item",onClick:()=>{T(),j()},children:[P.jsx("span",{style:{minWidth:60,color:"var(--archik-fg-dim)"},children:"Download"}),P.jsx("span",{children:"SVG"})]}),P.jsxs("button",{type:"button",className:"archik-menu-item",onClick:()=>{M(),j()},children:[P.jsx("span",{style:{minWidth:60,color:"var(--archik-fg-dim)"},children:"Download"}),P.jsx("span",{children:"PNG"})]})]})]})})}const d0n="archik-density",b0n="archik-view-mode",hI=1,D8e="detailed";function mXn(){if(typeof localStorage>"u")return D8e;try{return localStorage.getItem(b0n)==="compact"?"compact":D8e}catch{return D8e}}function vXn(h){if(!(typeof localStorage>"u"))try{localStorage.setItem(b0n,h)}catch{}}function yXn(){if(typeof localStorage>"u")return hI;try{const h=localStorage.getItem(d0n);if(!h)return hI;const g=Number.parseFloat(h);return Number.isFinite(g)?B7e(g):hI}catch{return hI}}function kXn(h){if(!(typeof localStorage>"u"))try{localStorage.setItem(d0n,String(B7e(h)))}catch{}}function B7e(h){return Math.max(.3,Math.min(4,h))}function jXn(h){const g=B7e(h);return{nodeSpacing:Math.round(60*g),layerSpacing:Math.round(100*g),padding:Math.round(40*g)}}function SXn({density:h,onChange:g}){const p=Math.round(h*100);return P.jsx(TT,{align:"end",trigger:v=>P.jsxs("button",{type:"button",className:"archik-btn","aria-expanded":v,title:"Layout density",children:["Spacing",P.jsxs("span",{style:{opacity:.6},children:[p,"%"]})]}),children:()=>P.jsxs("div",{style:{minWidth:240,padding:8},children:[P.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",marginBottom:6},children:[P.jsx("span",{className:"archik-label",style:{margin:0},children:"Node spacing"}),P.jsxs("span",{className:"archik-mono",style:{fontSize:11,color:"var(--archik-fg-dim)"},children:[p,"%"]})]}),P.jsx("input",{type:"range",min:.3,max:4,step:.1,value:h,onChange:v=>g(Number.parseFloat(v.target.value)),style:{width:"100%",accentColor:"var(--archik-accent)"}}),P.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:10,color:"var(--archik-fg-muted)",marginTop:4},children:[P.jsx("span",{children:"tight"}),P.jsx("span",{children:"roomy"})]}),P.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:10},children:P.jsx("button",{type:"button",className:"archik-btn",onClick:()=>g(hI),disabled:h===hI,children:"Reset"})})]})})}function EXn(){return P.jsx(TT,{align:"end",trigger:h=>P.jsxs("button",{type:"button",className:"archik-btn","aria-expanded":h,children:["Legend",P.jsx("span",{style:{opacity:.6},children:h?"▴":"▾"})]}),children:()=>P.jsxs("div",{style:{minWidth:320,maxHeight:"min(70vh, 520px)",overflowY:"auto",padding:6},children:[P.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"}),R7e.map(h=>{const g=Qm[h],p=g.icon;return P.jsxs("div",{style:{display:"grid",gridTemplateColumns:"20px 80px 1fr",alignItems:"center",gap:8,padding:"5px 6px",fontSize:12},children:[P.jsx("span",{"aria-hidden":"true",style:{display:"flex",alignItems:"center",justifyContent:"center",color:g.color},children:P.jsx(p,{size:14,strokeWidth:1.8})}),P.jsx("code",{style:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",color:"var(--archik-fg)",fontSize:11},children:h}),P.jsx("span",{style:{color:"var(--archik-fg-dim)"},children:g.description})]},h)}),P.jsx(TXn,{})]})})}const AXn=[{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 TXn(){return P.jsxs(P.Fragment,{children:[P.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)"}),AXn.map(h=>P.jsxs("div",{style:{display:"grid",gridTemplateColumns:"20px 80px 1fr",alignItems:"center",gap:8,padding:"5px 6px",fontSize:12},children:[P.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:12,height:12,borderRadius:3,background:`var(${h.varName})`}}),P.jsx("code",{style:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",color:"var(--archik-fg)",fontSize:11},children:h.id}),P.jsx("span",{style:{color:"var(--archik-fg-dim)"},children:h.description})]},h.id))]})}function xXn({size:h=22}){return P.jsxs("svg",{width:h,height:h,viewBox:"0 0 24 24",fill:"none",role:"img","aria-label":"Archik",style:{display:"block"},children:[P.jsx("path",{d:"M 12 5 L 5 18",stroke:"var(--archik-accent)",strokeWidth:"1.4",strokeLinecap:"round"}),P.jsx("path",{d:"M 12 5 L 19 18",stroke:"var(--archik-accent-bright)",strokeWidth:"1.4",strokeLinecap:"round"}),P.jsx("path",{d:"M 5 18 L 19 18",stroke:"var(--archik-magenta)",strokeWidth:"1.2",strokeLinecap:"round",strokeDasharray:"2.5 2.5"}),P.jsx("circle",{cx:"12",cy:"5",r:"2.6",fill:"var(--archik-accent)"}),P.jsx("circle",{cx:"5",cy:"18",r:"2.6",fill:"var(--archik-accent-bright)"}),P.jsx("circle",{cx:"19",cy:"18",r:"2.6",fill:"var(--archik-magenta)"})]})}const MXn="archik-theme";function u7e(){return typeof document>"u"?"dark":document.documentElement.getAttribute("data-theme")==="light"?"light":"dark"}function CXn(h){if(!(typeof document>"u")){document.documentElement.setAttribute("data-theme",h);try{localStorage.setItem(MXn,h)}catch{}}}function OXn(){const h=u7e()==="dark"?"light":"dark";return CXn(h),h}function _Xn(){const[h,g]=kt.useState(()=>u7e());kt.useEffect(()=>{g(u7e())},[]);const p=()=>{g(OXn())},v=h==="dark"?"Light theme":"Dark theme",T=h==="dark"?"☀":"☾";return P.jsx("button",{type:"button",onClick:p,title:v,"aria-label":v,className:"archik-btn",style:{minWidth:30,justifyContent:"center"},children:P.jsx("span",{"aria-hidden":"true",children:T})})}const NXn="/__archik/usecases",IXn="/__archik/trace";async function h1n(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 DXn(){const[h,g]=kt.useState({status:"loading"}),[p,v]=kt.useState(0);return kt.useEffect(()=>{let T=!1;const M=new AbortController;return Promise.all([h1n(NXn,M.signal),h1n(IXn,M.signal)]).then(([j,R])=>{T||g({status:"ready",useCases:j.useCases??[],trace:R.rows??[]})}).catch(j=>{T||M.signal.aborted||g({status:"error",message:j instanceof Error?j.message:String(j)})}),()=>{T=!0,M.abort()}},[p]),P.jsx(TT,{align:"end",trigger:T=>P.jsxs("button",{type:"button",className:"archik-btn","aria-expanded":T,onClick:()=>{T||v(M=>M+1)},children:[P.jsx($Xn,{state:h}),P.jsx("span",{style:{opacity:.6,marginLeft:6},children:T?"▴":"▾"})]}),children:()=>P.jsx(LXn,{state:h})})}function $Xn({state:h}){if(h.status!=="ready"||h.trace.length===0)return P.jsx(P.Fragment,{children:"Use cases"});const g=g0n(h.trace);return g.none>0?P.jsxs("span",{title:`${g.none} untraced — needs tests + seq`,children:["Use cases"," ",P.jsxs("span",{style:{color:"var(--archik-danger)"},children:["○ ",g.none," untraced"]})]}):g.partial>0?P.jsxs("span",{title:`${g.partial} partial — missing test or realisation`,children:["Use cases"," ",P.jsxs("span",{style:{color:"var(--archik-warning)"},children:["◐ ",g.partial," to finish"]})]}):P.jsxs("span",{title:`All ${g.full} slices traced — ready to ship`,children:["Use cases"," ",P.jsx("span",{style:{color:"var(--archik-success)",fontWeight:600},children:"✓ all traced"})]})}function g0n(h){let g=0,p=0,v=0;for(const T of h)T.level==="full"?g++:T.level==="partial"?p++:v++;return{full:g,partial:p,none:v}}function LXn({state:h}){return P.jsxs("div",{style:{minWidth:360,maxHeight:"min(70vh, 560px)",overflowY:"auto",padding:6},children:[P.jsx(GXn,{label:"Use cases",children:P.jsx("a",{href:"/__archik/usecases",style:{fontSize:10,letterSpacing:"0.04em",textTransform:"none",color:"var(--archik-accent)",textDecoration:"none",fontWeight:500},title:"Open the full use cases page (clickable test paths + seq links)",children:"Open page →"})}),h.status==="loading"&&P.jsx($8e,{children:"Loading…"}),h.status==="error"&&P.jsxs($8e,{tone:"error",children:["Couldn't load: ",h.message]}),h.status==="ready"&&h.useCases.length===0&&P.jsxs($8e,{children:["No use cases defined. Add a ",P.jsx("code",{children:"*.archik.uc.yaml"})," file under"," ",P.jsx("code",{children:".archik/usecases/"}),"."]}),h.status==="ready"&&h.useCases.length>0&&P.jsxs(P.Fragment,{children:[P.jsx(RXn,{trace:h.trace}),P.jsx(PXn,{useCases:h.useCases,trace:h.trace})]})]})}function RXn({trace:h}){const g=kt.useMemo(()=>g0n(h),[h]),p=h.length;return p===0?P.jsx(P.Fragment,{}):P.jsxs("div",{title:"Coverage matrix — same as `npx archik trace`. ● fully traced (test + seq), ◐ partial, ○ untraced.",style:{display:"flex",alignItems:"center",gap:12,padding:"6px 10px",margin:"2px 2px 6px",borderRadius:6,background:"var(--archik-surface)",fontSize:11,color:"var(--archik-fg-dim)"},children:[P.jsx("span",{style:{fontWeight:600,color:"var(--archik-fg)"},children:"Trace"}),P.jsxs("span",{children:[P.jsx("span",{style:{color:"var(--archik-success)"},children:"●"})," ",g.full," full"]}),P.jsxs("span",{children:[P.jsx("span",{style:{color:"var(--archik-warning)"},children:"◐"})," ",g.partial," partial"]}),P.jsxs("span",{children:[P.jsx("span",{style:{color:"var(--archik-fg-muted)"},children:"○"})," ",g.none," untraced"]}),P.jsxs("span",{style:{marginLeft:"auto",color:"var(--archik-fg-muted)"},children:[p," ",p===1?"slice":"slices"]})]})}function PXn({useCases:h,trace:g}){const p=kt.useMemo(()=>{const v=new Map;for(const T of g)v.set(`${T.useCase}/${T.slice}`,T.level);return v},[g]);return P.jsx("div",{children:h.map(v=>P.jsx(zXn,{uc:v,traceByKey:p},v.id))})}function zXn({uc:h,traceByKey:g}){return P.jsxs("div",{style:{padding:"8px 8px 6px",borderTop:"1px solid var(--archik-border)"},children:[P.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:6,marginBottom:2},children:[P.jsx("code",{style:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:12,color:"var(--archik-fg)"},children:h.id}),P.jsx("span",{style:{color:"var(--archik-fg-dim)",fontSize:11},children:h.name}),h.status&&h.status!=="active"&&P.jsx("span",{className:"archik-pill",style:{fontSize:9,marginLeft:"auto"},children:h.status})]}),P.jsxs("div",{style:{color:"var(--archik-fg-muted)",fontSize:11},children:["primary ",P.jsx("code",{children:h.primaryActor}),h.secondaryActors&&h.secondaryActors.length>0&&P.jsxs(P.Fragment,{children:[" ","· secondary"," ",h.secondaryActors.map((p,v)=>P.jsxs("span",{children:[v>0&&", ",P.jsx("code",{children:p})]},p))]})]}),P.jsx("ul",{style:{marginTop:6,listStyle:"none",padding:0},children:h.slices.map(p=>{const v=g.get(`${h.id}/${p.id}`);return P.jsx(BXn,{slice:p,level:v},p.id)})})]})}function BXn({slice:h,level:g}){const[p,v]=kt.useState(!1);return P.jsxs("li",{style:{padding:"3px 0"},children:[P.jsxs("button",{type:"button",onClick:()=>v(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:[P.jsx(qXn,{level:g}),P.jsxs("span",{style:{fontSize:12,color:"var(--archik-fg)",display:"flex",alignItems:"baseline",gap:6},children:[P.jsx("code",{children:h.id}),h.status&&h.status!=="active"&&P.jsxs("span",{style:{color:"var(--archik-fg-dim)",fontSize:10},children:["[",h.status,"]"]}),P.jsx("span",{style:{color:"var(--archik-fg-dim)",fontSize:11,marginLeft:"auto"},children:(()=>{const T=h.tests?.length??0,M=`${T} ${T===1?"test":"tests"}`,j=h.realization?"realized":"no seq";return`${M} • ${j}`})()})]})]}),p&&P.jsxs("div",{style:{paddingLeft:24,color:"var(--archik-fg-dim)",fontSize:11,paddingBottom:4},children:[P.jsx("div",{style:{color:"var(--archik-fg)",marginBottom:4,lineHeight:1.4},children:h.description}),h.tests&&h.tests.length>0&&P.jsxs("div",{children:["tests:"," ",h.tests.map((T,M)=>P.jsxs("code",{children:[M>0&&", ",T]},T))]}),h.realization&&P.jsxs("div",{children:["realises: ",P.jsx("code",{children:h.realization.seqFile})]}),!h.tests?.length&&!h.realization&&P.jsx("div",{children:"(no tests, no realisation)"})]})]})}const FXn={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 qXn({level:h}){const g=FXn[h??"missing"];return P.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 GXn({label:h,children:g}){return P.jsxs("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,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[P.jsx("span",{children:h}),g]})}function $8e({children:h,tone:g}){return P.jsx("div",{style:{padding:"8px 8px 12px",fontSize:12,color:g==="error"?"var(--archik-status-deprecated, #f87171)":"var(--archik-fg-dim)"},children:h})}const UXn={idle:"",saving:"archik-pill archik-pill--info",saved:"archik-pill archik-pill--success",error:"archik-pill archik-pill--danger"},JXn={idle:null,saving:"Saving…",saved:"Saved",error:"Save failed"};function HXn({document:h,filename:g="architecture.archik.yaml",commandError:p,reloadError:v,saveStatus:T="idle",saveError:M,isDirty:j=!1,onSave:R,onAddNode:G,connectingFromName:J,onCancelConnect:oe,density:re,onDensityChange:le,viewMode:Ee,onViewModeChange:nn,canUndo:ie=!1,canRedo:tn=!1,onUndo:vn,onRedo:Dn,getSvg:zn,seqHighlight:Kn,onToggleSeqHighlight:_t,seqNodeCount:Jt}){const vt=JXn[T],Ht=typeof navigator<"u"&&/Mac/i.test(navigator.platform)?"⌘S":"Ctrl+S";return P.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:[P.jsxs("div",{className:"flex items-center gap-2",children:[P.jsx(xXn,{}),P.jsx("span",{className:"text-sm font-semibold tracking-tight",style:{color:"var(--archik-fg)",letterSpacing:"0.02em"},children:"Archik"})]}),P.jsx("span",{className:"archik-mono",style:{color:"var(--archik-fg-dim)",fontSize:11,opacity:.85},children:h.name}),J!==void 0&&P.jsxs("span",{className:"archik-pill archik-pill--info",children:["Connecting from ",P.jsx("strong",{children:J}),P.jsx("button",{type:"button",onClick:oe,className:"underline hover:no-underline",style:{color:"var(--archik-accent)"},children:"cancel (Esc)"})]}),p!==void 0&&P.jsx("span",{className:"archik-pill archik-pill--danger",children:p}),v!==void 0&&P.jsx("span",{className:"archik-pill archik-pill--warning",title:v,children:"File reload error"}),vt!==null&&P.jsx("span",{className:UXn[T],...T==="error"&&M!==void 0?{title:M}:{},children:vt}),T==="error"&&M!==void 0&&P.jsx("span",{className:"archik-pill archik-pill--danger",style:{maxWidth:480,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontFamily:"ui-monospace, monospace",fontSize:11},title:M,children:KXn(M)}),P.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[vn!==void 0&&P.jsx("button",{type:"button",onClick:vn,disabled:!ie,title:`Undo (${Ht.replace("S","Z")})`,"aria-label":"Undo",className:"archik-btn",style:{padding:"5px 8px"},children:P.jsx(hFn,{size:14,strokeWidth:1.8})}),Dn!==void 0&&P.jsx("button",{type:"button",onClick:Dn,disabled:!tn,title:`Redo (${Ht.replace("S","⇧Z").replace("Ctrl+","Ctrl+Shift+")})`,"aria-label":"Redo",className:"archik-btn",style:{padding:"5px 8px"},children:P.jsx(VBn,{size:14,strokeWidth:1.8})}),G!==void 0&&P.jsx(VZn,{onAdd:G}),Ee!==void 0&&nn!==void 0&&P.jsx("button",{type:"button",onClick:()=>nn(Ee==="compact"?"detailed":"compact"),title:Ee==="compact"?"Switch to detailed view":"Switch to compact view","aria-label":"Toggle view mode",className:"archik-btn",style:{padding:"5px 8px"},children:Ee==="compact"?P.jsx(LBn,{size:14,strokeWidth:1.8}):P.jsx(eFn,{size:14,strokeWidth:1.8})}),re!==void 0&&le!==void 0&&P.jsx(SXn,{density:re,onChange:le}),_t!==void 0&&(Jt??0)>0&&P.jsx("button",{type:"button",onClick:_t,title:Kn?"Hide sequence diagram highlights":`Show ${Jt} node${Jt===1?"":"s"} with sequence diagrams`,"aria-label":"Toggle sequence diagram highlights","aria-pressed":Kn,className:"archik-btn",style:{padding:"5px 8px",...Kn?{background:"var(--archik-status-proposed)",borderColor:"var(--archik-status-proposed)",color:"white"}:{}},children:P.jsx(M1n,{size:14,strokeWidth:1.8})}),P.jsx(DXn,{}),P.jsx(eXn,{}),P.jsx(EXn,{}),P.jsx(h0n,{document:h,filename:g,...zn!==void 0?{getSvg:zn}:{}}),P.jsx("button",{type:"button",onClick:R,disabled:!j||T==="saving",title:`Save to ${g} (${Ht})`,className:"archik-btn archik-btn-primary",children:j?"Save •":"Save"}),P.jsx(_Xn,{})]})]})}function KXn(h){const g=h.indexOf(`
226
- `);return g===-1?h:h.slice(0,g)}function ZXn({files:h,currentPath:g,onSwitchFile:p}){const v=h.some(M=>M.hasSuggestion||M.isOrphanSuggestion);if(h.length<=1&&!v)return null;const T=h.find(M=>M.path===g)??h[0];return P.jsx(TT,{align:"start",trigger:M=>P.jsxs("button",{type:"button","aria-label":"Switch architecture file","aria-expanded":M,className:"archik-btn",style:{display:"flex",alignItems:"center",gap:6,padding:"4px 10px",fontSize:12,background:"transparent",color:"var(--archik-fg)"},children:[P.jsx(ABn,{size:13,strokeWidth:1.8}),P.jsx("span",{style:{fontWeight:600},children:T.name}),T.hasSuggestion&&P.jsx(bue,{}),P.jsx(x1n,{size:12,strokeWidth:2,style:{opacity:.6}})]}),children:M=>P.jsxs("div",{style:{minWidth:220,padding:4},children:[P.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 R=j.path===T.path,G=j.isOrphanSuggestion===!0;return P.jsxs("button",{type:"button",title:G?`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:()=>{M(),!R&&p(j)},className:"archik-menu-item",style:{display:"flex",alignItems:"center",gap:8,width:"100%",textAlign:"left",padding:"6px 10px",fontSize:12,background:R?"var(--archik-surface-hover)":void 0,borderLeft:G?"2px dashed var(--archik-accent)":void 0,paddingLeft:G?8:void 0},children:[P.jsxs("span",{style:{fontWeight:R?600:400,color:"var(--archik-fg)"},children:[j.name,G&&P.jsx("span",{style:{marginLeft:6,fontSize:10,fontWeight:500,color:"var(--archik-accent)",letterSpacing:"0.04em"},children:"(pending)"})]}),j.hasSuggestion&&!G&&P.jsx(bue,{}),P.jsx("span",{style:{flex:1,fontSize:10,fontFamily:"ui-monospace, monospace",color:"var(--archik-fg-muted)",textAlign:"right"},children:j.path})]},j.path)})]})})}function bue(){return P.jsx("span",{"aria-label":"pending suggestion",title:"Pending suggestion",style:{width:6,height:6,borderRadius:3,background:"var(--archik-accent)",flexShrink:0}})}function XXn({stack:h,onGoToFrame:g,suggestionsByPath:p}){return h.length<=1?null:P.jsx("nav",{"aria-label":"Architecture file navigation",style:{display:"flex",alignItems:"center",gap:6,fontSize:12,color:"var(--archik-fg-muted)"},children:h.map((v,T)=>{const M=T===h.length-1,j=v.archikFile!==null&&p!==void 0&&p.has(v.archikFile);return P.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[M?P.jsxs("span",{style:{color:"var(--archik-fg)",fontWeight:600,display:"inline-flex",alignItems:"center",gap:6},"aria-current":"page",children:[v.label,j&&P.jsx(bue,{})]}):P.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 ${v.label}`,children:[v.label,j&&P.jsx(bue,{})]}),!M&&P.jsx("span",{"aria-hidden":"true",style:{opacity:.5},children:"›"})]},`${T}-${v.archikFile??"root"}`)})})}const VXn="/architecture.archik.yaml",WXn="/architecture.archik.suggested.yaml",YXn="/__archik/accept-suggestion",QXn=1500,s7e={label:"main",docUrl:VXn,sidecarUrl:WXn,acceptUrl:YXn,archikFile:null};function w0n(h,g){const p=h.replace(/\.archik\.yaml$/,".archik.suggested.yaml"),v=encodeURIComponent(h),T=encodeURIComponent(p);return{label:g,docUrl:`/__archik/file?path=${v}`,sidecarUrl:`/__archik/file?path=${T}`,acceptUrl:`/__archik/file-accept?path=${v}`,archikFile:h}}function eVn(){if(typeof window>"u")return null;const h=new URLSearchParams(window.location.search).get("file");return h!==null&&h.length>0?h:null}function nVn(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 d1n(){const h=eVn();if(h===null)return[s7e];const p=(h.split("/").pop()??h).replace(/\.archik\.yaml$/i,"")||"main";return[w0n(h,p)]}function tVn(){const[h,g]=kt.useState({status:"loading"}),[p,v]=kt.useState(d1n),T=p[p.length-1],[M,j]=kt.useState([]),R=kt.useMemo(()=>new Set(M.filter(Nn=>Nn.hasSuggestion).map(Nn=>Nn.path)),[M]),G=kt.useMemo(()=>M.find(Nn=>Nn.isRoot)??null,[M]),J=T.archikFile===null?G?.path??null:T.archikFile,[oe,re]=kt.useState(void 0),[le,Ee]=kt.useState(void 0),[nn,ie]=kt.useState("idle"),[tn,vn]=kt.useState(null),[Dn,zn]=kt.useState(!1),[Kn,_t]=kt.useState(!1),[Jt,vt]=kt.useState({status:"none"}),[Ht,er]=kt.useState(!1),[eu,$c]=kt.useState([]),[Ii,Q]=kt.useState([]),kl=100,[jl,wn]=kt.useState(()=>yXn()),Ft=Nn=>{wn(Nn),kXn(Nn)},[ki,Lc]=kt.useState(()=>mXn()),pu=Nn=>{Lc(Nn),vXn(Nn)},Ke=kt.useMemo(()=>({...jXn(jl),viewMode:ki}),[jl,ki]),Wn=kt.useMemo(()=>h.status==="ready"?new Set(h.document.nodes.filter(Nn=>(Nn.seqFiles?.length??0)>0).map(Nn=>Nn.id)):new Set,[h]),ni=kt.useRef(!1),bi=kt.useRef(null),wr=kt.useRef(null),Qr=kt.useCallback(()=>wr.current,[]),Ur=kt.useRef(null),Rc=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),xf=oy(Nn=>Nn.clearSelection),u5=oy(Nn=>Nn.startConnect),gd=oy(Nn=>Nn.cancelConnect),y0=Rc.length>0?Rc.at(-1)??null:null,r7=kt.useMemo(()=>new Set(Rc.filter(Nn=>Nn.type==="node").map(Nn=>Nn.id)),[Rc]),ls=kt.useMemo(()=>new Set(Rc.filter(Nn=>Nn.type==="edge").map(Nn=>Nn.id)),[Rc]);kt.useEffect(()=>{const Nn=p[p.length-1];nVn(Nn.archikFile)},[p]),kt.useEffect(()=>{if(typeof window>"u")return;const Nn=()=>v(d1n());return window.addEventListener("popstate",Nn),()=>window.removeEventListener("popstate",Nn)},[]),kt.useEffect(()=>{let Nn=!1;bi.current="",ni.current=!1;const Nt=()=>{yZn(T.docUrl).then(({document:xi,text:Dr})=>{if(Nn||Dr===bi.current)return;bi.current=Dr,ni.current=!0,g({status:"ready",document:xi}),zn(!1),typeof window<"u"&&xi.name&&(window.document.title=`${xi.name} — Archik`),Ee(void 0),$c([]),Q([]);const Sl=new Set(xi.nodes.map(as=>as.id)),Ls=new Set(xi.edges.map(as=>as.id));oy.setState(as=>({selection:as.selection.filter(Lo=>Lo.type==="node"?Sl.has(Lo.id):Ls.has(Lo.id)),connectFrom:as.connectFrom!==null&&Sl.has(as.connectFrom)?as.connectFrom:null}))},xi=>{if(Nn)return;const Dr=xi instanceof Error?xi.message:String(xi);ni.current?Ee(Dr):g({status:"error",error:Dr})})};g({status:"loading"}),Nt();const Zi=t1n(Nt);return()=>{Nn=!0,Zi()}},[T.docUrl]),kt.useEffect(()=>()=>{Ur.current&&clearTimeout(Ur.current)},[]),kt.useEffect(()=>{let Nn=!1;const Nt=async()=>{try{const Dr=await fetch("/__archik/files",{cache:"no-store"});if(Nn||!Dr.ok)return;const Sl=await Dr.json();if(Nn)return;Array.isArray(Sl.files)&&j(Sl.files)}catch{}};Nt();const Zi=t1n(()=>{Nt()}),xi=i1n(()=>{Nt()});return()=>{Nn=!0,Zi(),xi()}},[]),kt.useEffect(()=>{if(h.status!=="ready")return;const Nn=h.document;let Nt=!1;const Zi=async()=>{if(J!==null&&M.length>0&&M.some(Dr=>Dr.path===J)&&!R.has(J)){vt({status:"none"});return}try{const Dr=await fetch(T.sidecarUrl,{cache:"no-store"});if(Nt)return;if(Dr.status===404){vt({status:"none"});return}if(!Dr.ok){vt({status:"error",message:`Sidecar fetch failed: HTTP ${Dr.status}`});return}const Sl=await Dr.text();let Ls;try{Ls=c0n(Sl)}catch(Lo){vt({status:"error",message:Lo instanceof Error?Lo.message:String(Lo)});return}const as=r7e(Nn,Ls);vt({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(Nt)return;vt({status:"error",message:Dr instanceof Error?Dr.message:String(Dr)})}};Zi();const xi=i1n(Zi);return()=>{Nt=!0,xi()}},[h,T.sidecarUrl,J,M,R]);const fs=kt.useCallback(async()=>{try{const Nn=await fetch(T.acceptUrl,{method:"POST"});if(!Nn.ok){const Nt=await Nn.text();vt({status:"error",message:`Accept failed: ${Nt||`HTTP ${Nn.status}`}`});return}vt({status:"none"}),er(!1)}catch(Nn){vt({status:"error",message:Nn instanceof Error?Nn.message:String(Nn)})}},[T.acceptUrl]),s5=kt.useCallback(async()=>{try{const Nn=await fetch(T.sidecarUrl,{method:"DELETE"});if(!Nn.ok&&Nn.status!==404){const Nt=await Nn.text();vt({status:"error",message:`Reject failed: ${Nt||`HTTP ${Nn.status}`}`});return}vt({status:"none"}),er(!1)}catch(Nn){vt({status:"error",message:Nn instanceof Error?Nn.message:String(Nn)})}},[T.sidecarUrl]),$s=kt.useCallback(()=>{er(Nn=>!Nn)},[]),o5=kt.useCallback(async()=>{let Nn=null;if(g(Zi=>(Zi.status==="ready"&&(Nn=Zi.document),Zi)),!Nn)return;const Nt=P7e(Nn);bi.current=Nt,ie("saving"),vn(null);try{await kZn(T.docUrl,Nn),ie("saved");let Zi=!1;g(xi=>(xi.status==="ready"&&xi.document===Nn&&(Zi=!0),xi)),Zi&&zn(!1),Ur.current&&clearTimeout(Ur.current),Ur.current=setTimeout(()=>ie("idle"),QXn)}catch(Zi){ie("error"),vn(Zi instanceof Error?Zi.message:String(Zi))}},[T.docUrl]),Mf=G?.path??null,dy=kt.useCallback((Nn,Nt)=>Mf===Nn?s7e:w0n(Nn,Nt),[Mf]),nv=kt.useCallback((Nn,Nt)=>Nn.archikFile===Nt?!0:Nn.archikFile===null&&Mf===Nt,[Mf]),c7=kt.useCallback((Nn,Nt)=>{v(Zi=>{const xi=Zi.findIndex(Dr=>nv(Dr,Nn));return xi>=0?xi===Zi.length-1?Zi:Zi.slice(0,xi+1):[...Zi,dy(Nn,Nt)]})},[dy,nv]),Dp=kt.useCallback((Nn,Nt)=>{v(Zi=>{const xi=Zi[Zi.length-1];return nv(xi,Nn)?Zi:[dy(Nn,Nt)]})},[dy,nv]),xT=kt.useCallback(Nn=>{v(Nt=>Nn<0||Nn>=Nt.length-1?Nt:Nt.slice(0,Nn+1))},[]),u7=kt.useCallback(Nn=>{Nn.isRoot?v([s7e]):Dp(Nn.path,Nn.name)},[Dp]),MT=kt.useCallback((Nn,Nt)=>{if(vc===null){Nt&&(Nt.metaKey||Nt.ctrlKey||Nt.shiftKey)?hy(Nn):Fh(Nn);return}if(Nn===vc){gd();return}let Zi=null;g(xi=>{if(xi.status!=="ready"||!xi.document.nodes.find(Lo=>Lo.id===vc))return xi;const Sl=new Set(xi.document.edges.map(Lo=>Lo.id)),Ls=N8e(_8e(`${vc}-${Nn}`),Sl,"edge"),as={id:Ls,from:vc,to:Nn,relationship:"http_call"};try{const Lo=nI(xi.document,{type:"connect",edge:as});return re(void 0),zn(!0),$c(Cf=>[...Cf.slice(-(kl-1)),xi.document]),Q([]),Zi=Ls,{status:"ready",document:Lo}}catch(Lo){const Cf=Lo instanceof Error?Lo.message:String(Lo);return re(Cf),xi}}),gd(),Zi&&E1(Zi)},[vc,gd,Fh,hy,E1]),CT=kt.useCallback((Nn,Nt)=>{Nt&&(Nt.metaKey||Nt.ctrlKey||Nt.shiftKey)?c5(Nn):E1(Nn)},[E1,c5]),tv=kt.useCallback((Nn,Nt)=>{let Zi=null;g(xi=>{if(xi.status!=="ready")return xi;const Dr=xi.document.nodes.find(Cf=>Cf.id===Nn),Sl=xi.document.nodes.find(Cf=>Cf.id===Nt);if(!Dr||!Sl)return xi;const Ls=new Set(xi.document.edges.map(Cf=>Cf.id)),as=N8e(_8e(`${Nn}-${Nt}`),Ls,"edge"),Lo={id:as,from:Nn,to:Nt,relationship:"http_call"};try{const Cf=nI(xi.document,{type:"connect",edge:Lo});return re(void 0),zn(!0),$c(A1=>[...A1.slice(-(kl-1)),xi.document]),Q([]),Zi=as,{status:"ready",document:Cf}}catch(Cf){const A1=Cf instanceof Error?Cf.message:String(Cf);return re(A1),xi}}),Zi&&E1(Zi)},[E1]),oh=kt.useCallback((Nn,Nt,Zi)=>{g(xi=>{if(xi.status!=="ready")return xi;const Dr=new Set(xi.document.nodes.map(Ls=>Ls.id)),Sl=N8e(_8e(Nt),Dr,Nn);try{const Ls=nI(xi.document,{type:"add_node",node:{id:Sl,kind:Nn,name:Nt,description:Zi}});return re(void 0),zn(!0),$c(as=>[...as.slice(-(kl-1)),xi.document]),Q([]),{status:"ready",document:Ls}}catch(Ls){const as=Ls instanceof Error?Ls.message:String(Ls);return re(as),xi}})},[]),k0=kt.useCallback(Nn=>{g(Nt=>{if(Nt.status!=="ready")return Nt;try{const Zi=nI(Nt.document,Nn);return re(void 0),zn(!0),$c(xi=>[...xi.slice(-(kl-1)),Nt.document]),Q([]),{status:"ready",document:Zi}}catch(Zi){const xi=Zi instanceof Error?Zi.message:String(Zi);return re(xi),Nt}})},[]),la=kt.useCallback(()=>{Rc.length!==0&&(g(Nn=>{if(Nn.status!=="ready")return Nn;let Nt=Nn.document;try{const Zi=Rc.filter(Dr=>Dr.type==="edge").map(Dr=>Dr.id);for(const Dr of Zi)Nt.edges.some(Sl=>Sl.id===Dr)&&(Nt=nI(Nt,{type:"disconnect",id:Dr}));const xi=Rc.filter(Dr=>Dr.type==="node").map(Dr=>Dr.id);for(const Dr of xi)Nt.nodes.some(Sl=>Sl.id===Dr)&&(Nt=nI(Nt,{type:"remove_node",id:Dr}));return Nt===Nn.document?Nn:(re(void 0),zn(!0),$c(Dr=>[...Dr.slice(-(kl-1)),Nn.document]),Q([]),{status:"ready",document:Nt})}catch(Zi){const xi=Zi instanceof Error?Zi.message:String(Zi);return re(xi),Nn}}),xf())},[Rc,xf]),l5=kt.useCallback(()=>{if(h.status!=="ready"||eu.length===0)return;const Nn=eu[eu.length-1];$c(Nt=>Nt.slice(0,-1)),Q(Nt=>[...Nt,h.document]),g({status:"ready",document:Nn}),zn(!0),re(void 0),xf()},[h,eu,xf]),by=kt.useCallback(()=>{if(h.status!=="ready"||Ii.length===0)return;const Nn=Ii[Ii.length-1];Q(Nt=>Nt.slice(0,-1)),$c(Nt=>[...Nt,h.document]),g({status:"ready",document:Nn}),zn(!0),re(void 0),xf()},[h,Ii,xf]);if(kt.useEffect(()=>{const Nn=Nt=>{if((Nt.metaKey||Nt.ctrlKey)&&Nt.key==="s"){Nt.preventDefault(),Dn&&o5();return}if((Nt.metaKey||Nt.ctrlKey)&&(Nt.key==="z"||Nt.key==="Z")){Nt.preventDefault(),Nt.shiftKey?by():l5();return}if((Nt.metaKey||Nt.ctrlKey)&&Nt.key==="y"){Nt.preventDefault(),by();return}if(Nt.key==="Escape"){vc&&gd();return}if(Nt.key==="Delete"||Nt.key==="Backspace"){const Zi=Nt.target;if(Zi instanceof HTMLInputElement||Zi instanceof HTMLTextAreaElement||Zi instanceof HTMLSelectElement||Zi instanceof HTMLElement&&Zi.isContentEditable||Rc.length===0)return;Nt.preventDefault(),la()}};return window.addEventListener("keydown",Nn),()=>window.removeEventListener("keydown",Nn)},[Dn,o5,vc,gd,Rc,la,l5,by]),h.status==="loading")return P.jsxs(b1n,{children:["Loading ",T.docUrl,"…"]});if(h.status==="error")return P.jsx(b1n,{children:P.jsx("pre",{className:"max-w-3xl whitespace-pre-wrap text-xs text-rose-700",children:h.error})});const iv=h.document,Ob=Ht&&Jt.status==="pending",gy=Ob&&Jt.status==="pending"?CZn(iv,Jt.doc):null,rv=Ob&&Jt.status==="pending"?l0n(r7e(iv,Jt.doc)):null,wd=gy??iv,wy=y0?.type==="node"?wd.nodes.find(Nn=>Nn.id===y0.id):void 0,cv=y0?.type==="edge"?wd.edges.find(Nn=>Nn.id===y0.id):void 0,s7=vc!==null?iv.nodes.find(Nn=>Nn.id===vc):void 0,f5=Rc.length>1;return P.jsxs("div",{className:"flex h-full flex-col",style:{background:"var(--archik-canvas)",color:"var(--archik-fg)"},children:[P.jsx(HXn,{document:iv,commandError:oe,saveStatus:nn,...tn!==null?{saveError:tn}:{},isDirty:Dn,onSave:()=>{o5()},onAddNode:oh,density:jl,onDensityChange:Ft,viewMode:ki,onViewModeChange:pu,canUndo:eu.length>0,canRedo:Ii.length>0,onUndo:l5,onRedo:by,getSvg:Qr,seqHighlight:Kn,onToggleSeqHighlight:()=>_t(Nn=>!Nn),seqNodeCount:Wn.size,...le!==void 0?{reloadError:le}:{},...s7!==void 0?{connectingFromName:s7.name,onCancelConnect:gd}:{}}),Jt.status==="pending"&&P.jsx(rVn,{added:Jt.added,removed:Jt.removed,changed:Jt.changed,note:Jt.note,reviewing:Ob,onReview:$s,onAccept:()=>{fs()},onReject:()=>{s5()}}),Jt.status==="error"&&P.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:[P.jsx("span",{style:{fontWeight:700},children:"SUGGESTION ERROR —"}),P.jsx("span",{style:{flex:1,color:"var(--archik-fg)"},children:Jt.message}),P.jsx("button",{type:"button",onClick:()=>vt({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&&P.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:[P.jsx("span",{style:{fontWeight:700,letterSpacing:"0.04em"},children:"FILE INVALID —"}),P.jsx("pre",{style:{margin:0,flex:1,whiteSpace:"pre-wrap",fontFamily:"inherit",color:"var(--archik-fg)"},children:le}),P.jsx("button",{type:"button",onClick:()=>Ee(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:"×"})]}),P.jsxs("main",{className:"flex min-h-0 flex-1 p-4",style:{gap:0},children:[P.jsx("div",{className:"archik-panel",style:{flex:1,minWidth:0,overflow:"hidden"},children:P.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",width:"100%"},children:[(M.length>1||p.length>1)&&P.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 10px",background:"var(--archik-surface)",borderBottom:"1px solid var(--archik-border)"},children:[P.jsx(ZXn,{files:M,currentPath:J,onSwitchFile:u7}),P.jsx(XXn,{stack:p,onGoToFrame:xT,suggestionsByPath:R})]}),P.jsx(yqn,{document:wd,className:"flex-1 archik-grid",layoutOptions:Ke,viewMode:ki,selectedNodeIds:r7,selectedEdgeIds:ls,onSelectNode:MT,onSelectEdge:CT,onSelectNothing:vc===null?xf:gd,onConnectDrag:tv,onOpenSubFile:c7,onCrossFileNavigate:Dp,viewKey:T.docUrl,svgRef:wr,...rv?{diffStatuses:rv}:{},...Kn&&Wn.size>0?{glowNodeIds:Wn}:{}})]})}),P.jsx("aside",{"aria-hidden":Rc.length===0,className:`archik-drawer-shell ${Rc.length>0?"archik-drawer-shell--open":"archik-drawer-shell--closed"}`,children:P.jsx("div",{className:"archik-panel archik-drawer-content archik-drawer-fade",style:{overflow:"hidden"},children:f5?P.jsx(iVn,{count:Rc.length,onDelete:la,onClear:xf}):y0?.type==="edge"?P.jsx(ZZn,{edge:cv,dispatch:k0,readOnly:Ob}):y0?.type==="node"?P.jsx(qZn,{node:wy,dispatch:k0,onStartConnect:u5,allNodes:wd.nodes,readOnly:Ob,viewKey:T.archikFile??void 0}):null},f5?`multi:${Rc.length}`:y0?`${y0.type}:${y0.id}`:"empty")})]})]})}function iVn({count:h,onDelete:g,onClear:p}){return P.jsxs("div",{className:"flex h-full flex-col gap-4 overflow-y-auto p-4 text-sm",children:[P.jsxs("div",{children:[P.jsx("div",{className:"archik-label",children:"Selection"}),P.jsxs("div",{style:{fontSize:18,fontWeight:600,color:"var(--archik-fg)",letterSpacing:"0.01em"},children:[h," items"]}),P.jsx("div",{style:{fontSize:11,color:"var(--archik-fg-dim)",marginTop:4},children:"Hold ⌘ / Ctrl while clicking to add or remove items."})]}),P.jsx("div",{className:"archik-divider"}),P.jsxs("div",{className:"mt-auto flex flex-col gap-2 pt-4",children:[P.jsx("button",{type:"button",onClick:p,className:"archik-btn",style:{justifyContent:"center",padding:"8px 12px"},children:"Clear selection"}),P.jsxs("button",{type:"button",onClick:g,className:"archik-btn archik-btn-danger",style:{justifyContent:"center",padding:"8px 12px"},children:["Delete ",h," items"]})]})]})}function b1n({children:h}){return P.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 rVn({added:h,removed:g,changed:p,note:v,reviewing:T,onReview:M,onAccept:j,onReject:R}){const G=h+g+p;return P.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:[P.jsx("span",{style:{fontWeight:700,letterSpacing:"0.04em",color:"#c4b5fd"},children:"📝 SUGGESTION PENDING"}),P.jsxs("span",{style:{color:"var(--archik-fg)"},children:[G===0?"(identical to current — nothing to apply)":P.jsxs(P.Fragment,{children:[P.jsxs("span",{style:{color:"var(--archik-success)"},children:["+",h]})," ",P.jsxs("span",{style:{color:"var(--archik-danger)"},children:["−",g]})," ",P.jsxs("span",{style:{color:"var(--archik-warning)"},children:["~",p]})]}),v?P.jsxs("span",{style:{marginLeft:10,color:"var(--archik-fg-dim)",fontStyle:"italic"},children:['"',v,'"']}):null]}),P.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:8},children:[P.jsx("button",{type:"button",onClick:M,className:"archik-btn",style:{padding:"5px 12px",fontSize:12,...T?{background:"#a855f7",color:"white",borderColor:"#a855f7"}:{}},children:T?"Hide diff":"Review"}),P.jsx("button",{type:"button",onClick:j,className:"archik-btn",title:G===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"}),P.jsx("button",{type:"button",onClick:R,className:"archik-btn",style:{padding:"5px 12px",fontSize:12,color:"var(--archik-danger)",borderColor:"var(--archik-danger)"},children:"Reject"})]})]})}const cVn=i7(["sync","async","return","create","destroy"]),uVn=i7(["over","left_of","right_of"]),sVn=i7(["alt","opt","loop","par","break","ref"]),oVn=Xg({id:bd,nodeId:bd,label:os().min(1).optional(),status:xI.optional()}),lVn=Xg({type:uJ("message"),id:bd,from:bd,to:bd,label:os().min(1),arrow:cVn,activate:OKn().optional(),status:xI.optional()}),fVn=Xg({type:uJ("note"),id:bd,position:uVn,participants:Kg(bd).min(1),text:os().min(1),status:xI.optional()}),aVn=L7e(()=>Xg({label:os().optional(),steps:Kg(p0n)})),hVn=L7e(()=>Xg({type:uJ("group"),id:bd,kind:sVn,condition:os().optional(),label:os().optional(),branches:Kg(aVn).optional(),seqFile:n0n.optional(),participants:Kg(bd).optional(),status:xI.optional()})),p0n=L7e(()=>Wdn([lVn,fVn,hVn]));function m0n(h,g){const p=[];for(const v of h)if(g.has(v.id)?p.push(v.id):g.add(v.id),v.type==="group"&&v.branches)for(const T of v.branches)p.push(...m0n(T.steps,g));return p}const dVn=Xg({useCase:bd,slice:bd}),bVn=Xg({version:uJ("1.0"),name:os().min(1),description:os().optional(),realizes:dVn.optional(),participants:Kg(oVn).min(1),steps:Kg(p0n)}).superRefine((h,g)=>{const p=new Set;for(let M=0;M<h.participants.length;M++){const j=h.participants[M];p.has(j.id)&&g.addIssue({code:xb.custom,path:["participants",M,"id"],message:`duplicate participant id "${j.id}"`}),p.add(j.id)}const v=new Set,T=m0n(h.steps,v);for(const M of T)g.addIssue({code:xb.custom,path:["steps"],message:`duplicate step id "${M}"`})}),sJ=56,gVn=160,wVn=40,o7e=56,pVn=24,L8e=12,g1n=64,Qce=32,w1n=24,p1n=8,v0n="seq-arrow-filled",y0n="seq-arrow-open";function mVn(h){return Math.max(gVn,h.length*8+wVn*2)}function k0n(h,g,p,v,T){let M=p;const j=[];for(const R of h)if(R.type==="message"){const G=g.get(R.from),J=g.get(R.to),oe=G?.cx??v,re=J?.cx??v;j.push({type:"message",id:R.id,fromCx:oe,toCx:re,y:M,label:R.label,arrow:R.arrow,activate:R.activate??!1,isSelf:R.from===R.to,...R.status!==void 0?{status:R.status}:{}}),M+=R.from===R.to?o7e*1.5:o7e}else if(R.type==="note"){const G=R.participants.map(Ee=>g.get(Ee)?.cx).filter(Ee=>Ee!==void 0).sort((Ee,nn)=>Ee-nn),J=G[0]??v,oe=G[G.length-1]??T,re=Math.min(Math.max(R.text.length*7.5+24,oe-J+16,80),400);let le;R.position==="left_of"?le=J-re-8:R.position==="right_of"?le=oe+8:le=(J+oe)/2-re/2,le=Math.max(0,le),j.push({type:"note",id:R.id,x:le,y:M,width:re,height:g1n,text:R.text,...R.status!==void 0?{status:R.status}:{}}),M+=g1n+8}else if(R.type==="group"){M+=8;const G=v-L8e,J=T-v+L8e*2,oe=M;M+=pVn;const re=[];if(R.branches)for(let le=0;le<R.branches.length;le++){const Ee=R.branches[le],nn=M,{items:ie,endY:tn}=k0n(Ee.steps,g,M,v,T);M=tn,re.push({...Ee.label!==void 0?{label:Ee.label}:{},startY:nn,...le<R.branches.length-1?{dividerY:M}:{},steps:ie}),le<R.branches.length-1&&(M+=4)}M+=L8e,j.push({type:"group",id:R.id,kind:R.kind,...R.condition!==void 0?{condition:R.condition}:{},...R.label!==void 0?{label:R.label}:{},...R.seqFile!==void 0?{seqFile:R.seqFile}:{},x:G,y:oe,width:J,height:M-oe,branches:re,...R.status!==void 0?{status:R.status}:{}})}return{items:j,endY:M}}function j0n(h){const g=new Map;for(const p of h)if(p.type==="message"&&p.arrow==="destroy"&&g.set(p.toCx,p.y+sJ+20),p.type==="group")for(const v of p.branches)for(const[T,M]of j0n(v.steps))g.set(T,M);return g}function vVn(h){const g=[],p=new Map;function v(T){for(const M of T)if(M.type==="message"){if(M.activate&&M.arrow==="sync"&&!M.isSelf){const j=p.get(M.toCx)??[];j.push(M.y),p.set(M.toCx,j)}if(M.arrow==="return"&&!M.isSelf){const j=p.get(M.fromCx);if(j&&j.length>0){const R=j.pop();g.push({cx:M.fromCx,startY:R,endY:M.y}),j.length===0&&p.delete(M.fromCx)}}}else if(M.type==="group")for(const j of M.branches)v(j.steps)}v(h);for(const[T,M]of p)for(const j of M)g.push({cx:T,startY:j,endY:j+o7e/2});return g}function yVn(h,g){const p=h.participants.map(tn=>mVn(tn.label??tn.nodeId));let v=Qce;const T=h.participants.map((tn,vn)=>{const Dn=p[vn],zn=v+Dn/2;v+=Dn;const Kn=g?.get(tn.nodeId);return{id:tn.id,nodeId:tn.nodeId,label:tn.label??tn.nodeId,cx:zn,colWidth:Dn,...Kn!==void 0?{kind:Kn}:{},...tn.status!==void 0?{status:tn.status}:{},lifelineEndY:0}}),M=v+Qce,j=new Map(T.map(tn=>[tn.id,tn])),R=T[0]?.cx??Qce,G=T[T.length-1]?.cx??M-Qce,J=w1n,{items:oe,endY:re}=k0n(h.steps,j,J,R,G),le=sJ+re+w1n,Ee=j0n(oe),nn=T.map(tn=>({...tn,lifelineEndY:Ee.get(tn.cx)??le})),ie=vVn(oe);return{participants:nn,steps:oe,activations:ie,totalWidth:M,totalHeight:le}}const eue=36,kVn=128,jVn=7,m1n=20,v1n=24;function SVn({participant:h,nodeKind:g}){const p=g?Qm[g]:void 0,v=p?.color??"var(--archik-fg-muted)",T=(sJ-eue)/2,M=p?.icon,j=Math.max(kVn,h.label.length*jVn+v1n+(M?m1n:0)),R=j/2,G=M?R+m1n/2:R,J=h.status,oe=J==="proposed"?.55:J==="deprecated"?.35:1,re=J==="proposed"||J==="deprecated"?"4 3":void 0;return P.jsxs("g",{transform:`translate(${h.cx-R}, ${T})`,opacity:oe,children:[P.jsx("rect",{width:j,height:eue,rx:8,fill:"var(--archik-node-fill)",stroke:v,strokeWidth:1.4,...re!==void 0?{strokeDasharray:re}:{}}),M&&P.jsx("g",{transform:`translate(${v1n/2}, ${(eue-14)/2})`,children:P.jsx(M,{size:14,color:v,strokeWidth:1.5})}),P.jsx("text",{x:G,y:eue/2+4,textAnchor:"middle",fontSize:12,fontWeight:500,fill:"var(--archik-fg)",fontFamily:"inherit",children:h.label})]})}function EVn({participant:h}){const g=h.status,p=g==="proposed"?.3:g==="deprecated"?.2:.5;return P.jsx("line",{x1:h.cx,y1:sJ,x2:h.cx,y2:h.lifelineEndY,stroke:"var(--archik-node-stroke)",strokeWidth:1,strokeDasharray:"4 4",opacity:p})}const R8e=32,P8e=20,AVn=-6;function TVn({msg:h}){const g=h.arrow==="return",p=h.arrow==="async",v=h.arrow==="create",T=g||v,M=h.arrow==="destroy",j=g||p?y0n:v0n,R=h.status==="proposed"?.5:h.status==="deprecated"?.35:1;if(h.isSelf){const re=h.fromCx,le=h.y,Ee=`M ${re} ${le} L ${re+R8e} ${le} L ${re+R8e} ${le+P8e} L ${re} ${le+P8e}`;return P.jsxs("g",{opacity:R,children:[P.jsx("path",{d:Ee,fill:"none",stroke:"var(--archik-edge-filled)",strokeWidth:1.4,markerEnd:`url(#${j})`}),P.jsx("text",{x:re+R8e+6,y:le+P8e/2+4,fontSize:11,fill:"var(--archik-fg)",fontFamily:"inherit",children:h.label})]})}const J=h.fromCx<h.toCx?h.toCx-6:h.toCx+6,oe=(h.fromCx+h.toCx)/2;return P.jsxs("g",{opacity:R,children:[P.jsx("line",{x1:h.fromCx,y1:h.y,x2:J,y2:h.y,stroke:"var(--archik-edge-filled)",strokeWidth:1.4,strokeDasharray:T?"4 4":void 0,markerEnd:M?void 0:`url(#${j})`}),P.jsxs("text",{x:oe,y:h.y+AVn,textAnchor:"middle",fontSize:11,fill:"var(--archik-fg)",fontFamily:"inherit",children:[v&&"«create» ",h.label]}),h.arrow==="destroy"&&P.jsxs("g",{transform:`translate(${h.toCx-6}, ${h.y-6})`,children:[P.jsx("line",{x1:0,y1:0,x2:12,y2:12,stroke:"var(--archik-fg-muted)",strokeWidth:1.5}),P.jsx("line",{x1:12,y1:0,x2:0,y2:12,stroke:"var(--archik-fg-muted)",strokeWidth:1.5})]})]})}const xVn={alt:"#6366f1",opt:"#0ea5e9",loop:"#10b981",par:"#f59e0b",break:"#ef4444",ref:"#8b5cf6"},y1n=36,z8e=18;function MVn({group:h,renderStep:g,onRefClick:p}){const v=xVn[h.kind]??"var(--archik-fg-muted)",T=h.status==="proposed"?.55:h.status==="deprecated"?.35:1,M=h.kind==="ref"&&h.seqFile!==void 0&&p!==void 0;return P.jsxs("g",{opacity:T,onClick:M?()=>p(h.seqFile):void 0,style:M?{cursor:"pointer"}:void 0,children:[P.jsx("rect",{x:h.x,y:h.y,width:h.width,height:h.height,rx:4,fill:"none",stroke:v,strokeWidth:1.2,opacity:.6}),P.jsx("rect",{x:h.x,y:h.y,width:y1n,height:z8e,rx:4,fill:v,opacity:.8}),P.jsx("text",{x:h.x+6,y:h.y+z8e-5,fontSize:10,fontWeight:600,fill:"#fff",fontFamily:"inherit",children:h.kind}),(h.condition??h.label)&&P.jsx("text",{x:h.x+y1n+6,y:h.y+z8e-5,fontSize:10,fill:v,fontFamily:"inherit",children:h.condition??h.label}),h.branches.map((j,R)=>P.jsxs("g",{children:[j.label&&P.jsx("text",{x:h.x+6,y:j.startY+12,fontSize:10,fill:v,fontFamily:"inherit",children:j.label}),j.steps.map(G=>g(G)),j.dividerY!==void 0&&P.jsx("line",{x1:h.x,y1:j.dividerY,x2:h.x+h.width,y2:j.dividerY,stroke:v,strokeWidth:1,strokeDasharray:"4 2",opacity:.5})]},R))]})}const iI=10;function CVn(h,g){const p=Math.max(10,Math.floor(g/6.5));if(h.length<=p)return[h];const v=h.split(" "),T=[];let M="";for(const j of v)(M+(M?" ":"")+j).length>p&&M?(T.push(M),M=j):M=M?M+" "+j:j;return M&&T.push(M),T.slice(0,3)}function OVn({note:h}){const{x:g,y:p,width:v,height:T,text:M}=h,j=h.status==="proposed"?.55:h.status==="deprecated"?.35:1;return P.jsxs("g",{opacity:j,children:[P.jsx("path",{d:`M ${g} ${p} L ${g+v-iI} ${p} L ${g+v} ${p+iI} L ${g+v} ${p+T} L ${g} ${p+T} Z`,fill:"var(--archik-node-fill)",stroke:"var(--archik-node-stroke)",strokeWidth:1.2}),P.jsx("path",{d:`M ${g+v-iI} ${p} L ${g+v-iI} ${p+iI} L ${g+v} ${p+iI}`,fill:"none",stroke:"var(--archik-node-stroke)",strokeWidth:1.2}),CVn(M,v-16).map((R,G)=>P.jsx("text",{x:g+8,y:p+8+11+G*13,fontSize:11,fill:"var(--archik-fg)",fontFamily:"inherit",children:R},G))]})}function _Vn({id:h}){return P.jsx("marker",{id:h,viewBox:"0 0 10 10",refX:"10",refY:"5",markerWidth:"6",markerHeight:"6",orient:"auto-start-reverse",children:P.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"context-stroke"})})}function NVn({id:h}){return P.jsx("marker",{id:h,viewBox:"0 0 12 12",refX:"11",refY:"6",markerWidth:"7",markerHeight:"7",orient:"auto-start-reverse",children:P.jsx("path",{d:"M 1 1 L 11 6 L 1 11",fill:"none",stroke:"context-stroke",strokeWidth:"1.5",strokeLinejoin:"round"})})}function S0n({step:h,onRefClick:g}){return h.type==="message"?P.jsx(TVn,{msg:h}):h.type==="note"?P.jsx(OVn,{note:h}):h.type==="group"?P.jsx(MVn,{group:h,...g!==void 0?{onRefClick:g}:{},renderStep:p=>P.jsx(S0n,{step:p,...g!==void 0?{onRefClick:g}:{}},p.id)}):null}function IVn({laid:h,svgRef:g,onRefClick:p}){const{participants:v,steps:T,activations:M,totalWidth:j,totalHeight:R}=h;return P.jsxs("svg",{ref:g,width:j,height:R,viewBox:`0 0 ${j} ${R}`,xmlns:"http://www.w3.org/2000/svg",style:{fontFamily:"var(--archik-font, system-ui)"},children:[P.jsxs("defs",{children:[P.jsx(_Vn,{id:v0n}),P.jsx(NVn,{id:y0n})]}),v.map(G=>P.jsx(EVn,{participant:G},G.id)),v.map(G=>P.jsx(SVn,{participant:G,...G.kind!==void 0?{nodeKind:G.kind}:{}},G.id)),P.jsxs("g",{transform:`translate(0, ${sJ})`,children:[M.map(G=>P.jsx("rect",{x:G.cx-p1n/2,y:G.startY,width:p1n,height:G.endY-G.startY,fill:"var(--archik-node-fill)",stroke:"var(--archik-node-stroke)",strokeWidth:1,rx:2},`${G.cx}-${G.startY}`)),T.map(G=>P.jsx(S0n,{step:G,...p!==void 0?{onRefClick:p}:{}},G.id))]})]})}function DVn({path:h,back:g}){const[p,v]=kt.useState({status:"loading"}),[T,M]=kt.useState(void 0),j=kt.useRef(null);kt.useEffect(()=>{fetch("/__archik/node-kinds").then(le=>le.ok?le.json():null).then(le=>{le&&M(new Map(Object.entries(le)))}).catch(()=>{})},[]),kt.useEffect(()=>{v({status:"loading"});const le=encodeURIComponent(h);fetch(`/__archik/seq-file?path=${le}`).then(async Ee=>{if(!Ee.ok)throw new Error(`${Ee.status} ${Ee.statusText}`);return Ee.text()}).then(Ee=>{const nn=M7e.parse(Ee),ie=bVn.safeParse(nn);if(!ie.success)throw new Error(ie.error.issues.map(tn=>tn.message).join("; "));v({status:"ready",doc:ie.data})}).catch(Ee=>{v({status:"error",message:Ee instanceof Error?Ee.message:String(Ee)})})},[h]);const R=g?g.type==="usecase"?`/__archik/usecases?uc=${encodeURIComponent(g.value)}`:`/?file=${encodeURIComponent(g.value)}`:"/",G=g?.type==="usecase"?"Use cases":"Architecture";if(p.status==="loading")return P.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 P.jsxs("div",{className:"flex h-screen flex-col items-center justify-center gap-4",children:[P.jsx("div",{style:{color:"var(--archik-fg-error, #ef4444)"},children:p.message}),P.jsxs("a",{href:R,style:{color:"var(--archik-fg-muted)",fontSize:13},children:["← ",G]})]});const J=yVn(p.doc,T),oe=h.replace(/^.*\//,"").replace(/\.archik\.seq\.yaml$/,""),re=le=>{const Ee=new URLSearchParams;Ee.set("path",le),g?.type==="usecase"?Ee.set("from-uc",g.value):g?.type==="file"&&Ee.set("from-file",g.value),window.location.href=`/__archik/seq?${Ee.toString()}`};return P.jsxs("div",{className:"flex h-screen flex-col",style:{background:"var(--archik-bg)"},children:[P.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:[P.jsxs("a",{href:R,style:{color:"var(--archik-fg-muted)",fontSize:13,textDecoration:"none"},children:["← ",G]}),P.jsx("span",{style:{color:"var(--archik-node-stroke)"},children:"|"}),P.jsx("span",{style:{fontWeight:500,fontSize:14,color:"var(--archik-fg)"},children:p.doc.name}),P.jsx("div",{className:"ml-auto",children:P.jsx(h0n,{filename:oe,getSvg:()=>j.current})})]}),P.jsx("div",{className:"flex-1 overflow-auto p-6",children:P.jsx(IVn,{laid:J,svgRef:j,onRefClick:re})})]})}const $Vn="/__archik/usecases",LVn="/__archik/trace";async function k1n(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 RVn({selectedId:h}){const[g,p]=kt.useState({status:"loading"});return kt.useEffect(()=>{let v=!1;const T=new AbortController;return Promise.all([k1n($Vn,T.signal),k1n(LVn,T.signal)]).then(([M,j])=>{v||p({status:"ready",useCases:M.useCases??[],trace:j.rows??[]})}).catch(M=>{v||T.signal.aborted||p({status:"error",message:M instanceof Error?M.message:String(M)})}),()=>{v=!0,T.abort()}},[]),P.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100vh",background:"var(--archik-canvas)",color:"var(--archik-fg)",fontFamily:"Inter, system-ui, sans-serif"},children:[P.jsx(PVn,{state:g}),P.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[g.status==="loading"&&P.jsx(B8e,{children:"Loading…"}),g.status==="error"&&P.jsxs(B8e,{tone:"error",children:["Couldn't load: ",g.message]}),g.status==="ready"&&g.useCases.length===0&&P.jsxs(B8e,{children:["No use cases defined yet. Add a ",P.jsx("code",{children:"*.archik.uc.yaml"})," file under ",P.jsx("code",{children:".archik/usecases/"}),"."]}),g.status==="ready"&&g.useCases.length>0&&P.jsx(zVn,{useCases:g.useCases,trace:g.trace,selectedId:h})]})]})}function PVn({state:h}){const g=kt.useMemo(()=>{if(h.status!=="ready")return null;let p=0,v=0,T=0;for(const M of h.trace)M.level==="full"?p++:M.level==="partial"?v++:T++;return{full:p,partial:v,none:T,total:h.trace.length}},[h]);return P.jsxs("header",{style:{display:"flex",alignItems:"center",gap:16,padding:"0 20px",height:52,borderBottom:"1px solid var(--archik-border)",background:"var(--archik-panel)",flexShrink:0},children:[P.jsxs("a",{href:"/",style:{display:"inline-flex",alignItems:"center",gap:4,color:"var(--archik-fg-dim)",fontSize:13,textDecoration:"none"},children:[P.jsx(lBn,{size:14}),"Architecture"]}),P.jsx("span",{style:{color:"var(--archik-border-strong)"},children:"|"}),P.jsx("h1",{style:{fontSize:14,fontWeight:600,margin:0,color:"var(--archik-fg)"},children:"Use cases"}),g&&g.total>0&&P.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginLeft:"auto",fontSize:12,color:"var(--archik-fg-dim)"},children:[P.jsxs("span",{children:[P.jsx("span",{style:{color:"var(--archik-success)"},children:"●"})," ",g.full," full"]}),P.jsxs("span",{children:[P.jsx("span",{style:{color:"var(--archik-warning)"},children:"◐"})," ",g.partial," partial"]}),P.jsxs("span",{children:[P.jsx("span",{style:{color:"var(--archik-fg-muted)"},children:"○"})," ",g.none," untraced"]}),P.jsxs("span",{style:{color:"var(--archik-fg-muted)"},children:["· ",g.total," ",g.total===1?"slice":"slices"]})]})]})}function zVn({useCases:h,trace:g,selectedId:p}){const v=kt.useMemo(()=>{const j=new Map;for(const R of g){const G=j.get(R.useCase);if(!G){j.set(R.useCase,R.level);continue}G==="none"||R.level==="none"?j.set(R.useCase,"none"):(G==="partial"||R.level==="partial")&&j.set(R.useCase,"partial")}return j},[g]),T=kt.useMemo(()=>{const j=new Map;for(const R of g)j.set(`${R.useCase}/${R.slice}`,R);return j},[g]),M=h.find(j=>j.id===p)??h[0];return P.jsxs(P.Fragment,{children:[P.jsx(BVn,{useCases:h,ucLevel:v,selectedId:M.id}),P.jsx(FVn,{useCase:M,traceByKey:T})]})}function BVn({useCases:h,ucLevel:g,selectedId:p}){return P.jsx("nav",{"aria-label":"Use cases",style:{width:260,borderRight:"1px solid var(--archik-border)",background:"var(--archik-panel)",overflowY:"auto",padding:"8px 0",flexShrink:0},children:P.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:h.map(v=>{const T=g.get(v.id)??"none",M=v.id===p;return P.jsx("li",{children:P.jsxs("a",{href:`/__archik/usecases?uc=${encodeURIComponent(v.id)}`,style:{display:"flex",alignItems:"center",gap:8,padding:"8px 14px",textDecoration:"none",color:"var(--archik-fg)",background:M?"var(--archik-surface-hover)":"transparent",borderLeft:M?"2px solid var(--archik-accent)":"2px solid transparent",fontSize:13},children:[P.jsx(E0n,{level:T}),P.jsxs("span",{style:{flex:1,minWidth:0},children:[P.jsx("code",{style:{fontSize:12,fontFamily:"ui-monospace, monospace"},children:v.id}),P.jsx("div",{style:{fontSize:11,color:"var(--archik-fg-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:v.name})]}),v.status&&v.status!=="active"&&P.jsx("span",{style:{fontSize:9,padding:"1px 6px",borderRadius:4,background:"var(--archik-surface)",color:"var(--archik-fg-muted)"},children:v.status})]})},v.id)})})})}function E0n({level:h}){const g=h==="full"?{glyph:"●",color:"var(--archik-success)",label:"fully traced"}:h==="partial"?{glyph:"◐",color:"var(--archik-warning)",label:"partially traced"}:{glyph:"○",color:"var(--archik-fg-muted)",label:"untraced"};return P.jsx("span",{title:g.label,"aria-label":g.label,style:{color:g.color,fontSize:12,lineHeight:1,width:12},children:g.glyph})}function FVn({useCase:h,traceByKey:g}){return P.jsx("main",{style:{flex:1,overflowY:"auto",padding:"24px 32px"},children:P.jsxs("div",{style:{maxWidth:820,margin:"0 auto"},children:[P.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:12,marginBottom:4},children:[P.jsx("code",{style:{fontSize:18,fontFamily:"ui-monospace, monospace",fontWeight:600,color:"var(--archik-fg)"},children:h.id}),h.status&&h.status!=="active"&&P.jsx("span",{className:"archik-pill",style:{fontSize:10},children:h.status})]}),P.jsx("div",{style:{fontSize:15,color:"var(--archik-fg-dim)",marginBottom:18},children:h.name}),P.jsx(qVn,{useCase:h}),h.goal&&P.jsx(rI,{title:"Goal",children:P.jsx("p",{style:{margin:0,lineHeight:1.55},children:h.goal})}),(h.preconditions?.length??0)>0&&P.jsx(rI,{title:"Preconditions",children:P.jsx("ul",{style:WU,children:h.preconditions.map((p,v)=>P.jsx("li",{children:p},v))})}),h.flows?.basic?.steps&&P.jsx(rI,{title:"Basic flow",children:P.jsx("ol",{style:{...WU,paddingLeft:22},children:h.flows.basic.steps.map((p,v)=>P.jsx("li",{style:{marginBottom:4},children:p},v))})}),(h.flows?.alternates?.length??0)>0&&P.jsx(rI,{title:"Alternate flows",children:h.flows.alternates.map(p=>P.jsxs("div",{style:{marginBottom:12,padding:12,background:"var(--archik-surface)",borderRadius:6,borderLeft:"3px solid var(--archik-warning)"},children:[P.jsxs("div",{style:{display:"flex",gap:8,alignItems:"baseline",marginBottom:6},children:[P.jsx("code",{style:{fontSize:12,fontWeight:600},children:p.id}),p.branchFrom&&P.jsxs("span",{style:{fontSize:11,color:"var(--archik-fg-muted)"},children:["branches from ",p.branchFrom]})]}),P.jsx("ol",{style:{...WU,paddingLeft:22,fontSize:13},children:p.steps.map((v,T)=>P.jsx("li",{children:v},T))})]},p.id))}),(h.postconditions?.length??0)>0&&P.jsx(rI,{title:"Postconditions",children:P.jsx("ul",{style:WU,children:h.postconditions.map((p,v)=>P.jsx("li",{children:p},v))})}),P.jsx(rI,{title:`Slices (${h.slices.length})`,children:P.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:h.slices.map(p=>P.jsx(GVn,{slice:p,useCaseId:h.id,trace:g.get(`${h.id}/${p.id}`)},p.id))})}),P.jsxs("div",{style:{marginTop:32,paddingTop:16,borderTop:"1px solid var(--archik-border)",fontSize:11,color:"var(--archik-fg-muted)"},children:["Source:"," ",P.jsx("code",{style:{fontFamily:"ui-monospace, monospace"},children:h.relPath})]})]})})}function qVn({useCase:h}){return P.jsxs("div",{style:{display:"flex",gap:24,padding:"10px 14px",background:"var(--archik-surface)",borderRadius:6,marginBottom:20,fontSize:12},children:[P.jsxs("div",{children:[P.jsx("div",{style:l7e,children:"Primary actor"}),P.jsx("div",{style:{marginTop:2},children:P.jsx("code",{style:{fontFamily:"ui-monospace, monospace"},children:h.primaryActor})})]}),(h.secondaryActors?.length??0)>0&&P.jsxs("div",{children:[P.jsx("div",{style:l7e,children:"Secondary actors"}),P.jsx("div",{style:{marginTop:2},children:h.secondaryActors.map((g,p)=>P.jsxs("span",{children:[P.jsx("code",{style:{fontFamily:"ui-monospace, monospace"},children:g}),p<h.secondaryActors.length-1&&", "]},g))})]})]})}function GVn({slice:h,useCaseId:g,trace:p}){const v=p?.level??"none";return P.jsxs("div",{style:{padding:14,background:"var(--archik-panel)",border:"1px solid var(--archik-border)",borderRadius:8},children:[P.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:8,marginBottom:8},children:[P.jsx(E0n,{level:v}),P.jsx("code",{style:{fontSize:13,fontFamily:"ui-monospace, monospace",fontWeight:600},children:h.id}),h.status&&h.status!=="active"&&P.jsxs("span",{style:{fontSize:10,color:"var(--archik-fg-muted)"},children:["[",h.status,"]"]}),P.jsx("span",{style:{marginLeft:"auto",fontSize:11,color:"var(--archik-fg-muted)"},children:p?.ecbTotal!==void 0&&p.ecbTotal>0&&P.jsxs(P.Fragment,{children:["ECB ",p.ecbTagged??0,"/",p.ecbTotal]})})]}),h.description&&P.jsx("div",{style:{fontSize:13,color:"var(--archik-fg-dim)",marginBottom:10,lineHeight:1.5},children:h.description}),P.jsxs("div",{style:{display:"grid",gridTemplateColumns:"auto 1fr",columnGap:14,rowGap:8,fontSize:12,alignItems:"start"},children:[P.jsx("div",{style:F8e,children:"Tests"}),P.jsx("div",{children:(h.tests?.length??0)===0?P.jsx("span",{style:{color:"var(--archik-fg-muted)"},children:"— none declared"}):P.jsx("ul",{style:{...WU,paddingLeft:0,listStyle:"none"},children:h.tests.map(T=>P.jsxs("li",{style:{fontFamily:"ui-monospace, monospace",fontSize:11},children:[P.jsx("span",{style:{color:"var(--archik-fg-muted)"},children:"•"})," ",T]},T))})}),P.jsx("div",{style:F8e,children:"Realization"}),P.jsx("div",{children:h.realization?P.jsxs("a",{href:`/__archik/seq?path=${encodeURIComponent(h.realization.seqFile)}&from-uc=${encodeURIComponent(g)}`,style:{display:"inline-flex",alignItems:"center",gap:4,color:"var(--archik-accent)",textDecoration:"none",fontFamily:"ui-monospace, monospace",fontSize:11},children:[P.jsx(A1n,{size:11}),UVn(h.realization.seqFile),P.jsx(T1n,{size:11,style:{opacity:.7}})]}):P.jsx("span",{style:{color:"var(--archik-fg-muted)"},children:"— no seq file yet"})}),P.jsx("div",{style:F8e,children:"Flows"}),P.jsx("div",{style:{fontSize:11,color:"var(--archik-fg-dim)"},children:h.flows.join(", ")})]})]})}function UVn(h){return h.split("/").pop()?.replace(/\.archik\.seq\.yaml$/,"")??h}function rI({title:h,children:g}){return P.jsxs("section",{style:{marginBottom:24},children:[P.jsx("h2",{style:{fontSize:12,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",color:"var(--archik-fg-muted)",margin:"0 0 8px"},children:h}),g]})}function B8e({children:h,tone:g}){return P.jsx("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",color:g==="error"?"var(--archik-danger)":"var(--archik-fg-muted)",fontSize:13,padding:24,textAlign:"center"},children:h})}const l7e={fontSize:10,textTransform:"uppercase",letterSpacing:"0.06em",color:"var(--archik-fg-muted)",fontWeight:600},F8e={...l7e,fontSize:10,paddingTop:1},WU={margin:0,paddingLeft:18,fontSize:13,lineHeight:1.55},A0n=document.getElementById("root");if(!A0n)throw new Error("#root not found");const ZU=new URLSearchParams(window.location.search),gue=window.location.pathname,JVn=gue==="/__archik/seq"||gue.startsWith("/__archik/seq/"),HVn=gue==="/__archik/usecases"||gue.startsWith("/__archik/usecases/"),q8e=vzn.createRoot(A0n);if(JVn){const h=ZU.get("path")??"",g=ZU.get("from-uc"),p=ZU.get("from-file")??ZU.get("from"),v=g?{type:"usecase",value:g}:p?{type:"file",value:p}:null;q8e.render(P.jsx(kt.StrictMode,{children:P.jsx(DVn,{path:h,back:v})}))}else if(HVn){const h=ZU.get("uc");q8e.render(P.jsx(kt.StrictMode,{children:P.jsx(RVn,{selectedId:h})}))}else q8e.render(P.jsx(kt.StrictMode,{children:P.jsx(tVn,{})}));
226
+ `);return g===-1?h:h.slice(0,g)}function ZXn({files:h,currentPath:g,onSwitchFile:p}){const v=h.some(M=>M.hasSuggestion||M.isOrphanSuggestion);if(h.length<=1&&!v)return null;const T=h.find(M=>M.path===g)??h[0];return P.jsx(TT,{align:"start",trigger:M=>P.jsxs("button",{type:"button","aria-label":"Switch architecture file","aria-expanded":M,className:"archik-btn",style:{display:"flex",alignItems:"center",gap:6,padding:"4px 10px",fontSize:12,background:"transparent",color:"var(--archik-fg)"},children:[P.jsx(ABn,{size:13,strokeWidth:1.8}),P.jsx("span",{style:{fontWeight:600},children:T.name}),T.hasSuggestion&&P.jsx(bue,{}),P.jsx(x1n,{size:12,strokeWidth:2,style:{opacity:.6}})]}),children:M=>P.jsxs("div",{style:{minWidth:220,padding:4},children:[P.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 R=j.path===T.path,G=j.isOrphanSuggestion===!0;return P.jsxs("button",{type:"button",title:G?`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:()=>{M(),!R&&p(j)},className:"archik-menu-item",style:{display:"flex",alignItems:"center",gap:8,width:"100%",textAlign:"left",padding:"6px 10px",fontSize:12,background:R?"var(--archik-surface-hover)":void 0,borderLeft:G?"2px dashed var(--archik-accent)":void 0,paddingLeft:G?8:void 0},children:[P.jsxs("span",{style:{fontWeight:R?600:400,color:"var(--archik-fg)"},children:[j.name,G&&P.jsx("span",{style:{marginLeft:6,fontSize:10,fontWeight:500,color:"var(--archik-accent)",letterSpacing:"0.04em"},children:"(pending)"})]}),j.hasSuggestion&&!G&&P.jsx(bue,{}),P.jsx("span",{style:{flex:1,fontSize:10,fontFamily:"ui-monospace, monospace",color:"var(--archik-fg-muted)",textAlign:"right"},children:j.path})]},j.path)})]})})}function bue(){return P.jsx("span",{"aria-label":"pending suggestion",title:"Pending suggestion",style:{width:6,height:6,borderRadius:3,background:"var(--archik-accent)",flexShrink:0}})}function XXn({stack:h,onGoToFrame:g,suggestionsByPath:p}){return h.length<=1?null:P.jsx("nav",{"aria-label":"Architecture file navigation",style:{display:"flex",alignItems:"center",gap:6,fontSize:12,color:"var(--archik-fg-muted)"},children:h.map((v,T)=>{const M=T===h.length-1,j=v.archikFile!==null&&p!==void 0&&p.has(v.archikFile);return P.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[M?P.jsxs("span",{style:{color:"var(--archik-fg)",fontWeight:600,display:"inline-flex",alignItems:"center",gap:6},"aria-current":"page",children:[v.label,j&&P.jsx(bue,{})]}):P.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 ${v.label}`,children:[v.label,j&&P.jsx(bue,{})]}),!M&&P.jsx("span",{"aria-hidden":"true",style:{opacity:.5},children:"›"})]},`${T}-${v.archikFile??"root"}`)})})}const VXn="/architecture.archik.yaml",WXn="/architecture.archik.suggested.yaml",YXn="/__archik/accept-suggestion",QXn=1500,s7e={label:"main",docUrl:VXn,sidecarUrl:WXn,acceptUrl:YXn,archikFile:null};function w0n(h,g){const p=h.replace(/\.archik\.yaml$/,".archik.suggested.yaml"),v=encodeURIComponent(h),T=encodeURIComponent(p);return{label:g,docUrl:`/__archik/file?path=${v}`,sidecarUrl:`/__archik/file?path=${T}`,acceptUrl:`/__archik/file-accept?path=${v}`,archikFile:h}}function eVn(){if(typeof window>"u")return null;const h=new URLSearchParams(window.location.search).get("file");return h!==null&&h.length>0?h:null}function nVn(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 d1n(){const h=eVn();if(h===null)return[s7e];const p=(h.split("/").pop()??h).replace(/\.archik\.yaml$/i,"")||"main";return[w0n(h,p)]}function tVn(){const[h,g]=kt.useState({status:"loading"}),[p,v]=kt.useState(d1n),T=p[p.length-1],[M,j]=kt.useState([]),R=kt.useMemo(()=>new Set(M.filter(Nn=>Nn.hasSuggestion).map(Nn=>Nn.path)),[M]),G=kt.useMemo(()=>M.find(Nn=>Nn.isRoot)??null,[M]),J=T.archikFile===null?G?.path??null:T.archikFile,[oe,re]=kt.useState(void 0),[le,Ee]=kt.useState(void 0),[nn,ie]=kt.useState("idle"),[tn,vn]=kt.useState(null),[Dn,zn]=kt.useState(!1),[Kn,_t]=kt.useState(!1),[Jt,vt]=kt.useState({status:"none"}),[Ht,er]=kt.useState(!1),[eu,$c]=kt.useState([]),[Ii,Q]=kt.useState([]),kl=100,[jl,wn]=kt.useState(()=>yXn()),Ft=Nn=>{wn(Nn),kXn(Nn)},[ki,Lc]=kt.useState(()=>mXn()),pu=Nn=>{Lc(Nn),vXn(Nn)},Ke=kt.useMemo(()=>({...jXn(jl),viewMode:ki}),[jl,ki]),Wn=kt.useMemo(()=>h.status==="ready"?new Set(h.document.nodes.filter(Nn=>(Nn.seqFiles?.length??0)>0).map(Nn=>Nn.id)):new Set,[h]),ni=kt.useRef(!1),bi=kt.useRef(null),wr=kt.useRef(null),Qr=kt.useCallback(()=>wr.current,[]),Ur=kt.useRef(null),Rc=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),xf=oy(Nn=>Nn.clearSelection),u5=oy(Nn=>Nn.startConnect),gd=oy(Nn=>Nn.cancelConnect),y0=Rc.length>0?Rc.at(-1)??null:null,r7=kt.useMemo(()=>new Set(Rc.filter(Nn=>Nn.type==="node").map(Nn=>Nn.id)),[Rc]),ls=kt.useMemo(()=>new Set(Rc.filter(Nn=>Nn.type==="edge").map(Nn=>Nn.id)),[Rc]);kt.useEffect(()=>{const Nn=p[p.length-1];nVn(Nn.archikFile)},[p]),kt.useEffect(()=>{if(typeof window>"u")return;const Nn=()=>v(d1n());return window.addEventListener("popstate",Nn),()=>window.removeEventListener("popstate",Nn)},[]),kt.useEffect(()=>{let Nn=!1;bi.current="",ni.current=!1;const Nt=()=>{yZn(T.docUrl).then(({document:xi,text:Dr})=>{if(Nn||Dr===bi.current)return;bi.current=Dr,ni.current=!0,g({status:"ready",document:xi}),zn(!1),typeof window<"u"&&xi.name&&(window.document.title=`${xi.name} — Archik`),Ee(void 0),$c([]),Q([]);const Sl=new Set(xi.nodes.map(as=>as.id)),Ls=new Set(xi.edges.map(as=>as.id));oy.setState(as=>({selection:as.selection.filter(Lo=>Lo.type==="node"?Sl.has(Lo.id):Ls.has(Lo.id)),connectFrom:as.connectFrom!==null&&Sl.has(as.connectFrom)?as.connectFrom:null}))},xi=>{if(Nn)return;const Dr=xi instanceof Error?xi.message:String(xi);ni.current?Ee(Dr):g({status:"error",error:Dr})})};g({status:"loading"}),Nt();const Zi=t1n(Nt);return()=>{Nn=!0,Zi()}},[T.docUrl]),kt.useEffect(()=>()=>{Ur.current&&clearTimeout(Ur.current)},[]),kt.useEffect(()=>{let Nn=!1;const Nt=async()=>{try{const Dr=await fetch("/__archik/files",{cache:"no-store"});if(Nn||!Dr.ok)return;const Sl=await Dr.json();if(Nn)return;Array.isArray(Sl.files)&&j(Sl.files)}catch{}};Nt();const Zi=t1n(()=>{Nt()}),xi=i1n(()=>{Nt()});return()=>{Nn=!0,Zi(),xi()}},[]),kt.useEffect(()=>{if(h.status!=="ready")return;const Nn=h.document;let Nt=!1;const Zi=async()=>{if(J!==null&&M.length>0&&M.some(Dr=>Dr.path===J)&&!R.has(J)){vt({status:"none"});return}try{const Dr=await fetch(T.sidecarUrl,{cache:"no-store"});if(Nt)return;if(Dr.status===404){vt({status:"none"});return}if(!Dr.ok){vt({status:"error",message:`Sidecar fetch failed: HTTP ${Dr.status}`});return}const Sl=await Dr.text();let Ls;try{Ls=c0n(Sl)}catch(Lo){vt({status:"error",message:Lo instanceof Error?Lo.message:String(Lo)});return}const as=r7e(Nn,Ls);vt({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(Nt)return;vt({status:"error",message:Dr instanceof Error?Dr.message:String(Dr)})}};Zi();const xi=i1n(Zi);return()=>{Nt=!0,xi()}},[h,T.sidecarUrl,J,M,R]);const fs=kt.useCallback(async()=>{try{const Nn=await fetch(T.acceptUrl,{method:"POST"});if(!Nn.ok){const Nt=await Nn.text();vt({status:"error",message:`Accept failed: ${Nt||`HTTP ${Nn.status}`}`});return}vt({status:"none"}),er(!1)}catch(Nn){vt({status:"error",message:Nn instanceof Error?Nn.message:String(Nn)})}},[T.acceptUrl]),s5=kt.useCallback(async()=>{try{const Nn=await fetch(T.sidecarUrl,{method:"DELETE"});if(!Nn.ok&&Nn.status!==404){const Nt=await Nn.text();vt({status:"error",message:`Reject failed: ${Nt||`HTTP ${Nn.status}`}`});return}vt({status:"none"}),er(!1)}catch(Nn){vt({status:"error",message:Nn instanceof Error?Nn.message:String(Nn)})}},[T.sidecarUrl]),$s=kt.useCallback(()=>{er(Nn=>!Nn)},[]),o5=kt.useCallback(async()=>{let Nn=null;if(g(Zi=>(Zi.status==="ready"&&(Nn=Zi.document),Zi)),!Nn)return;const Nt=P7e(Nn);bi.current=Nt,ie("saving"),vn(null);try{await kZn(T.docUrl,Nn),ie("saved");let Zi=!1;g(xi=>(xi.status==="ready"&&xi.document===Nn&&(Zi=!0),xi)),Zi&&zn(!1),Ur.current&&clearTimeout(Ur.current),Ur.current=setTimeout(()=>ie("idle"),QXn)}catch(Zi){ie("error"),vn(Zi instanceof Error?Zi.message:String(Zi))}},[T.docUrl]),Mf=G?.path??null,dy=kt.useCallback((Nn,Nt)=>Mf===Nn?s7e:w0n(Nn,Nt),[Mf]),nv=kt.useCallback((Nn,Nt)=>Nn.archikFile===Nt?!0:Nn.archikFile===null&&Mf===Nt,[Mf]),c7=kt.useCallback((Nn,Nt)=>{v(Zi=>{const xi=Zi.findIndex(Dr=>nv(Dr,Nn));return xi>=0?xi===Zi.length-1?Zi:Zi.slice(0,xi+1):[...Zi,dy(Nn,Nt)]})},[dy,nv]),Dp=kt.useCallback((Nn,Nt)=>{v(Zi=>{const xi=Zi[Zi.length-1];return nv(xi,Nn)?Zi:[dy(Nn,Nt)]})},[dy,nv]),xT=kt.useCallback(Nn=>{v(Nt=>Nn<0||Nn>=Nt.length-1?Nt:Nt.slice(0,Nn+1))},[]),u7=kt.useCallback(Nn=>{Nn.isRoot?v([s7e]):Dp(Nn.path,Nn.name)},[Dp]),MT=kt.useCallback((Nn,Nt)=>{if(vc===null){Nt&&(Nt.metaKey||Nt.ctrlKey||Nt.shiftKey)?hy(Nn):Fh(Nn);return}if(Nn===vc){gd();return}let Zi=null;g(xi=>{if(xi.status!=="ready"||!xi.document.nodes.find(Lo=>Lo.id===vc))return xi;const Sl=new Set(xi.document.edges.map(Lo=>Lo.id)),Ls=N8e(_8e(`${vc}-${Nn}`),Sl,"edge"),as={id:Ls,from:vc,to:Nn,relationship:"http_call"};try{const Lo=nI(xi.document,{type:"connect",edge:as});return re(void 0),zn(!0),$c(Cf=>[...Cf.slice(-(kl-1)),xi.document]),Q([]),Zi=Ls,{status:"ready",document:Lo}}catch(Lo){const Cf=Lo instanceof Error?Lo.message:String(Lo);return re(Cf),xi}}),gd(),Zi&&E1(Zi)},[vc,gd,Fh,hy,E1]),CT=kt.useCallback((Nn,Nt)=>{Nt&&(Nt.metaKey||Nt.ctrlKey||Nt.shiftKey)?c5(Nn):E1(Nn)},[E1,c5]),tv=kt.useCallback((Nn,Nt)=>{let Zi=null;g(xi=>{if(xi.status!=="ready")return xi;const Dr=xi.document.nodes.find(Cf=>Cf.id===Nn),Sl=xi.document.nodes.find(Cf=>Cf.id===Nt);if(!Dr||!Sl)return xi;const Ls=new Set(xi.document.edges.map(Cf=>Cf.id)),as=N8e(_8e(`${Nn}-${Nt}`),Ls,"edge"),Lo={id:as,from:Nn,to:Nt,relationship:"http_call"};try{const Cf=nI(xi.document,{type:"connect",edge:Lo});return re(void 0),zn(!0),$c(A1=>[...A1.slice(-(kl-1)),xi.document]),Q([]),Zi=as,{status:"ready",document:Cf}}catch(Cf){const A1=Cf instanceof Error?Cf.message:String(Cf);return re(A1),xi}}),Zi&&E1(Zi)},[E1]),oh=kt.useCallback((Nn,Nt,Zi)=>{g(xi=>{if(xi.status!=="ready")return xi;const Dr=new Set(xi.document.nodes.map(Ls=>Ls.id)),Sl=N8e(_8e(Nt),Dr,Nn);try{const Ls=nI(xi.document,{type:"add_node",node:{id:Sl,kind:Nn,name:Nt,description:Zi}});return re(void 0),zn(!0),$c(as=>[...as.slice(-(kl-1)),xi.document]),Q([]),{status:"ready",document:Ls}}catch(Ls){const as=Ls instanceof Error?Ls.message:String(Ls);return re(as),xi}})},[]),k0=kt.useCallback(Nn=>{g(Nt=>{if(Nt.status!=="ready")return Nt;try{const Zi=nI(Nt.document,Nn);return re(void 0),zn(!0),$c(xi=>[...xi.slice(-(kl-1)),Nt.document]),Q([]),{status:"ready",document:Zi}}catch(Zi){const xi=Zi instanceof Error?Zi.message:String(Zi);return re(xi),Nt}})},[]),la=kt.useCallback(()=>{Rc.length!==0&&(g(Nn=>{if(Nn.status!=="ready")return Nn;let Nt=Nn.document;try{const Zi=Rc.filter(Dr=>Dr.type==="edge").map(Dr=>Dr.id);for(const Dr of Zi)Nt.edges.some(Sl=>Sl.id===Dr)&&(Nt=nI(Nt,{type:"disconnect",id:Dr}));const xi=Rc.filter(Dr=>Dr.type==="node").map(Dr=>Dr.id);for(const Dr of xi)Nt.nodes.some(Sl=>Sl.id===Dr)&&(Nt=nI(Nt,{type:"remove_node",id:Dr}));return Nt===Nn.document?Nn:(re(void 0),zn(!0),$c(Dr=>[...Dr.slice(-(kl-1)),Nn.document]),Q([]),{status:"ready",document:Nt})}catch(Zi){const xi=Zi instanceof Error?Zi.message:String(Zi);return re(xi),Nn}}),xf())},[Rc,xf]),l5=kt.useCallback(()=>{if(h.status!=="ready"||eu.length===0)return;const Nn=eu[eu.length-1];$c(Nt=>Nt.slice(0,-1)),Q(Nt=>[...Nt,h.document]),g({status:"ready",document:Nn}),zn(!0),re(void 0),xf()},[h,eu,xf]),by=kt.useCallback(()=>{if(h.status!=="ready"||Ii.length===0)return;const Nn=Ii[Ii.length-1];Q(Nt=>Nt.slice(0,-1)),$c(Nt=>[...Nt,h.document]),g({status:"ready",document:Nn}),zn(!0),re(void 0),xf()},[h,Ii,xf]);if(kt.useEffect(()=>{const Nn=Nt=>{if((Nt.metaKey||Nt.ctrlKey)&&Nt.key==="s"){Nt.preventDefault(),Dn&&o5();return}if((Nt.metaKey||Nt.ctrlKey)&&(Nt.key==="z"||Nt.key==="Z")){Nt.preventDefault(),Nt.shiftKey?by():l5();return}if((Nt.metaKey||Nt.ctrlKey)&&Nt.key==="y"){Nt.preventDefault(),by();return}if(Nt.key==="Escape"){vc&&gd();return}if(Nt.key==="Delete"||Nt.key==="Backspace"){const Zi=Nt.target;if(Zi instanceof HTMLInputElement||Zi instanceof HTMLTextAreaElement||Zi instanceof HTMLSelectElement||Zi instanceof HTMLElement&&Zi.isContentEditable||Rc.length===0)return;Nt.preventDefault(),la()}};return window.addEventListener("keydown",Nn),()=>window.removeEventListener("keydown",Nn)},[Dn,o5,vc,gd,Rc,la,l5,by]),h.status==="loading")return P.jsxs(b1n,{children:["Loading ",T.docUrl,"…"]});if(h.status==="error")return P.jsx(b1n,{children:P.jsx("pre",{className:"max-w-3xl whitespace-pre-wrap text-xs text-rose-700",children:h.error})});const iv=h.document,Ob=Ht&&Jt.status==="pending",gy=Ob&&Jt.status==="pending"?CZn(iv,Jt.doc):null,rv=Ob&&Jt.status==="pending"?l0n(r7e(iv,Jt.doc)):null,wd=gy??iv,wy=y0?.type==="node"?wd.nodes.find(Nn=>Nn.id===y0.id):void 0,cv=y0?.type==="edge"?wd.edges.find(Nn=>Nn.id===y0.id):void 0,s7=vc!==null?iv.nodes.find(Nn=>Nn.id===vc):void 0,f5=Rc.length>1;return P.jsxs("div",{className:"flex h-full flex-col",style:{background:"var(--archik-canvas)",color:"var(--archik-fg)"},children:[P.jsx(HXn,{document:iv,commandError:oe,saveStatus:nn,...tn!==null?{saveError:tn}:{},isDirty:Dn,onSave:()=>{o5()},onAddNode:oh,density:jl,onDensityChange:Ft,viewMode:ki,onViewModeChange:pu,canUndo:eu.length>0,canRedo:Ii.length>0,onUndo:l5,onRedo:by,getSvg:Qr,seqHighlight:Kn,onToggleSeqHighlight:()=>_t(Nn=>!Nn),seqNodeCount:Wn.size,...le!==void 0?{reloadError:le}:{},...s7!==void 0?{connectingFromName:s7.name,onCancelConnect:gd}:{}}),Jt.status==="pending"&&P.jsx(rVn,{added:Jt.added,removed:Jt.removed,changed:Jt.changed,note:Jt.note,reviewing:Ob,onReview:$s,onAccept:()=>{fs()},onReject:()=>{s5()}}),Jt.status==="error"&&P.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:[P.jsx("span",{style:{fontWeight:700},children:"SUGGESTION ERROR —"}),P.jsx("span",{style:{flex:1,color:"var(--archik-fg)"},children:Jt.message}),P.jsx("button",{type:"button",onClick:()=>vt({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&&P.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:[P.jsx("span",{style:{fontWeight:700,letterSpacing:"0.04em"},children:"FILE INVALID —"}),P.jsx("pre",{style:{margin:0,flex:1,whiteSpace:"pre-wrap",fontFamily:"inherit",color:"var(--archik-fg)"},children:le}),P.jsx("button",{type:"button",onClick:()=>Ee(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:"×"})]}),P.jsxs("main",{className:"flex min-h-0 flex-1 p-4",style:{gap:0},children:[P.jsx("div",{className:"archik-panel",style:{flex:1,minWidth:0,overflow:"hidden"},children:P.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",width:"100%"},children:[(M.length>1||p.length>1)&&P.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 10px",background:"var(--archik-surface)",borderBottom:"1px solid var(--archik-border)"},children:[P.jsx(ZXn,{files:M,currentPath:J,onSwitchFile:u7}),P.jsx(XXn,{stack:p,onGoToFrame:xT,suggestionsByPath:R})]}),P.jsx(yqn,{document:wd,className:"flex-1 archik-grid",layoutOptions:Ke,viewMode:ki,selectedNodeIds:r7,selectedEdgeIds:ls,onSelectNode:MT,onSelectEdge:CT,onSelectNothing:vc===null?xf:gd,onConnectDrag:tv,onOpenSubFile:c7,onCrossFileNavigate:Dp,viewKey:T.docUrl,svgRef:wr,...rv?{diffStatuses:rv}:{},...Kn&&Wn.size>0?{glowNodeIds:Wn}:{}})]})}),P.jsx("aside",{"aria-hidden":Rc.length===0,className:`archik-drawer-shell ${Rc.length>0?"archik-drawer-shell--open":"archik-drawer-shell--closed"}`,children:P.jsx("div",{className:"archik-panel archik-drawer-content archik-drawer-fade",style:{overflow:"hidden"},children:f5?P.jsx(iVn,{count:Rc.length,onDelete:la,onClear:xf}):y0?.type==="edge"?P.jsx(ZZn,{edge:cv,dispatch:k0,readOnly:Ob}):y0?.type==="node"?P.jsx(qZn,{node:wy,dispatch:k0,onStartConnect:u5,allNodes:wd.nodes,readOnly:Ob,viewKey:T.archikFile??void 0}):null},f5?`multi:${Rc.length}`:y0?`${y0.type}:${y0.id}`:"empty")})]})]})}function iVn({count:h,onDelete:g,onClear:p}){return P.jsxs("div",{className:"flex h-full flex-col gap-4 overflow-y-auto p-4 text-sm",children:[P.jsxs("div",{children:[P.jsx("div",{className:"archik-label",children:"Selection"}),P.jsxs("div",{style:{fontSize:18,fontWeight:600,color:"var(--archik-fg)",letterSpacing:"0.01em"},children:[h," items"]}),P.jsx("div",{style:{fontSize:11,color:"var(--archik-fg-dim)",marginTop:4},children:"Hold ⌘ / Ctrl while clicking to add or remove items."})]}),P.jsx("div",{className:"archik-divider"}),P.jsxs("div",{className:"mt-auto flex flex-col gap-2 pt-4",children:[P.jsx("button",{type:"button",onClick:p,className:"archik-btn",style:{justifyContent:"center",padding:"8px 12px"},children:"Clear selection"}),P.jsxs("button",{type:"button",onClick:g,className:"archik-btn archik-btn-danger",style:{justifyContent:"center",padding:"8px 12px"},children:["Delete ",h," items"]})]})]})}function b1n({children:h}){return P.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 rVn({added:h,removed:g,changed:p,note:v,reviewing:T,onReview:M,onAccept:j,onReject:R}){const G=h+g+p;return P.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:[P.jsx("span",{style:{fontWeight:700,letterSpacing:"0.04em",color:"#c4b5fd"},children:"📝 SUGGESTION PENDING"}),P.jsxs("span",{style:{color:"var(--archik-fg)"},children:[G===0?"(identical to current — nothing to apply)":P.jsxs(P.Fragment,{children:[P.jsxs("span",{style:{color:"var(--archik-success)"},children:["+",h]})," ",P.jsxs("span",{style:{color:"var(--archik-danger)"},children:["−",g]})," ",P.jsxs("span",{style:{color:"var(--archik-warning)"},children:["~",p]})]}),v?P.jsxs("span",{style:{marginLeft:10,color:"var(--archik-fg-dim)",fontStyle:"italic"},children:['"',v,'"']}):null]}),P.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:8},children:[P.jsx("button",{type:"button",onClick:M,className:"archik-btn",style:{padding:"5px 12px",fontSize:12,...T?{background:"#a855f7",color:"white",borderColor:"#a855f7"}:{}},children:T?"Hide diff":"Review"}),P.jsx("button",{type:"button",onClick:j,className:"archik-btn",title:G===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"}),P.jsx("button",{type:"button",onClick:R,className:"archik-btn",style:{padding:"5px 12px",fontSize:12,color:"var(--archik-danger)",borderColor:"var(--archik-danger)"},children:"Reject"})]})]})}const cVn=i7(["sync","async","return","create","destroy"]),uVn=i7(["over","left_of","right_of"]),sVn=i7(["alt","opt","loop","par","break","ref"]),oVn=Xg({id:bd,nodeId:bd,label:os().min(1).optional(),status:xI.optional()}),lVn=Xg({type:uJ("message"),id:bd,from:bd,to:bd,label:os().min(1),arrow:cVn,activate:OKn().optional(),status:xI.optional()}),fVn=Xg({type:uJ("note"),id:bd,position:uVn,participants:Kg(bd).min(1),text:os().min(1),status:xI.optional()}),aVn=L7e(()=>Xg({label:os().optional(),steps:Kg(p0n)})),hVn=L7e(()=>Xg({type:uJ("group"),id:bd,kind:sVn,condition:os().optional(),label:os().optional(),branches:Kg(aVn).optional(),seqFile:n0n.optional(),participants:Kg(bd).optional(),status:xI.optional()})),p0n=L7e(()=>Wdn([lVn,fVn,hVn]));function m0n(h,g){const p=[];for(const v of h)if(g.has(v.id)?p.push(v.id):g.add(v.id),v.type==="group"&&v.branches)for(const T of v.branches)p.push(...m0n(T.steps,g));return p}const dVn=Xg({useCase:bd,slice:bd}),bVn=Xg({version:uJ("1.0"),name:os().min(1),description:os().optional(),realizes:dVn.optional(),participants:Kg(oVn).min(1),steps:Kg(p0n)}).superRefine((h,g)=>{const p=new Set;for(let M=0;M<h.participants.length;M++){const j=h.participants[M];p.has(j.id)&&g.addIssue({code:xb.custom,path:["participants",M,"id"],message:`duplicate participant id "${j.id}"`}),p.add(j.id)}const v=new Set,T=m0n(h.steps,v);for(const M of T)g.addIssue({code:xb.custom,path:["steps"],message:`duplicate step id "${M}"`})}),sJ=56,gVn=160,wVn=40,o7e=56,pVn=24,L8e=12,g1n=64,Qce=32,w1n=24,p1n=8,v0n="seq-arrow-filled",y0n="seq-arrow-open";function mVn(h){return Math.max(gVn,h.length*8+wVn*2)}function k0n(h,g,p,v,T){let M=p;const j=[];for(const R of h)if(R.type==="message"){const G=g.get(R.from),J=g.get(R.to),oe=G?.cx??v,re=J?.cx??v;j.push({type:"message",id:R.id,fromCx:oe,toCx:re,y:M,label:R.label,arrow:R.arrow,activate:R.activate??!1,isSelf:R.from===R.to,...R.status!==void 0?{status:R.status}:{}}),M+=R.from===R.to?o7e*1.5:o7e}else if(R.type==="note"){const G=R.participants.map(Ee=>g.get(Ee)?.cx).filter(Ee=>Ee!==void 0).sort((Ee,nn)=>Ee-nn),J=G[0]??v,oe=G[G.length-1]??T,re=Math.min(Math.max(R.text.length*7.5+24,oe-J+16,80),400);let le;R.position==="left_of"?le=J-re-8:R.position==="right_of"?le=oe+8:le=(J+oe)/2-re/2,le=Math.max(0,le),j.push({type:"note",id:R.id,x:le,y:M,width:re,height:g1n,text:R.text,...R.status!==void 0?{status:R.status}:{}}),M+=g1n+8}else if(R.type==="group"){M+=8;const G=v-L8e,J=T-v+L8e*2,oe=M;M+=pVn;const re=[];if(R.branches)for(let le=0;le<R.branches.length;le++){const Ee=R.branches[le],nn=M,{items:ie,endY:tn}=k0n(Ee.steps,g,M,v,T);M=tn,re.push({...Ee.label!==void 0?{label:Ee.label}:{},startY:nn,...le<R.branches.length-1?{dividerY:M}:{},steps:ie}),le<R.branches.length-1&&(M+=4)}M+=L8e,j.push({type:"group",id:R.id,kind:R.kind,...R.condition!==void 0?{condition:R.condition}:{},...R.label!==void 0?{label:R.label}:{},...R.seqFile!==void 0?{seqFile:R.seqFile}:{},x:G,y:oe,width:J,height:M-oe,branches:re,...R.status!==void 0?{status:R.status}:{}})}return{items:j,endY:M}}function j0n(h){const g=new Map;for(const p of h)if(p.type==="message"&&p.arrow==="destroy"&&g.set(p.toCx,p.y+sJ+20),p.type==="group")for(const v of p.branches)for(const[T,M]of j0n(v.steps))g.set(T,M);return g}function vVn(h){const g=[],p=new Map;function v(T){for(const M of T)if(M.type==="message"){if(M.activate&&M.arrow==="sync"&&!M.isSelf){const j=p.get(M.toCx)??[];j.push(M.y),p.set(M.toCx,j)}if(M.arrow==="return"&&!M.isSelf){const j=p.get(M.fromCx);if(j&&j.length>0){const R=j.pop();g.push({cx:M.fromCx,startY:R,endY:M.y}),j.length===0&&p.delete(M.fromCx)}}}else if(M.type==="group")for(const j of M.branches)v(j.steps)}v(h);for(const[T,M]of p)for(const j of M)g.push({cx:T,startY:j,endY:j+o7e/2});return g}function yVn(h,g){const p=h.participants.map(tn=>mVn(tn.label??tn.nodeId));let v=Qce;const T=h.participants.map((tn,vn)=>{const Dn=p[vn],zn=v+Dn/2;v+=Dn;const Kn=g?.get(tn.nodeId);return{id:tn.id,nodeId:tn.nodeId,label:tn.label??tn.nodeId,cx:zn,colWidth:Dn,...Kn!==void 0?{kind:Kn}:{},...tn.status!==void 0?{status:tn.status}:{},lifelineEndY:0}}),M=v+Qce,j=new Map(T.map(tn=>[tn.id,tn])),R=T[0]?.cx??Qce,G=T[T.length-1]?.cx??M-Qce,J=w1n,{items:oe,endY:re}=k0n(h.steps,j,J,R,G),le=sJ+re+w1n,Ee=j0n(oe),nn=T.map(tn=>({...tn,lifelineEndY:Ee.get(tn.cx)??le})),ie=vVn(oe);return{participants:nn,steps:oe,activations:ie,totalWidth:M,totalHeight:le}}const eue=36,kVn=128,jVn=7,m1n=20,v1n=24;function SVn({participant:h,nodeKind:g}){const p=g?Qm[g]:void 0,v=p?.color??"var(--archik-fg-muted)",T=(sJ-eue)/2,M=p?.icon,j=Math.max(kVn,h.label.length*jVn+v1n+(M?m1n:0)),R=j/2,G=M?R+m1n/2:R,J=h.status,oe=J==="proposed"?.55:J==="deprecated"?.35:1,re=J==="proposed"||J==="deprecated"?"4 3":void 0;return P.jsxs("g",{transform:`translate(${h.cx-R}, ${T})`,opacity:oe,children:[P.jsx("rect",{width:j,height:eue,rx:8,fill:"var(--archik-node-fill)",stroke:v,strokeWidth:1.4,...re!==void 0?{strokeDasharray:re}:{}}),M&&P.jsx("g",{transform:`translate(${v1n/2}, ${(eue-14)/2})`,children:P.jsx(M,{size:14,color:v,strokeWidth:1.5})}),P.jsx("text",{x:G,y:eue/2+4,textAnchor:"middle",fontSize:12,fontWeight:500,fill:"var(--archik-fg)",fontFamily:"inherit",children:h.label})]})}function EVn({participant:h}){const g=h.status,p=g==="proposed"?.3:g==="deprecated"?.2:.5;return P.jsx("line",{x1:h.cx,y1:sJ,x2:h.cx,y2:h.lifelineEndY,stroke:"var(--archik-node-stroke)",strokeWidth:1,strokeDasharray:"4 4",opacity:p})}const R8e=32,P8e=20,AVn=-6;function TVn({msg:h}){const g=h.arrow==="return",p=h.arrow==="async",v=h.arrow==="create",T=g||v,M=h.arrow==="destroy",j=g||p?y0n:v0n,R=h.status==="proposed"?.5:h.status==="deprecated"?.35:1;if(h.isSelf){const re=h.fromCx,le=h.y,Ee=`M ${re} ${le} L ${re+R8e} ${le} L ${re+R8e} ${le+P8e} L ${re} ${le+P8e}`;return P.jsxs("g",{opacity:R,children:[P.jsx("path",{d:Ee,fill:"none",stroke:"var(--archik-edge-filled)",strokeWidth:1.4,markerEnd:`url(#${j})`}),P.jsx("text",{x:re+R8e+6,y:le+P8e/2+4,fontSize:11,fill:"var(--archik-fg)",fontFamily:"inherit",children:h.label})]})}const J=h.fromCx<h.toCx?h.toCx-6:h.toCx+6,oe=(h.fromCx+h.toCx)/2;return P.jsxs("g",{opacity:R,children:[P.jsx("line",{x1:h.fromCx,y1:h.y,x2:J,y2:h.y,stroke:"var(--archik-edge-filled)",strokeWidth:1.4,strokeDasharray:T?"4 4":void 0,markerEnd:M?void 0:`url(#${j})`}),P.jsxs("text",{x:oe,y:h.y+AVn,textAnchor:"middle",fontSize:11,fill:"var(--archik-fg)",fontFamily:"inherit",children:[v&&"«create» ",h.label]}),h.arrow==="destroy"&&P.jsxs("g",{transform:`translate(${h.toCx-6}, ${h.y-6})`,children:[P.jsx("line",{x1:0,y1:0,x2:12,y2:12,stroke:"var(--archik-fg-muted)",strokeWidth:1.5}),P.jsx("line",{x1:12,y1:0,x2:0,y2:12,stroke:"var(--archik-fg-muted)",strokeWidth:1.5})]})]})}const xVn={alt:"#6366f1",opt:"#0ea5e9",loop:"#10b981",par:"#f59e0b",break:"#ef4444",ref:"#8b5cf6"},y1n=36,z8e=18;function MVn({group:h,renderStep:g,onRefClick:p}){const v=xVn[h.kind]??"var(--archik-fg-muted)",T=h.status==="proposed"?.55:h.status==="deprecated"?.35:1,M=h.kind==="ref"&&h.seqFile!==void 0&&p!==void 0;return P.jsxs("g",{opacity:T,onClick:M?()=>p(h.seqFile):void 0,style:M?{cursor:"pointer"}:void 0,children:[P.jsx("rect",{x:h.x,y:h.y,width:h.width,height:h.height,rx:4,fill:"none",stroke:v,strokeWidth:1.2,opacity:.6}),P.jsx("rect",{x:h.x,y:h.y,width:y1n,height:z8e,rx:4,fill:v,opacity:.8}),P.jsx("text",{x:h.x+6,y:h.y+z8e-5,fontSize:10,fontWeight:600,fill:"#fff",fontFamily:"inherit",children:h.kind}),(h.condition??h.label)&&P.jsx("text",{x:h.x+y1n+6,y:h.y+z8e-5,fontSize:10,fill:v,fontFamily:"inherit",children:h.condition??h.label}),h.branches.map((j,R)=>P.jsxs("g",{children:[j.label&&P.jsx("text",{x:h.x+6,y:j.startY+12,fontSize:10,fill:v,fontFamily:"inherit",children:j.label}),j.steps.map(G=>g(G)),j.dividerY!==void 0&&P.jsx("line",{x1:h.x,y1:j.dividerY,x2:h.x+h.width,y2:j.dividerY,stroke:v,strokeWidth:1,strokeDasharray:"4 2",opacity:.5})]},R))]})}const iI=10;function CVn(h,g){const p=Math.max(10,Math.floor(g/6.5));if(h.length<=p)return[h];const v=h.split(" "),T=[];let M="";for(const j of v)(M+(M?" ":"")+j).length>p&&M?(T.push(M),M=j):M=M?M+" "+j:j;return M&&T.push(M),T.slice(0,3)}function OVn({note:h}){const{x:g,y:p,width:v,height:T,text:M}=h,j=h.status==="proposed"?.55:h.status==="deprecated"?.35:1;return P.jsxs("g",{opacity:j,children:[P.jsx("path",{d:`M ${g} ${p} L ${g+v-iI} ${p} L ${g+v} ${p+iI} L ${g+v} ${p+T} L ${g} ${p+T} Z`,fill:"var(--archik-node-fill)",stroke:"var(--archik-node-stroke)",strokeWidth:1.2}),P.jsx("path",{d:`M ${g+v-iI} ${p} L ${g+v-iI} ${p+iI} L ${g+v} ${p+iI}`,fill:"none",stroke:"var(--archik-node-stroke)",strokeWidth:1.2}),CVn(M,v-16).map((R,G)=>P.jsx("text",{x:g+8,y:p+8+11+G*13,fontSize:11,fill:"var(--archik-fg)",fontFamily:"inherit",children:R},G))]})}function _Vn({id:h}){return P.jsx("marker",{id:h,viewBox:"0 0 10 10",refX:"10",refY:"5",markerWidth:"6",markerHeight:"6",orient:"auto-start-reverse",children:P.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"context-stroke"})})}function NVn({id:h}){return P.jsx("marker",{id:h,viewBox:"0 0 12 12",refX:"11",refY:"6",markerWidth:"7",markerHeight:"7",orient:"auto-start-reverse",children:P.jsx("path",{d:"M 1 1 L 11 6 L 1 11",fill:"none",stroke:"context-stroke",strokeWidth:"1.5",strokeLinejoin:"round"})})}function S0n({step:h,onRefClick:g}){return h.type==="message"?P.jsx(TVn,{msg:h}):h.type==="note"?P.jsx(OVn,{note:h}):h.type==="group"?P.jsx(MVn,{group:h,...g!==void 0?{onRefClick:g}:{},renderStep:p=>P.jsx(S0n,{step:p,...g!==void 0?{onRefClick:g}:{}},p.id)}):null}function IVn({laid:h,svgRef:g,onRefClick:p}){const{participants:v,steps:T,activations:M,totalWidth:j,totalHeight:R}=h;return P.jsxs("svg",{ref:g,width:j,height:R,viewBox:`0 0 ${j} ${R}`,xmlns:"http://www.w3.org/2000/svg",style:{fontFamily:"var(--archik-font, system-ui)"},children:[P.jsxs("defs",{children:[P.jsx(_Vn,{id:v0n}),P.jsx(NVn,{id:y0n})]}),v.map(G=>P.jsx(EVn,{participant:G},G.id)),v.map(G=>P.jsx(SVn,{participant:G,...G.kind!==void 0?{nodeKind:G.kind}:{}},G.id)),P.jsxs("g",{transform:`translate(0, ${sJ})`,children:[M.map(G=>P.jsx("rect",{x:G.cx-p1n/2,y:G.startY,width:p1n,height:G.endY-G.startY,fill:"var(--archik-node-fill)",stroke:"var(--archik-node-stroke)",strokeWidth:1,rx:2},`${G.cx}-${G.startY}`)),T.map(G=>P.jsx(S0n,{step:G,...p!==void 0?{onRefClick:p}:{}},G.id))]})]})}function DVn({path:h,back:g}){const[p,v]=kt.useState({status:"loading"}),[T,M]=kt.useState(void 0),j=kt.useRef(null);kt.useEffect(()=>{fetch("/__archik/node-kinds").then(le=>le.ok?le.json():null).then(le=>{le&&M(new Map(Object.entries(le)))}).catch(()=>{})},[]),kt.useEffect(()=>{v({status:"loading"});const le=encodeURIComponent(h);fetch(`/__archik/seq-file?path=${le}`).then(async Ee=>{if(!Ee.ok)throw new Error(`${Ee.status} ${Ee.statusText}`);return Ee.text()}).then(Ee=>{const nn=M7e.parse(Ee),ie=bVn.safeParse(nn);if(!ie.success)throw new Error(ie.error.issues.map(tn=>tn.message).join("; "));v({status:"ready",doc:ie.data})}).catch(Ee=>{v({status:"error",message:Ee instanceof Error?Ee.message:String(Ee)})})},[h]);const R=g?g.type==="usecase"?`/__archik/usecases?uc=${encodeURIComponent(g.value)}`:`/?file=${encodeURIComponent(g.value)}`:"/",G=g?.type==="usecase"?"Use cases":"Architecture";if(p.status==="loading")return P.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 P.jsxs("div",{className:"flex h-screen flex-col items-center justify-center gap-4",children:[P.jsx("div",{style:{color:"var(--archik-fg-error, #ef4444)"},children:p.message}),P.jsxs("a",{href:R,style:{color:"var(--archik-fg-muted)",fontSize:13},children:["← ",G]})]});const J=yVn(p.doc,T),oe=h.replace(/^.*\//,"").replace(/\.archik\.seq\.yaml$/,""),re=le=>{const Ee=new URLSearchParams;Ee.set("path",le),g?.type==="usecase"?Ee.set("from-uc",g.value):g?.type==="file"&&Ee.set("from-file",g.value),window.location.href=`/__archik/seq?${Ee.toString()}`};return P.jsxs("div",{className:"flex h-screen flex-col",style:{background:"var(--archik-bg)"},children:[P.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:[P.jsxs("a",{href:R,style:{color:"var(--archik-fg-muted)",fontSize:13,textDecoration:"none"},children:["← ",G]}),P.jsx("span",{style:{color:"var(--archik-node-stroke)"},children:"|"}),P.jsx("span",{style:{fontWeight:500,fontSize:14,color:"var(--archik-fg)"},children:p.doc.name}),P.jsx("div",{className:"ml-auto",children:P.jsx(h0n,{filename:oe,getSvg:()=>j.current})})]}),P.jsx("div",{className:"flex-1 overflow-auto p-6",children:P.jsx(IVn,{laid:J,svgRef:j,onRefClick:re})})]})}const $Vn="/__archik/usecases",LVn="/__archik/trace";async function k1n(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 RVn({selectedId:h}){const[g,p]=kt.useState({status:"loading"});return kt.useEffect(()=>{let v=!1;const T=new AbortController;return Promise.all([k1n($Vn,T.signal),k1n(LVn,T.signal)]).then(([M,j])=>{v||p({status:"ready",useCases:M.useCases??[],trace:j.rows??[]})}).catch(M=>{v||T.signal.aborted||p({status:"error",message:M instanceof Error?M.message:String(M)})}),()=>{v=!0,T.abort()}},[]),P.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100vh",background:"var(--archik-canvas)",color:"var(--archik-fg)",fontFamily:"Inter, system-ui, sans-serif"},children:[P.jsx(PVn,{state:g}),P.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[g.status==="loading"&&P.jsx(B8e,{children:"Loading…"}),g.status==="error"&&P.jsxs(B8e,{tone:"error",children:["Couldn't load: ",g.message]}),g.status==="ready"&&g.useCases.length===0&&P.jsxs(B8e,{children:["No use cases defined yet. Add a ",P.jsx("code",{children:"*.archik.uc.yaml"})," file under ",P.jsx("code",{children:".archik/usecases/"}),"."]}),g.status==="ready"&&g.useCases.length>0&&P.jsx(zVn,{useCases:g.useCases,trace:g.trace,selectedId:h})]})]})}function PVn({state:h}){const g=kt.useMemo(()=>{if(h.status!=="ready")return null;let p=0,v=0,T=0;for(const M of h.trace)M.level==="full"?p++:M.level==="partial"?v++:T++;return{full:p,partial:v,none:T,total:h.trace.length}},[h]);return P.jsxs("header",{style:{display:"flex",alignItems:"center",gap:16,padding:"0 20px",height:52,borderBottom:"1px solid var(--archik-border)",background:"var(--archik-panel)",flexShrink:0},children:[P.jsxs("a",{href:"/",style:{display:"inline-flex",alignItems:"center",gap:4,color:"var(--archik-fg-dim)",fontSize:13,textDecoration:"none"},children:[P.jsx(lBn,{size:14}),"Architecture"]}),P.jsx("span",{style:{color:"var(--archik-border-strong)"},children:"|"}),P.jsx("h1",{style:{fontSize:14,fontWeight:600,margin:0,color:"var(--archik-fg)"},children:"Use cases"}),g&&g.total>0&&P.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginLeft:"auto",fontSize:12,color:"var(--archik-fg-dim)"},children:[P.jsxs("span",{children:[P.jsx("span",{style:{color:"var(--archik-success)"},children:"●"})," ",g.full," full"]}),P.jsxs("span",{children:[P.jsx("span",{style:{color:"var(--archik-warning)"},children:"◐"})," ",g.partial," partial"]}),P.jsxs("span",{children:[P.jsx("span",{style:{color:"var(--archik-fg-muted)"},children:"○"})," ",g.none," untraced"]}),P.jsxs("span",{style:{color:"var(--archik-fg-muted)"},children:["· ",g.total," ",g.total===1?"slice":"slices"]})]})]})}function zVn({useCases:h,trace:g,selectedId:p}){const v=kt.useMemo(()=>{const j=new Map;for(const R of g){const G=j.get(R.useCase);if(!G){j.set(R.useCase,R.level);continue}G==="none"||R.level==="none"?j.set(R.useCase,"none"):(G==="partial"||R.level==="partial")&&j.set(R.useCase,"partial")}return j},[g]),T=kt.useMemo(()=>{const j=new Map;for(const R of g)j.set(`${R.useCase}/${R.slice}`,R);return j},[g]),M=h.find(j=>j.id===p)??h[0];return P.jsxs(P.Fragment,{children:[P.jsx(BVn,{useCases:h,ucLevel:v,selectedId:M.id}),P.jsx(FVn,{useCase:M,traceByKey:T})]})}function BVn({useCases:h,ucLevel:g,selectedId:p}){return P.jsx("nav",{"aria-label":"Use cases",style:{width:260,borderRight:"1px solid var(--archik-border)",background:"var(--archik-panel)",overflowY:"auto",padding:"8px 0",flexShrink:0},children:P.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:h.map(v=>{const T=g.get(v.id)??"none",M=v.id===p;return P.jsx("li",{children:P.jsxs("a",{href:`/__archik/usecases?uc=${encodeURIComponent(v.id)}`,style:{display:"flex",alignItems:"center",gap:8,padding:"8px 14px",textDecoration:"none",color:"var(--archik-fg)",background:M?"var(--archik-surface-hover)":"transparent",borderLeft:M?"2px solid var(--archik-accent)":"2px solid transparent",fontSize:13},children:[P.jsx(E0n,{level:T}),P.jsxs("span",{style:{flex:1,minWidth:0},children:[P.jsx("code",{style:{fontSize:12,fontFamily:"ui-monospace, monospace"},children:v.id}),P.jsx("div",{style:{fontSize:11,color:"var(--archik-fg-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:v.name})]}),v.status&&v.status!=="active"&&P.jsx("span",{style:{fontSize:9,padding:"1px 6px",borderRadius:4,background:"var(--archik-surface)",color:"var(--archik-fg-muted)"},children:v.status})]})},v.id)})})})}function E0n({level:h}){const g=h==="full"?{glyph:"●",color:"var(--archik-success)",label:"fully traced"}:h==="partial"?{glyph:"◐",color:"var(--archik-warning)",label:"partially traced"}:{glyph:"○",color:"var(--archik-fg-muted)",label:"untraced"};return P.jsx("span",{title:g.label,"aria-label":g.label,style:{color:g.color,fontSize:12,lineHeight:1,width:12},children:g.glyph})}function FVn({useCase:h,traceByKey:g}){return P.jsx("main",{style:{flex:1,overflowY:"auto",padding:"24px 32px"},children:P.jsxs("div",{style:{maxWidth:820,margin:"0 auto"},children:[P.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:12,marginBottom:4},children:[P.jsx("code",{style:{fontSize:18,fontFamily:"ui-monospace, monospace",fontWeight:600,color:"var(--archik-fg)"},children:h.id}),h.status&&h.status!=="active"&&P.jsx("span",{className:"archik-pill",style:{fontSize:10},children:h.status})]}),P.jsx("div",{style:{fontSize:15,color:"var(--archik-fg-dim)",marginBottom:18},children:h.name}),P.jsx(qVn,{useCase:h}),h.goal&&P.jsx(rI,{title:"Goal",children:P.jsx("p",{style:{margin:0,lineHeight:1.55},children:h.goal})}),(h.preconditions?.length??0)>0&&P.jsx(rI,{title:"Preconditions",children:P.jsx("ul",{style:WU,children:h.preconditions.map((p,v)=>P.jsx("li",{children:p},v))})}),h.flows?.basic?.steps&&P.jsx(rI,{title:"Basic flow",children:P.jsx("ol",{style:{...WU,paddingLeft:22},children:h.flows.basic.steps.map((p,v)=>P.jsx("li",{style:{marginBottom:4},children:p},v))})}),(h.flows?.alternates?.length??0)>0&&P.jsx(rI,{title:"Alternate flows",children:h.flows.alternates.map(p=>P.jsxs("div",{style:{marginBottom:12,padding:12,background:"var(--archik-surface)",borderRadius:6,borderLeft:"3px solid var(--archik-warning)"},children:[P.jsxs("div",{style:{display:"flex",gap:8,alignItems:"baseline",marginBottom:6},children:[P.jsx("code",{style:{fontSize:12,fontWeight:600},children:p.id}),p.branchFrom&&P.jsxs("span",{style:{fontSize:11,color:"var(--archik-fg-muted)"},children:["branches from ",p.branchFrom]})]}),P.jsx("ol",{style:{...WU,paddingLeft:22,fontSize:13},children:p.steps.map((v,T)=>P.jsx("li",{children:v},T))})]},p.id))}),(h.postconditions?.length??0)>0&&P.jsx(rI,{title:"Postconditions",children:P.jsx("ul",{style:WU,children:h.postconditions.map((p,v)=>P.jsx("li",{children:p},v))})}),(()=>{const p=h.slices??[];return P.jsx(rI,{title:`Slices (${p.length})`,children:p.length===0?P.jsx("div",{style:{fontSize:12,color:"var(--archik-fg-muted)"},children:"— no slices declared"}):P.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:p.map(v=>P.jsx(GVn,{slice:v,useCaseId:h.id,trace:g.get(`${h.id}/${v.id}`)},v.id))})})})(),P.jsxs("div",{style:{marginTop:32,paddingTop:16,borderTop:"1px solid var(--archik-border)",fontSize:11,color:"var(--archik-fg-muted)"},children:["Source:"," ",P.jsx("code",{style:{fontFamily:"ui-monospace, monospace"},children:h.relPath})]})]})})}function qVn({useCase:h}){return P.jsxs("div",{style:{display:"flex",gap:24,padding:"10px 14px",background:"var(--archik-surface)",borderRadius:6,marginBottom:20,fontSize:12},children:[P.jsxs("div",{children:[P.jsx("div",{style:l7e,children:"Primary actor"}),P.jsx("div",{style:{marginTop:2},children:P.jsx("code",{style:{fontFamily:"ui-monospace, monospace"},children:h.primaryActor})})]}),(h.secondaryActors?.length??0)>0&&P.jsxs("div",{children:[P.jsx("div",{style:l7e,children:"Secondary actors"}),P.jsx("div",{style:{marginTop:2},children:h.secondaryActors.map((g,p)=>P.jsxs("span",{children:[P.jsx("code",{style:{fontFamily:"ui-monospace, monospace"},children:g}),p<h.secondaryActors.length-1&&", "]},g))})]})]})}function GVn({slice:h,useCaseId:g,trace:p}){const v=p?.level??"none";return P.jsxs("div",{style:{padding:14,background:"var(--archik-panel)",border:"1px solid var(--archik-border)",borderRadius:8},children:[P.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:8,marginBottom:8},children:[P.jsx(E0n,{level:v}),P.jsx("code",{style:{fontSize:13,fontFamily:"ui-monospace, monospace",fontWeight:600},children:h.id}),h.status&&h.status!=="active"&&P.jsxs("span",{style:{fontSize:10,color:"var(--archik-fg-muted)"},children:["[",h.status,"]"]}),P.jsx("span",{style:{marginLeft:"auto",fontSize:11,color:"var(--archik-fg-muted)"},children:p?.realization&&p.realization.participants.length>0&&P.jsxs(P.Fragment,{children:["ECB"," ",p.realization.participants.filter(T=>T.stereotype!==void 0).length,"/",p.realization.participants.length]})})]}),h.description&&P.jsx("div",{style:{fontSize:13,color:"var(--archik-fg-dim)",marginBottom:10,lineHeight:1.5},children:h.description}),P.jsxs("div",{style:{display:"grid",gridTemplateColumns:"auto 1fr",columnGap:14,rowGap:8,fontSize:12,alignItems:"start"},children:[P.jsx("div",{style:F8e,children:"Tests"}),P.jsx("div",{children:(h.tests?.length??0)===0?P.jsx("span",{style:{color:"var(--archik-fg-muted)"},children:"— none declared"}):P.jsx("ul",{style:{...WU,paddingLeft:0,listStyle:"none"},children:h.tests.map(T=>P.jsxs("li",{style:{fontFamily:"ui-monospace, monospace",fontSize:11},children:[P.jsx("span",{style:{color:"var(--archik-fg-muted)"},children:"•"})," ",T]},T))})}),P.jsx("div",{style:F8e,children:"Realization"}),P.jsx("div",{children:h.realization?P.jsxs("a",{href:`/__archik/seq?path=${encodeURIComponent(h.realization.seqFile)}&from-uc=${encodeURIComponent(g)}`,style:{display:"inline-flex",alignItems:"center",gap:4,color:"var(--archik-accent)",textDecoration:"none",fontFamily:"ui-monospace, monospace",fontSize:11},children:[P.jsx(A1n,{size:11}),UVn(h.realization.seqFile),P.jsx(T1n,{size:11,style:{opacity:.7}})]}):P.jsx("span",{style:{color:"var(--archik-fg-muted)"},children:"— no seq file yet"})}),P.jsx("div",{style:F8e,children:"Flows"}),P.jsx("div",{style:{fontSize:11,color:"var(--archik-fg-dim)"},children:(h.flows??[]).join(", ")||"—"})]})]})}function UVn(h){return h.split("/").pop()?.replace(/\.archik\.seq\.yaml$/,"")??h}function rI({title:h,children:g}){return P.jsxs("section",{style:{marginBottom:24},children:[P.jsx("h2",{style:{fontSize:12,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",color:"var(--archik-fg-muted)",margin:"0 0 8px"},children:h}),g]})}function B8e({children:h,tone:g}){return P.jsx("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",color:g==="error"?"var(--archik-danger)":"var(--archik-fg-muted)",fontSize:13,padding:24,textAlign:"center"},children:h})}const l7e={fontSize:10,textTransform:"uppercase",letterSpacing:"0.06em",color:"var(--archik-fg-muted)",fontWeight:600},F8e={...l7e,fontSize:10,paddingTop:1},WU={margin:0,paddingLeft:18,fontSize:13,lineHeight:1.55},A0n=document.getElementById("root");if(!A0n)throw new Error("#root not found");const ZU=new URLSearchParams(window.location.search),gue=window.location.pathname,JVn=gue==="/__archik/seq"||gue.startsWith("/__archik/seq/"),HVn=gue==="/__archik/usecases"||gue.startsWith("/__archik/usecases/"),q8e=vzn.createRoot(A0n);if(JVn){const h=ZU.get("path")??"",g=ZU.get("from-uc"),p=ZU.get("from-file")??ZU.get("from"),v=g?{type:"usecase",value:g}:p?{type:"file",value:p}:null;q8e.render(P.jsx(kt.StrictMode,{children:P.jsx(DVn,{path:h,back:v})}))}else if(HVn){const h=ZU.get("uc");q8e.render(P.jsx(kt.StrictMode,{children:P.jsx(RVn,{selectedId:h})}))}else q8e.render(P.jsx(kt.StrictMode,{children:P.jsx(tVn,{})}));
@@ -14,7 +14,7 @@
14
14
  }
15
15
  } catch {}
16
16
  </script>
17
- <script type="module" crossorigin src="/assets/index-DyQL2X9h.js"></script>
17
+ <script type="module" crossorigin src="/assets/index-BGY3itFY.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.31",
3
+ "version": "0.12.32",
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",