forge-cw 0.1.23 → 0.1.24

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.
@@ -24,7 +24,7 @@ ${d.trim()}
24
24
 
25
25
  ${(S[F]??"").trim()}
26
26
  `).join(`
27
- `);try{const F=await ce("/api/kioku/pages",{brain:u.key,type:s,title:h,summary:v,body:M,namespace:E,create:A});F.status==="similar"?p(F.similar):F.status==="namespace"?j(`Pick an area of ${re(u)}`,"error"):(j(`Saved to ${F.brain}: ${F.path}`,"success"),Pe(!0),n())}catch(F){j(le(F),"error")}finally{$(!1)}};return l(Ze,{title:"New memory",onClose:n,children:[t(H,{label:"Brain",children:t("select",{class:"field",value:r,onChange:A=>{o(ae(A)),d(""),p(null)},children:a.map(A=>l("option",{value:A.key,children:[re(A)," · ",A.tier]},A.key))})}),u&&z.length===0&&l("div",{class:"flex items-center",style:{...oe,gap:"12px",background:Q("--orange")},children:[l("span",{class:"flex-1",children:[re(u)," has no areas yet. Each page goes in one, and a person names them."]}),t(I,{label:"Add area",variant:"secondary",size:"sm",onClick:()=>k(!0)})]}),z.length>1&&t(H,{label:"Area",children:l("select",{class:"field",value:i,onChange:A=>d(ae(A)),children:[t("option",{value:"",children:"Choose…"}),z.map(A=>t("option",{value:A,children:A},A))]})}),t("div",{class:"flex",children:t(de,{size:"sm",label:"Page type",tabs:Mt.map(A=>({id:A.id,label:A.label})),active:s,onChange:A=>{c(A),p(null)}})}),t(H,{label:"Title",children:t("input",{type:"text",class:"field",value:h,placeholder:"Payments retry at most three times",onInput:A=>{f(ae(A)),p(null)}})}),t(H,{label:"Summary · one line the agent reads first",children:t("input",{type:"text",class:"field",value:v,onInput:A=>x(ae(A))})}),R.map(A=>t(H,{label:A,children:t("textarea",{class:"field",rows:A==="Text"?8:3,value:S[A]??"",onInput:M=>b(F=>({...F,[A]:ae(M)}))})},`${s}:${A}`)),y&&l("div",{style:{...oe,background:Q("--orange")},children:[l("p",{style:{fontWeight:600,marginBottom:"6px"},children:[u?re(u):"The brain"," already has pages on this:"]}),t("ul",{class:"flex flex-col",style:{gap:"4px",paddingLeft:"16px",listStyle:"disc"},children:y.map(A=>l("li",{children:[t("b",{children:A.title}),A.summary?` — ${A.summary}`:""]},A.path))}),t("p",{style:{marginTop:"6px",color:"var(--ink-2)"},children:"Save it anyway to keep both; kioku links them under See also."})]}),(u==null?void 0:u.remote)&&l("p",{style:{fontSize:"12px",color:"var(--ink-3)"},children:["Kioku commits to ",re(u),"'s main branch and pushes it; it has no review step."]}),l("div",{class:"flex justify-end",style:{gap:"8px"},children:[t(I,{label:"Cancel",variant:"secondary",onClick:n}),t(I,{label:y?"Save anyway":"Save",variant:"primary",disabled:!P||w,onClick:()=>T(y!==null)})]}),g&&u&&t(ro,{brain:u,onClose:()=>k(!1)})]})},oo={fontSize:"11px",fontWeight:600,letterSpacing:".02em",color:"var(--ink-3)"},lo={gap:"10px",padding:"9px 16px",borderTop:"1px solid var(--hair)",fontSize:"12.5px"},fe={fontSize:"11.5px",color:"var(--ink-3)"},xi={updated:"--green",current:"--ink-3"},Ae=({text:e})=>l("div",{class:"flex items-center min-w-0",style:{gap:"6px"},children:[t("code",{class:"truncate",title:e,style:{fontSize:"11px",color:"var(--ink-2)",padding:"2px 6px",borderRadius:"6px",background:"var(--elev)"},children:e}),t("button",{type:"button","aria-label":"Copy command",title:"Copy command",class:"grid place-items-center shrink-0 cursor-pointer hover:text-ink",style:{padding:"2px",color:"var(--ink-3)",background:"none",border:0},onClick:()=>un(e,"Command"),children:t("span",{class:"i-lucide-copy",style:{width:"12px",height:"12px"}})})]}),so=({title:e,aside:n,command:a,children:r})=>l("section",{class:"flex flex-col min-w-0",style:{...Le,overflow:"hidden"},children:[l("div",{class:"flex items-center",style:{gap:"8px",padding:"12px 16px 8px"},children:[t("h2",{style:oo,children:e}),t("span",{class:"flex-1"}),n]}),r,t("div",{style:{padding:"8px 16px 12px",borderTop:"1px solid var(--hair)"},children:t(Ae,{text:a})})]}),La=({release:e,label:n,action:a,onTry:r})=>l("div",{class:"flex flex-col",style:lo,children:[l("div",{class:"flex items-center",style:{gap:"10px"},children:[t("span",{class:"shrink-0",style:{...fe,width:"70px"},children:n}),t("span",{class:"mono",style:{fontWeight:600},children:e.version}),e.date&&t("span",{style:fe,children:At(e.date)}),t("a",{href:e.notesUrl,target:"_blank",rel:"noreferrer",style:{fontSize:"11.5px",color:"var(--blue)"},children:"Notes ↗"}),t("span",{class:"flex-1"}),a&&t(I,{label:a,variant:e.prerelease?"primary":"secondary",size:"sm",onClick:()=>r(e.version)})]}),a&&t(Ae,{text:e.install}),e.notes&&l("details",{style:{fontSize:"12px",color:"var(--ink-2)"},children:[t("summary",{class:"cursor-pointer",style:fe,children:"What it brings"}),t("p",{style:{whiteSpace:"pre-wrap",marginTop:"6px"},children:e.notes})]})]}),mi=({onTry:e})=>{const n=$t.value;if(!n)return null;const{installed:a,stable:r,stableAction:o,prereleases:s}=n,c=l(U,{children:[t("span",{class:"mono",style:{fontSize:"13px",fontWeight:600},children:a??"unknown"}),(a==null?void 0:a.includes("-"))&&t(He,{label:"pre-release",color:"var(--orange)"})]});return l(so,{title:"KIOKU VERSION",aside:c,command:n.command,children:[n.error&&t("p",{style:{...oe,margin:"0 16px 10px",background:Q("--orange")},children:n.error}),r&&t(La,{release:r,label:"Stable",action:o==="back"?"Back to stable":o==="update"?`Update to ${r.version}`:void 0,onTry:e}),s.map(i=>t(La,{release:i,label:"Pre-release",action:`Try ${i.version}`,onTry:e},i.version)),!n.error&&s.length===0&&t("p",{style:{...fe,padding:"8px 16px 12px",borderTop:"1px solid var(--hair)"},children:"No pre-release newer than the one installed."})]})},vi=({version:e,onClose:n})=>{const[a,r]=m(null),[o,s]=m(null),[c,i]=m(null),[d,h]=m(!1);D(()=>{ce("/api/kioku/update/check",{version:e}).then(r,S=>i(le(S)))},[e]);const f=async()=>{h(!0),i(null);try{s(await ce("/api/kioku/update",{version:e})),Promise.all([Pe(),Hn()])}catch(S){i(le(S))}finally{h(!1)}},v=o??a,x=o?l(U,{children:[t("span",{class:"flex-1"}),t(I,{label:"Close",variant:"primary",onClick:n})]}):l(U,{children:[t("span",{class:"flex-1"}),t(I,{label:"Cancel",variant:"secondary",onClick:n}),t(I,{label:d?"Installing…":`Install ${e}`,variant:"primary",disabled:!a||a.status==="current"||d,onClick:f})]});return t(Re,{open:!0,title:o?`Kioku ${o.version??e}`:`Try Kioku ${e}`,onClose:d?()=>{}:n,footer:x,children:l("div",{class:"flex flex-col",style:{gap:"12px",fontSize:"13px"},children:[!v&&!c&&t("p",{style:fe,children:"Asking kioku what it would install…"}),v&&l("div",{class:"flex items-center",style:{gap:"10px"},children:[l("span",{class:"mono",style:{fontSize:"16px",fontWeight:600},children:[v.was??"?"," → ",v.version??e]}),t(He,{label:v.status,color:`var(${xi[v.status]??"--blue"})`})]}),(a==null?void 0:a.status)==="current"&&!o&&t("p",{style:fe,children:"This version is already installed."}),v&&t(Ae,{text:v.command}),!o&&(a==null?void 0:a.install)&&t(Ae,{text:a.install}),o&&o.agents.length>0&&l("div",{class:"flex flex-col",style:{gap:"4px"},children:[t("h3",{style:oo,children:"AGENT PLUGINS"}),o.agents.map(S=>l("div",{class:"flex items-center",style:{gap:"8px",fontSize:"12.5px"},children:[t("span",{style:{fontWeight:500},children:S.host}),t("span",{style:fe,children:S.name}),l("span",{class:"mono",children:[S.from??"–"," → ",S.to??"–"]}),t("span",{class:"flex-1"}),S.error?t(He,{label:S.error,color:"var(--red)"}):t(He,{label:S.changed?"changed":"unchanged",color:`var(${S.changed?"--green":"--ink-3"})`})]},`${S.host}:${S.name}`))]}),(o==null?void 0:o.finishError)&&t("p",{style:{...oe,background:Q("--orange")},children:o.finishError}),c&&t("p",{style:{...oe,background:Q("--red")},children:c}),!o&&l("p",{style:fe,children:["Kioku installs it on this machine for every session.",e.includes("-")?" Back to stable undoes it.":""]})]})})},yi=({mismatch:e,tool:n,onTry:a})=>{const[r,o]=m(!1),{fix:s}=e,c=async()=>{o(!0),await Rt(`${ln(e.plugin)}/update`,{scope:e.scope,scopeRef:e.scopeRef})&&(j(`Kioku's plugin updated in ${e.scopeRef} · applies to new sessions`,"success"),await Sr()),o(!1)};let i=null;return(s==null?void 0:s.kind)==="release"&&(i=t(I,{label:`Try ${s.version}`,variant:"primary",size:"sm",onClick:()=>a(s.version)})),(s==null?void 0:s.kind)==="plugin"&&(i=t(I,{label:r?"Updating…":"Update plugin",variant:"primary",size:"sm",disabled:r,onClick:c})),l("div",{class:"flex flex-col",style:{gap:"4px"},children:[l("div",{class:"flex items-center",style:{gap:"10px"},children:[l("span",{class:"flex-1",children:[e.scopeRef,": plugin ",t("span",{class:"mono",children:e.version}),", tool ",t("span",{class:"mono",children:n})]}),i]}),s?t(Ae,{text:s.command}):t("span",{style:fe,children:"No kioku release of that major yet."})]})},bi=({onTry:e})=>{const n=$t.value;return!(n!=null&&n.installed)||n.mismatches.length===0?null:l("section",{class:"flex flex-col",style:{...oe,gap:"8px",background:Q("--orange")},children:[t("p",{style:{fontWeight:600},children:"Kioku does nothing in these sessions: its plugin and the tool have different major versions."}),n.mismatches.map(a=>t(yi,{mismatch:a,tool:n.installed,onTry:e},`${a.scope}:${a.scopeRef}`))]})},ki=({lab:e})=>{const[n,a]=m(!1),r=async o=>{a(!0);try{ca.value=await ce(`/api/kioku/labs/${encodeURIComponent(e.name)}`,{enabled:o}),j(`${e.title} ${o?"on":"off"} · applies from the next session`,"info")}catch(s){j(le(s),"error")}finally{a(!1)}};return l("div",{class:"flex flex-col",style:{...lo,gap:"6px"},children:[l("div",{class:"flex items-center",style:{gap:"10px"},children:[t("span",{style:{fontWeight:600},children:e.title}),t("span",{class:"flex-1"}),t(jt,{checked:e.enabled,disabled:n,label:`${e.title} enabled`,onChange:r})]}),e.about&&t("p",{style:{color:"var(--ink-2)"},children:e.about}),t(Ae,{text:e.toggle}),e.command&&l("div",{class:"flex items-center",style:{gap:"8px"},children:[t("span",{style:fe,children:"In a session"}),t(Ae,{text:e.command}),t(Zn,{command:e.command,plugin:"kioku",disabled:!e.enabled,note:"A session has it only when it was opened after the lab was switched on."})]}),Object.entries(e.settings??{}).map(([o,s])=>{var c;return l("div",{class:"flex items-center",style:{gap:"8px"},children:[t("span",{class:"mono",style:fe,children:o}),t("span",{class:"mono",children:JSON.stringify(s)}),t("span",{class:"flex-1"}),((c=e.set)==null?void 0:c[o])&&t(Ae,{text:e.set[o]})]},o)})]})},wi=()=>{var n,a;const e=ca.value;return(n=e==null?void 0:e.labs)!=null&&n.length?t(so,{title:`LABS · ${((a=$t.value)==null?void 0:a.installed)??""}`,aside:t("span",{style:fe,children:"off by default, may change in any version"}),command:e.command,children:e.labs.map(r=>t(ki,{lab:r},r.name))}):null},Si=[{label:"Personal",tiers:["personal"]},{label:"Projects",tiers:["project","client"]},{label:"Team",tiers:["team"]}],Ci={save:"--green",update:"--blue",supersede:"--blue",evolve:"--purple",link:"--teal",confirm:"--green",retire:"--red",forget:"--red"},$i=({brain:e})=>{const n=Object.entries(e.kinds).filter(([,a])=>a>0).sort((a,r)=>r[1]-a[1]);return l(U,{children:[t("div",{class:"flex overflow-hidden",style:{height:"6px",borderRadius:"99px",background:"var(--elev)"},children:n.map(([a,r])=>t("span",{title:`${a} ${r}`,style:{width:`${r/e.pages*100}%`,background:`var(${va(a)})`}},a))}),t("div",{class:"flex flex-wrap",style:{gap:"3px 10px",fontSize:"11px",color:"var(--ink-2)"},children:n.slice(0,3).map(([a,r])=>l("span",{class:"inline-flex items-center",style:{gap:"4px"},children:[t(ze,{color:`var(${va(a)})`}),a," ",r]},a))})]})},Na={fontSize:"11.5px",fontWeight:500,color:"var(--blue)",background:"none",border:0,padding:0,cursor:"pointer"},Oa=({brain:e,usedBy:n,showTier:a,onDialog:r})=>{const o=Ve(e.tier);return l("div",{class:"flex flex-col min-w-0",style:{...Le,gap:"9px",padding:"14px 16px",borderTop:`3px solid var(${o})`},children:[l("div",{class:"flex items-center",style:{gap:"8px"},children:[a&&t("span",{style:{fontSize:"10.5px",fontWeight:700,letterSpacing:".04em",textTransform:"uppercase",color:`var(${o})`},children:e.tier}),t("span",{class:"truncate",style:{fontSize:"14.5px",fontWeight:600},title:e.folder,children:re(e)}),t("span",{class:"flex-1"}),t("span",{style:{fontSize:"11.5px",color:"var(--ink-3)"},children:e.onDisk?e.touched?At(e.touched):"quiet":"not on disk"})]}),l("div",{style:{fontSize:"26px",fontWeight:700,lineHeight:1},children:[e.pages," ",t("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--ink-3)"},children:"pages"})]}),e.pages>0&&t($i,{brain:e}),n&&t("div",{class:"flex flex-wrap",style:{gap:"4px"},children:e.tier==="personal"?t("span",{style:{fontSize:"11.5px",color:"var(--ink-3)"},children:"loads in every session"}):n.length===0?t("span",{style:{fontSize:"11.5px",color:"var(--ink-3)"},children:"no CW project loads it"}):n.map(s=>t(He,{label:s,variant:"neutral"},s))}),e.onDisk&&l("div",{class:"flex items-center",style:{gap:"12px",paddingTop:"8px",marginTop:"auto",borderTop:"1px solid var(--hair)"},children:[t("button",{type:"button",style:Na,onClick:()=>r({kind:"area",brain:e}),children:"+ Area"}),t("span",{class:"flex-1"}),!e.remote&&l(U,{children:[t("span",{style:{fontSize:"11.5px",color:"var(--ink-3)"},children:"only on this machine"}),t("button",{type:"button",style:Na,onClick:()=>r({kind:"publish",brain:e}),children:"Publish…"})]})]})]})},zi=({writes:e})=>l("section",{style:{...Le,overflow:"hidden"},children:[t("h2",{style:{padding:"12px 16px 6px",fontSize:"11px",fontWeight:600,letterSpacing:".02em",color:"var(--ink-3)"},children:"RECENT ACTIVITY · LAST 2 WEEKS"}),e.length===0&&t("p",{style:{padding:"4px 16px 14px",fontSize:"12.5px",color:"var(--ink-3)"},children:"Nothing written lately."}),e.map(n=>l("div",{class:"flex items-center",style:{gap:"10px",padding:"9px 16px",borderTop:"1px solid var(--hair)",fontSize:"12.5px"},children:[t("span",{class:"shrink-0 flex justify-center",style:{width:"76px"},children:t(He,{label:n.verb,color:`var(${Ci[n.verb]??"--ink-2"})`})}),t("span",{class:"truncate flex-1",title:n.path,children:n.title}),l("span",{class:"shrink-0",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:[n.brain,n.author?` · ${n.author}`:""," · ",At(n.date)]})]},`${n.brain}:${n.path}:${n.date}:${n.verb}`))]}),Ri=({project:e,onProject:n})=>{const[a,r]=m(!1),[o,s]=m(null),c=()=>s(null);D(()=>Cr(),[]);const i=ke.value,d=(i==null?void 0:i.installed)===!0;D(()=>{d&&Hn(!1,!e)},[d,e]);const h=k=>s({kind:"version",version:k}),f=async()=>{const k=window.open("","_blank");r(!0);try{const{address:u}=await ce("/api/kioku/viewer",{});k?k.location.href=u:j(`Viewer running at ${u}`,"info"),Pe()}catch(u){k==null||k.close(),j(le(u),"error")}finally{r(!1)}},v=async()=>{await fetch("/api/kioku/viewer",{method:"DELETE"}).catch(()=>{}),Pe()},x=(i==null?void 0:i.brains)??[],S=(i==null?void 0:i.projects)??{},b=Object.keys(S).filter(k=>S[k].some(u=>u.tier!=="personal")).sort();e&&!b.includes(e)&&b.unshift(e);const y=e?da(e):[],p=k=>Object.keys(S).filter(u=>S[u].some(z=>z.name===re(k))).sort(),w=new Set(y.map(re)),$=((i==null?void 0:i.activity)??[]).filter(k=>!e||w.has(k.brain)).slice(0,15),g=d?e?`${e} · ${an(y)} pages its sessions can recall`:`Kioku ${i.version??""} · ${an(x)} pages in ${x.length} brain${x.length===1?"":"s"}`:"Kioku brains on this machine";return l(U,{children:[l(tt,{title:"Memory",subtitle:g,children:[(i==null?void 0:i.viewer)&&t(I,{label:"Stop viewer",variant:"secondary",onClick:v}),t(I,{label:"Refresh",variant:"secondary",onClick:()=>Pe(!0).then(()=>d&&Hn(!0,!e))}),t(I,{label:"New brain",variant:"secondary",disabled:!d,onClick:()=>s({kind:"brain"})}),t(I,{label:"New memory",variant:"secondary",disabled:!x.some(k=>k.onDisk),onClick:()=>s({kind:"memory"})}),t(I,{label:i!=null&&i.viewer?"Viewer open ↗":"Open viewer",variant:"primary",disabled:!d||a,onClick:f})]}),l("div",{class:"flex flex-col w-full",style:{padding:"18px 22px 40px",gap:"14px",maxWidth:"1180px"},children:[i&&!i.installed&&l("p",{style:{...oe,background:Q("--red")},children:["Kioku is not installed. Install it from ",t("code",{children:"monoku/kioku"})," with its ",t("code",{children:"install.sh"}),", which puts ",t("code",{children:"kioku"})," in ",t("code",{children:"~/.local/bin"}),"."]}),d&&t(bi,{onTry:h}),d&&!e&&l("div",{class:"grid items-start",style:{gridTemplateColumns:"repeat(auto-fit, minmax(min(100%, 380px), 1fr))",gap:"12px"},children:[t(mi,{onTry:h}),t(wi,{})]}),d&&x.length===0&&t(Oe,{icon:"i-lucide-brain",title:"No brains yet",description:"New brain makes one on this machine: a personal one for what you learn anywhere, a project or team one to share."}),x.length>0&&b.length>0&&t("div",{class:"flex",children:t(de,{size:"sm",label:"Project",tabs:[{id:"",label:"All"},...b.map(k=>({id:k,label:k}))],active:e??"",onChange:k=>n(k||null)})}),x.length>0&&!e&&t("div",{class:"flex flex-wrap",style:{gap:"14px 12px"},children:Si.map(k=>{const u=x.filter(z=>k.tiers.includes(z.tier??""));return u.length===0?null:l("section",{class:"flex flex-col min-w-0",style:{gap:"8px",flex:`${u.length} 1 ${u.length*250}px`},children:[l("h2",{class:"flex items-center",style:{gap:"8px",fontSize:"11px",fontWeight:600,letterSpacing:".03em",color:`var(${Ve(k.tiers[0])})`},children:["● ",k.label.toUpperCase(),u.length>1&&t("span",{style:{color:"var(--ink-3)"},children:u.length})]}),t("div",{class:"grid",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))",gap:"12px"},children:u.map(z=>t(Oa,{brain:z,usedBy:p(z),onDialog:s},z.key))})]},k.label)})}),e&&y.length>0&&t("div",{class:"grid items-center",style:{gridTemplateColumns:y.map(()=>"minmax(0, 1fr)").join(" 24px ")},children:y.map((k,u)=>l(ho,{children:[u>0&&t("span",{style:{textAlign:"center",color:"var(--ink-3)",fontSize:"16px"},children:"→"}),t(Oa,{brain:k,showTier:!0,onDialog:s})]},k.key))}),e&&d&&!y.some(k=>k.tier!=="personal")&&l("div",{class:"flex items-center",style:{...oe,gap:"12px",background:"var(--elev)",color:"var(--ink-2)"},children:[l("span",{class:"flex-1",children:[e," has no project or team brain, so its sessions recall only yours."]}),t(I,{label:"Give it a brain",variant:"secondary",size:"sm",onClick:()=>s({kind:"link"})})]}),x.length>0&&t(zi,{writes:$}),d&&l("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:["Open viewer starts ",t("code",{children:"kioku web"}),": the graph of every page, each page with its history, lint and the latest changes. It opens in its own tab and stops with Forge."]})]}),(o==null?void 0:o.kind)==="memory"&&t(gi,{project:e,onClose:c}),(o==null?void 0:o.kind)==="brain"&&t(pi,{onClose:c}),(o==null?void 0:o.kind)==="link"&&e&&t(ui,{project:e,onClose:c}),(o==null?void 0:o.kind)==="area"&&t(ro,{brain:o.brain,onClose:c}),(o==null?void 0:o.kind)==="publish"&&t(hi,{brain:o.brain,onClose:c}),(o==null?void 0:o.kind)==="version"&&t(vi,{version:o.version,onClose:c})]})},aa=({value:e,onChange:n,initialPath:a,requireGit:r=!0})=>{const[o,s]=m(a??"~"),[c,i]=m(o),[d,h]=m([]),[f,v]=m(null),[x,S]=m(null),[b,y]=m(""),[p,w]=m(!1),[$,g]=m(!1),[k,u]=m(null);D(()=>{let A=!1;return(async()=>{g(!0),u(null);try{const q=await(await fetch(`/api/cw/browse-dirs?path=${encodeURIComponent(o)}`)).json();if(A)return;if(!q.ok){u(q.error??"Failed to load directory"),h([]);return}h(q.entries??[]),v(q.parent??null),S(q.home??null),y(q.path??o),w(!!q.isGitRepo)}catch{A||(u("Network error"),h([]))}finally{A||g(!1)}})(),()=>{A=!0}},[o]);const z=A=>{s(A),i(A)},E=e===b,L=r&&!p,O=b?x&&b===x?"~":x&&b.startsWith(x+"/")?"~"+b.slice(x.length):b:o,R={width:"24px",height:"24px",borderRadius:"7px",border:0,background:"var(--card)",color:"var(--ink-2)",boxShadow:"var(--shadow-s)"},P="flex items-center w-full text-left cursor-pointer transition-colors duration-140 hover:bg-elev disabled:cursor-not-allowed disabled:opacity-60",T={gap:"8px",padding:"7px 11px",border:0,borderBottom:"1px solid var(--hair)",background:"none",color:"var(--ink)",fontSize:"12.5px"},B={padding:"1px 7px",borderRadius:"99px",background:Q("--green"),color:"var(--green)",fontSize:"10.5px",fontWeight:600};return l("div",{style:{borderRadius:"12px",border:"1px solid var(--hair)",background:"var(--card)",boxShadow:"var(--shadow-s)",overflow:"hidden"},children:[l("div",{class:"flex items-center",style:{gap:"6px",padding:"7px 9px",borderBottom:"1px solid var(--hair)",background:"var(--elev)"},children:[t("button",{type:"button",class:"grid place-items-center cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:R,onClick:()=>f&&z(f),disabled:!f||$,title:"Parent folder","aria-label":"Parent folder",children:"←"}),t("button",{type:"button",class:"grid place-items-center cursor-pointer",style:R,onClick:()=>z("~"),title:"Home","aria-label":"Home",children:"~"}),t("input",{type:"text",value:c,"aria-label":"Path",onInput:A=>i(A.target.value),onBlur:()=>s(c),onKeyDown:A=>{A.key==="Enter"&&s(c)},class:"field mono flex-1 min-w-0",style:{height:"26px",padding:"0 9px",borderRadius:"7px",border:"1px solid var(--hair)",background:"var(--bg-2)",color:"var(--ink)",fontSize:"11.5px",outline:"none"},placeholder:"~/workspace"})]}),e&&l("div",{class:"flex items-center",style:{gap:"8px",padding:"7px 11px",borderBottom:"1px solid var(--hair)",background:Q("--blue",12),fontSize:"12px"},children:[t("span",{class:"i-lucide-check shrink-0",style:{width:"13px",height:"13px",color:"var(--blue)"}}),t("span",{class:"mono flex-1 truncate",children:e}),t("button",{type:"button",class:"grid place-items-center cursor-pointer text-ink3 hover:text-ink",style:{border:0,background:"none"},onClick:()=>n("",!1),title:"Clear selection","aria-label":"Clear selection",children:t("span",{class:"i-lucide-x",style:{width:"13px",height:"13px"}})})]}),t("div",{class:"overflow-y-auto",style:{maxHeight:"220px"},children:$?t("p",{style:{padding:"12px",fontSize:"12.5px",color:"var(--ink-2)"},children:"Loading…"}):k?t("p",{style:{padding:"12px",fontSize:"12.5px",color:"var(--red)"},children:k}):l(U,{children:[l("button",{type:"button",class:P,style:{...T,background:E?"var(--elev)":"none",fontWeight:600},onClick:()=>n(b,p),disabled:L,title:L?"Not a git repository":"Pick this folder",children:[t("span",{class:"i-lucide-check shrink-0",style:{width:"12px",height:"12px",color:"var(--blue)"}}),l("span",{class:"flex-1 truncate",children:["Pick ",t("span",{class:"mono",children:O})]}),p?t("span",{style:B,children:"git"}):L?t("span",{style:{fontSize:"11px",color:"var(--ink-3)"},children:"no .git"}):null]}),d.length===0?t("p",{style:{padding:"12px",fontSize:"12.5px",color:"var(--ink-3)"},children:"No subfolders"}):d.map(A=>l("button",{type:"button",class:P,style:T,onClick:()=>z(A.path),children:[t("span",{class:"i-lucide-chevron-right shrink-0",style:{width:"12px",height:"12px",color:"var(--ink-3)"}}),t("span",{class:"mono flex-1 truncate",children:A.name}),A.isGitRepo&&t("span",{style:B,children:"git"})]},A.path))]})})]})},io={fontSize:"11.5px",color:"var(--red)"},Wa=e=>e.type==="boolean"||e.type==="string"&&e.format==="path",Da=({def:e,value:n,projects:a,onChange:r})=>e.type==="boolean"?t(jt,{checked:n===!0,onChange:r,label:e.label}):e.type==="enum"?t("select",{class:"field",value:typeof n=="string"?n:"",onChange:o=>r(ae(o)),children:e.values.map(o=>t("option",{value:o,children:o},o))}):e.type==="number"?t("input",{type:"number",class:"field",value:typeof n=="number"?n:"",min:e.min,max:e.max,onInput:o=>{const s=ae(o);r(s===""?void 0:Number(s))}}):e.format==="cw-project"?l("select",{class:"field",value:typeof n=="string"?n:"",onChange:o=>r(ae(o)||void 0),children:[t("option",{value:"",children:"None"}),a.map(o=>t("option",{value:o,children:o},o))]}):e.format==="path"?t(aa,{value:typeof n=="string"?n:"",onChange:o=>r(o),requireGit:!1}):t("input",{type:e.format==="url"?"url":"text",class:"field",value:typeof n=="string"?n:"",onInput:o=>r(ae(o))}),Ma=({def:e,error:n,plain:a,children:r})=>l(H,{plain:a,label:l(U,{children:[e.label??"",e.required?" *":""]}),children:[r,e.help&&t("span",{style:ye,children:e.help}),n&&t("span",{style:io,children:n})]}),Ti=({moduleId:e,displayName:n,schema:a,banner:r,onClose:o,onSaved:s})=>{const[c,i]=m(null),[d,h]=m({}),[f,v]=m([]),[x,S]=m(!1),[b,y]=m((r==null?void 0:r.enabled)===!0),p=`/api/modules/${encodeURIComponent(e)}/settings`;D(()=>{fetch(p).then(k=>k.json()).then(i).catch(()=>i({})),fetch("/api/cw/projects").then(k=>k.json()).then(k=>v(Object.keys(k))).catch(()=>{})},[p]);const w=(k,u)=>i(z=>({...z,[k]:u})),$=(k,u,z,E)=>i(L=>{const O=[...(L==null?void 0:L[k])??[]];return O[u]={...O[u],[z]:E},{...L,[k]:O}}),g=async()=>{S(!0);try{if(r&&b!==r.enabled&&await et("PUT",`/api/modules/${encodeURIComponent(e)}/banner`,{enabled:b}),Object.keys(a).length===0){j(`${n} settings saved`,"success"),s(),o();return}const k=await fetch(p,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)});if(k.status===400){const{errors:u}=await k.json();h(Object.fromEntries(u.map(z=>[z.path,z.message])));return}if(!k.ok)throw new Error(`Saving failed (${k.status})`);h({}),j(`${n} settings saved`,"success"),s(),o()}catch(k){j(le(k),"error")}finally{S(!1)}};return t(Ze,{title:`${n} settings`,onClose:o,children:c?l("div",{class:"flex flex-col",style:{gap:"14px"},children:[r&&t(jt,{checked:b,onChange:y,label:"Show on task list"}),Object.entries(a).map(([k,u])=>{if(u.type!=="list")return t(Ma,{def:{...u,label:u.label??k},error:d[k],plain:Wa(u),children:t(Da,{def:u,value:c[k],projects:f,onChange:E=>w(k,E)})},k);const z=c[k]??[];return l("div",{class:"flex flex-col",style:{gap:"10px"},children:[t("span",{style:{...ye,fontWeight:600},children:u.label??k}),u.help&&t("span",{style:ye,children:u.help}),d[k]&&t("span",{style:io,children:d[k]}),z.map((E,L)=>l("div",{class:"flex flex-col",style:{gap:"10px",padding:"12px",borderRadius:"12px",background:"var(--card)",border:"1px solid var(--hair)"},children:[Object.entries(u.item).map(([O,R])=>t(Ma,{def:{...R,label:R.label??O},error:d[`${k}[${L}].${O}`],plain:Wa(R),children:t(Da,{def:R,value:E[O],projects:f,onChange:P=>$(k,L,O,P)})},O)),t("div",{children:t(I,{label:"Remove",variant:"danger",size:"sm",onClick:()=>i(O=>({...O,[k]:z.filter((R,P)=>P!==L)}))})})]},L)),t("div",{children:t(I,{label:`Add ${(u.label??k).replace(/s$/,"").toLowerCase()}`,icon:"i-lucide-plus",variant:"secondary",size:"sm",onClick:()=>w(k,[...z,{}])})})]},k)}),l("div",{class:"flex",style:{gap:"8px",marginTop:"6px"},children:[t("span",{class:"flex-1"}),t(I,{label:"Cancel",variant:"secondary",onClick:o}),t(I,{label:"Save",loading:x,onClick:g})]})]}):t("div",{class:"text-ink2",style:{fontSize:"13px"},children:"Loading…"})})},En=({title:e,message:n,onReload:a})=>l("div",{style:{margin:"24px 22px",padding:"16px 18px",borderRadius:"14px",background:"var(--card)",border:"1px solid color-mix(in srgb, var(--red) 45%, var(--hair))"},children:[t("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--red)"},children:e}),t("pre",{class:"mono",style:{marginTop:"8px",fontSize:"12px",color:"var(--ink-2)",whiteSpace:"pre-wrap"},children:n}),t("div",{style:{marginTop:"12px"},children:t(I,{label:"Reload view",variant:"secondary",size:"sm",onClick:a})})]}),ji=({status:e,onClose:n,onRemoved:a})=>{const[r,o]=m(!1),s=async()=>{o(!0);try{ve.value=await et("DELETE",`/api/modules/${encodeURIComponent(e.id)}`),j(`Removed ${e.displayName}`,"success"),a()}catch(c){j(le(c),"error"),o(!1)}};return t(Re,{open:!0,title:`Remove ${e.displayName}?`,onClose:n,footer:l(U,{children:[t("span",{class:"flex-1"}),t(I,{label:"Cancel",variant:"secondary",onClick:n}),t(I,{label:"Remove",variant:"destructive",loading:r,onClick:s})]}),children:l("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:["Forge uninstalls ",t("span",{class:"mono",children:e.name})," and stops it now. Its settings stay saved, so installing it again brings them back."]})})},Pi=({moduleId:e,cwProject:n,onBack:a})=>{var u,z,E,L;const r=ve.value.find(O=>O.id===e),[o,s]=m(!1),[c,i]=m(!1),[d,h]=m(null),[f,v]=m(0),x=se(e);r&&(x.current=r.displayName);const S=x.current,b=ee(()=>Kr(e,()=>x.current,()=>s(!0)),[e]),y=(r==null?void 0:r.state)==="enabled"?(u=r.view)==null?void 0:u.version:void 0,p=((z=ur.value[e])==null?void 0:z.attention)??0;D(()=>{p>0&&Xo(e)},[e,p]),D(()=>{if(!r||!y)return;let O=!0;return _r(r.view.url,r.view.version).then(R=>{O&&h({version:y,config:R})},R=>{O&&h({version:y,error:R.message})}),()=>{O=!1}},[e,y,f]);const w=r?pr(r):null,$=l(tt,{title:((E=r==null?void 0:r.view)==null?void 0:E.title)??S,subtitle:r?`${r.name} ${r.version}`:void 0,children:[w&&l("span",{class:"mono truncate",title:w,style:{maxWidth:"320px",fontSize:"11.5px",color:"var(--orange)"},children:["⚠ ",w]}),((r==null?void 0:r.settingsSchema)&&Object.keys(r.settingsSchema).length>0||(r==null?void 0:r.banner))&&t(I,{label:"Settings",icon:"i-lucide-settings",variant:"secondary",size:"sm",onClick:()=>s(!0)}),(r==null?void 0:r.removable)&&t(I,{label:"Remove",icon:"i-lucide-trash-2",variant:"secondary",size:"sm",onClick:()=>i(!0)}),c&&r&&t(ji,{status:r,onClose:()=>i(!1),onRemoved:a})]});if(!r)return l("div",{children:[$,t("div",{style:{padding:"56px 22px"},children:t(Oe,{icon:"i-lucide-package-x",title:`${S} was removed`,description:"The module is no longer installed.",action:{label:"Back to Tasks",onClick:a}})})]});if(r.state!=="enabled")return l("div",{children:[$,t(En,{title:`${S} is disabled`,message:r.reason??"No reason given",onReload:()=>{kt()}})]});const g=d&&d.version===y?d:null,k=(L=g==null?void 0:g.config)==null?void 0:L.component;return l("div",{children:[$,g!=null&&g.error?t(En,{title:`${S}'s view did not load`,message:g.error,onReload:()=>v(O=>O+1)}):k?t(Dr,{fallback:O=>t(En,{title:`${S}'s view crashed`,message:O.message,onReload:()=>v(R=>R+1)}),children:t(k,{moduleId:e,projectId:null,cwProject:n,forge:b})},`${y}-${f}`):l("div",{class:"py-20 text-center text-ink2",children:["Loading ",S,"…"]}),o&&(r.settingsSchema||r.banner)&&t(Ti,{moduleId:e,displayName:S,schema:r.settingsSchema??{},banner:r.banner,onClose:()=>s(!1),onSaved:()=>{b.reloadSettings(),kt()}})]})},Ln={padding:"12px 14px",borderRadius:"12px",background:"var(--card)",border:"1px solid var(--hair)"},Ai=({onClose:e,onInstalled:n})=>{const[a,r]=m(""),[o,s]=m(null),[c,i]=m(null),[d,h]=m(null),f=async()=>{h("preview"),i(null);try{s(await ce("/api/modules/install/preview",{spec:a}))}catch(x){i(le(x))}finally{h(null)}},v=async()=>{if(o){h("install"),i(null);try{const{status:x,modules:S}=await ce("/api/modules/install",{token:o.token});ve.value=S,(x==null?void 0:x.state)==="disabled"?j(`Installed ${o.displayName}, but Forge disabled it: ${x.reason??""}`,"error"):j(`Installed ${o.displayName}`,"success"),x&&n(x),e()}catch(x){s(null),i(le(x))}finally{h(null)}}};return l(Ze,{title:"Add a module",onClose:e,children:[l("form",{class:"flex flex-col",style:{gap:"10px"},onSubmit:x=>{x.preventDefault(),a.trim()&&!d&&f()},children:[t(H,{label:"npm package, folder or git url",children:t("input",{class:"field mono",value:a,placeholder:"@scope/forge-mod-name",autoFocus:!0,spellcheck:!1,onInput:x=>{r(ae(x)),s(null)}})}),t("span",{style:ye,children:"Forge reads the module's manifest first; none of its code runs until you install it."})]}),c&&t("div",{role:"alert",class:"mono",style:{...Ln,fontSize:"12px",color:"var(--red)",whiteSpace:"pre-wrap",borderColor:"color-mix(in srgb, var(--red) 45%, var(--hair))"},children:c}),o&&l("div",{class:"flex flex-col",style:{gap:"12px"},children:[l("div",{style:Ln,children:[t("div",{style:{fontSize:"15px",fontWeight:650},children:o.displayName}),l("div",{class:"mono",style:{marginTop:"2px",fontSize:"11.5px",color:"var(--ink-3)"},children:[o.name," ",o.version,o.kind==="legacy"?" · legacy module":""]}),o.description&&t("p",{style:{marginTop:"8px",fontSize:"13px",color:"var(--ink-2)"},children:o.description})]}),o.banner&&t("span",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:"Adds a banner to the task list"}),l("div",{class:"flex flex-col",style:{gap:"6px"},children:[t("span",{style:{...ye,fontWeight:600},children:o.permissions.length?"It asks for":"It asks for no permissions"}),o.permissions.map((x,S)=>l("div",{class:"flex",style:{gap:"10px",fontSize:"12.5px"},children:[t("span",{class:"mono shrink-0",style:{width:"64px",color:"var(--ink-3)"},children:x.kind}),t("span",{class:"mono",style:{wordBreak:"break-all"},children:x.value})]},S))]}),t("p",{style:{...Ln,fontSize:"12.5px",color:"var(--ink-2)",borderColor:"color-mix(in srgb, var(--orange) 45%, var(--hair))"},children:o.trustNote}),l("span",{class:"mono",style:{fontSize:"11px",color:"var(--ink-3)",wordBreak:"break-all"},children:["npm install ",o.spec]})]}),l("div",{class:"flex",style:{gap:"8px"},children:[t("span",{class:"flex-1"}),t(I,{label:"Cancel",variant:"secondary",onClick:e}),o?t(I,{label:`Install ${o.displayName}`,loading:d==="install",onClick:v}):t(I,{label:"Review",loading:d==="preview",disabled:!a.trim(),onClick:f})]})]})},Ii=({open:e,accounts:n,onClose:a,onCreated:r})=>{const[o,s]=m("create"),[c,i]=m(""),[d,h]=m(""),[f,v]=m(""),[x,S]=m(""),[b,y]=m(""),[p,w]=m(""),[$,g]=m(!1),[k,u]=m(""),[z,E]=m(!1);D(()=>{e&&n.length>0&&!c&&i(n[0])},[e,n]),D(()=>{e||(s("create"),h(""),v(""),S(""),y(""),w(""),g(!1),u(""),E(!1))},[e]);const L=c.trim().length>0&&d.trim().length>0&&x.trim().length>0,O=c.trim().length>0&&p.length>0&&$,R=async()=>{if(L){E(!0);try{const F=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"create",project:d.trim(),task:d.trim(),description:x.trim(),account:c.trim()||void 0,directory:f.trim()||void 0,model:b||void 0})})).json();F.ok?(j("Project creation started in terminal","success"),r(F.session)):j(F.error??"Failed to create project","error")}catch{j("Failed to create project","error")}finally{E(!1)}}},P=async()=>{if(O){E(!0);try{const F=await(await fetch("/api/cw/register-project",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:p,account:c.trim(),alias:k.trim()||void 0})})).json();F.ok?(j(`Project "${F.project}" registered`,"success"),r()):j(F.error??"Failed to register project","error")}catch{j("Failed to register project","error")}finally{E(!1)}}},T=o==="create";return t(Re,{open:e,title:"Add a project",onClose:a,footer:l(U,{children:[t("span",{class:"mono flex-1 truncate",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:T?"cw create":"cw project register"}),t(I,{label:"Cancel",variant:"secondary",onClick:a}),t(I,{label:T?z?"Creating…":"Create":z?"Registering…":"Register",variant:"primary",loading:z,disabled:!(T?L:O),onClick:T?R:P})]}),children:l("div",{class:"flex flex-col",style:{gap:"13px"},children:[t(de,{fill:!0,label:"Mode",tabs:[{id:"create",label:"Create new"},{id:"existing",label:"Register existing"}],active:o,onChange:M=>s(M)}),l("div",{class:"grid",style:{gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:"10px"},children:[t(H,{label:"Account",children:n.length>0?t("select",{class:"field",value:c,onChange:M=>i(M.target.value),children:n.map(M=>t("option",{value:M,children:M},M))}):t("input",{type:"text",class:"field",value:c,placeholder:"account-name",onInput:M=>i(M.target.value)})}),T?t(H,{label:"Project name",children:t("input",{type:"text",class:"field",value:d,placeholder:"my-new-project",onInput:M=>h(M.target.value)})}):t(H,{label:"Alias",children:t("input",{type:"text",class:"field",value:k,placeholder:"defaults to folder name",onInput:M=>u(M.target.value)})})]}),l("div",{class:"flex flex-col",style:{gap:"5px"},children:[t("span",{style:ye,children:T?"Parent folder · optional":"Repository · must contain .git"}),T?t(aa,{value:f,onChange:v,requireGit:!1},"dir-create"):t(aa,{value:p,onChange:(M,F)=>{w(M),g(F)}},"dir-existing")]}),T&&l(U,{children:[t(H,{label:"Description",children:t("textarea",{rows:2,class:"field",value:x,placeholder:"A SaaS platform for…",onInput:M=>S(M.target.value)})}),l("div",{class:"flex flex-col",style:{gap:"5px"},children:[t("span",{style:ye,children:"Model"}),t(de,{size:"sm",label:"Model",tabs:[{id:"",label:"Auto"},{id:"haiku",label:"Haiku"},{id:"sonnet",label:"Sonnet"},{id:"opus",label:"Opus"}],active:b,onChange:y})]})]})]})})},Ei=(e,n)=>{if(n)return{kind:"connecting"};const a=typeof e.detail=="string"?e.detail:"",r=[e.provider,e.model].filter(Boolean).join(" · ");if(e.status==="not_installed")return{kind:"not_installed",detail:a};if(e.status==="error")return{kind:"error",detail:a};if(e.status==="local"){const o=e.detail&&typeof e.detail=="object"?e.detail:null;return{kind:"local",providerModel:r,reachable:(o==null?void 0:o.reachable)??null,pulled:(o==null?void 0:o.model_pulled)??null}}return e.status==="connected"&&(e.provider_kind==="api"||e.has_api_key)?{kind:"api_key",providerModel:e.provider!=="native"?r:null}:e.status==="connected"?{kind:"connected"}:{kind:"connect"}},Li=(e,n,a,r)=>{const o=[];switch(e.kind){case"connecting":o.push("Waiting for the login to finish");break;case"not_installed":o.push(e.detail||"Not on PATH");break;case"error":o.push(e.detail||"cw doctor reported an error");break;case"local":{const s=[e.reachable===null?null:e.reachable?"reachable":"unreachable",e.pulled===null?null:e.pulled?"model pulled":"model not pulled"].filter(Boolean).join(", ");o.push(...[e.providerModel,s].filter(Boolean));break}case"api_key":o.push(...[e.providerModel,"stored by cw"].filter(s=>!!s));break;case"connected":o.push(...[r.model,n].filter(s=>!!s)),o.length===0&&o.push("Signed in");break;case"connect":o.push(a?"Not logged in — device code, no terminal needed":"Not logged in");break}return r.unofficial&&o.push("unofficial"),o.join(" · ")},_e=({token:e,label:n})=>l("span",{class:"inline-flex items-center shrink-0 whitespace-nowrap",style:{gap:"6px",padding:"3px 10px",borderRadius:"99px",fontSize:"11.5px",fontWeight:600,background:e?Q(e):"var(--elev)",color:e?`var(${e})`:"var(--ink-3)"},children:[t("span",{style:{width:"6px",height:"6px",borderRadius:"50%",background:"currentColor"}}),n]}),Ni=({view:e,onConnect:n,onCancel:a})=>{switch(e.kind){case"connecting":return l("span",{class:"inline-flex items-center shrink-0",style:{gap:"8px"},children:[t(_e,{token:"--blue",label:"Connecting…"}),t("button",{type:"button",class:"cursor-pointer hover:text-ink",style:{border:0,background:"none",color:"var(--ink-2)",fontSize:"12px"},onClick:a,children:"Cancel"})]});case"not_installed":return t(_e,{token:null,label:"Not installed"});case"error":return t(_e,{token:"--red",label:"Error"});case"local":return t(_e,{token:"--orange",label:"Local"});case"api_key":return t(_e,{token:"--green",label:"API key"});case"connected":return t(_e,{token:"--green",label:"Connected"});case"connect":return t(I,{label:"Connect",size:"sm",onClick:n})}},Nn=({children:e})=>l("div",{class:"flex",style:{padding:"0 15px 11px"},children:[t("span",{class:"shrink-0",style:{width:"144px"}}),t("span",{class:"flex flex-col flex-1",style:{gap:"5px",minWidth:0},children:e})]}),On=({warn:e,children:n})=>t("span",{style:{fontSize:"11.5px",color:e?"var(--orange)":"var(--ink-3)"},children:n}),Oi=({account:e,harness:n})=>{const a=Bo(e,n);return!a||a.state==="not_connected"?null:a.state==="expired"?t(Nn,{children:t(On,{warn:!0,children:"Reconnect to see usage limits"})}):a.state==="error"?t(Nn,{children:l(On,{children:["Limits unavailable — ",a.detail??"the request failed"]})}):a.windows.length===0?null:l(Nn,{children:[t(Ka,{bars:Ya(a.windows)}),a.stale&&l(On,{children:["Last known values — ",a.detail??"the refresh failed"]})]})},Wi=3e3,Di=({account:e,harness:n,canUseApiKey:a,onConnected:r,onClose:o})=>{const[s,c]=m(null),[i,d]=m(!1),[h,f]=m(0),[v,x]=m(""),[S,b]=m(!1),y=ge(n).label,p=`/api/cw/accounts/${encodeURIComponent(e)}`,w=`${p}/login/${encodeURIComponent(n)}`,$=se(!1),g=se(!1);D(()=>{let E=!1,L=null;c(null),d(!1),$.current=!1,g.current=!1;const O=()=>{$.current||($.current=!0,fetch(w,{method:"DELETE"}).catch(()=>{}),j(`${e} is connected to ${y}`,"success"),r())},R=async()=>{var M;const T=await fetch(w).catch(()=>null);if(!(T!=null&&T.ok)||E)return;const{login:B}=await T.json();if(c(B),B.status!=="exited"||(g.current=!0,L&&(clearInterval(L),L=null),B.exitCode!==0))return;d(!0);const A=await be(!0);E||(A.available&&((M=We(A.doctor,e,n))==null?void 0:M.status)==="connected"?O():d(!1))};fetch(`${p}/login`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({harness:n})}).then(T=>T.json()).then(T=>{if(!E){if(!T.ok||!T.login){j(T.error??"Could not start the login","error");return}c(T.login),L=setInterval(R,Wi)}}).catch(()=>j("Could not start the login","error"));const P=il(T=>{var B;return((B=We(T,e,n))==null?void 0:B.status)==="connected"},{onDone:T=>{T&&O()}});return()=>{E=!0,L&&clearInterval(L),P(),g.current||fetch(w,{method:"DELETE"}).catch(()=>{})}},[e,n,h]);const k=()=>{fetch(w,{method:"DELETE"}).catch(()=>{}),o()},u=async()=>{const E=v.trim();if(E){b(!0);try{const O=await(await fetch(`${p}/api-key`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({harness:n,apiKey:E})})).json();O.ok?(x(""),j("API key saved","success"),be(!0)):j(O.error??"Could not save the API key","error")}catch{j("Could not save the API key","error")}finally{b(!1)}}},z=(s==null?void 0:s.status)==="exited";return l("div",{class:"flex flex-col",style:{gap:"12px",padding:"14px 16px",borderRadius:"16px",background:"var(--bg-2)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",animation:"riseIn .3s var(--ease) both"},children:[l("div",{class:"flex items-center",style:{gap:"10px"},children:[l("h3",{style:{fontSize:"14px",fontWeight:650},children:["Connect ",e," on ",y]}),t("span",{class:"flex-1"}),t(I,{label:"Cancel",variant:"secondary",size:"sm",onClick:k})]}),!s&&t("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:"Starting the login…"}),s&&!z&&l(U,{children:[l("div",{class:"flex flex-wrap items-center",style:{gap:"12px"},children:[s.url&&l("a",{href:s.url,target:"_blank",rel:"noopener noreferrer",class:"inline-flex items-center gap-1 transition-all duration-180 ease-spring hover:-translate-y-px hover:brightness-106",style:{padding:"6px 14px",borderRadius:"9px",background:"linear-gradient(180deg, var(--blue-2), var(--blue))",color:"#fff",fontSize:"12.5px",fontWeight:600,boxShadow:"var(--shadow-m)"},children:["Open login ",t("span",{class:"i-lucide-external-link",style:{width:"12px",height:"12px"}})]}),s.code&&l(U,{children:[t("span",{class:"mono",style:{fontSize:"19px",fontWeight:650,letterSpacing:".12em"},children:s.code}),t(I,{label:"Copy",variant:"secondary",size:"sm",onClick:()=>un(s.code??"","Code")})]})]}),s.code&&t("p",{style:{fontSize:"12px",color:"var(--ink-3)"},children:"If the code is rejected, use the one shown in Output."}),t("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:s.url||s.code?"Checks every 3 s. The status turns Connected on its own.":"Waiting for the login URL…"})]}),z&&i&&t("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:"Checking the connection…"}),z&&!i&&l("div",{class:"flex items-center",style:{gap:"10px",fontSize:"12.5px"},children:[t("span",{style:{color:"var(--red)"},children:"The login ended before connecting."}),t(I,{label:"Retry",variant:"secondary",size:"sm",onClick:()=>f(E=>E+1)})]}),s&&s.output.length>0&&l("details",{style:{fontSize:"12.5px"},children:[t("summary",{class:"cursor-pointer",style:{color:"var(--ink-2)"},children:"Output"}),t("pre",{class:"overflow-x-auto",style:{marginTop:"8px",padding:"10px 12px",borderRadius:"11px",background:"var(--term)",color:"#e3e3e8",fontSize:"11.5px"},children:s.output.join(`
27
+ `);try{const F=await ce("/api/kioku/pages",{brain:u.key,type:s,title:h,summary:v,body:M,namespace:E,create:A});F.status==="similar"?p(F.similar):F.status==="namespace"?j(`Pick an area of ${re(u)}`,"error"):(j(`Saved to ${F.brain}: ${F.path}`,"success"),Pe(!0),n())}catch(F){j(le(F),"error")}finally{$(!1)}};return l(Ze,{title:"New memory",onClose:n,children:[t(H,{label:"Brain",children:t("select",{class:"field",value:r,onChange:A=>{o(ae(A)),d(""),p(null)},children:a.map(A=>l("option",{value:A.key,children:[re(A)," · ",A.tier]},A.key))})}),u&&z.length===0&&l("div",{class:"flex items-center",style:{...oe,gap:"12px",background:Q("--orange")},children:[l("span",{class:"flex-1",children:[re(u)," has no areas yet. Each page goes in one, and a person names them."]}),t(I,{label:"Add area",variant:"secondary",size:"sm",onClick:()=>k(!0)})]}),z.length>1&&t(H,{label:"Area",children:l("select",{class:"field",value:i,onChange:A=>d(ae(A)),children:[t("option",{value:"",children:"Choose…"}),z.map(A=>t("option",{value:A,children:A},A))]})}),t("div",{class:"flex",children:t(de,{size:"sm",label:"Page type",tabs:Mt.map(A=>({id:A.id,label:A.label})),active:s,onChange:A=>{c(A),p(null)}})}),t(H,{label:"Title",children:t("input",{type:"text",class:"field",value:h,placeholder:"Payments retry at most three times",onInput:A=>{f(ae(A)),p(null)}})}),t(H,{label:"Summary · one line the agent reads first",children:t("input",{type:"text",class:"field",value:v,onInput:A=>x(ae(A))})}),R.map(A=>t(H,{label:A,children:t("textarea",{class:"field",rows:A==="Text"?8:3,value:S[A]??"",onInput:M=>b(F=>({...F,[A]:ae(M)}))})},`${s}:${A}`)),y&&l("div",{style:{...oe,background:Q("--orange")},children:[l("p",{style:{fontWeight:600,marginBottom:"6px"},children:[u?re(u):"The brain"," already has pages on this:"]}),t("ul",{class:"flex flex-col",style:{gap:"4px",paddingLeft:"16px",listStyle:"disc"},children:y.map(A=>l("li",{children:[t("b",{children:A.title}),A.summary?` — ${A.summary}`:""]},A.path))}),t("p",{style:{marginTop:"6px",color:"var(--ink-2)"},children:"Save it anyway to keep both; kioku links them under See also."})]}),(u==null?void 0:u.remote)&&l("p",{style:{fontSize:"12px",color:"var(--ink-3)"},children:["Kioku commits to ",re(u),"'s main branch and pushes it; it has no review step."]}),l("div",{class:"flex justify-end",style:{gap:"8px"},children:[t(I,{label:"Cancel",variant:"secondary",onClick:n}),t(I,{label:y?"Save anyway":"Save",variant:"primary",disabled:!P||w,onClick:()=>T(y!==null)})]}),g&&u&&t(ro,{brain:u,onClose:()=>k(!1)})]})},oo={fontSize:"11px",fontWeight:600,letterSpacing:".02em",color:"var(--ink-3)"},lo={gap:"10px",padding:"9px 16px",borderTop:"1px solid var(--hair)",fontSize:"12.5px"},fe={fontSize:"11.5px",color:"var(--ink-3)"},xi={updated:"--green",current:"--ink-3"},Ae=({text:e})=>l("div",{class:"flex items-center min-w-0",style:{gap:"6px"},children:[t("code",{class:"truncate",title:e,style:{fontSize:"11px",color:"var(--ink-2)",padding:"2px 6px",borderRadius:"6px",background:"var(--elev)"},children:e}),t("button",{type:"button","aria-label":"Copy command",title:"Copy command",class:"grid place-items-center shrink-0 cursor-pointer hover:text-ink",style:{padding:"2px",color:"var(--ink-3)",background:"none",border:0},onClick:()=>un(e,"Command"),children:t("span",{class:"i-lucide-copy",style:{width:"12px",height:"12px"}})})]}),so=({title:e,aside:n,command:a,children:r})=>l("section",{class:"flex flex-col min-w-0",style:{...Le,overflow:"hidden"},children:[l("div",{class:"flex items-center",style:{gap:"8px",padding:"12px 16px 8px"},children:[t("h2",{style:oo,children:e}),t("span",{class:"flex-1"}),n]}),r,t("div",{style:{padding:"8px 16px 12px",borderTop:"1px solid var(--hair)"},children:t(Ae,{text:a})})]}),La=({release:e,label:n,action:a,onTry:r})=>l("div",{class:"flex flex-col",style:lo,children:[l("div",{class:"flex items-center",style:{gap:"10px"},children:[t("span",{class:"shrink-0",style:{...fe,width:"70px"},children:n}),t("span",{class:"mono",style:{fontWeight:600},children:e.version}),e.date&&t("span",{style:fe,children:At(e.date)}),t("a",{href:e.notesUrl,target:"_blank",rel:"noreferrer",style:{fontSize:"11.5px",color:"var(--blue)"},children:"Notes ↗"}),t("span",{class:"flex-1"}),a&&t(I,{label:a,variant:e.prerelease?"primary":"secondary",size:"sm",onClick:()=>r(e.version)})]}),a&&t(Ae,{text:e.install}),e.notes&&l("details",{style:{fontSize:"12px",color:"var(--ink-2)"},children:[t("summary",{class:"cursor-pointer",style:fe,children:"What it brings"}),t("p",{style:{whiteSpace:"pre-wrap",marginTop:"6px"},children:e.notes})]})]}),mi=({onTry:e})=>{const n=$t.value;if(!n)return null;const{installed:a,stable:r,stableAction:o,prereleases:s}=n,c=l(U,{children:[t("span",{class:"mono",style:{fontSize:"13px",fontWeight:600},children:a??"unknown"}),(a==null?void 0:a.includes("-"))&&t(He,{label:"pre-release",color:"var(--orange)"})]});return l(so,{title:"KIOKU VERSION",aside:c,command:n.command,children:[n.error&&t("p",{style:{...oe,margin:"0 16px 10px",background:Q("--orange")},children:n.error}),r&&t(La,{release:r,label:"Stable",action:o==="back"?"Back to stable":o==="update"?`Update to ${r.version}`:void 0,onTry:e}),s.map(i=>t(La,{release:i,label:"Pre-release",action:`Try ${i.version}`,onTry:e},i.version)),!n.error&&s.length===0&&t("p",{style:{...fe,padding:"8px 16px 12px",borderTop:"1px solid var(--hair)"},children:"No pre-release newer than the one installed."})]})},vi=({version:e,onClose:n})=>{const[a,r]=m(null),[o,s]=m(null),[c,i]=m(null),[d,h]=m(!1);D(()=>{ce("/api/kioku/update/check",{version:e}).then(r,S=>i(le(S)))},[e]);const f=async()=>{h(!0),i(null);try{s(await ce("/api/kioku/update",{version:e})),Promise.all([Pe(),Hn()])}catch(S){i(le(S))}finally{h(!1)}},v=o??a,x=o?l(U,{children:[t("span",{class:"flex-1"}),t(I,{label:"Close",variant:"primary",onClick:n})]}):l(U,{children:[t("span",{class:"flex-1"}),t(I,{label:"Cancel",variant:"secondary",onClick:n}),t(I,{label:d?"Installing…":`Install ${e}`,variant:"primary",disabled:!a||a.status==="current"||d,onClick:f})]});return t(Re,{open:!0,title:o?`Kioku ${o.version??e}`:`Try Kioku ${e}`,onClose:d?()=>{}:n,footer:x,children:l("div",{class:"flex flex-col",style:{gap:"12px",fontSize:"13px"},children:[!v&&!c&&t("p",{style:fe,children:"Asking kioku what it would install…"}),v&&l("div",{class:"flex items-center",style:{gap:"10px"},children:[l("span",{class:"mono",style:{fontSize:"16px",fontWeight:600},children:[v.was??"?"," → ",v.version??e]}),t(He,{label:v.status,color:`var(${xi[v.status]??"--blue"})`})]}),(a==null?void 0:a.status)==="current"&&!o&&t("p",{style:fe,children:"This version is already installed."}),v&&t(Ae,{text:v.command}),!o&&(a==null?void 0:a.install)&&t(Ae,{text:a.install}),o&&o.agents.length>0&&l("div",{class:"flex flex-col",style:{gap:"4px"},children:[t("h3",{style:oo,children:"AGENT PLUGINS"}),o.agents.map(S=>l("div",{class:"flex items-center",style:{gap:"8px",fontSize:"12.5px"},children:[t("span",{style:{fontWeight:500},children:S.host}),t("span",{style:fe,children:S.name}),l("span",{class:"mono",children:[S.from??"–"," → ",S.to??"–"]}),t("span",{class:"flex-1"}),S.error?t(He,{label:S.error,color:"var(--red)"}):t(He,{label:S.changed?"changed":"unchanged",color:`var(${S.changed?"--green":"--ink-3"})`})]},`${S.host}:${S.name}`))]}),(o==null?void 0:o.finishError)&&t("p",{style:{...oe,background:Q("--orange")},children:o.finishError}),c&&t("p",{style:{...oe,background:Q("--red")},children:c}),!o&&l("p",{style:fe,children:["Kioku installs it on this machine for every session.",e.includes("-")?" Back to stable undoes it.":""]})]})})},yi=({mismatch:e,tool:n,onTry:a})=>{const[r,o]=m(!1),{fix:s}=e,c=async()=>{o(!0),await Rt(`${ln(e.plugin)}/update`,{scope:e.scope,scopeRef:e.scopeRef})&&(j(`Kioku's plugin updated in ${e.scopeRef} · applies to new sessions`,"success"),await Sr()),o(!1)};let i=null;return(s==null?void 0:s.kind)==="release"&&(i=t(I,{label:`Try ${s.version}`,variant:"primary",size:"sm",onClick:()=>a(s.version)})),(s==null?void 0:s.kind)==="plugin"&&(i=t(I,{label:r?"Updating…":"Update plugin",variant:"primary",size:"sm",disabled:r,onClick:c})),l("div",{class:"flex flex-col",style:{gap:"4px"},children:[l("div",{class:"flex items-center",style:{gap:"10px"},children:[l("span",{class:"flex-1",children:[e.scopeRef,": plugin ",t("span",{class:"mono",children:e.version}),", tool ",t("span",{class:"mono",children:n})]}),i]}),s?t(Ae,{text:s.command}):t("span",{style:fe,children:"No kioku release of that major yet."})]})},bi=({onTry:e})=>{const n=$t.value;return!(n!=null&&n.installed)||n.mismatches.length===0?null:l("section",{class:"flex flex-col",style:{...oe,gap:"8px",background:Q("--orange")},children:[t("p",{style:{fontWeight:600},children:"Kioku does nothing in these sessions: its plugin and the tool have different major versions."}),n.mismatches.map(a=>t(yi,{mismatch:a,tool:n.installed,onTry:e},`${a.scope}:${a.scopeRef}`))]})},ki=({lab:e})=>{const[n,a]=m(!1),r=async o=>{a(!0);try{ca.value=await ce(`/api/kioku/labs/${encodeURIComponent(e.name)}`,{enabled:o}),j(`${e.title} ${o?"on":"off"} · applies from the next session`,"info")}catch(s){j(le(s),"error")}finally{a(!1)}};return l("div",{class:"flex flex-col",style:{...lo,gap:"6px"},children:[l("div",{class:"flex items-center",style:{gap:"10px"},children:[t("span",{style:{fontWeight:600},children:e.title}),t("span",{class:"flex-1"}),t(jt,{checked:e.enabled,disabled:n,label:`${e.title} enabled`,onChange:r})]}),e.about&&t("p",{style:{color:"var(--ink-2)"},children:e.about}),t(Ae,{text:e.toggle}),e.command&&l("div",{class:"flex items-center",style:{gap:"8px"},children:[t("span",{style:fe,children:"In a session"}),t(Ae,{text:e.command}),t(Zn,{command:e.command,plugin:"kioku",disabled:!e.enabled,note:"A session has it only when it was opened after the lab was switched on."})]}),Object.entries(e.settings??{}).map(([o,s])=>{var c;return l("div",{class:"flex items-center",style:{gap:"8px"},children:[t("span",{class:"mono",style:fe,children:o}),t("span",{class:"mono",children:JSON.stringify(s)}),t("span",{class:"flex-1"}),((c=e.set)==null?void 0:c[o])&&t(Ae,{text:e.set[o]})]},o)})]})},wi=()=>{var n,a;const e=ca.value;return(n=e==null?void 0:e.labs)!=null&&n.length?t(so,{title:`LABS · ${((a=$t.value)==null?void 0:a.installed)??""}`,aside:t("span",{style:fe,children:"off by default, may change in any version"}),command:e.command,children:e.labs.map(r=>t(ki,{lab:r},r.name))}):null},Si=[{label:"Personal",tiers:["personal"]},{label:"Projects",tiers:["project","client"]},{label:"Team",tiers:["team"]}],Ci={save:"--green",update:"--blue",supersede:"--blue",evolve:"--purple",link:"--teal",confirm:"--green",retire:"--red",forget:"--red"},$i=({brain:e})=>{const n=Object.entries(e.kinds).filter(([,a])=>a>0).sort((a,r)=>r[1]-a[1]);return l(U,{children:[t("div",{class:"flex overflow-hidden",style:{height:"6px",borderRadius:"99px",background:"var(--elev)"},children:n.map(([a,r])=>t("span",{title:`${a} ${r}`,style:{width:`${r/e.pages*100}%`,background:`var(${va(a)})`}},a))}),t("div",{class:"flex flex-wrap",style:{gap:"3px 10px",fontSize:"11px",color:"var(--ink-2)"},children:n.slice(0,3).map(([a,r])=>l("span",{class:"inline-flex items-center",style:{gap:"4px"},children:[t(ze,{color:`var(${va(a)})`}),a," ",r]},a))})]})},Na={fontSize:"11.5px",fontWeight:500,color:"var(--blue)",background:"none",border:0,padding:0,cursor:"pointer"},Oa=({brain:e,usedBy:n,showTier:a,onDialog:r})=>{const o=Ve(e.tier);return l("div",{class:"flex flex-col min-w-0",style:{...Le,gap:"9px",padding:"14px 16px",borderTop:`3px solid var(${o})`},children:[l("div",{class:"flex items-center",style:{gap:"8px"},children:[a&&t("span",{style:{fontSize:"10.5px",fontWeight:700,letterSpacing:".04em",textTransform:"uppercase",color:`var(${o})`},children:e.tier}),t("span",{class:"truncate",style:{fontSize:"14.5px",fontWeight:600},title:e.folder,children:re(e)}),t("span",{class:"flex-1"}),t("span",{style:{fontSize:"11.5px",color:"var(--ink-3)"},children:e.onDisk?e.touched?At(e.touched):"quiet":"not on disk"})]}),l("div",{style:{fontSize:"26px",fontWeight:700,lineHeight:1},children:[e.pages," ",t("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--ink-3)"},children:"pages"})]}),e.pages>0&&t($i,{brain:e}),n&&t("div",{class:"flex flex-wrap",style:{gap:"4px"},children:e.tier==="personal"?t("span",{style:{fontSize:"11.5px",color:"var(--ink-3)"},children:"loads in every session"}):n.length===0?t("span",{style:{fontSize:"11.5px",color:"var(--ink-3)"},children:"no CW project loads it"}):n.map(s=>t(He,{label:s,variant:"neutral"},s))}),e.onDisk&&l("div",{class:"flex items-center",style:{gap:"12px",paddingTop:"8px",marginTop:"auto",borderTop:"1px solid var(--hair)"},children:[t("button",{type:"button",style:Na,onClick:()=>r({kind:"area",brain:e}),children:"+ Area"}),t("span",{class:"flex-1"}),!e.remote&&l(U,{children:[t("span",{style:{fontSize:"11.5px",color:"var(--ink-3)"},children:"only on this machine"}),t("button",{type:"button",style:Na,onClick:()=>r({kind:"publish",brain:e}),children:"Publish…"})]})]})]})},zi=({writes:e})=>l("section",{style:{...Le,overflow:"hidden"},children:[t("h2",{style:{padding:"12px 16px 6px",fontSize:"11px",fontWeight:600,letterSpacing:".02em",color:"var(--ink-3)"},children:"RECENT ACTIVITY · LAST 2 WEEKS"}),e.length===0&&t("p",{style:{padding:"4px 16px 14px",fontSize:"12.5px",color:"var(--ink-3)"},children:"Nothing written lately."}),e.map(n=>l("div",{class:"flex items-center",style:{gap:"10px",padding:"9px 16px",borderTop:"1px solid var(--hair)",fontSize:"12.5px"},children:[t("span",{class:"shrink-0 flex justify-center",style:{width:"76px"},children:t(He,{label:n.verb,color:`var(${Ci[n.verb]??"--ink-2"})`})}),t("span",{class:"truncate flex-1",title:n.path,children:n.title}),l("span",{class:"shrink-0",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:[n.brain,n.author?` · ${n.author}`:""," · ",At(n.date)]})]},`${n.brain}:${n.path}:${n.date}:${n.verb}`))]}),Ri=({project:e,onProject:n})=>{const[a,r]=m(!1),[o,s]=m(null),c=()=>s(null);D(()=>Cr(),[]);const i=ke.value,d=(i==null?void 0:i.installed)===!0;D(()=>{d&&Hn(!1,!e)},[d,e]);const h=k=>s({kind:"version",version:k}),f=async()=>{const k=window.open("","_blank");r(!0);try{const{address:u}=await ce("/api/kioku/viewer",{});k?k.location.href=u:(window.open(u,"_blank"),j(`Viewer running at ${u}`,"info")),Pe()}catch(u){k==null||k.close(),j(le(u),"error")}finally{r(!1)}},v=async()=>{await fetch("/api/kioku/viewer",{method:"DELETE"}).catch(()=>{}),Pe()},x=(i==null?void 0:i.brains)??[],S=(i==null?void 0:i.projects)??{},b=Object.keys(S).filter(k=>S[k].some(u=>u.tier!=="personal")).sort();e&&!b.includes(e)&&b.unshift(e);const y=e?da(e):[],p=k=>Object.keys(S).filter(u=>S[u].some(z=>z.name===re(k))).sort(),w=new Set(y.map(re)),$=((i==null?void 0:i.activity)??[]).filter(k=>!e||w.has(k.brain)).slice(0,15),g=d?e?`${e} · ${an(y)} pages its sessions can recall`:`Kioku ${i.version??""} · ${an(x)} pages in ${x.length} brain${x.length===1?"":"s"}`:"Kioku brains on this machine";return l(U,{children:[l(tt,{title:"Memory",subtitle:g,children:[(i==null?void 0:i.viewer)&&t(I,{label:"Stop viewer",variant:"secondary",onClick:v}),t(I,{label:"Refresh",variant:"secondary",onClick:()=>Pe(!0).then(()=>d&&Hn(!0,!e))}),t(I,{label:"New brain",variant:"secondary",disabled:!d,onClick:()=>s({kind:"brain"})}),t(I,{label:"New memory",variant:"secondary",disabled:!x.some(k=>k.onDisk),onClick:()=>s({kind:"memory"})}),t(I,{label:i!=null&&i.viewer?"Viewer open ↗":"Open viewer",variant:"primary",disabled:!d||a,onClick:f})]}),l("div",{class:"flex flex-col w-full",style:{padding:"18px 22px 40px",gap:"14px",maxWidth:"1180px"},children:[i&&!i.installed&&l("p",{style:{...oe,background:Q("--red")},children:["Kioku is not installed. Install it from ",t("code",{children:"monoku/kioku"})," with its ",t("code",{children:"install.sh"}),", which puts ",t("code",{children:"kioku"})," in ",t("code",{children:"~/.local/bin"}),"."]}),d&&t(bi,{onTry:h}),d&&!e&&l("div",{class:"grid items-start",style:{gridTemplateColumns:"repeat(auto-fit, minmax(min(100%, 380px), 1fr))",gap:"12px"},children:[t(mi,{onTry:h}),t(wi,{})]}),d&&x.length===0&&t(Oe,{icon:"i-lucide-brain",title:"No brains yet",description:"New brain makes one on this machine: a personal one for what you learn anywhere, a project or team one to share."}),x.length>0&&b.length>0&&t("div",{class:"flex",children:t(de,{size:"sm",label:"Project",tabs:[{id:"",label:"All"},...b.map(k=>({id:k,label:k}))],active:e??"",onChange:k=>n(k||null)})}),x.length>0&&!e&&t("div",{class:"flex flex-wrap",style:{gap:"14px 12px"},children:Si.map(k=>{const u=x.filter(z=>k.tiers.includes(z.tier??""));return u.length===0?null:l("section",{class:"flex flex-col min-w-0",style:{gap:"8px",flex:`${u.length} 1 ${u.length*250}px`},children:[l("h2",{class:"flex items-center",style:{gap:"8px",fontSize:"11px",fontWeight:600,letterSpacing:".03em",color:`var(${Ve(k.tiers[0])})`},children:["● ",k.label.toUpperCase(),u.length>1&&t("span",{style:{color:"var(--ink-3)"},children:u.length})]}),t("div",{class:"grid",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))",gap:"12px"},children:u.map(z=>t(Oa,{brain:z,usedBy:p(z),onDialog:s},z.key))})]},k.label)})}),e&&y.length>0&&t("div",{class:"grid items-center",style:{gridTemplateColumns:y.map(()=>"minmax(0, 1fr)").join(" 24px ")},children:y.map((k,u)=>l(ho,{children:[u>0&&t("span",{style:{textAlign:"center",color:"var(--ink-3)",fontSize:"16px"},children:"→"}),t(Oa,{brain:k,showTier:!0,onDialog:s})]},k.key))}),e&&d&&!y.some(k=>k.tier!=="personal")&&l("div",{class:"flex items-center",style:{...oe,gap:"12px",background:"var(--elev)",color:"var(--ink-2)"},children:[l("span",{class:"flex-1",children:[e," has no project or team brain, so its sessions recall only yours."]}),t(I,{label:"Give it a brain",variant:"secondary",size:"sm",onClick:()=>s({kind:"link"})})]}),x.length>0&&t(zi,{writes:$}),d&&l("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:["Open viewer starts ",t("code",{children:"kioku web"}),": the graph of every page, each page with its history, lint and the latest changes. It opens in its own tab and stops with Forge."]})]}),(o==null?void 0:o.kind)==="memory"&&t(gi,{project:e,onClose:c}),(o==null?void 0:o.kind)==="brain"&&t(pi,{onClose:c}),(o==null?void 0:o.kind)==="link"&&e&&t(ui,{project:e,onClose:c}),(o==null?void 0:o.kind)==="area"&&t(ro,{brain:o.brain,onClose:c}),(o==null?void 0:o.kind)==="publish"&&t(hi,{brain:o.brain,onClose:c}),(o==null?void 0:o.kind)==="version"&&t(vi,{version:o.version,onClose:c})]})},aa=({value:e,onChange:n,initialPath:a,requireGit:r=!0})=>{const[o,s]=m(a??"~"),[c,i]=m(o),[d,h]=m([]),[f,v]=m(null),[x,S]=m(null),[b,y]=m(""),[p,w]=m(!1),[$,g]=m(!1),[k,u]=m(null);D(()=>{let A=!1;return(async()=>{g(!0),u(null);try{const q=await(await fetch(`/api/cw/browse-dirs?path=${encodeURIComponent(o)}`)).json();if(A)return;if(!q.ok){u(q.error??"Failed to load directory"),h([]);return}h(q.entries??[]),v(q.parent??null),S(q.home??null),y(q.path??o),w(!!q.isGitRepo)}catch{A||(u("Network error"),h([]))}finally{A||g(!1)}})(),()=>{A=!0}},[o]);const z=A=>{s(A),i(A)},E=e===b,L=r&&!p,O=b?x&&b===x?"~":x&&b.startsWith(x+"/")?"~"+b.slice(x.length):b:o,R={width:"24px",height:"24px",borderRadius:"7px",border:0,background:"var(--card)",color:"var(--ink-2)",boxShadow:"var(--shadow-s)"},P="flex items-center w-full text-left cursor-pointer transition-colors duration-140 hover:bg-elev disabled:cursor-not-allowed disabled:opacity-60",T={gap:"8px",padding:"7px 11px",border:0,borderBottom:"1px solid var(--hair)",background:"none",color:"var(--ink)",fontSize:"12.5px"},B={padding:"1px 7px",borderRadius:"99px",background:Q("--green"),color:"var(--green)",fontSize:"10.5px",fontWeight:600};return l("div",{style:{borderRadius:"12px",border:"1px solid var(--hair)",background:"var(--card)",boxShadow:"var(--shadow-s)",overflow:"hidden"},children:[l("div",{class:"flex items-center",style:{gap:"6px",padding:"7px 9px",borderBottom:"1px solid var(--hair)",background:"var(--elev)"},children:[t("button",{type:"button",class:"grid place-items-center cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:R,onClick:()=>f&&z(f),disabled:!f||$,title:"Parent folder","aria-label":"Parent folder",children:"←"}),t("button",{type:"button",class:"grid place-items-center cursor-pointer",style:R,onClick:()=>z("~"),title:"Home","aria-label":"Home",children:"~"}),t("input",{type:"text",value:c,"aria-label":"Path",onInput:A=>i(A.target.value),onBlur:()=>s(c),onKeyDown:A=>{A.key==="Enter"&&s(c)},class:"field mono flex-1 min-w-0",style:{height:"26px",padding:"0 9px",borderRadius:"7px",border:"1px solid var(--hair)",background:"var(--bg-2)",color:"var(--ink)",fontSize:"11.5px",outline:"none"},placeholder:"~/workspace"})]}),e&&l("div",{class:"flex items-center",style:{gap:"8px",padding:"7px 11px",borderBottom:"1px solid var(--hair)",background:Q("--blue",12),fontSize:"12px"},children:[t("span",{class:"i-lucide-check shrink-0",style:{width:"13px",height:"13px",color:"var(--blue)"}}),t("span",{class:"mono flex-1 truncate",children:e}),t("button",{type:"button",class:"grid place-items-center cursor-pointer text-ink3 hover:text-ink",style:{border:0,background:"none"},onClick:()=>n("",!1),title:"Clear selection","aria-label":"Clear selection",children:t("span",{class:"i-lucide-x",style:{width:"13px",height:"13px"}})})]}),t("div",{class:"overflow-y-auto",style:{maxHeight:"220px"},children:$?t("p",{style:{padding:"12px",fontSize:"12.5px",color:"var(--ink-2)"},children:"Loading…"}):k?t("p",{style:{padding:"12px",fontSize:"12.5px",color:"var(--red)"},children:k}):l(U,{children:[l("button",{type:"button",class:P,style:{...T,background:E?"var(--elev)":"none",fontWeight:600},onClick:()=>n(b,p),disabled:L,title:L?"Not a git repository":"Pick this folder",children:[t("span",{class:"i-lucide-check shrink-0",style:{width:"12px",height:"12px",color:"var(--blue)"}}),l("span",{class:"flex-1 truncate",children:["Pick ",t("span",{class:"mono",children:O})]}),p?t("span",{style:B,children:"git"}):L?t("span",{style:{fontSize:"11px",color:"var(--ink-3)"},children:"no .git"}):null]}),d.length===0?t("p",{style:{padding:"12px",fontSize:"12.5px",color:"var(--ink-3)"},children:"No subfolders"}):d.map(A=>l("button",{type:"button",class:P,style:T,onClick:()=>z(A.path),children:[t("span",{class:"i-lucide-chevron-right shrink-0",style:{width:"12px",height:"12px",color:"var(--ink-3)"}}),t("span",{class:"mono flex-1 truncate",children:A.name}),A.isGitRepo&&t("span",{style:B,children:"git"})]},A.path))]})})]})},io={fontSize:"11.5px",color:"var(--red)"},Wa=e=>e.type==="boolean"||e.type==="string"&&e.format==="path",Da=({def:e,value:n,projects:a,onChange:r})=>e.type==="boolean"?t(jt,{checked:n===!0,onChange:r,label:e.label}):e.type==="enum"?t("select",{class:"field",value:typeof n=="string"?n:"",onChange:o=>r(ae(o)),children:e.values.map(o=>t("option",{value:o,children:o},o))}):e.type==="number"?t("input",{type:"number",class:"field",value:typeof n=="number"?n:"",min:e.min,max:e.max,onInput:o=>{const s=ae(o);r(s===""?void 0:Number(s))}}):e.format==="cw-project"?l("select",{class:"field",value:typeof n=="string"?n:"",onChange:o=>r(ae(o)||void 0),children:[t("option",{value:"",children:"None"}),a.map(o=>t("option",{value:o,children:o},o))]}):e.format==="path"?t(aa,{value:typeof n=="string"?n:"",onChange:o=>r(o),requireGit:!1}):t("input",{type:e.format==="url"?"url":"text",class:"field",value:typeof n=="string"?n:"",onInput:o=>r(ae(o))}),Ma=({def:e,error:n,plain:a,children:r})=>l(H,{plain:a,label:l(U,{children:[e.label??"",e.required?" *":""]}),children:[r,e.help&&t("span",{style:ye,children:e.help}),n&&t("span",{style:io,children:n})]}),Ti=({moduleId:e,displayName:n,schema:a,banner:r,onClose:o,onSaved:s})=>{const[c,i]=m(null),[d,h]=m({}),[f,v]=m([]),[x,S]=m(!1),[b,y]=m((r==null?void 0:r.enabled)===!0),p=`/api/modules/${encodeURIComponent(e)}/settings`;D(()=>{fetch(p).then(k=>k.json()).then(i).catch(()=>i({})),fetch("/api/cw/projects").then(k=>k.json()).then(k=>v(Object.keys(k))).catch(()=>{})},[p]);const w=(k,u)=>i(z=>({...z,[k]:u})),$=(k,u,z,E)=>i(L=>{const O=[...(L==null?void 0:L[k])??[]];return O[u]={...O[u],[z]:E},{...L,[k]:O}}),g=async()=>{S(!0);try{if(r&&b!==r.enabled&&await et("PUT",`/api/modules/${encodeURIComponent(e)}/banner`,{enabled:b}),Object.keys(a).length===0){j(`${n} settings saved`,"success"),s(),o();return}const k=await fetch(p,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)});if(k.status===400){const{errors:u}=await k.json();h(Object.fromEntries(u.map(z=>[z.path,z.message])));return}if(!k.ok)throw new Error(`Saving failed (${k.status})`);h({}),j(`${n} settings saved`,"success"),s(),o()}catch(k){j(le(k),"error")}finally{S(!1)}};return t(Ze,{title:`${n} settings`,onClose:o,children:c?l("div",{class:"flex flex-col",style:{gap:"14px"},children:[r&&t(jt,{checked:b,onChange:y,label:"Show on task list"}),Object.entries(a).map(([k,u])=>{if(u.type!=="list")return t(Ma,{def:{...u,label:u.label??k},error:d[k],plain:Wa(u),children:t(Da,{def:u,value:c[k],projects:f,onChange:E=>w(k,E)})},k);const z=c[k]??[];return l("div",{class:"flex flex-col",style:{gap:"10px"},children:[t("span",{style:{...ye,fontWeight:600},children:u.label??k}),u.help&&t("span",{style:ye,children:u.help}),d[k]&&t("span",{style:io,children:d[k]}),z.map((E,L)=>l("div",{class:"flex flex-col",style:{gap:"10px",padding:"12px",borderRadius:"12px",background:"var(--card)",border:"1px solid var(--hair)"},children:[Object.entries(u.item).map(([O,R])=>t(Ma,{def:{...R,label:R.label??O},error:d[`${k}[${L}].${O}`],plain:Wa(R),children:t(Da,{def:R,value:E[O],projects:f,onChange:P=>$(k,L,O,P)})},O)),t("div",{children:t(I,{label:"Remove",variant:"danger",size:"sm",onClick:()=>i(O=>({...O,[k]:z.filter((R,P)=>P!==L)}))})})]},L)),t("div",{children:t(I,{label:`Add ${(u.label??k).replace(/s$/,"").toLowerCase()}`,icon:"i-lucide-plus",variant:"secondary",size:"sm",onClick:()=>w(k,[...z,{}])})})]},k)}),l("div",{class:"flex",style:{gap:"8px",marginTop:"6px"},children:[t("span",{class:"flex-1"}),t(I,{label:"Cancel",variant:"secondary",onClick:o}),t(I,{label:"Save",loading:x,onClick:g})]})]}):t("div",{class:"text-ink2",style:{fontSize:"13px"},children:"Loading…"})})},En=({title:e,message:n,onReload:a})=>l("div",{style:{margin:"24px 22px",padding:"16px 18px",borderRadius:"14px",background:"var(--card)",border:"1px solid color-mix(in srgb, var(--red) 45%, var(--hair))"},children:[t("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--red)"},children:e}),t("pre",{class:"mono",style:{marginTop:"8px",fontSize:"12px",color:"var(--ink-2)",whiteSpace:"pre-wrap"},children:n}),t("div",{style:{marginTop:"12px"},children:t(I,{label:"Reload view",variant:"secondary",size:"sm",onClick:a})})]}),ji=({status:e,onClose:n,onRemoved:a})=>{const[r,o]=m(!1),s=async()=>{o(!0);try{ve.value=await et("DELETE",`/api/modules/${encodeURIComponent(e.id)}`),j(`Removed ${e.displayName}`,"success"),a()}catch(c){j(le(c),"error"),o(!1)}};return t(Re,{open:!0,title:`Remove ${e.displayName}?`,onClose:n,footer:l(U,{children:[t("span",{class:"flex-1"}),t(I,{label:"Cancel",variant:"secondary",onClick:n}),t(I,{label:"Remove",variant:"destructive",loading:r,onClick:s})]}),children:l("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:["Forge uninstalls ",t("span",{class:"mono",children:e.name})," and stops it now. Its settings stay saved, so installing it again brings them back."]})})},Pi=({moduleId:e,cwProject:n,onBack:a})=>{var u,z,E,L;const r=ve.value.find(O=>O.id===e),[o,s]=m(!1),[c,i]=m(!1),[d,h]=m(null),[f,v]=m(0),x=se(e);r&&(x.current=r.displayName);const S=x.current,b=ee(()=>Kr(e,()=>x.current,()=>s(!0)),[e]),y=(r==null?void 0:r.state)==="enabled"?(u=r.view)==null?void 0:u.version:void 0,p=((z=ur.value[e])==null?void 0:z.attention)??0;D(()=>{p>0&&Xo(e)},[e,p]),D(()=>{if(!r||!y)return;let O=!0;return _r(r.view.url,r.view.version).then(R=>{O&&h({version:y,config:R})},R=>{O&&h({version:y,error:R.message})}),()=>{O=!1}},[e,y,f]);const w=r?pr(r):null,$=l(tt,{title:((E=r==null?void 0:r.view)==null?void 0:E.title)??S,subtitle:r?`${r.name} ${r.version}`:void 0,children:[w&&l("span",{class:"mono truncate",title:w,style:{maxWidth:"320px",fontSize:"11.5px",color:"var(--orange)"},children:["⚠ ",w]}),((r==null?void 0:r.settingsSchema)&&Object.keys(r.settingsSchema).length>0||(r==null?void 0:r.banner))&&t(I,{label:"Settings",icon:"i-lucide-settings",variant:"secondary",size:"sm",onClick:()=>s(!0)}),(r==null?void 0:r.removable)&&t(I,{label:"Remove",icon:"i-lucide-trash-2",variant:"secondary",size:"sm",onClick:()=>i(!0)}),c&&r&&t(ji,{status:r,onClose:()=>i(!1),onRemoved:a})]});if(!r)return l("div",{children:[$,t("div",{style:{padding:"56px 22px"},children:t(Oe,{icon:"i-lucide-package-x",title:`${S} was removed`,description:"The module is no longer installed.",action:{label:"Back to Tasks",onClick:a}})})]});if(r.state!=="enabled")return l("div",{children:[$,t(En,{title:`${S} is disabled`,message:r.reason??"No reason given",onReload:()=>{kt()}})]});const g=d&&d.version===y?d:null,k=(L=g==null?void 0:g.config)==null?void 0:L.component;return l("div",{children:[$,g!=null&&g.error?t(En,{title:`${S}'s view did not load`,message:g.error,onReload:()=>v(O=>O+1)}):k?t(Dr,{fallback:O=>t(En,{title:`${S}'s view crashed`,message:O.message,onReload:()=>v(R=>R+1)}),children:t(k,{moduleId:e,projectId:null,cwProject:n,forge:b})},`${y}-${f}`):l("div",{class:"py-20 text-center text-ink2",children:["Loading ",S,"…"]}),o&&(r.settingsSchema||r.banner)&&t(Ti,{moduleId:e,displayName:S,schema:r.settingsSchema??{},banner:r.banner,onClose:()=>s(!1),onSaved:()=>{b.reloadSettings(),kt()}})]})},Ln={padding:"12px 14px",borderRadius:"12px",background:"var(--card)",border:"1px solid var(--hair)"},Ai=({onClose:e,onInstalled:n})=>{const[a,r]=m(""),[o,s]=m(null),[c,i]=m(null),[d,h]=m(null),f=async()=>{h("preview"),i(null);try{s(await ce("/api/modules/install/preview",{spec:a}))}catch(x){i(le(x))}finally{h(null)}},v=async()=>{if(o){h("install"),i(null);try{const{status:x,modules:S}=await ce("/api/modules/install",{token:o.token});ve.value=S,(x==null?void 0:x.state)==="disabled"?j(`Installed ${o.displayName}, but Forge disabled it: ${x.reason??""}`,"error"):j(`Installed ${o.displayName}`,"success"),x&&n(x),e()}catch(x){s(null),i(le(x))}finally{h(null)}}};return l(Ze,{title:"Add a module",onClose:e,children:[l("form",{class:"flex flex-col",style:{gap:"10px"},onSubmit:x=>{x.preventDefault(),a.trim()&&!d&&f()},children:[t(H,{label:"npm package, folder or git url",children:t("input",{class:"field mono",value:a,placeholder:"@scope/forge-mod-name",autoFocus:!0,spellcheck:!1,onInput:x=>{r(ae(x)),s(null)}})}),t("span",{style:ye,children:"Forge reads the module's manifest first; none of its code runs until you install it."})]}),c&&t("div",{role:"alert",class:"mono",style:{...Ln,fontSize:"12px",color:"var(--red)",whiteSpace:"pre-wrap",borderColor:"color-mix(in srgb, var(--red) 45%, var(--hair))"},children:c}),o&&l("div",{class:"flex flex-col",style:{gap:"12px"},children:[l("div",{style:Ln,children:[t("div",{style:{fontSize:"15px",fontWeight:650},children:o.displayName}),l("div",{class:"mono",style:{marginTop:"2px",fontSize:"11.5px",color:"var(--ink-3)"},children:[o.name," ",o.version,o.kind==="legacy"?" · legacy module":""]}),o.description&&t("p",{style:{marginTop:"8px",fontSize:"13px",color:"var(--ink-2)"},children:o.description})]}),o.banner&&t("span",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:"Adds a banner to the task list"}),l("div",{class:"flex flex-col",style:{gap:"6px"},children:[t("span",{style:{...ye,fontWeight:600},children:o.permissions.length?"It asks for":"It asks for no permissions"}),o.permissions.map((x,S)=>l("div",{class:"flex",style:{gap:"10px",fontSize:"12.5px"},children:[t("span",{class:"mono shrink-0",style:{width:"64px",color:"var(--ink-3)"},children:x.kind}),t("span",{class:"mono",style:{wordBreak:"break-all"},children:x.value})]},S))]}),t("p",{style:{...Ln,fontSize:"12.5px",color:"var(--ink-2)",borderColor:"color-mix(in srgb, var(--orange) 45%, var(--hair))"},children:o.trustNote}),l("span",{class:"mono",style:{fontSize:"11px",color:"var(--ink-3)",wordBreak:"break-all"},children:["npm install ",o.spec]})]}),l("div",{class:"flex",style:{gap:"8px"},children:[t("span",{class:"flex-1"}),t(I,{label:"Cancel",variant:"secondary",onClick:e}),o?t(I,{label:`Install ${o.displayName}`,loading:d==="install",onClick:v}):t(I,{label:"Review",loading:d==="preview",disabled:!a.trim(),onClick:f})]})]})},Ii=({open:e,accounts:n,onClose:a,onCreated:r})=>{const[o,s]=m("create"),[c,i]=m(""),[d,h]=m(""),[f,v]=m(""),[x,S]=m(""),[b,y]=m(""),[p,w]=m(""),[$,g]=m(!1),[k,u]=m(""),[z,E]=m(!1);D(()=>{e&&n.length>0&&!c&&i(n[0])},[e,n]),D(()=>{e||(s("create"),h(""),v(""),S(""),y(""),w(""),g(!1),u(""),E(!1))},[e]);const L=c.trim().length>0&&d.trim().length>0&&x.trim().length>0,O=c.trim().length>0&&p.length>0&&$,R=async()=>{if(L){E(!0);try{const F=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"create",project:d.trim(),task:d.trim(),description:x.trim(),account:c.trim()||void 0,directory:f.trim()||void 0,model:b||void 0})})).json();F.ok?(j("Project creation started in terminal","success"),r(F.session)):j(F.error??"Failed to create project","error")}catch{j("Failed to create project","error")}finally{E(!1)}}},P=async()=>{if(O){E(!0);try{const F=await(await fetch("/api/cw/register-project",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:p,account:c.trim(),alias:k.trim()||void 0})})).json();F.ok?(j(`Project "${F.project}" registered`,"success"),r()):j(F.error??"Failed to register project","error")}catch{j("Failed to register project","error")}finally{E(!1)}}},T=o==="create";return t(Re,{open:e,title:"Add a project",onClose:a,footer:l(U,{children:[t("span",{class:"mono flex-1 truncate",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:T?"cw create":"cw project register"}),t(I,{label:"Cancel",variant:"secondary",onClick:a}),t(I,{label:T?z?"Creating…":"Create":z?"Registering…":"Register",variant:"primary",loading:z,disabled:!(T?L:O),onClick:T?R:P})]}),children:l("div",{class:"flex flex-col",style:{gap:"13px"},children:[t(de,{fill:!0,label:"Mode",tabs:[{id:"create",label:"Create new"},{id:"existing",label:"Register existing"}],active:o,onChange:M=>s(M)}),l("div",{class:"grid",style:{gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:"10px"},children:[t(H,{label:"Account",children:n.length>0?t("select",{class:"field",value:c,onChange:M=>i(M.target.value),children:n.map(M=>t("option",{value:M,children:M},M))}):t("input",{type:"text",class:"field",value:c,placeholder:"account-name",onInput:M=>i(M.target.value)})}),T?t(H,{label:"Project name",children:t("input",{type:"text",class:"field",value:d,placeholder:"my-new-project",onInput:M=>h(M.target.value)})}):t(H,{label:"Alias",children:t("input",{type:"text",class:"field",value:k,placeholder:"defaults to folder name",onInput:M=>u(M.target.value)})})]}),l("div",{class:"flex flex-col",style:{gap:"5px"},children:[t("span",{style:ye,children:T?"Parent folder · optional":"Repository · must contain .git"}),T?t(aa,{value:f,onChange:v,requireGit:!1},"dir-create"):t(aa,{value:p,onChange:(M,F)=>{w(M),g(F)}},"dir-existing")]}),T&&l(U,{children:[t(H,{label:"Description",children:t("textarea",{rows:2,class:"field",value:x,placeholder:"A SaaS platform for…",onInput:M=>S(M.target.value)})}),l("div",{class:"flex flex-col",style:{gap:"5px"},children:[t("span",{style:ye,children:"Model"}),t(de,{size:"sm",label:"Model",tabs:[{id:"",label:"Auto"},{id:"haiku",label:"Haiku"},{id:"sonnet",label:"Sonnet"},{id:"opus",label:"Opus"}],active:b,onChange:y})]})]})]})})},Ei=(e,n)=>{if(n)return{kind:"connecting"};const a=typeof e.detail=="string"?e.detail:"",r=[e.provider,e.model].filter(Boolean).join(" · ");if(e.status==="not_installed")return{kind:"not_installed",detail:a};if(e.status==="error")return{kind:"error",detail:a};if(e.status==="local"){const o=e.detail&&typeof e.detail=="object"?e.detail:null;return{kind:"local",providerModel:r,reachable:(o==null?void 0:o.reachable)??null,pulled:(o==null?void 0:o.model_pulled)??null}}return e.status==="connected"&&(e.provider_kind==="api"||e.has_api_key)?{kind:"api_key",providerModel:e.provider!=="native"?r:null}:e.status==="connected"?{kind:"connected"}:{kind:"connect"}},Li=(e,n,a,r)=>{const o=[];switch(e.kind){case"connecting":o.push("Waiting for the login to finish");break;case"not_installed":o.push(e.detail||"Not on PATH");break;case"error":o.push(e.detail||"cw doctor reported an error");break;case"local":{const s=[e.reachable===null?null:e.reachable?"reachable":"unreachable",e.pulled===null?null:e.pulled?"model pulled":"model not pulled"].filter(Boolean).join(", ");o.push(...[e.providerModel,s].filter(Boolean));break}case"api_key":o.push(...[e.providerModel,"stored by cw"].filter(s=>!!s));break;case"connected":o.push(...[r.model,n].filter(s=>!!s)),o.length===0&&o.push("Signed in");break;case"connect":o.push(a?"Not logged in — device code, no terminal needed":"Not logged in");break}return r.unofficial&&o.push("unofficial"),o.join(" · ")},_e=({token:e,label:n})=>l("span",{class:"inline-flex items-center shrink-0 whitespace-nowrap",style:{gap:"6px",padding:"3px 10px",borderRadius:"99px",fontSize:"11.5px",fontWeight:600,background:e?Q(e):"var(--elev)",color:e?`var(${e})`:"var(--ink-3)"},children:[t("span",{style:{width:"6px",height:"6px",borderRadius:"50%",background:"currentColor"}}),n]}),Ni=({view:e,onConnect:n,onCancel:a})=>{switch(e.kind){case"connecting":return l("span",{class:"inline-flex items-center shrink-0",style:{gap:"8px"},children:[t(_e,{token:"--blue",label:"Connecting…"}),t("button",{type:"button",class:"cursor-pointer hover:text-ink",style:{border:0,background:"none",color:"var(--ink-2)",fontSize:"12px"},onClick:a,children:"Cancel"})]});case"not_installed":return t(_e,{token:null,label:"Not installed"});case"error":return t(_e,{token:"--red",label:"Error"});case"local":return t(_e,{token:"--orange",label:"Local"});case"api_key":return t(_e,{token:"--green",label:"API key"});case"connected":return t(_e,{token:"--green",label:"Connected"});case"connect":return t(I,{label:"Connect",size:"sm",onClick:n})}},Nn=({children:e})=>l("div",{class:"flex",style:{padding:"0 15px 11px"},children:[t("span",{class:"shrink-0",style:{width:"144px"}}),t("span",{class:"flex flex-col flex-1",style:{gap:"5px",minWidth:0},children:e})]}),On=({warn:e,children:n})=>t("span",{style:{fontSize:"11.5px",color:e?"var(--orange)":"var(--ink-3)"},children:n}),Oi=({account:e,harness:n})=>{const a=Bo(e,n);return!a||a.state==="not_connected"?null:a.state==="expired"?t(Nn,{children:t(On,{warn:!0,children:"Reconnect to see usage limits"})}):a.state==="error"?t(Nn,{children:l(On,{children:["Limits unavailable — ",a.detail??"the request failed"]})}):a.windows.length===0?null:l(Nn,{children:[t(Ka,{bars:Ya(a.windows)}),a.stale&&l(On,{children:["Last known values — ",a.detail??"the refresh failed"]})]})},Wi=3e3,Di=({account:e,harness:n,canUseApiKey:a,onConnected:r,onClose:o})=>{const[s,c]=m(null),[i,d]=m(!1),[h,f]=m(0),[v,x]=m(""),[S,b]=m(!1),y=ge(n).label,p=`/api/cw/accounts/${encodeURIComponent(e)}`,w=`${p}/login/${encodeURIComponent(n)}`,$=se(!1),g=se(!1);D(()=>{let E=!1,L=null;c(null),d(!1),$.current=!1,g.current=!1;const O=()=>{$.current||($.current=!0,fetch(w,{method:"DELETE"}).catch(()=>{}),j(`${e} is connected to ${y}`,"success"),r())},R=async()=>{var M;const T=await fetch(w).catch(()=>null);if(!(T!=null&&T.ok)||E)return;const{login:B}=await T.json();if(c(B),B.status!=="exited"||(g.current=!0,L&&(clearInterval(L),L=null),B.exitCode!==0))return;d(!0);const A=await be(!0);E||(A.available&&((M=We(A.doctor,e,n))==null?void 0:M.status)==="connected"?O():d(!1))};fetch(`${p}/login`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({harness:n})}).then(T=>T.json()).then(T=>{if(!E){if(!T.ok||!T.login){j(T.error??"Could not start the login","error");return}c(T.login),L=setInterval(R,Wi)}}).catch(()=>j("Could not start the login","error"));const P=il(T=>{var B;return((B=We(T,e,n))==null?void 0:B.status)==="connected"},{onDone:T=>{T&&O()}});return()=>{E=!0,L&&clearInterval(L),P(),g.current||fetch(w,{method:"DELETE"}).catch(()=>{})}},[e,n,h]);const k=()=>{fetch(w,{method:"DELETE"}).catch(()=>{}),o()},u=async()=>{const E=v.trim();if(E){b(!0);try{const O=await(await fetch(`${p}/api-key`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({harness:n,apiKey:E})})).json();O.ok?(x(""),j("API key saved","success"),be(!0)):j(O.error??"Could not save the API key","error")}catch{j("Could not save the API key","error")}finally{b(!1)}}},z=(s==null?void 0:s.status)==="exited";return l("div",{class:"flex flex-col",style:{gap:"12px",padding:"14px 16px",borderRadius:"16px",background:"var(--bg-2)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",animation:"riseIn .3s var(--ease) both"},children:[l("div",{class:"flex items-center",style:{gap:"10px"},children:[l("h3",{style:{fontSize:"14px",fontWeight:650},children:["Connect ",e," on ",y]}),t("span",{class:"flex-1"}),t(I,{label:"Cancel",variant:"secondary",size:"sm",onClick:k})]}),!s&&t("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:"Starting the login…"}),s&&!z&&l(U,{children:[l("div",{class:"flex flex-wrap items-center",style:{gap:"12px"},children:[s.url&&l("a",{href:s.url,target:"_blank",rel:"noopener noreferrer",class:"inline-flex items-center gap-1 transition-all duration-180 ease-spring hover:-translate-y-px hover:brightness-106",style:{padding:"6px 14px",borderRadius:"9px",background:"linear-gradient(180deg, var(--blue-2), var(--blue))",color:"#fff",fontSize:"12.5px",fontWeight:600,boxShadow:"var(--shadow-m)"},children:["Open login ",t("span",{class:"i-lucide-external-link",style:{width:"12px",height:"12px"}})]}),s.code&&l(U,{children:[t("span",{class:"mono",style:{fontSize:"19px",fontWeight:650,letterSpacing:".12em"},children:s.code}),t(I,{label:"Copy",variant:"secondary",size:"sm",onClick:()=>un(s.code??"","Code")})]})]}),s.code&&t("p",{style:{fontSize:"12px",color:"var(--ink-3)"},children:"If the code is rejected, use the one shown in Output."}),t("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:s.url||s.code?"Checks every 3 s. The status turns Connected on its own.":"Waiting for the login URL…"})]}),z&&i&&t("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:"Checking the connection…"}),z&&!i&&l("div",{class:"flex items-center",style:{gap:"10px",fontSize:"12.5px"},children:[t("span",{style:{color:"var(--red)"},children:"The login ended before connecting."}),t(I,{label:"Retry",variant:"secondary",size:"sm",onClick:()=>f(E=>E+1)})]}),s&&s.output.length>0&&l("details",{style:{fontSize:"12.5px"},children:[t("summary",{class:"cursor-pointer",style:{color:"var(--ink-2)"},children:"Output"}),t("pre",{class:"overflow-x-auto",style:{marginTop:"8px",padding:"10px 12px",borderRadius:"11px",background:"var(--term)",color:"#e3e3e8",fontSize:"11.5px"},children:s.output.join(`
28
28
  `)})]}),a&&l("div",{class:"flex flex-col",style:{gap:"8px",paddingTop:"12px",borderTop:"1px solid var(--hair)"},children:[t("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--ink-3)"},children:"Or with an API key"}),l("div",{class:"flex items-center",style:{gap:"8px"},children:[t("input",{type:"password",autocomplete:"off","aria-label":"API key",value:v,onInput:E=>x(E.target.value),placeholder:"sk-…",class:"field mono flex-1 min-w-0"}),t(I,{label:"Save",variant:"secondary",size:"sm",loading:S,disabled:!v.trim(),onClick:u})]}),t("p",{style:{fontSize:"12px",color:"var(--ink-3)"},children:"Sent to cw over stdin. Forge never stores or shows it."})]})]})},qt={display:"block",fontSize:"12px",color:"var(--ink-2)",marginBottom:"5px"},Mi=({response:e,onCancel:n,onCreated:a})=>{const[r,o]=m(""),[s,c]=m(""),[i,d]=m(""),[h,f]=m(""),[v,x]=m(!1),S=It(),b=r.trim(),y=To.test(b),p=e!=null&&e.available?e.doctor.harnesses.map(g=>g.name).filter(g=>g!=="claude"):[],w=!!s&&qe(e,s,"custom_provider"),$=async()=>{if(!(!y||v)){x(!0);try{const k=await(await fetch("/api/cw/accounts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:b,harness:s||void 0,provider:w&&i.trim()||void 0,model:w&&h.trim()||void 0})})).json();k.ok?(j(`Account "${b}" created`,"success"),a()):j(k.error??"Failed to create account","error")}catch{j("Failed to create account","error")}finally{x(!1)}}};return l("section",{class:"flex flex-col",style:{gap:"14px",padding:"16px 18px",borderRadius:"16px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-m)",animation:"riseIn .3s var(--ease) both"},"aria-label":"Add account",children:[t("h2",{style:{fontSize:"17px",fontWeight:700,letterSpacing:"-0.02em"},children:"Add an account"}),l("div",{style:{maxWidth:"360px"},children:[t("label",{style:qt,for:"new-account-name",children:"Account name"}),t("input",{id:"new-account-name",type:"text",value:r,onInput:g=>o(g.target.value),onKeyDown:g=>{g.key==="Enter"&&$()},placeholder:"my-account",class:"field",ref:S}),b&&!y&&t("p",{style:{fontSize:"12px",color:"var(--red)",marginTop:"5px"},children:"Must start with a letter or number. Only letters, numbers, hyphens, and underscores allowed."})]}),p.length>0&&l("div",{children:[t("span",{style:qt,children:"Default harness"}),t(de,{label:"Default harness",tabs:[{id:"",label:"Claude Code"},...p.map(g=>({id:g,label:ge(g).label}))],active:s,onChange:c}),t("p",{style:{fontSize:"12px",color:"var(--ink-3)",marginTop:"5px"},children:"The default harness cannot be changed later."})]}),w&&l("div",{class:"grid",style:{gridTemplateColumns:"1fr 1fr",gap:"10px",maxWidth:"520px"},children:[l("div",{children:[t("label",{style:qt,children:"Provider · optional"}),t("input",{type:"text",value:i,onInput:g=>d(g.target.value),placeholder:"zai, ollama, openrouter",class:"field"})]}),l("div",{children:[t("label",{style:qt,children:"Model · optional"}),t("input",{type:"text",value:h,onInput:g=>f(g.target.value),placeholder:"glm-5.1",class:"field"})]})]}),l("div",{class:"flex",style:{gap:"8px"},children:[t(I,{label:v?"Creating…":"Add account",variant:"primary",loading:v,disabled:!y,onClick:$}),t(I,{label:"Cancel",variant:"secondary",onClick:n})]})]})},Fi=new Set(["localhost","127.0.0.1","::1","[::1]"]),Fa={...Le,overflow:"hidden"},Bi=({account:e,onRemoved:n})=>{const[a,r]=m(!1),o=async()=>{try{const c=await(await fetch(`/api/cw/accounts/${encodeURIComponent(e)}`,{method:"DELETE"})).json();c.ok?(j(`Account "${e}" removed`,"info"),n()):j(c.error??"Failed to remove account","error")}catch{j("Failed to remove account","error")}finally{r(!1)}};return a?l("span",{class:"flex items-center flex-wrap",style:{gap:"8px"},children:[t("span",{style:{fontSize:"12px",color:"var(--ink-2)"},children:"Deletes the profile and its harness config. Projects stay."}),t(I,{label:"Remove account",variant:"destructive",size:"sm",onClick:o}),t(I,{label:"Cancel",variant:"secondary",size:"sm",onClick:()=>r(!1)})]}):t(I,{label:"Remove",variant:"danger",size:"sm",onClick:()=>r(!0)})},_i=({projects:e,onOpenSession:n,onAccountsChanged:a})=>{const[r,o]=m(null),[s,c]=m(!1);D(()=>{be()},[]),D(()=>or(),[]);const i=pn.value,d=!Fi.has(window.location.hostname),h=i!=null&&i.available?i.doctor:null,f=()=>{r&&(fetch(`/api/cw/accounts/${encodeURIComponent(r.account)}/login/${encodeURIComponent(r.harness)}`,{method:"DELETE"}).catch(()=>{}),o(null))},v=async(p,w)=>{if(qe(i,w,"headless_login")){o({account:p,harness:w});return}try{const g=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"login",account:p,harness:w})})).json();g.ok&&g.session?n(g.session):j(g.error??"Could not open the login","error")}catch{j("Could not open the login","error")}},x=h?h.accounts.reduce((p,w)=>p+w.harnesses.filter($=>$.status==="not_logged_in").length,0):0,S=h?`${h.accounts.length} account${h.accounts.length===1?"":"s"} · ${h.harnesses.length} harnesses · ${x} need${x===1?"s":""} connecting`:"Reading cw doctor…",b=p=>Object.values(e).filter(w=>w.account===p).length,y=(p,w)=>{if(!h)return null;const[$,g]=qa(w),k=b(p.name),u=We(h,p.name,p.default_harness),z=[ge(p.default_harness).label,u&&u.provider!=="native"?u.provider:null].filter(Boolean).join(" · ");return l("section",{style:{...Fa,animation:`riseIn .36s var(--ease) ${w*90}ms both`},"aria-label":p.name,children:[l("div",{class:"flex items-center flex-wrap",style:{gap:"11px",padding:"12px 15px",borderBottom:"1px solid var(--hair)",background:"var(--elev)"},children:[t("span",{class:"grid place-items-center shrink-0",style:{width:"28px",height:"28px",borderRadius:"9px",background:`linear-gradient(160deg, var(${$}), var(${g}))`,boxShadow:"var(--shadow-s)",color:"#fff",fontSize:"12px",fontWeight:700},children:p.name.charAt(0).toUpperCase()}),t("span",{style:{fontSize:"15px",fontWeight:650,letterSpacing:"-0.01em"},children:p.name}),l("span",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:["Default ",z," · ",k," project",k===1?"":"s"]}),t("span",{class:"flex-1"}),t(Bi,{account:p.name,onRemoved:()=>{be(!0),a()}})]}),h.harnesses.map(E=>{const L=We(h,p.name,E.name),O=(r==null?void 0:r.account)===p.name&&r.harness===E.name,R=ge(E.name),P=L?Ei(L,O):null;return l("div",{style:{borderBottom:"1px solid var(--hair)"},children:[l("div",{class:"flex items-center flex-wrap",style:{gap:"12px",padding:"11px 15px"},children:[l("span",{class:"inline-flex items-center shrink-0",style:{gap:"6px",width:"132px",fontSize:"13px",fontWeight:600},children:[t("span",{style:{width:"8px",height:"8px",borderRadius:"50%",background:R.color}}),R.label]}),t("span",{class:"flex-1",style:{minWidth:"140px",fontSize:"12.5px",color:"var(--ink-2)"},children:L&&P?Li(P,E.version,qe(i,E.name,"headless_login"),L):"Not configured for this account"}),P&&t(Ni,{view:P,onConnect:()=>{v(p.name,E.name)},onCancel:f})]}),L&&t(Oi,{account:p.name,harness:E.name}),O&&t("div",{style:{padding:"0 15px 13px"},children:t(Di,{account:p.name,harness:E.name,canUseApiKey:qe(i,E.name,"api_key_login"),onConnected:()=>o(null),onClose:()=>o(null)},`${p.name}::${E.name}`)})]},E.name)})]},p.name)};return l(U,{children:[l(tt,{title:"Accounts",subtitle:S,children:[t(I,{label:"Refresh",variant:"secondary",onClick:()=>{be(!0)}}),t(I,{label:"Add account",variant:"primary",onClick:()=>c(!0)})]}),l("div",{class:"flex flex-col w-full",style:{padding:"18px 22px 40px",gap:"14px",maxWidth:"1180px"},children:[s&&t(Mi,{response:i,onCancel:()=>c(!1),onCreated:()=>{c(!1),be(!0),a()}}),i&&!i.available&&l("section",{style:{...Fa,padding:"16px 18px"},children:[l("p",{style:{fontSize:"13.5px",marginBottom:"4px"},children:["Harness status is unavailable: ",i.reason]}),t("p",{style:{fontSize:"12.5px",color:"var(--ink-2)",marginBottom:"12px"},children:"The account view needs CW 0.3.0 or newer. You can still add an account by name."}),t(I,{label:"Retry",variant:"secondary",size:"sm",onClick:()=>{be(!0)}})]}),h&&d&&t("p",{style:{...oe,background:Q("--orange")},children:"Forge is not opened on localhost. Browser logins redirect to localhost on the machine running the harness, so only device-code logins work from here."}),h&&h.issues.map(p=>t("p",{style:{...oe,background:Q("--red"),color:"var(--ink)"},children:p.message},p.code)),h&&h.warnings.map(p=>t("p",{style:{...oe,background:"var(--elev)",color:"var(--ink-2)"},children:p.message},p.code)),h==null?void 0:h.accounts.map(y)]})]})},Ba="flex items-center w-full text-left cursor-pointer transition-colors duration-140 hover:bg-elev",Ki=({sessions:e,openTabKeys:n,onOpenSession:a,onNewTask:r,onClose:o,position:s})=>{const c=se(null);D(()=>{const d=f=>{c.current&&!c.current.contains(f.target)&&o()},h=f=>{f.key==="Escape"&&o()};return document.addEventListener("mousedown",d),document.addEventListener("keydown",h),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",h)}},[o]);const i=e.filter(d=>!n.has(V(d)));return l("div",{ref:c,class:"popover fixed z-[60] flex flex-col",style:{top:`${s.top}px`,left:`${s.left}px`,width:"min(320px, calc(100vw - 16px))",maxHeight:"420px",overflowY:"auto",padding:"6px",borderRadius:"14px"},children:[t("div",{style:{padding:"7px 10px 3px",fontSize:"11px",fontWeight:600,color:"var(--ink-3)"},children:"New"}),Xe.map(d=>l("button",{type:"button",class:Ba,style:{gap:"10px",padding:"7px 10px",borderRadius:"10px",border:0,background:"none",color:"var(--ink)",fontSize:"13px"},onClick:()=>{r(d.key),o()},children:[t(Vn,{type:d.sessionType,size:22,radius:7,font:10}),t("span",{class:"flex-1",children:oa(d.key)})]},d.key)),i.length>0&&l(U,{children:[t("div",{style:{padding:"9px 10px 3px",fontSize:"11px",fontWeight:600,color:"var(--ink-3)"},children:"Resume"}),i.map(d=>l("button",{type:"button",class:Ba,style:{gap:"10px",padding:"7px 10px",borderRadius:"10px",border:0,background:"none",color:"var(--ink)",fontSize:"13px"},onClick:()=>{a(d),o()},children:[t(Vn,{type:d.type,size:22,radius:7,font:10}),t("span",{class:"flex-1 truncate",children:ue(d)}),t("span",{class:"mono truncate",style:{fontSize:"10.5px",color:"var(--ink-3)",maxWidth:"110px"},children:ie(d)})]},V(d)))]})]})},Ui=({tabs:e,activeIndex:n,onActivate:a,onClose:r,onBack:o,allSessions:s,openTabKeys:c,onOpenSession:i,onNewTask:d})=>{const[h,f]=m(!1),v=se(null),[x,S]=m({top:0,left:0}),b=Y(()=>f(!1),[]),y=()=>{if(!h&&v.current){const p=v.current.getBoundingClientRect();S({top:p.bottom+6,left:Math.max(8,Math.min(p.left,window.innerWidth-328))})}f(!h)};return l(U,{children:[l("div",{class:"glass flex items-center shrink-0 overflow-x-auto",role:"tablist","aria-label":"Open sessions",style:{gap:"8px",padding:"9px 16px",borderBottom:"1px solid var(--hair)"},children:[t(ha,{}),t(Bl,{onClick:o}),e.map((p,w)=>{const $=w===n,g=Ie.value[V(p)],k=!$&&Je(g);return l("div",{role:"tab",tabIndex:0,"aria-selected":$,title:[k?tn(g):null,w<5?`⌘${w+1}`:null].filter(Boolean).join(" · ")||void 0,class:"flex items-center shrink-0 whitespace-nowrap cursor-pointer transition-all duration-200 ease-spring",style:{gap:"8px",padding:"6px 11px",borderRadius:"10px",fontSize:"12.5px",background:$?"var(--card)":"transparent",border:`1px solid ${$?"var(--hair)":"transparent"}`,boxShadow:$?"var(--shadow-s)":"none"},onClick:()=>a(w),onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),a(w))},children:[t(ze,{size:6,live:p.status==="active",color:k?`var(${Gt(g)})`:void 0}),t("span",{style:{fontWeight:600,color:$?"var(--ink)":"var(--ink-2)"},children:ue(p)}),t("span",{class:"mono truncate",style:{fontSize:"11px",color:"var(--ink-3)",maxWidth:"110px"},children:ie(p)}),t("button",{type:"button",class:"grid place-items-center cursor-pointer text-ink3 hover:text-red",style:{border:0,background:"none",padding:"0 1px"},onClick:u=>{u.stopPropagation(),r(w)},title:"Close tab (⌘W)","aria-label":`Close ${ue(p)}`,children:t("span",{class:"i-lucide-x",style:{width:"13px",height:"13px"}})})]},V(p))}),t("button",{ref:v,type:"button",class:"grid place-items-center shrink-0 cursor-pointer text-ink2 hover:text-ink",style:{width:"26px",height:"26px",borderRadius:"8px",border:"1px solid var(--hair)",background:"var(--card)"},onClick:y,"aria-expanded":h,title:"Open or create a tab","aria-label":"Open or create a tab",children:t("span",{class:"i-lucide-plus",style:{width:"14px",height:"14px"}})})]}),h&&t(Ki,{sessions:s,openTabKeys:c,onOpenSession:i,onNewTask:d,onClose:b,position:x})]})};function Hi(e,n){switch(e){case"uncommitted":{const a=(n==null?void 0:n.uncommitted)??0;return`${a} file${a===1?" has":"s have"} uncommitted changes. Closing deletes them.`}case"unpushed":{const a=n?Ct(n):0;return`${a} commit${a===1?" is":"s are"} not pushed. They stay on ${(n==null?void 0:n.branch)??"the task branch"} on this machine only.`}case"pr-open":return`PR #${(n==null?void 0:n.pr.status)==="found"?n.pr.number:""} is still open. If changes are requested, reopening starts the agent without this conversation.`;case"state-unknown":return"Forge could not read this task's changes."}}const qi=({request:e,onCancel:n,onConfirm:a})=>{if(!e)return null;const r=e.state?e.state.closeWarnings:["state-unknown"],o=r.includes("uncommitted");return l(Re,{open:!0,title:"Close this task?",onClose:n,footer:l(U,{children:[t("span",{class:"flex-1"}),t(I,{label:"Cancel",variant:"secondary",onClick:n}),t(I,{label:"Close task",variant:o?"destructive":"primary",onClick:a})]}),width:460,children:[t("ul",{class:"flex flex-col",style:{gap:"8px",fontSize:"13.5px",paddingLeft:"18px"},children:r.map(c=>t("li",{children:Hi(c,e.state)},c))}),e.error&&t("p",{style:{marginTop:"10px",fontSize:"12.5px",color:"var(--ink-2)"},children:e.error})]})},Wn="forge-open-tabs";function Gi({spaces:e,loading:n,onFetchData:a}){const[r,o]=m([]),[s,c]=m(0),[i,d]=m(!0),h=se(!1),f=se(r);f.current=r,D(()=>{if(!(n||e.length===0||h.current)){h.current=!0;try{const p=sessionStorage.getItem(Wn);if(!p)return;const{keys:w,activeIndex:$}=JSON.parse(p),g=[];for(const k of w){const u=e.find(z=>V(z)===k);u&&g.push(u)}g.length>0&&(o(g),c(Math.min($,g.length-1)))}catch{}}},[n,e]),D(()=>{if(h.current)if(r.length>0){const p=r.map(V);sessionStorage.setItem(Wn,JSON.stringify({keys:p,activeIndex:s}))}else sessionStorage.removeItem(Wn)},[r,s]);const v=Y(p=>{const w=V(p),$=r.findIndex(g=>V(g)===w);$>=0?c($):(o(g=>[...g,p]),c(r.length)),d(!1)},[r]),x=Y(async p=>{const w=f.current.find(u=>V(u)===p);if(!w)return;const $=w.sessionDir??(w.type==="review"?`review-pr-${w.pr}`:`task-${w.task}`);try{await fetch("/api/cw/terminal/kill",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:w.project,sessionDir:$})})}catch{}const g=f.current.findIndex(u=>V(u)===p);if(g<0)return;Mo(p);const k=f.current.length-1;o(u=>u.filter(z=>V(z)!==p)),k===0?(d(!0),c(0),a()):c(u=>u>g?u-1:Math.min(u,k-1))},[a]),S=Y(p=>{const w=r[p];return w?x(V(w)):Promise.resolve()},[r,x]),b=Y(()=>{d(!0),a()},[a]);D(()=>{const p=w=>{if(r.length===0||i)return;const $=w.metaKey||w.ctrlKey;if($&&w.key>="1"&&w.key<="5"){const g=parseInt(w.key)-1;g<r.length&&(w.preventDefault(),c(g));return}if($&&(w.key==="ArrowLeft"||w.key==="ArrowRight")){w.preventDefault(),c(g=>w.key==="ArrowLeft"?g>0?g-1:r.length-1:g<r.length-1?g+1:0);return}if($&&w.key==="w"){w.preventDefault(),S(s);return}$&&w.key==="l"&&(w.preventDefault(),b())};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[r,i,s,S,b]);const y=ee(()=>new Set(r.map(V)),[r]);return{openTabs:r,activeTabIndex:s,setActiveTabIndex:c,showList:i,openTab:v,closeTab:S,closeTabByKey:x,goToList:b,openTabKeys:y}}function Vi({spaces:e,accounts:n,projects:a}){const[r,o]=m(null),[s,c]=m(null),[i,d]=m(null),[h,f]=m(null),[v,x]=m(!1),S=ee(()=>Array.from(new Set(e.map($=>$.harness??"claude"))).sort(),[e]),b=ee(()=>{if(n.length>0)return n;const $=new Set;for(const g of e)g.account&&$.add(g.account);return Array.from($).sort()},[n,e]),y=ee(()=>{const $=new Set;for(const g of e)r&&g.account!==r||ie(g)&&$.add(g.project);for(const[g,k]of Object.entries(a))r&&k.account!==r||$.add(g);return Array.from($).sort()},[e,a,r]),p=$=>{if(o($),$&&s){const g=a[s];g&&g.account!==$&&c(null)}},w=ee(()=>e.filter($=>!(r&&$.account!==r||s&&$.project!==s||h&&($.harness??"claude")!==h||i&&$.type!==Co(i)||!v&&$.status==="done")),[e,r,s,i,h,v]);return{filterAccount:r,setFilterAccount:p,filterProject:s,setFilterProject:c,filterType:i,setFilterType:d,filterHarness:h,setFilterHarness:f,showDone:v,setShowDone:x,accountNames:b,projectNames:y,harnessNames:S,filteredSpaces:w}}function Ji(){const[e,n]=m([]),[a,r]=m({}),[o,s]=m([]),[c,i]=m(!0),[d,h]=m("list"),[f,v]=m(!1),[x,S]=m(null),[b,y]=m(!1);D(()=>{be(),kr(),fetch("/api/liveframe/frames").then(C=>C.json()).then(C=>S(C.length)).catch(()=>{})},[]);const p=Y(async()=>{try{const[C,W,_]=await Promise.all([fetch("/api/cw/spaces"),fetch("/api/cw/projects"),fetch("/api/cw/accounts")]);n(await C.json()),r(await W.json()),s(await _.json()),yl()}catch{j("Failed to connect to server","error")}finally{i(!1)}},[]),w=Y(()=>{setTimeout(p,500),setTimeout(p,2500)},[p]);D(()=>{p()},[p]);const $=Gi({spaces:e,loading:c,onFetchData:p}),g=Vi({spaces:e,accounts:o,projects:a}),k=Object.keys(a).length>0,u=C=>{const W=Xe.find(_=>_.key===C);W&&(Ye.value=W.key),v(!0)},[z,E]=m(null),L=Y(async(C,W)=>{try{const G=await(await fetch("/api/cw/done",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:C.project,task:C.type==="review"?C.pr:C.task,type:C.type,sessionDir:C.sessionDir})})).json();if(G.ok)j("Task closed","info"),W==null||W(),w();else{const ne=G.error??"cw --done failed";console.error(`[forge] closing ${C.project}/${C.task??C.pr} failed:
29
29
  ${ne}`),j(ne.split(`
30
30
  `)[0],"error")}}catch{j("Failed to close the task","error")}},[w]),O=Y(async(C,W)=>{const _=await Gn(C,!0);if(_.state&&_.state.closeWarnings.length===0){await L(C,W);return}E({session:C,state:_.state,error:_.error,onClosed:W})},[L]),R=t(qi,{request:z,onCancel:()=>E(null),onConfirm:async()=>{const C=z;if(C)try{await L(C.session,C.onClosed)}finally{E(null)}}}),P=Y(C=>{je.value=!1,$.showList||$.goToList(),v(!1),h(C)},[$.showList,$.goToList]),T=Y(()=>P("list"),[P]),B=Y(()=>v(!1),[]),A=Y(C=>{g.setFilterProject(g.filterProject===C?null:C),P(d==="memory"?"memory":"list")},[g.filterProject,g.setFilterProject,P,d]),M=Y(C=>{g.setFilterProject(C),P("memory")},[g.setFilterProject,P]),F=Y(C=>{je.value=!1,v(!1),$.openTab(C)},[$.openTab]),[q,he]=m(!1),N=Y(()=>he(!1),[]),Z=Y(()=>he(!0),[]);D(()=>{const C=W=>{const _=W.metaKey||W.ctrlKey,G=W.key.toLowerCase();if(_&&G==="j"){W.preventDefault(),xa();return}if(_&&G==="k"){W.preventDefault(),q?he(!1):Z();return}const ne=W.target;ne!=null&&ne.closest('input, textarea, select, [contenteditable="true"]')||_||W.altKey||q||f||b||(W.key==="/"?(W.preventDefault(),Z()):G==="n"?(W.preventDefault(),v(!0)):G==="p"&&(W.preventDefault(),y(!0)))};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[q,f,b,Z]);const te=Y(async(C,W,_,G)=>{try{const X=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"general",account:W,project:_,description:C})})).json();X.ok&&X.session?(F(X.session),w(),j(G,"success")):j(X.error??"Failed to start session","error")}catch{j("Failed to start session","error")}},[F,w]),Se=Y((C,W)=>{const _=C==="project"&&a[W]?W:void 0;return{account:C==="account"?W:_?a[_].account:o[0]||"default",project:_}},[o,a]),Lt=Y((C,W,_)=>{const{account:G,project:ne}=Se(C,W),X=C==="global"?"~/.claude/skills/":C==="account"?`~/.cw/accounts/${W}/skills/`:`${ne?a[ne].path:"<project>"}/.claude/skills/`,ot=["Use the skill-creator skill to create a new Claude Code skill.","",`The user wants: ${_}`,`Target scope: ${C}${C!=="global"?` (${W})`:""}`,`Save location: ${X}`,"","Before creating from scratch, search for existing similar skills:","1. Search skills.sh for related skills (WebSearch or WebFetch https://skills.sh/api/search?q=<keywords>)","2. Search GitHub for claude-code skill repos","3. Present what you find — let the user pick a base or start fresh","","Then use skill-creator to build/customize the skill and save it."].join(`
@@ -7,7 +7,7 @@
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
8
8
  <title>Forge Console</title>
9
9
  <script type="importmap">{"imports":{"preact":"/shared/preact.js","preact/hooks":"/shared/preact-hooks.js","preact/jsx-runtime":"/shared/preact-jsx-runtime.js","preact/compat":"/shared/preact-compat.js","@preact/signals":"/shared/preact-signals.js","@forge-dev/ui":"/shared/forge-dev-ui.js","@forge-dev/sdk":"/shared/forge-dev-sdk.js"}}</script>
10
- <script type="module" crossorigin src="/assets/index-_CULM3sT.js"></script>
10
+ <script type="module" crossorigin src="/assets/index-BWlifYmN.js"></script>
11
11
  <link rel="stylesheet" crossorigin href="/assets/index-DPf7M8cb.css">
12
12
  <link rel="stylesheet" href="/shared/forge-dev-ui.css">
13
13
  </head>
@@ -1,13 +1,13 @@
1
- import{jsx as e}from"./preact-jsx-runtime.js";import{useState as B,useRef as w,useEffect as _,useLayoutEffect as H,useCallback as U}from"./preact-hooks.js";import{signal as ee}from"./preact-signals.js";import{createPortal as Z}from"./preact-compat.js";import"./preact.js";const re={good:"var(--green)",warn:"var(--orange)",bad:"var(--red)",neutral:"var(--ink-3)"},me=({icon:r,label:n,value:o,trend:t,status:a})=>e("div",{class:"relative overflow-hidden",style:{padding:"10px 12px",borderRadius:"13px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)"},children:[e("div",{class:"flex items-center gap-2",style:{fontSize:"11.5px",color:"var(--ink-2)"},children:[e("span",{children:r}),e("span",{children:n})]}),e("div",{class:"mono",style:{fontSize:"19px",fontWeight:650,marginTop:"2px"},children:o}),t&&e("div",{class:"mono",style:{fontSize:"11.5px",marginTop:"2px",color:t.startsWith("-")?"var(--red)":"var(--green)"},children:t}),e("div",{class:"absolute bottom-0 left-0 right-0 h-0.5",style:{backgroundColor:re[a]}})]}),te={sm:{pad:"6px 12px",primaryPad:"6px 14px",font:"12.5px",radius:"9px"},md:{pad:"7px 13px",primaryPad:"7px 15px",font:"13px",radius:"9px"},lg:{pad:"12px 16px",primaryPad:"12px 16px",font:"14.5px",radius:"12px"}},q={primary:{background:"linear-gradient(180deg, var(--blue-2), var(--blue))",color:"#fff",border:"0",boxShadow:"var(--shadow-m)",fontWeight:"600"},secondary:{background:"var(--card)",color:"var(--ink)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",fontWeight:"500"},danger:{background:"var(--card)",color:"var(--red)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",fontWeight:"500"},destructive:{background:"var(--red)",color:"#fff",border:"0",boxShadow:"var(--shadow-m)",fontWeight:"600"}},ne={background:"var(--elev)",color:"var(--ink-3)",border:"1px solid transparent",boxShadow:"none",opacity:".8"},oe=({label:r,icon:n,variant:o="primary",size:t="md",block:a,title:x,disabled:s,loading:c,onClick:d})=>{const[i,h]=B(!1),p=c??i,l=!!(s||p),u=async()=>{if(!l){h(!0);try{await d()}finally{h(!1)}}},f=te[t],S=o==="primary"||o==="destructive",L=s&&!p?{...q[o],...ne}:q[o];return e("button",{type:"button",class:`inline-flex items-center justify-center gap-1.5 whitespace-nowrap transition-all duration-180 ease-spring ${l?"cursor-not-allowed":`cursor-pointer hover:-translate-y-px hover:shadow-m${S?" hover:brightness-106":""}`}${a?" w-full":""}`,style:{...L,padding:S?f.primaryPad:f.pad,fontSize:f.font,borderRadius:f.radius},disabled:l,title:x,onClick:u,children:[p?e("span",{class:"i-lucide-loader-2 animate-spin"}):n?e("span",{class:n}):null,e("span",{children:r})]})},se="modulepreload",ae=function(r){return"/"+r},X={},N=function(n,o,t){let a=Promise.resolve();if(o&&o.length>0){let s=function(i){return Promise.all(i.map(h=>Promise.resolve(h).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),d=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));a=s(o.map(i=>{if(i=ae(i),i in X)return;X[i]=!0;const h=i.endsWith(".css"),p=h?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${i}"]${p}`))return;const l=document.createElement("link");if(l.rel=h?"stylesheet":se,h||(l.as="script"),l.crossOrigin="",l.href=i,d&&l.setAttribute("nonce",d),document.head.appendChild(l),h)return new Promise((u,f)=>{l.addEventListener("load",u),l.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${i}`)))})}))}function x(s){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=s,window.dispatchEvent(c),!c.defaultPrevented)throw s}return a.then(s=>{for(const c of s||[])c.status==="rejected"&&x(c.reason);return n().catch(x)})},ie='ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace',I=r=>({background:r==="dark"?"#0e0e10":"#1c1c1e",foreground:"#e3e3e8",cursor:"#e3e3e8",selectionBackground:"rgba(10,132,255,0.35)"}),ye=({streamUrl:r,content:n,wsUrl:o,height:t=300,onExit:a,onGiveUp:x,onConnectionChange:s,onOutput:c,focused:d=!0,theme:i="dark"})=>{const h=w(null),p=!!o,l=w(a);l.current=a;const u=w(x);u.current=x;const f=w(s);f.current=s;const S=w(c);S.current=c;const L=w(i);L.current=i;const j=w(d);j.current=d;const T=w(null);_(()=>{T.current&&(T.current.options.theme=I(i))},[i]),_(()=>{var k;p&&d&&((k=T.current)==null||k.focus())},[d,p]),_(()=>{if(!h.current)return;let k=!1,v=null,C=null,$=0;const J=[];return(async()=>{const{Terminal:F}=await N(async()=>{const{Terminal:b}=await import("./chunk-DlVFs1Kw.js").then(m=>m.x);return{Terminal:b}},[]),{FitAddon:K}=await N(async()=>{const{FitAddon:b}=await import("./chunk-BlxrFPDK.js").then(m=>m.a);return{FitAddon:b}},[]),{WebLinksAddon:G}=await N(async()=>{const{WebLinksAddon:b}=await import("./chunk-BWjmmSgS.js");return{WebLinksAddon:b}},[]);if(k)return;const g=new F({theme:I(L.current),fontSize:13,fontFamily:ie,convertEol:!p,disableStdin:!p,cursorBlink:p,scrollback:1e4});T.current=g;const D=b=>{var m;g.write(b),(m=S.current)==null||m.call(S,b)},M=new K;g.loadAddon(M),g.loadAddon(new G),g.open(h.current),setTimeout(()=>{M.fit(),p&&j.current&&g.focus()},50),n&&!p&&D(n);let E;if(r&&!p&&(E=new EventSource(r),E.addEventListener("output",b=>{const{chunk:m}=JSON.parse(b.data);D(m)}),E.addEventListener("done",b=>{const{exitCode:m}=JSON.parse(b.data);g.write(`\r
2
- \x1B[${m===0?"32":"31"}m--- Exit code: ${m} ---\x1B[0m\r
3
- `),E==null||E.close()})),o&&!k){const b=m=>{if(k)return;console.log("[ForgeTerminal] Connecting to:",m),v=new WebSocket(m);const O=[];v.onopen=()=>{var y;console.log("[ForgeTerminal] WebSocket OPEN"),$=0,(y=f.current)==null||y.call(f,!0),M.fit();const{cols:W,rows:z}=g;v.send(JSON.stringify({type:"resize",cols:W,rows:z})),O.push(g.onData(R=>{(v==null?void 0:v.readyState)===WebSocket.OPEN&&v.send(JSON.stringify({type:"input",data:R}))})),O.push(g.onResize(({cols:R,rows:P})=>{(v==null?void 0:v.readyState)===WebSocket.OPEN&&v.send(JSON.stringify({type:"resize",cols:R,rows:P}))}))},v.onmessage=W=>{var z;try{const y=JSON.parse(W.data);y.type==="output"||y.type==="scrollback"?D(y.data):y.type==="exit"?(g.write(`\r
1
+ import{jsx as e}from"./preact-jsx-runtime.js";import{useState as B,useRef as w,useEffect as O,useLayoutEffect as H,useCallback as U}from"./preact-hooks.js";import{signal as ee}from"./preact-signals.js";import{createPortal as Z}from"./preact-compat.js";import"./preact.js";const re={good:"var(--green)",warn:"var(--orange)",bad:"var(--red)",neutral:"var(--ink-3)"},me=({icon:r,label:n,value:o,trend:t,status:a})=>e("div",{class:"relative overflow-hidden",style:{padding:"10px 12px",borderRadius:"13px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)"},children:[e("div",{class:"flex items-center gap-2",style:{fontSize:"11.5px",color:"var(--ink-2)"},children:[e("span",{children:r}),e("span",{children:n})]}),e("div",{class:"mono",style:{fontSize:"19px",fontWeight:650,marginTop:"2px"},children:o}),t&&e("div",{class:"mono",style:{fontSize:"11.5px",marginTop:"2px",color:t.startsWith("-")?"var(--red)":"var(--green)"},children:t}),e("div",{class:"absolute bottom-0 left-0 right-0 h-0.5",style:{backgroundColor:re[a]}})]}),te={sm:{pad:"6px 12px",primaryPad:"6px 14px",font:"12.5px",radius:"9px"},md:{pad:"7px 13px",primaryPad:"7px 15px",font:"13px",radius:"9px"},lg:{pad:"12px 16px",primaryPad:"12px 16px",font:"14.5px",radius:"12px"}},q={primary:{background:"linear-gradient(180deg, var(--blue-2), var(--blue))",color:"#fff",border:"0",boxShadow:"var(--shadow-m)",fontWeight:"600"},secondary:{background:"var(--card)",color:"var(--ink)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",fontWeight:"500"},danger:{background:"var(--card)",color:"var(--red)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",fontWeight:"500"},destructive:{background:"var(--red)",color:"#fff",border:"0",boxShadow:"var(--shadow-m)",fontWeight:"600"}},ne={background:"var(--elev)",color:"var(--ink-3)",border:"1px solid transparent",boxShadow:"none",opacity:".8"},oe=({label:r,icon:n,variant:o="primary",size:t="md",block:a,title:h,disabled:s,loading:c,onClick:d})=>{const[i,f]=B(!1),p=c??i,l=!!(s||p),u=async()=>{if(!l){f(!0);try{await d()}finally{f(!1)}}},v=te[t],S=o==="primary"||o==="destructive",L=s&&!p?{...q[o],...ne}:q[o];return e("button",{type:"button",class:`inline-flex items-center justify-center gap-1.5 whitespace-nowrap transition-all duration-180 ease-spring ${l?"cursor-not-allowed":`cursor-pointer hover:-translate-y-px hover:shadow-m${S?" hover:brightness-106":""}`}${a?" w-full":""}`,style:{...L,padding:S?v.primaryPad:v.pad,fontSize:v.font,borderRadius:v.radius},disabled:l,title:h,onClick:u,children:[p?e("span",{class:"i-lucide-loader-2 animate-spin"}):n?e("span",{class:n}):null,e("span",{children:r})]})},se="modulepreload",ae=function(r){return"/"+r},X={},N=function(n,o,t){let a=Promise.resolve();if(o&&o.length>0){let s=function(i){return Promise.all(i.map(f=>Promise.resolve(f).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),d=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));a=s(o.map(i=>{if(i=ae(i),i in X)return;X[i]=!0;const f=i.endsWith(".css"),p=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${i}"]${p}`))return;const l=document.createElement("link");if(l.rel=f?"stylesheet":se,f||(l.as="script"),l.crossOrigin="",l.href=i,d&&l.setAttribute("nonce",d),document.head.appendChild(l),f)return new Promise((u,v)=>{l.addEventListener("load",u),l.addEventListener("error",()=>v(new Error(`Unable to preload CSS for ${i}`)))})}))}function h(s){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=s,window.dispatchEvent(c),!c.defaultPrevented)throw s}return a.then(s=>{for(const c of s||[])c.status==="rejected"&&h(c.reason);return n().catch(h)})},ie='ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace',I=r=>({background:r==="dark"?"#0e0e10":"#1c1c1e",foreground:"#e3e3e8",cursor:"#e3e3e8",selectionBackground:"rgba(10,132,255,0.35)"}),ye=({streamUrl:r,content:n,wsUrl:o,height:t=300,onExit:a,onGiveUp:h,onConnectionChange:s,onOutput:c,focused:d=!0,theme:i="dark"})=>{const f=w(null),p=!!o,l=w(a);l.current=a;const u=w(h);u.current=h;const v=w(s);v.current=s;const S=w(c);S.current=c;const L=w(i);L.current=i;const j=w(d);j.current=d;const T=w(null);O(()=>{T.current&&(T.current.options.theme=I(i))},[i]),O(()=>{var k;p&&d&&((k=T.current)==null||k.focus())},[d,p]),O(()=>{if(!f.current)return;let k=!1,g=null,C=null,$=0;const J=[];return(async()=>{const{Terminal:F}=await N(async()=>{const{Terminal:m}=await import("./chunk-DlVFs1Kw.js").then(x=>x.x);return{Terminal:m}},[]),{FitAddon:K}=await N(async()=>{const{FitAddon:m}=await import("./chunk-BlxrFPDK.js").then(x=>x.a);return{FitAddon:m}},[]),{WebLinksAddon:G}=await N(async()=>{const{WebLinksAddon:m}=await import("./chunk-BWjmmSgS.js");return{WebLinksAddon:m}},[]);if(k)return;const b=new F({theme:I(L.current),fontSize:13,fontFamily:ie,convertEol:!p,disableStdin:!p,cursorBlink:p,scrollback:1e4});T.current=b;const D=m=>{var x;b.write(m),(x=S.current)==null||x.call(S,m)},A=new K;b.loadAddon(A),b.loadAddon(new G((m,x)=>{/^https?:\/\//i.test(x)&&window.open(x,"_blank","noopener")})),b.open(f.current),setTimeout(()=>{A.fit(),p&&j.current&&b.focus()},50),n&&!p&&D(n);let E;if(r&&!p&&(E=new EventSource(r),E.addEventListener("output",m=>{const{chunk:x}=JSON.parse(m.data);D(x)}),E.addEventListener("done",m=>{const{exitCode:x}=JSON.parse(m.data);b.write(`\r
2
+ \x1B[${x===0?"32":"31"}m--- Exit code: ${x} ---\x1B[0m\r
3
+ `),E==null||E.close()})),o&&!k){const m=x=>{if(k)return;console.log("[ForgeTerminal] Connecting to:",x),g=new WebSocket(x);const M=[];g.onopen=()=>{var y;console.log("[ForgeTerminal] WebSocket OPEN"),$=0,(y=v.current)==null||y.call(v,!0),A.fit();const{cols:W,rows:z}=b;g.send(JSON.stringify({type:"resize",cols:W,rows:z})),M.push(b.onData(R=>{(g==null?void 0:g.readyState)===WebSocket.OPEN&&g.send(JSON.stringify({type:"input",data:R}))})),M.push(b.onResize(({cols:R,rows:P})=>{(g==null?void 0:g.readyState)===WebSocket.OPEN&&g.send(JSON.stringify({type:"resize",cols:R,rows:P}))}))},g.onmessage=W=>{var z;try{const y=JSON.parse(W.data);y.type==="output"||y.type==="scrollback"?D(y.data):y.type==="exit"?(b.write(`\r
4
4
  \x1B[33m--- Session ended (code ${y.code}) ---\x1B[0m\r
5
- `),(z=l.current)==null||z.call(l,y.code)):y.type==="error"&&g.write(`\r
5
+ `),(z=l.current)==null||z.call(l,y.code)):y.type==="error"&&b.write(`\r
6
6
  \x1B[31m--- Error: ${y.message} ---\x1B[0m\r
7
- `)}catch{}},v.onclose=W=>{var z,y,R;if(console.log("[ForgeTerminal] WebSocket CLOSE:",W.code,W.reason),O.forEach(P=>P.dispose()),O.length=0,(z=f.current)==null||z.call(f,!1),!k)if(W.code===4404)g.write(`\r
7
+ `)}catch{}},g.onclose=W=>{var z,y,R;if(console.log("[ForgeTerminal] WebSocket CLOSE:",W.code,W.reason),M.forEach(P=>P.dispose()),M.length=0,(z=v.current)==null||z.call(v,!1),!k)if(W.code===4404)b.write(`\r
8
8
  \x1B[31m--- Click Restart to try again. ---\x1B[0m\r
9
- `),(y=u.current)==null||y.call(u);else if($<5){const P=Math.min(2e3*Math.pow(2,$),16e3);$++,g.write(`\r
9
+ `),(y=u.current)==null||y.call(u);else if($<5){const P=Math.min(2e3*Math.pow(2,$),16e3);$++,b.write(`\r
10
10
  \x1B[90m--- Reconnecting (attempt ${$}/5)... ---\x1B[0m\r
11
- `),C=setTimeout(()=>b(m),P)}else g.write(`\r
11
+ `),C=setTimeout(()=>m(x),P)}else b.write(`\r
12
12
  \x1B[31m--- Connection lost. Click Restart to try again. ---\x1B[0m\r
13
- `),(R=u.current)==null||R.call(u)},v.onerror=W=>{console.error("[ForgeTerminal] WebSocket error:",W)}};b(o)}const V=new ResizeObserver(()=>{k||M.fit()});V.observe(h.current),J.push({dispose:()=>{E==null||E.close(),V.disconnect(),C&&clearTimeout(C),v&&(k=!0,v.close()),g.dispose(),T.current=null}})})(),()=>{k=!0,J.forEach(F=>F.dispose())}},[r,n,o,p]);const Y=p?{width:"100%",height:"100%"}:{width:"100%",height:`${t}px`};return e("div",{ref:h,class:"overflow-hidden",style:{...Y,background:I(i).background}})},A=ee([]);function we(r,n="info"){const o=Math.random().toString(36).slice(2);A.value=[...A.value,{id:o,message:r,type:n}],setTimeout(()=>{A.value=A.value.filter(t=>t.id!==o)},4e3)}const le={success:"var(--green)",error:"var(--red)",info:"var(--blue)"},ke=()=>e("div",{class:"fixed bottom-4 right-4 flex flex-col gap-2 z-[70]",style:{maxWidth:"calc(100vw - 32px)"},role:"status","aria-live":"polite",children:A.value.map(r=>e("div",{class:"flex items-center gap-2.5",style:{padding:"10px 14px",borderRadius:"12px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-l)",fontSize:"13px",color:"var(--ink)",animation:"riseIn .3s var(--ease) both"},children:[e("span",{class:"shrink-0",style:{width:"6px",height:"6px",borderRadius:"50%",background:le[r.type]}}),r.message]},r.id))}),ce=({label:r,color:n="var(--ink-2)",variant:o="tint",dot:t})=>{const a=o==="tint"?{background:`color-mix(in srgb, ${n} 18%, transparent)`,color:n}:{background:"var(--elev)",color:"var(--ink-2)",border:"1px solid var(--hair)"};return e("span",{class:"inline-flex items-center gap-1.5 whitespace-nowrap shrink-0",style:{...a,padding:"2px 8px",borderRadius:"99px",fontSize:"11px",fontWeight:600},children:[t&&e("span",{style:{width:"6px",height:"6px",borderRadius:"50%",background:n}}),r]})},Q=({onClick:r,label:n="Close"})=>e("button",{type:"button","aria-label":n,class:"grid place-items-center shrink-0 cursor-pointer transition-all duration-180 ease-spring hover:text-ink",style:{width:"26px",height:"26px",borderRadius:"50%",border:"1px solid var(--hair)",background:"var(--card)",color:"var(--ink-2)"},onClick:r,children:e("span",{class:"i-lucide-x",style:{width:"13px",height:"13px"}})}),Se=({open:r,title:n,onClose:o,footer:t,width:a=540,children:x})=>(H(()=>{if(!r)return;const s=c=>{c.key==="Escape"&&o()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[r,o]),r?Z(e("div",{class:"fixed inset-0 z-[55] flex items-start justify-center overflow-auto",style:{background:"rgba(0,0,0,.42)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",padding:"56px 16px 16px"},onClick:o,children:e("div",{role:"dialog","aria-modal":"true","aria-label":n,class:"flex flex-col overflow-hidden",style:{width:`min(${a}px, 100%)`,maxHeight:"calc(100vh - 72px)",borderRadius:"18px",background:"var(--bg-2)",border:"1px solid var(--hair-2)",boxShadow:"var(--shadow-l)",animation:"popIn .26s var(--ease) both"},onClick:s=>s.stopPropagation(),children:[e("div",{class:"flex items-center gap-2.5 shrink-0",style:{padding:"14px 18px",borderBottom:"1px solid var(--hair)"},children:[e("h2",{style:{fontSize:"17px",fontWeight:700,letterSpacing:"-0.02em"},children:n}),e("span",{class:"flex-1"}),e(Q,{onClick:o})]}),e("div",{class:"overflow-auto min-h-0",style:{padding:"16px 18px"},children:x}),t&&e("div",{class:"flex items-center gap-2.5 shrink-0",style:{padding:"13px 18px",borderTop:"1px solid var(--hair)"},children:t})]})}),document.body):null),Ee=({title:r,onClose:n,children:o})=>(H(()=>{const t=a=>{a.key==="Escape"&&n()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[n]),Z(e("div",{class:"fixed inset-0 z-50 flex justify-end",style:{background:"rgba(0,0,0,.38)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)"},onClick:n,children:e("aside",{role:"dialog","aria-modal":"true","aria-label":r,class:"flex flex-col h-full overflow-auto",style:{width:"min(492px, 100%)",background:"var(--bg-2)",borderLeft:"1px solid var(--hair)",boxShadow:"var(--shadow-l)",animation:"slideIn .3s var(--ease) both"},onClick:t=>t.stopPropagation(),children:[e("div",{class:"glass flex items-center sticky top-0 z-1",style:{gap:"10px",padding:"14px 18px",borderBottom:"1px solid var(--hair)"},children:[e("h2",{style:{fontSize:"17px",fontWeight:700,letterSpacing:"-0.02em"},children:r}),e("span",{class:"flex-1"}),e(Q,{onClick:n})]}),e("div",{class:"flex flex-col",style:{padding:"16px 18px 24px",gap:"14px"},children:o})]})}),document.body)),We=({tabs:r,active:n,onChange:o,fill:t,size:a="md",label:x})=>{const s=a!=="md",c=a==="xs";return e("div",{role:"tablist","aria-label":x,class:`${t?"flex":"inline-flex"} max-w-full overflow-x-auto`,style:{padding:"3px",borderRadius:s?"10px":"11px",background:"var(--elev)",border:"1px solid var(--hair)"},children:r.map(d=>{const i=n===d.id;return e("button",{type:"button",role:"tab","aria-selected":i,disabled:d.disabled,class:`flex items-center justify-center gap-1.5 whitespace-nowrap transition-all duration-200 ease-spring ${t?"flex-1":""} ${d.disabled?"cursor-not-allowed opacity-50":"cursor-pointer"}`,style:{padding:c?"4px 0":t?s?"5px 6px":"7px 8px":s?"5px 11px":"6px 12px",border:0,borderRadius:s?"7px":"8px",fontSize:c?"11.5px":s?"12px":"12.5px",fontWeight:600,background:i?"var(--card)":"transparent",color:i?"var(--ink)":"var(--ink-3)",boxShadow:i?"var(--shadow-s)":"none"},onClick:()=>o(d.id),children:[d.label,d.count!==void 0&&e("span",{class:"mono",style:{fontSize:"11px",fontWeight:400,color:"var(--ink-3)"},children:d.count})]},d.id)})})},de=({item:r,onItemClick:n})=>{const[o,t]=B(!1);return e("div",{class:`flex items-center justify-between transition-all duration-180 ease-spring ${n?"cursor-pointer":""}`,style:{padding:"11px 15px",borderRadius:"12px",background:"var(--card)",border:`1px solid ${n&&o?"var(--hair-2)":"var(--hair)"}`,boxShadow:"var(--shadow-s)"},onMouseEnter:n?()=>t(!0):void 0,onMouseLeave:n?()=>t(!1):void 0,onClick:n?()=>n(r.id):void 0,children:[e("div",{class:"min-w-0 flex-1",children:[e("div",{class:"truncate",style:{fontSize:"14px",fontWeight:600},children:r.title}),r.subtitle&&e("div",{class:"truncate",style:{fontSize:"12px",color:"var(--ink-2)",marginTop:"2px"},children:r.subtitle})]}),e("div",{class:"flex items-center gap-2 ml-3",children:[r.badge&&e(ce,{label:r.badge.label,color:r.badge.color,variant:"tint"}),r.trailing]})]})},ze=({items:r,loading:n,onItemClick:o})=>n?e("div",{class:"space-y-2",children:[1,2,3].map(t=>e("div",{class:"h-16 animate-pulse",style:{borderRadius:"12px",background:"var(--card)"}},t))}):r.length===0?null:e("div",{class:"space-y-1",children:r.map(t=>e(de,{item:t,onItemClick:o},t.id))}),Le=({icon:r,title:n,description:o,action:t})=>e("div",{class:"flex flex-col items-center justify-center text-center mx-auto",style:{maxWidth:"520px",padding:"36px 28px",borderRadius:"16px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-m)",animation:"riseIn .34s var(--ease) both"},children:[r&&e("span",{class:r,style:{width:"28px",height:"28px",color:"var(--ink-3)",marginBottom:"14px"}}),e("h3",{style:{fontSize:"17px",fontWeight:700,letterSpacing:"-0.02em",marginBottom:"6px"},children:n}),o&&e("p",{style:{fontSize:"13px",color:"var(--ink-2)",maxWidth:"40ch",marginBottom:t?"16px":0},children:o}),t&&e(oe,{label:t.label,variant:"primary",onClick:t.onClick})]}),Re=({checked:r,onChange:n,label:o,disabled:t})=>e("button",{type:"button",role:"switch","aria-checked":r,"aria-label":o,disabled:t,class:`relative shrink-0 ${t?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,style:{width:"44px",height:"26px",borderRadius:"99px",border:0,background:r?"var(--green)":"var(--hair-2)",transition:"background .22s var(--ease)"},onClick:()=>!t&&n(!r),children:e("span",{class:"absolute pointer-events-none",style:{top:"3px",left:r?"21px":"3px",width:"20px",height:"20px",borderRadius:"50%",background:"#fff",boxShadow:"var(--shadow-s)",transition:"left .22s var(--ease)"}})}),Te=({left:r,right:n,defaultWidth:o=300,minWidth:t=200,maxWidth:a=600,storageKey:x="forge-split-width"})=>{const[s,c]=B(()=>{if(typeof localStorage<"u"&&x){const l=localStorage.getItem(x);if(l){const u=parseInt(l,10);if(!isNaN(u)&&u>=t&&u<=a)return u}}return o}),d=w(!1),i=w(0),h=w(0),p=U(l=>{l.preventDefault(),d.current=!0,i.current=l.clientX,h.current=s,document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[s]);return _(()=>{const l=f=>{if(!d.current)return;const S=f.clientX-i.current,L=Math.min(a,Math.max(t,h.current+S));c(L)},u=()=>{d.current&&(d.current=!1,document.body.style.cursor="",document.body.style.userSelect="",typeof localStorage<"u"&&x&&localStorage.setItem(x,String(s)))};return document.addEventListener("mousemove",l),document.addEventListener("mouseup",u),()=>{document.removeEventListener("mousemove",l),document.removeEventListener("mouseup",u)}},[s,t,a,x]),e("div",{class:"flex h-full w-full overflow-hidden",children:[e("div",{class:"shrink-0 overflow-y-auto overflow-x-hidden",style:{width:`${s}px`},children:r}),e("div",{class:"shrink-0 w-1 cursor-col-resize transition-colors hover:bg-blue",style:{backgroundColor:"var(--hair)"},onMouseDown:p}),e("div",{class:"flex-1 min-w-0 overflow-hidden",children:n})]})},$e=({title:r,defaultOpen:n=!1,children:o})=>{const[t,a]=B(n);return e("div",{style:{borderBottom:"1px solid var(--hair)"},children:[e("button",{class:"flex items-center justify-between w-full px-3 py-2.5 cursor-pointer transition-colors text-ink3 hover:text-ink",style:{fontSize:"11px",fontWeight:600,border:0,background:"none"},onClick:()=>a(!t),children:[e("span",{children:r}),e("span",{class:"transition-transform",style:{transform:t?"rotate(90deg)":"rotate(0deg)"},children:e("span",{class:"i-lucide-chevron-right"})})]}),t&&e("div",{class:"px-3 pb-3",children:o})]})},pe={normal:"--blue",warning:"--orange",critical:"--red"},ue=({bar:r,size:n})=>{const o=`var(${pe[r.severity]})`,t=n==="sm",a=Math.max(0,Math.min(100,r.percent));return e("span",{class:"flex items-center w-full",style:{gap:t?"6px":"9px"},children:[e("span",{class:"mono shrink-0 text-right",style:{width:t?"28px":"32px",fontSize:t?"10px":"11.5px",color:"var(--ink-3)"},children:r.label}),e("span",{class:"relative block flex-1 overflow-hidden",style:{height:t?"4px":"6px",borderRadius:"99px",background:"var(--elev)"},children:e("span",{class:"block h-full",style:{width:`${a}%`,borderRadius:"99px",background:o,transition:"width .6s var(--ease)"}})}),e("span",{class:"mono shrink-0 text-right",style:{width:t?"30px":"36px",fontSize:t?"10px":"11.5px",fontWeight:600,color:r.severity==="normal"?"var(--ink-2)":o},children:[Math.round(r.percent),"%"]}),!t&&r.reset&&e("span",{class:"shrink-0 whitespace-nowrap",style:{fontSize:"11px",color:"var(--ink-3)"},children:r.reset})]})},Pe=({bars:r,size:n="md"})=>e("span",{class:"flex flex-col w-full",style:{gap:n==="sm"?"4px":"6px"},children:r.map((o,t)=>e("span",{class:"flex flex-col w-full",style:{gap:"2px"},children:[e(ue,{bar:o,size:n}),o.scope&&n==="md"&&e("span",{style:{paddingLeft:"39px",fontSize:"10.5px",color:"var(--ink-3)"},children:o.scope})]},t))});export{$e as AccordionSection,oe as ActionButton,ce as Badge,Q as CloseButton,ze as DataList,Ee as Drawer,Le as EmptyState,ye as ForgeTerminal,Se as Modal,Te as SplitPane,me as StatusCard,We as Tabs,ke as ToastContainer,Re as ToggleSwitch,Pe as UsageMeter,we as showToast,A as toasts};
13
+ `),(R=u.current)==null||R.call(u)},g.onerror=W=>{console.error("[ForgeTerminal] WebSocket error:",W)}};m(o)}const V=new ResizeObserver(()=>{k||A.fit()});V.observe(f.current),J.push({dispose:()=>{E==null||E.close(),V.disconnect(),C&&clearTimeout(C),g&&(k=!0,g.close()),b.dispose(),T.current=null}})})(),()=>{k=!0,J.forEach(F=>F.dispose())}},[r,n,o,p]);const Y=p?{width:"100%",height:"100%"}:{width:"100%",height:`${t}px`};return e("div",{ref:f,class:"overflow-hidden",style:{...Y,background:I(i).background}})},_=ee([]);function we(r,n="info"){const o=Math.random().toString(36).slice(2);_.value=[..._.value,{id:o,message:r,type:n}],setTimeout(()=>{_.value=_.value.filter(t=>t.id!==o)},4e3)}const le={success:"var(--green)",error:"var(--red)",info:"var(--blue)"},ke=()=>e("div",{class:"fixed bottom-4 right-4 flex flex-col gap-2 z-[70]",style:{maxWidth:"calc(100vw - 32px)"},role:"status","aria-live":"polite",children:_.value.map(r=>e("div",{class:"flex items-center gap-2.5",style:{padding:"10px 14px",borderRadius:"12px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-l)",fontSize:"13px",color:"var(--ink)",animation:"riseIn .3s var(--ease) both"},children:[e("span",{class:"shrink-0",style:{width:"6px",height:"6px",borderRadius:"50%",background:le[r.type]}}),r.message]},r.id))}),ce=({label:r,color:n="var(--ink-2)",variant:o="tint",dot:t})=>{const a=o==="tint"?{background:`color-mix(in srgb, ${n} 18%, transparent)`,color:n}:{background:"var(--elev)",color:"var(--ink-2)",border:"1px solid var(--hair)"};return e("span",{class:"inline-flex items-center gap-1.5 whitespace-nowrap shrink-0",style:{...a,padding:"2px 8px",borderRadius:"99px",fontSize:"11px",fontWeight:600},children:[t&&e("span",{style:{width:"6px",height:"6px",borderRadius:"50%",background:n}}),r]})},Q=({onClick:r,label:n="Close"})=>e("button",{type:"button","aria-label":n,class:"grid place-items-center shrink-0 cursor-pointer transition-all duration-180 ease-spring hover:text-ink",style:{width:"26px",height:"26px",borderRadius:"50%",border:"1px solid var(--hair)",background:"var(--card)",color:"var(--ink-2)"},onClick:r,children:e("span",{class:"i-lucide-x",style:{width:"13px",height:"13px"}})}),Se=({open:r,title:n,onClose:o,footer:t,width:a=540,children:h})=>(H(()=>{if(!r)return;const s=c=>{c.key==="Escape"&&o()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[r,o]),r?Z(e("div",{class:"fixed inset-0 z-[55] flex items-start justify-center overflow-auto",style:{background:"rgba(0,0,0,.42)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",padding:"56px 16px 16px"},onClick:o,children:e("div",{role:"dialog","aria-modal":"true","aria-label":n,class:"flex flex-col overflow-hidden",style:{width:`min(${a}px, 100%)`,maxHeight:"calc(100vh - 72px)",borderRadius:"18px",background:"var(--bg-2)",border:"1px solid var(--hair-2)",boxShadow:"var(--shadow-l)",animation:"popIn .26s var(--ease) both"},onClick:s=>s.stopPropagation(),children:[e("div",{class:"flex items-center gap-2.5 shrink-0",style:{padding:"14px 18px",borderBottom:"1px solid var(--hair)"},children:[e("h2",{style:{fontSize:"17px",fontWeight:700,letterSpacing:"-0.02em"},children:n}),e("span",{class:"flex-1"}),e(Q,{onClick:o})]}),e("div",{class:"overflow-auto min-h-0",style:{padding:"16px 18px"},children:h}),t&&e("div",{class:"flex items-center gap-2.5 shrink-0",style:{padding:"13px 18px",borderTop:"1px solid var(--hair)"},children:t})]})}),document.body):null),Ee=({title:r,onClose:n,children:o})=>(H(()=>{const t=a=>{a.key==="Escape"&&n()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[n]),Z(e("div",{class:"fixed inset-0 z-50 flex justify-end",style:{background:"rgba(0,0,0,.38)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)"},onClick:n,children:e("aside",{role:"dialog","aria-modal":"true","aria-label":r,class:"flex flex-col h-full overflow-auto",style:{width:"min(492px, 100%)",background:"var(--bg-2)",borderLeft:"1px solid var(--hair)",boxShadow:"var(--shadow-l)",animation:"slideIn .3s var(--ease) both"},onClick:t=>t.stopPropagation(),children:[e("div",{class:"glass flex items-center sticky top-0 z-1",style:{gap:"10px",padding:"14px 18px",borderBottom:"1px solid var(--hair)"},children:[e("h2",{style:{fontSize:"17px",fontWeight:700,letterSpacing:"-0.02em"},children:r}),e("span",{class:"flex-1"}),e(Q,{onClick:n})]}),e("div",{class:"flex flex-col",style:{padding:"16px 18px 24px",gap:"14px"},children:o})]})}),document.body)),We=({tabs:r,active:n,onChange:o,fill:t,size:a="md",label:h})=>{const s=a!=="md",c=a==="xs";return e("div",{role:"tablist","aria-label":h,class:`${t?"flex":"inline-flex"} max-w-full overflow-x-auto`,style:{padding:"3px",borderRadius:s?"10px":"11px",background:"var(--elev)",border:"1px solid var(--hair)"},children:r.map(d=>{const i=n===d.id;return e("button",{type:"button",role:"tab","aria-selected":i,disabled:d.disabled,class:`flex items-center justify-center gap-1.5 whitespace-nowrap transition-all duration-200 ease-spring ${t?"flex-1":""} ${d.disabled?"cursor-not-allowed opacity-50":"cursor-pointer"}`,style:{padding:c?"4px 0":t?s?"5px 6px":"7px 8px":s?"5px 11px":"6px 12px",border:0,borderRadius:s?"7px":"8px",fontSize:c?"11.5px":s?"12px":"12.5px",fontWeight:600,background:i?"var(--card)":"transparent",color:i?"var(--ink)":"var(--ink-3)",boxShadow:i?"var(--shadow-s)":"none"},onClick:()=>o(d.id),children:[d.label,d.count!==void 0&&e("span",{class:"mono",style:{fontSize:"11px",fontWeight:400,color:"var(--ink-3)"},children:d.count})]},d.id)})})},de=({item:r,onItemClick:n})=>{const[o,t]=B(!1);return e("div",{class:`flex items-center justify-between transition-all duration-180 ease-spring ${n?"cursor-pointer":""}`,style:{padding:"11px 15px",borderRadius:"12px",background:"var(--card)",border:`1px solid ${n&&o?"var(--hair-2)":"var(--hair)"}`,boxShadow:"var(--shadow-s)"},onMouseEnter:n?()=>t(!0):void 0,onMouseLeave:n?()=>t(!1):void 0,onClick:n?()=>n(r.id):void 0,children:[e("div",{class:"min-w-0 flex-1",children:[e("div",{class:"truncate",style:{fontSize:"14px",fontWeight:600},children:r.title}),r.subtitle&&e("div",{class:"truncate",style:{fontSize:"12px",color:"var(--ink-2)",marginTop:"2px"},children:r.subtitle})]}),e("div",{class:"flex items-center gap-2 ml-3",children:[r.badge&&e(ce,{label:r.badge.label,color:r.badge.color,variant:"tint"}),r.trailing]})]})},ze=({items:r,loading:n,onItemClick:o})=>n?e("div",{class:"space-y-2",children:[1,2,3].map(t=>e("div",{class:"h-16 animate-pulse",style:{borderRadius:"12px",background:"var(--card)"}},t))}):r.length===0?null:e("div",{class:"space-y-1",children:r.map(t=>e(de,{item:t,onItemClick:o},t.id))}),Le=({icon:r,title:n,description:o,action:t})=>e("div",{class:"flex flex-col items-center justify-center text-center mx-auto",style:{maxWidth:"520px",padding:"36px 28px",borderRadius:"16px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-m)",animation:"riseIn .34s var(--ease) both"},children:[r&&e("span",{class:r,style:{width:"28px",height:"28px",color:"var(--ink-3)",marginBottom:"14px"}}),e("h3",{style:{fontSize:"17px",fontWeight:700,letterSpacing:"-0.02em",marginBottom:"6px"},children:n}),o&&e("p",{style:{fontSize:"13px",color:"var(--ink-2)",maxWidth:"40ch",marginBottom:t?"16px":0},children:o}),t&&e(oe,{label:t.label,variant:"primary",onClick:t.onClick})]}),Re=({checked:r,onChange:n,label:o,disabled:t})=>e("button",{type:"button",role:"switch","aria-checked":r,"aria-label":o,disabled:t,class:`relative shrink-0 ${t?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,style:{width:"44px",height:"26px",borderRadius:"99px",border:0,background:r?"var(--green)":"var(--hair-2)",transition:"background .22s var(--ease)"},onClick:()=>!t&&n(!r),children:e("span",{class:"absolute pointer-events-none",style:{top:"3px",left:r?"21px":"3px",width:"20px",height:"20px",borderRadius:"50%",background:"#fff",boxShadow:"var(--shadow-s)",transition:"left .22s var(--ease)"}})}),Te=({left:r,right:n,defaultWidth:o=300,minWidth:t=200,maxWidth:a=600,storageKey:h="forge-split-width"})=>{const[s,c]=B(()=>{if(typeof localStorage<"u"&&h){const l=localStorage.getItem(h);if(l){const u=parseInt(l,10);if(!isNaN(u)&&u>=t&&u<=a)return u}}return o}),d=w(!1),i=w(0),f=w(0),p=U(l=>{l.preventDefault(),d.current=!0,i.current=l.clientX,f.current=s,document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[s]);return O(()=>{const l=v=>{if(!d.current)return;const S=v.clientX-i.current,L=Math.min(a,Math.max(t,f.current+S));c(L)},u=()=>{d.current&&(d.current=!1,document.body.style.cursor="",document.body.style.userSelect="",typeof localStorage<"u"&&h&&localStorage.setItem(h,String(s)))};return document.addEventListener("mousemove",l),document.addEventListener("mouseup",u),()=>{document.removeEventListener("mousemove",l),document.removeEventListener("mouseup",u)}},[s,t,a,h]),e("div",{class:"flex h-full w-full overflow-hidden",children:[e("div",{class:"shrink-0 overflow-y-auto overflow-x-hidden",style:{width:`${s}px`},children:r}),e("div",{class:"shrink-0 w-1 cursor-col-resize transition-colors hover:bg-blue",style:{backgroundColor:"var(--hair)"},onMouseDown:p}),e("div",{class:"flex-1 min-w-0 overflow-hidden",children:n})]})},$e=({title:r,defaultOpen:n=!1,children:o})=>{const[t,a]=B(n);return e("div",{style:{borderBottom:"1px solid var(--hair)"},children:[e("button",{class:"flex items-center justify-between w-full px-3 py-2.5 cursor-pointer transition-colors text-ink3 hover:text-ink",style:{fontSize:"11px",fontWeight:600,border:0,background:"none"},onClick:()=>a(!t),children:[e("span",{children:r}),e("span",{class:"transition-transform",style:{transform:t?"rotate(90deg)":"rotate(0deg)"},children:e("span",{class:"i-lucide-chevron-right"})})]}),t&&e("div",{class:"px-3 pb-3",children:o})]})},pe={normal:"--blue",warning:"--orange",critical:"--red"},ue=({bar:r,size:n})=>{const o=`var(${pe[r.severity]})`,t=n==="sm",a=Math.max(0,Math.min(100,r.percent));return e("span",{class:"flex items-center w-full",style:{gap:t?"6px":"9px"},children:[e("span",{class:"mono shrink-0 text-right",style:{width:t?"28px":"32px",fontSize:t?"10px":"11.5px",color:"var(--ink-3)"},children:r.label}),e("span",{class:"relative block flex-1 overflow-hidden",style:{height:t?"4px":"6px",borderRadius:"99px",background:"var(--elev)"},children:e("span",{class:"block h-full",style:{width:`${a}%`,borderRadius:"99px",background:o,transition:"width .6s var(--ease)"}})}),e("span",{class:"mono shrink-0 text-right",style:{width:t?"30px":"36px",fontSize:t?"10px":"11.5px",fontWeight:600,color:r.severity==="normal"?"var(--ink-2)":o},children:[Math.round(r.percent),"%"]}),!t&&r.reset&&e("span",{class:"shrink-0 whitespace-nowrap",style:{fontSize:"11px",color:"var(--ink-3)"},children:r.reset})]})},Pe=({bars:r,size:n="md"})=>e("span",{class:"flex flex-col w-full",style:{gap:n==="sm"?"4px":"6px"},children:r.map((o,t)=>e("span",{class:"flex flex-col w-full",style:{gap:"2px"},children:[e(ue,{bar:o,size:n}),o.scope&&n==="md"&&e("span",{style:{paddingLeft:"39px",fontSize:"10.5px",color:"var(--ink-3)"},children:o.scope})]},t))});export{$e as AccordionSection,oe as ActionButton,ce as Badge,Q as CloseButton,ze as DataList,Ee as Drawer,Le as EmptyState,ye as ForgeTerminal,Se as Modal,Te as SplitPane,me as StatusCard,We as Tabs,ke as ToastContainer,Re as ToggleSwitch,Pe as UsageMeter,we as showToast,_ as toasts};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forge-cw",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "description": "A visual dashboard for your coding agents on Claude Code, Codex, Pi or OpenCode. Installs CW for you.",
5
5
  "license": "MIT",
6
6
  "type": "module",