forge-cw 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,33 @@
1
+ (function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))o(i);new MutationObserver(i=>{for(const a of i)if(a.type==="childList")for(const l of a.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&o(l)}).observe(document,{childList:!0,subtree:!0});function r(i){const a={};return i.integrity&&(a.integrity=i.integrity),i.referrerPolicy&&(a.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?a.credentials="include":i.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function o(i){if(i.ep)return;i.ep=!0;const a=r(i);fetch(i.href,a)}})();var Ut,q,Lr,Ar,we,rr,Er,Ir,en,_t,et,Nr,In,mn,yn,Pt={},Lt=[],ri=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,Ht=Array.isArray;function ye(e,t){for(var r in t)e[r]=t[r];return e}function Nn(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function oi(e,t,r){var o,i,a,l={};for(a in t)a=="key"?o=t[a]:a=="ref"?i=t[a]:l[a]=t[a];if(arguments.length>2&&(l.children=arguments.length>3?Ut.call(arguments,2):r),typeof e=="function"&&e.defaultProps!=null)for(a in e.defaultProps)l[a]===void 0&&(l[a]=e.defaultProps[a]);return St(e,l,o,i,null)}function St(e,t,r,o,i){var a={type:e,props:t,key:r,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++Lr,__i:-1,__u:0};return i==null&&q.vnode!=null&&q.vnode(a),a}function Z(e){return e.children}function tt(e,t){this.props=e,this.context=t}function Ne(e,t){if(t==null)return e.__?Ne(e.__,e.__i+1):null;for(var r;t<e.__k.length;t++)if((r=e.__k[t])!=null&&r.__e!=null)return r.__e;return typeof e.type=="function"?Ne(e):null}function ii(e){if(e.__P&&e.__d){var t=e.__v,r=t.__e,o=[],i=[],a=ye({},t);a.__v=t.__v+1,q.vnode&&q.vnode(a),On(e.__P,a,t,e.__n,e.__P.namespaceURI,32&t.__u?[r]:null,o,r??Ne(t),!!(32&t.__u),i),a.__v=t.__v,a.__.__k[a.__i]=a,Fr(o,a,i),t.__e=t.__=null,a.__e!=r&&Or(a)}}function Or(e){if((e=e.__)!=null&&e.__c!=null)return e.__e=e.__c.base=null,e.__k.some(function(t){if(t!=null&&t.__e!=null)return e.__e=e.__c.base=t.__e}),Or(e)}function or(e){(!e.__d&&(e.__d=!0)&&we.push(e)&&!At.__r++||rr!=q.debounceRendering)&&((rr=q.debounceRendering)||Er)(At)}function At(){try{for(var e,t=1;we.length;)we.length>t&&we.sort(Ir),e=we.shift(),t=we.length,ii(e)}finally{we.length=At.__r=0}}function Wr(e,t,r,o,i,a,l,s,p,d,h){var c,m,k,g,b,f,u,x=o&&o.__k||Lt,v=t.length;for(p=ai(r,t,x,p,v),c=0;c<v;c++)(k=r.__k[c])!=null&&(m=k.__i!=-1&&x[k.__i]||Pt,k.__i=c,f=On(e,k,m,i,a,l,s,p,d,h),g=k.__e,k.ref&&m.ref!=k.ref&&(m.ref&&Wn(m.ref,null,k),h.push(k.ref,k.__c||g,k)),b==null&&g!=null&&(b=g),(u=!!(4&k.__u))||m.__k===k.__k?(p=Dr(k,p,e,u),u&&m.__e&&(m.__e=null)):typeof k.type=="function"&&f!==void 0?p=f:g&&(p=g.nextSibling),k.__u&=-7);return r.__e=b,p}function ai(e,t,r,o,i){var a,l,s,p,d,h=r.length,c=h,m=0;for(e.__k=new Array(i),a=0;a<i;a++)(l=t[a])!=null&&typeof l!="boolean"&&typeof l!="function"?(typeof l=="string"||typeof l=="number"||typeof l=="bigint"||l.constructor==String?l=e.__k[a]=St(null,l,null,null,null):Ht(l)?l=e.__k[a]=St(Z,{children:l},null,null,null):l.constructor===void 0&&l.__b>0?l=e.__k[a]=St(l.type,l.props,l.key,l.ref?l.ref:null,l.__v):e.__k[a]=l,p=a+m,l.__=e,l.__b=e.__b+1,s=null,(d=l.__i=si(l,r,p,c))!=-1&&(c--,(s=r[d])&&(s.__u|=2)),s==null||s.__v==null?(d==-1&&(i>h?m--:i<h&&m++),typeof l.type!="function"&&(l.__u|=4)):d!=p&&(d==p-1?m--:d==p+1?m++:(d>p?m--:m++,l.__u|=4))):e.__k[a]=null;if(c)for(a=0;a<h;a++)(s=r[a])!=null&&(2&s.__u)==0&&(s.__e==o&&(o=Ne(s)),Br(s,s));return o}function Dr(e,t,r,o){var i,a;if(typeof e.type=="function"){for(i=e.__k,a=0;i&&a<i.length;a++)i[a]&&(i[a].__=e,t=Dr(i[a],t,r,o));return t}e.__e!=t&&(o&&(t&&e.type&&!t.parentNode&&(t=Ne(e)),r.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function si(e,t,r,o){var i,a,l,s=e.key,p=e.type,d=t[r],h=d!=null&&(2&d.__u)==0;if(d===null&&s==null||h&&s==d.key&&p==d.type)return r;if(o>(h?1:0)){for(i=r-1,a=r+1;i>=0||a<t.length;)if((d=t[l=i>=0?i--:a++])!=null&&(2&d.__u)==0&&s==d.key&&p==d.type)return l}return-1}function ir(e,t,r){t[0]=="-"?e.setProperty(t,r??""):e[t]=r==null?"":typeof r!="number"||ri.test(t)?r:r+"px"}function vt(e,t,r,o,i){var a,l;e:if(t=="style")if(typeof r=="string")e.style.cssText=r;else{if(typeof o=="string"&&(e.style.cssText=o=""),o)for(t in o)r&&t in r||ir(e.style,t,"");if(r)for(t in r)o&&r[t]==o[t]||ir(e.style,t,r[t])}else if(t[0]=="o"&&t[1]=="n")a=t!=(t=t.replace(Nr,"$1")),l=t.toLowerCase(),t=l in e||t=="onFocusOut"||t=="onFocusIn"?l.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+a]=r,r?o?r[et]=o[et]:(r[et]=In,e.addEventListener(t,a?yn:mn,a)):e.removeEventListener(t,a?yn:mn,a);else{if(i=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{e[t]=r??"";break e}catch{}typeof r=="function"||(r==null||r===!1&&t[4]!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&r==1?"":r))}}function ar(e){return function(t){if(this.l){var r=this.l[t.type+e];if(t[_t]==null)t[_t]=In++;else if(t[_t]<r[et])return;return r(q.event?q.event(t):t)}}}function On(e,t,r,o,i,a,l,s,p,d){var h,c,m,k,g,b,f,u,x,v,C,y,R,A,L,I=t.type;if(t.constructor!==void 0)return null;128&r.__u&&(p=!!(32&r.__u),a=[s=t.__e=r.__e]),(h=q.__b)&&h(t);e:if(typeof I=="function")try{if(u=t.props,x=I.prototype&&I.prototype.render,v=(h=I.contextType)&&o[h.__c],C=h?v?v.props.value:h.__:o,r.__c?f=(c=t.__c=r.__c).__=c.__E:(x?t.__c=c=new I(u,C):(t.__c=c=new tt(u,C),c.constructor=I,c.render=ci),v&&v.sub(c),c.state||(c.state={}),c.__n=o,m=c.__d=!0,c.__h=[],c._sb=[]),x&&c.__s==null&&(c.__s=c.state),x&&I.getDerivedStateFromProps!=null&&(c.__s==c.state&&(c.__s=ye({},c.__s)),ye(c.__s,I.getDerivedStateFromProps(u,c.__s))),k=c.props,g=c.state,c.__v=t,m)x&&I.getDerivedStateFromProps==null&&c.componentWillMount!=null&&c.componentWillMount(),x&&c.componentDidMount!=null&&c.__h.push(c.componentDidMount);else{if(x&&I.getDerivedStateFromProps==null&&u!==k&&c.componentWillReceiveProps!=null&&c.componentWillReceiveProps(u,C),t.__v==r.__v||!c.__e&&c.shouldComponentUpdate!=null&&c.shouldComponentUpdate(u,c.__s,C)===!1){t.__v!=r.__v&&(c.props=u,c.state=c.__s,c.__d=!1),t.__e=r.__e,t.__k=r.__k,t.__k.some(function(S){S&&(S.__=t)}),Lt.push.apply(c.__h,c._sb),c._sb=[],c.__h.length&&l.push(c);break e}c.componentWillUpdate!=null&&c.componentWillUpdate(u,c.__s,C),x&&c.componentDidUpdate!=null&&c.__h.push(function(){c.componentDidUpdate(k,g,b)})}if(c.context=C,c.props=u,c.__P=e,c.__e=!1,y=q.__r,R=0,x)c.state=c.__s,c.__d=!1,y&&y(t),h=c.render(c.props,c.state,c.context),Lt.push.apply(c.__h,c._sb),c._sb=[];else do c.__d=!1,y&&y(t),h=c.render(c.props,c.state,c.context),c.state=c.__s;while(c.__d&&++R<25);c.state=c.__s,c.getChildContext!=null&&(o=ye(ye({},o),c.getChildContext())),x&&!m&&c.getSnapshotBeforeUpdate!=null&&(b=c.getSnapshotBeforeUpdate(k,g)),A=h!=null&&h.type===Z&&h.key==null?Mr(h.props.children):h,s=Wr(e,Ht(A)?A:[A],t,r,o,i,a,l,s,p,d),c.base=t.__e,t.__u&=-161,c.__h.length&&l.push(c),f&&(c.__E=c.__=null)}catch(S){if(t.__v=null,p||a!=null)if(S.then){for(t.__u|=p?160:128;s&&s.nodeType==8&&s.nextSibling;)s=s.nextSibling;a[a.indexOf(s)]=null,t.__e=s}else{for(L=a.length;L--;)Nn(a[L]);bn(t)}else t.__e=r.__e,t.__k=r.__k,S.then||bn(t);q.__e(S,t,r)}else a==null&&t.__v==r.__v?(t.__k=r.__k,t.__e=r.__e):s=t.__e=li(r.__e,t,r,o,i,a,l,p,d);return(h=q.diffed)&&h(t),128&t.__u?void 0:s}function bn(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(bn))}function Fr(e,t,r){for(var o=0;o<r.length;o++)Wn(r[o],r[++o],r[++o]);q.__c&&q.__c(t,e),e.some(function(i){try{e=i.__h,i.__h=[],e.some(function(a){a.call(i)})}catch(a){q.__e(a,i.__v)}})}function Mr(e){return typeof e!="object"||e==null||e.__b>0?e:Ht(e)?e.map(Mr):ye({},e)}function li(e,t,r,o,i,a,l,s,p){var d,h,c,m,k,g,b,f=r.props||Pt,u=t.props,x=t.type;if(x=="svg"?i="http://www.w3.org/2000/svg":x=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),a!=null){for(d=0;d<a.length;d++)if((k=a[d])&&"setAttribute"in k==!!x&&(x?k.localName==x:k.nodeType==3)){e=k,a[d]=null;break}}if(e==null){if(x==null)return document.createTextNode(u);e=document.createElementNS(i,x,u.is&&u),s&&(q.__m&&q.__m(t,a),s=!1),a=null}if(x==null)f===u||s&&e.data==u||(e.data=u);else{if(a=a&&Ut.call(e.childNodes),!s&&a!=null)for(f={},d=0;d<e.attributes.length;d++)f[(k=e.attributes[d]).name]=k.value;for(d in f)k=f[d],d=="dangerouslySetInnerHTML"?c=k:d=="children"||d in u||d=="value"&&"defaultValue"in u||d=="checked"&&"defaultChecked"in u||vt(e,d,null,k,i);for(d in u)k=u[d],d=="children"?m=k:d=="dangerouslySetInnerHTML"?h=k:d=="value"?g=k:d=="checked"?b=k:s&&typeof k!="function"||f[d]===k||vt(e,d,k,f[d],i);if(h)s||c&&(h.__html==c.__html||h.__html==e.innerHTML)||(e.innerHTML=h.__html),t.__k=[];else if(c&&(e.innerHTML=""),Wr(t.type=="template"?e.content:e,Ht(m)?m:[m],t,r,o,x=="foreignObject"?"http://www.w3.org/1999/xhtml":i,a,l,a?a[0]:r.__k&&Ne(r,0),s,p),a!=null)for(d=a.length;d--;)Nn(a[d]);s||(d="value",x=="progress"&&g==null?e.removeAttribute("value"):g!=null&&(g!==e[d]||x=="progress"&&!g||x=="option"&&g!=f[d])&&vt(e,d,g,f[d],i),d="checked",b!=null&&b!=e[d]&&vt(e,d,b,f[d],i))}return e}function Wn(e,t,r){try{if(typeof e=="function"){var o=typeof e.__u=="function";o&&e.__u(),o&&t==null||(e.__u=e(t))}else e.current=t}catch(i){q.__e(i,r)}}function Br(e,t,r){var o,i;if(q.unmount&&q.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||Wn(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(a){q.__e(a,t)}o.base=o.__P=null}if(o=e.__k)for(i=0;i<o.length;i++)o[i]&&Br(o[i],t,r||typeof e.type!="function");r||Nn(e.__e),e.__c=e.__=e.__e=void 0}function ci(e,t,r){return this.constructor(e,r)}function di(e,t,r){var o,i,a,l;t==document&&(t=document.documentElement),q.__&&q.__(e,t),i=(o=!1)?null:t.__k,a=[],l=[],On(t,e=t.__k=oi(Z,null,[e]),i||Pt,Pt,t.namespaceURI,i?null:t.firstChild?Ut.call(t.childNodes):null,a,i?i.__e:t.firstChild,o,l),Fr(a,e,l)}Ut=Lt.slice,q={__e:function(e,t,r,o){for(var i,a,l;t=t.__;)if((i=t.__c)&&!i.__)try{if((a=i.constructor)&&a.getDerivedStateFromError!=null&&(i.setState(a.getDerivedStateFromError(e)),l=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(e,o||{}),l=i.__d),l)return i.__E=i}catch(s){e=s}throw e}},Lr=0,Ar=function(e){return e!=null&&e.constructor===void 0},tt.prototype.setState=function(e,t){var r;r=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=ye({},this.state),typeof e=="function"&&(e=e(ye({},r),this.props)),e&&ye(r,e),e!=null&&this.__v&&(t&&this._sb.push(t),or(this))},tt.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),or(this))},tt.prototype.render=Z,we=[],Er=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Ir=function(e,t){return e.__v.__b-t.__v.__b},At.__r=0,en=Math.random().toString(8),_t="__d"+en,et="__a"+en,Nr=/(PointerCapture)$|Capture$/i,In=0,mn=ar(!1),yn=ar(!0);var pi=0;function n(e,t,r,o,i,a){t||(t={});var l,s,p=t;if("ref"in p)for(s in p={},t)s=="ref"?l=t[s]:p[s]=t[s];var d={type:e,props:p,key:r,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--pi,__i:-1,__u:0,__source:i,__self:a};if(typeof e=="function"&&(l=e.defaultProps))for(s in l)p[s]===void 0&&(p[s]=l[s]);return q.vnode&&q.vnode(d),d}var at,oe,tn,sr,st=0,Ur=[],ie=q,lr=ie.__b,cr=ie.__r,dr=ie.diffed,pr=ie.__c,ur=ie.unmount,hr=ie.__;function Dn(e,t){ie.__h&&ie.__h(oe,e,st||t),st=0;var r=oe.__H||(oe.__H={__:[],__h:[]});return e>=r.__.length&&r.__.push({}),r.__[e]}function w(e){return st=1,ui(Kr,e)}function ui(e,t,r){var o=Dn(at++,2);if(o.t=e,!o.__c&&(o.__=[Kr(void 0,t),function(s){var p=o.__N?o.__N[0]:o.__[0],d=o.t(p,s);p!==d&&(o.__N=[d,o.__[1]],o.__c.setState({}))}],o.__c=oe,!oe.__f)){var i=function(s,p,d){if(!o.__c.__H)return!0;var h=o.__c.__H.__.filter(function(m){return m.__c});if(h.every(function(m){return!m.__N}))return!a||a.call(this,s,p,d);var c=o.__c.props!==s;return h.some(function(m){if(m.__N){var k=m.__[0];m.__=m.__N,m.__N=void 0,k!==m.__[0]&&(c=!0)}}),a&&a.call(this,s,p,d)||c};oe.__f=!0;var a=oe.shouldComponentUpdate,l=oe.componentWillUpdate;oe.componentWillUpdate=function(s,p,d){if(this.__e){var h=a;a=void 0,i(s,p,d),a=h}l&&l.call(this,s,p,d)},oe.shouldComponentUpdate=i}return o.__N||o.__}function F(e,t){var r=Dn(at++,3);!ie.__s&&Hr(r.__H,t)&&(r.__=e,r.u=t,oe.__H.__h.push(r))}function X(e){return st=5,Q(function(){return{current:e}},[])}function Q(e,t){var r=Dn(at++,7);return Hr(r.__H,t)&&(r.__=e(),r.__H=t,r.__h=e),r.__}function Y(e,t){return st=8,Q(function(){return e},t)}function hi(){for(var e;e=Ur.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Ct),t.__h.some(kn),t.__h=[]}catch(r){t.__h=[],ie.__e(r,e.__v)}}}ie.__b=function(e){oe=null,lr&&lr(e)},ie.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),hr&&hr(e,t)},ie.__r=function(e){cr&&cr(e),at=0;var t=(oe=e.__c).__H;t&&(tn===oe?(t.__h=[],oe.__h=[],t.__.some(function(r){r.__N&&(r.__=r.__N),r.u=r.__N=void 0})):(t.__h.some(Ct),t.__h.some(kn),t.__h=[],at=0)),tn=oe},ie.diffed=function(e){dr&&dr(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Ur.push(t)!==1&&sr===ie.requestAnimationFrame||((sr=ie.requestAnimationFrame)||fi)(hi)),t.__H.__.some(function(r){r.u&&(r.__H=r.u),r.u=void 0})),tn=oe=null},ie.__c=function(e,t){t.some(function(r){try{r.__h.some(Ct),r.__h=r.__h.filter(function(o){return!o.__||kn(o)})}catch(o){t.some(function(i){i.__h&&(i.__h=[])}),t=[],ie.__e(o,r.__v)}}),pr&&pr(e,t)},ie.unmount=function(e){ur&&ur(e);var t,r=e.__c;r&&r.__H&&(r.__H.__.some(function(o){try{Ct(o)}catch(i){t=i}}),r.__H=void 0,t&&ie.__e(t,r.__v))};var fr=typeof requestAnimationFrame=="function";function fi(e){var t,r=function(){clearTimeout(o),fr&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(r,35);fr&&(t=requestAnimationFrame(r))}function Ct(e){var t=oe,r=e.__c;typeof r=="function"&&(e.__c=void 0,r()),oe=t}function kn(e){var t=oe;e.__c=e.__(),oe=t}function Hr(e,t){return!e||e.length!==t.length||t.some(function(r,o){return r!==e[o]})}function Kr(e,t){return typeof t=="function"?t(e):t}var vi=Symbol.for("preact-signals");function Kt(){if(be>1)be--;else{var e,t=!1;for((function(){var i=It;for(It=void 0;i!==void 0;)i.S.v===i.v&&(i.S.i=i.i),i=i.o})();nt!==void 0;){var r=nt;for(nt=void 0,Et++;r!==void 0;){var o=r.u;if(r.u=void 0,r.f&=-3,!(8&r.f)&&Jr(r))try{r.c()}catch(i){t||(e=i,t=!0)}r=o}}if(Et=0,be--,t)throw e}}function xi(e){if(be>0)return e();wn=++gi,be++;try{return e()}finally{Kt()}}var J=void 0;function Fn(e){var t=J;J=void 0;try{return e()}finally{J=t}}var nt=void 0,be=0,Et=0,gi=0,wn=0,It=void 0,Nt=0;function qr(e){if(J!==void 0){var t=e.n;if(t===void 0||t.t!==J)return t={i:0,S:e,p:J.s,n:void 0,t:J,e:void 0,x:void 0,r:t},J.s!==void 0&&(J.s.n=t),J.s=t,e.n=t,32&J.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=J.s,t.n=void 0,J.s.n=t,J.s=t),t}}function le(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t==null?void 0:t.watched,this.Z=t==null?void 0:t.unwatched,this.name=t==null?void 0:t.name}le.prototype.brand=vi;le.prototype.h=function(){return!0};le.prototype.S=function(e){var t=this,r=this.t;r!==e&&e.e===void 0&&(e.x=r,this.t=e,r!==void 0?r.e=e:Fn(function(){var o;(o=t.W)==null||o.call(t)}))};le.prototype.U=function(e){var t=this;if(this.t!==void 0){var r=e.e,o=e.x;r!==void 0&&(r.x=o,e.e=void 0),o!==void 0&&(o.e=r,e.x=void 0),e===this.t&&(this.t=o,o===void 0&&Fn(function(){var i;(i=t.Z)==null||i.call(t)}))}};le.prototype.subscribe=function(e){var t=this;return pt(function(){var r=t.value,o=J;J=void 0;try{e(r)}finally{J=o}},{name:"sub"})};le.prototype.valueOf=function(){return this.value};le.prototype.toString=function(){return this.value+""};le.prototype.toJSON=function(){return this.value};le.prototype.peek=function(){var e=this;return Fn(function(){return e.value})};Object.defineProperty(le.prototype,"value",{get:function(){var e=qr(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Et>100)throw new Error("Cycle detected");(function(r){be!==0&&Et===0&&r.l!==wn&&(r.l=wn,It={S:r,v:r.v,i:r.i,o:It})})(this),this.v=e,this.i++,Nt++,be++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Kt()}}}});function te(e,t){return new le(e,t)}function Jr(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function Gr(e){for(var t=e.s;t!==void 0;t=t.n){var r=t.S.n;if(r!==void 0&&(t.r=r),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function Vr(e){for(var t=e.s,r=void 0;t!==void 0;){var o=t.p;t.i===-1?(t.S.U(t),o!==void 0&&(o.n=t.n),t.n!==void 0&&(t.n.p=o)):r=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=o}e.s=r}function ze(e,t){le.call(this,void 0),this.x=e,this.s=void 0,this.g=Nt-1,this.f=4,this.W=t==null?void 0:t.watched,this.Z=t==null?void 0:t.unwatched,this.name=t==null?void 0:t.name}ze.prototype=new le;ze.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Nt))return!0;if(this.g=Nt,this.f|=1,this.i>0&&!Jr(this))return this.f&=-2,!0;var e=J;try{Gr(this),J=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(r){this.v=r,this.f|=16,this.i++}return J=e,Vr(this),this.f&=-2,!0};ze.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}le.prototype.S.call(this,e)};ze.prototype.U=function(e){if(this.t!==void 0&&(le.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};ze.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(ze.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=qr(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function vr(e,t){return new ze(e,t)}function Yr(e){var t=e.m;if(e.m=void 0,typeof t=="function"){be++;var r=J;J=void 0;try{t()}catch(o){throw e.f&=-2,e.f|=8,Mn(e),o}finally{J=r,Kt()}}}function Mn(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Yr(e)}function mi(e){if(J!==this)throw new Error("Out-of-order effect");Vr(this),J=e,this.f&=-2,8&this.f&&Mn(this),Kt()}function Be(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t==null?void 0:t.name}Be.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.m=t)}finally{e()}};Be.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Yr(this),Gr(this),be++;var e=J;return J=this,mi.bind(this,e)};Be.prototype.N=function(){2&this.f||(this.f|=2,this.u=nt,nt=this)};Be.prototype.d=function(){this.f|=8,1&this.f||Mn(this)};Be.prototype.dispose=function(){this.d()};function pt(e,t){var r=new Be(e,t);try{r.c()}catch(i){throw r.d(),i}var o=r.d.bind(r);return o[Symbol.dispose]=o,o}var Qr,xt,yi=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__,Zr=[];pt(function(){Qr=this.N})();function Ue(e,t){q[e]=t.bind(null,q[e]||function(){})}function Ot(e){if(xt){var t=xt;xt=void 0,t()}xt=e&&e.S()}function Xr(e){var t=this,r=e.data,o=ki(r);o.value=r;var i=Q(function(){for(var s=t,p=t.__v;p=p.__;)if(p.__c){p.__c.__$f|=4;break}var d=vr(function(){var k=o.value.value;return k===0?0:k===!0?"":k||""}),h=vr(function(){return!Array.isArray(d.value)&&!Ar(d.value)}),c=pt(function(){if(this.N=eo,h.value){var k=d.value;s.__v&&s.__v.__e&&s.__v.__e.nodeType===3&&(s.__v.__e.data=k)}}),m=t.__$u.d;return t.__$u.d=function(){c(),m.call(this)},[h,d]},[]),a=i[0],l=i[1];return a.value?l.peek():l.value}Xr.displayName="ReactiveTextNode";Object.defineProperties(le.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:Xr},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}});Ue("__b",function(e,t){if(typeof t.type=="string"){var r,o=t.props;for(var i in o)if(i!=="children"){var a=o[i];a instanceof le&&(r||(t.__np=r={}),r[i]=a,o[i]=a.peek())}}e(t)});Ue("__r",function(e,t){if(e(t),t.type!==Z){Ot();var r,o=t.__c;o&&(o.__$f&=-2,(r=o.__$u)===void 0&&(o.__$u=r=(function(i,a){var l;return pt(function(){l=this},{name:a}),l.c=i,l})(function(){var i;yi&&((i=r.y)==null||i.call(r)),o.__$f|=1,o.setState({})},typeof t.type=="function"?t.type.displayName||t.type.name:""))),Ot(r)}});Ue("__e",function(e,t,r,o){Ot(),e(t,r,o)});Ue("diffed",function(e,t){Ot();var r;if(typeof t.type=="string"&&(r=t.__e)){var o=t.__np,i=t.props;if(o){var a=r.U;if(a)for(var l in a){var s=a[l];s!==void 0&&!(l in o)&&(s.d(),a[l]=void 0)}else a={},r.U=a;for(var p in o){var d=a[p],h=o[p];d===void 0?(d=bi(r,p,h),a[p]=d):d.o(h,i)}for(var c in o)i[c]=o[c]}}e(t)});function bi(e,t,r,o){var i=t in e&&e.ownerSVGElement===void 0,a=te(r),l=r.peek();return{o:function(s,p){a.value=s,l=s.peek()},d:pt(function(){this.N=eo;var s=a.value.value;l!==s?(l=void 0,i?e[t]=s:s!=null&&(s!==!1||t[4]==="-")?e.setAttribute(t,s):e.removeAttribute(t)):l=void 0})}}Ue("unmount",function(e,t){if(typeof t.type=="string"){var r=t.__e;if(r){var o=r.U;if(o){r.U=void 0;for(var i in o){var a=o[i];a&&a.d()}}}t.__np=void 0}else{var l=t.__c;if(l){var s=l.__$u;s&&(l.__$u=void 0,s.d())}}e(t)});Ue("__h",function(e,t,r,o){(o<3||o===9)&&(t.__$f|=2),e(t,r,o)});tt.prototype.shouldComponentUpdate=function(e,t){if(this.__R)return!0;var r=this.__$u,o=r&&r.s!==void 0;for(var i in t)return!0;if(this.__f||typeof this.u=="boolean"&&this.u===!0){var a=2&this.__$f;if(!(o||a||4&this.__$f)||1&this.__$f)return!0}else if(!(o||4&this.__$f)||3&this.__$f)return!0;for(var l in e)if(l!=="__source"&&e[l]!==this.props[l])return!0;for(var s in this.props)if(!(s in e))return!0;return!1};function ki(e,t){return Q(function(){return te(e,t)},[])}var wi=function(e){queueMicrotask(function(){queueMicrotask(e)})};function _i(){xi(function(){for(var e;e=Zr.shift();)Qr.call(e)})}function eo(){Zr.push(this)===1&&(q.requestAnimationFrame||wi)(_i)}const Si={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"}},xr={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"}},Ci={background:"var(--elev)",color:"var(--ink-3)",border:"1px solid transparent",boxShadow:"none",opacity:".8"},D=({label:e,icon:t,variant:r="primary",size:o="md",block:i,title:a,disabled:l,loading:s,onClick:p})=>{const[d,h]=w(!1),c=s??d,m=!!(l||c),k=async()=>{if(!m){h(!0);try{await p()}finally{h(!1)}}},g=Si[o],b=r==="primary"||r==="destructive",f=l&&!c?{...xr[r],...Ci}:xr[r];return n("button",{type:"button",class:`inline-flex items-center justify-center gap-1.5 whitespace-nowrap transition-all duration-180 ease-spring ${m?"cursor-not-allowed":`cursor-pointer hover:-translate-y-px hover:shadow-m${b?" hover:brightness-106":""}`}${i?" w-full":""}`,style:{...f,padding:b?g.primaryPad:g.pad,fontSize:g.font,borderRadius:g.radius},disabled:m,title:a,onClick:k,children:[c?n("span",{class:"i-lucide-loader-2 animate-spin"}):t?n("span",{class:t}):null,n("span",{children:e})]})},$i="modulepreload",Ti=function(e){return"/"+e},gr={},nn=function(t,r,o){let i=Promise.resolve();if(r&&r.length>0){let l=function(d){return Promise.all(d.map(h=>Promise.resolve(h).then(c=>({status:"fulfilled",value:c}),c=>({status:"rejected",reason:c}))))};document.getElementsByTagName("link");const s=document.querySelector("meta[property=csp-nonce]"),p=(s==null?void 0:s.nonce)||(s==null?void 0:s.getAttribute("nonce"));i=l(r.map(d=>{if(d=Ti(d),d in gr)return;gr[d]=!0;const h=d.endsWith(".css"),c=h?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${c}`))return;const m=document.createElement("link");if(m.rel=h?"stylesheet":$i,h||(m.as="script"),m.crossOrigin="",m.href=d,p&&m.setAttribute("nonce",p),document.head.appendChild(m),h)return new Promise((k,g)=>{m.addEventListener("load",k),m.addEventListener("error",()=>g(new Error(`Unable to preload CSS for ${d}`)))})}))}function a(l){const s=new Event("vite:preloadError",{cancelable:!0});if(s.payload=l,window.dispatchEvent(s),!s.defaultPrevented)throw l}return i.then(l=>{for(const s of l||[])s.status==="rejected"&&a(s.reason);return t().catch(a)})},Ri='ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace',rn=e=>({background:e==="dark"?"#0e0e10":"#1c1c1e",foreground:"#e3e3e8",cursor:"#e3e3e8",selectionBackground:"rgba(10,132,255,0.35)"}),zi=({streamUrl:e,content:t,wsUrl:r,height:o=300,onExit:i,onGiveUp:a,onConnectionChange:l,onOutput:s,focused:p=!0,theme:d="dark"})=>{const h=X(null),c=!!r,m=X(i);m.current=i;const k=X(a);k.current=a;const g=X(l);g.current=l;const b=X(s);b.current=s;const f=X(d);f.current=d;const u=X(p);u.current=p;const x=X(null);F(()=>{x.current&&(x.current.options.theme=rn(d))},[d]),F(()=>{var C;c&&p&&((C=x.current)==null||C.focus())},[p,c]),F(()=>{if(!h.current)return;let C=!1,y=null,R=null,A=0;const L=[];return(async()=>{const{Terminal:S}=await nn(async()=>{const{Terminal:M}=await import("./xterm-DlVFs1Kw.js").then(j=>j.x);return{Terminal:M}},[]),{FitAddon:z}=await nn(async()=>{const{FitAddon:M}=await import("./addon-fit-BlxrFPDK.js").then(j=>j.a);return{FitAddon:M}},[]),{WebLinksAddon:_}=await nn(async()=>{const{WebLinksAddon:M}=await import("./addon-web-links-BWjmmSgS.js");return{WebLinksAddon:M}},[]);if(C)return;const N=new S({theme:rn(f.current),fontSize:13,fontFamily:Ri,convertEol:!c,disableStdin:!c,cursorBlink:c,scrollback:1e4});x.current=N;const O=M=>{var j;N.write(M),(j=b.current)==null||j.call(b,M)},E=new z;N.loadAddon(E),N.loadAddon(new _),N.open(h.current),setTimeout(()=>{E.fit(),c&&u.current&&N.focus()},50),t&&!c&&O(t);let B;if(e&&!c&&(B=new EventSource(e),B.addEventListener("output",M=>{const{chunk:j}=JSON.parse(M.data);O(j)}),B.addEventListener("done",M=>{const{exitCode:j}=JSON.parse(M.data);N.write(`\r
2
+ \x1B[${j===0?"32":"31"}m--- Exit code: ${j} ---\x1B[0m\r
3
+ `),B==null||B.close()})),r&&!C){const M=j=>{if(C)return;console.log("[ForgeTerminal] Connecting to:",j),y=new WebSocket(j);const G=[];y.onopen=()=>{var ae;console.log("[ForgeTerminal] WebSocket OPEN"),A=0,(ae=g.current)==null||ae.call(g,!0),E.fit();const{cols:V,rows:de}=N;y.send(JSON.stringify({type:"resize",cols:V,rows:de})),G.push(N.onData(ce=>{(y==null?void 0:y.readyState)===WebSocket.OPEN&&y.send(JSON.stringify({type:"input",data:ce}))})),G.push(N.onResize(({cols:ce,rows:pe})=>{(y==null?void 0:y.readyState)===WebSocket.OPEN&&y.send(JSON.stringify({type:"resize",cols:ce,rows:pe}))}))},y.onmessage=V=>{var de;try{const ae=JSON.parse(V.data);ae.type==="output"||ae.type==="scrollback"?O(ae.data):ae.type==="exit"?(N.write(`\r
4
+ \x1B[33m--- Session ended (code ${ae.code}) ---\x1B[0m\r
5
+ `),(de=m.current)==null||de.call(m,ae.code)):ae.type==="error"&&N.write(`\r
6
+ \x1B[31m--- Error: ${ae.message} ---\x1B[0m\r
7
+ `)}catch{}},y.onclose=V=>{var de,ae,ce;if(console.log("[ForgeTerminal] WebSocket CLOSE:",V.code,V.reason),G.forEach(pe=>pe.dispose()),G.length=0,(de=g.current)==null||de.call(g,!1),!C)if(V.code===4404)N.write(`\r
8
+ \x1B[31m--- Click Restart to try again. ---\x1B[0m\r
9
+ `),(ae=k.current)==null||ae.call(k);else if(A<5){const pe=Math.min(2e3*Math.pow(2,A),16e3);A++,N.write(`\r
10
+ \x1B[90m--- Reconnecting (attempt ${A}/5)... ---\x1B[0m\r
11
+ `),R=setTimeout(()=>M(j),pe)}else N.write(`\r
12
+ \x1B[31m--- Connection lost. Click Restart to try again. ---\x1B[0m\r
13
+ `),(ce=k.current)==null||ce.call(k)},y.onerror=V=>{console.error("[ForgeTerminal] WebSocket error:",V)}};M(r)}const H=new ResizeObserver(()=>{C||E.fit()});H.observe(h.current),L.push({dispose:()=>{B==null||B.close(),H.disconnect(),R&&clearTimeout(R),y&&(C=!0,y.close()),N.dispose(),x.current=null}})})(),()=>{C=!0,L.forEach(S=>S.dispose())}},[e,t,r,c]);const v=c?{width:"100%",height:"100%"}:{width:"100%",height:`${o}px`};return n("div",{ref:h,class:"overflow-hidden",style:{...v,background:rn(d).background}})},Ze=te([]);function P(e,t="info"){const r=Math.random().toString(36).slice(2);Ze.value=[...Ze.value,{id:r,message:e,type:t}],setTimeout(()=>{Ze.value=Ze.value.filter(o=>o.id!==r)},4e3)}const ji={success:"var(--green)",error:"var(--red)",info:"var(--blue)"},Pi=()=>n("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:Ze.value.map(e=>n("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:[n("span",{class:"shrink-0",style:{width:"6px",height:"6px",borderRadius:"50%",background:ji[e.type]}}),e.message]},e.id))}),to=({onClick:e,label:t="Close"})=>n("button",{type:"button","aria-label":t,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:e,children:n("span",{class:"i-lucide-x",style:{width:"13px",height:"13px"}})}),Bn=({open:e,title:t,onClose:r,footer:o,width:i=540,children:a})=>(F(()=>{if(!e)return;const l=s=>{s.key==="Escape"&&r()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[e,r]),e?n("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:r,children:n("div",{role:"dialog","aria-modal":"true","aria-label":t,class:"flex flex-col overflow-hidden",style:{width:`min(${i}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:l=>l.stopPropagation(),children:[n("div",{class:"flex items-center gap-2.5 shrink-0",style:{padding:"14px 18px",borderBottom:"1px solid var(--hair)"},children:[n("h2",{style:{fontSize:"17px",fontWeight:700,letterSpacing:"-0.02em"},children:t}),n("span",{class:"flex-1"}),n(to,{onClick:r})]}),n("div",{class:"overflow-auto min-h-0",style:{padding:"16px 18px"},children:a}),o&&n("div",{class:"flex items-center gap-2.5 shrink-0",style:{padding:"13px 18px",borderTop:"1px solid var(--hair)"},children:o})]})}):null),ve=({tabs:e,active:t,onChange:r,fill:o,size:i="md",label:a})=>{const l=i!=="md",s=i==="xs";return n("div",{role:"tablist","aria-label":a,class:`${o?"flex":"inline-flex"} max-w-full overflow-x-auto`,style:{padding:"3px",borderRadius:l?"10px":"11px",background:"var(--elev)",border:"1px solid var(--hair)"},children:e.map(p=>{const d=t===p.id;return n("button",{type:"button",role:"tab","aria-selected":d,disabled:p.disabled,class:`flex items-center justify-center gap-1.5 whitespace-nowrap transition-all duration-200 ease-spring ${o?"flex-1":""} ${p.disabled?"cursor-not-allowed opacity-50":"cursor-pointer"}`,style:{padding:s?"4px 0":o?l?"5px 6px":"7px 8px":l?"5px 11px":"6px 12px",border:0,borderRadius:l?"7px":"8px",fontSize:s?"11.5px":l?"12px":"12.5px",fontWeight:600,background:d?"var(--card)":"transparent",color:d?"var(--ink)":"var(--ink-3)",boxShadow:d?"var(--shadow-s)":"none"},onClick:()=>r(p.id),children:[p.label,p.count!==void 0&&n("span",{class:"mono",style:{fontSize:"11px",fontWeight:400,color:"var(--ink-3)"},children:p.count})]},p.id)})})},no=({icon:e,title:t,description:r,action:o})=>n("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:[e&&n("span",{class:e,style:{width:"28px",height:"28px",color:"var(--ink-3)",marginBottom:"14px"}}),n("h3",{style:{fontSize:"17px",fontWeight:700,letterSpacing:"-0.02em",marginBottom:"6px"},children:t}),r&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)",maxWidth:"40ch",marginBottom:o?"16px":0},children:r}),o&&n(D,{label:o.label,variant:"primary",onClick:o.onClick})]}),ro=({checked:e,onChange:t,label:r,disabled:o})=>n("button",{type:"button",role:"switch","aria-checked":e,"aria-label":r,disabled:o,class:`relative shrink-0 ${o?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,style:{width:"44px",height:"26px",borderRadius:"99px",border:0,background:e?"var(--green)":"var(--hair-2)",transition:"background .22s var(--ease)"},onClick:()=>!o&&t(!e),children:n("span",{class:"absolute pointer-events-none",style:{top:"3px",left:e?"21px":"3px",width:"20px",height:"20px",borderRadius:"50%",background:"#fff",boxShadow:"var(--shadow-s)",transition:"left .22s var(--ease)"}})}),Li={normal:"--blue",warning:"--orange",critical:"--red"},Ai=({bar:e,size:t})=>{const r=`var(${Li[e.severity]})`,o=t==="sm",i=Math.max(0,Math.min(100,e.percent));return n("span",{class:"flex items-center w-full",style:{gap:o?"6px":"9px"},children:[n("span",{class:"mono shrink-0 text-right",style:{width:o?"28px":"32px",fontSize:o?"10px":"11.5px",color:"var(--ink-3)"},children:e.label}),n("span",{class:"relative block flex-1 overflow-hidden",style:{height:o?"4px":"6px",borderRadius:"99px",background:"var(--elev)"},children:n("span",{class:"block h-full",style:{width:`${i}%`,borderRadius:"99px",background:r,transition:"width .6s var(--ease)"}})}),n("span",{class:"mono shrink-0 text-right",style:{width:o?"30px":"36px",fontSize:o?"10px":"11.5px",fontWeight:600,color:e.severity==="normal"?"var(--ink-2)":r},children:[Math.round(e.percent),"%"]}),!o&&e.reset&&n("span",{class:"shrink-0 whitespace-nowrap",style:{fontSize:"11px",color:"var(--ink-3)"},children:e.reset})]})},oo=({bars:e,size:t="md"})=>n("span",{class:"flex flex-col w-full",style:{gap:t==="sm"?"4px":"6px"},children:e.map((r,o)=>n("span",{class:"flex flex-col w-full",style:{gap:"2px"},children:[n(Ai,{bar:r,size:t}),r.scope&&t==="md"&&n("span",{style:{paddingLeft:"39px",fontSize:"10.5px",color:"var(--ink-3)"},children:r.scope})]},o))}),io="forge-theme",Ei=()=>{try{return localStorage.getItem(io)==="light"?"light":"dark"}catch{return"dark"}},ut=te(Ei());document.documentElement.setAttribute("data-theme",ut.value);const ao=e=>{ut.value=e,document.documentElement.setAttribute("data-theme",e);try{localStorage.setItem(io,e)}catch{}},Se=te(!1),mr=()=>ao(ut.value==="dark"?"light":"dark"),Ii=({sidebar:e,children:t})=>n("div",{class:"forge-shell",style:{minHeight:"100vh",display:"grid",gridTemplateColumns:"236px minmax(0,1fr)",background:"var(--bg)",color:"var(--ink)"},children:[e,n("div",{class:`sb-scrim${Se.value?" open":""}`,onClick:()=>{Se.value=!1}}),n("div",{class:"min-w-0 flex flex-col relative",style:{minHeight:"100vh"},children:t}),n(Pi,{})]}),yr=[["--blue","--purple"],["--teal","--blue"],["--orange","--red"],["--green","--teal"]],so=e=>yr[e%yr.length],se=(e,t=18)=>`color-mix(in srgb, var(${e}) ${t}%, transparent)`,Ae=(e,t,r)=>({label:e,glyph:t,token:r,ink:`var(${r})`,fill:se(r)}),_n={task:Ae("Dev","D","--orange"),review:Ae("Review","R","--blue"),loop:Ae("Loop","L","--purple"),general:Ae("General","G","--green")},Ni={create:Ae("Create","C","--teal"),login:Ae("Login","A","--ink-2")},Un=e=>_n[e]??Ni[e]??_n.task,He=[{key:"dev",sessionType:"task"},{key:"review",sessionType:"review"},{key:"loop",sessionType:"loop"},{key:"general",sessionType:"general"}],Hn=e=>{var t;return _n[((t=He.find(r=>r.key===e))==null?void 0:t.sessionType)??"task"].label},Oi=e=>{var t;return((t=He.find(r=>r.key===e))==null?void 0:t.sessionType)??"task"},Kn={working:{label:"Working",token:"--green",attention:!1},waiting:{label:"Waiting for you",token:"--orange",attention:!0},permission:{label:"Needs approval",token:"--red",attention:!0},error:{label:"Stopped on an error",token:"--red",attention:!0},exited:{label:"Exited",token:"--ink-3",attention:!1},idle:{label:"Idle",token:"--ink-3",attention:!1}},Oe=e=>!!(e&&(Kn[e.state].attention||e.state==="exited"&&(e.exitCode??0)!==0)),Wt=e=>e.state==="exited"&&e.exitCode?`Exited with code ${e.exitCode}`:Kn[e.state].label,$t=e=>e.state==="exited"&&e.exitCode?"--red":Kn[e.state].token,K=e=>e.sessionDir?`${e.project}::${e.sessionDir}`:`${e.project}::${e.task??e.pr}`,ue=e=>e.project==="__general"?"":e.project,qt=e=>e.sessionDir??(e.type==="review"?`review-pr-${e.pr}`:e.type==="loop"?`loop-${e.task}`:`task-${e.task}`),he=e=>e.type==="review"?`PR #${e.pr}`:e.type==="general"?e.task??`General (${e.account})`:e.type==="create"?`Create: ${e.task??"project"}`:e.type==="loop"?`Loop: ${e.task??"loop"}`:e.type==="login"?`Login: ${e.account} · ${fe(e.harness).label}`:e.task??"unknown",Wi={linear:"Linear",notion:"Notion"},qn=e=>{var r;const t=e.source?Wi[e.source]:void 0;return t&&((r=e.source_url)!=null&&r.startsWith("https://"))?{label:t,url:e.source_url}:null},lo=e=>{const t=Math.floor((Date.now()-new Date(e).getTime())/6e4);if(t<1)return"now";if(t<60)return`${t}m`;const r=Math.floor(t/60);if(r<24)return`${r}h`;const o=Math.floor(r/24);return o<30?`${o}d`:`${Math.floor(o/30)}mo`},gt=(e,t)=>({label:e,color:`var(--forge-harness-${t})`,bg:se(`--forge-harness-${t}`)}),Di={claude:gt("Claude Code","claude"),codex:gt("Codex","codex"),pi:gt("Pi","pi"),opencode:gt("OpenCode","opencode")},fe=e=>Di[e??"claude"]??{label:e??"claude",color:"var(--ink-3)",bg:"var(--elev)"},co=e=>{const t=fe(e.harness).label;return e.provider&&e.provider!=="native"?`${t} · ${e.model||e.provider}`:t},Fi=[{id:"",label:"Default",description:"Recommended model"},{id:"haiku",label:"Haiku",description:"Fast, simple tasks"},{id:"sonnet",label:"Sonnet",description:"Daily coding"},{id:"opus",label:"Opus",description:"Complex reasoning"}],po=(e,t,r,o)=>{var i,a;return(e?(i=r[e])==null?void 0:i.harness:void 0)??((a=o.accounts.find(l=>l.name===t))==null?void 0:a.default_harness)??"claude"},Ce=(e,t,r)=>{var o;return(o=e.accounts.find(i=>i.name===t))==null?void 0:o.harnesses.find(i=>i.harness===r)},Mi=/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/,Bi=new Intl.DateTimeFormat(void 0,{weekday:"short",hour:"2-digit",minute:"2-digit"}),uo=(e,t=Date.now())=>{if(!e)return null;const r=new Date(e).getTime();if(!Number.isFinite(r))return null;const o=Math.round((r-t)/6e4);if(o<=0)return"resets now";if(o<60)return`resets in ${o} m`;const i=Math.floor(o/60);if(i>=24)return`resets ${Bi.format(Math.round(r/6e4)*6e4)}`;const a=o%60;return`resets in ${i} h${a?` ${a} m`:""}`},ho=e=>e.map(t=>({label:t.label,percent:t.percent,severity:t.severity,scope:t.scope,reset:uo(t.resetsAt)})),We=te(null),Ui=3e3;let qe=null;function ge(e=!1){return qe||(qe=fetch(`/api/cw/harnesses${e?"?fresh=1":""}`).then(t=>t.json()).catch(()=>({available:!1,reason:"Could not reach the Forge server"})).then(t=>(We.value=t,qe=null,t)),qe)}const lt=new Set;let rt=null;const fo=()=>{lt.size===0&&rt&&(clearInterval(rt),rt=null)},Hi=async()=>{const e=await ge(!0),t=Date.now();for(const r of lt){const o=e.available&&r.check(e.doctor);(o||t>r.deadline)&&(lt.delete(r),r.onDone(o))}fo()};function Ki(e,{timeoutMs:t=6e5,onDone:r=()=>{}}={}){const o={check:e,deadline:Date.now()+t,onDone:r};return lt.add(o),rt||(rt=setInterval(Hi,Ui)),()=>{lt.delete(o),fo()}}const Ee=(e,t,r)=>{var o;return!!(e!=null&&e.available&&((o=e.capabilities[t])!=null&&o.includes(r)))},vo=e=>/linear\.app/.test(e)?"linear":/notion\.(so|site)/.test(e)?"notion":null,xo=(e,t,r)=>{const o=vo(r);return!!(e!=null&&e.available&&o&&!Ee(e,t,"mcp")&&!e.contextTokens[o])},ot=te(null);async function go(){const e=await fetch("/api/skills");if(!e.ok)throw new Error("fetch failed");ot.value=await e.json()}const $e=({size:e=7,color:t,live:r,glow:o=r})=>{const i=t??(r?"var(--green)":"var(--ink-3)");return n("span",{"aria-hidden":"true",class:`shrink-0 inline-block${r?" breathe":""}`,style:{width:`${e}px`,height:`${e}px`,borderRadius:"50%",background:i,boxShadow:o?`0 0 8px ${i}`:"none"}})},on=5,mo="forge-sidebar-collapsed",qi=()=>{try{const e=localStorage.getItem(mo);return e?JSON.parse(e):[]}catch{return[]}},Ji=(e,t)=>Number(t.live)-Number(e.live)||t.count-e.count||e.name.localeCompare(t.name),Gi=({projects:e,accounts:t,selected:r,onSelect:o,onAdd:i})=>{const[a,l]=w(""),[s,p]=w(qi),[d,h]=w([]),c=a.trim().toLowerCase(),m=Q(()=>{const g=[...t,...e.map(b=>b.account).filter(b=>!t.includes(b))];return Array.from(new Set(g)).map((b,f)=>({account:b,index:f,items:e.filter(u=>u.account===b&&(!c||u.name.toLowerCase().includes(c))).sort(Ji),active:e.filter(u=>u.account===b).reduce((u,x)=>u+x.count,0)})).filter(b=>b.items.length>0)},[e,t,c]),k=g=>{const b=s.includes(g)?s.filter(f=>f!==g):[...s,g];p(b);try{localStorage.setItem(mo,JSON.stringify(b))}catch{}};return n("div",{class:"flex flex-col sb-section min-h-0",style:{gap:"6px",flex:"0 1 auto",minHeight:"120px"},children:[n("div",{class:"flex items-center justify-between shrink-0",style:{padding:"0 9px"},children:[n("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--ink-3)",letterSpacing:".02em"},children:"Projects"}),n("button",{type:"button","aria-label":"Add project",title:"Add project (P)",class:"grid place-items-center cursor-pointer",style:{border:0,background:"none",color:"var(--blue)",padding:"0 2px"},onClick:i,children:n("span",{class:"i-lucide-plus",style:{width:"14px",height:"14px"}})})]}),n("label",{class:"relative shrink-0 block",style:{margin:"0 2px"},children:[n("span",{class:"i-lucide-search absolute pointer-events-none",style:{left:"9px",top:"8px",width:"12px",height:"12px",color:"var(--ink-3)"}}),n("input",{type:"search",class:"field","aria-label":"Filter projects",placeholder:"Filter projects",value:a,style:{height:"28px",padding:"0 8px 0 27px",borderRadius:"8px",fontSize:"12.5px",background:"var(--elev)"},onInput:g=>l(g.target.value),onKeyDown:g=>{g.key==="Escape"&&l("")}})]}),n("div",{class:"flex flex-col overflow-y-auto min-h-0",style:{gap:"8px",overscrollBehavior:"contain"},children:[m.length===0&&n("p",{style:{padding:"4px 9px",fontSize:"12px",color:"var(--ink-3)"},children:["No project matches “",a.trim(),"”."]}),m.map(g=>{const b=c!==""||!s.includes(g.account),f=c!==""||d.includes(g.account)||g.items.some((y,R)=>R>=on&&y.name===r),u=f?g.items:g.items.slice(0,on),[x,v]=so(g.index),C=g.items.some(y=>y.live);return n("div",{class:"flex flex-col shrink-0",style:{gap:"1px"},children:[n("button",{type:"button","aria-expanded":b,class:"flex items-center w-full text-left cursor-pointer transition-colors duration-160 hover:bg-elev",style:{gap:"7px",height:"26px",padding:"0 7px",borderRadius:"8px",border:0,background:"none",color:"var(--ink-2)"},onClick:()=>k(g.account),children:[n("span",{class:"i-lucide-chevron-right shrink-0",style:{width:"11px",height:"11px",color:"var(--ink-3)",transform:b?"rotate(90deg)":"none",transition:"transform .2s var(--ease)"}}),n("span",{class:"grid place-items-center shrink-0",style:{width:"16px",height:"16px",borderRadius:"5px",background:`linear-gradient(160deg, var(${x}), var(${v}))`,color:"#fff",fontSize:"9px",fontWeight:700},children:g.account.charAt(0).toUpperCase()}),n("span",{class:"flex-1 truncate",style:{fontSize:"12px",fontWeight:600},children:g.account}),C&&n($e,{size:5,live:!0,glow:!1}),n("span",{class:"mono",style:{fontSize:"10.5px",color:"var(--ink-3)"},title:`${g.items.length} projects · ${g.active} active tasks`,children:g.items.length})]}),b&&n("div",{class:"flex flex-col",style:{gap:"1px",marginLeft:"13px",paddingLeft:"6px",borderLeft:"1px solid var(--hair)",animation:"riseIn .24s var(--ease) both"},children:[u.map(y=>{const R=r===y.name;return n("button",{type:"button","aria-pressed":R,class:"flex items-center w-full text-left shrink-0 cursor-pointer transition-all duration-180 ease-spring hover:bg-elev",style:{gap:"8px",height:"27px",padding:"0 8px",borderRadius:"8px",fontSize:"13px",color:"var(--ink)",border:`1px solid ${R?"var(--hair)":"transparent"}`,background:R?"var(--card)":"transparent",boxShadow:R?"var(--shadow-s)":"none"},onClick:()=>o(y.name),children:[n($e,{size:6,live:y.live}),n("span",{class:"flex-1 truncate",style:{fontWeight:R?600:450,opacity:y.count>0||y.live||R?1:.62},children:y.name}),y.count>0&&n("span",{class:"mono",style:{fontSize:"11px",color:"var(--ink-3)"},children:y.count})]},y.name)}),g.items.length>on&&c===""&&n("button",{type:"button",class:"text-left cursor-pointer hover:underline",style:{padding:"3px 8px",border:0,background:"none",color:"var(--blue)",fontSize:"11.5px",fontWeight:500},onClick:()=>h(f?d.filter(y=>y!==g.account):[...d,g.account]),children:f?"Show less":`Show all ${g.items.length}`})]})]},g.account)})]})]})},yo={context:null,tokens:null,cost:null},Vi=250,Dt=new Map,Yi=/\x1b\[[0-9;?]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\x1b[@-_]/g,Je=(e,t)=>{let r=null;for(const o of e.matchAll(t))r=o;return r},an=e=>{const t=parseFloat(e),r=e.slice(-1).toLowerCase();return r==="k"?t*1e3:r==="m"?t*1e6:t};function Qi(e){const t={},r=Je(e,/(?:ctx|context)[:\s]*(\d{1,3}(?:\.\d+)?)\s*%/gi)??Je(e,/[▓█▒░]+\s*(\d{1,3}(?:\.\d+)?)\s*%/g);r&&(t.context=Math.min(100,parseFloat(r[1])));const o=Je(e,/(\d+(?:\.\d+)?[kKmM]?)\s*↑\s*(\d+(?:\.\d+)?[kKmM]?)\s*↓/g),i=Je(e,/\((\d+(?:\.\d+)?[kKmM])\s*\/\s*\d+(?:\.\d+)?[kKmM]\)/g);o?t.tokens=an(o[1])+an(o[2]):i&&(t.tokens=an(i[1]));const a=Je(e,/\$(\d+\.\d{2})\b/g);return a&&(t.cost=parseFloat(a[1])),t}const bo=e=>{let t=Dt.get(e);return t||(t={tail:"",timer:null,metrics:te(yo)},Dt.set(e,t)),t},ko=e=>bo(e).metrics,Zi=e=>{e.timer=null;const t=e.metrics.value,r={...t,...Qi(e.tail)};(r.context!==t.context||r.tokens!==t.tokens||r.cost!==t.cost)&&(e.metrics.value=r)};function Xi(e,t){const r=bo(e);r.tail=(r.tail+t.slice(-4e3*2).replace(Yi,"")).slice(-4e3),r.timer||(r.timer=setTimeout(()=>Zi(r),Vi))}function ea(e){const t=Dt.get(e);t&&(t.timer&&clearTimeout(t.timer),t.metrics.value=yo,Dt.delete(e))}const wo=e=>e>=1e6?`${(e/1e6).toFixed(e>=1e7?0:1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:String(e),_o=e=>`$${e.toFixed(2)}`,ct=te(null),ta=6e4;let Ge=null,Ve=null,sn=0;function br(e=!1){return Ge||(Ge=fetch(`/api/cw/usage${e?"?fresh=1":""}`).then(t=>t.json()).catch(()=>({available:!1,reason:"Could not reach the Forge server"})).then(t=>(ct.value=t,Ge=null,t)),Ge)}function So(){return sn+=1,br(),Ve||(Ve=setInterval(()=>{document.visibilityState==="visible"&&br()},ta)),()=>{sn-=1,sn===0&&Ve&&(clearInterval(Ve),Ve=null)}}const na=(e,t)=>{var r;return((r=ct.value)!=null&&r.available?ct.value.usage.find(o=>o.account===e&&o.harness===t):null)??null},Te=te({}),kr=te(null),Co=2e3,ra=15e3;let Ye=null,$o=0,ln=!1;const Tt=new Set,oa=(e,t)=>!!e&&Oe(t)&&(e.state!==t.state||e.since!==t.since);async function To(){if(!ln){ln=!0,$o=Date.now();try{const e=await fetch("/api/cw/session-states");if(!e.ok)return;const{states:t}=await e.json(),r=Te.value;Te.value=t;for(const[o,i]of Object.entries(t))if(oa(r[o],i))for(const a of Tt)a(o,i)}catch{}finally{ln=!1}}}const ia=()=>{const e=document.visibilityState==="visible"?Co:ra;Date.now()-$o>=e-100&&To()};function aa(e){return Tt.add(e),Ye||(To(),Ye=setInterval(ia,Co)),()=>{Tt.delete(e),Tt.size===0&&Ye&&(clearInterval(Ye),Ye=null)}}const Ro="forge.notify-sessions",Jt=typeof window<"u"&&"Notification"in window,sa=()=>{try{return Jt&&Notification.permission==="granted"&&localStorage.getItem(Ro)==="1"}catch{return!1}},Jn=te(sa());async function la(e){if(e&&(!Jt||(Notification.permission==="default"?await Notification.requestPermission():Notification.permission)!=="granted"))return!1;Jn.value=e;try{localStorage.setItem(Ro,e?"1":"0")}catch{}return!0}function ca(e,t,r,o){if(!Jn.value||!Jt||Notification.permission!=="granted")return;const i=new Notification(e,{body:t,tag:r});i.onclick=()=>{window.focus(),o(),i.close()}}const zo=[{view:"list",label:"Tasks",glyph:"T",token:"--blue"},{view:"accounts",label:"Accounts",glyph:"A",token:"--purple"},{view:"skills",label:"Skills",glyph:"S",token:"--green"},{view:"prototypes",label:"Prototypes",glyph:"P",token:"--orange"}],da="flex items-center w-full text-left cursor-pointer transition-all duration-180 ease-spring hover:bg-elev",pa=e=>({borderRadius:"9px",border:`1px solid ${e?"var(--hair)":"transparent"}`,background:e?"var(--card)":"transparent",boxShadow:e?"var(--shadow-s)":"none",color:"var(--ink)"}),jo="flex flex-col text-left cursor-pointer transition-all duration-180 ease-spring hover:-translate-y-px hover:shadow-m",Sn={gap:"6px",padding:"9px 10px",borderRadius:"12px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",color:"var(--ink)"},Cn={fontSize:"10.5px",color:"var(--ink-3)"},wr=({children:e})=>n("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--ink-3)",letterSpacing:".02em"},children:e}),ua=({id:e,session:t,index:r,onOpen:o})=>{const i=ko(e).value,a=Te.value[e],l=Oe(a),s=t.type==="loop",p=(i==null?void 0:i.context)??null,[d,h]=r%2===0?["var(--blue)","var(--purple)"]:["var(--purple)","var(--blue)"],c=l?Wt(a):s?t.loop_interval?`every ${t.loop_interval}`:"self-paced":i&&(i.tokens!==null||i.cost!==null)?[i.tokens!==null?`${wo(i.tokens)} tokens`:null,i.cost!==null?_o(i.cost):null].filter(Boolean).join(" · "):ue(t)||t.account;return n("button",{type:"button",class:jo,style:l?{...Sn,borderColor:`var(${$t(a)})`}:Sn,onClick:o,title:a?Wt(a):void 0,children:[n("span",{class:"flex items-center w-full",style:{gap:"6px"},children:[n($e,{size:6,color:a?`var(${$t(a)})`:d,live:!a||a.state==="working"||l}),n("span",{class:"truncate",style:{fontSize:"12.5px",fontWeight:600},children:he(t)}),n("span",{class:"flex-1"}),n("span",{class:"mono",style:{fontSize:"11px",color:"var(--ink-2)"},children:p!==null?`${Math.round(p)}%`:"—"})]}),n("span",{class:"relative block w-full overflow-hidden",style:{height:"5px",borderRadius:"99px",background:"var(--elev)"},children:[n("span",{class:"block h-full",style:{width:`${p??0}%`,borderRadius:"99px",background:`linear-gradient(90deg, ${d}, ${h})`,transition:"width .6s var(--ease)"}}),n("span",{class:"absolute inset-y-0 left-0",style:{width:"30%",background:"linear-gradient(90deg, transparent, rgba(255,255,255,.22), transparent)",animation:"sweep 2.6s ease-in-out infinite"}})]}),n("span",{class:"mono truncate w-full",style:l?{...Cn,color:`var(${$t(a)})`,fontWeight:600}:Cn,children:c})]})},ha=()=>n("label",{class:"flex items-center justify-between",style:{gap:"8px",padding:"0 9px",fontSize:"12px",color:"var(--ink-2)"},children:[n("span",{class:"sb-label",children:"Notify when a session needs me"}),n(ro,{checked:Jn.value,label:"Notify when a session needs me",onChange:e=>{la(e).then(t=>{t||P("The browser blocked notifications for Forge","error")})}})]}),fa=({account:e,harness:t,windows:r,stale:o,onOpen:i})=>{const a=r.reduce((s,p)=>p.percent>s.percent?p:s),l=fe(t).label;return n("button",{type:"button",class:jo,style:Sn,onClick:i,title:`Usage limits for ${e} on ${l}`,children:[n("span",{class:"flex items-center w-full",style:{gap:"6px"},children:[n("span",{class:"truncate",style:{fontSize:"12.5px",fontWeight:600},children:e}),n("span",{class:"flex-1"}),n("span",{class:"mono truncate",style:{fontSize:"10px",color:"var(--ink-3)"},children:l})]}),n(oo,{bars:ho(r),size:"sm"}),n("span",{class:"mono truncate w-full",style:Cn,children:o?"last known values":uo(a.resetsAt)})]})},va=({view:e,counts:t,projects:r,accounts:o,selectedProject:i,live:a,onNavigate:l,onSelectProject:s,onAddProject:p,onOpenLive:d,onSearch:h})=>{var b,f;const c=(b=We.value)!=null&&b.available?We.value.doctor.cw_version:null,m=zo.map(u=>{var x;return{...u,count:u.view==="skills"?((x=ot.value)==null?void 0:x.length)??null:t[u.view]??null}});F(()=>So(),[]);const k=[...a].sort((u,x)=>Number(Oe(Te.value[x.key]))-Number(Oe(Te.value[u.key]))),g=(f=ct.value)!=null&&f.available?ct.value.usage.filter(u=>u.state==="ok"&&u.windows.some(x=>!x.scope)):[];return n("aside",{class:`forge-sidebar flex flex-col${Se.value?" open":""}`,"aria-label":"Sidebar",style:{position:"sticky",top:0,height:"100vh",overflowY:"auto",overscrollBehavior:"contain",gap:"18px",padding:"14px 10px 12px",background:"var(--bg-2)",borderRight:"1px solid var(--hair)"},children:[n("div",{role:"button",tabIndex:0,class:"flex items-center cursor-pointer",style:{gap:"9px",padding:"2px 8px"},onClick:()=>l("list"),onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&l("list")},children:[n("span",{class:"grid place-items-center shrink-0",style:{width:"22px",height:"22px",borderRadius:"7px",background:"linear-gradient(160deg, var(--blue), var(--purple))",boxShadow:"var(--shadow-s)",fontSize:"12px",fontWeight:700,color:"#fff"},children:"F"}),n("span",{class:"sb-label",style:{fontSize:"15px",fontWeight:600,letterSpacing:"-0.015em"},children:"Forge"}),n("span",{class:"flex-1 sb-label"}),c&&n("span",{class:"mono sb-label",style:{fontSize:"10px",color:"var(--ink-3)"},title:"CW version",children:c})]}),h&&n("button",{type:"button",class:"flex items-center text-left cursor-pointer transition-all duration-180 ease-spring text-ink2 hover:text-ink hover:border-hair2 hover:-translate-y-px hover:shadow-m",style:{gap:"8px",padding:"6px 9px",borderRadius:"9px",border:"1px solid var(--hair)",background:"var(--card)",fontSize:"12.5px",boxShadow:"var(--shadow-s)"},onClick:h,"aria-label":"Search (⌘K)",children:[n("span",{class:"i-lucide-search shrink-0",style:{width:"13px",height:"13px",opacity:.7}}),n("span",{class:"flex-1 sb-label",children:"Search"}),n("kbd",{class:"sb-label",style:{fontSize:"10px",padding:"1px 5px",borderRadius:"5px",background:"var(--elev)",border:"1px solid var(--hair)"},children:"⌘K"})]}),n("nav",{class:"flex flex-col",style:{gap:"2px"},"aria-label":"Sections",children:m.map(u=>{const x=e===u.view;return n("button",{type:"button","aria-current":x?"page":void 0,title:u.label,class:da,style:{...pa(x),gap:"9px",height:"32px",padding:"0 9px",fontSize:"13.5px",fontWeight:x?600:450},onClick:()=>l(u.view),children:[n("span",{class:"grid place-items-center shrink-0",style:{width:"18px",height:"18px",borderRadius:"5px",fontSize:"10px",fontWeight:600,background:x?se(u.token):"var(--elev)",color:x?`var(${u.token})`:"var(--ink-3)"},children:u.glyph}),n("span",{class:"flex-1 sb-label",children:u.label}),u.count!==null&&n("span",{class:"mono sb-label",style:{fontSize:"11px",color:"var(--ink-3)"},children:u.count})]},u.view)})}),n(Gi,{projects:r,accounts:o,selected:i,onSelect:s,onAdd:p}),n("div",{class:"flex flex-col",style:{marginTop:"auto",flex:"none",gap:"8px"},children:[a.length>0&&n("div",{class:"flex flex-col sb-section",style:{gap:"8px"},children:[n("span",{style:{padding:"0 9px"},children:n(wr,{children:"Live now"})}),k.map((u,x)=>n(ua,{id:u.key,session:u.session,index:x,onOpen:()=>d(u.session)},u.key))]}),g.length>0&&n("div",{class:"flex flex-col sb-section",style:{gap:"8px"},children:[n("span",{style:{padding:"0 9px"},children:n(wr,{children:"Limits"})}),g.map(u=>n(fa,{account:u.account,harness:u.harness,windows:u.windows.filter(x=>!x.scope),stale:u.stale,onOpen:()=>l("accounts")},`${u.account}/${u.harness}`))]}),Jt&&n("div",{class:"sb-section",children:n(ha,{})}),n("div",{class:"sb-section",children:n(ve,{fill:!0,size:"xs",label:"Appearance",tabs:[{id:"light",label:"Light"},{id:"dark",label:"Dark"}],active:ut.value,onChange:u=>ao(u==="light"?"light":"dark")})})]})]})};function Gt(){const e=X(null);return F(()=>{var t;(t=e.current)==null||t.focus()},[]),e}const _r=(e,t,r)=>{const o=Un(e.type);return{id:K(e),label:ue(e)?`${he(e)} · ${ue(e)}`:he(e),hint:t,glyph:o.glyph,token:o.token,run:()=>r(e)}},xa=({openTabs:e,sessions:t,projects:r,commands:o,onOpenSession:i,onSelectProject:a,onClose:l})=>{const[s,p]=w(""),[d,h]=w(0),c=X(null),m=Gt(),k=Q(()=>{const v=s.trim().toLowerCase(),C=I=>!v||I.label.toLowerCase().includes(v),y=new Set(e.map(K)),R=e.map((I,S)=>_r(I,S<5?`⌘${S+1}`:"open",i)),A=t.filter(I=>I.status==="active"&&!y.has(K(I))).map(I=>_r(I,"resume",i)),L=v?r.map(I=>({id:`project:${I}`,label:I,hint:"project",glyph:"P",token:"--green",run:()=>a(I)})):[];return[{name:"Live now",items:R.filter(C)},{name:"Tasks",items:A.filter(C).slice(0,v?12:6)},{name:"Projects",items:L.filter(C).slice(0,6)},{name:"Commands",items:o.filter(C)}].filter(I=>I.items.length>0)},[s,e,t,r,o,i,a]),g=k.flatMap(v=>v.items),b=Math.min(d,g.length-1);F(()=>{var v,C;(C=(v=c.current)==null?void 0:v.querySelector('[data-active="true"]'))==null||C.scrollIntoView({block:"nearest"})},[b]);const f=v=>{v&&(l(),v.run())},u=X({flat:g,current:b,activate:f});u.current={flat:g,current:b,activate:f},F(()=>{const v=C=>{const{flat:y,current:R,activate:A}=u.current,L=y.length;C.key==="ArrowDown"?(C.preventDefault(),h(I=>L?(Math.min(I,L-1)+1)%L:0)):C.key==="ArrowUp"?(C.preventDefault(),h(I=>L?(Math.min(I,L-1)-1+L)%L:0)):C.key==="Enter"?(C.preventDefault(),A(y[R])):C.key==="Escape"&&(C.preventDefault(),l())};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[l]);let x=-1;return n("div",{class:"fixed inset-0 z-[60] flex justify-center items-start overflow-auto",style:{background:"rgba(0,0,0,.42)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",padding:"88px 16px 16px"},onClick:l,children:n("div",{role:"dialog","aria-modal":"true","aria-label":"Command palette",class:"flex flex-col overflow-hidden",style:{width:"min(560px, 100%)",maxHeight:"calc(100vh - 104px)",borderRadius:"18px",background:"var(--glass)",backdropFilter:"blur(30px) saturate(180%)",WebkitBackdropFilter:"blur(30px) saturate(180%)",border:"1px solid var(--hair-2)",boxShadow:"var(--shadow-l)",animation:"popIn .26s var(--ease) both"},onClick:v=>v.stopPropagation(),children:[n("input",{ref:m,role:"combobox","aria-expanded":"true","aria-controls":"palette-list","aria-activedescendant":g[b]?`palette-${g[b].id}`:void 0,"aria-label":"Search tasks, projects and commands",class:"shrink-0",style:{height:"48px",padding:"0 16px",border:0,borderBottom:"1px solid var(--hair)",background:"transparent",color:"var(--ink)",fontSize:"16px",outline:"none"},placeholder:"Task, project, skill or command…",value:s,onInput:v=>{p(v.target.value),h(0)}}),n("div",{id:"palette-list",role:"listbox",ref:c,class:"overflow-auto",style:{padding:"6px"},children:[g.length===0&&n("p",{style:{padding:"14px 10px",fontSize:"13px",color:"var(--ink-2)"},children:["Nothing matches “",s,"”."]}),k.map(v=>n("div",{role:"group","aria-label":v.name,children:[n("div",{style:{padding:"7px 10px 3px",fontSize:"11px",fontWeight:600,color:"var(--ink-3)"},children:v.name}),v.items.map(C=>{x+=1;const y=x,R=y===b;return n("button",{id:`palette-${C.id}`,type:"button",role:"option","aria-selected":R,"data-active":R,tabIndex:-1,class:"flex items-center w-full text-left cursor-pointer",style:{gap:"10px",padding:"8px 10px",borderRadius:"10px",border:0,background:R?"var(--elev)":"transparent",color:"var(--ink)",fontSize:"13px",transition:"background .14s"},onMouseMove:()=>{R||h(y)},onClick:()=>f(C),children:[n("span",{class:"grid place-items-center shrink-0",style:{width:"22px",height:"22px",borderRadius:"7px",fontSize:"10px",fontWeight:700,background:C.token?se(C.token):"var(--elev)",color:C.token?`var(${C.token})`:"var(--ink-2)"},children:C.glyph}),n("span",{class:"flex-1 min-w-0 truncate",children:C.label}),n("span",{class:"mono shrink-0",style:{fontSize:"10.5px",color:"var(--ink-3)"},children:C.hint})]},C.id)})]},v.name))]}),n("div",{class:"flex shrink-0",style:{gap:"14px",padding:"8px 14px",borderTop:"1px solid var(--hair)"},children:["↑↓ move","↵ open","esc close"].map(v=>n("span",{class:"mono",style:{fontSize:"10.5px",color:"var(--ink-3)"},children:v},v))})]})})},$n=te(null);let cn=null;function Po(){return cn||(cn=fetch("/api/cw/editors").then(e=>e.json()).then(e=>{$n.value=e}).catch(()=>{$n.value={enabled:!1,editors:[]}})),cn}async function ga(e,t){const r=await fetch("/api/cw/open-in-editor",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:e.project,sessionDir:qt(e),editor:t})}),o=await r.json().catch(()=>({ok:!1,error:`HTTP ${r.status}`}));if(!r.ok||!o.ok)throw new Error(o.error??"Could not open the editor")}const dt=e=>e.unpushed??e.commits??0,Lo={OPEN:"open",MERGED:"merged",CLOSED:"closed"},ma={passing:"✓",failing:"✗",pending:"…",none:""};function ya(e){if(e.workspace==="missing")return"Workspace not created yet";if(e.closeWarnings.includes("state-unknown")&&e.branch===null)return"Changes unknown";const t=[];e.diff&&e.diff.files>0&&t.push(`+${e.diff.insertions} −${e.diff.deletions} · ${e.diff.files} file${e.diff.files===1?"":"s"}`),e.uncommitted>0&&t.push(`${e.uncommitted} uncommitted`);const r=dt(e);if(r>0&&t.push(`${r} unpushed`),e.pr.status==="found"){const o=e.pr.state==="OPEN"&&e.pr.isDraft?"draft":Lo[e.pr.state];t.push(`PR #${e.pr.number} ${o}`),e.pr.checks!=="none"&&t.push(`checks ${ma[e.pr.checks]}`),e.pr.review==="APPROVED"&&t.push("approved"),e.pr.review==="CHANGES_REQUESTED"&&t.push("changes requested")}return t.length>0?t.join(" · "):e.workspace==="ready"?"No changes yet":""}const ba={passing:"checks pass",failing:"checks failing",pending:"checks running",none:""},Sr=(e,t)=>`${e} ${t}${e===1?"":"s"}`;function ka(e){if(e.workspace==="missing")return"not created yet";if(e.pr.status==="found"){const o=e.pr.state==="OPEN"&&e.pr.isDraft?"draft":Lo[e.pr.state];return[`PR #${e.pr.number} ${o}`,ba[e.pr.checks]].filter(Boolean).join(" · ")}const t=[];e.diff&&e.diff.files>0&&t.push(Sr(e.diff.files,"file")),e.commits&&t.push(Sr(e.commits,"commit"));const r=dt(e);return r>0&&e.commits&&t.push(`${r} unpushed`),e.uncommitted>0&&t.push(`${e.uncommitted} uncommitted`),t.length>0?t.join(" · "):"no changes yet"}async function Xe(e,t){const r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),o=await r.json().catch(()=>({}));if(!r.ok||o.error)throw new Error(o.error??`Request failed (${r.status})`);return o}const Rt=e=>e instanceof Error?e.message:String(e);function Gn(e,t){navigator.clipboard.writeText(e).then(()=>P(`${t} copied`,"info"),()=>P(`Could not copy the ${t.toLowerCase()}`,"error"))}const wa=({session:e,muted:t})=>{const r=fe(e.harness);return n("span",{class:`harness-pill inline-flex items-center shrink-0 whitespace-nowrap${t?" opacity-60":""}`,style:{gap:"6px",padding:"3px 9px",borderRadius:"99px",background:r.bg,color:r.color,fontSize:"11.5px",fontWeight:600},children:[n("span",{style:{width:"6px",height:"6px",borderRadius:"50%",background:r.color}}),co(e)]})},Tn=te({}),Ao=te(0),_a=6e4,mt=new Map,Eo=e=>`${e.project}::${qt(e)}`;function Rn(e,t=!1){const r=Eo(e),o=mt.get(r);if(o&&!t)return o;const i=`/api/cw/review-state/${encodeURIComponent(e.project)}/${encodeURIComponent(qt(e))}${t?"?fresh=1":""}`,a=fetch(i).then(async l=>l.ok?{state:await l.json(),error:null}:{state:null,error:`Forge could not read this task (HTTP ${l.status})`}).catch(()=>({state:null,error:"Could not reach the Forge server"})).then(l=>(Tn.value={...Tn.value,[r]:l},mt.get(r)===a&&mt.delete(r),l));return mt.set(r,a),a}function Sa(){Ao.value++}function Io(e,{poll:t=!1}={}){const r=Eo(e),o=Ao.value;return F(()=>{if(Rn(e),!t)return;const i=setInterval(()=>{Rn(e,!0)},_a);return()=>clearInterval(i)},[r,t,o]),Tn.value[r]??null}const zn=({type:e,size:t=28,radius:r=9,font:o=11})=>{const i=Un(e);return n("span",{class:"grid place-items-center shrink-0",title:i.label,style:{width:`${t}px`,height:`${t}px`,borderRadius:`${r}px`,background:i.fill,color:i.ink,fontSize:`${o}px`,fontWeight:700},children:i.glyph})},Ca=()=>n("span",{class:"inline-flex items-center shrink-0",style:{gap:"5px",padding:"1px 8px",borderRadius:"99px",background:se("--green"),color:"var(--green)",fontSize:"11px",fontWeight:600},children:[n($e,{size:5,color:"var(--green)",live:!0,glow:!1}),"live"]}),No=({label:e,href:t})=>{const r={padding:"1px 7px",borderRadius:"99px",background:"var(--elev)",border:"1px solid var(--hair)",color:"var(--ink-2)",fontSize:"11px"};return t?n("a",{class:"inline-flex items-center gap-1 shrink-0 hover:text-ink",style:r,href:t,target:"_blank",rel:"noopener noreferrer",title:t,onClick:o=>o.stopPropagation(),onKeyDown:o=>o.stopPropagation(),children:[e," ",n("span",{class:"i-lucide-external-link",style:{width:"10px",height:"10px"}})]}):n("span",{class:"shrink-0",style:r,children:e})},Oo=({session:e})=>{const t=qn(e);return t&&n(No,{label:t.label,href:t.url})},$a=({session:e})=>qn(e)?n(Oo,{session:e}):e.source?n("span",{class:"task-chip contents",children:n(No,{label:e.source,href:e.source_url})}):null,Wo=e=>e.type==="review"?`review/pr-${e.pr}`:e.type==="loop"?`loop/${e.task??"loop"}`:e.type==="task"?`task/${e.task}`:null,Ta=({session:e,project:t})=>{var a;const r=Io(e),o=((a=r==null?void 0:r.state)==null?void 0:a.branch)??Wo(e),i=r?r.error!==null?"changes unknown":ka(r.state):"checking…";return n(Do,{branch:o,status:i,project:t})},Do=({branch:e,status:t,project:r})=>n("div",{class:"task-meta flex items-center min-w-0",style:{gap:"9px",marginTop:"2px"},children:[r&&n("span",{class:"shrink-0",style:{fontSize:"12px",fontWeight:600,color:"var(--ink-2)"},children:r}),e===null?n("span",{class:"mono",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:"—"}):n("button",{type:"button",class:"mono truncate min-w-0 cursor-copy hover:text-ink transition-colors duration-160",style:{fontSize:"11.5px",color:"var(--ink-3)",padding:0,border:0,background:"transparent"},title:"Copy branch name",onClick:o=>{o.stopPropagation(),Gn(e,"Branch")},onKeyDown:o=>o.stopPropagation(),children:e}),n("span",{class:"whitespace-nowrap truncate",style:{fontSize:"12px",color:"var(--ink-2)"},children:t})]}),Ra=e=>e.type==="loop"?e.loop_interval?`every ${e.loop_interval}`:"self-paced":`${e.opens} session${e.opens===1?"":"s"}`,Fo=({session:e,isOpenInTab:t,onSelect:r,onMarkDone:o,showProject:i})=>{const a=i?ue(e)||"no project":void 0,[l,s]=w(!1),p=e.type==="task"||e.type==="review",d=async()=>{if(!(!o||l)){s(!0);try{await o()}finally{s(!1)}}};return n("div",{class:"task-row group flex items-center cursor-pointer transition-colors duration-160 hover:bg-elev",style:{gap:"13px",padding:"11px 15px",borderBottom:"1px solid var(--hair)"},onClick:r,role:"button",tabIndex:0,"aria-label":`${t?"Open":"Resume"} ${he(e)}`,onKeyDown:h=>{h.target===h.currentTarget&&(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),r())},children:[n(zn,{type:e.type}),n("div",{class:"flex-1 min-w-0",children:[n("div",{class:"flex items-center min-w-0",style:{gap:"8px"},children:[n("span",{class:"truncate",style:{fontSize:"14px",fontWeight:600},children:he(e)}),t&&e.status==="active"&&n(Ca,{}),n($a,{session:e})]}),p?n(Ta,{session:e,project:a}):n(Do,{branch:Wo(e),status:Ra(e),project:a})]}),n(wa,{session:e}),n("span",{class:"mono shrink-0 text-right",style:{width:"52px",fontSize:"11.5px",color:"var(--ink-3)"},title:new Date(e.last_opened).toLocaleString(),children:lo(e.last_opened)}),o&&n("button",{type:"button",class:`task-done grid place-items-center shrink-0 cursor-pointer transition-all duration-180 ease-spring hover:text-green disabled:cursor-wait ${l?"":"opacity-0 group-hover:opacity-100 focus-visible:opacity-100"}`,style:{width:"28px",height:"28px",borderRadius:"9px",border:"1px solid var(--hair)",background:"var(--card)",color:"var(--ink-2)"},onClick:h=>{h.stopPropagation(),d()},disabled:l,title:l?"Closing…":"Mark done","aria-label":"Mark done",children:n("span",{class:l?"i-lucide-loader-2 animate-spin":"i-lucide-check",style:{width:"14px",height:"14px"}})}),n("span",{class:"shrink-0 whitespace-nowrap",style:t?{padding:"5px 11px",borderRadius:"9px",background:"linear-gradient(180deg, var(--blue-2), var(--blue))",color:"#fff",fontSize:"12.5px",fontWeight:600,boxShadow:"var(--shadow-m)"}:{padding:"5px 11px",borderRadius:"9px",background:"var(--elev)",color:"var(--ink)",fontSize:"12.5px",fontWeight:600},children:t?"Open":"Resume"})]})},za=({session:e,onSelect:t})=>n("div",{class:"flex items-center cursor-pointer transition-colors duration-160 hover:bg-elev",style:{gap:"12px",padding:"9px 15px",borderBottom:"1px solid var(--hair)",color:"var(--ink-2)"},onClick:t,role:"button",tabIndex:0,onKeyDown:r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),t())},children:[n("span",{class:"grid place-items-center shrink-0",style:{width:"22px",height:"22px",borderRadius:"7px",background:"var(--elev)"},children:n("span",{class:"i-lucide-check",style:{width:"12px",height:"12px"}})}),n("span",{class:"flex-1 min-w-0 truncate",style:{fontSize:"13px"},children:[he(e)," ",n("span",{class:"mono",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:ue(e)})]}),n(Oo,{session:e}),n("span",{class:"mono shrink-0",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:lo(e.closed??e.last_opened)})]}),ja=({project:e,account:t,accounts:r,onDeleted:o,onMoved:i})=>{const[a,l]=w(null),[s,p]=w(null),[d,h]=w(!1),[c,m]=w(!1),[k,g]=w(""),[b,f]=w(!1),u=(r??[]).filter(_=>_!==t);F(()=>{let _=!1;return fetch(`/api/cw/mcps?project=${encodeURIComponent(e)}`).then(N=>N.json()).catch(()=>null).then(N=>{_||l(N)}),()=>{_=!0}},[e]);const x=a?Object.keys(a.global):[],v=(a==null?void 0:a.project)??[],C=(a==null?void 0:a.cw)??[],y=(a==null?void 0:a.plugins)??[],R=[...v.map(_=>`${_} (project)`),...x,...C.map(_=>`${_} (CW)`)],A=_=>{p(s===_?null:_),g(""),h(!1)},L=async()=>{m(!0);try{(await(await fetch("/api/cw/delete-project",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:e,deleteFiles:d})})).json()).ok&&(P(`Project "${e}" deleted${d?" (files removed)":""}`,"info"),o==null||o())}catch{P("Failed to delete project","error")}finally{m(!1),p(null)}},I=async()=>{if(k){f(!0);try{const N=await(await fetch("/api/cw/move-project",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:e,toAccount:k})})).json();N.ok?(P(`Project "${e}" moved to "${k}"`,"success"),p(null),g(""),i==null||i()):P(N.error??"Failed to move project","error")}catch{P("Failed to move project","error")}finally{f(!1)}}};if(!a)return null;const S={padding:"12px 15px",borderTop:"1px solid var(--hair)",display:"flex",flexDirection:"column",gap:"10px"},z=(_,N)=>({padding:"5px 11px",borderRadius:"9px",border:"1px solid var(--hair)",fontSize:"12.5px",fontWeight:500,background:N?"var(--elev)":"var(--card)",color:_==="red"?"var(--red)":"var(--ink)",boxShadow:"var(--shadow-s)"});return n("section",{style:{borderRadius:"16px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",overflow:"hidden"},"aria-label":"Project settings",children:[n("div",{class:"flex items-center flex-wrap",style:{padding:"10px 15px",gap:"8px 12px"},children:[n("div",{class:"flex-1 min-w-0 flex flex-col",style:{gap:"2px",fontSize:"12.5px",color:"var(--ink-2)"},children:[R.length>0&&n("span",{class:"truncate",title:R.join(", "),children:["MCP · ",R.join(", ")]}),y.length>0&&n("span",{class:"truncate",title:y.join(", "),children:["Plugins · ",y.join(", ")]}),R.length===0&&y.length===0&&n("span",{children:"No MCPs or plugins for this project"})]}),u.length>0&&n("button",{type:"button",class:"cursor-pointer",style:z("ink",s==="move"),"aria-expanded":s==="move",onClick:()=>A("move"),children:"Move to account"}),n("button",{type:"button",class:"cursor-pointer",style:z("red",s==="delete"),"aria-expanded":s==="delete",onClick:()=>A("delete"),children:"Delete project"})]}),s==="move"&&n("div",{style:S,children:[n("p",{style:{fontSize:"13px"},children:['Move "',e,'" to a different account.']}),n("select",{class:"field",value:k,onChange:_=>g(_.target.value),children:[n("option",{value:"",children:"Select account…"}),u.map(_=>n("option",{value:_,children:_},_))]}),n("div",{class:"flex",style:{gap:"8px"},children:[n(D,{label:b?"Moving…":"Move project",variant:"primary",size:"sm",loading:b,disabled:!k,onClick:I}),n(D,{label:"Cancel",variant:"secondary",size:"sm",onClick:()=>{p(null),g("")}})]})]}),s==="delete"&&n("div",{style:S,children:[n("p",{style:{fontSize:"13px"},children:['This unregisters "',e,'" from CW.']}),n("label",{class:"flex items-center cursor-pointer",style:{gap:"8px",fontSize:"12.5px",color:"var(--ink-2)"},children:[n("input",{type:"checkbox",checked:d,onChange:_=>h(_.target.checked)}),"Also delete project files from disk"]}),d&&n("p",{style:{fontSize:"12.5px",color:"var(--red)"},children:"This permanently deletes all files. It cannot be undone."}),n("div",{class:"flex",style:{gap:"8px"},children:[n(D,{label:c?"Deleting…":d?"Delete project and files":"Unregister project",variant:"destructive",size:"sm",loading:c,onClick:L}),n(D,{label:"Cancel",variant:"secondary",size:"sm",onClick:()=>{p(null),h(!1)}})]})]})]})},Mo=e=>e.trim().replace(/\s+/g,"-").toLowerCase();function Vt(e){const t=e.trim();return t?/github\.com\/.+\/pull\/\d+/.test(t)||/^#?\d{1,6}$/.test(t)?{kind:"pr",type:"review"}:/linear\.app/.test(t)?{kind:"linear",type:"dev"}:/notion\.(so|site)/.test(t)?{kind:"notion",type:"dev"}:{kind:"name",type:"dev",slug:Mo(t)}:null}const Pa="A PR link becomes a review. A Linear or Notion link becomes a dev task with its notes.";function La(e,t){const r=Vt(e),o=t.project?` on ${t.project}`:"";if(t.type==="general")return{text:`General session as ${t.account||"an account"}${t.project?` in ${t.project}`:", outside any project"}, run by ${t.harness}.`,ready:!!t.account};if(!t.project)return{text:"Pick a project to start.",ready:!1};if(!r)return{text:Pa,ready:!1};if(t.type==="loop")return{text:`Loop${o} — pick its interval in the next step.`,ready:!0};if(t.type==="review")return{text:r.kind==="pr"?`Pull request detected — this becomes a review${o}, run by ${t.harness}.`:`Review of “${e.trim()}”${o}, run by ${t.harness}.`,ready:!0};switch(r.kind){case"linear":return{text:"Linear ticket detected — a dev task, and the ticket lands in TASK_NOTES.md first.",ready:!0};case"notion":return{text:"Notion page detected — a dev task, and the page lands in TASK_NOTES.md first.",ready:!0};case"pr":return{text:`Dev task${o} from pull request ${e.trim()}, run by ${t.harness}.`,ready:!0};case"name":return{text:`Dev task${o} · branch task/${r.slug}`,ready:!0}}}const Vn=(e,t)=>{var r;return t??((r=Vt(e))==null?void 0:r.type)??"dev"},me=te(""),De=te(null),Ie=te(""),Ft=te(""),Mt=e=>{me.value=e,De.value=null},Yn=(e,t,r)=>r&&e!=="claude"?"Loop uses Claude Code's /loop":(t==null?void 0:t.status)==="not_installed"?typeof t.detail=="string"&&t.detail?t.detail:"Not installed":null,Aa=(e,t,r,o,i)=>{var s;if(i)return i;if((r==null?void 0:r.status)==="not_logged_in")return"Not logged in";if((r==null?void 0:r.status)==="error"&&typeof r.detail=="string")return r.detail;const a=(s=e.harnesses.find(p=>p.name===t))==null?void 0:s.version,l=r==null?void 0:r.model;return[o?"Default":a,l].filter(Boolean).join(" · ")||(o?"Default":"")},Ea=({doctor:e,account:t,value:r,defaultHarness:o,isLoop:i,onChange:a,onOpenAccounts:l})=>n("div",{class:"flex flex-col",style:{gap:"6px"},role:"radiogroup","aria-label":"Harness",children:[n("span",{style:{fontSize:"12px",color:"var(--ink-2)"},children:"Harness · this task only"}),n("div",{class:"grid",style:{gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:"8px"},children:e.harnesses.map(s=>{const p=Ce(e,t,s.name),d=Yn(s.name,p,i),h=fe(s.name),c=r===s.name,m=(p==null?void 0:p.status)==="not_logged_in",k=Aa(e,s.name,p,s.name===o,d);return n("div",{role:"radio","aria-checked":c,tabIndex:d?-1:0,"aria-disabled":!!d,title:d??void 0,class:`flex items-start transition-all duration-180 ease-spring ${d?"cursor-not-allowed":"cursor-pointer hover:bg-elev"}`,style:{gap:"9px",padding:"10px 11px",borderRadius:"12px",border:`1px solid ${c?"var(--blue)":"var(--hair)"}`,background:c?se("--blue"):"var(--card)",boxShadow:c?"var(--shadow-s)":"none",opacity:d?.45:1},onClick:()=>{d||a(s.name)},onKeyDown:g=>{!d&&(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),a(s.name))},children:[n("span",{class:"shrink-0",style:{width:"8px",height:"8px",borderRadius:"50%",marginTop:"5px",background:h.color,boxShadow:c?`0 0 8px ${h.color}`:"none"}}),n("span",{class:"flex flex-col min-w-0",children:[n("span",{style:{fontSize:"12.5px",fontWeight:600},children:h.label}),n("span",{class:"truncate",style:{fontSize:"11.5px",color:"var(--ink-2)"},title:k,children:k}),m&&l&&n("button",{type:"button",class:"self-start cursor-pointer",style:{border:0,background:"none",padding:0,color:"var(--blue)",fontSize:"11.5px",fontWeight:600},onClick:g=>{g.stopPropagation(),l()},onKeyDown:g=>g.stopPropagation(),children:"Connect"})]})]},s.name)})})]}),Ia=({options:e,value:t,label:r,onPick:o,onClose:i})=>{const[a,l]=w(""),[s,p]=w(0),d=Gt(),h=X(null),c=a.trim().toLowerCase(),m=Q(()=>e.filter(b=>{var f;return!c||b.label.toLowerCase().includes(c)||((f=b.group)==null?void 0:f.toLowerCase().includes(c))}),[e,c]);F(()=>{const b=m.findIndex(f=>f.value===t);p(b>=0&&!c?b:0)},[c]),F(()=>{var b,f;(f=(b=h.current)==null?void 0:b.querySelector('[data-active="true"]'))==null||f.scrollIntoView({block:"nearest"})},[s]);const k=b=>{if(b.key==="ArrowDown")b.preventDefault(),p(f=>Math.min(f+1,m.length-1));else if(b.key==="ArrowUp")b.preventDefault(),p(f=>Math.max(f-1,0));else if(b.key==="Enter"){b.preventDefault();const f=m[s];f&&o(f.value)}else b.key==="Escape"&&(b.preventDefault(),b.stopPropagation(),i())};let g;return n("div",{class:"popover absolute right-0 top-full z-40 flex flex-col",style:{marginTop:"6px",width:"260px",maxHeight:"320px",padding:"6px",borderRadius:"12px",background:"var(--card-2)",backdropFilter:"none",WebkitBackdropFilter:"none"},onKeyDown:k,children:[n("label",{class:"relative block shrink-0",children:[n("span",{class:"i-lucide-search absolute pointer-events-none",style:{left:"9px",top:"9px",width:"12px",height:"12px",color:"var(--ink-3)"}}),n("input",{ref:d,type:"search",class:"field",role:"combobox","aria-expanded":"true","aria-label":`Search ${r.toLowerCase()}`,placeholder:`Search ${r.toLowerCase()}s`,value:a,style:{height:"30px",padding:"0 8px 0 27px",borderRadius:"8px",fontSize:"12.5px",background:"var(--elev)"},onInput:b=>l(b.target.value)})]}),n("div",{ref:h,role:"listbox","aria-label":r,class:"overflow-y-auto min-h-0",style:{marginTop:"6px"},children:[m.length===0&&n("p",{style:{padding:"8px 10px",fontSize:"12.5px",color:"var(--ink-3)"},children:["No match for “",a.trim(),"”."]}),m.map((b,f)=>{const u=b.group&&b.group!==g?b.group:null;g=b.group;const x=f===s,v=b.value===t;return n("div",{children:[u&&n("div",{style:{padding:"7px 9px 3px",fontSize:"11px",fontWeight:600,color:"var(--ink-3)"},children:u}),n("button",{type:"button",role:"option","aria-selected":v,"data-active":x,tabIndex:-1,class:"flex items-center w-full text-left cursor-pointer",style:{gap:"8px",padding:"6px 9px",borderRadius:"8px",border:0,background:x?"var(--elev)":"transparent",color:"var(--ink)",fontSize:"13px"},onMouseMove:()=>{x||p(f)},onClick:()=>o(b.value),children:[n("span",{class:"flex-1 truncate",style:{fontWeight:v?600:400,color:b.value?"var(--ink)":"var(--ink-2)"},children:b.label}),v&&n("span",{class:"i-lucide-check shrink-0",style:{width:"13px",height:"13px",color:"var(--blue)"}})]})]},b.value||"__empty")})]})]})},Bo=({label:e,value:t,options:r,onChange:o,placeholder:i="Choose…",size:a="sm",width:l})=>{const[s,p]=w(!1),d=X(null),h=r.find(m=>m.value===t);return F(()=>{if(!s)return;const m=k=>{d.current&&!d.current.contains(k.target)&&p(!1)};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[s]),n("div",{ref:d,class:"relative",style:{width:l},children:[n("button",{type:"button","aria-haspopup":"listbox","aria-expanded":s,"aria-label":e,class:"field flex items-center text-left cursor-pointer",style:a==="sm"?{width:l??"auto",minWidth:"130px",maxWidth:"200px",height:"30px",padding:"0 9px 0 10px",borderRadius:"9px",fontSize:"12.5px",background:"var(--bg-2)",gap:"6px"}:{gap:"6px",boxShadow:"var(--shadow-s)"},onClick:()=>p(m=>!m),onKeyDown:m=>{m.key==="ArrowDown"&&(m.preventDefault(),p(!0))},children:[n("span",{class:"flex-1 truncate",style:{color:h&&h.value?"var(--ink)":"var(--ink-2)"},children:(h==null?void 0:h.label)??i}),n("span",{class:"i-lucide-chevrons-up-down shrink-0",style:{width:"12px",height:"12px",color:"var(--ink-3)"}})]}),s&&n(Ia,{options:r,value:t,label:e,onPick:m=>{o(m),p(!1)},onClose:()=>p(!1)})]})},jn=(e,t,r=Object.keys(e))=>{const o=i=>{const a=t.indexOf(i);return a<0?t.length:a};return[...r].sort((i,a)=>o(e[i].account)-o(e[a].account)||i.localeCompare(a)).map(i=>({value:i,label:i,group:e[i].account}))},Uo=({ctx:e,size:t="md"})=>{const{text:r,ready:o}=La(me.value,{...e,harness:fe(e.harness).label}),i=o&&(e.type==="general"||Vt(me.value)!==null);return n("p",{class:"flex items-center min-w-0","aria-live":"polite",style:{gap:"7px",fontSize:t==="md"?"12.5px":"12px",color:i?"var(--blue)":"var(--ink-3)"},children:[i&&n("span",{class:"grid place-items-center shrink-0",style:{width:"16px",height:"16px",borderRadius:"50%",background:se("--blue",22)},children:n("span",{class:"i-lucide-check",style:{width:"10px",height:"10px"}})}),n("span",{class:"min-w-0",style:{overflowWrap:"anywhere"},children:r})]})},Ho=({fill:e})=>n(ve,{fill:e,label:"Task type",tabs:He.map(t=>({id:t.key,label:Hn(t.key)})),active:Vn(me.value,De.value),onChange:t=>{De.value=t}}),Na={width:"auto",maxWidth:"180px",height:"30px",padding:"0 26px 0 10px",borderRadius:"9px",fontSize:"12.5px",background:"var(--bg-2)"},Oa=({label:e,value:t,onChange:r,options:o})=>n("label",{class:"inline-flex items-center shrink-0",style:{gap:"6px",fontSize:"12px",color:"var(--ink-3)"},children:[e,n("select",{class:"field","aria-label":e,style:Na,value:t,onChange:i=>r(i.target.value),children:o.map(i=>n("option",{value:i.value,children:i.label},i.value))})]}),Wa=({projects:e,accounts:t,onStarted:r,onOpenDrawer:o})=>{var v,C;const[i,a]=w(!1),l=We.value,s=l!=null&&l.available?l.doctor:null,p=Vn(me.value,De.value),d=p==="general",h=Ie.value,c=Object.keys(e).sort(),m=d?Ft.value||((v=e[h])==null?void 0:v.account)||t[0]||"":((C=e[h])==null?void 0:C.account)??"",k=c.filter(y=>e[y].account===m),g=p==="loop"?"claude":s?po(h||void 0,m,e,s):"claude",b=me.value.trim(),f=i||(d?!m:!b||!h),u=async()=>{if(f)return;const y=s?Ce(s,m,g):void 0,R=s?Yn(g,y,p==="loop"):null,A=!d&&xo(l,g,b);if(p==="loop"||R||A||(y==null?void 0:y.status)==="not_logged_in"){o();return}a(!0);try{const S=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(d?{type:p,account:m,project:h||void 0,harness:s?g:void 0}:{type:p,project:h,task:b,account:m||void 0,harness:s?g:void 0})})).json();S.ok?(P(d?"Session started":p==="review"?"Review started":"Task started","success"),d||Mt(""),r(S.session)):P(S.error??"Failed to start","error")}catch{P("Failed to start","error")}finally{a(!1)}},x=y=>{var R;Ft.value=y,h&&((R=e[h])==null?void 0:R.account)!==y&&(Ie.value="")};return n("section",{style:{position:"relative",zIndex:5,padding:"14px",borderRadius:"16px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-m)",animation:"riseIn .34s var(--ease) both"},"aria-label":"Start a task",children:[n("div",{class:"flex items-center flex-wrap",style:{gap:"9px"},children:[n("input",{class:"field min-w-0",style:{flex:"1 1 300px",height:"40px",padding:"0 13px",borderRadius:"11px",background:"var(--bg-2)",fontSize:"14.5px"},placeholder:d?"A general session needs no name — pick the account below":"Paste a Linear ticket, a PR link, or type a task name","aria-label":"Task name, ticket or pull request",value:me.value,onInput:y=>Mt(y.target.value),onKeyDown:y=>{y.key==="Enter"&&u()}}),n(Ho,{}),n("button",{type:"button",disabled:f,class:f?"":"cursor-pointer transition-all duration-180 ease-spring hover:-translate-y-px hover:brightness-106",style:{height:"40px",padding:"0 18px",borderRadius:"11px",border:0,fontSize:"13.5px",fontWeight:600,background:f&&!i?"var(--elev)":"linear-gradient(180deg, var(--blue-2), var(--blue))",color:f&&!i?"var(--ink-3)":"#fff",boxShadow:f&&!i?"none":"var(--shadow-m)",opacity:f&&!i?.8:1,cursor:f?"not-allowed":"pointer"},onClick:()=>void u(),children:i?"Starting…":d?"Launch":"Start"})]}),n("div",{class:"flex items-center flex-wrap",style:{gap:"8px 14px",marginTop:"10px",padding:"0 2px"},children:[n("div",{class:"flex-1 min-w-0",style:{flexBasis:"280px"},children:n(Uo,{ctx:{type:p,project:h,account:m,harness:g}})}),d&&n(Oa,{label:"Account",value:m,onChange:x,options:t.map(y=>({value:y,label:y}))}),n("div",{class:"inline-flex items-center shrink-0",style:{gap:"6px",fontSize:"12px",color:"var(--ink-3)"},children:[n("span",{"aria-hidden":"true",children:"Project"}),n(Bo,{label:"Project",value:h,onChange:y=>{Ie.value=y},placeholder:d?"No project":"Choose…",options:d?[{value:"",label:"No project"},...jn(e,t,k)]:jn(e,t,c)})]})]})]})},Qn=({title:e,subtitle:t,leading:r,children:o,sticky:i=!0,size:a="lg"})=>n("header",{class:`glass flex items-center flex-wrap shrink-0 ${i?"sticky top-0 z-20":""}`,style:{gap:"12px 14px",padding:"12px 22px",borderBottom:"1px solid var(--hair)"},children:[n(Zn,{}),r,n("div",{class:"min-w-0",children:[n("h1",{class:"truncate",style:{fontSize:a==="lg"?"20px":"18px",fontWeight:700,letterSpacing:"-0.02em"},children:e}),t&&n("p",{class:"truncate",style:{marginTop:"1px",fontSize:"12.5px",color:"var(--ink-2)"},children:t})]}),n("span",{style:{flex:"1 1 40px"}}),o&&n("div",{class:"flex items-center flex-wrap",style:{gap:"7px"},children:o})]}),Da=({label:e="Tasks",onClick:t})=>n("button",{type:"button",class:"inline-flex items-center gap-1 shrink-0 whitespace-nowrap cursor-pointer transition-all duration-180 ease-spring text-ink2 hover:text-ink",style:{padding:"5px 10px",borderRadius:"8px",border:"1px solid var(--hair)",background:"var(--card)",fontSize:"12.5px"},onClick:t,children:[n("span",{"aria-hidden":"true",children:"←"})," ",e]}),Zn=()=>n("button",{type:"button",class:"sb-toggle place-items-center shrink-0 cursor-pointer text-ink2 hover:text-ink",style:{width:"30px",height:"30px",borderRadius:"9px",border:"1px solid var(--hair)",background:"var(--card)",boxShadow:"var(--shadow-s)"},"aria-label":"Open sidebar",onClick:()=>{Se.value=!0},children:n("span",{class:"i-lucide-menu",style:{width:"15px",height:"15px"}})}),Pn=te({}),Cr=new Set;function Fa(e){!e||Cr.has(e)||(Cr.add(e),fetch(`/api/cw/detect/${encodeURIComponent(e)}`).then(t=>t.ok?t.json():null).catch(()=>null).then(t=>{Pn.value={...Pn.value,[e]:t}}))}const Ko=e=>{if(!e)return[];const t=[];return e.framework&&t.push(e.framework),e.testRunner&&t.push(e.testRunner),e.hasTailwind&&t.push("Tailwind"),e.hasShadcn&&t.push("shadcn"),e.hasPlaywright&&t.push("Playwright"),e.hasDockerfile&&t.push("Docker"),t};function qo(e){return F(()=>{Fa(e)},[e]),Pn.value[e]}const $r=10,Jo="forge-task-layout",Ma=()=>{try{return localStorage.getItem(Jo)==="project"?"project":"recent"}catch{return"recent"}},zt={borderRadius:"16px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-m)",overflow:"hidden"},jt={padding:"11px 15px",borderBottom:"1px solid var(--hair)",background:"var(--elev)"},Ba=({project:e,account:t,sessions:r,index:o,openTabKeys:i,onSelectTask:a,onMarkDone:l})=>{const s=Ko(qo(e)),p=r.some(d=>i.has(K(d)));return n("section",{style:{...zt,animation:`riseIn .4s var(--ease) ${o*70}ms both`},"aria-label":e||"No project",children:[n("div",{class:"flex items-center flex-wrap",style:{...jt,gap:"10px"},children:[n($e,{size:9,live:p}),n("span",{style:{fontSize:"14px",fontWeight:650,letterSpacing:"-0.01em"},children:e||"No project"}),n("span",{class:"truncate",style:{fontSize:"12.5px",color:"var(--ink-2)"},children:[t,s.join(" · ")].filter(Boolean).join(" · ")}),n("span",{class:"flex-1"}),n("span",{class:"mono",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:[r.length," task",r.length===1?"":"s"]})]}),r.map(d=>n(Fo,{session:d,isOpenInTab:i.has(K(d)),onSelect:()=>a(d),onMarkDone:d.type==="login"?void 0:()=>l(d)},K(d)))]})},Ua=({spaces:e,allSpaces:t,projects:r,accountNames:o,filterAccount:i,filterProject:a,onFilterProject:l,filterType:s,onFilterType:p,harnessNames:d,filterHarness:h,onFilterHarness:c,showDone:m,onShowDone:k,openTabKeys:g,onSelectTask:b,onMarkDone:f,onNewTask:u,onCreateProject:x,onRefresh:v,onStarted:C})=>{var H,M;const[y,R]=w(Ma),A=j=>{R(j);try{localStorage.setItem(Jo,j)}catch{}},L=Q(()=>e.filter(j=>j.status==="active"),[e]),I=Q(()=>e.filter(j=>j.status==="done"),[e]),S=Q(()=>t.filter(j=>j.status==="active").length,[t]),z=Q(()=>t.filter(j=>j.status==="done").length,[t]),_=Q(()=>t.filter(j=>j.status==="active"&&g.has(K(j))).length,[t,g]),N=Q(()=>t.filter(j=>j.status==="active"&&(!i||j.account===i)&&(!a||j.project===a)&&(!h||(j.harness??"claude")===h)),[t,i,a,h]),O=Q(()=>{const j=new Map;for(const G of L){const V=ue(G),de=j.get(V)??[];de.push(G),j.set(V,de)}return Array.from(j,([G,V])=>({project:G,sessions:V}))},[L]),E=a?((H=r[a])==null?void 0:H.account)??((M=L[0])==null?void 0:M.account):void 0,B=a?`${E?`${E} · `:""}${N.length} active`:`${S} active · ${z} done · ${_} agent${_===1?"":"s"} working`;return n(Z,{children:[n(Qn,{title:a??"Tasks",subtitle:B,children:[n(D,{label:"Add project",variant:"secondary",onClick:x}),n(D,{label:"New task",variant:"primary",onClick:u})]}),n("div",{class:"flex flex-col w-full",style:{padding:"18px 22px 40px",gap:"16px",maxWidth:"1180px"},children:[n(Wa,{projects:r,accounts:o,onStarted:C,onOpenDrawer:u}),n("div",{class:"flex items-center flex-wrap",style:{gap:"12px"},children:[n(ve,{label:"Filter by type",tabs:[{id:"all",label:"All",count:N.length},...He.map(j=>({id:j.key,label:Hn(j.key),count:N.filter(G=>G.type===j.sessionType).length}))],active:s??"all",onChange:j=>p(j==="all"?null:j)}),d.length>1&&n(ve,{label:"Filter by harness",tabs:[{id:"all",label:"Any harness"},...d.map(j=>({id:j,label:fe(j).label}))],active:h??"all",onChange:j=>c(j==="all"?null:j)}),n("span",{class:"flex-1"}),!a&&n(ve,{size:"sm",label:"Order tasks",tabs:[{id:"recent",label:"Recent"},{id:"project",label:"By project"}],active:y,onChange:j=>A(j==="project"?"project":"recent")}),n("button",{type:"button","aria-pressed":m,class:"cursor-pointer transition-all duration-180 ease-spring",style:{padding:"6px 12px",borderRadius:"9px",border:"1px solid var(--hair)",background:m?"var(--card)":"transparent",color:m?"var(--ink)":"var(--ink-2)",fontSize:"12.5px",fontWeight:500,boxShadow:m?"var(--shadow-s)":"none"},onClick:()=>k(!m),children:m?"Hide done":"Show done"})]}),a&&n(ja,{project:a,account:E,accounts:o,onDeleted:()=>{l(null),v()},onMoved:v}),y==="recent"&&!a&&L.length>0&&n("section",{style:{...zt,animation:"riseIn .4s var(--ease) both"},"aria-label":"Recently opened",children:[n("div",{class:"flex items-center",style:{...jt,gap:"10px"},children:[n("span",{class:"i-lucide-clock shrink-0",style:{width:"14px",height:"14px",color:"var(--ink-2)"}}),n("span",{style:{fontSize:"14px",fontWeight:650,letterSpacing:"-0.01em"},children:"Recently opened"}),n("span",{class:"flex-1"}),n("span",{class:"mono",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:[L.length," task",L.length===1?"":"s"]})]}),L.map(j=>n(Fo,{session:j,showProject:!0,isOpenInTab:g.has(K(j)),onSelect:()=>b(j),onMarkDone:j.type==="login"?void 0:()=>f(j)},K(j)))]}),(y==="project"||a)&&O.map((j,G)=>{var V;return n(Ba,{project:j.project,account:((V=r[j.project])==null?void 0:V.account)??j.sessions[0].account,sessions:j.sessions,index:G,openTabKeys:g,onSelectTask:b,onMarkDone:f},j.project)}),O.length===0&&n("section",{style:{...zt,animation:"riseIn .4s var(--ease) both"},children:[a&&n("div",{class:"flex items-center",style:{...jt,gap:"10px"},children:[n($e,{size:9}),n("span",{style:{fontSize:"14px",fontWeight:650,letterSpacing:"-0.01em"},children:a})]}),n("div",{class:"flex flex-col items-center text-center",style:{padding:"28px 16px",gap:"12px"},children:[n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:s||h?"No active tasks match these filters.":a?`No active tasks on ${a}.`:"No active tasks. Start something new."}),n(D,{label:"New task",variant:"primary",onClick:u})]})]}),m&&I.length>0&&n("section",{style:{...zt,boxShadow:"var(--shadow-s)"},"aria-label":"Done",children:[n("div",{style:{...jt,padding:"10px 15px",fontSize:"13px",fontWeight:600,color:"var(--ink-2)"},children:["Done · last ",Math.min($r,I.length)," of ",I.length]}),I.slice(0,$r).map(j=>n(za,{session:j,onSelect:()=>b(j)},K(j)))]})]})]})},Re={padding:"6px 12px",borderRadius:"9px",border:"1px solid var(--hair)",background:"var(--card)",color:"var(--ink)",fontSize:"12.5px",fontWeight:500,boxShadow:"var(--shadow-s)",whiteSpace:"nowrap"},Fe="inline-flex items-center gap-1 cursor-pointer transition-all duration-180 ease-spring hover:-translate-y-px hover:shadow-m hover:text-ink",Go={...Re,color:"var(--ink-3)",boxShadow:"none"},Vo=({href:e,title:t,children:r})=>n("a",{class:Fe,style:Re,href:e,target:"_blank",rel:"noopener noreferrer",title:t,children:[r," ",n("span",{class:"i-lucide-external-link",style:{width:"12px",height:"12px"}})]}),Ha=({entry:e})=>{var r;const t=(r=e==null?void 0:e.state)==null?void 0:r.github;if(!t||t.url===null){const o=e?e.error??(t==null?void 0:t.reason)??"This task has no GitHub remote":"Checking the repository…";return n("button",{type:"button",class:"inline-flex items-center gap-1 cursor-not-allowed",style:Go,disabled:!0,title:o,children:["GitHub ",n("span",{class:"i-lucide-external-link",style:{width:"12px",height:"12px"}})]})}return n(Vo,{href:t.url,title:t.label,children:"GitHub"})},Ka=({session:e})=>{const t=qn(e);return t&&n(Vo,{href:t.url,title:t.url,children:t.label})},qa=({session:e,entry:t})=>{var d;const[r,o]=w(!1),i=X(null);F(()=>{Po()},[]),F(()=>{if(!r)return;const h=c=>{i.current&&!i.current.contains(c.target)&&o(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[r]);const a=$n.value,l=a!=null&&a.enabled?a.editors:[];if(l.length===0)return null;const s=(d=t==null?void 0:t.state)==null?void 0:d.workspace;if(s!=="ready")return n("button",{type:"button",class:"cursor-not-allowed",style:Go,disabled:!0,title:t?s==="missing"?"Workspace not created yet":"This session has no worktree":"Checking the worktree…",children:["Open in ",l.length===1?l[0].label:"editor"]});const p=async h=>{o(!1);try{await ga(e,h)}catch(c){P(c.message,"error")}};return l.length===1?n("button",{type:"button",class:Fe,style:Re,onClick:()=>p(l[0].id),children:["Open in ",l[0].label]}):n("div",{class:"relative",ref:i,children:[n("button",{type:"button",class:Fe,style:Re,"aria-expanded":r,onClick:()=>o(h=>!h),children:["Open in editor ",n("span",{class:"i-lucide-chevron-down",style:{width:"12px",height:"12px"}})]}),r&&n("div",{class:"popover absolute right-0 top-full z-30 flex flex-col",style:{marginTop:"6px",minWidth:"160px",padding:"5px",borderRadius:"12px"},children:l.map(h=>n("button",{type:"button",class:"text-left cursor-pointer hover:bg-elev",style:{padding:"7px 10px",borderRadius:"8px",border:0,background:"none",color:"var(--ink)",fontSize:"13px"},onClick:()=>p(h.id),children:h.label},h.id))})]})},Ja={"--orange":"--red","--blue":"--purple","--purple":"--blue","--green":"--teal"},Qe=({label:e,index:t,color:r="var(--ink)",bar:o,title:i,children:a})=>n("div",{class:"min-w-0",title:i,style:{padding:"10px 12px",borderRadius:"13px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",animation:`riseIn .34s var(--ease) ${t*60}ms both`},children:[n("div",{style:{fontSize:"11.5px",color:"var(--ink-2)"},children:e}),n("div",{class:"mono truncate",style:{fontSize:"19px",fontWeight:650,color:r,marginTop:"2px"},children:a}),o!==void 0&&n("div",{style:{height:"5px",borderRadius:"99px",background:"var(--elev)",marginTop:"7px",overflow:"hidden"},children:n("div",{style:{height:"100%",width:`${o??0}%`,borderRadius:"99px",background:"linear-gradient(90deg, var(--blue), var(--purple))",transition:"width .6s var(--ease)"}})})]}),dn=({title:e,items:t,tone:r,empty:o})=>n("div",{style:{padding:"11px 13px",borderRadius:"13px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)"},children:[n("div",{style:{fontSize:"11.5px",fontWeight:600,color:"var(--ink-2)",marginBottom:"5px"},children:e}),n("div",{class:"flex flex-wrap",style:{gap:"5px"},children:[t.length===0&&n("span",{style:{fontSize:"12px",color:"var(--ink-3)"},children:o}),t.map(i=>n("span",{title:i.title,style:{padding:"2px 8px",borderRadius:"99px",fontSize:"11px",fontWeight:500,background:r&&!i.muted?se(r):"var(--elev)",color:r&&!i.muted?`var(${r})`:"var(--ink-2)",opacity:i.muted?.6:1},children:i.name},i.name))]})]}),Ga=({session:e,active:t,onDone:r})=>{const[o,i]=w(""),[a,l]=w(!1),[s,p]=w(!1),[d,h]=w(0),[c,m]=w(null),[k,g]=w(!1),b=K(e),f=qt(e),u=e.type==="task"||e.type==="review",x=Io(e,{poll:t&&e.type==="task"}),v=Un(e.type),C=e.type==="login",y=Ko(qo(C?"":ue(e))),R=ko(b).value,A=encodeURIComponent(e.project),L=encodeURIComponent(f),S=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws/terminal/${A}/${L}?k=${d}`;F(()=>{if(C)return;let M=!1;return Promise.all([fetch(`/api/cw/tools?project=${A}`).then(j=>j.json()).catch(()=>null),fetch(`/api/cw/git/branch/${A}/${L}`).then(j=>j.json()).catch(()=>null)]).then(([j,G])=>{M||(j&&m(j),i((G==null?void 0:G.branch)||e.task||e.pr||""))}),()=>{M=!0}},[b]);const z=()=>{l(!1),h(M=>M+1)},_=(c==null?void 0:c.mcps)??[],N=(c==null?void 0:c.plugins)??[],O=(x==null?void 0:x.state)??null,E=(O==null?void 0:O.branch)??o,B=x?x.error!==null?"Changes unknown":ya(x.state):"Checking changes…",H=[ue(e)||"no project",e.account,[co(e),e.provider&&e.provider!=="native"?null:e.model].filter(Boolean).join(", "),`${e.opens} session${e.opens===1?"":"s"}`].filter(Boolean).join(" · ");return n("div",{class:"flex flex-col h-full min-w-0",children:[n("div",{class:"flex flex-col shrink-0",style:{padding:"14px 20px",gap:"12px"},children:[n("div",{class:"flex items-center flex-wrap",style:{gap:"12px"},children:[n("span",{class:"grid place-items-center shrink-0",style:{width:"34px",height:"34px",borderRadius:"11px",background:`linear-gradient(160deg, var(${v.token}), var(${Ja[v.token]??v.token}))`,boxShadow:"var(--shadow-m)",color:"#fff",fontSize:"13px",fontWeight:700},"aria-hidden":"true",children:v.glyph}),n("div",{class:"min-w-0",children:[n("h1",{class:"truncate",style:{fontSize:"19px",fontWeight:700,letterSpacing:"-0.02em"},children:he(e)}),n("p",{class:"truncate",style:{marginTop:"1px",fontSize:"12.5px",color:"var(--ink-2)"},children:H}),!C&&n("p",{class:"mono truncate",style:{marginTop:"2px",fontSize:"11.5px",color:"var(--ink-3)"},title:B,children:B})]}),n("span",{style:{flex:"1 1 60px"}}),n("div",{class:"flex flex-wrap items-center",style:{gap:"7px"},children:[!C&&n("button",{type:"button",class:Fe,style:Re,"aria-expanded":k,onClick:()=>g(M=>!M),children:k?"Hide context":`Context · ${_.length} MCP, ${N.length} plugins`}),!C&&n(Ka,{session:e}),!C&&n(Ha,{entry:x}),!C&&n(qa,{session:e,entry:x}),a&&n(D,{label:"Restart",variant:"secondary",size:"sm",onClick:z}),e.status==="active"&&!C&&n(D,{label:"Mark done",variant:"primary",size:"sm",onClick:r})]})]}),!C&&n("div",{class:"grid",style:{gridTemplateColumns:"repeat(auto-fit, minmax(138px, 1fr))",gap:"9px"},children:[n(Qe,{index:0,label:"Context used",color:"var(--blue)",bar:(R==null?void 0:R.context)??null,title:"Read from the harness status line",children:(R==null?void 0:R.context)!=null?`${Math.round(R.context)}%`:"—"}),n(Qe,{index:1,label:"Tokens",children:(R==null?void 0:R.tokens)!=null?wo(R.tokens):"—"}),n(Qe,{index:2,label:"Cost",color:"var(--green)",children:(R==null?void 0:R.cost)!=null?_o(R.cost):"—"}),u&&n(Qe,{index:3,label:"Commits",children:(O==null?void 0:O.commits)??"—"}),u&&n(Qe,{index:4,label:"Unpushed",color:O&&dt(O)>0?"var(--orange)":"var(--ink)",children:O?dt(O):"—"}),E&&n("button",{type:"button",class:"text-left cursor-pointer transition-all duration-180 ease-spring hover:-translate-y-px hover:shadow-m min-w-0",style:{padding:"10px 12px",borderRadius:"13px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",color:"var(--ink)",animation:"riseIn .34s var(--ease) 300ms both"},title:"Copy branch name",onClick:()=>Gn(E,"Branch"),children:[n("div",{class:"flex items-center",style:{gap:"4px",fontSize:"11.5px",color:"var(--ink-2)"},children:["Branch ",n("span",{class:"i-lucide-copy",style:{width:"11px",height:"11px"}})]}),n("div",{class:"mono truncate",style:{fontSize:"13px",fontWeight:600,marginTop:"6px"},children:E})]})]}),k&&n("div",{class:"grid",style:{gridTemplateColumns:"repeat(auto-fit, minmax(230px, 1fr))",gap:"9px",animation:"riseIn .3s var(--ease) both"},children:[n(dn,{title:`MCP · ${_.length}`,tone:"--blue",empty:"No MCP servers",items:_.map(M=>({name:M.name,title:`${M.type} · ${M.source}`}))}),n(dn,{title:`Plugins · ${N.length}`,tone:"--green",empty:"No plugins",items:N.map(M=>({name:M.name,muted:!M.enabled,title:`${M.enabled?"enabled":"disabled"} · ${M.marketplace}${M.hasMcp?` · MCP ${M.mcpName??""}`:""}`}))}),n(dn,{title:"Stack",tone:null,empty:"Nothing detected",items:y.map(M=>({name:M}))})]})]}),n("div",{class:"task-terminal relative flex-1 min-h-0",style:{margin:"0 20px 20px",borderRadius:"14px",overflow:"hidden",background:"var(--term)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-l)"},children:n("div",{class:"absolute inset-0 flex flex-col",children:[n("div",{class:"flex items-center shrink-0",style:{gap:"7px",padding:"8px 12px",borderBottom:"1px solid rgba(255,255,255,.08)"},children:[n("span",{style:{width:"11px",height:"11px",borderRadius:"50%",background:"#ff5f57"}}),n("span",{style:{width:"11px",height:"11px",borderRadius:"50%",background:"#febc2e"}}),n("span",{style:{width:"11px",height:"11px",borderRadius:"50%",background:"#28c840"}}),n("span",{class:"mono truncate",style:{fontSize:"11px",color:"#8a8a92",marginLeft:"6px"},children:[E||he(e)," — ",e.harness??"claude"]}),n("span",{class:"flex-1"}),n("span",{class:"mono",style:{fontSize:"11px",color:s?"#30d158":"#8a8a92"},children:s?"connected":a?"exited":"offline"})]}),n("div",{class:"relative flex-1 min-h-0",style:{padding:"12px 6px 6px 14px"},children:[n(zi,{wsUrl:S,theme:ut.value,focused:t,onOutput:M=>Xi(b,M),onExit:()=>l(!0),onGiveUp:()=>l(!0),onConnectionChange:p}),!s&&!a&&n("div",{class:"absolute inset-0 grid place-items-center pointer-events-none",style:{background:"rgba(0,0,0,.35)"},children:n("span",{style:{fontSize:"13px",color:"rgba(255,255,255,.7)"},children:"Connecting…"})})]})]})})]})},Me={fontSize:"12px",color:"var(--ink-2)"},ee=({label:e,plain:t,children:r})=>n(t?"div":"label",{class:"flex flex-col min-w-0",style:{gap:"5px"},children:[n("span",{style:Me,children:e}),r]}),Tr={dev:"New dev task",review:"Review a pull request",loop:"New loop",general:"New session"},Va={dev:"A worktree session that ends in a pull request. Paste a Linear or Notion link and the ticket lands in TASK_NOTES.md first.",review:"Opens a pull request in a review worktree and walks the agent through the diff.",loop:"A recurring Claude Code /loop on one project — babysit PRs, fix failing tests, work a backlog.",general:"A plain agent session on an account, optionally inside a project. No worktree."},Ya={dev:"Task name or ticket URL",review:"Pull request number or URL",loop:"Loop prompt",general:""},Qa={dev:"fix-auth or https://linear.app/…",review:"42 or https://github.com/…/pull/42",loop:"Babysit my open PRs…",general:""},Za=[{id:"",label:"Auto"},{id:"feature",label:"feature"},{id:"bugfix",label:"bugfix"},{id:"refactor",label:"refactor"}],pn={boxShadow:"var(--shadow-s)"},yt=e=>/^[\w./:#-]+$/.test(e)?e:`"${e.replace(/"/g,'\\"')}"`,Xa=({projects:e,accounts:t,initialAccount:r,initialProject:o,onClose:i,onCreated:a,onOpenAccounts:l})=>{var $;const s=Vn(me.value,De.value),[p,d]=w(""),[h,c]=w(""),[m,k]=w(""),[g,b]=w(""),[f,u]=w(""),[x,v]=w(!1),[C,y]=w(!1),[R,A]=w(""),[L,I]=w("claude"),S=Gt();F(()=>{ge()},[]),F(()=>{const T=W=>{W.key==="Escape"&&i()};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[i]);const z=We.value,_=z!=null&&z.available?z.doctor:null,N=Object.keys(e),O=s==="general",E=s==="review",B=s==="loop",H=me.value,M=!R.trim()||/^\d+[smh]$/.test(R.trim()),j=t.length>0?t:Array.from(new Set(Object.values(e).map(T=>T.account).filter(Boolean))).sort(),G=p?N.filter(T=>{var W;return((W=e[T])==null?void 0:W.account)===p}):N;F(()=>{const T=o&&!r&&e[o]?e[o].account:void 0,W=r??T,U=W&&j.includes(W)?W:j[0]??"";d(U);const ne=U?N.filter(_e=>{var nr;return((nr=e[_e])==null?void 0:nr.account)===U}):N,re=o&&ne.includes(o)?o:!O&&ne.length>0?ne[0]:"";re&&c(re)},[]);const V=X(!1);F(()=>{if(!V.current){V.current=!0;return}!O&&!h&&G.length>0&&c(G[0])},[O]);const de=T=>{d(T);const W=N.filter(U=>{var ne;return((ne=e[U])==null?void 0:ne.account)===T});!O&&W.length>0&&!W.includes(h)?c(W[0]):O&&h&&!W.includes(h)&&c("")},ae=_?po(h||void 0,p,e,_):"claude";F(()=>{!_||!p||I(B?"claude":ae)},[z==null?void 0:z.available,p,h,B]);const ce=_?Ce(_,p,L):void 0,pe=!_||Ee(z,L,"skip_permissions"),ke=!_||L==="claude",xe=ke||!O,Pe=_?Yn(L,ce,B):null,Ke=fe(L).label;F(()=>{pe||v(!1),u(ke?"":(ce==null?void 0:ce.model)??"")},[L]),F(()=>{ke||u((ce==null?void 0:ce.model)??"")},[p]);const Yt=vo(H),Qt=xo(z,L,H),ht=!O&&!H.trim()||B&&!M||!O&&!h||!!Pe,ft=async()=>{if(!ht){y(!0);try{const T={type:s,account:p||void 0,skipPermissions:x||void 0};_&&(T.harness=L),B?(T.project=h,T.loopPrompt=H.trim(),T.loopInterval=R.trim()||void 0):O?h&&(T.project=h):(T.project=h,T.task=H.trim(),T.description=m.trim()||void 0,T.workflow=g||void 0),T.model=xe&&f||void 0;const U=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(T)})).json();U.ok?(P(O?"Session started":B?"Loop started":"Task started","success"),O||Mt(""),a(U.session)):P(U.error??"Failed to start","error")}catch{P("Failed to start","error")}finally{y(!1)}}},Zt=p||j[0]||"default",Xt=O?`cw launch ${yt(Zt)}`:B?`cw loop ${h||"<project>"} ${yt(H.trim()||"<prompt>")}${R.trim()?` --every ${R.trim()}`:""}`:E?`cw review ${h||"<project>"} ${yt(H.trim()||"<pr>")}`:`cw work ${h||"<project>"} ${H.trim()?yt((($=Vt(H))==null?void 0:$.kind)==="name"?Mo(H):H.trim()):"<task>"}`;return n("div",{class:"fixed inset-0 z-50 flex justify-end",style:{background:"rgba(0,0,0,.38)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)"},onClick:i,children:n("aside",{role:"dialog","aria-modal":"true","aria-label":Tr[s],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:[n("div",{class:"glass flex items-center sticky top-0 z-1",style:{gap:"10px",padding:"14px 18px",borderBottom:"1px solid var(--hair)"},children:[n("h2",{style:{fontSize:"17px",fontWeight:700,letterSpacing:"-0.02em"},children:Tr[s]}),n("span",{class:"flex-1"}),n(to,{onClick:i})]}),n("div",{class:"flex flex-col",style:{padding:"16px 18px 24px",gap:"14px"},children:[n(Ho,{fill:!0}),n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)",lineHeight:1.5},children:Va[s]}),!O&&n("div",{class:"flex flex-col",style:{gap:"5px"},children:[n(ee,{label:Ya[s],children:n("input",{class:"field",style:{...pn,fontSize:"14px"},placeholder:Qa[s],value:H,ref:S,onInput:T=>{const W=T.target.value;B?me.value=W:Mt(W)},onKeyDown:T=>{T.key==="Enter"&&ft()}})}),!B&&n(Uo,{ctx:{type:s,project:h,account:p,harness:L},size:"sm"})]}),n("div",{class:"grid",style:{gridTemplateColumns:"1fr 1fr",gap:"10px"},children:[n(ee,{label:"Account",children:n("select",{class:"field",value:p,onChange:T=>{const W=T.target.value;de(W),Ft.value=W},children:j.map(T=>n("option",{value:T,children:T},T))})}),n(ee,{plain:!0,label:O?"Project · optional":"Project",children:n(Bo,{label:"Project",size:"md",width:"100%",value:h,placeholder:O?"No project":"Choose…",onChange:T=>{c(T),Ie.value=T},options:[...O?[{value:"",label:"No project"}]:[],...jn(e,j,G)]})})]}),B&&n(ee,{label:"Interval · optional",children:[n("input",{class:"field mono",style:{...pn,borderColor:M?void 0:"var(--red)"},value:R,placeholder:"auto — Claude decides the pace",onInput:T=>A(T.target.value)}),!M&&n("span",{style:{fontSize:"12px",color:"var(--red)"},children:"Use forms like 30s, 5m, 2h — or leave it empty to self-pace"})]}),(s==="dev"||E)&&n(ee,{label:"Description (optional)",children:n("textarea",{class:"field",rows:3,style:pn,placeholder:"Context the agent reads first…",value:m,onInput:T=>k(T.target.value)})}),_&&n(Ea,{doctor:_,account:p,value:L,defaultHarness:ae,isLoop:B,onChange:I,onOpenAccounts:l}),xe&&n("div",{class:"grid",style:{gridTemplateColumns:s==="dev"?"1fr 1fr":"1fr",gap:"10px"},children:[n("div",{class:"flex flex-col min-w-0",style:{gap:"5px"},children:[n("span",{style:Me,children:"Model"}),ke?n(ve,{fill:!0,size:"sm",label:"Model",tabs:Fi.map(T=>({id:T.id,label:T.label})),active:f,onChange:u}):n("input",{class:"field mono",style:{height:"32px",fontSize:"12.5px"},value:f,placeholder:"the account's model","aria-label":"Model",onInput:T=>u(T.target.value)})]}),s==="dev"&&n("div",{class:"flex flex-col min-w-0",style:{gap:"5px"},children:[n("span",{style:Me,children:"Workflow"}),n(ve,{fill:!0,size:"sm",label:"Workflow",tabs:Za,active:g,onChange:b})]})]}),pe&&n("div",{class:"flex items-center",style:{gap:"10px",padding:"10px 12px",borderRadius:"12px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)"},children:[n("span",{class:"flex-1",style:{fontSize:"13px"},children:["Bypass permissions ",n("span",{class:"mono",style:{fontSize:"11px",color:"var(--ink-3)"},children:"--skip-permissions"})]}),n(ro,{checked:x,onChange:v,label:"Bypass permissions"})]}),Qt&&n("p",{style:{fontSize:"12.5px",padding:"10px 12px",borderRadius:"12px",background:se("--orange"),color:"var(--ink)"},children:[Ke," has no MCP and CW has no ",Yt==="linear"?"LINEAR_API_KEY":"NOTION_TOKEN",", so the ticket will not reach TASK_NOTES.md. The task still starts, without the ticket."]}),n(D,{label:C?"Starting…":O?"Launch session":B?"Start loop":E?"Start review":"Start task",variant:"primary",size:"lg",block:!0,loading:C,disabled:ht,onClick:ft}),Pe&&n("p",{style:{fontSize:"12px",color:"var(--red)",textAlign:"center"},children:Pe}),n("p",{class:"mono",style:{fontSize:"11.5px",color:"var(--ink-3)",textAlign:"center",overflowWrap:"anywhere"},children:Xt})]})]})})},Bt=te(null),Ln=te(null);async function Xn(){const e=await fetch("/api/skills/plugins");if(!e.ok)throw new Error("fetch failed");Bt.value=await e.json()}async function An(){const e=await fetch("/api/skills/marketplaces");if(!e.ok)throw new Error("fetch failed");Ln.value=await e.json()}const je=({title:e,sub:t,children:r})=>n("div",{class:"glass flex items-center flex-wrap shrink-0",style:{gap:"10px",padding:"12px 20px",borderBottom:"1px solid var(--hair)"},children:[n("div",{class:"min-w-0",children:[n("h2",{style:{fontSize:"17px",fontWeight:650,letterSpacing:"-0.015em",overflowWrap:"anywhere"},children:e}),t&&n("p",{class:"mono",style:{marginTop:"1px",fontSize:"11.5px",color:"var(--ink-3)",overflowWrap:"anywhere"},children:t})]}),n("span",{style:{flex:"1 1 40px"}}),r]});function es(e){const t=new Set;for(const r of e.skills){const o=r.path.split(/[\\/]/),i=o.lastIndexOf("skills");i>=0&&o.length-i===3&&t.add(o[i+1])}return[...t].sort()}function ts(e){return`add-skill-${e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,30).replace(/-+$/,"")||Date.now()}`}function ns(e,t,r){return["Add a new skill to this repository and open a pull request.",`The skill: ${t}`,r?`Area: ${r}`:"",e.contributing?"Follow CONTRIBUTING.md.":"",e.projectSkills.length>0?`Use this repository's own skills: ${e.projectSkills.map(o=>`/${o}`).join(", ")}`:""].filter(Boolean).join(`
14
+ `)}const Yo=e=>`/api/skills/plugins/${encodeURIComponent(e)}`;async function er(e,t){try{return await Xe(e,t)}catch(r){return P(Rt(r),"error"),null}}async function Qo(e,t,r){await er("/api/skills/plugins/install",{id:e,account:r})&&(P(`${t} installed in ${r} · applies to new sessions`,"success"),await Promise.all([Xn(),An()]).catch(()=>{}))}const Zo=(e,t)=>t?e.skills.filter(r=>r.name.toLowerCase().includes(t)||r.description.toLowerCase().includes(t)):e.skills,rs=({list:e,query:t,selected:r,onSelect:o})=>{const i=e.flatMap(a=>{const l=Zo(a,t).length;return!t||l>0||a.name.toLowerCase().includes(t)?[{p:a,count:l}]:[]});return i.length===0?null:n("div",{style:{marginTop:"10px"},children:[n("p",{style:{padding:"6px 11px",fontSize:"11px",fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"var(--ink-3)"},children:"Plugins"}),i.map(({p:a,count:l})=>{const s=r===a.id;return n("button",{type:"button","aria-current":s?"true":void 0,class:"flex items-center w-full text-left cursor-pointer transition-all duration-180 ease-spring hover:bg-elev",style:{gap:"8px",padding:"9px 11px",marginBottom:"4px",borderRadius:"11px",border:`1px solid ${s?"var(--hair)":"transparent"}`,background:s?"var(--card)":"transparent",boxShadow:s?"var(--shadow-s)":"none",color:"var(--ink)"},onClick:()=>o(a.id),children:[n("span",{class:"i-lucide-package shrink-0",style:{width:"13px",height:"13px",color:"var(--ink-3)"}}),n("span",{class:"flex-1 min-w-0 truncate",style:{fontSize:"13px",fontWeight:600},children:a.name}),n("span",{class:"mono",style:{fontSize:"11px",color:"var(--ink-3)"},children:l})]},a.id)})]})},Rr={fontSize:"12px",fontWeight:600,color:"var(--ink-2)",margin:"0 0 8px"},Xo={gap:"10px",padding:"9px 12px",borderRadius:"11px",border:"1px solid var(--hair)",background:"var(--card)"},os=({plugin:e,install:t})=>{const[r,o]=w(!1),i=t.scope==="global"?"global":t.scopeRef,a=async()=>{o(!0);const l=await er(`${Yo(e.id)}/update`,{scope:t.scope,scopeRef:t.scopeRef});o(!1),l&&(P(`${e.name} ${l.version??""} · applies to new sessions`,"success"),Xn().catch(()=>{}))};return n("div",{class:"flex items-center",style:Xo,children:[n("span",{class:"flex-1 min-w-0 truncate",style:{fontSize:"13px",fontWeight:600},children:i}),n("span",{class:"mono",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:t.version}),n("span",{style:{fontSize:"11.5px",color:t.enabled?"var(--green)":"var(--ink-3)"},children:t.enabled?"on":"off"}),n(D,{label:r?"Updating…":"Update",variant:"secondary",size:"sm",loading:r,onClick:a})]})},is=({plugin:e,account:t})=>{const[r,o]=w(!1);return n("div",{class:"flex items-center",style:Xo,children:[n("span",{class:"flex-1",style:{fontSize:"13px",color:"var(--ink-2)"},children:t}),n("span",{style:{fontSize:"11.5px",color:"var(--ink-3)"},children:"not installed"}),n(D,{label:r?"Installing…":"Install",variant:"secondary",size:"sm",loading:r,onClick:async()=>{o(!0),await Qo(e.id,e.name,t),o(!1)}})]})},as=({plugin:e,name:t,onBack:r})=>{const[o,i]=w(null),[a,l]=w(!1);return F(()=>{let s=!1;return i(null),l(!1),fetch(`${Yo(e.id)}/skills/${encodeURIComponent(t)}`).then(p=>p.ok?p.json():Promise.reject(new Error("not found"))).then(p=>{s||i(p.content)}).catch(()=>{s||l(!0)}),()=>{s=!0}},[e.id,t]),n(Z,{children:[n(je,{title:t,sub:`${e.name} · read-only`,children:n(D,{label:"Back",variant:"secondary",size:"sm",onClick:r})}),n("div",{class:"flex-1 min-h-0 overflow-auto",style:{padding:"12px 20px 20px"},children:[n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)",margin:"0 0 10px"},children:"Comes from the plugin. To change it, propose the change in the repository."}),a?n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:"Skill not found."}):o===null?n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:"Loading skill…"}):n("pre",{class:"mono",style:{margin:0,padding:"14px 16px",borderRadius:"14px",border:"1px solid var(--hair)",background:"var(--card)",fontSize:"12.5px",lineHeight:1.7,whiteSpace:"pre-wrap",overflowWrap:"anywhere",boxShadow:"var(--shadow-s)"},children:o})]})]})},ss=({plugin:e,accounts:t,query:r,onSelectSkill:o,onPropose:i})=>{const a=new Set(e.installs.map(s=>s.scopeRef)),l=t.filter(s=>!a.has(s));return n(Z,{children:[n(je,{title:e.name,sub:e.repo?`${e.repo} · Claude Code only`:"Claude Code only",children:[e.repo&&n("a",{href:`https://github.com/${e.repo}`,target:"_blank",rel:"noreferrer",style:{fontSize:"12.5px",color:"var(--blue)"},children:"GitHub"}),e.project&&i&&n(D,{label:"Propose a skill",variant:"primary",size:"sm",onClick:i})]}),n("div",{class:"flex-1 min-h-0 overflow-auto",children:n("div",{class:"flex flex-col",style:{padding:"16px 20px 24px",gap:"18px",maxWidth:"720px"},children:[e.description&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)",margin:0},children:e.description}),!e.project&&e.repo&&n("p",{style:{fontSize:"12.5px",color:"var(--ink-3)",margin:0},children:["Register ",n("span",{class:"mono",children:e.repo})," as a CW project to propose skills."]}),n("section",{children:[n("h3",{style:Rr,children:"Accounts"}),n("div",{class:"flex flex-col",style:{gap:"6px"},children:[e.installs.map(s=>n(os,{plugin:e,install:s},`${s.scope}/${s.scopeRef}`)),l.map(s=>n(is,{plugin:e,account:s},s))]})]}),n("section",{children:[n("h3",{style:Rr,children:["Skills (",e.skills.length,")"]}),n("div",{class:"flex flex-col",style:{gap:"4px"},children:Zo(e,r).map(s=>n("button",{type:"button",class:"flex items-center w-full text-left cursor-pointer hover:bg-elev",style:{gap:"10px",padding:"8px 11px",borderRadius:"10px",border:0,background:"transparent",color:"var(--ink)"},onClick:()=>o(s.name),children:[n("span",{class:"shrink-0",style:{fontSize:"13px",fontWeight:600},children:s.name}),n("span",{class:"flex-1 min-w-0 truncate",style:{fontSize:"12px",color:"var(--ink-2)"},children:s.description}),n("span",{class:"i-lucide-chevron-right shrink-0",style:{width:"13px",height:"13px",color:"var(--ink-3)"}})]},s.name))})]})]})})]})},ls=({accounts:e})=>{const[t,r]=w(""),o=e.includes(t)?t:e[0]??"",[i,a]=w(""),[l,s]=w(""),[p,d]=w(""),[h,c]=w(!1),[m,k]=w(null);F(()=>{Ln.value===null&&An().catch(()=>P("Failed to load marketplaces","error"))},[]);const g=Ln.value,b=(g==null?void 0:g.find(y=>y.name===i))??(g==null?void 0:g[0]),f=new Set((Bt.value??[]).flatMap(y=>y.installs.some(R=>R.scope==="account"&&R.scopeRef===o)?[y.id]:[])),u=l.trim().toLowerCase(),x=((b==null?void 0:b.plugins)??[]).filter(y=>!u||y.name.toLowerCase().includes(u)||y.description.toLowerCase().includes(u)),v=async()=>{c(!0);const y=await er("/api/skills/marketplaces",{source:p.trim(),account:o});c(!1),y&&(P(`Marketplace added to ${o}`,"success"),d(""),await An().catch(()=>{}))},C=async(y,R)=>{k(y),await Qo(y,R,o),k(null)};return n(Z,{children:[n(je,{title:"Add a plugin",sub:o?`Claude Code only · installs into ${o}`:"Claude Code only"}),n("div",{class:"flex-1 min-h-0 overflow-auto flex flex-col",style:{padding:"14px 20px 20px",gap:"8px"},children:[n("div",{class:"flex flex-col",style:{gap:"10px",maxWidth:"560px",marginBottom:"6px"},children:[e.length===0&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)",margin:0},children:"Plugins install into a CW account. Add one in Accounts first."}),e.length>0&&n(ee,{label:"Account",children:n("select",{class:"field",value:o,onChange:y=>r(y.target.value),children:e.map(y=>n("option",{value:y,children:y},y))})}),g&&g.length>0&&n(ee,{label:"Marketplace",children:n("select",{class:"field",value:b==null?void 0:b.name,onChange:y=>a(y.target.value),children:g.map(y=>n("option",{value:y.name,children:[y.name," · ",y.source]},y.name))})}),n(ee,{label:"Add a marketplace",children:n("div",{class:"flex",style:{gap:"8px"},children:[n("input",{class:"field flex-1",value:p,placeholder:"owner/repo, git URL or path",onInput:y=>d(y.target.value),onKeyDown:y=>{y.key==="Enter"&&p.trim()&&v()}}),n(D,{label:h?"Adding…":"Add",variant:"secondary",size:"sm",loading:h,disabled:!p.trim()||!o,onClick:v})]})}),b&&b.plugins.length>0&&n("input",{class:"field",type:"search","aria-label":"Filter plugins",value:l,placeholder:`Filter ${b.plugins.length} plugins`,onInput:y=>s(y.target.value)})]}),g===null&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:"Loading marketplaces…"}),(g==null?void 0:g.length)===0&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:"No marketplace yet. Add one above."}),b&&x.length===0&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:u?"No plugin matches.":"This marketplace lists no plugins."}),x.map((y,R)=>n("div",{class:"flex items-center",style:{gap:"12px",padding:"11px 15px",borderRadius:"13px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",animation:`riseIn .3s var(--ease) ${Math.min(R,8)*40}ms both`},children:[n("div",{class:"flex-1 min-w-0",children:[n("div",{class:"flex items-center min-w-0",style:{gap:"8px"},children:[n("span",{class:"truncate",style:{fontSize:"13.5px",fontWeight:600},children:y.name}),y.category&&n("span",{class:"mono shrink-0",style:{fontSize:"11px",color:"var(--ink-3)"},children:y.category})]}),y.description&&n("div",{class:"truncate",style:{fontSize:"12px",color:"var(--ink-2)"},title:y.description,children:y.description})]}),f.has(y.id)?n("span",{style:{fontSize:"12px",color:"var(--green)"},children:"Installed"}):n(D,{label:m===y.id?"Installing…":"Install",variant:"secondary",size:"sm",loading:m===y.id,disabled:m!==null||!o,onClick:()=>C(y.id,y.name)})]},y.id))]})]})},cs=({plugin:e,accounts:t,onSubmit:r,onCancel:o})=>{const i=es(e),a=e.installs.filter(f=>f.scope==="account").map(f=>f.scopeRef),l=t.find(f=>a.includes(f))??t[0]??"",[s,p]=w(""),[d,h]=w(i[0]??""),[c,m]=w(l),[k,g]=w(!1),b=async()=>{g(!0);try{await r(s.trim(),i.length>1?d:void 0,c)}finally{g(!1)}};return n(Z,{children:[n(je,{title:"Propose a skill",sub:`${e.repo??e.name} · project ${e.project??""}`}),n("div",{class:"flex-1 min-h-0 overflow-auto",children:n("div",{class:"flex flex-col",style:{padding:"16px 20px 24px",gap:"14px",maxWidth:"560px"},children:[n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)",margin:0},children:["Starts a task in ",n("span",{class:"mono",children:e.project})," that writes the skill and opens a pull request for review."]}),n(ee,{label:"What the skill does and when to use it",children:n("textarea",{class:"field",rows:4,value:s,placeholder:"Summarize a release's merged PRs into notes when someone asks for a changelog",onInput:f=>p(f.target.value)})}),i.length>1&&n(ee,{label:"Area",children:n("select",{class:"field",value:d,onChange:f=>h(f.target.value),children:i.map(f=>n("option",{value:f,children:f},f))})}),t.length>0&&n(ee,{label:"Account",children:n("select",{class:"field",value:c,onChange:f=>m(f.target.value),children:t.map(f=>n("option",{value:f,children:f},f))})}),n("div",{class:"flex flex-wrap",style:{gap:"8px"},children:[n(D,{label:k?"Starting…":"Start task",variant:"primary",loading:k,disabled:!s.trim()||!c,onClick:b}),n(D,{label:"Cancel",variant:"secondary",onClick:o})]})]})})]})},ds={global:"--blue",account:"--orange",project:"--green"},bt=e=>`${e.scope}/${e.scopeRef}/${e.dirName}`;function ps(e,t){return e==="global"?"global":e==="account"?`account/${encodeURIComponent(t)}`:`project/${encodeURIComponent(t)}`}const it=e=>e.scope==="global"?"Global":`${e.scope==="account"?"Account":"Project"} · ${e.scopeRef}`,us=e=>e.scope==="global"?`~/.claude/skills/${e.dirName}`:e.scope==="account"?`~/.cw/accounts/${e.scopeRef}/skills/${e.dirName}`:`<${e.scopeRef}>/.claude/skills/${e.dirName}`,hs={global:"Lands in ~/.claude/skills; CW links it into every account when a Claude Code session starts.",account:"Every session on this account loads it.",project:"Sessions in this project load it from its .claude/skills."},ei=e=>e[0]?{scope:"account",scopeRef:e[0]}:{scope:"global",scopeRef:"global"},En=e=>e.scope==="global"||e.scopeRef!=="",ti=({accounts:e,projects:t,value:r,onChange:o})=>{const i=a=>{const l=a==="account"?e:t;o({scope:a,scopeRef:a==="global"?"global":l.includes(r.scopeRef)?r.scopeRef:l[0]??""})};return n(Z,{children:[n("div",{class:"flex flex-col",style:{gap:"5px"},children:[n("span",{style:Me,children:"Scope"}),n(ve,{label:"Scope",tabs:[{id:"account",label:"Account"},{id:"project",label:"Project"},{id:"global",label:"Global"}],active:r.scope,onChange:a=>i(a)}),n("span",{style:{fontSize:"12px",color:"var(--ink-3)"},children:hs[r.scope]})]}),r.scope!=="global"&&n(ee,{label:r.scope==="account"?"Account":"Project",children:n("select",{class:"field",value:r.scopeRef,onChange:a=>o({...r,scopeRef:a.target.value}),children:(r.scope==="account"?e:t).map(a=>n("option",{value:a,children:a},a))})})]})},fs=(e,t,r)=>[...t.map(o=>({scope:"account",scopeRef:o})),...r.map(o=>({scope:"project",scopeRef:o})),{scope:"global",scopeRef:"global"}].filter(o=>o.scope!==e.scope||o.scopeRef!==e.scopeRef),ni=(e,t="")=>{const r=[];for(const[o,i]of Object.entries(e))i&&typeof i=="object"&&!Array.isArray(i)?(r.push(`${t}${o}:`),r.push(...ni(i,t+" "))):r.push(`${t}${o}: ${String(i??"")}`);return r},vs=({skill:e,accounts:t,projects:r,onDeleted:o,onCopied:i,onRun:a})=>{const[l,s]=w(null),[p,d]=w(!0),[h,c]=w("SKILL.md"),[m,k]=w(""),[g,b]=w({}),[f,u]=w(!1),x=`/api/skills/${ps(e.scope,e.scopeRef)}/${encodeURIComponent(e.dirName)}`;F(()=>{let S=!1;return d(!0),c("SKILL.md"),fetch(x).then(z=>{if(!z.ok)throw new Error("fetch failed");return z.json()}).then(z=>{if(S)return;s(z);const _=ni(z.frontmatter);k(_.length>0?`---
15
+ ${_.join(`
16
+ `)}
17
+ ---
18
+
19
+ ${z.body}`:z.body),b(Object.fromEntries(z.references.map(N=>[N.name,N.content])))}).catch(()=>{S||(s(null),P("Failed to load skill","error"))}).finally(()=>{S||d(!1)}),()=>{S=!0}},[x]);const v=async()=>{u(!0);const S=h==="SKILL.md";try{const _=await(await fetch(S?x:`${x}/references/${encodeURIComponent(h)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:S?m:g[h]??""})})).json();_.ok?P(S?"Skill saved":"Reference saved","success"):P(_.error??"Failed to save","error")}catch{P("Failed to save","error")}finally{u(!1)}},C=async()=>{if(confirm(`Delete the skill "${e.name}" permanently?`))try{const z=await(await fetch(x,{method:"DELETE"})).json();z.ok?(P("Skill deleted","info"),o()):P(z.error??"Failed to delete","error")}catch{P("Failed to delete","error")}},y=async S=>{try{const _=await(await fetch("/api/skills/copy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({from:{scope:e.scope,scopeRef:e.scopeRef,name:e.dirName},to:S})})).json();_.ok?(P(`Copied to ${it(S)}`,"success"),i()):P(_.error??"Failed to copy","error")}catch{P("Failed to copy","error")}},R=async()=>{const S=prompt("Reference filename (e.g. examples.md):");if(!(S!=null&&S.trim()))return;const z=S.trim(),_=`# ${z}
20
+ `;try{const O=await(await fetch(`${x}/references/${encodeURIComponent(z)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:_})})).json();O.ok?(b(E=>({...E,[z]:_})),s(E=>E&&{...E,references:[...E.references,{name:z,content:_}]}),c(z),P("Reference added","success")):P(O.error??"Failed to add reference","error")}catch{P("Failed to add reference","error")}},A=async S=>{if(confirm(`Delete reference "${S}"?`))try{const _=await(await fetch(`${x}/references/${encodeURIComponent(S)}`,{method:"DELETE"})).json();_.ok?(b(N=>{const{[S]:O,...E}=N;return E}),s(N=>N&&{...N,references:N.references.filter(O=>O.name!==S)}),h===S&&c("SKILL.md"),P("Reference deleted","info")):P(_.error??"Failed to delete reference","error")}catch{P("Failed to delete reference","error")}},L=["SKILL.md",...(l==null?void 0:l.references.map(S=>S.name))??[]],I=fs(e,t,r);return n(Z,{children:[n(je,{title:e.name,sub:`${it(e)} · ${us(e)}`,children:[n(D,{label:"Delete",variant:"danger",size:"sm",onClick:C}),n("select",{class:"field","aria-label":"Copy to",style:{height:"30px",padding:"0 8px",fontSize:"12.5px",width:"auto"},value:"",disabled:!l,onChange:S=>{const z=S.target,_=I[Number(z.value)];z.value="",_&&y(_)},children:[n("option",{value:"",disabled:!0,children:"Copy to…"}),I.map((S,z)=>n("option",{value:z,children:it(S)},`${S.scope}/${S.scopeRef}`))]}),n(D,{label:"Run in session",variant:"secondary",size:"sm",onClick:a}),n(D,{label:f?"Saving…":"Save",variant:"primary",size:"sm",loading:f,disabled:!l,onClick:v})]}),n("div",{class:"flex items-center flex-wrap shrink-0",style:{gap:"6px",padding:"10px 20px 0"},role:"tablist","aria-label":"Files",children:[L.map(S=>{const z=h===S;return n("span",{class:"inline-flex items-center",style:{gap:"4px",padding:z?"5px 8px 5px 11px":"5px 11px",borderRadius:"9px",background:z?"var(--card)":"transparent",border:`1px solid ${z?"var(--hair)":"transparent"}`,boxShadow:z?"var(--shadow-s)":"none"},children:[n("button",{type:"button",role:"tab","aria-selected":z,class:"mono cursor-pointer",style:{border:0,background:"none",padding:0,fontSize:"12px",fontWeight:z?600:400,color:z?"var(--ink)":"var(--ink-3)"},onClick:()=>c(S),children:S}),z&&S!=="SKILL.md"&&n("button",{type:"button","aria-label":`Delete ${S}`,class:"grid place-items-center cursor-pointer text-ink3 hover:text-red",style:{border:0,background:"none",padding:0},onClick:()=>A(S),children:n("span",{class:"i-lucide-x",style:{width:"12px",height:"12px"}})})]},S)}),n("span",{class:"flex-1"}),n("button",{type:"button",class:"cursor-pointer transition-all duration-180 ease-spring hover:-translate-y-px",style:{padding:"5px 10px",borderRadius:"9px",border:"1px solid var(--hair)",background:"var(--card)",color:"var(--blue)",fontSize:"12px",fontWeight:500},onClick:R,disabled:!l,children:"+ Reference"})]}),n("div",{class:"flex-1 min-h-0",style:{padding:"12px 20px 20px"},children:p?n("p",{style:{padding:"24px 0",textAlign:"center",fontSize:"13px",color:"var(--ink-2)"},children:"Loading skill…"}):l?n("textarea",{class:"field mono w-full h-full","aria-label":h,spellcheck:!1,style:{height:"100%",padding:"14px 16px",borderRadius:"14px",border:"1px solid var(--hair)",background:"var(--card)",color:"var(--ink)",fontSize:"12.5px",lineHeight:1.7,resize:"none",outline:"none",boxShadow:"var(--shadow-s)",minHeight:"240px"},value:h==="SKILL.md"?m:g[h]??"",onInput:S=>{const z=S.target.value;h==="SKILL.md"?k(z):b(_=>({..._,[h]:z}))}}):n("p",{style:{padding:"24px 0",textAlign:"center",fontSize:"13px",color:"var(--ink-2)"},children:"Skill not found."})})]})},xs=({query:e,accounts:t,projects:r,onInstalled:o})=>{const[i,a]=w(null),[l,s]=w(null),[p,d]=w(()=>ei(t));F(()=>{let c=!1;return a(null),fetch(`/api/skills/explore?q=${encodeURIComponent(e)}`).then(m=>{if(!m.ok)throw new Error("search failed");return m.json()}).then(m=>{c||a(m.results)}).catch(()=>{c||(a([]),P("Failed to search skills","error"))}),()=>{c=!0}},[e]);const h=async c=>{s(c.slug);try{const k=await(await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({repo:c.repo,skill:c.skillId,...p})})).json();k.ok?(P(`Installed in ${it(p)}`,"success"),o()):P(k.error??"Failed to install","error")}catch{P("Failed to install","error")}finally{s(null)}};return n(Z,{children:[n(je,{title:`skills.sh · “${e}”`,sub:`Installs into ${it(p)}`}),n("div",{class:"flex-1 min-h-0 overflow-auto flex flex-col",style:{padding:"14px 20px 20px",gap:"8px"},children:[n("div",{class:"flex flex-col",style:{gap:"10px",maxWidth:"560px",marginBottom:"6px"},children:n(ti,{accounts:t,projects:r,value:p,onChange:d})}),i===null&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:"Searching…"}),(i==null?void 0:i.length)===0&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:"No results on skills.sh."}),i==null?void 0:i.map((c,m)=>n("div",{class:"flex items-center",style:{gap:"12px",padding:"11px 15px",borderRadius:"13px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",animation:`riseIn .3s var(--ease) ${Math.min(m,8)*40}ms both`},children:[n("div",{class:"flex-1 min-w-0",children:[n("div",{class:"truncate",style:{fontSize:"13.5px",fontWeight:600},children:c.name}),n("div",{class:"mono truncate",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:[c.repo," · ",c.installs," installs"]})]}),n(D,{label:l===c.slug?"Installing…":"Install",variant:"secondary",size:"sm",loading:l===c.slug,disabled:!En(p),onClick:()=>h(c)})]},c.slug))]})]})},gs=({accounts:e,projects:t,onCreated:r,onCreateWithAI:o})=>{const[i,a]=w(()=>ei(e)),[l,s]=w(""),[p,d]=w(""),[h,c]=w(!1),{scope:m,scopeRef:k}=i,g=async()=>{if(!l.trim())return;c(!0);const b=`---
21
+ name: ${l.trim()}
22
+ description: ${p.trim()}
23
+ domain: general
24
+ ---
25
+
26
+ # ${l.trim()}
27
+
28
+ ${p.trim()}
29
+ `;try{const u=await(await fetch("/api/skills",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scope:m,scopeRef:k,name:l.trim(),content:b})})).json();u.ok?(P("Skill created","success"),r()):P(u.error??"Failed to create skill","error")}catch{P("Failed to create skill","error")}finally{c(!1)}};return n(Z,{children:[n(je,{title:"New skill",sub:"Write it yourself or let an agent draft it with skill-creator"}),n("div",{class:"flex-1 min-h-0 overflow-auto",children:n("div",{class:"flex flex-col",style:{padding:"16px 20px 24px",gap:"14px",maxWidth:"560px"},children:[n(ti,{accounts:e,projects:Object.keys(t),value:i,onChange:a}),n(ee,{label:"Name",children:n("input",{class:"field",value:l,placeholder:"my-skill",onInput:b=>s(b.target.value)})}),n(ee,{label:"Description",children:n("textarea",{class:"field",rows:3,value:p,placeholder:"What does this skill do?",onInput:b=>d(b.target.value)})}),n("div",{class:"flex flex-wrap",style:{gap:"8px"},children:[n(D,{label:h?"Creating…":"Create",variant:"primary",loading:h,disabled:!l.trim()||!En(i),onClick:g}),o&&n(D,{label:"Create with AI",variant:"secondary",disabled:!p.trim()||!En(i),title:"Starts a session that drafts the skill",onClick:()=>o(m,k,p.trim())})]})]})})]})},ms=({accounts:e,projects:t,onCreateWithAI:r,onRunSkill:o,onProposeSkill:i})=>{const[a,l]=w(""),[s,p]=w({kind:"empty"}),[d,h]=w(ot.value===null),c=Object.keys(t),m=Y(async()=>{try{await Promise.all([go(),Xn()])}catch{P("Failed to load skills","error")}finally{h(!1)}},[]);F(()=>{(ot.value===null||Bt.value===null)&&m()},[m]);const k=ot.value??[],g=a.trim().toLowerCase(),b=g?k.filter(v=>v.name.toLowerCase().includes(g)||v.description.toLowerCase().includes(g)):k,f=Bt.value??[],u=s.kind==="plugin"||s.kind==="propose"?f.find(v=>v.id===s.id):void 0;F(()=>{s.kind==="empty"&&k.length>0&&p({kind:"editor",skill:k[0]})},[k.length]);const x=s.kind==="editor"?bt(s.skill):null;return n("main",{class:"skills-page grid min-w-0",style:{gridTemplateColumns:"292px minmax(0,1fr)",height:"100vh"},children:[n("div",{class:"skills-rail flex flex-col min-h-0 overflow-hidden",style:{borderRight:"1px solid var(--hair)",background:"var(--bg-2)"},children:[n("div",{class:"flex flex-col shrink-0",style:{padding:"12px 14px",borderBottom:"1px solid var(--hair)",gap:"10px"},children:[n("div",{class:"flex items-center",style:{gap:"10px"},children:[n(Zn,{}),n("h1",{style:{fontSize:"18px",fontWeight:700,letterSpacing:"-0.02em"},children:"Skills"}),n("span",{class:"mono",style:{fontSize:"11px",color:"var(--ink-3)"},children:k.length}),n("span",{class:"flex-1"}),n(D,{label:"New",variant:"primary",size:"sm",onClick:()=>p({kind:"create"})})]}),n("input",{class:"field",type:"search","aria-label":"Search skills",style:{height:"32px",padding:"0 11px",borderRadius:"9px",border:"1px solid var(--hair)",background:"var(--card)",color:"var(--ink)",fontSize:"13px",outline:"none"},placeholder:"Search installed or skills.sh",value:a,onInput:v=>l(v.target.value),onKeyDown:v=>{v.key==="Enter"&&a.trim()&&p({kind:"explore",query:a.trim()})}})]}),n("div",{class:"overflow-auto min-h-0",style:{padding:"8px"},children:[d&&n("p",{style:{padding:"12px",fontSize:"12.5px",color:"var(--ink-2)"},children:"Loading skills…"}),!d&&b.length===0&&f.length===0&&n("p",{style:{padding:"12px",fontSize:"12.5px",color:"var(--ink-2)"},children:g?"No installed skill matches.":"No skills yet."}),b.map(v=>{const C=x===bt(v);return n("button",{type:"button","aria-current":C?"true":void 0,class:"block w-full text-left cursor-pointer transition-all duration-180 ease-spring hover:bg-elev",style:{padding:"9px 11px",marginBottom:"4px",borderRadius:"11px",border:`1px solid ${C?"var(--hair)":"transparent"}`,background:C?"var(--card)":"transparent",boxShadow:C?"var(--shadow-s)":"none",color:"var(--ink)"},onClick:()=>p({kind:"editor",skill:v}),children:[n("span",{class:"flex items-center",style:{gap:"8px"},children:[n("span",{class:"shrink-0",style:{width:"7px",height:"7px",borderRadius:"50%",background:`var(${ds[v.scope]})`}}),n("span",{class:"flex-1 min-w-0 truncate",style:{fontSize:"13px",fontWeight:600},children:v.name}),n("span",{class:"truncate",style:{fontSize:"11px",color:"var(--ink-3)",maxWidth:"90px"},children:v.scope==="global"?"global":v.scopeRef})]}),v.description&&n("span",{class:"block truncate",style:{fontSize:"12px",color:"var(--ink-2)",marginTop:"2px"},children:v.description})]},bt(v))}),n(rs,{list:f,query:g,selected:s.kind==="plugin"||s.kind==="propose"?s.id:null,onSelect:v=>p({kind:"plugin",id:v})}),!g&&n("button",{type:"button","aria-current":s.kind==="plugins"?"true":void 0,class:"flex items-center w-full text-left cursor-pointer hover:bg-elev",style:{gap:"8px",padding:"9px 11px",marginTop:"6px",borderRadius:"11px",border:"1px dashed var(--hair-2)",background:"transparent",color:"var(--blue)",fontSize:"12.5px",fontWeight:500},onClick:()=>p({kind:"plugins"}),children:[n("span",{class:"i-lucide-plus shrink-0",style:{width:"13px",height:"13px"}}),n("span",{class:"truncate",children:"Add a plugin"})]}),g&&n("button",{type:"button",class:"flex items-center w-full text-left cursor-pointer hover:bg-elev",style:{gap:"8px",padding:"9px 11px",borderRadius:"11px",border:"1px dashed var(--hair-2)",background:"transparent",color:"var(--blue)",fontSize:"12.5px",fontWeight:500},onClick:()=>p({kind:"explore",query:a.trim()}),children:[n("span",{class:"i-lucide-search shrink-0",style:{width:"13px",height:"13px"}}),n("span",{class:"truncate",children:["Search skills.sh for “",a.trim(),"”"]})]})]})]}),n("div",{class:"flex flex-col min-h-0 min-w-0",children:[s.kind==="editor"&&n(vs,{skill:s.skill,accounts:e,projects:c,onCopied:()=>{m()},onRun:()=>o(s.skill),onDeleted:()=>{p({kind:"empty"}),m()}},bt(s.skill)),s.kind==="create"&&n(gs,{accounts:e,projects:t,onCreateWithAI:r,onCreated:()=>{p({kind:"empty"}),m()}}),s.kind==="explore"&&n(xs,{query:s.query,accounts:e,projects:c,onInstalled:()=>{m()}}),s.kind==="plugins"&&n(ls,{accounts:e}),s.kind==="plugin"&&u&&!s.skill&&n(ss,{plugin:u,accounts:e,query:g,onSelectSkill:v=>p({kind:"plugin",id:u.id,skill:v}),onPropose:()=>p({kind:"propose",id:u.id})}),s.kind==="plugin"&&u&&s.skill&&n(as,{plugin:u,name:s.skill,onBack:()=>p({kind:"plugin",id:u.id})},s.skill),s.kind==="propose"&&u&&n(cs,{plugin:u,accounts:e,onCancel:()=>p({kind:"plugin",id:u.id}),onSubmit:async(v,C,y)=>{await i(u,v,C,y)&&p({kind:"plugin",id:u.id})}}),s.kind==="empty"&&!d&&n("div",{class:"flex-1 grid place-items-center",style:{padding:"24px"},children:n("div",{class:"flex flex-col items-center text-center",style:{gap:"12px"},children:[n("p",{style:{fontSize:"13.5px",color:"var(--ink-2)"},children:"Pick a skill to edit it, or write a new one."}),n(D,{label:"New skill",variant:"primary",onClick:()=>p({kind:"create"})})]})})]})]})},un={borderRadius:"16px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-m)"},hn={padding:"10px 14px",borderRadius:"12px",fontSize:"12.5px"},kt=e=>e.target.value,ys=({accounts:e,onOpenSession:t,onFramesChanged:r})=>{const[o,i]=w(null),[a,l]=w(null),[s,p]=w(""),[d,h]=w(""),[c,m]=w(""),[k,g]=w(null),[b,f]=w(""),u=Y(async()=>{try{const S=await(await fetch("/api/liveframe/frames")).json();l(S),r(S.length)}catch{l([])}},[r]);F(()=>{u(),fetch("/api/liveframe/status").then(S=>S.json()).then(i).catch(()=>{})},[u]);const x=async S=>{if(o)try{const z=await Xe("/api/cw/start",{type:"general",account:o.account,directory:S.dir,task:`Liveframe: ${S.project}/${S.frame}`});t(z.session)}catch(z){P(Rt(z),"error")}},v=async(S,z)=>{try{const _=await S;return P(z,"success"),u(),await x(_),!0}catch(_){return P(Rt(_),"error"),!1}},C=async()=>{await v(Xe("/api/liveframe/frames",{project:s,name:d}),`Frame "${d}" created`)&&h("")},y=async()=>{await v(Xe("/api/liveframe/pull",{target:c}),`Pulled ${c}`)&&m("")},R=async()=>{if(k)try{const{url:S}=await Xe(`/api/liveframe/frames/${k.project}/${k.frame}/push`,{note:b});P(`Published: ${S}`,"success"),g(null)}catch(S){P(Rt(S),"error")}},A=o!==null&&!e.includes(o.account),L=(o==null?void 0:o.installed)!==!1&&!A,I=(a??[]).reduce((S,z)=>{var _;return(S[_=z.project]??(S[_]=[])).push(z),S},{});return n(Z,{children:[n(Qn,{title:"Prototypes",subtitle:o?`Liveframe frames in ${o.root} · agents run on ${o.account}`:"Liveframe frames",children:[o&&n("a",{class:Fe,style:Re,href:o.api,target:"_blank",rel:"noopener noreferrer",children:["Liveframe gallery ",n("span",{class:"i-lucide-external-link",style:{width:"12px",height:"12px"}})]}),n(D,{label:"Refresh",variant:"secondary",onClick:u})]}),n("div",{class:"flex flex-col w-full",style:{padding:"18px 22px 40px",gap:"14px",maxWidth:"1180px"},children:[o&&!o.installed&&n("p",{style:{...hn,background:se("--red")},children:["The Liveframe CLI is not installed. Run ",n("code",{children:["npm i -g ",o.api,"/cli.tgz"]}),", then ",n("code",{children:"lf login"}),"."]}),A&&n("p",{style:{...hn,background:se("--red")},children:["Liveframe agents run on the CW account ",n("code",{children:o==null?void 0:o.account}),", which does not exist here. Add it in Accounts or set ",n("code",{children:"FORGE_LIVEFRAME_ACCOUNT"}),"."]}),(o==null?void 0:o.installed)&&!o.signedIn&&n("p",{style:{...hn,background:se("--orange")},children:["Liveframe is not signed in on this machine. Run ",n("code",{children:"lf login"})," in a terminal."]}),n("section",{class:"grid",style:{gridTemplateColumns:"repeat(auto-fit, minmax(300px, 1fr))",gap:"14px"},children:[n("div",{class:"flex flex-col",style:{...un,padding:"16px 18px",gap:"12px"},children:[n("div",{children:[n("h2",{style:{fontSize:"14.5px",fontWeight:600},children:"New prototype"}),n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:["Scaffolds a frame with ",n("code",{children:"lf new"})," and opens an agent in it. The frame's CLAUDE.md teaches the agent Liveframe's conventions and ",n("code",{children:"lf push"}),"."]})]}),n(ee,{label:"Liveframe project · created if missing",children:n("input",{type:"text",class:"field",value:s,placeholder:"Reservas",onInput:S=>p(kt(S))})}),n(ee,{label:"Frame name",children:n("input",{type:"text",class:"field",value:d,placeholder:"Checkout ideas",onInput:S=>h(kt(S))})}),n("div",{class:"flex justify-end",children:n(D,{label:"Create and open agent",variant:"primary",size:"sm",disabled:!L||!s.trim()||!d.trim(),onClick:C})})]}),n("div",{class:"flex flex-col",style:{...un,padding:"16px 18px",gap:"12px"},children:[n("div",{children:[n("h2",{style:{fontSize:"14.5px",fontWeight:600},children:"Continue a frame"}),n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:["Pulls an existing frame's latest source with ",n("code",{children:"lf pull"})," and opens an agent in it."]})]}),n(ee,{label:"project/frame",children:n("input",{type:"text",class:"field",value:c,placeholder:"reservas/checkout-flow",onInput:S=>m(kt(S))})}),n("div",{class:"flex justify-end",children:n(D,{label:"Pull and open agent",variant:"secondary",size:"sm",disabled:!L||!c.includes("/"),onClick:y})})]})]}),a&&a.length===0&&n(no,{icon:"i-lucide-frame",title:"No frames yet",description:"Frames you create or pull here live on this machine, one folder per frame."}),Object.entries(I).map(([S,z])=>n("section",{style:{...un,overflow:"hidden"},children:[n("h2",{style:{padding:"12px 18px",fontSize:"13px",fontWeight:600,borderBottom:"1px solid var(--hair)"},children:S}),z.map(_=>n("div",{class:"flex items-center flex-wrap",style:{gap:"10px",padding:"12px 18px",borderBottom:"1px solid var(--hair)"},children:[n("div",{class:"min-w-0",style:{flex:"1 1 220px"},children:[n("p",{class:"truncate",style:{fontSize:"13.5px",fontWeight:500},children:_.frame}),n("p",{class:"truncate",style:{fontSize:"12px",color:"var(--ink-3)"},children:[_.kind," · ",_.branch," · ",_.dir]})]}),n("a",{class:Fe,style:Re,href:_.url,target:"_blank",rel:"noopener noreferrer",children:["Live ",n("span",{class:"i-lucide-external-link",style:{width:"12px",height:"12px"}})]}),n(D,{label:"Push",variant:"secondary",size:"sm",disabled:!L,onClick:()=>{f(""),g(_)}}),n(D,{label:"Open agent",variant:"primary",size:"sm",disabled:!o||A,onClick:()=>x(_)})]},_.dir))]},S))]}),n(Bn,{open:k!==null,title:`Push ${k==null?void 0:k.project}/${k==null?void 0:k.frame}`,onClose:()=>g(null),children:n("div",{class:"space-y-4",children:[n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:["Builds the frame and deploys it as a new version with ",n("code",{children:"lf push"}),"."]}),n(ee,{label:"What changed · optional",children:n("input",{type:"text",class:"field",value:b,placeholder:"wallet-first layout",onInput:S=>f(kt(S))})}),n("div",{class:"flex justify-end pt-1",children:n(D,{label:"Push",variant:"primary",onClick:R})})]})})]})},zr=({value:e,onChange:t,initialPath:r,requireGit:o=!0})=>{const[i,a]=w(r??"~"),[l,s]=w(i),[p,d]=w([]),[h,c]=w(null),[m,k]=w(null),[g,b]=w(""),[f,u]=w(!1),[x,v]=w(!1),[C,y]=w(null);F(()=>{let O=!1;return(async()=>{v(!0),y(null);try{const H=await(await fetch(`/api/cw/browse-dirs?path=${encodeURIComponent(i)}`)).json();if(O)return;if(!H.ok){y(H.error??"Failed to load directory"),d([]);return}d(H.entries??[]),c(H.parent??null),k(H.home??null),b(H.path??i),u(!!H.isGitRepo)}catch{O||(y("Network error"),d([]))}finally{O||v(!1)}})(),()=>{O=!0}},[i]);const R=O=>{a(O),s(O)},A=e===g,L=o&&!f,I=g?m&&g===m?"~":m&&g.startsWith(m+"/")?"~"+g.slice(m.length):g:i,S={width:"24px",height:"24px",borderRadius:"7px",border:0,background:"var(--card)",color:"var(--ink-2)",boxShadow:"var(--shadow-s)"},z="flex items-center w-full text-left cursor-pointer transition-colors duration-140 hover:bg-elev disabled:cursor-not-allowed disabled:opacity-60",_={gap:"8px",padding:"7px 11px",border:0,borderBottom:"1px solid var(--hair)",background:"none",color:"var(--ink)",fontSize:"12.5px"},N={padding:"1px 7px",borderRadius:"99px",background:se("--green"),color:"var(--green)",fontSize:"10.5px",fontWeight:600};return n("div",{style:{borderRadius:"12px",border:"1px solid var(--hair)",background:"var(--card)",boxShadow:"var(--shadow-s)",overflow:"hidden"},children:[n("div",{class:"flex items-center",style:{gap:"6px",padding:"7px 9px",borderBottom:"1px solid var(--hair)",background:"var(--elev)"},children:[n("button",{type:"button",class:"grid place-items-center cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:S,onClick:()=>h&&R(h),disabled:!h||x,title:"Parent folder","aria-label":"Parent folder",children:"←"}),n("button",{type:"button",class:"grid place-items-center cursor-pointer",style:S,onClick:()=>R("~"),title:"Home","aria-label":"Home",children:"~"}),n("input",{type:"text",value:l,"aria-label":"Path",onInput:O=>s(O.target.value),onBlur:()=>a(l),onKeyDown:O=>{O.key==="Enter"&&a(l)},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&&n("div",{class:"flex items-center",style:{gap:"8px",padding:"7px 11px",borderBottom:"1px solid var(--hair)",background:se("--blue",12),fontSize:"12px"},children:[n("span",{class:"i-lucide-check shrink-0",style:{width:"13px",height:"13px",color:"var(--blue)"}}),n("span",{class:"mono flex-1 truncate",children:e}),n("button",{type:"button",class:"grid place-items-center cursor-pointer text-ink3 hover:text-ink",style:{border:0,background:"none"},onClick:()=>t("",!1),title:"Clear selection","aria-label":"Clear selection",children:n("span",{class:"i-lucide-x",style:{width:"13px",height:"13px"}})})]}),n("div",{class:"overflow-y-auto",style:{maxHeight:"220px"},children:x?n("p",{style:{padding:"12px",fontSize:"12.5px",color:"var(--ink-2)"},children:"Loading…"}):C?n("p",{style:{padding:"12px",fontSize:"12.5px",color:"var(--red)"},children:C}):n(Z,{children:[n("button",{type:"button",class:z,style:{..._,background:A?"var(--elev)":"none",fontWeight:600},onClick:()=>t(g,f),disabled:L,title:L?"Not a git repository":"Pick this folder",children:[n("span",{class:"i-lucide-check shrink-0",style:{width:"12px",height:"12px",color:"var(--blue)"}}),n("span",{class:"flex-1 truncate",children:["Pick ",n("span",{class:"mono",children:I})]}),f?n("span",{style:N,children:"git"}):L?n("span",{style:{fontSize:"11px",color:"var(--ink-3)"},children:"no .git"}):null]}),p.length===0?n("p",{style:{padding:"12px",fontSize:"12.5px",color:"var(--ink-3)"},children:"No subfolders"}):p.map(O=>n("button",{type:"button",class:z,style:_,onClick:()=>R(O.path),children:[n("span",{class:"i-lucide-chevron-right shrink-0",style:{width:"12px",height:"12px",color:"var(--ink-3)"}}),n("span",{class:"mono flex-1 truncate",children:O.name}),O.isGitRepo&&n("span",{style:N,children:"git"})]},O.path))]})})]})},bs=({open:e,accounts:t,onClose:r,onCreated:o})=>{const[i,a]=w("create"),[l,s]=w(""),[p,d]=w(""),[h,c]=w(""),[m,k]=w(""),[g,b]=w(""),[f,u]=w(""),[x,v]=w(!1),[C,y]=w(""),[R,A]=w(!1);F(()=>{e&&t.length>0&&!l&&s(t[0])},[e,t]),F(()=>{e||(a("create"),d(""),c(""),k(""),b(""),u(""),v(!1),y(""),A(!1))},[e]);const L=l.trim().length>0&&p.trim().length>0&&m.trim().length>0,I=l.trim().length>0&&f.length>0&&x,S=async()=>{if(L){A(!0);try{const B=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"create",project:p.trim(),task:p.trim(),description:m.trim(),account:l.trim()||void 0,directory:h.trim()||void 0,model:g||void 0})})).json();B.ok?(P("Project creation started in terminal","success"),o(B.session)):P(B.error??"Failed to create project","error")}catch{P("Failed to create project","error")}finally{A(!1)}}},z=async()=>{if(I){A(!0);try{const B=await(await fetch("/api/cw/register-project",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:f,account:l.trim(),alias:C.trim()||void 0})})).json();B.ok?(P(`Project "${B.project}" registered`,"success"),o()):P(B.error??"Failed to register project","error")}catch{P("Failed to register project","error")}finally{A(!1)}}},_=i==="create";return n(Bn,{open:e,title:"Add a project",onClose:r,footer:n(Z,{children:[n("span",{class:"mono flex-1 truncate",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:_?"cw create":"cw project register"}),n(D,{label:"Cancel",variant:"secondary",onClick:r}),n(D,{label:_?R?"Creating…":"Create":R?"Registering…":"Register",variant:"primary",loading:R,disabled:!(_?L:I),onClick:_?S:z})]}),children:n("div",{class:"flex flex-col",style:{gap:"13px"},children:[n(ve,{fill:!0,label:"Mode",tabs:[{id:"create",label:"Create new"},{id:"existing",label:"Register existing"}],active:i,onChange:E=>a(E)}),n("div",{class:"grid",style:{gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:"10px"},children:[n(ee,{label:"Account",children:t.length>0?n("select",{class:"field",value:l,onChange:E=>s(E.target.value),children:t.map(E=>n("option",{value:E,children:E},E))}):n("input",{type:"text",class:"field",value:l,placeholder:"account-name",onInput:E=>s(E.target.value)})}),_?n(ee,{label:"Project name",children:n("input",{type:"text",class:"field",value:p,placeholder:"my-new-project",onInput:E=>d(E.target.value)})}):n(ee,{label:"Alias",children:n("input",{type:"text",class:"field",value:C,placeholder:"defaults to folder name",onInput:E=>y(E.target.value)})})]}),n("div",{class:"flex flex-col",style:{gap:"5px"},children:[n("span",{style:Me,children:_?"Parent folder · optional":"Repository · must contain .git"}),_?n(zr,{value:h,onChange:c,requireGit:!1},"dir-create"):n(zr,{value:f,onChange:(E,B)=>{u(E),v(B)}},"dir-existing")]}),_&&n(Z,{children:[n(ee,{label:"Description",children:n("textarea",{rows:2,class:"field",value:m,placeholder:"A SaaS platform for…",onInput:E=>k(E.target.value)})}),n("div",{class:"flex flex-col",style:{gap:"5px"},children:[n("span",{style:Me,children:"Model"}),n(ve,{size:"sm",label:"Model",tabs:[{id:"",label:"Auto"},{id:"haiku",label:"Haiku"},{id:"sonnet",label:"Sonnet"},{id:"opus",label:"Opus"}],active:g,onChange:b})]})]})]})})},ks=(e,t)=>{if(t)return{kind:"connecting"};const r=typeof e.detail=="string"?e.detail:"",o=[e.provider,e.model].filter(Boolean).join(" · ");if(e.status==="not_installed")return{kind:"not_installed",detail:r};if(e.status==="error")return{kind:"error",detail:r};if(e.status==="local"){const i=e.detail&&typeof e.detail=="object"?e.detail:null;return{kind:"local",providerModel:o,reachable:(i==null?void 0:i.reachable)??null,pulled:(i==null?void 0:i.model_pulled)??null}}return e.status==="connected"&&(e.provider_kind==="api"||e.has_api_key)?{kind:"api_key",providerModel:e.provider!=="native"?o:null}:e.status==="connected"?{kind:"connected"}:{kind:"connect"}},ws=(e,t,r,o)=>{const i=[];switch(e.kind){case"connecting":i.push("Waiting for the login to finish");break;case"not_installed":i.push(e.detail||"Not on PATH");break;case"error":i.push(e.detail||"cw doctor reported an error");break;case"local":{const a=[e.reachable===null?null:e.reachable?"reachable":"unreachable",e.pulled===null?null:e.pulled?"model pulled":"model not pulled"].filter(Boolean).join(", ");i.push(...[e.providerModel,a].filter(Boolean));break}case"api_key":i.push(...[e.providerModel,"stored by cw"].filter(a=>!!a));break;case"connected":i.push(...[o.model,t].filter(a=>!!a)),i.length===0&&i.push("Signed in");break;case"connect":i.push(r?"Not logged in — device code, no terminal needed":"Not logged in");break}return o.unofficial&&i.push("unofficial"),i.join(" · ")},Le=({token:e,label:t})=>n("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?se(e):"var(--elev)",color:e?`var(${e})`:"var(--ink-3)"},children:[n("span",{style:{width:"6px",height:"6px",borderRadius:"50%",background:"currentColor"}}),t]}),_s=({view:e,onConnect:t,onCancel:r})=>{switch(e.kind){case"connecting":return n("span",{class:"inline-flex items-center shrink-0",style:{gap:"8px"},children:[n(Le,{token:"--blue",label:"Connecting…"}),n("button",{type:"button",class:"cursor-pointer hover:text-ink",style:{border:0,background:"none",color:"var(--ink-2)",fontSize:"12px"},onClick:r,children:"Cancel"})]});case"not_installed":return n(Le,{token:null,label:"Not installed"});case"error":return n(Le,{token:"--red",label:"Error"});case"local":return n(Le,{token:"--orange",label:"Local"});case"api_key":return n(Le,{token:"--green",label:"API key"});case"connected":return n(Le,{token:"--green",label:"Connected"});case"connect":return n(D,{label:"Connect",size:"sm",onClick:t})}},fn=({children:e})=>n("div",{class:"flex",style:{padding:"0 15px 11px"},children:[n("span",{class:"shrink-0",style:{width:"144px"}}),n("span",{class:"flex flex-col flex-1",style:{gap:"5px",minWidth:0},children:e})]}),vn=({warn:e,children:t})=>n("span",{style:{fontSize:"11.5px",color:e?"var(--orange)":"var(--ink-3)"},children:t}),Ss=({account:e,harness:t})=>{const r=na(e,t);return!r||r.state==="not_connected"?null:r.state==="expired"?n(fn,{children:n(vn,{warn:!0,children:"Reconnect to see usage limits"})}):r.state==="error"?n(fn,{children:n(vn,{children:["Limits unavailable — ",r.detail??"the request failed"]})}):r.windows.length===0?null:n(fn,{children:[n(oo,{bars:ho(r.windows)}),r.stale&&n(vn,{children:["Last known values — ",r.detail??"the refresh failed"]})]})},Cs=3e3,$s=({account:e,harness:t,canUseApiKey:r,onConnected:o,onClose:i})=>{const[a,l]=w(null),[s,p]=w(!1),[d,h]=w(0),[c,m]=w(""),[k,g]=w(!1),b=fe(t).label,f=`/api/cw/accounts/${encodeURIComponent(e)}`,u=`${f}/login/${encodeURIComponent(t)}`,x=X(!1),v=X(!1);F(()=>{let A=!1,L=null;l(null),p(!1),x.current=!1,v.current=!1;const I=()=>{x.current||(x.current=!0,fetch(u,{method:"DELETE"}).catch(()=>{}),P(`${e} is connected to ${b}`,"success"),o())},S=async()=>{var E;const _=await fetch(u).catch(()=>null);if(!(_!=null&&_.ok)||A)return;const{login:N}=await _.json();if(l(N),N.status!=="exited"||(v.current=!0,L&&(clearInterval(L),L=null),N.exitCode!==0))return;p(!0);const O=await ge(!0);A||(O.available&&((E=Ce(O.doctor,e,t))==null?void 0:E.status)==="connected"?I():p(!1))};fetch(`${f}/login`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({harness:t})}).then(_=>_.json()).then(_=>{if(!A){if(!_.ok||!_.login){P(_.error??"Could not start the login","error");return}l(_.login),L=setInterval(S,Cs)}}).catch(()=>P("Could not start the login","error"));const z=Ki(_=>{var N;return((N=Ce(_,e,t))==null?void 0:N.status)==="connected"},{onDone:_=>{_&&I()}});return()=>{A=!0,L&&clearInterval(L),z(),v.current||fetch(u,{method:"DELETE"}).catch(()=>{})}},[e,t,d]);const C=()=>{fetch(u,{method:"DELETE"}).catch(()=>{}),i()},y=async()=>{const A=c.trim();if(A){g(!0);try{const I=await(await fetch(`${f}/api-key`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({harness:t,apiKey:A})})).json();I.ok?(m(""),P("API key saved","success"),ge(!0)):P(I.error??"Could not save the API key","error")}catch{P("Could not save the API key","error")}finally{g(!1)}}},R=(a==null?void 0:a.status)==="exited";return n("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:[n("div",{class:"flex items-center",style:{gap:"10px"},children:[n("h3",{style:{fontSize:"14px",fontWeight:650},children:["Connect ",e," on ",b]}),n("span",{class:"flex-1"}),n(D,{label:"Cancel",variant:"secondary",size:"sm",onClick:C})]}),!a&&n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:"Starting the login…"}),a&&!R&&n(Z,{children:[n("div",{class:"flex flex-wrap items-center",style:{gap:"12px"},children:[a.url&&n("a",{href:a.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 ",n("span",{class:"i-lucide-external-link",style:{width:"12px",height:"12px"}})]}),a.code&&n(Z,{children:[n("span",{class:"mono",style:{fontSize:"19px",fontWeight:650,letterSpacing:".12em"},children:a.code}),n(D,{label:"Copy",variant:"secondary",size:"sm",onClick:()=>Gn(a.code??"","Code")})]})]}),a.code&&n("p",{style:{fontSize:"12px",color:"var(--ink-3)"},children:"If the code is rejected, use the one shown in Output."}),n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:a.url||a.code?"Checks every 3 s. The status turns Connected on its own.":"Waiting for the login URL…"})]}),R&&s&&n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:"Checking the connection…"}),R&&!s&&n("div",{class:"flex items-center",style:{gap:"10px",fontSize:"12.5px"},children:[n("span",{style:{color:"var(--red)"},children:"The login ended before connecting."}),n(D,{label:"Retry",variant:"secondary",size:"sm",onClick:()=>h(A=>A+1)})]}),a&&a.output.length>0&&n("details",{style:{fontSize:"12.5px"},children:[n("summary",{class:"cursor-pointer",style:{color:"var(--ink-2)"},children:"Output"}),n("pre",{class:"overflow-x-auto",style:{marginTop:"8px",padding:"10px 12px",borderRadius:"11px",background:"var(--term)",color:"#e3e3e8",fontSize:"11.5px"},children:a.output.join(`
30
+ `)})]}),r&&n("div",{class:"flex flex-col",style:{gap:"8px",paddingTop:"12px",borderTop:"1px solid var(--hair)"},children:[n("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--ink-3)"},children:"Or with an API key"}),n("div",{class:"flex items-center",style:{gap:"8px"},children:[n("input",{type:"password",autocomplete:"off","aria-label":"API key",value:c,onInput:A=>m(A.target.value),placeholder:"sk-…",class:"field mono flex-1 min-w-0"}),n(D,{label:"Save",variant:"secondary",size:"sm",loading:k,disabled:!c.trim(),onClick:y})]}),n("p",{style:{fontSize:"12px",color:"var(--ink-3)"},children:"Sent to cw over stdin. Forge never stores or shows it."})]})]})},wt={display:"block",fontSize:"12px",color:"var(--ink-2)",marginBottom:"5px"},Ts=({response:e,onCancel:t,onCreated:r})=>{const[o,i]=w(""),[a,l]=w(""),[s,p]=w(""),[d,h]=w(""),[c,m]=w(!1),k=Gt(),g=o.trim(),b=Mi.test(g),f=e!=null&&e.available?e.doctor.harnesses.map(v=>v.name).filter(v=>v!=="claude"):[],u=!!a&&Ee(e,a,"custom_provider"),x=async()=>{if(!(!b||c)){m(!0);try{const C=await(await fetch("/api/cw/accounts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:g,harness:a||void 0,provider:u&&s.trim()||void 0,model:u&&d.trim()||void 0})})).json();C.ok?(P(`Account "${g}" created`,"success"),r()):P(C.error??"Failed to create account","error")}catch{P("Failed to create account","error")}finally{m(!1)}}};return n("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:[n("h2",{style:{fontSize:"17px",fontWeight:700,letterSpacing:"-0.02em"},children:"Add an account"}),n("div",{style:{maxWidth:"360px"},children:[n("label",{style:wt,for:"new-account-name",children:"Account name"}),n("input",{id:"new-account-name",type:"text",value:o,onInput:v=>i(v.target.value),onKeyDown:v=>{v.key==="Enter"&&x()},placeholder:"my-account",class:"field",ref:k}),g&&!b&&n("p",{style:{fontSize:"12px",color:"var(--red)",marginTop:"5px"},children:"Must start with a letter or number. Only letters, numbers, hyphens, and underscores allowed."})]}),f.length>0&&n("div",{children:[n("span",{style:wt,children:"Default harness"}),n(ve,{label:"Default harness",tabs:[{id:"",label:"Claude Code"},...f.map(v=>({id:v,label:fe(v).label}))],active:a,onChange:l}),n("p",{style:{fontSize:"12px",color:"var(--ink-3)",marginTop:"5px"},children:"The default harness cannot be changed later."})]}),u&&n("div",{class:"grid",style:{gridTemplateColumns:"1fr 1fr",gap:"10px",maxWidth:"520px"},children:[n("div",{children:[n("label",{style:wt,children:"Provider · optional"}),n("input",{type:"text",value:s,onInput:v=>p(v.target.value),placeholder:"zai, ollama, openrouter",class:"field"})]}),n("div",{children:[n("label",{style:wt,children:"Model · optional"}),n("input",{type:"text",value:d,onInput:v=>h(v.target.value),placeholder:"glm-5.1",class:"field"})]})]}),n("div",{class:"flex",style:{gap:"8px"},children:[n(D,{label:c?"Creating…":"Add account",variant:"primary",loading:c,disabled:!b,onClick:x}),n(D,{label:"Cancel",variant:"secondary",onClick:t})]})]})},Rs=new Set(["localhost","127.0.0.1","::1","[::1]"]),jr={borderRadius:"16px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-m)",overflow:"hidden"},xn={padding:"10px 14px",borderRadius:"12px",fontSize:"12.5px"},zs=({account:e,onRemoved:t})=>{const[r,o]=w(!1),i=async()=>{try{const l=await(await fetch(`/api/cw/accounts/${encodeURIComponent(e)}`,{method:"DELETE"})).json();l.ok?(P(`Account "${e}" removed`,"info"),t()):P(l.error??"Failed to remove account","error")}catch{P("Failed to remove account","error")}finally{o(!1)}};return r?n("span",{class:"flex items-center flex-wrap",style:{gap:"8px"},children:[n("span",{style:{fontSize:"12px",color:"var(--ink-2)"},children:"Deletes the profile and its harness config. Projects stay."}),n(D,{label:"Remove account",variant:"destructive",size:"sm",onClick:i}),n(D,{label:"Cancel",variant:"secondary",size:"sm",onClick:()=>o(!1)})]}):n(D,{label:"Remove",variant:"danger",size:"sm",onClick:()=>o(!0)})},js=({projects:e,onOpenSession:t,onAccountsChanged:r})=>{const[o,i]=w(null),[a,l]=w(!1);F(()=>{ge()},[]),F(()=>So(),[]);const s=We.value,p=!Rs.has(window.location.hostname),d=s!=null&&s.available?s.doctor:null,h=()=>{o&&(fetch(`/api/cw/accounts/${encodeURIComponent(o.account)}/login/${encodeURIComponent(o.harness)}`,{method:"DELETE"}).catch(()=>{}),i(null))},c=async(f,u)=>{if(Ee(s,u,"headless_login")){i({account:f,harness:u});return}try{const v=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"login",account:f,harness:u})})).json();v.ok&&v.session?t(v.session):P(v.error??"Could not open the login","error")}catch{P("Could not open the login","error")}},m=d?d.accounts.reduce((f,u)=>f+u.harnesses.filter(x=>x.status==="not_logged_in").length,0):0,k=d?`${d.accounts.length} account${d.accounts.length===1?"":"s"} · ${d.harnesses.length} harnesses · ${m} need${m===1?"s":""} connecting`:"Reading cw doctor…",g=f=>Object.values(e).filter(u=>u.account===f).length,b=(f,u)=>{if(!d)return null;const[x,v]=so(u),C=g(f.name),y=Ce(d,f.name,f.default_harness),R=[fe(f.default_harness).label,y&&y.provider!=="native"?y.provider:null].filter(Boolean).join(" · ");return n("section",{style:{...jr,animation:`riseIn .36s var(--ease) ${u*90}ms both`},"aria-label":f.name,children:[n("div",{class:"flex items-center flex-wrap",style:{gap:"11px",padding:"12px 15px",borderBottom:"1px solid var(--hair)",background:"var(--elev)"},children:[n("span",{class:"grid place-items-center shrink-0",style:{width:"28px",height:"28px",borderRadius:"9px",background:`linear-gradient(160deg, var(${x}), var(${v}))`,boxShadow:"var(--shadow-s)",color:"#fff",fontSize:"12px",fontWeight:700},children:f.name.charAt(0).toUpperCase()}),n("span",{style:{fontSize:"15px",fontWeight:650,letterSpacing:"-0.01em"},children:f.name}),n("span",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:["Default ",R," · ",C," project",C===1?"":"s"]}),n("span",{class:"flex-1"}),n(zs,{account:f.name,onRemoved:()=>{ge(!0),r()}})]}),d.harnesses.map(A=>{const L=Ce(d,f.name,A.name),I=(o==null?void 0:o.account)===f.name&&o.harness===A.name,S=fe(A.name),z=L?ks(L,I):null;return n("div",{style:{borderBottom:"1px solid var(--hair)"},children:[n("div",{class:"flex items-center flex-wrap",style:{gap:"12px",padding:"11px 15px"},children:[n("span",{class:"inline-flex items-center shrink-0",style:{gap:"6px",width:"132px",fontSize:"13px",fontWeight:600},children:[n("span",{style:{width:"8px",height:"8px",borderRadius:"50%",background:S.color}}),S.label]}),n("span",{class:"flex-1",style:{minWidth:"140px",fontSize:"12.5px",color:"var(--ink-2)"},children:L&&z?ws(z,A.version,Ee(s,A.name,"headless_login"),L):"Not configured for this account"}),z&&n(_s,{view:z,onConnect:()=>{c(f.name,A.name)},onCancel:h})]}),L&&n(Ss,{account:f.name,harness:A.name}),I&&n("div",{style:{padding:"0 15px 13px"},children:n($s,{account:f.name,harness:A.name,canUseApiKey:Ee(s,A.name,"api_key_login"),onConnected:()=>i(null),onClose:()=>i(null)},`${f.name}::${A.name}`)})]},A.name)})]},f.name)};return n(Z,{children:[n(Qn,{title:"Accounts",subtitle:k,children:[n(D,{label:"Refresh",variant:"secondary",onClick:()=>{ge(!0)}}),n(D,{label:"Add account",variant:"primary",onClick:()=>l(!0)})]}),n("div",{class:"flex flex-col w-full",style:{padding:"18px 22px 40px",gap:"14px",maxWidth:"1180px"},children:[a&&n(Ts,{response:s,onCancel:()=>l(!1),onCreated:()=>{l(!1),ge(!0),r()}}),s&&!s.available&&n("section",{style:{...jr,padding:"16px 18px"},children:[n("p",{style:{fontSize:"13.5px",marginBottom:"4px"},children:["Harness status is unavailable: ",s.reason]}),n("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."}),n(D,{label:"Retry",variant:"secondary",size:"sm",onClick:()=>{ge(!0)}})]}),d&&p&&n("p",{style:{...xn,background:se("--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."}),d&&d.issues.map(f=>n("p",{style:{...xn,background:se("--red"),color:"var(--ink)"},children:f.message},f.code)),d&&d.warnings.map(f=>n("p",{style:{...xn,background:"var(--elev)",color:"var(--ink-2)"},children:f.message},f.code)),d==null?void 0:d.accounts.map(b)]})]})},Pr="flex items-center w-full text-left cursor-pointer transition-colors duration-140 hover:bg-elev",Ps=({sessions:e,openTabKeys:t,onOpenSession:r,onNewTask:o,onClose:i,position:a})=>{const l=X(null);F(()=>{const p=h=>{l.current&&!l.current.contains(h.target)&&i()},d=h=>{h.key==="Escape"&&i()};return document.addEventListener("mousedown",p),document.addEventListener("keydown",d),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",d)}},[i]);const s=e.filter(p=>!t.has(K(p)));return n("div",{ref:l,class:"popover fixed z-[60] flex flex-col",style:{top:`${a.top}px`,left:`${a.left}px`,width:"min(320px, calc(100vw - 16px))",maxHeight:"420px",overflowY:"auto",padding:"6px",borderRadius:"14px"},children:[n("div",{style:{padding:"7px 10px 3px",fontSize:"11px",fontWeight:600,color:"var(--ink-3)"},children:"New"}),He.map(p=>n("button",{type:"button",class:Pr,style:{gap:"10px",padding:"7px 10px",borderRadius:"10px",border:0,background:"none",color:"var(--ink)",fontSize:"13px"},onClick:()=>{o(p.key),i()},children:[n(zn,{type:p.sessionType,size:22,radius:7,font:10}),n("span",{class:"flex-1",children:Hn(p.key)})]},p.key)),s.length>0&&n(Z,{children:[n("div",{style:{padding:"9px 10px 3px",fontSize:"11px",fontWeight:600,color:"var(--ink-3)"},children:"Resume"}),s.map(p=>n("button",{type:"button",class:Pr,style:{gap:"10px",padding:"7px 10px",borderRadius:"10px",border:0,background:"none",color:"var(--ink)",fontSize:"13px"},onClick:()=>{r(p),i()},children:[n(zn,{type:p.type,size:22,radius:7,font:10}),n("span",{class:"flex-1 truncate",children:he(p)}),n("span",{class:"mono truncate",style:{fontSize:"10.5px",color:"var(--ink-3)",maxWidth:"110px"},children:ue(p)})]},K(p)))]})]})},Ls=({tabs:e,activeIndex:t,onActivate:r,onClose:o,onBack:i,allSessions:a,openTabKeys:l,onOpenSession:s,onNewTask:p})=>{const[d,h]=w(!1),c=X(null),[m,k]=w({top:0,left:0}),g=Y(()=>h(!1),[]),b=()=>{if(!d&&c.current){const f=c.current.getBoundingClientRect();k({top:f.bottom+6,left:Math.max(8,Math.min(f.left,window.innerWidth-328))})}h(!d)};return n(Z,{children:[n("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:[n(Zn,{}),n(Da,{onClick:i}),e.map((f,u)=>{const x=u===t,v=Te.value[K(f)],C=!x&&Oe(v);return n("div",{role:"tab",tabIndex:0,"aria-selected":x,title:[C?Wt(v):null,u<5?`⌘${u+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:x?"var(--card)":"transparent",border:`1px solid ${x?"var(--hair)":"transparent"}`,boxShadow:x?"var(--shadow-s)":"none"},onClick:()=>r(u),onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.preventDefault(),r(u))},children:[n($e,{size:6,live:f.status==="active",color:C?`var(${$t(v)})`:void 0}),n("span",{style:{fontWeight:600,color:x?"var(--ink)":"var(--ink-2)"},children:he(f)}),n("span",{class:"mono truncate",style:{fontSize:"11px",color:"var(--ink-3)",maxWidth:"110px"},children:ue(f)}),n("button",{type:"button",class:"grid place-items-center cursor-pointer text-ink3 hover:text-red",style:{border:0,background:"none",padding:"0 1px"},onClick:y=>{y.stopPropagation(),o(u)},title:"Close tab (⌘W)","aria-label":`Close ${he(f)}`,children:n("span",{class:"i-lucide-x",style:{width:"13px",height:"13px"}})})]},K(f))}),n("button",{ref:c,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:b,"aria-expanded":d,title:"Open or create a tab","aria-label":"Open or create a tab",children:n("span",{class:"i-lucide-plus",style:{width:"14px",height:"14px"}})})]}),d&&n(Ps,{sessions:a,openTabKeys:l,onOpenSession:s,onNewTask:p,onClose:g,position:m})]})};function As(e,t){switch(e){case"uncommitted":{const r=(t==null?void 0:t.uncommitted)??0;return`${r} file${r===1?" has":"s have"} uncommitted changes. Closing deletes them.`}case"unpushed":{const r=t?dt(t):0;return`${r} commit${r===1?" is":"s are"} not pushed. They stay on ${(t==null?void 0:t.branch)??"the task branch"} on this machine only.`}case"pr-open":return`PR #${(t==null?void 0:t.pr.status)==="found"?t.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 Es=({request:e,onCancel:t,onConfirm:r})=>{if(!e)return null;const o=e.state?e.state.closeWarnings:["state-unknown"],i=o.includes("uncommitted");return n(Bn,{open:!0,title:"Close this task?",onClose:t,footer:n(Z,{children:[n("span",{class:"flex-1"}),n(D,{label:"Cancel",variant:"secondary",onClick:t}),n(D,{label:"Close task",variant:i?"destructive":"primary",onClick:r})]}),width:460,children:[n("ul",{class:"flex flex-col",style:{gap:"8px",fontSize:"13.5px",paddingLeft:"18px"},children:o.map(l=>n("li",{children:As(l,e.state)},l))}),e.error&&n("p",{style:{marginTop:"10px",fontSize:"12.5px",color:"var(--ink-2)"},children:e.error})]})},gn="forge-open-tabs";function Is({spaces:e,loading:t,onFetchData:r}){const[o,i]=w([]),[a,l]=w(0),[s,p]=w(!0),d=X(!1),h=X(o);h.current=o,F(()=>{if(!(t||e.length===0||d.current)){d.current=!0;try{const f=sessionStorage.getItem(gn);if(!f)return;const{keys:u,activeIndex:x}=JSON.parse(f),v=[];for(const C of u){const y=e.find(R=>K(R)===C);y&&v.push(y)}v.length>0&&(i(v),l(Math.min(x,v.length-1)))}catch{}}},[t,e]),F(()=>{if(d.current)if(o.length>0){const f=o.map(K);sessionStorage.setItem(gn,JSON.stringify({keys:f,activeIndex:a}))}else sessionStorage.removeItem(gn)},[o,a]);const c=Y(f=>{const u=K(f),x=o.findIndex(v=>K(v)===u);x>=0?l(x):(i(v=>[...v,f]),l(o.length)),p(!1)},[o]),m=Y(async f=>{const u=h.current.find(y=>K(y)===f);if(!u)return;const x=u.sessionDir??(u.type==="review"?`review-pr-${u.pr}`:`task-${u.task}`);try{await fetch("/api/cw/terminal/kill",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:u.project,sessionDir:x})})}catch{}const v=h.current.findIndex(y=>K(y)===f);if(v<0)return;ea(f);const C=h.current.length-1;i(y=>y.filter(R=>K(R)!==f)),C===0?(p(!0),l(0),r()):l(y=>y>v?y-1:Math.min(y,C-1))},[r]),k=Y(f=>{const u=o[f];return u?m(K(u)):Promise.resolve()},[o,m]),g=Y(()=>{p(!0),r()},[r]);F(()=>{const f=u=>{if(o.length===0||s)return;const x=u.metaKey||u.ctrlKey;if(x&&u.key>="1"&&u.key<="5"){const v=parseInt(u.key)-1;v<o.length&&(u.preventDefault(),l(v));return}if(x&&(u.key==="ArrowLeft"||u.key==="ArrowRight")){u.preventDefault(),l(v=>u.key==="ArrowLeft"?v>0?v-1:o.length-1:v<o.length-1?v+1:0);return}if(x&&u.key==="w"){u.preventDefault(),k(a);return}x&&u.key==="l"&&(u.preventDefault(),g())};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[o,s,a,k,g]);const b=Q(()=>new Set(o.map(K)),[o]);return{openTabs:o,activeTabIndex:a,setActiveTabIndex:l,showList:s,openTab:c,closeTab:k,closeTabByKey:m,goToList:g,openTabKeys:b}}function Ns({spaces:e,accounts:t,projects:r}){const[o,i]=w(null),[a,l]=w(null),[s,p]=w(null),[d,h]=w(null),[c,m]=w(!1),k=Q(()=>Array.from(new Set(e.map(x=>x.harness??"claude"))).sort(),[e]),g=Q(()=>{if(t.length>0)return t;const x=new Set;for(const v of e)v.account&&x.add(v.account);return Array.from(x).sort()},[t,e]),b=Q(()=>{const x=new Set;for(const v of e)o&&v.account!==o||ue(v)&&x.add(v.project);for(const[v,C]of Object.entries(r))o&&C.account!==o||x.add(v);return Array.from(x).sort()},[e,r,o]),f=x=>{if(i(x),x&&a){const v=r[a];v&&v.account!==x&&l(null)}},u=Q(()=>e.filter(x=>!(o&&x.account!==o||a&&x.project!==a||d&&(x.harness??"claude")!==d||s&&x.type!==Oi(s)||!c&&x.status==="done")),[e,o,a,s,d,c]);return{filterAccount:o,setFilterAccount:f,filterProject:a,setFilterProject:l,filterType:s,setFilterType:p,filterHarness:d,setFilterHarness:h,showDone:c,setShowDone:m,accountNames:g,projectNames:b,harnessNames:k,filteredSpaces:u}}function Os(){const[e,t]=w([]),[r,o]=w({}),[i,a]=w([]),[l,s]=w(!0),[p,d]=w("list"),[h,c]=w(!1),[m,k]=w(null),[g,b]=w(!1);F(()=>{ge(),Po(),fetch("/api/liveframe/frames").then($=>$.json()).then($=>k($.length)).catch(()=>{})},[]);const f=Y(async()=>{try{const[$,T,W]=await Promise.all([fetch("/api/cw/spaces"),fetch("/api/cw/projects"),fetch("/api/cw/accounts")]);t(await $.json()),o(await T.json()),a(await W.json()),Sa()}catch{P("Failed to connect to server","error")}finally{s(!1)}},[]),u=Y(()=>{setTimeout(f,500),setTimeout(f,2500)},[f]);F(()=>{f()},[f]);const x=Is({spaces:e,loading:l,onFetchData:f}),v=Ns({spaces:e,accounts:i,projects:r}),C=Object.keys(r).length>0,y=$=>{const T=He.find(W=>W.key===$);T&&(De.value=T.key),c(!0)},[R,A]=w(null),L=Y(async($,T)=>{try{const U=await(await fetch("/api/cw/done",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:$.project,task:$.type==="review"?$.pr:$.task,type:$.type,sessionDir:$.sessionDir})})).json();if(U.ok)P("Task closed","info"),T==null||T(),u();else{const ne=U.error??"cw --done failed";console.error(`[forge] closing ${$.project}/${$.task??$.pr} failed:
31
+ ${ne}`),P(ne.split(`
32
+ `)[0],"error")}}catch{P("Failed to close the task","error")}},[u]),I=Y(async($,T)=>{const W=await Rn($,!0);if(W.state&&W.state.closeWarnings.length===0){await L($,T);return}A({session:$,state:W.state,error:W.error,onClosed:T})},[L]),S=n(Es,{request:R,onCancel:()=>A(null),onConfirm:async()=>{const $=R;if($)try{await L($.session,$.onClosed)}finally{A(null)}}}),z=Y($=>{Se.value=!1,x.showList||x.goToList(),c(!1),d($)},[x.showList,x.goToList]),_=Y(()=>z("list"),[z]),N=Y(()=>c(!1),[]),O=Y($=>{v.setFilterProject(v.filterProject===$?null:$),z("list")},[v.filterProject,v.setFilterProject,z]),E=Y($=>{Se.value=!1,c(!1),x.openTab($)},[x.openTab]),[B,H]=w(!1),M=Y(()=>H(!1),[]),j=Y(()=>H(!0),[]);F(()=>{const $=T=>{const W=T.metaKey||T.ctrlKey,U=T.key.toLowerCase();if(W&&U==="j"){T.preventDefault(),mr();return}if(W&&U==="k"){T.preventDefault(),B?H(!1):j();return}const ne=T.target;ne!=null&&ne.closest('input, textarea, select, [contenteditable="true"]')||W||T.altKey||B||h||g||(T.key==="/"?(T.preventDefault(),j()):U==="n"?(T.preventDefault(),c(!0)):U==="p"&&(T.preventDefault(),b(!0)))};return window.addEventListener("keydown",$),()=>window.removeEventListener("keydown",$)},[B,h,g,j]);const G=Y(async($,T,W,U)=>{try{const re=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"general",account:T,project:W,description:$})})).json();re.ok&&re.session?(E(re.session),u(),P(U,"success")):P(re.error??"Failed to start session","error")}catch{P("Failed to start session","error")}},[E,u]),V=Y(($,T)=>{const W=$==="project"&&r[T]?T:void 0;return{account:$==="account"?T:W?r[W].account:i[0]||"default",project:W}},[i,r]),de=Y(($,T,W)=>{const{account:U,project:ne}=V($,T),re=$==="global"?"~/.claude/skills/":$==="account"?`~/.cw/accounts/${T}/skills/`:`${ne?r[ne].path:"<project>"}/.claude/skills/`,_e=["Use the skill-creator skill to create a new Claude Code skill.","",`The user wants: ${W}`,`Target scope: ${$}${$!=="global"?` (${T})`:""}`,`Save location: ${re}`,"","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(`
33
+ `);G(_e,U,ne,"AI skill creation session started")},[r,V,G]),ae=Y($=>{const{account:T,project:W}=V($.scope,$.scopeRef);G(`Use the ${$.name} skill.`,T,W,`Session started with ${$.name}`)},[V,G]),ce=Y(async($,T,W,U)=>{if(!$.project)return!1;try{const re=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"task",project:$.project,task:ts(T),description:ns($,T,W),account:U,harness:"claude"})})).json();if(re.ok&&re.session)return E(re.session),u(),P(`Proposing a skill in ${$.project}`,"success"),!0;P(re.error??"Failed to start session","error")}catch{P("Failed to start session","error")}return!1},[E,u]);F(()=>{l||go().catch(()=>{})},[l]);const pe=Q(()=>e.filter($=>$.status==="active"),[e]),ke=Q(()=>x.openTabs.filter($=>$.status==="active"&&$.type!=="login").map($=>({key:K($),session:$})),[x.openTabs]),xe=!x.showList&&x.openTabs.length>0;F(()=>{const $=xe?x.openTabs[x.activeTabIndex]:void 0;kr.value=$?K($):null},[xe,x.openTabs,x.activeTabIndex]);const Pe=X({openTabs:x.openTabs,spaces:e,openSession:E});Pe.current={openTabs:x.openTabs,spaces:e,openSession:E},F(()=>aa(($,T)=>{if(document.visibilityState==="visible"&&$===kr.value)return;const{openTabs:W,spaces:U,openSession:ne}=Pe.current,re=W.find(_e=>K(_e)===$)??U.find(_e=>K(_e)===$);re&&ca(`${he(re)}: ${Wt(T).toLowerCase()}`,ue(re)||re.account,$,()=>ne(re))}),[]);const Ke=Object.values(Te.value).filter(Oe).length;F(()=>{document.title=Ke>0?`(${Ke}) Forge Console`:"Forge Console"},[Ke]);const Yt=Q(()=>{const $=new Map(Object.entries(r).map(([T,W])=>[T,W.account]));for(const T of e)ue(T)&&!$.has(T.project)&&$.set(T.project,T.account);return Array.from($,([T,W])=>({name:T,account:W||"unassigned",count:pe.filter(U=>U.project===T).length,live:ke.some(U=>U.session.project===T)}))},[r,e,pe,ke]);F(()=>{v.filterProject&&(Ie.value=v.filterProject)},[v.filterProject]);const Qt=Q(()=>Object.keys(r),[r]),tr=Y($=>{v.setFilterProject($),z("list")},[v.setFilterProject,z]),ht=xe?"list":p,ft=Q(()=>[{id:"new-task",label:"New task",hint:"N",glyph:"+",token:"--blue",run:()=>y()},{id:"add-project",label:"Add project",hint:"P",glyph:"P",token:"--green",run:()=>b(!0)},...zo.map($=>({id:$.view,label:$.label,hint:$.view==="list"?"⌘L":"",glyph:$.glyph,token:$.token,run:()=>z($.view)})),{id:"appearance",label:"Toggle appearance",hint:"⌘J",glyph:"◐",token:null,run:mr}],[z]),Zt=n(va,{view:ht,counts:{list:pe.length,accounts:v.accountNames.length,prototypes:m},projects:Yt,accounts:v.accountNames,selectedProject:v.filterProject,live:ke,onNavigate:z,onSelectProject:O,onAddProject:()=>{Se.value=!1,b(!0)},onOpenLive:E,onSearch:j}),Xt=l?n("div",{class:"py-20 text-center text-ink2",children:"Loading…"}):p==="list"&&!C?n("div",{style:{padding:"56px 22px"},children:n(no,{icon:"i-lucide-folder",title:"Welcome to Forge",description:"No projects found in CW. Register a project with 'cw open <project>' or create one with 'cw create' first.",action:{label:"Add project",onClick:()=>b(!0)}})}):p==="list"?n(Ua,{spaces:v.filteredSpaces,allSpaces:e,projects:r,accountNames:v.accountNames,filterAccount:v.filterAccount,filterProject:v.filterProject,onFilterProject:v.setFilterProject,filterType:v.filterType,onFilterType:v.setFilterType,harnessNames:v.harnessNames,filterHarness:v.filterHarness,onFilterHarness:v.setFilterHarness,showDone:v.showDone,onShowDone:v.setShowDone,openTabKeys:x.openTabKeys,onSelectTask:E,onMarkDone:I,onNewTask:()=>y(),onCreateProject:()=>b(!0),onRefresh:()=>f(),onStarted:$=>{$&&E($),u()}}):p==="prototypes"?n(ys,{accounts:v.accountNames,onOpenSession:E,onFramesChanged:k}):p==="accounts"?n(js,{projects:r,onOpenSession:E,onAccountsChanged:()=>{f()}}):n(ms,{accounts:v.accountNames,projects:r,onCreateWithAI:de,onRunSkill:ae,onProposeSkill:ce});return n(Ii,{sidebar:Zt,children:[!xe&&Xt,x.openTabs.length>0&&n("div",{class:"flex flex-col","aria-hidden":!xe,style:xe?{height:"100vh"}:{position:"absolute",top:0,left:0,right:0,height:"100vh",visibility:"hidden",pointerEvents:"none",zIndex:-1},children:[n(Ls,{tabs:x.openTabs,activeIndex:x.activeTabIndex,onActivate:x.setActiveTabIndex,onClose:x.closeTab,onBack:_,allSessions:pe,openTabKeys:x.openTabKeys,onOpenSession:E,onNewTask:$=>{_(),y($)}}),n("div",{class:"flex-1 min-h-0 relative",children:x.openTabs.map(($,T)=>{const W=T===x.activeTabIndex,U=W&&xe;return n("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,display:"flex",flexDirection:"column",visibility:U?"visible":"hidden",zIndex:W?1:0,pointerEvents:U?"auto":"none"},children:n(Ga,{session:$,active:U,onDone:()=>I($,()=>{x.closeTabByKey(K($))})})},K($))})})]}),h&&n(Xa,{projects:r,accounts:v.accountNames,initialAccount:v.filterAccount??(Ft.value||void 0),initialProject:Ie.value||void 0,onClose:N,onCreated:$=>{c(!1),$&&E($),u()},onOpenAccounts:()=>z("accounts")}),B&&n(xa,{openTabs:x.openTabs,sessions:e,projects:Qt,commands:ft,onOpenSession:E,onSelectProject:tr,onClose:M}),n(bs,{open:g,accounts:v.accountNames,onClose:()=>b(!1),onCreated:$=>{b(!1),$&&E($),u()}}),S]})}di(n(Os,{}),document.getElementById("app"));
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Forge Console</title>
7
- <script type="module" crossorigin src="/assets/index-ciIvVZWo.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-CER8DSNM.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/assets/index-D_58OQhA.css">
9
9
  </head>
10
10
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forge-cw",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
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",
@@ -1,33 +0,0 @@
1
- (function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))o(i);new MutationObserver(i=>{for(const a of i)if(a.type==="childList")for(const l of a.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&o(l)}).observe(document,{childList:!0,subtree:!0});function r(i){const a={};return i.integrity&&(a.integrity=i.integrity),i.referrerPolicy&&(a.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?a.credentials="include":i.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function o(i){if(i.ep)return;i.ep=!0;const a=r(i);fetch(i.href,a)}})();var Ht,q,Pr,Lr,we,nr,Ar,Er,en,_t,et,Ir,In,mn,yn,Pt={},Lt=[],Xo=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,Ut=Array.isArray;function ye(e,t){for(var r in t)e[r]=t[r];return e}function Nn(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function ei(e,t,r){var o,i,a,l={};for(a in t)a=="key"?o=t[a]:a=="ref"?i=t[a]:l[a]=t[a];if(arguments.length>2&&(l.children=arguments.length>3?Ht.call(arguments,2):r),typeof e=="function"&&e.defaultProps!=null)for(a in e.defaultProps)l[a]===void 0&&(l[a]=e.defaultProps[a]);return St(e,l,o,i,null)}function St(e,t,r,o,i){var a={type:e,props:t,key:r,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++Pr,__i:-1,__u:0};return i==null&&q.vnode!=null&&q.vnode(a),a}function Z(e){return e.children}function tt(e,t){this.props=e,this.context=t}function Ne(e,t){if(t==null)return e.__?Ne(e.__,e.__i+1):null;for(var r;t<e.__k.length;t++)if((r=e.__k[t])!=null&&r.__e!=null)return r.__e;return typeof e.type=="function"?Ne(e):null}function ti(e){if(e.__P&&e.__d){var t=e.__v,r=t.__e,o=[],i=[],a=ye({},t);a.__v=t.__v+1,q.vnode&&q.vnode(a),On(e.__P,a,t,e.__n,e.__P.namespaceURI,32&t.__u?[r]:null,o,r??Ne(t),!!(32&t.__u),i),a.__v=t.__v,a.__.__k[a.__i]=a,Dr(o,a,i),t.__e=t.__=null,a.__e!=r&&Nr(a)}}function Nr(e){if((e=e.__)!=null&&e.__c!=null)return e.__e=e.__c.base=null,e.__k.some(function(t){if(t!=null&&t.__e!=null)return e.__e=e.__c.base=t.__e}),Nr(e)}function rr(e){(!e.__d&&(e.__d=!0)&&we.push(e)&&!At.__r++||nr!=q.debounceRendering)&&((nr=q.debounceRendering)||Ar)(At)}function At(){try{for(var e,t=1;we.length;)we.length>t&&we.sort(Er),e=we.shift(),t=we.length,ti(e)}finally{we.length=At.__r=0}}function Or(e,t,r,o,i,a,l,s,p,d,h){var c,m,k,g,b,f,u,x=o&&o.__k||Lt,v=t.length;for(p=ni(r,t,x,p,v),c=0;c<v;c++)(k=r.__k[c])!=null&&(m=k.__i!=-1&&x[k.__i]||Pt,k.__i=c,f=On(e,k,m,i,a,l,s,p,d,h),g=k.__e,k.ref&&m.ref!=k.ref&&(m.ref&&Wn(m.ref,null,k),h.push(k.ref,k.__c||g,k)),b==null&&g!=null&&(b=g),(u=!!(4&k.__u))||m.__k===k.__k?(p=Wr(k,p,e,u),u&&m.__e&&(m.__e=null)):typeof k.type=="function"&&f!==void 0?p=f:g&&(p=g.nextSibling),k.__u&=-7);return r.__e=b,p}function ni(e,t,r,o,i){var a,l,s,p,d,h=r.length,c=h,m=0;for(e.__k=new Array(i),a=0;a<i;a++)(l=t[a])!=null&&typeof l!="boolean"&&typeof l!="function"?(typeof l=="string"||typeof l=="number"||typeof l=="bigint"||l.constructor==String?l=e.__k[a]=St(null,l,null,null,null):Ut(l)?l=e.__k[a]=St(Z,{children:l},null,null,null):l.constructor===void 0&&l.__b>0?l=e.__k[a]=St(l.type,l.props,l.key,l.ref?l.ref:null,l.__v):e.__k[a]=l,p=a+m,l.__=e,l.__b=e.__b+1,s=null,(d=l.__i=ri(l,r,p,c))!=-1&&(c--,(s=r[d])&&(s.__u|=2)),s==null||s.__v==null?(d==-1&&(i>h?m--:i<h&&m++),typeof l.type!="function"&&(l.__u|=4)):d!=p&&(d==p-1?m--:d==p+1?m++:(d>p?m--:m++,l.__u|=4))):e.__k[a]=null;if(c)for(a=0;a<h;a++)(s=r[a])!=null&&(2&s.__u)==0&&(s.__e==o&&(o=Ne(s)),Mr(s,s));return o}function Wr(e,t,r,o){var i,a;if(typeof e.type=="function"){for(i=e.__k,a=0;i&&a<i.length;a++)i[a]&&(i[a].__=e,t=Wr(i[a],t,r,o));return t}e.__e!=t&&(o&&(t&&e.type&&!t.parentNode&&(t=Ne(e)),r.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function ri(e,t,r,o){var i,a,l,s=e.key,p=e.type,d=t[r],h=d!=null&&(2&d.__u)==0;if(d===null&&s==null||h&&s==d.key&&p==d.type)return r;if(o>(h?1:0)){for(i=r-1,a=r+1;i>=0||a<t.length;)if((d=t[l=i>=0?i--:a++])!=null&&(2&d.__u)==0&&s==d.key&&p==d.type)return l}return-1}function or(e,t,r){t[0]=="-"?e.setProperty(t,r??""):e[t]=r==null?"":typeof r!="number"||Xo.test(t)?r:r+"px"}function vt(e,t,r,o,i){var a,l;e:if(t=="style")if(typeof r=="string")e.style.cssText=r;else{if(typeof o=="string"&&(e.style.cssText=o=""),o)for(t in o)r&&t in r||or(e.style,t,"");if(r)for(t in r)o&&r[t]==o[t]||or(e.style,t,r[t])}else if(t[0]=="o"&&t[1]=="n")a=t!=(t=t.replace(Ir,"$1")),l=t.toLowerCase(),t=l in e||t=="onFocusOut"||t=="onFocusIn"?l.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+a]=r,r?o?r[et]=o[et]:(r[et]=In,e.addEventListener(t,a?yn:mn,a)):e.removeEventListener(t,a?yn:mn,a);else{if(i=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{e[t]=r??"";break e}catch{}typeof r=="function"||(r==null||r===!1&&t[4]!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&r==1?"":r))}}function ir(e){return function(t){if(this.l){var r=this.l[t.type+e];if(t[_t]==null)t[_t]=In++;else if(t[_t]<r[et])return;return r(q.event?q.event(t):t)}}}function On(e,t,r,o,i,a,l,s,p,d){var h,c,m,k,g,b,f,u,x,v,C,y,R,A,L,I=t.type;if(t.constructor!==void 0)return null;128&r.__u&&(p=!!(32&r.__u),a=[s=t.__e=r.__e]),(h=q.__b)&&h(t);e:if(typeof I=="function")try{if(u=t.props,x=I.prototype&&I.prototype.render,v=(h=I.contextType)&&o[h.__c],C=h?v?v.props.value:h.__:o,r.__c?f=(c=t.__c=r.__c).__=c.__E:(x?t.__c=c=new I(u,C):(t.__c=c=new tt(u,C),c.constructor=I,c.render=ii),v&&v.sub(c),c.state||(c.state={}),c.__n=o,m=c.__d=!0,c.__h=[],c._sb=[]),x&&c.__s==null&&(c.__s=c.state),x&&I.getDerivedStateFromProps!=null&&(c.__s==c.state&&(c.__s=ye({},c.__s)),ye(c.__s,I.getDerivedStateFromProps(u,c.__s))),k=c.props,g=c.state,c.__v=t,m)x&&I.getDerivedStateFromProps==null&&c.componentWillMount!=null&&c.componentWillMount(),x&&c.componentDidMount!=null&&c.__h.push(c.componentDidMount);else{if(x&&I.getDerivedStateFromProps==null&&u!==k&&c.componentWillReceiveProps!=null&&c.componentWillReceiveProps(u,C),t.__v==r.__v||!c.__e&&c.shouldComponentUpdate!=null&&c.shouldComponentUpdate(u,c.__s,C)===!1){t.__v!=r.__v&&(c.props=u,c.state=c.__s,c.__d=!1),t.__e=r.__e,t.__k=r.__k,t.__k.some(function(S){S&&(S.__=t)}),Lt.push.apply(c.__h,c._sb),c._sb=[],c.__h.length&&l.push(c);break e}c.componentWillUpdate!=null&&c.componentWillUpdate(u,c.__s,C),x&&c.componentDidUpdate!=null&&c.__h.push(function(){c.componentDidUpdate(k,g,b)})}if(c.context=C,c.props=u,c.__P=e,c.__e=!1,y=q.__r,R=0,x)c.state=c.__s,c.__d=!1,y&&y(t),h=c.render(c.props,c.state,c.context),Lt.push.apply(c.__h,c._sb),c._sb=[];else do c.__d=!1,y&&y(t),h=c.render(c.props,c.state,c.context),c.state=c.__s;while(c.__d&&++R<25);c.state=c.__s,c.getChildContext!=null&&(o=ye(ye({},o),c.getChildContext())),x&&!m&&c.getSnapshotBeforeUpdate!=null&&(b=c.getSnapshotBeforeUpdate(k,g)),A=h!=null&&h.type===Z&&h.key==null?Fr(h.props.children):h,s=Or(e,Ut(A)?A:[A],t,r,o,i,a,l,s,p,d),c.base=t.__e,t.__u&=-161,c.__h.length&&l.push(c),f&&(c.__E=c.__=null)}catch(S){if(t.__v=null,p||a!=null)if(S.then){for(t.__u|=p?160:128;s&&s.nodeType==8&&s.nextSibling;)s=s.nextSibling;a[a.indexOf(s)]=null,t.__e=s}else{for(L=a.length;L--;)Nn(a[L]);bn(t)}else t.__e=r.__e,t.__k=r.__k,S.then||bn(t);q.__e(S,t,r)}else a==null&&t.__v==r.__v?(t.__k=r.__k,t.__e=r.__e):s=t.__e=oi(r.__e,t,r,o,i,a,l,p,d);return(h=q.diffed)&&h(t),128&t.__u?void 0:s}function bn(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(bn))}function Dr(e,t,r){for(var o=0;o<r.length;o++)Wn(r[o],r[++o],r[++o]);q.__c&&q.__c(t,e),e.some(function(i){try{e=i.__h,i.__h=[],e.some(function(a){a.call(i)})}catch(a){q.__e(a,i.__v)}})}function Fr(e){return typeof e!="object"||e==null||e.__b>0?e:Ut(e)?e.map(Fr):ye({},e)}function oi(e,t,r,o,i,a,l,s,p){var d,h,c,m,k,g,b,f=r.props||Pt,u=t.props,x=t.type;if(x=="svg"?i="http://www.w3.org/2000/svg":x=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),a!=null){for(d=0;d<a.length;d++)if((k=a[d])&&"setAttribute"in k==!!x&&(x?k.localName==x:k.nodeType==3)){e=k,a[d]=null;break}}if(e==null){if(x==null)return document.createTextNode(u);e=document.createElementNS(i,x,u.is&&u),s&&(q.__m&&q.__m(t,a),s=!1),a=null}if(x==null)f===u||s&&e.data==u||(e.data=u);else{if(a=a&&Ht.call(e.childNodes),!s&&a!=null)for(f={},d=0;d<e.attributes.length;d++)f[(k=e.attributes[d]).name]=k.value;for(d in f)k=f[d],d=="dangerouslySetInnerHTML"?c=k:d=="children"||d in u||d=="value"&&"defaultValue"in u||d=="checked"&&"defaultChecked"in u||vt(e,d,null,k,i);for(d in u)k=u[d],d=="children"?m=k:d=="dangerouslySetInnerHTML"?h=k:d=="value"?g=k:d=="checked"?b=k:s&&typeof k!="function"||f[d]===k||vt(e,d,k,f[d],i);if(h)s||c&&(h.__html==c.__html||h.__html==e.innerHTML)||(e.innerHTML=h.__html),t.__k=[];else if(c&&(e.innerHTML=""),Or(t.type=="template"?e.content:e,Ut(m)?m:[m],t,r,o,x=="foreignObject"?"http://www.w3.org/1999/xhtml":i,a,l,a?a[0]:r.__k&&Ne(r,0),s,p),a!=null)for(d=a.length;d--;)Nn(a[d]);s||(d="value",x=="progress"&&g==null?e.removeAttribute("value"):g!=null&&(g!==e[d]||x=="progress"&&!g||x=="option"&&g!=f[d])&&vt(e,d,g,f[d],i),d="checked",b!=null&&b!=e[d]&&vt(e,d,b,f[d],i))}return e}function Wn(e,t,r){try{if(typeof e=="function"){var o=typeof e.__u=="function";o&&e.__u(),o&&t==null||(e.__u=e(t))}else e.current=t}catch(i){q.__e(i,r)}}function Mr(e,t,r){var o,i;if(q.unmount&&q.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||Wn(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(a){q.__e(a,t)}o.base=o.__P=null}if(o=e.__k)for(i=0;i<o.length;i++)o[i]&&Mr(o[i],t,r||typeof e.type!="function");r||Nn(e.__e),e.__c=e.__=e.__e=void 0}function ii(e,t,r){return this.constructor(e,r)}function ai(e,t,r){var o,i,a,l;t==document&&(t=document.documentElement),q.__&&q.__(e,t),i=(o=!1)?null:t.__k,a=[],l=[],On(t,e=t.__k=ei(Z,null,[e]),i||Pt,Pt,t.namespaceURI,i?null:t.firstChild?Ht.call(t.childNodes):null,a,i?i.__e:t.firstChild,o,l),Dr(a,e,l)}Ht=Lt.slice,q={__e:function(e,t,r,o){for(var i,a,l;t=t.__;)if((i=t.__c)&&!i.__)try{if((a=i.constructor)&&a.getDerivedStateFromError!=null&&(i.setState(a.getDerivedStateFromError(e)),l=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(e,o||{}),l=i.__d),l)return i.__E=i}catch(s){e=s}throw e}},Pr=0,Lr=function(e){return e!=null&&e.constructor===void 0},tt.prototype.setState=function(e,t){var r;r=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=ye({},this.state),typeof e=="function"&&(e=e(ye({},r),this.props)),e&&ye(r,e),e!=null&&this.__v&&(t&&this._sb.push(t),rr(this))},tt.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),rr(this))},tt.prototype.render=Z,we=[],Ar=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Er=function(e,t){return e.__v.__b-t.__v.__b},At.__r=0,en=Math.random().toString(8),_t="__d"+en,et="__a"+en,Ir=/(PointerCapture)$|Capture$/i,In=0,mn=ir(!1),yn=ir(!0);var si=0;function n(e,t,r,o,i,a){t||(t={});var l,s,p=t;if("ref"in p)for(s in p={},t)s=="ref"?l=t[s]:p[s]=t[s];var d={type:e,props:p,key:r,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--si,__i:-1,__u:0,__source:i,__self:a};if(typeof e=="function"&&(l=e.defaultProps))for(s in l)p[s]===void 0&&(p[s]=l[s]);return q.vnode&&q.vnode(d),d}var at,oe,tn,ar,st=0,Br=[],ie=q,sr=ie.__b,lr=ie.__r,cr=ie.diffed,dr=ie.__c,pr=ie.unmount,ur=ie.__;function Dn(e,t){ie.__h&&ie.__h(oe,e,st||t),st=0;var r=oe.__H||(oe.__H={__:[],__h:[]});return e>=r.__.length&&r.__.push({}),r.__[e]}function w(e){return st=1,li(Ur,e)}function li(e,t,r){var o=Dn(at++,2);if(o.t=e,!o.__c&&(o.__=[Ur(void 0,t),function(s){var p=o.__N?o.__N[0]:o.__[0],d=o.t(p,s);p!==d&&(o.__N=[d,o.__[1]],o.__c.setState({}))}],o.__c=oe,!oe.__f)){var i=function(s,p,d){if(!o.__c.__H)return!0;var h=o.__c.__H.__.filter(function(m){return m.__c});if(h.every(function(m){return!m.__N}))return!a||a.call(this,s,p,d);var c=o.__c.props!==s;return h.some(function(m){if(m.__N){var k=m.__[0];m.__=m.__N,m.__N=void 0,k!==m.__[0]&&(c=!0)}}),a&&a.call(this,s,p,d)||c};oe.__f=!0;var a=oe.shouldComponentUpdate,l=oe.componentWillUpdate;oe.componentWillUpdate=function(s,p,d){if(this.__e){var h=a;a=void 0,i(s,p,d),a=h}l&&l.call(this,s,p,d)},oe.shouldComponentUpdate=i}return o.__N||o.__}function F(e,t){var r=Dn(at++,3);!ie.__s&&Hr(r.__H,t)&&(r.__=e,r.u=t,oe.__H.__h.push(r))}function X(e){return st=5,Q(function(){return{current:e}},[])}function Q(e,t){var r=Dn(at++,7);return Hr(r.__H,t)&&(r.__=e(),r.__H=t,r.__h=e),r.__}function Y(e,t){return st=8,Q(function(){return e},t)}function ci(){for(var e;e=Br.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Ct),t.__h.some(kn),t.__h=[]}catch(r){t.__h=[],ie.__e(r,e.__v)}}}ie.__b=function(e){oe=null,sr&&sr(e)},ie.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ur&&ur(e,t)},ie.__r=function(e){lr&&lr(e),at=0;var t=(oe=e.__c).__H;t&&(tn===oe?(t.__h=[],oe.__h=[],t.__.some(function(r){r.__N&&(r.__=r.__N),r.u=r.__N=void 0})):(t.__h.some(Ct),t.__h.some(kn),t.__h=[],at=0)),tn=oe},ie.diffed=function(e){cr&&cr(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Br.push(t)!==1&&ar===ie.requestAnimationFrame||((ar=ie.requestAnimationFrame)||di)(ci)),t.__H.__.some(function(r){r.u&&(r.__H=r.u),r.u=void 0})),tn=oe=null},ie.__c=function(e,t){t.some(function(r){try{r.__h.some(Ct),r.__h=r.__h.filter(function(o){return!o.__||kn(o)})}catch(o){t.some(function(i){i.__h&&(i.__h=[])}),t=[],ie.__e(o,r.__v)}}),dr&&dr(e,t)},ie.unmount=function(e){pr&&pr(e);var t,r=e.__c;r&&r.__H&&(r.__H.__.some(function(o){try{Ct(o)}catch(i){t=i}}),r.__H=void 0,t&&ie.__e(t,r.__v))};var hr=typeof requestAnimationFrame=="function";function di(e){var t,r=function(){clearTimeout(o),hr&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(r,35);hr&&(t=requestAnimationFrame(r))}function Ct(e){var t=oe,r=e.__c;typeof r=="function"&&(e.__c=void 0,r()),oe=t}function kn(e){var t=oe;e.__c=e.__(),oe=t}function Hr(e,t){return!e||e.length!==t.length||t.some(function(r,o){return r!==e[o]})}function Ur(e,t){return typeof t=="function"?t(e):t}var pi=Symbol.for("preact-signals");function Kt(){if(be>1)be--;else{var e,t=!1;for((function(){var i=It;for(It=void 0;i!==void 0;)i.S.v===i.v&&(i.S.i=i.i),i=i.o})();nt!==void 0;){var r=nt;for(nt=void 0,Et++;r!==void 0;){var o=r.u;if(r.u=void 0,r.f&=-3,!(8&r.f)&&qr(r))try{r.c()}catch(i){t||(e=i,t=!0)}r=o}}if(Et=0,be--,t)throw e}}function ui(e){if(be>0)return e();wn=++hi,be++;try{return e()}finally{Kt()}}var J=void 0;function Fn(e){var t=J;J=void 0;try{return e()}finally{J=t}}var nt=void 0,be=0,Et=0,hi=0,wn=0,It=void 0,Nt=0;function Kr(e){if(J!==void 0){var t=e.n;if(t===void 0||t.t!==J)return t={i:0,S:e,p:J.s,n:void 0,t:J,e:void 0,x:void 0,r:t},J.s!==void 0&&(J.s.n=t),J.s=t,e.n=t,32&J.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=J.s,t.n=void 0,J.s.n=t,J.s=t),t}}function le(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t==null?void 0:t.watched,this.Z=t==null?void 0:t.unwatched,this.name=t==null?void 0:t.name}le.prototype.brand=pi;le.prototype.h=function(){return!0};le.prototype.S=function(e){var t=this,r=this.t;r!==e&&e.e===void 0&&(e.x=r,this.t=e,r!==void 0?r.e=e:Fn(function(){var o;(o=t.W)==null||o.call(t)}))};le.prototype.U=function(e){var t=this;if(this.t!==void 0){var r=e.e,o=e.x;r!==void 0&&(r.x=o,e.e=void 0),o!==void 0&&(o.e=r,e.x=void 0),e===this.t&&(this.t=o,o===void 0&&Fn(function(){var i;(i=t.Z)==null||i.call(t)}))}};le.prototype.subscribe=function(e){var t=this;return pt(function(){var r=t.value,o=J;J=void 0;try{e(r)}finally{J=o}},{name:"sub"})};le.prototype.valueOf=function(){return this.value};le.prototype.toString=function(){return this.value+""};le.prototype.toJSON=function(){return this.value};le.prototype.peek=function(){var e=this;return Fn(function(){return e.value})};Object.defineProperty(le.prototype,"value",{get:function(){var e=Kr(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Et>100)throw new Error("Cycle detected");(function(r){be!==0&&Et===0&&r.l!==wn&&(r.l=wn,It={S:r,v:r.v,i:r.i,o:It})})(this),this.v=e,this.i++,Nt++,be++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Kt()}}}});function te(e,t){return new le(e,t)}function qr(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function Jr(e){for(var t=e.s;t!==void 0;t=t.n){var r=t.S.n;if(r!==void 0&&(t.r=r),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function Gr(e){for(var t=e.s,r=void 0;t!==void 0;){var o=t.p;t.i===-1?(t.S.U(t),o!==void 0&&(o.n=t.n),t.n!==void 0&&(t.n.p=o)):r=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=o}e.s=r}function ze(e,t){le.call(this,void 0),this.x=e,this.s=void 0,this.g=Nt-1,this.f=4,this.W=t==null?void 0:t.watched,this.Z=t==null?void 0:t.unwatched,this.name=t==null?void 0:t.name}ze.prototype=new le;ze.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Nt))return!0;if(this.g=Nt,this.f|=1,this.i>0&&!qr(this))return this.f&=-2,!0;var e=J;try{Jr(this),J=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(r){this.v=r,this.f|=16,this.i++}return J=e,Gr(this),this.f&=-2,!0};ze.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}le.prototype.S.call(this,e)};ze.prototype.U=function(e){if(this.t!==void 0&&(le.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};ze.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(ze.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Kr(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function fr(e,t){return new ze(e,t)}function Vr(e){var t=e.m;if(e.m=void 0,typeof t=="function"){be++;var r=J;J=void 0;try{t()}catch(o){throw e.f&=-2,e.f|=8,Mn(e),o}finally{J=r,Kt()}}}function Mn(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Vr(e)}function fi(e){if(J!==this)throw new Error("Out-of-order effect");Gr(this),J=e,this.f&=-2,8&this.f&&Mn(this),Kt()}function Be(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t==null?void 0:t.name}Be.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.m=t)}finally{e()}};Be.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Vr(this),Jr(this),be++;var e=J;return J=this,fi.bind(this,e)};Be.prototype.N=function(){2&this.f||(this.f|=2,this.u=nt,nt=this)};Be.prototype.d=function(){this.f|=8,1&this.f||Mn(this)};Be.prototype.dispose=function(){this.d()};function pt(e,t){var r=new Be(e,t);try{r.c()}catch(i){throw r.d(),i}var o=r.d.bind(r);return o[Symbol.dispose]=o,o}var Yr,xt,vi=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__,Qr=[];pt(function(){Yr=this.N})();function He(e,t){q[e]=t.bind(null,q[e]||function(){})}function Ot(e){if(xt){var t=xt;xt=void 0,t()}xt=e&&e.S()}function Zr(e){var t=this,r=e.data,o=gi(r);o.value=r;var i=Q(function(){for(var s=t,p=t.__v;p=p.__;)if(p.__c){p.__c.__$f|=4;break}var d=fr(function(){var k=o.value.value;return k===0?0:k===!0?"":k||""}),h=fr(function(){return!Array.isArray(d.value)&&!Lr(d.value)}),c=pt(function(){if(this.N=Xr,h.value){var k=d.value;s.__v&&s.__v.__e&&s.__v.__e.nodeType===3&&(s.__v.__e.data=k)}}),m=t.__$u.d;return t.__$u.d=function(){c(),m.call(this)},[h,d]},[]),a=i[0],l=i[1];return a.value?l.peek():l.value}Zr.displayName="ReactiveTextNode";Object.defineProperties(le.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:Zr},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}});He("__b",function(e,t){if(typeof t.type=="string"){var r,o=t.props;for(var i in o)if(i!=="children"){var a=o[i];a instanceof le&&(r||(t.__np=r={}),r[i]=a,o[i]=a.peek())}}e(t)});He("__r",function(e,t){if(e(t),t.type!==Z){Ot();var r,o=t.__c;o&&(o.__$f&=-2,(r=o.__$u)===void 0&&(o.__$u=r=(function(i,a){var l;return pt(function(){l=this},{name:a}),l.c=i,l})(function(){var i;vi&&((i=r.y)==null||i.call(r)),o.__$f|=1,o.setState({})},typeof t.type=="function"?t.type.displayName||t.type.name:""))),Ot(r)}});He("__e",function(e,t,r,o){Ot(),e(t,r,o)});He("diffed",function(e,t){Ot();var r;if(typeof t.type=="string"&&(r=t.__e)){var o=t.__np,i=t.props;if(o){var a=r.U;if(a)for(var l in a){var s=a[l];s!==void 0&&!(l in o)&&(s.d(),a[l]=void 0)}else a={},r.U=a;for(var p in o){var d=a[p],h=o[p];d===void 0?(d=xi(r,p,h),a[p]=d):d.o(h,i)}for(var c in o)i[c]=o[c]}}e(t)});function xi(e,t,r,o){var i=t in e&&e.ownerSVGElement===void 0,a=te(r),l=r.peek();return{o:function(s,p){a.value=s,l=s.peek()},d:pt(function(){this.N=Xr;var s=a.value.value;l!==s?(l=void 0,i?e[t]=s:s!=null&&(s!==!1||t[4]==="-")?e.setAttribute(t,s):e.removeAttribute(t)):l=void 0})}}He("unmount",function(e,t){if(typeof t.type=="string"){var r=t.__e;if(r){var o=r.U;if(o){r.U=void 0;for(var i in o){var a=o[i];a&&a.d()}}}t.__np=void 0}else{var l=t.__c;if(l){var s=l.__$u;s&&(l.__$u=void 0,s.d())}}e(t)});He("__h",function(e,t,r,o){(o<3||o===9)&&(t.__$f|=2),e(t,r,o)});tt.prototype.shouldComponentUpdate=function(e,t){if(this.__R)return!0;var r=this.__$u,o=r&&r.s!==void 0;for(var i in t)return!0;if(this.__f||typeof this.u=="boolean"&&this.u===!0){var a=2&this.__$f;if(!(o||a||4&this.__$f)||1&this.__$f)return!0}else if(!(o||4&this.__$f)||3&this.__$f)return!0;for(var l in e)if(l!=="__source"&&e[l]!==this.props[l])return!0;for(var s in this.props)if(!(s in e))return!0;return!1};function gi(e,t){return Q(function(){return te(e,t)},[])}var mi=function(e){queueMicrotask(function(){queueMicrotask(e)})};function yi(){ui(function(){for(var e;e=Qr.shift();)Yr.call(e)})}function Xr(){Qr.push(this)===1&&(q.requestAnimationFrame||mi)(yi)}const bi={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"}},vr={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"}},ki={background:"var(--elev)",color:"var(--ink-3)",border:"1px solid transparent",boxShadow:"none",opacity:".8"},D=({label:e,icon:t,variant:r="primary",size:o="md",block:i,title:a,disabled:l,loading:s,onClick:p})=>{const[d,h]=w(!1),c=s??d,m=!!(l||c),k=async()=>{if(!m){h(!0);try{await p()}finally{h(!1)}}},g=bi[o],b=r==="primary"||r==="destructive",f=l&&!c?{...vr[r],...ki}:vr[r];return n("button",{type:"button",class:`inline-flex items-center justify-center gap-1.5 whitespace-nowrap transition-all duration-180 ease-spring ${m?"cursor-not-allowed":`cursor-pointer hover:-translate-y-px hover:shadow-m${b?" hover:brightness-106":""}`}${i?" w-full":""}`,style:{...f,padding:b?g.primaryPad:g.pad,fontSize:g.font,borderRadius:g.radius},disabled:m,title:a,onClick:k,children:[c?n("span",{class:"i-lucide-loader-2 animate-spin"}):t?n("span",{class:t}):null,n("span",{children:e})]})},wi="modulepreload",_i=function(e){return"/"+e},xr={},nn=function(t,r,o){let i=Promise.resolve();if(r&&r.length>0){let l=function(d){return Promise.all(d.map(h=>Promise.resolve(h).then(c=>({status:"fulfilled",value:c}),c=>({status:"rejected",reason:c}))))};document.getElementsByTagName("link");const s=document.querySelector("meta[property=csp-nonce]"),p=(s==null?void 0:s.nonce)||(s==null?void 0:s.getAttribute("nonce"));i=l(r.map(d=>{if(d=_i(d),d in xr)return;xr[d]=!0;const h=d.endsWith(".css"),c=h?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${c}`))return;const m=document.createElement("link");if(m.rel=h?"stylesheet":wi,h||(m.as="script"),m.crossOrigin="",m.href=d,p&&m.setAttribute("nonce",p),document.head.appendChild(m),h)return new Promise((k,g)=>{m.addEventListener("load",k),m.addEventListener("error",()=>g(new Error(`Unable to preload CSS for ${d}`)))})}))}function a(l){const s=new Event("vite:preloadError",{cancelable:!0});if(s.payload=l,window.dispatchEvent(s),!s.defaultPrevented)throw l}return i.then(l=>{for(const s of l||[])s.status==="rejected"&&a(s.reason);return t().catch(a)})},Si='ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace',rn=e=>({background:e==="dark"?"#0e0e10":"#1c1c1e",foreground:"#e3e3e8",cursor:"#e3e3e8",selectionBackground:"rgba(10,132,255,0.35)"}),Ci=({streamUrl:e,content:t,wsUrl:r,height:o=300,onExit:i,onGiveUp:a,onConnectionChange:l,onOutput:s,focused:p=!0,theme:d="dark"})=>{const h=X(null),c=!!r,m=X(i);m.current=i;const k=X(a);k.current=a;const g=X(l);g.current=l;const b=X(s);b.current=s;const f=X(d);f.current=d;const u=X(p);u.current=p;const x=X(null);F(()=>{x.current&&(x.current.options.theme=rn(d))},[d]),F(()=>{var C;c&&p&&((C=x.current)==null||C.focus())},[p,c]),F(()=>{if(!h.current)return;let C=!1,y=null,R=null,A=0;const L=[];return(async()=>{const{Terminal:S}=await nn(async()=>{const{Terminal:M}=await import("./xterm-DlVFs1Kw.js").then(j=>j.x);return{Terminal:M}},[]),{FitAddon:z}=await nn(async()=>{const{FitAddon:M}=await import("./addon-fit-BlxrFPDK.js").then(j=>j.a);return{FitAddon:M}},[]),{WebLinksAddon:_}=await nn(async()=>{const{WebLinksAddon:M}=await import("./addon-web-links-BWjmmSgS.js");return{WebLinksAddon:M}},[]);if(C)return;const N=new S({theme:rn(f.current),fontSize:13,fontFamily:Si,convertEol:!c,disableStdin:!c,cursorBlink:c,scrollback:1e4});x.current=N;const O=M=>{var j;N.write(M),(j=b.current)==null||j.call(b,M)},E=new z;N.loadAddon(E),N.loadAddon(new _),N.open(h.current),setTimeout(()=>{E.fit(),c&&u.current&&N.focus()},50),t&&!c&&O(t);let B;if(e&&!c&&(B=new EventSource(e),B.addEventListener("output",M=>{const{chunk:j}=JSON.parse(M.data);O(j)}),B.addEventListener("done",M=>{const{exitCode:j}=JSON.parse(M.data);N.write(`\r
2
- \x1B[${j===0?"32":"31"}m--- Exit code: ${j} ---\x1B[0m\r
3
- `),B==null||B.close()})),r&&!C){const M=j=>{if(C)return;console.log("[ForgeTerminal] Connecting to:",j),y=new WebSocket(j);const G=[];y.onopen=()=>{var ae;console.log("[ForgeTerminal] WebSocket OPEN"),A=0,(ae=g.current)==null||ae.call(g,!0),E.fit();const{cols:V,rows:de}=N;y.send(JSON.stringify({type:"resize",cols:V,rows:de})),G.push(N.onData(ce=>{(y==null?void 0:y.readyState)===WebSocket.OPEN&&y.send(JSON.stringify({type:"input",data:ce}))})),G.push(N.onResize(({cols:ce,rows:pe})=>{(y==null?void 0:y.readyState)===WebSocket.OPEN&&y.send(JSON.stringify({type:"resize",cols:ce,rows:pe}))}))},y.onmessage=V=>{var de;try{const ae=JSON.parse(V.data);ae.type==="output"||ae.type==="scrollback"?O(ae.data):ae.type==="exit"?(N.write(`\r
4
- \x1B[33m--- Session ended (code ${ae.code}) ---\x1B[0m\r
5
- `),(de=m.current)==null||de.call(m,ae.code)):ae.type==="error"&&N.write(`\r
6
- \x1B[31m--- Error: ${ae.message} ---\x1B[0m\r
7
- `)}catch{}},y.onclose=V=>{var de,ae,ce;if(console.log("[ForgeTerminal] WebSocket CLOSE:",V.code,V.reason),G.forEach(pe=>pe.dispose()),G.length=0,(de=g.current)==null||de.call(g,!1),!C)if(V.code===4404)N.write(`\r
8
- \x1B[31m--- Click Restart to try again. ---\x1B[0m\r
9
- `),(ae=k.current)==null||ae.call(k);else if(A<5){const pe=Math.min(2e3*Math.pow(2,A),16e3);A++,N.write(`\r
10
- \x1B[90m--- Reconnecting (attempt ${A}/5)... ---\x1B[0m\r
11
- `),R=setTimeout(()=>M(j),pe)}else N.write(`\r
12
- \x1B[31m--- Connection lost. Click Restart to try again. ---\x1B[0m\r
13
- `),(ce=k.current)==null||ce.call(k)},y.onerror=V=>{console.error("[ForgeTerminal] WebSocket error:",V)}};M(r)}const U=new ResizeObserver(()=>{C||E.fit()});U.observe(h.current),L.push({dispose:()=>{B==null||B.close(),U.disconnect(),R&&clearTimeout(R),y&&(C=!0,y.close()),N.dispose(),x.current=null}})})(),()=>{C=!0,L.forEach(S=>S.dispose())}},[e,t,r,c]);const v=c?{width:"100%",height:"100%"}:{width:"100%",height:`${o}px`};return n("div",{ref:h,class:"overflow-hidden",style:{...v,background:rn(d).background}})},Ze=te([]);function P(e,t="info"){const r=Math.random().toString(36).slice(2);Ze.value=[...Ze.value,{id:r,message:e,type:t}],setTimeout(()=>{Ze.value=Ze.value.filter(o=>o.id!==r)},4e3)}const $i={success:"var(--green)",error:"var(--red)",info:"var(--blue)"},Ti=()=>n("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:Ze.value.map(e=>n("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:[n("span",{class:"shrink-0",style:{width:"6px",height:"6px",borderRadius:"50%",background:$i[e.type]}}),e.message]},e.id))}),eo=({onClick:e,label:t="Close"})=>n("button",{type:"button","aria-label":t,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:e,children:n("span",{class:"i-lucide-x",style:{width:"13px",height:"13px"}})}),Bn=({open:e,title:t,onClose:r,footer:o,width:i=540,children:a})=>(F(()=>{if(!e)return;const l=s=>{s.key==="Escape"&&r()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[e,r]),e?n("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:r,children:n("div",{role:"dialog","aria-modal":"true","aria-label":t,class:"flex flex-col overflow-hidden",style:{width:`min(${i}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:l=>l.stopPropagation(),children:[n("div",{class:"flex items-center gap-2.5 shrink-0",style:{padding:"14px 18px",borderBottom:"1px solid var(--hair)"},children:[n("h2",{style:{fontSize:"17px",fontWeight:700,letterSpacing:"-0.02em"},children:t}),n("span",{class:"flex-1"}),n(eo,{onClick:r})]}),n("div",{class:"overflow-auto min-h-0",style:{padding:"16px 18px"},children:a}),o&&n("div",{class:"flex items-center gap-2.5 shrink-0",style:{padding:"13px 18px",borderTop:"1px solid var(--hair)"},children:o})]})}):null),ve=({tabs:e,active:t,onChange:r,fill:o,size:i="md",label:a})=>{const l=i!=="md",s=i==="xs";return n("div",{role:"tablist","aria-label":a,class:`${o?"flex":"inline-flex"} max-w-full overflow-x-auto`,style:{padding:"3px",borderRadius:l?"10px":"11px",background:"var(--elev)",border:"1px solid var(--hair)"},children:e.map(p=>{const d=t===p.id;return n("button",{type:"button",role:"tab","aria-selected":d,disabled:p.disabled,class:`flex items-center justify-center gap-1.5 whitespace-nowrap transition-all duration-200 ease-spring ${o?"flex-1":""} ${p.disabled?"cursor-not-allowed opacity-50":"cursor-pointer"}`,style:{padding:s?"4px 0":o?l?"5px 6px":"7px 8px":l?"5px 11px":"6px 12px",border:0,borderRadius:l?"7px":"8px",fontSize:s?"11.5px":l?"12px":"12.5px",fontWeight:600,background:d?"var(--card)":"transparent",color:d?"var(--ink)":"var(--ink-3)",boxShadow:d?"var(--shadow-s)":"none"},onClick:()=>r(p.id),children:[p.label,p.count!==void 0&&n("span",{class:"mono",style:{fontSize:"11px",fontWeight:400,color:"var(--ink-3)"},children:p.count})]},p.id)})})},to=({icon:e,title:t,description:r,action:o})=>n("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:[e&&n("span",{class:e,style:{width:"28px",height:"28px",color:"var(--ink-3)",marginBottom:"14px"}}),n("h3",{style:{fontSize:"17px",fontWeight:700,letterSpacing:"-0.02em",marginBottom:"6px"},children:t}),r&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)",maxWidth:"40ch",marginBottom:o?"16px":0},children:r}),o&&n(D,{label:o.label,variant:"primary",onClick:o.onClick})]}),no=({checked:e,onChange:t,label:r,disabled:o})=>n("button",{type:"button",role:"switch","aria-checked":e,"aria-label":r,disabled:o,class:`relative shrink-0 ${o?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,style:{width:"44px",height:"26px",borderRadius:"99px",border:0,background:e?"var(--green)":"var(--hair-2)",transition:"background .22s var(--ease)"},onClick:()=>!o&&t(!e),children:n("span",{class:"absolute pointer-events-none",style:{top:"3px",left:e?"21px":"3px",width:"20px",height:"20px",borderRadius:"50%",background:"#fff",boxShadow:"var(--shadow-s)",transition:"left .22s var(--ease)"}})}),Ri={normal:"--blue",warning:"--orange",critical:"--red"},zi=({bar:e,size:t})=>{const r=`var(${Ri[e.severity]})`,o=t==="sm",i=Math.max(0,Math.min(100,e.percent));return n("span",{class:"flex items-center w-full",style:{gap:o?"6px":"9px"},children:[n("span",{class:"mono shrink-0 text-right",style:{width:o?"28px":"32px",fontSize:o?"10px":"11.5px",color:"var(--ink-3)"},children:e.label}),n("span",{class:"relative block flex-1 overflow-hidden",style:{height:o?"4px":"6px",borderRadius:"99px",background:"var(--elev)"},children:n("span",{class:"block h-full",style:{width:`${i}%`,borderRadius:"99px",background:r,transition:"width .6s var(--ease)"}})}),n("span",{class:"mono shrink-0 text-right",style:{width:o?"30px":"36px",fontSize:o?"10px":"11.5px",fontWeight:600,color:e.severity==="normal"?"var(--ink-2)":r},children:[Math.round(e.percent),"%"]}),!o&&e.reset&&n("span",{class:"shrink-0 whitespace-nowrap",style:{fontSize:"11px",color:"var(--ink-3)"},children:e.reset})]})},ro=({bars:e,size:t="md"})=>n("span",{class:"flex flex-col w-full",style:{gap:t==="sm"?"4px":"6px"},children:e.map((r,o)=>n("span",{class:"flex flex-col w-full",style:{gap:"2px"},children:[n(zi,{bar:r,size:t}),r.scope&&t==="md"&&n("span",{style:{paddingLeft:"39px",fontSize:"10.5px",color:"var(--ink-3)"},children:r.scope})]},o))}),oo="forge-theme",ji=()=>{try{return localStorage.getItem(oo)==="light"?"light":"dark"}catch{return"dark"}},ut=te(ji());document.documentElement.setAttribute("data-theme",ut.value);const io=e=>{ut.value=e,document.documentElement.setAttribute("data-theme",e);try{localStorage.setItem(oo,e)}catch{}},Se=te(!1),gr=()=>io(ut.value==="dark"?"light":"dark"),Pi=({sidebar:e,children:t})=>n("div",{class:"forge-shell",style:{minHeight:"100vh",display:"grid",gridTemplateColumns:"236px minmax(0,1fr)",background:"var(--bg)",color:"var(--ink)"},children:[e,n("div",{class:`sb-scrim${Se.value?" open":""}`,onClick:()=>{Se.value=!1}}),n("div",{class:"min-w-0 flex flex-col relative",style:{minHeight:"100vh"},children:t}),n(Ti,{})]}),mr=[["--blue","--purple"],["--teal","--blue"],["--orange","--red"],["--green","--teal"]],ao=e=>mr[e%mr.length],se=(e,t=18)=>`color-mix(in srgb, var(${e}) ${t}%, transparent)`,Ae=(e,t,r)=>({label:e,glyph:t,token:r,ink:`var(${r})`,fill:se(r)}),_n={task:Ae("Dev","D","--orange"),review:Ae("Review","R","--blue"),loop:Ae("Loop","L","--purple"),general:Ae("General","G","--green")},Li={create:Ae("Create","C","--teal"),login:Ae("Login","A","--ink-2")},Hn=e=>_n[e]??Li[e]??_n.task,Ue=[{key:"dev",sessionType:"task"},{key:"review",sessionType:"review"},{key:"loop",sessionType:"loop"},{key:"general",sessionType:"general"}],Un=e=>{var t;return _n[((t=Ue.find(r=>r.key===e))==null?void 0:t.sessionType)??"task"].label},Ai=e=>{var t;return((t=Ue.find(r=>r.key===e))==null?void 0:t.sessionType)??"task"},Kn={working:{label:"Working",token:"--green",attention:!1},waiting:{label:"Waiting for you",token:"--orange",attention:!0},permission:{label:"Needs approval",token:"--red",attention:!0},error:{label:"Stopped on an error",token:"--red",attention:!0},exited:{label:"Exited",token:"--ink-3",attention:!1},idle:{label:"Idle",token:"--ink-3",attention:!1}},Oe=e=>!!(e&&(Kn[e.state].attention||e.state==="exited"&&(e.exitCode??0)!==0)),Wt=e=>e.state==="exited"&&e.exitCode?`Exited with code ${e.exitCode}`:Kn[e.state].label,$t=e=>e.state==="exited"&&e.exitCode?"--red":Kn[e.state].token,K=e=>e.sessionDir?`${e.project}::${e.sessionDir}`:`${e.project}::${e.task??e.pr}`,ue=e=>e.project==="__general"?"":e.project,qt=e=>e.sessionDir??(e.type==="review"?`review-pr-${e.pr}`:e.type==="loop"?`loop-${e.task}`:`task-${e.task}`),he=e=>e.type==="review"?`PR #${e.pr}`:e.type==="general"?e.task??`General (${e.account})`:e.type==="create"?`Create: ${e.task??"project"}`:e.type==="loop"?`Loop: ${e.task??"loop"}`:e.type==="login"?`Login: ${e.account} · ${fe(e.harness).label}`:e.task??"unknown",so=e=>{const t=Math.floor((Date.now()-new Date(e).getTime())/6e4);if(t<1)return"now";if(t<60)return`${t}m`;const r=Math.floor(t/60);if(r<24)return`${r}h`;const o=Math.floor(r/24);return o<30?`${o}d`:`${Math.floor(o/30)}mo`},gt=(e,t)=>({label:e,color:`var(--forge-harness-${t})`,bg:se(`--forge-harness-${t}`)}),Ei={claude:gt("Claude Code","claude"),codex:gt("Codex","codex"),pi:gt("Pi","pi"),opencode:gt("OpenCode","opencode")},fe=e=>Ei[e??"claude"]??{label:e??"claude",color:"var(--ink-3)",bg:"var(--elev)"},lo=e=>{const t=fe(e.harness).label;return e.provider&&e.provider!=="native"?`${t} · ${e.model||e.provider}`:t},Ii=[{id:"",label:"Default",description:"Recommended model"},{id:"haiku",label:"Haiku",description:"Fast, simple tasks"},{id:"sonnet",label:"Sonnet",description:"Daily coding"},{id:"opus",label:"Opus",description:"Complex reasoning"}],co=(e,t,r,o)=>{var i,a;return(e?(i=r[e])==null?void 0:i.harness:void 0)??((a=o.accounts.find(l=>l.name===t))==null?void 0:a.default_harness)??"claude"},Ce=(e,t,r)=>{var o;return(o=e.accounts.find(i=>i.name===t))==null?void 0:o.harnesses.find(i=>i.harness===r)},Ni=/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/,Oi=new Intl.DateTimeFormat(void 0,{weekday:"short",hour:"2-digit",minute:"2-digit"}),po=(e,t=Date.now())=>{if(!e)return null;const r=new Date(e).getTime();if(!Number.isFinite(r))return null;const o=Math.round((r-t)/6e4);if(o<=0)return"resets now";if(o<60)return`resets in ${o} m`;const i=Math.floor(o/60);if(i>=24)return`resets ${Oi.format(Math.round(r/6e4)*6e4)}`;const a=o%60;return`resets in ${i} h${a?` ${a} m`:""}`},uo=e=>e.map(t=>({label:t.label,percent:t.percent,severity:t.severity,scope:t.scope,reset:po(t.resetsAt)})),We=te(null),Wi=3e3;let qe=null;function ge(e=!1){return qe||(qe=fetch(`/api/cw/harnesses${e?"?fresh=1":""}`).then(t=>t.json()).catch(()=>({available:!1,reason:"Could not reach the Forge server"})).then(t=>(We.value=t,qe=null,t)),qe)}const lt=new Set;let rt=null;const ho=()=>{lt.size===0&&rt&&(clearInterval(rt),rt=null)},Di=async()=>{const e=await ge(!0),t=Date.now();for(const r of lt){const o=e.available&&r.check(e.doctor);(o||t>r.deadline)&&(lt.delete(r),r.onDone(o))}ho()};function Fi(e,{timeoutMs:t=6e5,onDone:r=()=>{}}={}){const o={check:e,deadline:Date.now()+t,onDone:r};return lt.add(o),rt||(rt=setInterval(Di,Wi)),()=>{lt.delete(o),ho()}}const Ee=(e,t,r)=>{var o;return!!(e!=null&&e.available&&((o=e.capabilities[t])!=null&&o.includes(r)))},fo=e=>/linear\.app/.test(e)?"linear":/notion\.(so|site)/.test(e)?"notion":null,vo=(e,t,r)=>{const o=fo(r);return!!(e!=null&&e.available&&o&&!Ee(e,t,"mcp")&&!e.contextTokens[o])},ot=te(null);async function xo(){const e=await fetch("/api/skills");if(!e.ok)throw new Error("fetch failed");ot.value=await e.json()}const $e=({size:e=7,color:t,live:r,glow:o=r})=>{const i=t??(r?"var(--green)":"var(--ink-3)");return n("span",{"aria-hidden":"true",class:`shrink-0 inline-block${r?" breathe":""}`,style:{width:`${e}px`,height:`${e}px`,borderRadius:"50%",background:i,boxShadow:o?`0 0 8px ${i}`:"none"}})},on=5,go="forge-sidebar-collapsed",Mi=()=>{try{const e=localStorage.getItem(go);return e?JSON.parse(e):[]}catch{return[]}},Bi=(e,t)=>Number(t.live)-Number(e.live)||t.count-e.count||e.name.localeCompare(t.name),Hi=({projects:e,accounts:t,selected:r,onSelect:o,onAdd:i})=>{const[a,l]=w(""),[s,p]=w(Mi),[d,h]=w([]),c=a.trim().toLowerCase(),m=Q(()=>{const g=[...t,...e.map(b=>b.account).filter(b=>!t.includes(b))];return Array.from(new Set(g)).map((b,f)=>({account:b,index:f,items:e.filter(u=>u.account===b&&(!c||u.name.toLowerCase().includes(c))).sort(Bi),active:e.filter(u=>u.account===b).reduce((u,x)=>u+x.count,0)})).filter(b=>b.items.length>0)},[e,t,c]),k=g=>{const b=s.includes(g)?s.filter(f=>f!==g):[...s,g];p(b);try{localStorage.setItem(go,JSON.stringify(b))}catch{}};return n("div",{class:"flex flex-col sb-section min-h-0",style:{gap:"6px",flex:"0 1 auto",minHeight:"120px"},children:[n("div",{class:"flex items-center justify-between shrink-0",style:{padding:"0 9px"},children:[n("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--ink-3)",letterSpacing:".02em"},children:"Projects"}),n("button",{type:"button","aria-label":"Add project",title:"Add project (P)",class:"grid place-items-center cursor-pointer",style:{border:0,background:"none",color:"var(--blue)",padding:"0 2px"},onClick:i,children:n("span",{class:"i-lucide-plus",style:{width:"14px",height:"14px"}})})]}),n("label",{class:"relative shrink-0 block",style:{margin:"0 2px"},children:[n("span",{class:"i-lucide-search absolute pointer-events-none",style:{left:"9px",top:"8px",width:"12px",height:"12px",color:"var(--ink-3)"}}),n("input",{type:"search",class:"field","aria-label":"Filter projects",placeholder:"Filter projects",value:a,style:{height:"28px",padding:"0 8px 0 27px",borderRadius:"8px",fontSize:"12.5px",background:"var(--elev)"},onInput:g=>l(g.target.value),onKeyDown:g=>{g.key==="Escape"&&l("")}})]}),n("div",{class:"flex flex-col overflow-y-auto min-h-0",style:{gap:"8px",overscrollBehavior:"contain"},children:[m.length===0&&n("p",{style:{padding:"4px 9px",fontSize:"12px",color:"var(--ink-3)"},children:["No project matches “",a.trim(),"”."]}),m.map(g=>{const b=c!==""||!s.includes(g.account),f=c!==""||d.includes(g.account)||g.items.some((y,R)=>R>=on&&y.name===r),u=f?g.items:g.items.slice(0,on),[x,v]=ao(g.index),C=g.items.some(y=>y.live);return n("div",{class:"flex flex-col shrink-0",style:{gap:"1px"},children:[n("button",{type:"button","aria-expanded":b,class:"flex items-center w-full text-left cursor-pointer transition-colors duration-160 hover:bg-elev",style:{gap:"7px",height:"26px",padding:"0 7px",borderRadius:"8px",border:0,background:"none",color:"var(--ink-2)"},onClick:()=>k(g.account),children:[n("span",{class:"i-lucide-chevron-right shrink-0",style:{width:"11px",height:"11px",color:"var(--ink-3)",transform:b?"rotate(90deg)":"none",transition:"transform .2s var(--ease)"}}),n("span",{class:"grid place-items-center shrink-0",style:{width:"16px",height:"16px",borderRadius:"5px",background:`linear-gradient(160deg, var(${x}), var(${v}))`,color:"#fff",fontSize:"9px",fontWeight:700},children:g.account.charAt(0).toUpperCase()}),n("span",{class:"flex-1 truncate",style:{fontSize:"12px",fontWeight:600},children:g.account}),C&&n($e,{size:5,live:!0,glow:!1}),n("span",{class:"mono",style:{fontSize:"10.5px",color:"var(--ink-3)"},title:`${g.items.length} projects · ${g.active} active tasks`,children:g.items.length})]}),b&&n("div",{class:"flex flex-col",style:{gap:"1px",marginLeft:"13px",paddingLeft:"6px",borderLeft:"1px solid var(--hair)",animation:"riseIn .24s var(--ease) both"},children:[u.map(y=>{const R=r===y.name;return n("button",{type:"button","aria-pressed":R,class:"flex items-center w-full text-left shrink-0 cursor-pointer transition-all duration-180 ease-spring hover:bg-elev",style:{gap:"8px",height:"27px",padding:"0 8px",borderRadius:"8px",fontSize:"13px",color:"var(--ink)",border:`1px solid ${R?"var(--hair)":"transparent"}`,background:R?"var(--card)":"transparent",boxShadow:R?"var(--shadow-s)":"none"},onClick:()=>o(y.name),children:[n($e,{size:6,live:y.live}),n("span",{class:"flex-1 truncate",style:{fontWeight:R?600:450,opacity:y.count>0||y.live||R?1:.62},children:y.name}),y.count>0&&n("span",{class:"mono",style:{fontSize:"11px",color:"var(--ink-3)"},children:y.count})]},y.name)}),g.items.length>on&&c===""&&n("button",{type:"button",class:"text-left cursor-pointer hover:underline",style:{padding:"3px 8px",border:0,background:"none",color:"var(--blue)",fontSize:"11.5px",fontWeight:500},onClick:()=>h(f?d.filter(y=>y!==g.account):[...d,g.account]),children:f?"Show less":`Show all ${g.items.length}`})]})]},g.account)})]})]})},mo={context:null,tokens:null,cost:null},Ui=250,Dt=new Map,Ki=/\x1b\[[0-9;?]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\x1b[@-_]/g,Je=(e,t)=>{let r=null;for(const o of e.matchAll(t))r=o;return r},an=e=>{const t=parseFloat(e),r=e.slice(-1).toLowerCase();return r==="k"?t*1e3:r==="m"?t*1e6:t};function qi(e){const t={},r=Je(e,/(?:ctx|context)[:\s]*(\d{1,3}(?:\.\d+)?)\s*%/gi)??Je(e,/[▓█▒░]+\s*(\d{1,3}(?:\.\d+)?)\s*%/g);r&&(t.context=Math.min(100,parseFloat(r[1])));const o=Je(e,/(\d+(?:\.\d+)?[kKmM]?)\s*↑\s*(\d+(?:\.\d+)?[kKmM]?)\s*↓/g),i=Je(e,/\((\d+(?:\.\d+)?[kKmM])\s*\/\s*\d+(?:\.\d+)?[kKmM]\)/g);o?t.tokens=an(o[1])+an(o[2]):i&&(t.tokens=an(i[1]));const a=Je(e,/\$(\d+\.\d{2})\b/g);return a&&(t.cost=parseFloat(a[1])),t}const yo=e=>{let t=Dt.get(e);return t||(t={tail:"",timer:null,metrics:te(mo)},Dt.set(e,t)),t},bo=e=>yo(e).metrics,Ji=e=>{e.timer=null;const t=e.metrics.value,r={...t,...qi(e.tail)};(r.context!==t.context||r.tokens!==t.tokens||r.cost!==t.cost)&&(e.metrics.value=r)};function Gi(e,t){const r=yo(e);r.tail=(r.tail+t.slice(-4e3*2).replace(Ki,"")).slice(-4e3),r.timer||(r.timer=setTimeout(()=>Ji(r),Ui))}function Vi(e){const t=Dt.get(e);t&&(t.timer&&clearTimeout(t.timer),t.metrics.value=mo,Dt.delete(e))}const ko=e=>e>=1e6?`${(e/1e6).toFixed(e>=1e7?0:1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:String(e),wo=e=>`$${e.toFixed(2)}`,ct=te(null),Yi=6e4;let Ge=null,Ve=null,sn=0;function yr(e=!1){return Ge||(Ge=fetch(`/api/cw/usage${e?"?fresh=1":""}`).then(t=>t.json()).catch(()=>({available:!1,reason:"Could not reach the Forge server"})).then(t=>(ct.value=t,Ge=null,t)),Ge)}function _o(){return sn+=1,yr(),Ve||(Ve=setInterval(()=>{document.visibilityState==="visible"&&yr()},Yi)),()=>{sn-=1,sn===0&&Ve&&(clearInterval(Ve),Ve=null)}}const Qi=(e,t)=>{var r;return((r=ct.value)!=null&&r.available?ct.value.usage.find(o=>o.account===e&&o.harness===t):null)??null},Te=te({}),br=te(null),So=2e3,Zi=15e3;let Ye=null,Co=0,ln=!1;const Tt=new Set,Xi=(e,t)=>!!e&&Oe(t)&&(e.state!==t.state||e.since!==t.since);async function $o(){if(!ln){ln=!0,Co=Date.now();try{const e=await fetch("/api/cw/session-states");if(!e.ok)return;const{states:t}=await e.json(),r=Te.value;Te.value=t;for(const[o,i]of Object.entries(t))if(Xi(r[o],i))for(const a of Tt)a(o,i)}catch{}finally{ln=!1}}}const ea=()=>{const e=document.visibilityState==="visible"?So:Zi;Date.now()-Co>=e-100&&$o()};function ta(e){return Tt.add(e),Ye||($o(),Ye=setInterval(ea,So)),()=>{Tt.delete(e),Tt.size===0&&Ye&&(clearInterval(Ye),Ye=null)}}const To="forge.notify-sessions",Jt=typeof window<"u"&&"Notification"in window,na=()=>{try{return Jt&&Notification.permission==="granted"&&localStorage.getItem(To)==="1"}catch{return!1}},qn=te(na());async function ra(e){if(e&&(!Jt||(Notification.permission==="default"?await Notification.requestPermission():Notification.permission)!=="granted"))return!1;qn.value=e;try{localStorage.setItem(To,e?"1":"0")}catch{}return!0}function oa(e,t,r,o){if(!qn.value||!Jt||Notification.permission!=="granted")return;const i=new Notification(e,{body:t,tag:r});i.onclick=()=>{window.focus(),o(),i.close()}}const Ro=[{view:"list",label:"Tasks",glyph:"T",token:"--blue"},{view:"accounts",label:"Accounts",glyph:"A",token:"--purple"},{view:"skills",label:"Skills",glyph:"S",token:"--green"},{view:"prototypes",label:"Prototypes",glyph:"P",token:"--orange"}],ia="flex items-center w-full text-left cursor-pointer transition-all duration-180 ease-spring hover:bg-elev",aa=e=>({borderRadius:"9px",border:`1px solid ${e?"var(--hair)":"transparent"}`,background:e?"var(--card)":"transparent",boxShadow:e?"var(--shadow-s)":"none",color:"var(--ink)"}),zo="flex flex-col text-left cursor-pointer transition-all duration-180 ease-spring hover:-translate-y-px hover:shadow-m",Sn={gap:"6px",padding:"9px 10px",borderRadius:"12px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",color:"var(--ink)"},Cn={fontSize:"10.5px",color:"var(--ink-3)"},kr=({children:e})=>n("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--ink-3)",letterSpacing:".02em"},children:e}),sa=({id:e,session:t,index:r,onOpen:o})=>{const i=bo(e).value,a=Te.value[e],l=Oe(a),s=t.type==="loop",p=(i==null?void 0:i.context)??null,[d,h]=r%2===0?["var(--blue)","var(--purple)"]:["var(--purple)","var(--blue)"],c=l?Wt(a):s?t.loop_interval?`every ${t.loop_interval}`:"self-paced":i&&(i.tokens!==null||i.cost!==null)?[i.tokens!==null?`${ko(i.tokens)} tokens`:null,i.cost!==null?wo(i.cost):null].filter(Boolean).join(" · "):ue(t)||t.account;return n("button",{type:"button",class:zo,style:l?{...Sn,borderColor:`var(${$t(a)})`}:Sn,onClick:o,title:a?Wt(a):void 0,children:[n("span",{class:"flex items-center w-full",style:{gap:"6px"},children:[n($e,{size:6,color:a?`var(${$t(a)})`:d,live:!a||a.state==="working"||l}),n("span",{class:"truncate",style:{fontSize:"12.5px",fontWeight:600},children:he(t)}),n("span",{class:"flex-1"}),n("span",{class:"mono",style:{fontSize:"11px",color:"var(--ink-2)"},children:p!==null?`${Math.round(p)}%`:"—"})]}),n("span",{class:"relative block w-full overflow-hidden",style:{height:"5px",borderRadius:"99px",background:"var(--elev)"},children:[n("span",{class:"block h-full",style:{width:`${p??0}%`,borderRadius:"99px",background:`linear-gradient(90deg, ${d}, ${h})`,transition:"width .6s var(--ease)"}}),n("span",{class:"absolute inset-y-0 left-0",style:{width:"30%",background:"linear-gradient(90deg, transparent, rgba(255,255,255,.22), transparent)",animation:"sweep 2.6s ease-in-out infinite"}})]}),n("span",{class:"mono truncate w-full",style:l?{...Cn,color:`var(${$t(a)})`,fontWeight:600}:Cn,children:c})]})},la=()=>n("label",{class:"flex items-center justify-between",style:{gap:"8px",padding:"0 9px",fontSize:"12px",color:"var(--ink-2)"},children:[n("span",{class:"sb-label",children:"Notify when a session needs me"}),n(no,{checked:qn.value,label:"Notify when a session needs me",onChange:e=>{ra(e).then(t=>{t||P("The browser blocked notifications for Forge","error")})}})]}),ca=({account:e,harness:t,windows:r,stale:o,onOpen:i})=>{const a=r.reduce((s,p)=>p.percent>s.percent?p:s),l=fe(t).label;return n("button",{type:"button",class:zo,style:Sn,onClick:i,title:`Usage limits for ${e} on ${l}`,children:[n("span",{class:"flex items-center w-full",style:{gap:"6px"},children:[n("span",{class:"truncate",style:{fontSize:"12.5px",fontWeight:600},children:e}),n("span",{class:"flex-1"}),n("span",{class:"mono truncate",style:{fontSize:"10px",color:"var(--ink-3)"},children:l})]}),n(ro,{bars:uo(r),size:"sm"}),n("span",{class:"mono truncate w-full",style:Cn,children:o?"last known values":po(a.resetsAt)})]})},da=({view:e,counts:t,projects:r,accounts:o,selectedProject:i,live:a,onNavigate:l,onSelectProject:s,onAddProject:p,onOpenLive:d,onSearch:h})=>{var b,f;const c=(b=We.value)!=null&&b.available?We.value.doctor.cw_version:null,m=Ro.map(u=>{var x;return{...u,count:u.view==="skills"?((x=ot.value)==null?void 0:x.length)??null:t[u.view]??null}});F(()=>_o(),[]);const k=[...a].sort((u,x)=>Number(Oe(Te.value[x.key]))-Number(Oe(Te.value[u.key]))),g=(f=ct.value)!=null&&f.available?ct.value.usage.filter(u=>u.state==="ok"&&u.windows.some(x=>!x.scope)):[];return n("aside",{class:`forge-sidebar flex flex-col${Se.value?" open":""}`,"aria-label":"Sidebar",style:{position:"sticky",top:0,height:"100vh",overflowY:"auto",overscrollBehavior:"contain",gap:"18px",padding:"14px 10px 12px",background:"var(--bg-2)",borderRight:"1px solid var(--hair)"},children:[n("div",{role:"button",tabIndex:0,class:"flex items-center cursor-pointer",style:{gap:"9px",padding:"2px 8px"},onClick:()=>l("list"),onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&l("list")},children:[n("span",{class:"grid place-items-center shrink-0",style:{width:"22px",height:"22px",borderRadius:"7px",background:"linear-gradient(160deg, var(--blue), var(--purple))",boxShadow:"var(--shadow-s)",fontSize:"12px",fontWeight:700,color:"#fff"},children:"F"}),n("span",{class:"sb-label",style:{fontSize:"15px",fontWeight:600,letterSpacing:"-0.015em"},children:"Forge"}),n("span",{class:"flex-1 sb-label"}),c&&n("span",{class:"mono sb-label",style:{fontSize:"10px",color:"var(--ink-3)"},title:"CW version",children:c})]}),h&&n("button",{type:"button",class:"flex items-center text-left cursor-pointer transition-all duration-180 ease-spring text-ink2 hover:text-ink hover:border-hair2 hover:-translate-y-px hover:shadow-m",style:{gap:"8px",padding:"6px 9px",borderRadius:"9px",border:"1px solid var(--hair)",background:"var(--card)",fontSize:"12.5px",boxShadow:"var(--shadow-s)"},onClick:h,"aria-label":"Search (⌘K)",children:[n("span",{class:"i-lucide-search shrink-0",style:{width:"13px",height:"13px",opacity:.7}}),n("span",{class:"flex-1 sb-label",children:"Search"}),n("kbd",{class:"sb-label",style:{fontSize:"10px",padding:"1px 5px",borderRadius:"5px",background:"var(--elev)",border:"1px solid var(--hair)"},children:"⌘K"})]}),n("nav",{class:"flex flex-col",style:{gap:"2px"},"aria-label":"Sections",children:m.map(u=>{const x=e===u.view;return n("button",{type:"button","aria-current":x?"page":void 0,title:u.label,class:ia,style:{...aa(x),gap:"9px",height:"32px",padding:"0 9px",fontSize:"13.5px",fontWeight:x?600:450},onClick:()=>l(u.view),children:[n("span",{class:"grid place-items-center shrink-0",style:{width:"18px",height:"18px",borderRadius:"5px",fontSize:"10px",fontWeight:600,background:x?se(u.token):"var(--elev)",color:x?`var(${u.token})`:"var(--ink-3)"},children:u.glyph}),n("span",{class:"flex-1 sb-label",children:u.label}),u.count!==null&&n("span",{class:"mono sb-label",style:{fontSize:"11px",color:"var(--ink-3)"},children:u.count})]},u.view)})}),n(Hi,{projects:r,accounts:o,selected:i,onSelect:s,onAdd:p}),n("div",{class:"flex flex-col",style:{marginTop:"auto",flex:"none",gap:"8px"},children:[a.length>0&&n("div",{class:"flex flex-col sb-section",style:{gap:"8px"},children:[n("span",{style:{padding:"0 9px"},children:n(kr,{children:"Live now"})}),k.map((u,x)=>n(sa,{id:u.key,session:u.session,index:x,onOpen:()=>d(u.session)},u.key))]}),g.length>0&&n("div",{class:"flex flex-col sb-section",style:{gap:"8px"},children:[n("span",{style:{padding:"0 9px"},children:n(kr,{children:"Limits"})}),g.map(u=>n(ca,{account:u.account,harness:u.harness,windows:u.windows.filter(x=>!x.scope),stale:u.stale,onOpen:()=>l("accounts")},`${u.account}/${u.harness}`))]}),Jt&&n("div",{class:"sb-section",children:n(la,{})}),n("div",{class:"sb-section",children:n(ve,{fill:!0,size:"xs",label:"Appearance",tabs:[{id:"light",label:"Light"},{id:"dark",label:"Dark"}],active:ut.value,onChange:u=>io(u==="light"?"light":"dark")})})]})]})};function Gt(){const e=X(null);return F(()=>{var t;(t=e.current)==null||t.focus()},[]),e}const wr=(e,t,r)=>{const o=Hn(e.type);return{id:K(e),label:ue(e)?`${he(e)} · ${ue(e)}`:he(e),hint:t,glyph:o.glyph,token:o.token,run:()=>r(e)}},pa=({openTabs:e,sessions:t,projects:r,commands:o,onOpenSession:i,onSelectProject:a,onClose:l})=>{const[s,p]=w(""),[d,h]=w(0),c=X(null),m=Gt(),k=Q(()=>{const v=s.trim().toLowerCase(),C=I=>!v||I.label.toLowerCase().includes(v),y=new Set(e.map(K)),R=e.map((I,S)=>wr(I,S<5?`⌘${S+1}`:"open",i)),A=t.filter(I=>I.status==="active"&&!y.has(K(I))).map(I=>wr(I,"resume",i)),L=v?r.map(I=>({id:`project:${I}`,label:I,hint:"project",glyph:"P",token:"--green",run:()=>a(I)})):[];return[{name:"Live now",items:R.filter(C)},{name:"Tasks",items:A.filter(C).slice(0,v?12:6)},{name:"Projects",items:L.filter(C).slice(0,6)},{name:"Commands",items:o.filter(C)}].filter(I=>I.items.length>0)},[s,e,t,r,o,i,a]),g=k.flatMap(v=>v.items),b=Math.min(d,g.length-1);F(()=>{var v,C;(C=(v=c.current)==null?void 0:v.querySelector('[data-active="true"]'))==null||C.scrollIntoView({block:"nearest"})},[b]);const f=v=>{v&&(l(),v.run())},u=X({flat:g,current:b,activate:f});u.current={flat:g,current:b,activate:f},F(()=>{const v=C=>{const{flat:y,current:R,activate:A}=u.current,L=y.length;C.key==="ArrowDown"?(C.preventDefault(),h(I=>L?(Math.min(I,L-1)+1)%L:0)):C.key==="ArrowUp"?(C.preventDefault(),h(I=>L?(Math.min(I,L-1)-1+L)%L:0)):C.key==="Enter"?(C.preventDefault(),A(y[R])):C.key==="Escape"&&(C.preventDefault(),l())};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[l]);let x=-1;return n("div",{class:"fixed inset-0 z-[60] flex justify-center items-start overflow-auto",style:{background:"rgba(0,0,0,.42)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",padding:"88px 16px 16px"},onClick:l,children:n("div",{role:"dialog","aria-modal":"true","aria-label":"Command palette",class:"flex flex-col overflow-hidden",style:{width:"min(560px, 100%)",maxHeight:"calc(100vh - 104px)",borderRadius:"18px",background:"var(--glass)",backdropFilter:"blur(30px) saturate(180%)",WebkitBackdropFilter:"blur(30px) saturate(180%)",border:"1px solid var(--hair-2)",boxShadow:"var(--shadow-l)",animation:"popIn .26s var(--ease) both"},onClick:v=>v.stopPropagation(),children:[n("input",{ref:m,role:"combobox","aria-expanded":"true","aria-controls":"palette-list","aria-activedescendant":g[b]?`palette-${g[b].id}`:void 0,"aria-label":"Search tasks, projects and commands",class:"shrink-0",style:{height:"48px",padding:"0 16px",border:0,borderBottom:"1px solid var(--hair)",background:"transparent",color:"var(--ink)",fontSize:"16px",outline:"none"},placeholder:"Task, project, skill or command…",value:s,onInput:v=>{p(v.target.value),h(0)}}),n("div",{id:"palette-list",role:"listbox",ref:c,class:"overflow-auto",style:{padding:"6px"},children:[g.length===0&&n("p",{style:{padding:"14px 10px",fontSize:"13px",color:"var(--ink-2)"},children:["Nothing matches “",s,"”."]}),k.map(v=>n("div",{role:"group","aria-label":v.name,children:[n("div",{style:{padding:"7px 10px 3px",fontSize:"11px",fontWeight:600,color:"var(--ink-3)"},children:v.name}),v.items.map(C=>{x+=1;const y=x,R=y===b;return n("button",{id:`palette-${C.id}`,type:"button",role:"option","aria-selected":R,"data-active":R,tabIndex:-1,class:"flex items-center w-full text-left cursor-pointer",style:{gap:"10px",padding:"8px 10px",borderRadius:"10px",border:0,background:R?"var(--elev)":"transparent",color:"var(--ink)",fontSize:"13px",transition:"background .14s"},onMouseMove:()=>{R||h(y)},onClick:()=>f(C),children:[n("span",{class:"grid place-items-center shrink-0",style:{width:"22px",height:"22px",borderRadius:"7px",fontSize:"10px",fontWeight:700,background:C.token?se(C.token):"var(--elev)",color:C.token?`var(${C.token})`:"var(--ink-2)"},children:C.glyph}),n("span",{class:"flex-1 min-w-0 truncate",children:C.label}),n("span",{class:"mono shrink-0",style:{fontSize:"10.5px",color:"var(--ink-3)"},children:C.hint})]},C.id)})]},v.name))]}),n("div",{class:"flex shrink-0",style:{gap:"14px",padding:"8px 14px",borderTop:"1px solid var(--hair)"},children:["↑↓ move","↵ open","esc close"].map(v=>n("span",{class:"mono",style:{fontSize:"10.5px",color:"var(--ink-3)"},children:v},v))})]})})},$n=te(null);let cn=null;function jo(){return cn||(cn=fetch("/api/cw/editors").then(e=>e.json()).then(e=>{$n.value=e}).catch(()=>{$n.value={enabled:!1,editors:[]}})),cn}async function ua(e,t){const r=await fetch("/api/cw/open-in-editor",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:e.project,sessionDir:qt(e),editor:t})}),o=await r.json().catch(()=>({ok:!1,error:`HTTP ${r.status}`}));if(!r.ok||!o.ok)throw new Error(o.error??"Could not open the editor")}const dt=e=>e.unpushed??e.commits??0,Po={OPEN:"open",MERGED:"merged",CLOSED:"closed"},ha={passing:"✓",failing:"✗",pending:"…",none:""};function fa(e){if(e.workspace==="missing")return"Workspace not created yet";if(e.closeWarnings.includes("state-unknown")&&e.branch===null)return"Changes unknown";const t=[];e.diff&&e.diff.files>0&&t.push(`+${e.diff.insertions} −${e.diff.deletions} · ${e.diff.files} file${e.diff.files===1?"":"s"}`),e.uncommitted>0&&t.push(`${e.uncommitted} uncommitted`);const r=dt(e);if(r>0&&t.push(`${r} unpushed`),e.pr.status==="found"){const o=e.pr.state==="OPEN"&&e.pr.isDraft?"draft":Po[e.pr.state];t.push(`PR #${e.pr.number} ${o}`),e.pr.checks!=="none"&&t.push(`checks ${ha[e.pr.checks]}`),e.pr.review==="APPROVED"&&t.push("approved"),e.pr.review==="CHANGES_REQUESTED"&&t.push("changes requested")}return t.length>0?t.join(" · "):e.workspace==="ready"?"No changes yet":""}const va={passing:"checks pass",failing:"checks failing",pending:"checks running",none:""},_r=(e,t)=>`${e} ${t}${e===1?"":"s"}`;function xa(e){if(e.workspace==="missing")return"not created yet";if(e.pr.status==="found"){const o=e.pr.state==="OPEN"&&e.pr.isDraft?"draft":Po[e.pr.state];return[`PR #${e.pr.number} ${o}`,va[e.pr.checks]].filter(Boolean).join(" · ")}const t=[];e.diff&&e.diff.files>0&&t.push(_r(e.diff.files,"file")),e.commits&&t.push(_r(e.commits,"commit"));const r=dt(e);return r>0&&e.commits&&t.push(`${r} unpushed`),e.uncommitted>0&&t.push(`${e.uncommitted} uncommitted`),t.length>0?t.join(" · "):"no changes yet"}async function Xe(e,t){const r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),o=await r.json().catch(()=>({}));if(!r.ok||o.error)throw new Error(o.error??`Request failed (${r.status})`);return o}const Rt=e=>e instanceof Error?e.message:String(e);function Jn(e,t){navigator.clipboard.writeText(e).then(()=>P(`${t} copied`,"info"),()=>P(`Could not copy the ${t.toLowerCase()}`,"error"))}const ga=({session:e,muted:t})=>{const r=fe(e.harness);return n("span",{class:`harness-pill inline-flex items-center shrink-0 whitespace-nowrap${t?" opacity-60":""}`,style:{gap:"6px",padding:"3px 9px",borderRadius:"99px",background:r.bg,color:r.color,fontSize:"11.5px",fontWeight:600},children:[n("span",{style:{width:"6px",height:"6px",borderRadius:"50%",background:r.color}}),lo(e)]})},Tn=te({}),Lo=te(0),ma=6e4,mt=new Map,Ao=e=>`${e.project}::${qt(e)}`;function Rn(e,t=!1){const r=Ao(e),o=mt.get(r);if(o&&!t)return o;const i=`/api/cw/review-state/${encodeURIComponent(e.project)}/${encodeURIComponent(qt(e))}${t?"?fresh=1":""}`,a=fetch(i).then(async l=>l.ok?{state:await l.json(),error:null}:{state:null,error:`Forge could not read this task (HTTP ${l.status})`}).catch(()=>({state:null,error:"Could not reach the Forge server"})).then(l=>(Tn.value={...Tn.value,[r]:l},mt.get(r)===a&&mt.delete(r),l));return mt.set(r,a),a}function ya(){Lo.value++}function Eo(e,{poll:t=!1}={}){const r=Ao(e),o=Lo.value;return F(()=>{if(Rn(e),!t)return;const i=setInterval(()=>{Rn(e,!0)},ma);return()=>clearInterval(i)},[r,t,o]),Tn.value[r]??null}const zn=({type:e,size:t=28,radius:r=9,font:o=11})=>{const i=Hn(e);return n("span",{class:"grid place-items-center shrink-0",title:i.label,style:{width:`${t}px`,height:`${t}px`,borderRadius:`${r}px`,background:i.fill,color:i.ink,fontSize:`${o}px`,fontWeight:700},children:i.glyph})},ba=()=>n("span",{class:"inline-flex items-center shrink-0",style:{gap:"5px",padding:"1px 8px",borderRadius:"99px",background:se("--green"),color:"var(--green)",fontSize:"11px",fontWeight:600},children:[n($e,{size:5,color:"var(--green)",live:!0,glow:!1}),"live"]}),ka=({label:e,href:t})=>{const r={padding:"1px 7px",borderRadius:"99px",background:"var(--elev)",border:"1px solid var(--hair)",color:"var(--ink-2)",fontSize:"11px"};return t?n("a",{class:"shrink-0 hover:text-ink",style:r,href:t,target:"_blank",rel:"noopener noreferrer",onClick:o=>o.stopPropagation(),children:e}):n("span",{class:"shrink-0",style:r,children:e})},Io=e=>e.type==="review"?`review/pr-${e.pr}`:e.type==="loop"?`loop/${e.task??"loop"}`:e.type==="task"?`task/${e.task}`:null,wa=({session:e,project:t})=>{var a;const r=Eo(e),o=((a=r==null?void 0:r.state)==null?void 0:a.branch)??Io(e),i=r?r.error!==null?"changes unknown":xa(r.state):"checking…";return n(No,{branch:o,status:i,project:t})},No=({branch:e,status:t,project:r})=>n("div",{class:"task-meta flex items-center min-w-0",style:{gap:"9px",marginTop:"2px"},children:[r&&n("span",{class:"shrink-0",style:{fontSize:"12px",fontWeight:600,color:"var(--ink-2)"},children:r}),e===null?n("span",{class:"mono",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:"—"}):n("button",{type:"button",class:"mono truncate min-w-0 cursor-copy hover:text-ink transition-colors duration-160",style:{fontSize:"11.5px",color:"var(--ink-3)",padding:0,border:0,background:"transparent"},title:"Copy branch name",onClick:o=>{o.stopPropagation(),Jn(e,"Branch")},onKeyDown:o=>o.stopPropagation(),children:e}),n("span",{class:"whitespace-nowrap truncate",style:{fontSize:"12px",color:"var(--ink-2)"},children:t})]}),_a=e=>e.type==="loop"?e.loop_interval?`every ${e.loop_interval}`:"self-paced":`${e.opens} session${e.opens===1?"":"s"}`,Oo=({session:e,isOpenInTab:t,onSelect:r,onMarkDone:o,showProject:i})=>{const a=i?ue(e)||"no project":void 0,[l,s]=w(!1),p=e.type==="task"||e.type==="review",d=async()=>{if(!(!o||l)){s(!0);try{await o()}finally{s(!1)}}};return n("div",{class:"task-row group flex items-center cursor-pointer transition-colors duration-160 hover:bg-elev",style:{gap:"13px",padding:"11px 15px",borderBottom:"1px solid var(--hair)"},onClick:r,role:"button",tabIndex:0,"aria-label":`${t?"Open":"Resume"} ${he(e)}`,onKeyDown:h=>{h.target===h.currentTarget&&(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),r())},children:[n(zn,{type:e.type}),n("div",{class:"flex-1 min-w-0",children:[n("div",{class:"flex items-center min-w-0",style:{gap:"8px"},children:[n("span",{class:"truncate",style:{fontSize:"14px",fontWeight:600},children:he(e)}),t&&e.status==="active"&&n(ba,{}),e.source&&n("span",{class:"task-chip contents",children:n(ka,{label:e.source,href:e.source_url})})]}),p?n(wa,{session:e,project:a}):n(No,{branch:Io(e),status:_a(e),project:a})]}),n(ga,{session:e}),n("span",{class:"mono shrink-0 text-right",style:{width:"52px",fontSize:"11.5px",color:"var(--ink-3)"},title:new Date(e.last_opened).toLocaleString(),children:so(e.last_opened)}),o&&n("button",{type:"button",class:`task-done grid place-items-center shrink-0 cursor-pointer transition-all duration-180 ease-spring hover:text-green disabled:cursor-wait ${l?"":"opacity-0 group-hover:opacity-100 focus-visible:opacity-100"}`,style:{width:"28px",height:"28px",borderRadius:"9px",border:"1px solid var(--hair)",background:"var(--card)",color:"var(--ink-2)"},onClick:h=>{h.stopPropagation(),d()},disabled:l,title:l?"Closing…":"Mark done","aria-label":"Mark done",children:n("span",{class:l?"i-lucide-loader-2 animate-spin":"i-lucide-check",style:{width:"14px",height:"14px"}})}),n("span",{class:"shrink-0 whitespace-nowrap",style:t?{padding:"5px 11px",borderRadius:"9px",background:"linear-gradient(180deg, var(--blue-2), var(--blue))",color:"#fff",fontSize:"12.5px",fontWeight:600,boxShadow:"var(--shadow-m)"}:{padding:"5px 11px",borderRadius:"9px",background:"var(--elev)",color:"var(--ink)",fontSize:"12.5px",fontWeight:600},children:t?"Open":"Resume"})]})},Sa=({session:e,onSelect:t})=>n("div",{class:"flex items-center cursor-pointer transition-colors duration-160 hover:bg-elev",style:{gap:"12px",padding:"9px 15px",borderBottom:"1px solid var(--hair)",color:"var(--ink-2)"},onClick:t,role:"button",tabIndex:0,onKeyDown:r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),t())},children:[n("span",{class:"grid place-items-center shrink-0",style:{width:"22px",height:"22px",borderRadius:"7px",background:"var(--elev)"},children:n("span",{class:"i-lucide-check",style:{width:"12px",height:"12px"}})}),n("span",{class:"flex-1 min-w-0 truncate",style:{fontSize:"13px"},children:[he(e)," ",n("span",{class:"mono",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:ue(e)})]}),n("span",{class:"mono shrink-0",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:so(e.closed??e.last_opened)})]}),Ca=({project:e,account:t,accounts:r,onDeleted:o,onMoved:i})=>{const[a,l]=w(null),[s,p]=w(null),[d,h]=w(!1),[c,m]=w(!1),[k,g]=w(""),[b,f]=w(!1),u=(r??[]).filter(_=>_!==t);F(()=>{let _=!1;return fetch(`/api/cw/mcps?project=${encodeURIComponent(e)}`).then(N=>N.json()).catch(()=>null).then(N=>{_||l(N)}),()=>{_=!0}},[e]);const x=a?Object.keys(a.global):[],v=(a==null?void 0:a.project)??[],C=(a==null?void 0:a.cw)??[],y=(a==null?void 0:a.plugins)??[],R=[...v.map(_=>`${_} (project)`),...x,...C.map(_=>`${_} (CW)`)],A=_=>{p(s===_?null:_),g(""),h(!1)},L=async()=>{m(!0);try{(await(await fetch("/api/cw/delete-project",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:e,deleteFiles:d})})).json()).ok&&(P(`Project "${e}" deleted${d?" (files removed)":""}`,"info"),o==null||o())}catch{P("Failed to delete project","error")}finally{m(!1),p(null)}},I=async()=>{if(k){f(!0);try{const N=await(await fetch("/api/cw/move-project",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:e,toAccount:k})})).json();N.ok?(P(`Project "${e}" moved to "${k}"`,"success"),p(null),g(""),i==null||i()):P(N.error??"Failed to move project","error")}catch{P("Failed to move project","error")}finally{f(!1)}}};if(!a)return null;const S={padding:"12px 15px",borderTop:"1px solid var(--hair)",display:"flex",flexDirection:"column",gap:"10px"},z=(_,N)=>({padding:"5px 11px",borderRadius:"9px",border:"1px solid var(--hair)",fontSize:"12.5px",fontWeight:500,background:N?"var(--elev)":"var(--card)",color:_==="red"?"var(--red)":"var(--ink)",boxShadow:"var(--shadow-s)"});return n("section",{style:{borderRadius:"16px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",overflow:"hidden"},"aria-label":"Project settings",children:[n("div",{class:"flex items-center flex-wrap",style:{padding:"10px 15px",gap:"8px 12px"},children:[n("div",{class:"flex-1 min-w-0 flex flex-col",style:{gap:"2px",fontSize:"12.5px",color:"var(--ink-2)"},children:[R.length>0&&n("span",{class:"truncate",title:R.join(", "),children:["MCP · ",R.join(", ")]}),y.length>0&&n("span",{class:"truncate",title:y.join(", "),children:["Plugins · ",y.join(", ")]}),R.length===0&&y.length===0&&n("span",{children:"No MCPs or plugins for this project"})]}),u.length>0&&n("button",{type:"button",class:"cursor-pointer",style:z("ink",s==="move"),"aria-expanded":s==="move",onClick:()=>A("move"),children:"Move to account"}),n("button",{type:"button",class:"cursor-pointer",style:z("red",s==="delete"),"aria-expanded":s==="delete",onClick:()=>A("delete"),children:"Delete project"})]}),s==="move"&&n("div",{style:S,children:[n("p",{style:{fontSize:"13px"},children:['Move "',e,'" to a different account.']}),n("select",{class:"field",value:k,onChange:_=>g(_.target.value),children:[n("option",{value:"",children:"Select account…"}),u.map(_=>n("option",{value:_,children:_},_))]}),n("div",{class:"flex",style:{gap:"8px"},children:[n(D,{label:b?"Moving…":"Move project",variant:"primary",size:"sm",loading:b,disabled:!k,onClick:I}),n(D,{label:"Cancel",variant:"secondary",size:"sm",onClick:()=>{p(null),g("")}})]})]}),s==="delete"&&n("div",{style:S,children:[n("p",{style:{fontSize:"13px"},children:['This unregisters "',e,'" from CW.']}),n("label",{class:"flex items-center cursor-pointer",style:{gap:"8px",fontSize:"12.5px",color:"var(--ink-2)"},children:[n("input",{type:"checkbox",checked:d,onChange:_=>h(_.target.checked)}),"Also delete project files from disk"]}),d&&n("p",{style:{fontSize:"12.5px",color:"var(--red)"},children:"This permanently deletes all files. It cannot be undone."}),n("div",{class:"flex",style:{gap:"8px"},children:[n(D,{label:c?"Deleting…":d?"Delete project and files":"Unregister project",variant:"destructive",size:"sm",loading:c,onClick:L}),n(D,{label:"Cancel",variant:"secondary",size:"sm",onClick:()=>{p(null),h(!1)}})]})]})]})},Wo=e=>e.trim().replace(/\s+/g,"-").toLowerCase();function Vt(e){const t=e.trim();return t?/github\.com\/.+\/pull\/\d+/.test(t)||/^#?\d{1,6}$/.test(t)?{kind:"pr",type:"review"}:/linear\.app/.test(t)?{kind:"linear",type:"dev"}:/notion\.(so|site)/.test(t)?{kind:"notion",type:"dev"}:{kind:"name",type:"dev",slug:Wo(t)}:null}const $a="A PR link becomes a review. A Linear or Notion link becomes a dev task with its notes.";function Ta(e,t){const r=Vt(e),o=t.project?` on ${t.project}`:"";if(t.type==="general")return{text:`General session as ${t.account||"an account"}${t.project?` in ${t.project}`:", outside any project"}, run by ${t.harness}.`,ready:!!t.account};if(!t.project)return{text:"Pick a project to start.",ready:!1};if(!r)return{text:$a,ready:!1};if(t.type==="loop")return{text:`Loop${o} — pick its interval in the next step.`,ready:!0};if(t.type==="review")return{text:r.kind==="pr"?`Pull request detected — this becomes a review${o}, run by ${t.harness}.`:`Review of “${e.trim()}”${o}, run by ${t.harness}.`,ready:!0};switch(r.kind){case"linear":return{text:"Linear ticket detected — a dev task, and the ticket lands in TASK_NOTES.md first.",ready:!0};case"notion":return{text:"Notion page detected — a dev task, and the page lands in TASK_NOTES.md first.",ready:!0};case"pr":return{text:`Dev task${o} from pull request ${e.trim()}, run by ${t.harness}.`,ready:!0};case"name":return{text:`Dev task${o} · branch task/${r.slug}`,ready:!0}}}const Gn=(e,t)=>{var r;return t??((r=Vt(e))==null?void 0:r.type)??"dev"},me=te(""),De=te(null),Ie=te(""),Ft=te(""),Mt=e=>{me.value=e,De.value=null},Vn=(e,t,r)=>r&&e!=="claude"?"Loop uses Claude Code's /loop":(t==null?void 0:t.status)==="not_installed"?typeof t.detail=="string"&&t.detail?t.detail:"Not installed":null,Ra=(e,t,r,o,i)=>{var s;if(i)return i;if((r==null?void 0:r.status)==="not_logged_in")return"Not logged in";if((r==null?void 0:r.status)==="error"&&typeof r.detail=="string")return r.detail;const a=(s=e.harnesses.find(p=>p.name===t))==null?void 0:s.version,l=r==null?void 0:r.model;return[o?"Default":a,l].filter(Boolean).join(" · ")||(o?"Default":"")},za=({doctor:e,account:t,value:r,defaultHarness:o,isLoop:i,onChange:a,onOpenAccounts:l})=>n("div",{class:"flex flex-col",style:{gap:"6px"},role:"radiogroup","aria-label":"Harness",children:[n("span",{style:{fontSize:"12px",color:"var(--ink-2)"},children:"Harness · this task only"}),n("div",{class:"grid",style:{gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:"8px"},children:e.harnesses.map(s=>{const p=Ce(e,t,s.name),d=Vn(s.name,p,i),h=fe(s.name),c=r===s.name,m=(p==null?void 0:p.status)==="not_logged_in",k=Ra(e,s.name,p,s.name===o,d);return n("div",{role:"radio","aria-checked":c,tabIndex:d?-1:0,"aria-disabled":!!d,title:d??void 0,class:`flex items-start transition-all duration-180 ease-spring ${d?"cursor-not-allowed":"cursor-pointer hover:bg-elev"}`,style:{gap:"9px",padding:"10px 11px",borderRadius:"12px",border:`1px solid ${c?"var(--blue)":"var(--hair)"}`,background:c?se("--blue"):"var(--card)",boxShadow:c?"var(--shadow-s)":"none",opacity:d?.45:1},onClick:()=>{d||a(s.name)},onKeyDown:g=>{!d&&(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),a(s.name))},children:[n("span",{class:"shrink-0",style:{width:"8px",height:"8px",borderRadius:"50%",marginTop:"5px",background:h.color,boxShadow:c?`0 0 8px ${h.color}`:"none"}}),n("span",{class:"flex flex-col min-w-0",children:[n("span",{style:{fontSize:"12.5px",fontWeight:600},children:h.label}),n("span",{class:"truncate",style:{fontSize:"11.5px",color:"var(--ink-2)"},title:k,children:k}),m&&l&&n("button",{type:"button",class:"self-start cursor-pointer",style:{border:0,background:"none",padding:0,color:"var(--blue)",fontSize:"11.5px",fontWeight:600},onClick:g=>{g.stopPropagation(),l()},onKeyDown:g=>g.stopPropagation(),children:"Connect"})]})]},s.name)})})]}),ja=({options:e,value:t,label:r,onPick:o,onClose:i})=>{const[a,l]=w(""),[s,p]=w(0),d=Gt(),h=X(null),c=a.trim().toLowerCase(),m=Q(()=>e.filter(b=>{var f;return!c||b.label.toLowerCase().includes(c)||((f=b.group)==null?void 0:f.toLowerCase().includes(c))}),[e,c]);F(()=>{const b=m.findIndex(f=>f.value===t);p(b>=0&&!c?b:0)},[c]),F(()=>{var b,f;(f=(b=h.current)==null?void 0:b.querySelector('[data-active="true"]'))==null||f.scrollIntoView({block:"nearest"})},[s]);const k=b=>{if(b.key==="ArrowDown")b.preventDefault(),p(f=>Math.min(f+1,m.length-1));else if(b.key==="ArrowUp")b.preventDefault(),p(f=>Math.max(f-1,0));else if(b.key==="Enter"){b.preventDefault();const f=m[s];f&&o(f.value)}else b.key==="Escape"&&(b.preventDefault(),b.stopPropagation(),i())};let g;return n("div",{class:"popover absolute right-0 top-full z-40 flex flex-col",style:{marginTop:"6px",width:"260px",maxHeight:"320px",padding:"6px",borderRadius:"12px",background:"var(--card-2)",backdropFilter:"none",WebkitBackdropFilter:"none"},onKeyDown:k,children:[n("label",{class:"relative block shrink-0",children:[n("span",{class:"i-lucide-search absolute pointer-events-none",style:{left:"9px",top:"9px",width:"12px",height:"12px",color:"var(--ink-3)"}}),n("input",{ref:d,type:"search",class:"field",role:"combobox","aria-expanded":"true","aria-label":`Search ${r.toLowerCase()}`,placeholder:`Search ${r.toLowerCase()}s`,value:a,style:{height:"30px",padding:"0 8px 0 27px",borderRadius:"8px",fontSize:"12.5px",background:"var(--elev)"},onInput:b=>l(b.target.value)})]}),n("div",{ref:h,role:"listbox","aria-label":r,class:"overflow-y-auto min-h-0",style:{marginTop:"6px"},children:[m.length===0&&n("p",{style:{padding:"8px 10px",fontSize:"12.5px",color:"var(--ink-3)"},children:["No match for “",a.trim(),"”."]}),m.map((b,f)=>{const u=b.group&&b.group!==g?b.group:null;g=b.group;const x=f===s,v=b.value===t;return n("div",{children:[u&&n("div",{style:{padding:"7px 9px 3px",fontSize:"11px",fontWeight:600,color:"var(--ink-3)"},children:u}),n("button",{type:"button",role:"option","aria-selected":v,"data-active":x,tabIndex:-1,class:"flex items-center w-full text-left cursor-pointer",style:{gap:"8px",padding:"6px 9px",borderRadius:"8px",border:0,background:x?"var(--elev)":"transparent",color:"var(--ink)",fontSize:"13px"},onMouseMove:()=>{x||p(f)},onClick:()=>o(b.value),children:[n("span",{class:"flex-1 truncate",style:{fontWeight:v?600:400,color:b.value?"var(--ink)":"var(--ink-2)"},children:b.label}),v&&n("span",{class:"i-lucide-check shrink-0",style:{width:"13px",height:"13px",color:"var(--blue)"}})]})]},b.value||"__empty")})]})]})},Do=({label:e,value:t,options:r,onChange:o,placeholder:i="Choose…",size:a="sm",width:l})=>{const[s,p]=w(!1),d=X(null),h=r.find(m=>m.value===t);return F(()=>{if(!s)return;const m=k=>{d.current&&!d.current.contains(k.target)&&p(!1)};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[s]),n("div",{ref:d,class:"relative",style:{width:l},children:[n("button",{type:"button","aria-haspopup":"listbox","aria-expanded":s,"aria-label":e,class:"field flex items-center text-left cursor-pointer",style:a==="sm"?{width:l??"auto",minWidth:"130px",maxWidth:"200px",height:"30px",padding:"0 9px 0 10px",borderRadius:"9px",fontSize:"12.5px",background:"var(--bg-2)",gap:"6px"}:{gap:"6px",boxShadow:"var(--shadow-s)"},onClick:()=>p(m=>!m),onKeyDown:m=>{m.key==="ArrowDown"&&(m.preventDefault(),p(!0))},children:[n("span",{class:"flex-1 truncate",style:{color:h&&h.value?"var(--ink)":"var(--ink-2)"},children:(h==null?void 0:h.label)??i}),n("span",{class:"i-lucide-chevrons-up-down shrink-0",style:{width:"12px",height:"12px",color:"var(--ink-3)"}})]}),s&&n(ja,{options:r,value:t,label:e,onPick:m=>{o(m),p(!1)},onClose:()=>p(!1)})]})},jn=(e,t,r=Object.keys(e))=>{const o=i=>{const a=t.indexOf(i);return a<0?t.length:a};return[...r].sort((i,a)=>o(e[i].account)-o(e[a].account)||i.localeCompare(a)).map(i=>({value:i,label:i,group:e[i].account}))},Fo=({ctx:e,size:t="md"})=>{const{text:r,ready:o}=Ta(me.value,{...e,harness:fe(e.harness).label}),i=o&&(e.type==="general"||Vt(me.value)!==null);return n("p",{class:"flex items-center min-w-0","aria-live":"polite",style:{gap:"7px",fontSize:t==="md"?"12.5px":"12px",color:i?"var(--blue)":"var(--ink-3)"},children:[i&&n("span",{class:"grid place-items-center shrink-0",style:{width:"16px",height:"16px",borderRadius:"50%",background:se("--blue",22)},children:n("span",{class:"i-lucide-check",style:{width:"10px",height:"10px"}})}),n("span",{class:"min-w-0",style:{overflowWrap:"anywhere"},children:r})]})},Mo=({fill:e})=>n(ve,{fill:e,label:"Task type",tabs:Ue.map(t=>({id:t.key,label:Un(t.key)})),active:Gn(me.value,De.value),onChange:t=>{De.value=t}}),Pa={width:"auto",maxWidth:"180px",height:"30px",padding:"0 26px 0 10px",borderRadius:"9px",fontSize:"12.5px",background:"var(--bg-2)"},La=({label:e,value:t,onChange:r,options:o})=>n("label",{class:"inline-flex items-center shrink-0",style:{gap:"6px",fontSize:"12px",color:"var(--ink-3)"},children:[e,n("select",{class:"field","aria-label":e,style:Pa,value:t,onChange:i=>r(i.target.value),children:o.map(i=>n("option",{value:i.value,children:i.label},i.value))})]}),Aa=({projects:e,accounts:t,onStarted:r,onOpenDrawer:o})=>{var v,C;const[i,a]=w(!1),l=We.value,s=l!=null&&l.available?l.doctor:null,p=Gn(me.value,De.value),d=p==="general",h=Ie.value,c=Object.keys(e).sort(),m=d?Ft.value||((v=e[h])==null?void 0:v.account)||t[0]||"":((C=e[h])==null?void 0:C.account)??"",k=c.filter(y=>e[y].account===m),g=p==="loop"?"claude":s?co(h||void 0,m,e,s):"claude",b=me.value.trim(),f=i||(d?!m:!b||!h),u=async()=>{if(f)return;const y=s?Ce(s,m,g):void 0,R=s?Vn(g,y,p==="loop"):null,A=!d&&vo(l,g,b);if(p==="loop"||R||A||(y==null?void 0:y.status)==="not_logged_in"){o();return}a(!0);try{const S=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(d?{type:p,account:m,project:h||void 0,harness:s?g:void 0}:{type:p,project:h,task:b,account:m||void 0,harness:s?g:void 0})})).json();S.ok?(P(d?"Session started":p==="review"?"Review started":"Task started","success"),d||Mt(""),r(S.session)):P(S.error??"Failed to start","error")}catch{P("Failed to start","error")}finally{a(!1)}},x=y=>{var R;Ft.value=y,h&&((R=e[h])==null?void 0:R.account)!==y&&(Ie.value="")};return n("section",{style:{position:"relative",zIndex:5,padding:"14px",borderRadius:"16px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-m)",animation:"riseIn .34s var(--ease) both"},"aria-label":"Start a task",children:[n("div",{class:"flex items-center flex-wrap",style:{gap:"9px"},children:[n("input",{class:"field min-w-0",style:{flex:"1 1 300px",height:"40px",padding:"0 13px",borderRadius:"11px",background:"var(--bg-2)",fontSize:"14.5px"},placeholder:d?"A general session needs no name — pick the account below":"Paste a Linear ticket, a PR link, or type a task name","aria-label":"Task name, ticket or pull request",value:me.value,onInput:y=>Mt(y.target.value),onKeyDown:y=>{y.key==="Enter"&&u()}}),n(Mo,{}),n("button",{type:"button",disabled:f,class:f?"":"cursor-pointer transition-all duration-180 ease-spring hover:-translate-y-px hover:brightness-106",style:{height:"40px",padding:"0 18px",borderRadius:"11px",border:0,fontSize:"13.5px",fontWeight:600,background:f&&!i?"var(--elev)":"linear-gradient(180deg, var(--blue-2), var(--blue))",color:f&&!i?"var(--ink-3)":"#fff",boxShadow:f&&!i?"none":"var(--shadow-m)",opacity:f&&!i?.8:1,cursor:f?"not-allowed":"pointer"},onClick:()=>void u(),children:i?"Starting…":d?"Launch":"Start"})]}),n("div",{class:"flex items-center flex-wrap",style:{gap:"8px 14px",marginTop:"10px",padding:"0 2px"},children:[n("div",{class:"flex-1 min-w-0",style:{flexBasis:"280px"},children:n(Fo,{ctx:{type:p,project:h,account:m,harness:g}})}),d&&n(La,{label:"Account",value:m,onChange:x,options:t.map(y=>({value:y,label:y}))}),n("div",{class:"inline-flex items-center shrink-0",style:{gap:"6px",fontSize:"12px",color:"var(--ink-3)"},children:[n("span",{"aria-hidden":"true",children:"Project"}),n(Do,{label:"Project",value:h,onChange:y=>{Ie.value=y},placeholder:d?"No project":"Choose…",options:d?[{value:"",label:"No project"},...jn(e,t,k)]:jn(e,t,c)})]})]})]})},Yn=({title:e,subtitle:t,leading:r,children:o,sticky:i=!0,size:a="lg"})=>n("header",{class:`glass flex items-center flex-wrap shrink-0 ${i?"sticky top-0 z-20":""}`,style:{gap:"12px 14px",padding:"12px 22px",borderBottom:"1px solid var(--hair)"},children:[n(Qn,{}),r,n("div",{class:"min-w-0",children:[n("h1",{class:"truncate",style:{fontSize:a==="lg"?"20px":"18px",fontWeight:700,letterSpacing:"-0.02em"},children:e}),t&&n("p",{class:"truncate",style:{marginTop:"1px",fontSize:"12.5px",color:"var(--ink-2)"},children:t})]}),n("span",{style:{flex:"1 1 40px"}}),o&&n("div",{class:"flex items-center flex-wrap",style:{gap:"7px"},children:o})]}),Ea=({label:e="Tasks",onClick:t})=>n("button",{type:"button",class:"inline-flex items-center gap-1 shrink-0 whitespace-nowrap cursor-pointer transition-all duration-180 ease-spring text-ink2 hover:text-ink",style:{padding:"5px 10px",borderRadius:"8px",border:"1px solid var(--hair)",background:"var(--card)",fontSize:"12.5px"},onClick:t,children:[n("span",{"aria-hidden":"true",children:"←"})," ",e]}),Qn=()=>n("button",{type:"button",class:"sb-toggle place-items-center shrink-0 cursor-pointer text-ink2 hover:text-ink",style:{width:"30px",height:"30px",borderRadius:"9px",border:"1px solid var(--hair)",background:"var(--card)",boxShadow:"var(--shadow-s)"},"aria-label":"Open sidebar",onClick:()=>{Se.value=!0},children:n("span",{class:"i-lucide-menu",style:{width:"15px",height:"15px"}})}),Pn=te({}),Sr=new Set;function Ia(e){!e||Sr.has(e)||(Sr.add(e),fetch(`/api/cw/detect/${encodeURIComponent(e)}`).then(t=>t.ok?t.json():null).catch(()=>null).then(t=>{Pn.value={...Pn.value,[e]:t}}))}const Bo=e=>{if(!e)return[];const t=[];return e.framework&&t.push(e.framework),e.testRunner&&t.push(e.testRunner),e.hasTailwind&&t.push("Tailwind"),e.hasShadcn&&t.push("shadcn"),e.hasPlaywright&&t.push("Playwright"),e.hasDockerfile&&t.push("Docker"),t};function Ho(e){return F(()=>{Ia(e)},[e]),Pn.value[e]}const Cr=10,Uo="forge-task-layout",Na=()=>{try{return localStorage.getItem(Uo)==="project"?"project":"recent"}catch{return"recent"}},zt={borderRadius:"16px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-m)",overflow:"hidden"},jt={padding:"11px 15px",borderBottom:"1px solid var(--hair)",background:"var(--elev)"},Oa=({project:e,account:t,sessions:r,index:o,openTabKeys:i,onSelectTask:a,onMarkDone:l})=>{const s=Bo(Ho(e)),p=r.some(d=>i.has(K(d)));return n("section",{style:{...zt,animation:`riseIn .4s var(--ease) ${o*70}ms both`},"aria-label":e||"No project",children:[n("div",{class:"flex items-center flex-wrap",style:{...jt,gap:"10px"},children:[n($e,{size:9,live:p}),n("span",{style:{fontSize:"14px",fontWeight:650,letterSpacing:"-0.01em"},children:e||"No project"}),n("span",{class:"truncate",style:{fontSize:"12.5px",color:"var(--ink-2)"},children:[t,s.join(" · ")].filter(Boolean).join(" · ")}),n("span",{class:"flex-1"}),n("span",{class:"mono",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:[r.length," task",r.length===1?"":"s"]})]}),r.map(d=>n(Oo,{session:d,isOpenInTab:i.has(K(d)),onSelect:()=>a(d),onMarkDone:d.type==="login"?void 0:()=>l(d)},K(d)))]})},Wa=({spaces:e,allSpaces:t,projects:r,accountNames:o,filterAccount:i,filterProject:a,onFilterProject:l,filterType:s,onFilterType:p,harnessNames:d,filterHarness:h,onFilterHarness:c,showDone:m,onShowDone:k,openTabKeys:g,onSelectTask:b,onMarkDone:f,onNewTask:u,onCreateProject:x,onRefresh:v,onStarted:C})=>{var U,M;const[y,R]=w(Na),A=j=>{R(j);try{localStorage.setItem(Uo,j)}catch{}},L=Q(()=>e.filter(j=>j.status==="active"),[e]),I=Q(()=>e.filter(j=>j.status==="done"),[e]),S=Q(()=>t.filter(j=>j.status==="active").length,[t]),z=Q(()=>t.filter(j=>j.status==="done").length,[t]),_=Q(()=>t.filter(j=>j.status==="active"&&g.has(K(j))).length,[t,g]),N=Q(()=>t.filter(j=>j.status==="active"&&(!i||j.account===i)&&(!a||j.project===a)&&(!h||(j.harness??"claude")===h)),[t,i,a,h]),O=Q(()=>{const j=new Map;for(const G of L){const V=ue(G),de=j.get(V)??[];de.push(G),j.set(V,de)}return Array.from(j,([G,V])=>({project:G,sessions:V}))},[L]),E=a?((U=r[a])==null?void 0:U.account)??((M=L[0])==null?void 0:M.account):void 0,B=a?`${E?`${E} · `:""}${N.length} active`:`${S} active · ${z} done · ${_} agent${_===1?"":"s"} working`;return n(Z,{children:[n(Yn,{title:a??"Tasks",subtitle:B,children:[n(D,{label:"Add project",variant:"secondary",onClick:x}),n(D,{label:"New task",variant:"primary",onClick:u})]}),n("div",{class:"flex flex-col w-full",style:{padding:"18px 22px 40px",gap:"16px",maxWidth:"1180px"},children:[n(Aa,{projects:r,accounts:o,onStarted:C,onOpenDrawer:u}),n("div",{class:"flex items-center flex-wrap",style:{gap:"12px"},children:[n(ve,{label:"Filter by type",tabs:[{id:"all",label:"All",count:N.length},...Ue.map(j=>({id:j.key,label:Un(j.key),count:N.filter(G=>G.type===j.sessionType).length}))],active:s??"all",onChange:j=>p(j==="all"?null:j)}),d.length>1&&n(ve,{label:"Filter by harness",tabs:[{id:"all",label:"Any harness"},...d.map(j=>({id:j,label:fe(j).label}))],active:h??"all",onChange:j=>c(j==="all"?null:j)}),n("span",{class:"flex-1"}),!a&&n(ve,{size:"sm",label:"Order tasks",tabs:[{id:"recent",label:"Recent"},{id:"project",label:"By project"}],active:y,onChange:j=>A(j==="project"?"project":"recent")}),n("button",{type:"button","aria-pressed":m,class:"cursor-pointer transition-all duration-180 ease-spring",style:{padding:"6px 12px",borderRadius:"9px",border:"1px solid var(--hair)",background:m?"var(--card)":"transparent",color:m?"var(--ink)":"var(--ink-2)",fontSize:"12.5px",fontWeight:500,boxShadow:m?"var(--shadow-s)":"none"},onClick:()=>k(!m),children:m?"Hide done":"Show done"})]}),a&&n(Ca,{project:a,account:E,accounts:o,onDeleted:()=>{l(null),v()},onMoved:v}),y==="recent"&&!a&&L.length>0&&n("section",{style:{...zt,animation:"riseIn .4s var(--ease) both"},"aria-label":"Recently opened",children:[n("div",{class:"flex items-center",style:{...jt,gap:"10px"},children:[n("span",{class:"i-lucide-clock shrink-0",style:{width:"14px",height:"14px",color:"var(--ink-2)"}}),n("span",{style:{fontSize:"14px",fontWeight:650,letterSpacing:"-0.01em"},children:"Recently opened"}),n("span",{class:"flex-1"}),n("span",{class:"mono",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:[L.length," task",L.length===1?"":"s"]})]}),L.map(j=>n(Oo,{session:j,showProject:!0,isOpenInTab:g.has(K(j)),onSelect:()=>b(j),onMarkDone:j.type==="login"?void 0:()=>f(j)},K(j)))]}),(y==="project"||a)&&O.map((j,G)=>{var V;return n(Oa,{project:j.project,account:((V=r[j.project])==null?void 0:V.account)??j.sessions[0].account,sessions:j.sessions,index:G,openTabKeys:g,onSelectTask:b,onMarkDone:f},j.project)}),O.length===0&&n("section",{style:{...zt,animation:"riseIn .4s var(--ease) both"},children:[a&&n("div",{class:"flex items-center",style:{...jt,gap:"10px"},children:[n($e,{size:9}),n("span",{style:{fontSize:"14px",fontWeight:650,letterSpacing:"-0.01em"},children:a})]}),n("div",{class:"flex flex-col items-center text-center",style:{padding:"28px 16px",gap:"12px"},children:[n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:s||h?"No active tasks match these filters.":a?`No active tasks on ${a}.`:"No active tasks. Start something new."}),n(D,{label:"New task",variant:"primary",onClick:u})]})]}),m&&I.length>0&&n("section",{style:{...zt,boxShadow:"var(--shadow-s)"},"aria-label":"Done",children:[n("div",{style:{...jt,padding:"10px 15px",fontSize:"13px",fontWeight:600,color:"var(--ink-2)"},children:["Done · last ",Math.min(Cr,I.length)," of ",I.length]}),I.slice(0,Cr).map(j=>n(Sa,{session:j,onSelect:()=>b(j)},K(j)))]})]})]})},Re={padding:"6px 12px",borderRadius:"9px",border:"1px solid var(--hair)",background:"var(--card)",color:"var(--ink)",fontSize:"12.5px",fontWeight:500,boxShadow:"var(--shadow-s)",whiteSpace:"nowrap"},Fe="inline-flex items-center gap-1 cursor-pointer transition-all duration-180 ease-spring hover:-translate-y-px hover:shadow-m hover:text-ink",Ko={...Re,color:"var(--ink-3)",boxShadow:"none"},Da=({entry:e})=>{var r;const t=(r=e==null?void 0:e.state)==null?void 0:r.github;if(!t||t.url===null){const o=e?e.error??(t==null?void 0:t.reason)??"This task has no GitHub remote":"Checking the repository…";return n("button",{type:"button",class:"inline-flex items-center gap-1 cursor-not-allowed",style:Ko,disabled:!0,title:o,children:["GitHub ",n("span",{class:"i-lucide-external-link",style:{width:"12px",height:"12px"}})]})}return n("a",{class:Fe,style:Re,href:t.url,target:"_blank",rel:"noopener noreferrer",title:t.label,children:["GitHub ",n("span",{class:"i-lucide-external-link",style:{width:"12px",height:"12px"}})]})},Fa=({session:e,entry:t})=>{var d;const[r,o]=w(!1),i=X(null);F(()=>{jo()},[]),F(()=>{if(!r)return;const h=c=>{i.current&&!i.current.contains(c.target)&&o(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[r]);const a=$n.value,l=a!=null&&a.enabled?a.editors:[];if(l.length===0)return null;const s=(d=t==null?void 0:t.state)==null?void 0:d.workspace;if(s!=="ready")return n("button",{type:"button",class:"cursor-not-allowed",style:Ko,disabled:!0,title:t?s==="missing"?"Workspace not created yet":"This session has no worktree":"Checking the worktree…",children:["Open in ",l.length===1?l[0].label:"editor"]});const p=async h=>{o(!1);try{await ua(e,h)}catch(c){P(c.message,"error")}};return l.length===1?n("button",{type:"button",class:Fe,style:Re,onClick:()=>p(l[0].id),children:["Open in ",l[0].label]}):n("div",{class:"relative",ref:i,children:[n("button",{type:"button",class:Fe,style:Re,"aria-expanded":r,onClick:()=>o(h=>!h),children:["Open in editor ",n("span",{class:"i-lucide-chevron-down",style:{width:"12px",height:"12px"}})]}),r&&n("div",{class:"popover absolute right-0 top-full z-30 flex flex-col",style:{marginTop:"6px",minWidth:"160px",padding:"5px",borderRadius:"12px"},children:l.map(h=>n("button",{type:"button",class:"text-left cursor-pointer hover:bg-elev",style:{padding:"7px 10px",borderRadius:"8px",border:0,background:"none",color:"var(--ink)",fontSize:"13px"},onClick:()=>p(h.id),children:h.label},h.id))})]})},Ma={"--orange":"--red","--blue":"--purple","--purple":"--blue","--green":"--teal"},Qe=({label:e,index:t,color:r="var(--ink)",bar:o,title:i,children:a})=>n("div",{class:"min-w-0",title:i,style:{padding:"10px 12px",borderRadius:"13px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",animation:`riseIn .34s var(--ease) ${t*60}ms both`},children:[n("div",{style:{fontSize:"11.5px",color:"var(--ink-2)"},children:e}),n("div",{class:"mono truncate",style:{fontSize:"19px",fontWeight:650,color:r,marginTop:"2px"},children:a}),o!==void 0&&n("div",{style:{height:"5px",borderRadius:"99px",background:"var(--elev)",marginTop:"7px",overflow:"hidden"},children:n("div",{style:{height:"100%",width:`${o??0}%`,borderRadius:"99px",background:"linear-gradient(90deg, var(--blue), var(--purple))",transition:"width .6s var(--ease)"}})})]}),dn=({title:e,items:t,tone:r,empty:o})=>n("div",{style:{padding:"11px 13px",borderRadius:"13px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)"},children:[n("div",{style:{fontSize:"11.5px",fontWeight:600,color:"var(--ink-2)",marginBottom:"5px"},children:e}),n("div",{class:"flex flex-wrap",style:{gap:"5px"},children:[t.length===0&&n("span",{style:{fontSize:"12px",color:"var(--ink-3)"},children:o}),t.map(i=>n("span",{title:i.title,style:{padding:"2px 8px",borderRadius:"99px",fontSize:"11px",fontWeight:500,background:r&&!i.muted?se(r):"var(--elev)",color:r&&!i.muted?`var(${r})`:"var(--ink-2)",opacity:i.muted?.6:1},children:i.name},i.name))]})]}),Ba=({session:e,active:t,onDone:r})=>{const[o,i]=w(""),[a,l]=w(!1),[s,p]=w(!1),[d,h]=w(0),[c,m]=w(null),[k,g]=w(!1),b=K(e),f=qt(e),u=e.type==="task"||e.type==="review",x=Eo(e,{poll:t&&e.type==="task"}),v=Hn(e.type),C=e.type==="login",y=Bo(Ho(C?"":ue(e))),R=bo(b).value,A=encodeURIComponent(e.project),L=encodeURIComponent(f),S=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws/terminal/${A}/${L}?k=${d}`;F(()=>{if(C)return;let M=!1;return Promise.all([fetch(`/api/cw/tools?project=${A}`).then(j=>j.json()).catch(()=>null),fetch(`/api/cw/git/branch/${A}/${L}`).then(j=>j.json()).catch(()=>null)]).then(([j,G])=>{M||(j&&m(j),i((G==null?void 0:G.branch)||e.task||e.pr||""))}),()=>{M=!0}},[b]);const z=()=>{l(!1),h(M=>M+1)},_=(c==null?void 0:c.mcps)??[],N=(c==null?void 0:c.plugins)??[],O=(x==null?void 0:x.state)??null,E=(O==null?void 0:O.branch)??o,B=x?x.error!==null?"Changes unknown":fa(x.state):"Checking changes…",U=[ue(e)||"no project",e.account,[lo(e),e.provider&&e.provider!=="native"?null:e.model].filter(Boolean).join(", "),`${e.opens} session${e.opens===1?"":"s"}`].filter(Boolean).join(" · ");return n("div",{class:"flex flex-col h-full min-w-0",children:[n("div",{class:"flex flex-col shrink-0",style:{padding:"14px 20px",gap:"12px"},children:[n("div",{class:"flex items-center flex-wrap",style:{gap:"12px"},children:[n("span",{class:"grid place-items-center shrink-0",style:{width:"34px",height:"34px",borderRadius:"11px",background:`linear-gradient(160deg, var(${v.token}), var(${Ma[v.token]??v.token}))`,boxShadow:"var(--shadow-m)",color:"#fff",fontSize:"13px",fontWeight:700},"aria-hidden":"true",children:v.glyph}),n("div",{class:"min-w-0",children:[n("h1",{class:"truncate",style:{fontSize:"19px",fontWeight:700,letterSpacing:"-0.02em"},children:he(e)}),n("p",{class:"truncate",style:{marginTop:"1px",fontSize:"12.5px",color:"var(--ink-2)"},children:U}),!C&&n("p",{class:"mono truncate",style:{marginTop:"2px",fontSize:"11.5px",color:"var(--ink-3)"},title:B,children:B})]}),n("span",{style:{flex:"1 1 60px"}}),n("div",{class:"flex flex-wrap items-center",style:{gap:"7px"},children:[!C&&n("button",{type:"button",class:Fe,style:Re,"aria-expanded":k,onClick:()=>g(M=>!M),children:k?"Hide context":`Context · ${_.length} MCP, ${N.length} plugins`}),!C&&n(Da,{entry:x}),!C&&n(Fa,{session:e,entry:x}),a&&n(D,{label:"Restart",variant:"secondary",size:"sm",onClick:z}),e.status==="active"&&!C&&n(D,{label:"Mark done",variant:"primary",size:"sm",onClick:r})]})]}),!C&&n("div",{class:"grid",style:{gridTemplateColumns:"repeat(auto-fit, minmax(138px, 1fr))",gap:"9px"},children:[n(Qe,{index:0,label:"Context used",color:"var(--blue)",bar:(R==null?void 0:R.context)??null,title:"Read from the harness status line",children:(R==null?void 0:R.context)!=null?`${Math.round(R.context)}%`:"—"}),n(Qe,{index:1,label:"Tokens",children:(R==null?void 0:R.tokens)!=null?ko(R.tokens):"—"}),n(Qe,{index:2,label:"Cost",color:"var(--green)",children:(R==null?void 0:R.cost)!=null?wo(R.cost):"—"}),u&&n(Qe,{index:3,label:"Commits",children:(O==null?void 0:O.commits)??"—"}),u&&n(Qe,{index:4,label:"Unpushed",color:O&&dt(O)>0?"var(--orange)":"var(--ink)",children:O?dt(O):"—"}),E&&n("button",{type:"button",class:"text-left cursor-pointer transition-all duration-180 ease-spring hover:-translate-y-px hover:shadow-m min-w-0",style:{padding:"10px 12px",borderRadius:"13px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",color:"var(--ink)",animation:"riseIn .34s var(--ease) 300ms both"},title:"Copy branch name",onClick:()=>Jn(E,"Branch"),children:[n("div",{class:"flex items-center",style:{gap:"4px",fontSize:"11.5px",color:"var(--ink-2)"},children:["Branch ",n("span",{class:"i-lucide-copy",style:{width:"11px",height:"11px"}})]}),n("div",{class:"mono truncate",style:{fontSize:"13px",fontWeight:600,marginTop:"6px"},children:E})]})]}),k&&n("div",{class:"grid",style:{gridTemplateColumns:"repeat(auto-fit, minmax(230px, 1fr))",gap:"9px",animation:"riseIn .3s var(--ease) both"},children:[n(dn,{title:`MCP · ${_.length}`,tone:"--blue",empty:"No MCP servers",items:_.map(M=>({name:M.name,title:`${M.type} · ${M.source}`}))}),n(dn,{title:`Plugins · ${N.length}`,tone:"--green",empty:"No plugins",items:N.map(M=>({name:M.name,muted:!M.enabled,title:`${M.enabled?"enabled":"disabled"} · ${M.marketplace}${M.hasMcp?` · MCP ${M.mcpName??""}`:""}`}))}),n(dn,{title:"Stack",tone:null,empty:"Nothing detected",items:y.map(M=>({name:M}))})]})]}),n("div",{class:"task-terminal relative flex-1 min-h-0",style:{margin:"0 20px 20px",borderRadius:"14px",overflow:"hidden",background:"var(--term)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-l)"},children:n("div",{class:"absolute inset-0 flex flex-col",children:[n("div",{class:"flex items-center shrink-0",style:{gap:"7px",padding:"8px 12px",borderBottom:"1px solid rgba(255,255,255,.08)"},children:[n("span",{style:{width:"11px",height:"11px",borderRadius:"50%",background:"#ff5f57"}}),n("span",{style:{width:"11px",height:"11px",borderRadius:"50%",background:"#febc2e"}}),n("span",{style:{width:"11px",height:"11px",borderRadius:"50%",background:"#28c840"}}),n("span",{class:"mono truncate",style:{fontSize:"11px",color:"#8a8a92",marginLeft:"6px"},children:[E||he(e)," — ",e.harness??"claude"]}),n("span",{class:"flex-1"}),n("span",{class:"mono",style:{fontSize:"11px",color:s?"#30d158":"#8a8a92"},children:s?"connected":a?"exited":"offline"})]}),n("div",{class:"relative flex-1 min-h-0",style:{padding:"12px 6px 6px 14px"},children:[n(Ci,{wsUrl:S,theme:ut.value,focused:t,onOutput:M=>Gi(b,M),onExit:()=>l(!0),onGiveUp:()=>l(!0),onConnectionChange:p}),!s&&!a&&n("div",{class:"absolute inset-0 grid place-items-center pointer-events-none",style:{background:"rgba(0,0,0,.35)"},children:n("span",{style:{fontSize:"13px",color:"rgba(255,255,255,.7)"},children:"Connecting…"})})]})]})})]})},Me={fontSize:"12px",color:"var(--ink-2)"},ee=({label:e,plain:t,children:r})=>n(t?"div":"label",{class:"flex flex-col min-w-0",style:{gap:"5px"},children:[n("span",{style:Me,children:e}),r]}),$r={dev:"New dev task",review:"Review a pull request",loop:"New loop",general:"New session"},Ha={dev:"A worktree session that ends in a pull request. Paste a Linear or Notion link and the ticket lands in TASK_NOTES.md first.",review:"Opens a pull request in a review worktree and walks the agent through the diff.",loop:"A recurring Claude Code /loop on one project — babysit PRs, fix failing tests, work a backlog.",general:"A plain agent session on an account, optionally inside a project. No worktree."},Ua={dev:"Task name or ticket URL",review:"Pull request number or URL",loop:"Loop prompt",general:""},Ka={dev:"fix-auth or https://linear.app/…",review:"42 or https://github.com/…/pull/42",loop:"Babysit my open PRs…",general:""},qa=[{id:"",label:"Auto"},{id:"feature",label:"feature"},{id:"bugfix",label:"bugfix"},{id:"refactor",label:"refactor"}],pn={boxShadow:"var(--shadow-s)"},yt=e=>/^[\w./:#-]+$/.test(e)?e:`"${e.replace(/"/g,'\\"')}"`,Ja=({projects:e,accounts:t,initialAccount:r,initialProject:o,onClose:i,onCreated:a,onOpenAccounts:l})=>{var $;const s=Gn(me.value,De.value),[p,d]=w(""),[h,c]=w(""),[m,k]=w(""),[g,b]=w(""),[f,u]=w(""),[x,v]=w(!1),[C,y]=w(!1),[R,A]=w(""),[L,I]=w("claude"),S=Gt();F(()=>{ge()},[]),F(()=>{const T=W=>{W.key==="Escape"&&i()};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[i]);const z=We.value,_=z!=null&&z.available?z.doctor:null,N=Object.keys(e),O=s==="general",E=s==="review",B=s==="loop",U=me.value,M=!R.trim()||/^\d+[smh]$/.test(R.trim()),j=t.length>0?t:Array.from(new Set(Object.values(e).map(T=>T.account).filter(Boolean))).sort(),G=p?N.filter(T=>{var W;return((W=e[T])==null?void 0:W.account)===p}):N;F(()=>{const T=o&&!r&&e[o]?e[o].account:void 0,W=r??T,H=W&&j.includes(W)?W:j[0]??"";d(H);const ne=H?N.filter(_e=>{var tr;return((tr=e[_e])==null?void 0:tr.account)===H}):N,re=o&&ne.includes(o)?o:!O&&ne.length>0?ne[0]:"";re&&c(re)},[]);const V=X(!1);F(()=>{if(!V.current){V.current=!0;return}!O&&!h&&G.length>0&&c(G[0])},[O]);const de=T=>{d(T);const W=N.filter(H=>{var ne;return((ne=e[H])==null?void 0:ne.account)===T});!O&&W.length>0&&!W.includes(h)?c(W[0]):O&&h&&!W.includes(h)&&c("")},ae=_?co(h||void 0,p,e,_):"claude";F(()=>{!_||!p||I(B?"claude":ae)},[z==null?void 0:z.available,p,h,B]);const ce=_?Ce(_,p,L):void 0,pe=!_||Ee(z,L,"skip_permissions"),ke=!_||L==="claude",xe=ke||!O,Pe=_?Vn(L,ce,B):null,Ke=fe(L).label;F(()=>{pe||v(!1),u(ke?"":(ce==null?void 0:ce.model)??"")},[L]),F(()=>{ke||u((ce==null?void 0:ce.model)??"")},[p]);const Yt=fo(U),Qt=vo(z,L,U),ht=!O&&!U.trim()||B&&!M||!O&&!h||!!Pe,ft=async()=>{if(!ht){y(!0);try{const T={type:s,account:p||void 0,skipPermissions:x||void 0};_&&(T.harness=L),B?(T.project=h,T.loopPrompt=U.trim(),T.loopInterval=R.trim()||void 0):O?h&&(T.project=h):(T.project=h,T.task=U.trim(),T.description=m.trim()||void 0,T.workflow=g||void 0),T.model=xe&&f||void 0;const H=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(T)})).json();H.ok?(P(O?"Session started":B?"Loop started":"Task started","success"),O||Mt(""),a(H.session)):P(H.error??"Failed to start","error")}catch{P("Failed to start","error")}finally{y(!1)}}},Zt=p||j[0]||"default",Xt=O?`cw launch ${yt(Zt)}`:B?`cw loop ${h||"<project>"} ${yt(U.trim()||"<prompt>")}${R.trim()?` --every ${R.trim()}`:""}`:E?`cw review ${h||"<project>"} ${yt(U.trim()||"<pr>")}`:`cw work ${h||"<project>"} ${U.trim()?yt((($=Vt(U))==null?void 0:$.kind)==="name"?Wo(U):U.trim()):"<task>"}`;return n("div",{class:"fixed inset-0 z-50 flex justify-end",style:{background:"rgba(0,0,0,.38)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)"},onClick:i,children:n("aside",{role:"dialog","aria-modal":"true","aria-label":$r[s],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:[n("div",{class:"glass flex items-center sticky top-0 z-1",style:{gap:"10px",padding:"14px 18px",borderBottom:"1px solid var(--hair)"},children:[n("h2",{style:{fontSize:"17px",fontWeight:700,letterSpacing:"-0.02em"},children:$r[s]}),n("span",{class:"flex-1"}),n(eo,{onClick:i})]}),n("div",{class:"flex flex-col",style:{padding:"16px 18px 24px",gap:"14px"},children:[n(Mo,{fill:!0}),n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)",lineHeight:1.5},children:Ha[s]}),!O&&n("div",{class:"flex flex-col",style:{gap:"5px"},children:[n(ee,{label:Ua[s],children:n("input",{class:"field",style:{...pn,fontSize:"14px"},placeholder:Ka[s],value:U,ref:S,onInput:T=>{const W=T.target.value;B?me.value=W:Mt(W)},onKeyDown:T=>{T.key==="Enter"&&ft()}})}),!B&&n(Fo,{ctx:{type:s,project:h,account:p,harness:L},size:"sm"})]}),n("div",{class:"grid",style:{gridTemplateColumns:"1fr 1fr",gap:"10px"},children:[n(ee,{label:"Account",children:n("select",{class:"field",value:p,onChange:T=>{const W=T.target.value;de(W),Ft.value=W},children:j.map(T=>n("option",{value:T,children:T},T))})}),n(ee,{plain:!0,label:O?"Project · optional":"Project",children:n(Do,{label:"Project",size:"md",width:"100%",value:h,placeholder:O?"No project":"Choose…",onChange:T=>{c(T),Ie.value=T},options:[...O?[{value:"",label:"No project"}]:[],...jn(e,j,G)]})})]}),B&&n(ee,{label:"Interval · optional",children:[n("input",{class:"field mono",style:{...pn,borderColor:M?void 0:"var(--red)"},value:R,placeholder:"auto — Claude decides the pace",onInput:T=>A(T.target.value)}),!M&&n("span",{style:{fontSize:"12px",color:"var(--red)"},children:"Use forms like 30s, 5m, 2h — or leave it empty to self-pace"})]}),(s==="dev"||E)&&n(ee,{label:"Description (optional)",children:n("textarea",{class:"field",rows:3,style:pn,placeholder:"Context the agent reads first…",value:m,onInput:T=>k(T.target.value)})}),_&&n(za,{doctor:_,account:p,value:L,defaultHarness:ae,isLoop:B,onChange:I,onOpenAccounts:l}),xe&&n("div",{class:"grid",style:{gridTemplateColumns:s==="dev"?"1fr 1fr":"1fr",gap:"10px"},children:[n("div",{class:"flex flex-col min-w-0",style:{gap:"5px"},children:[n("span",{style:Me,children:"Model"}),ke?n(ve,{fill:!0,size:"sm",label:"Model",tabs:Ii.map(T=>({id:T.id,label:T.label})),active:f,onChange:u}):n("input",{class:"field mono",style:{height:"32px",fontSize:"12.5px"},value:f,placeholder:"the account's model","aria-label":"Model",onInput:T=>u(T.target.value)})]}),s==="dev"&&n("div",{class:"flex flex-col min-w-0",style:{gap:"5px"},children:[n("span",{style:Me,children:"Workflow"}),n(ve,{fill:!0,size:"sm",label:"Workflow",tabs:qa,active:g,onChange:b})]})]}),pe&&n("div",{class:"flex items-center",style:{gap:"10px",padding:"10px 12px",borderRadius:"12px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)"},children:[n("span",{class:"flex-1",style:{fontSize:"13px"},children:["Bypass permissions ",n("span",{class:"mono",style:{fontSize:"11px",color:"var(--ink-3)"},children:"--skip-permissions"})]}),n(no,{checked:x,onChange:v,label:"Bypass permissions"})]}),Qt&&n("p",{style:{fontSize:"12.5px",padding:"10px 12px",borderRadius:"12px",background:se("--orange"),color:"var(--ink)"},children:[Ke," has no MCP and CW has no ",Yt==="linear"?"LINEAR_API_KEY":"NOTION_TOKEN",", so the ticket will not reach TASK_NOTES.md. The task still starts, without the ticket."]}),n(D,{label:C?"Starting…":O?"Launch session":B?"Start loop":E?"Start review":"Start task",variant:"primary",size:"lg",block:!0,loading:C,disabled:ht,onClick:ft}),Pe&&n("p",{style:{fontSize:"12px",color:"var(--red)",textAlign:"center"},children:Pe}),n("p",{class:"mono",style:{fontSize:"11.5px",color:"var(--ink-3)",textAlign:"center",overflowWrap:"anywhere"},children:Xt})]})]})})},Bt=te(null),Ln=te(null);async function Zn(){const e=await fetch("/api/skills/plugins");if(!e.ok)throw new Error("fetch failed");Bt.value=await e.json()}async function An(){const e=await fetch("/api/skills/marketplaces");if(!e.ok)throw new Error("fetch failed");Ln.value=await e.json()}const je=({title:e,sub:t,children:r})=>n("div",{class:"glass flex items-center flex-wrap shrink-0",style:{gap:"10px",padding:"12px 20px",borderBottom:"1px solid var(--hair)"},children:[n("div",{class:"min-w-0",children:[n("h2",{style:{fontSize:"17px",fontWeight:650,letterSpacing:"-0.015em",overflowWrap:"anywhere"},children:e}),t&&n("p",{class:"mono",style:{marginTop:"1px",fontSize:"11.5px",color:"var(--ink-3)",overflowWrap:"anywhere"},children:t})]}),n("span",{style:{flex:"1 1 40px"}}),r]});function Ga(e){const t=new Set;for(const r of e.skills){const o=r.path.split(/[\\/]/),i=o.lastIndexOf("skills");i>=0&&o.length-i===3&&t.add(o[i+1])}return[...t].sort()}function Va(e){return`add-skill-${e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,30).replace(/-+$/,"")||Date.now()}`}function Ya(e,t,r){return["Add a new skill to this repository and open a pull request.",`The skill: ${t}`,r?`Area: ${r}`:"",e.contributing?"Follow CONTRIBUTING.md.":"",e.projectSkills.length>0?`Use this repository's own skills: ${e.projectSkills.map(o=>`/${o}`).join(", ")}`:""].filter(Boolean).join(`
14
- `)}const qo=e=>`/api/skills/plugins/${encodeURIComponent(e)}`;async function Xn(e,t){try{return await Xe(e,t)}catch(r){return P(Rt(r),"error"),null}}async function Jo(e,t,r){await Xn("/api/skills/plugins/install",{id:e,account:r})&&(P(`${t} installed in ${r} · applies to new sessions`,"success"),await Promise.all([Zn(),An()]).catch(()=>{}))}const Go=(e,t)=>t?e.skills.filter(r=>r.name.toLowerCase().includes(t)||r.description.toLowerCase().includes(t)):e.skills,Qa=({list:e,query:t,selected:r,onSelect:o})=>{const i=e.flatMap(a=>{const l=Go(a,t).length;return!t||l>0||a.name.toLowerCase().includes(t)?[{p:a,count:l}]:[]});return i.length===0?null:n("div",{style:{marginTop:"10px"},children:[n("p",{style:{padding:"6px 11px",fontSize:"11px",fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"var(--ink-3)"},children:"Plugins"}),i.map(({p:a,count:l})=>{const s=r===a.id;return n("button",{type:"button","aria-current":s?"true":void 0,class:"flex items-center w-full text-left cursor-pointer transition-all duration-180 ease-spring hover:bg-elev",style:{gap:"8px",padding:"9px 11px",marginBottom:"4px",borderRadius:"11px",border:`1px solid ${s?"var(--hair)":"transparent"}`,background:s?"var(--card)":"transparent",boxShadow:s?"var(--shadow-s)":"none",color:"var(--ink)"},onClick:()=>o(a.id),children:[n("span",{class:"i-lucide-package shrink-0",style:{width:"13px",height:"13px",color:"var(--ink-3)"}}),n("span",{class:"flex-1 min-w-0 truncate",style:{fontSize:"13px",fontWeight:600},children:a.name}),n("span",{class:"mono",style:{fontSize:"11px",color:"var(--ink-3)"},children:l})]},a.id)})]})},Tr={fontSize:"12px",fontWeight:600,color:"var(--ink-2)",margin:"0 0 8px"},Vo={gap:"10px",padding:"9px 12px",borderRadius:"11px",border:"1px solid var(--hair)",background:"var(--card)"},Za=({plugin:e,install:t})=>{const[r,o]=w(!1),i=t.scope==="global"?"global":t.scopeRef,a=async()=>{o(!0);const l=await Xn(`${qo(e.id)}/update`,{scope:t.scope,scopeRef:t.scopeRef});o(!1),l&&(P(`${e.name} ${l.version??""} · applies to new sessions`,"success"),Zn().catch(()=>{}))};return n("div",{class:"flex items-center",style:Vo,children:[n("span",{class:"flex-1 min-w-0 truncate",style:{fontSize:"13px",fontWeight:600},children:i}),n("span",{class:"mono",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:t.version}),n("span",{style:{fontSize:"11.5px",color:t.enabled?"var(--green)":"var(--ink-3)"},children:t.enabled?"on":"off"}),n(D,{label:r?"Updating…":"Update",variant:"secondary",size:"sm",loading:r,onClick:a})]})},Xa=({plugin:e,account:t})=>{const[r,o]=w(!1);return n("div",{class:"flex items-center",style:Vo,children:[n("span",{class:"flex-1",style:{fontSize:"13px",color:"var(--ink-2)"},children:t}),n("span",{style:{fontSize:"11.5px",color:"var(--ink-3)"},children:"not installed"}),n(D,{label:r?"Installing…":"Install",variant:"secondary",size:"sm",loading:r,onClick:async()=>{o(!0),await Jo(e.id,e.name,t),o(!1)}})]})},es=({plugin:e,name:t,onBack:r})=>{const[o,i]=w(null),[a,l]=w(!1);return F(()=>{let s=!1;return i(null),l(!1),fetch(`${qo(e.id)}/skills/${encodeURIComponent(t)}`).then(p=>p.ok?p.json():Promise.reject(new Error("not found"))).then(p=>{s||i(p.content)}).catch(()=>{s||l(!0)}),()=>{s=!0}},[e.id,t]),n(Z,{children:[n(je,{title:t,sub:`${e.name} · read-only`,children:n(D,{label:"Back",variant:"secondary",size:"sm",onClick:r})}),n("div",{class:"flex-1 min-h-0 overflow-auto",style:{padding:"12px 20px 20px"},children:[n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)",margin:"0 0 10px"},children:"Comes from the plugin. To change it, propose the change in the repository."}),a?n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:"Skill not found."}):o===null?n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:"Loading skill…"}):n("pre",{class:"mono",style:{margin:0,padding:"14px 16px",borderRadius:"14px",border:"1px solid var(--hair)",background:"var(--card)",fontSize:"12.5px",lineHeight:1.7,whiteSpace:"pre-wrap",overflowWrap:"anywhere",boxShadow:"var(--shadow-s)"},children:o})]})]})},ts=({plugin:e,accounts:t,query:r,onSelectSkill:o,onPropose:i})=>{const a=new Set(e.installs.map(s=>s.scopeRef)),l=t.filter(s=>!a.has(s));return n(Z,{children:[n(je,{title:e.name,sub:e.repo?`${e.repo} · Claude Code only`:"Claude Code only",children:[e.repo&&n("a",{href:`https://github.com/${e.repo}`,target:"_blank",rel:"noreferrer",style:{fontSize:"12.5px",color:"var(--blue)"},children:"GitHub"}),e.project&&i&&n(D,{label:"Propose a skill",variant:"primary",size:"sm",onClick:i})]}),n("div",{class:"flex-1 min-h-0 overflow-auto",children:n("div",{class:"flex flex-col",style:{padding:"16px 20px 24px",gap:"18px",maxWidth:"720px"},children:[e.description&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)",margin:0},children:e.description}),!e.project&&e.repo&&n("p",{style:{fontSize:"12.5px",color:"var(--ink-3)",margin:0},children:["Register ",n("span",{class:"mono",children:e.repo})," as a CW project to propose skills."]}),n("section",{children:[n("h3",{style:Tr,children:"Accounts"}),n("div",{class:"flex flex-col",style:{gap:"6px"},children:[e.installs.map(s=>n(Za,{plugin:e,install:s},`${s.scope}/${s.scopeRef}`)),l.map(s=>n(Xa,{plugin:e,account:s},s))]})]}),n("section",{children:[n("h3",{style:Tr,children:["Skills (",e.skills.length,")"]}),n("div",{class:"flex flex-col",style:{gap:"4px"},children:Go(e,r).map(s=>n("button",{type:"button",class:"flex items-center w-full text-left cursor-pointer hover:bg-elev",style:{gap:"10px",padding:"8px 11px",borderRadius:"10px",border:0,background:"transparent",color:"var(--ink)"},onClick:()=>o(s.name),children:[n("span",{class:"shrink-0",style:{fontSize:"13px",fontWeight:600},children:s.name}),n("span",{class:"flex-1 min-w-0 truncate",style:{fontSize:"12px",color:"var(--ink-2)"},children:s.description}),n("span",{class:"i-lucide-chevron-right shrink-0",style:{width:"13px",height:"13px",color:"var(--ink-3)"}})]},s.name))})]})]})})]})},ns=({accounts:e})=>{const[t,r]=w(""),o=e.includes(t)?t:e[0]??"",[i,a]=w(""),[l,s]=w(""),[p,d]=w(""),[h,c]=w(!1),[m,k]=w(null);F(()=>{Ln.value===null&&An().catch(()=>P("Failed to load marketplaces","error"))},[]);const g=Ln.value,b=(g==null?void 0:g.find(y=>y.name===i))??(g==null?void 0:g[0]),f=new Set((Bt.value??[]).flatMap(y=>y.installs.some(R=>R.scope==="account"&&R.scopeRef===o)?[y.id]:[])),u=l.trim().toLowerCase(),x=((b==null?void 0:b.plugins)??[]).filter(y=>!u||y.name.toLowerCase().includes(u)||y.description.toLowerCase().includes(u)),v=async()=>{c(!0);const y=await Xn("/api/skills/marketplaces",{source:p.trim(),account:o});c(!1),y&&(P(`Marketplace added to ${o}`,"success"),d(""),await An().catch(()=>{}))},C=async(y,R)=>{k(y),await Jo(y,R,o),k(null)};return n(Z,{children:[n(je,{title:"Add a plugin",sub:o?`Claude Code only · installs into ${o}`:"Claude Code only"}),n("div",{class:"flex-1 min-h-0 overflow-auto flex flex-col",style:{padding:"14px 20px 20px",gap:"8px"},children:[n("div",{class:"flex flex-col",style:{gap:"10px",maxWidth:"560px",marginBottom:"6px"},children:[e.length===0&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)",margin:0},children:"Plugins install into a CW account. Add one in Accounts first."}),e.length>0&&n(ee,{label:"Account",children:n("select",{class:"field",value:o,onChange:y=>r(y.target.value),children:e.map(y=>n("option",{value:y,children:y},y))})}),g&&g.length>0&&n(ee,{label:"Marketplace",children:n("select",{class:"field",value:b==null?void 0:b.name,onChange:y=>a(y.target.value),children:g.map(y=>n("option",{value:y.name,children:[y.name," · ",y.source]},y.name))})}),n(ee,{label:"Add a marketplace",children:n("div",{class:"flex",style:{gap:"8px"},children:[n("input",{class:"field flex-1",value:p,placeholder:"owner/repo, git URL or path",onInput:y=>d(y.target.value),onKeyDown:y=>{y.key==="Enter"&&p.trim()&&v()}}),n(D,{label:h?"Adding…":"Add",variant:"secondary",size:"sm",loading:h,disabled:!p.trim()||!o,onClick:v})]})}),b&&b.plugins.length>0&&n("input",{class:"field",type:"search","aria-label":"Filter plugins",value:l,placeholder:`Filter ${b.plugins.length} plugins`,onInput:y=>s(y.target.value)})]}),g===null&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:"Loading marketplaces…"}),(g==null?void 0:g.length)===0&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:"No marketplace yet. Add one above."}),b&&x.length===0&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:u?"No plugin matches.":"This marketplace lists no plugins."}),x.map((y,R)=>n("div",{class:"flex items-center",style:{gap:"12px",padding:"11px 15px",borderRadius:"13px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",animation:`riseIn .3s var(--ease) ${Math.min(R,8)*40}ms both`},children:[n("div",{class:"flex-1 min-w-0",children:[n("div",{class:"flex items-center min-w-0",style:{gap:"8px"},children:[n("span",{class:"truncate",style:{fontSize:"13.5px",fontWeight:600},children:y.name}),y.category&&n("span",{class:"mono shrink-0",style:{fontSize:"11px",color:"var(--ink-3)"},children:y.category})]}),y.description&&n("div",{class:"truncate",style:{fontSize:"12px",color:"var(--ink-2)"},title:y.description,children:y.description})]}),f.has(y.id)?n("span",{style:{fontSize:"12px",color:"var(--green)"},children:"Installed"}):n(D,{label:m===y.id?"Installing…":"Install",variant:"secondary",size:"sm",loading:m===y.id,disabled:m!==null||!o,onClick:()=>C(y.id,y.name)})]},y.id))]})]})},rs=({plugin:e,accounts:t,onSubmit:r,onCancel:o})=>{const i=Ga(e),a=e.installs.filter(f=>f.scope==="account").map(f=>f.scopeRef),l=t.find(f=>a.includes(f))??t[0]??"",[s,p]=w(""),[d,h]=w(i[0]??""),[c,m]=w(l),[k,g]=w(!1),b=async()=>{g(!0);try{await r(s.trim(),i.length>1?d:void 0,c)}finally{g(!1)}};return n(Z,{children:[n(je,{title:"Propose a skill",sub:`${e.repo??e.name} · project ${e.project??""}`}),n("div",{class:"flex-1 min-h-0 overflow-auto",children:n("div",{class:"flex flex-col",style:{padding:"16px 20px 24px",gap:"14px",maxWidth:"560px"},children:[n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)",margin:0},children:["Starts a task in ",n("span",{class:"mono",children:e.project})," that writes the skill and opens a pull request for review."]}),n(ee,{label:"What the skill does and when to use it",children:n("textarea",{class:"field",rows:4,value:s,placeholder:"Summarize a release's merged PRs into notes when someone asks for a changelog",onInput:f=>p(f.target.value)})}),i.length>1&&n(ee,{label:"Area",children:n("select",{class:"field",value:d,onChange:f=>h(f.target.value),children:i.map(f=>n("option",{value:f,children:f},f))})}),t.length>0&&n(ee,{label:"Account",children:n("select",{class:"field",value:c,onChange:f=>m(f.target.value),children:t.map(f=>n("option",{value:f,children:f},f))})}),n("div",{class:"flex flex-wrap",style:{gap:"8px"},children:[n(D,{label:k?"Starting…":"Start task",variant:"primary",loading:k,disabled:!s.trim()||!c,onClick:b}),n(D,{label:"Cancel",variant:"secondary",onClick:o})]})]})})]})},os={global:"--blue",account:"--orange",project:"--green"},bt=e=>`${e.scope}/${e.scopeRef}/${e.dirName}`;function is(e,t){return e==="global"?"global":e==="account"?`account/${encodeURIComponent(t)}`:`project/${encodeURIComponent(t)}`}const it=e=>e.scope==="global"?"Global":`${e.scope==="account"?"Account":"Project"} · ${e.scopeRef}`,as=e=>e.scope==="global"?`~/.claude/skills/${e.dirName}`:e.scope==="account"?`~/.cw/accounts/${e.scopeRef}/skills/${e.dirName}`:`<${e.scopeRef}>/.claude/skills/${e.dirName}`,ss={global:"Lands in ~/.claude/skills; CW links it into every account when a Claude Code session starts.",account:"Every session on this account loads it.",project:"Sessions in this project load it from its .claude/skills."},Yo=e=>e[0]?{scope:"account",scopeRef:e[0]}:{scope:"global",scopeRef:"global"},En=e=>e.scope==="global"||e.scopeRef!=="",Qo=({accounts:e,projects:t,value:r,onChange:o})=>{const i=a=>{const l=a==="account"?e:t;o({scope:a,scopeRef:a==="global"?"global":l.includes(r.scopeRef)?r.scopeRef:l[0]??""})};return n(Z,{children:[n("div",{class:"flex flex-col",style:{gap:"5px"},children:[n("span",{style:Me,children:"Scope"}),n(ve,{label:"Scope",tabs:[{id:"account",label:"Account"},{id:"project",label:"Project"},{id:"global",label:"Global"}],active:r.scope,onChange:a=>i(a)}),n("span",{style:{fontSize:"12px",color:"var(--ink-3)"},children:ss[r.scope]})]}),r.scope!=="global"&&n(ee,{label:r.scope==="account"?"Account":"Project",children:n("select",{class:"field",value:r.scopeRef,onChange:a=>o({...r,scopeRef:a.target.value}),children:(r.scope==="account"?e:t).map(a=>n("option",{value:a,children:a},a))})})]})},ls=(e,t,r)=>[...t.map(o=>({scope:"account",scopeRef:o})),...r.map(o=>({scope:"project",scopeRef:o})),{scope:"global",scopeRef:"global"}].filter(o=>o.scope!==e.scope||o.scopeRef!==e.scopeRef),Zo=(e,t="")=>{const r=[];for(const[o,i]of Object.entries(e))i&&typeof i=="object"&&!Array.isArray(i)?(r.push(`${t}${o}:`),r.push(...Zo(i,t+" "))):r.push(`${t}${o}: ${String(i??"")}`);return r},cs=({skill:e,accounts:t,projects:r,onDeleted:o,onCopied:i,onRun:a})=>{const[l,s]=w(null),[p,d]=w(!0),[h,c]=w("SKILL.md"),[m,k]=w(""),[g,b]=w({}),[f,u]=w(!1),x=`/api/skills/${is(e.scope,e.scopeRef)}/${encodeURIComponent(e.dirName)}`;F(()=>{let S=!1;return d(!0),c("SKILL.md"),fetch(x).then(z=>{if(!z.ok)throw new Error("fetch failed");return z.json()}).then(z=>{if(S)return;s(z);const _=Zo(z.frontmatter);k(_.length>0?`---
15
- ${_.join(`
16
- `)}
17
- ---
18
-
19
- ${z.body}`:z.body),b(Object.fromEntries(z.references.map(N=>[N.name,N.content])))}).catch(()=>{S||(s(null),P("Failed to load skill","error"))}).finally(()=>{S||d(!1)}),()=>{S=!0}},[x]);const v=async()=>{u(!0);const S=h==="SKILL.md";try{const _=await(await fetch(S?x:`${x}/references/${encodeURIComponent(h)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:S?m:g[h]??""})})).json();_.ok?P(S?"Skill saved":"Reference saved","success"):P(_.error??"Failed to save","error")}catch{P("Failed to save","error")}finally{u(!1)}},C=async()=>{if(confirm(`Delete the skill "${e.name}" permanently?`))try{const z=await(await fetch(x,{method:"DELETE"})).json();z.ok?(P("Skill deleted","info"),o()):P(z.error??"Failed to delete","error")}catch{P("Failed to delete","error")}},y=async S=>{try{const _=await(await fetch("/api/skills/copy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({from:{scope:e.scope,scopeRef:e.scopeRef,name:e.dirName},to:S})})).json();_.ok?(P(`Copied to ${it(S)}`,"success"),i()):P(_.error??"Failed to copy","error")}catch{P("Failed to copy","error")}},R=async()=>{const S=prompt("Reference filename (e.g. examples.md):");if(!(S!=null&&S.trim()))return;const z=S.trim(),_=`# ${z}
20
- `;try{const O=await(await fetch(`${x}/references/${encodeURIComponent(z)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:_})})).json();O.ok?(b(E=>({...E,[z]:_})),s(E=>E&&{...E,references:[...E.references,{name:z,content:_}]}),c(z),P("Reference added","success")):P(O.error??"Failed to add reference","error")}catch{P("Failed to add reference","error")}},A=async S=>{if(confirm(`Delete reference "${S}"?`))try{const _=await(await fetch(`${x}/references/${encodeURIComponent(S)}`,{method:"DELETE"})).json();_.ok?(b(N=>{const{[S]:O,...E}=N;return E}),s(N=>N&&{...N,references:N.references.filter(O=>O.name!==S)}),h===S&&c("SKILL.md"),P("Reference deleted","info")):P(_.error??"Failed to delete reference","error")}catch{P("Failed to delete reference","error")}},L=["SKILL.md",...(l==null?void 0:l.references.map(S=>S.name))??[]],I=ls(e,t,r);return n(Z,{children:[n(je,{title:e.name,sub:`${it(e)} · ${as(e)}`,children:[n(D,{label:"Delete",variant:"danger",size:"sm",onClick:C}),n("select",{class:"field","aria-label":"Copy to",style:{height:"30px",padding:"0 8px",fontSize:"12.5px",width:"auto"},value:"",disabled:!l,onChange:S=>{const z=S.target,_=I[Number(z.value)];z.value="",_&&y(_)},children:[n("option",{value:"",disabled:!0,children:"Copy to…"}),I.map((S,z)=>n("option",{value:z,children:it(S)},`${S.scope}/${S.scopeRef}`))]}),n(D,{label:"Run in session",variant:"secondary",size:"sm",onClick:a}),n(D,{label:f?"Saving…":"Save",variant:"primary",size:"sm",loading:f,disabled:!l,onClick:v})]}),n("div",{class:"flex items-center flex-wrap shrink-0",style:{gap:"6px",padding:"10px 20px 0"},role:"tablist","aria-label":"Files",children:[L.map(S=>{const z=h===S;return n("span",{class:"inline-flex items-center",style:{gap:"4px",padding:z?"5px 8px 5px 11px":"5px 11px",borderRadius:"9px",background:z?"var(--card)":"transparent",border:`1px solid ${z?"var(--hair)":"transparent"}`,boxShadow:z?"var(--shadow-s)":"none"},children:[n("button",{type:"button",role:"tab","aria-selected":z,class:"mono cursor-pointer",style:{border:0,background:"none",padding:0,fontSize:"12px",fontWeight:z?600:400,color:z?"var(--ink)":"var(--ink-3)"},onClick:()=>c(S),children:S}),z&&S!=="SKILL.md"&&n("button",{type:"button","aria-label":`Delete ${S}`,class:"grid place-items-center cursor-pointer text-ink3 hover:text-red",style:{border:0,background:"none",padding:0},onClick:()=>A(S),children:n("span",{class:"i-lucide-x",style:{width:"12px",height:"12px"}})})]},S)}),n("span",{class:"flex-1"}),n("button",{type:"button",class:"cursor-pointer transition-all duration-180 ease-spring hover:-translate-y-px",style:{padding:"5px 10px",borderRadius:"9px",border:"1px solid var(--hair)",background:"var(--card)",color:"var(--blue)",fontSize:"12px",fontWeight:500},onClick:R,disabled:!l,children:"+ Reference"})]}),n("div",{class:"flex-1 min-h-0",style:{padding:"12px 20px 20px"},children:p?n("p",{style:{padding:"24px 0",textAlign:"center",fontSize:"13px",color:"var(--ink-2)"},children:"Loading skill…"}):l?n("textarea",{class:"field mono w-full h-full","aria-label":h,spellcheck:!1,style:{height:"100%",padding:"14px 16px",borderRadius:"14px",border:"1px solid var(--hair)",background:"var(--card)",color:"var(--ink)",fontSize:"12.5px",lineHeight:1.7,resize:"none",outline:"none",boxShadow:"var(--shadow-s)",minHeight:"240px"},value:h==="SKILL.md"?m:g[h]??"",onInput:S=>{const z=S.target.value;h==="SKILL.md"?k(z):b(_=>({..._,[h]:z}))}}):n("p",{style:{padding:"24px 0",textAlign:"center",fontSize:"13px",color:"var(--ink-2)"},children:"Skill not found."})})]})},ds=({query:e,accounts:t,projects:r,onInstalled:o})=>{const[i,a]=w(null),[l,s]=w(null),[p,d]=w(()=>Yo(t));F(()=>{let c=!1;return a(null),fetch(`/api/skills/explore?q=${encodeURIComponent(e)}`).then(m=>{if(!m.ok)throw new Error("search failed");return m.json()}).then(m=>{c||a(m.results)}).catch(()=>{c||(a([]),P("Failed to search skills","error"))}),()=>{c=!0}},[e]);const h=async c=>{s(c.slug);try{const k=await(await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({repo:c.repo,skill:c.skillId,...p})})).json();k.ok?(P(`Installed in ${it(p)}`,"success"),o()):P(k.error??"Failed to install","error")}catch{P("Failed to install","error")}finally{s(null)}};return n(Z,{children:[n(je,{title:`skills.sh · “${e}”`,sub:`Installs into ${it(p)}`}),n("div",{class:"flex-1 min-h-0 overflow-auto flex flex-col",style:{padding:"14px 20px 20px",gap:"8px"},children:[n("div",{class:"flex flex-col",style:{gap:"10px",maxWidth:"560px",marginBottom:"6px"},children:n(Qo,{accounts:t,projects:r,value:p,onChange:d})}),i===null&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:"Searching…"}),(i==null?void 0:i.length)===0&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:"No results on skills.sh."}),i==null?void 0:i.map((c,m)=>n("div",{class:"flex items-center",style:{gap:"12px",padding:"11px 15px",borderRadius:"13px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",animation:`riseIn .3s var(--ease) ${Math.min(m,8)*40}ms both`},children:[n("div",{class:"flex-1 min-w-0",children:[n("div",{class:"truncate",style:{fontSize:"13.5px",fontWeight:600},children:c.name}),n("div",{class:"mono truncate",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:[c.repo," · ",c.installs," installs"]})]}),n(D,{label:l===c.slug?"Installing…":"Install",variant:"secondary",size:"sm",loading:l===c.slug,disabled:!En(p),onClick:()=>h(c)})]},c.slug))]})]})},ps=({accounts:e,projects:t,onCreated:r,onCreateWithAI:o})=>{const[i,a]=w(()=>Yo(e)),[l,s]=w(""),[p,d]=w(""),[h,c]=w(!1),{scope:m,scopeRef:k}=i,g=async()=>{if(!l.trim())return;c(!0);const b=`---
21
- name: ${l.trim()}
22
- description: ${p.trim()}
23
- domain: general
24
- ---
25
-
26
- # ${l.trim()}
27
-
28
- ${p.trim()}
29
- `;try{const u=await(await fetch("/api/skills",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scope:m,scopeRef:k,name:l.trim(),content:b})})).json();u.ok?(P("Skill created","success"),r()):P(u.error??"Failed to create skill","error")}catch{P("Failed to create skill","error")}finally{c(!1)}};return n(Z,{children:[n(je,{title:"New skill",sub:"Write it yourself or let an agent draft it with skill-creator"}),n("div",{class:"flex-1 min-h-0 overflow-auto",children:n("div",{class:"flex flex-col",style:{padding:"16px 20px 24px",gap:"14px",maxWidth:"560px"},children:[n(Qo,{accounts:e,projects:Object.keys(t),value:i,onChange:a}),n(ee,{label:"Name",children:n("input",{class:"field",value:l,placeholder:"my-skill",onInput:b=>s(b.target.value)})}),n(ee,{label:"Description",children:n("textarea",{class:"field",rows:3,value:p,placeholder:"What does this skill do?",onInput:b=>d(b.target.value)})}),n("div",{class:"flex flex-wrap",style:{gap:"8px"},children:[n(D,{label:h?"Creating…":"Create",variant:"primary",loading:h,disabled:!l.trim()||!En(i),onClick:g}),o&&n(D,{label:"Create with AI",variant:"secondary",disabled:!p.trim()||!En(i),title:"Starts a session that drafts the skill",onClick:()=>o(m,k,p.trim())})]})]})})]})},us=({accounts:e,projects:t,onCreateWithAI:r,onRunSkill:o,onProposeSkill:i})=>{const[a,l]=w(""),[s,p]=w({kind:"empty"}),[d,h]=w(ot.value===null),c=Object.keys(t),m=Y(async()=>{try{await Promise.all([xo(),Zn()])}catch{P("Failed to load skills","error")}finally{h(!1)}},[]);F(()=>{(ot.value===null||Bt.value===null)&&m()},[m]);const k=ot.value??[],g=a.trim().toLowerCase(),b=g?k.filter(v=>v.name.toLowerCase().includes(g)||v.description.toLowerCase().includes(g)):k,f=Bt.value??[],u=s.kind==="plugin"||s.kind==="propose"?f.find(v=>v.id===s.id):void 0;F(()=>{s.kind==="empty"&&k.length>0&&p({kind:"editor",skill:k[0]})},[k.length]);const x=s.kind==="editor"?bt(s.skill):null;return n("main",{class:"skills-page grid min-w-0",style:{gridTemplateColumns:"292px minmax(0,1fr)",height:"100vh"},children:[n("div",{class:"skills-rail flex flex-col min-h-0 overflow-hidden",style:{borderRight:"1px solid var(--hair)",background:"var(--bg-2)"},children:[n("div",{class:"flex flex-col shrink-0",style:{padding:"12px 14px",borderBottom:"1px solid var(--hair)",gap:"10px"},children:[n("div",{class:"flex items-center",style:{gap:"10px"},children:[n(Qn,{}),n("h1",{style:{fontSize:"18px",fontWeight:700,letterSpacing:"-0.02em"},children:"Skills"}),n("span",{class:"mono",style:{fontSize:"11px",color:"var(--ink-3)"},children:k.length}),n("span",{class:"flex-1"}),n(D,{label:"New",variant:"primary",size:"sm",onClick:()=>p({kind:"create"})})]}),n("input",{class:"field",type:"search","aria-label":"Search skills",style:{height:"32px",padding:"0 11px",borderRadius:"9px",border:"1px solid var(--hair)",background:"var(--card)",color:"var(--ink)",fontSize:"13px",outline:"none"},placeholder:"Search installed or skills.sh",value:a,onInput:v=>l(v.target.value),onKeyDown:v=>{v.key==="Enter"&&a.trim()&&p({kind:"explore",query:a.trim()})}})]}),n("div",{class:"overflow-auto min-h-0",style:{padding:"8px"},children:[d&&n("p",{style:{padding:"12px",fontSize:"12.5px",color:"var(--ink-2)"},children:"Loading skills…"}),!d&&b.length===0&&f.length===0&&n("p",{style:{padding:"12px",fontSize:"12.5px",color:"var(--ink-2)"},children:g?"No installed skill matches.":"No skills yet."}),b.map(v=>{const C=x===bt(v);return n("button",{type:"button","aria-current":C?"true":void 0,class:"block w-full text-left cursor-pointer transition-all duration-180 ease-spring hover:bg-elev",style:{padding:"9px 11px",marginBottom:"4px",borderRadius:"11px",border:`1px solid ${C?"var(--hair)":"transparent"}`,background:C?"var(--card)":"transparent",boxShadow:C?"var(--shadow-s)":"none",color:"var(--ink)"},onClick:()=>p({kind:"editor",skill:v}),children:[n("span",{class:"flex items-center",style:{gap:"8px"},children:[n("span",{class:"shrink-0",style:{width:"7px",height:"7px",borderRadius:"50%",background:`var(${os[v.scope]})`}}),n("span",{class:"flex-1 min-w-0 truncate",style:{fontSize:"13px",fontWeight:600},children:v.name}),n("span",{class:"truncate",style:{fontSize:"11px",color:"var(--ink-3)",maxWidth:"90px"},children:v.scope==="global"?"global":v.scopeRef})]}),v.description&&n("span",{class:"block truncate",style:{fontSize:"12px",color:"var(--ink-2)",marginTop:"2px"},children:v.description})]},bt(v))}),n(Qa,{list:f,query:g,selected:s.kind==="plugin"||s.kind==="propose"?s.id:null,onSelect:v=>p({kind:"plugin",id:v})}),!g&&n("button",{type:"button","aria-current":s.kind==="plugins"?"true":void 0,class:"flex items-center w-full text-left cursor-pointer hover:bg-elev",style:{gap:"8px",padding:"9px 11px",marginTop:"6px",borderRadius:"11px",border:"1px dashed var(--hair-2)",background:"transparent",color:"var(--blue)",fontSize:"12.5px",fontWeight:500},onClick:()=>p({kind:"plugins"}),children:[n("span",{class:"i-lucide-plus shrink-0",style:{width:"13px",height:"13px"}}),n("span",{class:"truncate",children:"Add a plugin"})]}),g&&n("button",{type:"button",class:"flex items-center w-full text-left cursor-pointer hover:bg-elev",style:{gap:"8px",padding:"9px 11px",borderRadius:"11px",border:"1px dashed var(--hair-2)",background:"transparent",color:"var(--blue)",fontSize:"12.5px",fontWeight:500},onClick:()=>p({kind:"explore",query:a.trim()}),children:[n("span",{class:"i-lucide-search shrink-0",style:{width:"13px",height:"13px"}}),n("span",{class:"truncate",children:["Search skills.sh for “",a.trim(),"”"]})]})]})]}),n("div",{class:"flex flex-col min-h-0 min-w-0",children:[s.kind==="editor"&&n(cs,{skill:s.skill,accounts:e,projects:c,onCopied:()=>{m()},onRun:()=>o(s.skill),onDeleted:()=>{p({kind:"empty"}),m()}},bt(s.skill)),s.kind==="create"&&n(ps,{accounts:e,projects:t,onCreateWithAI:r,onCreated:()=>{p({kind:"empty"}),m()}}),s.kind==="explore"&&n(ds,{query:s.query,accounts:e,projects:c,onInstalled:()=>{m()}}),s.kind==="plugins"&&n(ns,{accounts:e}),s.kind==="plugin"&&u&&!s.skill&&n(ts,{plugin:u,accounts:e,query:g,onSelectSkill:v=>p({kind:"plugin",id:u.id,skill:v}),onPropose:()=>p({kind:"propose",id:u.id})}),s.kind==="plugin"&&u&&s.skill&&n(es,{plugin:u,name:s.skill,onBack:()=>p({kind:"plugin",id:u.id})},s.skill),s.kind==="propose"&&u&&n(rs,{plugin:u,accounts:e,onCancel:()=>p({kind:"plugin",id:u.id}),onSubmit:async(v,C,y)=>{await i(u,v,C,y)&&p({kind:"plugin",id:u.id})}}),s.kind==="empty"&&!d&&n("div",{class:"flex-1 grid place-items-center",style:{padding:"24px"},children:n("div",{class:"flex flex-col items-center text-center",style:{gap:"12px"},children:[n("p",{style:{fontSize:"13.5px",color:"var(--ink-2)"},children:"Pick a skill to edit it, or write a new one."}),n(D,{label:"New skill",variant:"primary",onClick:()=>p({kind:"create"})})]})})]})]})},un={borderRadius:"16px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-m)"},hn={padding:"10px 14px",borderRadius:"12px",fontSize:"12.5px"},kt=e=>e.target.value,hs=({accounts:e,onOpenSession:t,onFramesChanged:r})=>{const[o,i]=w(null),[a,l]=w(null),[s,p]=w(""),[d,h]=w(""),[c,m]=w(""),[k,g]=w(null),[b,f]=w(""),u=Y(async()=>{try{const S=await(await fetch("/api/liveframe/frames")).json();l(S),r(S.length)}catch{l([])}},[r]);F(()=>{u(),fetch("/api/liveframe/status").then(S=>S.json()).then(i).catch(()=>{})},[u]);const x=async S=>{if(o)try{const z=await Xe("/api/cw/start",{type:"general",account:o.account,directory:S.dir,task:`Liveframe: ${S.project}/${S.frame}`});t(z.session)}catch(z){P(Rt(z),"error")}},v=async(S,z)=>{try{const _=await S;return P(z,"success"),u(),await x(_),!0}catch(_){return P(Rt(_),"error"),!1}},C=async()=>{await v(Xe("/api/liveframe/frames",{project:s,name:d}),`Frame "${d}" created`)&&h("")},y=async()=>{await v(Xe("/api/liveframe/pull",{target:c}),`Pulled ${c}`)&&m("")},R=async()=>{if(k)try{const{url:S}=await Xe(`/api/liveframe/frames/${k.project}/${k.frame}/push`,{note:b});P(`Published: ${S}`,"success"),g(null)}catch(S){P(Rt(S),"error")}},A=o!==null&&!e.includes(o.account),L=(o==null?void 0:o.installed)!==!1&&!A,I=(a??[]).reduce((S,z)=>{var _;return(S[_=z.project]??(S[_]=[])).push(z),S},{});return n(Z,{children:[n(Yn,{title:"Prototypes",subtitle:o?`Liveframe frames in ${o.root} · agents run on ${o.account}`:"Liveframe frames",children:[o&&n("a",{class:Fe,style:Re,href:o.api,target:"_blank",rel:"noopener noreferrer",children:["Liveframe gallery ",n("span",{class:"i-lucide-external-link",style:{width:"12px",height:"12px"}})]}),n(D,{label:"Refresh",variant:"secondary",onClick:u})]}),n("div",{class:"flex flex-col w-full",style:{padding:"18px 22px 40px",gap:"14px",maxWidth:"1180px"},children:[o&&!o.installed&&n("p",{style:{...hn,background:se("--red")},children:["The Liveframe CLI is not installed. Run ",n("code",{children:["npm i -g ",o.api,"/cli.tgz"]}),", then ",n("code",{children:"lf login"}),"."]}),A&&n("p",{style:{...hn,background:se("--red")},children:["Liveframe agents run on the CW account ",n("code",{children:o==null?void 0:o.account}),", which does not exist here. Add it in Accounts or set ",n("code",{children:"FORGE_LIVEFRAME_ACCOUNT"}),"."]}),(o==null?void 0:o.installed)&&!o.signedIn&&n("p",{style:{...hn,background:se("--orange")},children:["Liveframe is not signed in on this machine. Run ",n("code",{children:"lf login"})," in a terminal."]}),n("section",{class:"grid",style:{gridTemplateColumns:"repeat(auto-fit, minmax(300px, 1fr))",gap:"14px"},children:[n("div",{class:"flex flex-col",style:{...un,padding:"16px 18px",gap:"12px"},children:[n("div",{children:[n("h2",{style:{fontSize:"14.5px",fontWeight:600},children:"New prototype"}),n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:["Scaffolds a frame with ",n("code",{children:"lf new"})," and opens an agent in it. The frame's CLAUDE.md teaches the agent Liveframe's conventions and ",n("code",{children:"lf push"}),"."]})]}),n(ee,{label:"Liveframe project · created if missing",children:n("input",{type:"text",class:"field",value:s,placeholder:"Reservas",onInput:S=>p(kt(S))})}),n(ee,{label:"Frame name",children:n("input",{type:"text",class:"field",value:d,placeholder:"Checkout ideas",onInput:S=>h(kt(S))})}),n("div",{class:"flex justify-end",children:n(D,{label:"Create and open agent",variant:"primary",size:"sm",disabled:!L||!s.trim()||!d.trim(),onClick:C})})]}),n("div",{class:"flex flex-col",style:{...un,padding:"16px 18px",gap:"12px"},children:[n("div",{children:[n("h2",{style:{fontSize:"14.5px",fontWeight:600},children:"Continue a frame"}),n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:["Pulls an existing frame's latest source with ",n("code",{children:"lf pull"})," and opens an agent in it."]})]}),n(ee,{label:"project/frame",children:n("input",{type:"text",class:"field",value:c,placeholder:"reservas/checkout-flow",onInput:S=>m(kt(S))})}),n("div",{class:"flex justify-end",children:n(D,{label:"Pull and open agent",variant:"secondary",size:"sm",disabled:!L||!c.includes("/"),onClick:y})})]})]}),a&&a.length===0&&n(to,{icon:"i-lucide-frame",title:"No frames yet",description:"Frames you create or pull here live on this machine, one folder per frame."}),Object.entries(I).map(([S,z])=>n("section",{style:{...un,overflow:"hidden"},children:[n("h2",{style:{padding:"12px 18px",fontSize:"13px",fontWeight:600,borderBottom:"1px solid var(--hair)"},children:S}),z.map(_=>n("div",{class:"flex items-center flex-wrap",style:{gap:"10px",padding:"12px 18px",borderBottom:"1px solid var(--hair)"},children:[n("div",{class:"min-w-0",style:{flex:"1 1 220px"},children:[n("p",{class:"truncate",style:{fontSize:"13.5px",fontWeight:500},children:_.frame}),n("p",{class:"truncate",style:{fontSize:"12px",color:"var(--ink-3)"},children:[_.kind," · ",_.branch," · ",_.dir]})]}),n("a",{class:Fe,style:Re,href:_.url,target:"_blank",rel:"noopener noreferrer",children:["Live ",n("span",{class:"i-lucide-external-link",style:{width:"12px",height:"12px"}})]}),n(D,{label:"Push",variant:"secondary",size:"sm",disabled:!L,onClick:()=>{f(""),g(_)}}),n(D,{label:"Open agent",variant:"primary",size:"sm",disabled:!o||A,onClick:()=>x(_)})]},_.dir))]},S))]}),n(Bn,{open:k!==null,title:`Push ${k==null?void 0:k.project}/${k==null?void 0:k.frame}`,onClose:()=>g(null),children:n("div",{class:"space-y-4",children:[n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:["Builds the frame and deploys it as a new version with ",n("code",{children:"lf push"}),"."]}),n(ee,{label:"What changed · optional",children:n("input",{type:"text",class:"field",value:b,placeholder:"wallet-first layout",onInput:S=>f(kt(S))})}),n("div",{class:"flex justify-end pt-1",children:n(D,{label:"Push",variant:"primary",onClick:R})})]})})]})},Rr=({value:e,onChange:t,initialPath:r,requireGit:o=!0})=>{const[i,a]=w(r??"~"),[l,s]=w(i),[p,d]=w([]),[h,c]=w(null),[m,k]=w(null),[g,b]=w(""),[f,u]=w(!1),[x,v]=w(!1),[C,y]=w(null);F(()=>{let O=!1;return(async()=>{v(!0),y(null);try{const U=await(await fetch(`/api/cw/browse-dirs?path=${encodeURIComponent(i)}`)).json();if(O)return;if(!U.ok){y(U.error??"Failed to load directory"),d([]);return}d(U.entries??[]),c(U.parent??null),k(U.home??null),b(U.path??i),u(!!U.isGitRepo)}catch{O||(y("Network error"),d([]))}finally{O||v(!1)}})(),()=>{O=!0}},[i]);const R=O=>{a(O),s(O)},A=e===g,L=o&&!f,I=g?m&&g===m?"~":m&&g.startsWith(m+"/")?"~"+g.slice(m.length):g:i,S={width:"24px",height:"24px",borderRadius:"7px",border:0,background:"var(--card)",color:"var(--ink-2)",boxShadow:"var(--shadow-s)"},z="flex items-center w-full text-left cursor-pointer transition-colors duration-140 hover:bg-elev disabled:cursor-not-allowed disabled:opacity-60",_={gap:"8px",padding:"7px 11px",border:0,borderBottom:"1px solid var(--hair)",background:"none",color:"var(--ink)",fontSize:"12.5px"},N={padding:"1px 7px",borderRadius:"99px",background:se("--green"),color:"var(--green)",fontSize:"10.5px",fontWeight:600};return n("div",{style:{borderRadius:"12px",border:"1px solid var(--hair)",background:"var(--card)",boxShadow:"var(--shadow-s)",overflow:"hidden"},children:[n("div",{class:"flex items-center",style:{gap:"6px",padding:"7px 9px",borderBottom:"1px solid var(--hair)",background:"var(--elev)"},children:[n("button",{type:"button",class:"grid place-items-center cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:S,onClick:()=>h&&R(h),disabled:!h||x,title:"Parent folder","aria-label":"Parent folder",children:"←"}),n("button",{type:"button",class:"grid place-items-center cursor-pointer",style:S,onClick:()=>R("~"),title:"Home","aria-label":"Home",children:"~"}),n("input",{type:"text",value:l,"aria-label":"Path",onInput:O=>s(O.target.value),onBlur:()=>a(l),onKeyDown:O=>{O.key==="Enter"&&a(l)},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&&n("div",{class:"flex items-center",style:{gap:"8px",padding:"7px 11px",borderBottom:"1px solid var(--hair)",background:se("--blue",12),fontSize:"12px"},children:[n("span",{class:"i-lucide-check shrink-0",style:{width:"13px",height:"13px",color:"var(--blue)"}}),n("span",{class:"mono flex-1 truncate",children:e}),n("button",{type:"button",class:"grid place-items-center cursor-pointer text-ink3 hover:text-ink",style:{border:0,background:"none"},onClick:()=>t("",!1),title:"Clear selection","aria-label":"Clear selection",children:n("span",{class:"i-lucide-x",style:{width:"13px",height:"13px"}})})]}),n("div",{class:"overflow-y-auto",style:{maxHeight:"220px"},children:x?n("p",{style:{padding:"12px",fontSize:"12.5px",color:"var(--ink-2)"},children:"Loading…"}):C?n("p",{style:{padding:"12px",fontSize:"12.5px",color:"var(--red)"},children:C}):n(Z,{children:[n("button",{type:"button",class:z,style:{..._,background:A?"var(--elev)":"none",fontWeight:600},onClick:()=>t(g,f),disabled:L,title:L?"Not a git repository":"Pick this folder",children:[n("span",{class:"i-lucide-check shrink-0",style:{width:"12px",height:"12px",color:"var(--blue)"}}),n("span",{class:"flex-1 truncate",children:["Pick ",n("span",{class:"mono",children:I})]}),f?n("span",{style:N,children:"git"}):L?n("span",{style:{fontSize:"11px",color:"var(--ink-3)"},children:"no .git"}):null]}),p.length===0?n("p",{style:{padding:"12px",fontSize:"12.5px",color:"var(--ink-3)"},children:"No subfolders"}):p.map(O=>n("button",{type:"button",class:z,style:_,onClick:()=>R(O.path),children:[n("span",{class:"i-lucide-chevron-right shrink-0",style:{width:"12px",height:"12px",color:"var(--ink-3)"}}),n("span",{class:"mono flex-1 truncate",children:O.name}),O.isGitRepo&&n("span",{style:N,children:"git"})]},O.path))]})})]})},fs=({open:e,accounts:t,onClose:r,onCreated:o})=>{const[i,a]=w("create"),[l,s]=w(""),[p,d]=w(""),[h,c]=w(""),[m,k]=w(""),[g,b]=w(""),[f,u]=w(""),[x,v]=w(!1),[C,y]=w(""),[R,A]=w(!1);F(()=>{e&&t.length>0&&!l&&s(t[0])},[e,t]),F(()=>{e||(a("create"),d(""),c(""),k(""),b(""),u(""),v(!1),y(""),A(!1))},[e]);const L=l.trim().length>0&&p.trim().length>0&&m.trim().length>0,I=l.trim().length>0&&f.length>0&&x,S=async()=>{if(L){A(!0);try{const B=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"create",project:p.trim(),task:p.trim(),description:m.trim(),account:l.trim()||void 0,directory:h.trim()||void 0,model:g||void 0})})).json();B.ok?(P("Project creation started in terminal","success"),o(B.session)):P(B.error??"Failed to create project","error")}catch{P("Failed to create project","error")}finally{A(!1)}}},z=async()=>{if(I){A(!0);try{const B=await(await fetch("/api/cw/register-project",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:f,account:l.trim(),alias:C.trim()||void 0})})).json();B.ok?(P(`Project "${B.project}" registered`,"success"),o()):P(B.error??"Failed to register project","error")}catch{P("Failed to register project","error")}finally{A(!1)}}},_=i==="create";return n(Bn,{open:e,title:"Add a project",onClose:r,footer:n(Z,{children:[n("span",{class:"mono flex-1 truncate",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:_?"cw create":"cw project register"}),n(D,{label:"Cancel",variant:"secondary",onClick:r}),n(D,{label:_?R?"Creating…":"Create":R?"Registering…":"Register",variant:"primary",loading:R,disabled:!(_?L:I),onClick:_?S:z})]}),children:n("div",{class:"flex flex-col",style:{gap:"13px"},children:[n(ve,{fill:!0,label:"Mode",tabs:[{id:"create",label:"Create new"},{id:"existing",label:"Register existing"}],active:i,onChange:E=>a(E)}),n("div",{class:"grid",style:{gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:"10px"},children:[n(ee,{label:"Account",children:t.length>0?n("select",{class:"field",value:l,onChange:E=>s(E.target.value),children:t.map(E=>n("option",{value:E,children:E},E))}):n("input",{type:"text",class:"field",value:l,placeholder:"account-name",onInput:E=>s(E.target.value)})}),_?n(ee,{label:"Project name",children:n("input",{type:"text",class:"field",value:p,placeholder:"my-new-project",onInput:E=>d(E.target.value)})}):n(ee,{label:"Alias",children:n("input",{type:"text",class:"field",value:C,placeholder:"defaults to folder name",onInput:E=>y(E.target.value)})})]}),n("div",{class:"flex flex-col",style:{gap:"5px"},children:[n("span",{style:Me,children:_?"Parent folder · optional":"Repository · must contain .git"}),_?n(Rr,{value:h,onChange:c,requireGit:!1},"dir-create"):n(Rr,{value:f,onChange:(E,B)=>{u(E),v(B)}},"dir-existing")]}),_&&n(Z,{children:[n(ee,{label:"Description",children:n("textarea",{rows:2,class:"field",value:m,placeholder:"A SaaS platform for…",onInput:E=>k(E.target.value)})}),n("div",{class:"flex flex-col",style:{gap:"5px"},children:[n("span",{style:Me,children:"Model"}),n(ve,{size:"sm",label:"Model",tabs:[{id:"",label:"Auto"},{id:"haiku",label:"Haiku"},{id:"sonnet",label:"Sonnet"},{id:"opus",label:"Opus"}],active:g,onChange:b})]})]})]})})},vs=(e,t)=>{if(t)return{kind:"connecting"};const r=typeof e.detail=="string"?e.detail:"",o=[e.provider,e.model].filter(Boolean).join(" · ");if(e.status==="not_installed")return{kind:"not_installed",detail:r};if(e.status==="error")return{kind:"error",detail:r};if(e.status==="local"){const i=e.detail&&typeof e.detail=="object"?e.detail:null;return{kind:"local",providerModel:o,reachable:(i==null?void 0:i.reachable)??null,pulled:(i==null?void 0:i.model_pulled)??null}}return e.status==="connected"&&(e.provider_kind==="api"||e.has_api_key)?{kind:"api_key",providerModel:e.provider!=="native"?o:null}:e.status==="connected"?{kind:"connected"}:{kind:"connect"}},xs=(e,t,r,o)=>{const i=[];switch(e.kind){case"connecting":i.push("Waiting for the login to finish");break;case"not_installed":i.push(e.detail||"Not on PATH");break;case"error":i.push(e.detail||"cw doctor reported an error");break;case"local":{const a=[e.reachable===null?null:e.reachable?"reachable":"unreachable",e.pulled===null?null:e.pulled?"model pulled":"model not pulled"].filter(Boolean).join(", ");i.push(...[e.providerModel,a].filter(Boolean));break}case"api_key":i.push(...[e.providerModel,"stored by cw"].filter(a=>!!a));break;case"connected":i.push(...[o.model,t].filter(a=>!!a)),i.length===0&&i.push("Signed in");break;case"connect":i.push(r?"Not logged in — device code, no terminal needed":"Not logged in");break}return o.unofficial&&i.push("unofficial"),i.join(" · ")},Le=({token:e,label:t})=>n("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?se(e):"var(--elev)",color:e?`var(${e})`:"var(--ink-3)"},children:[n("span",{style:{width:"6px",height:"6px",borderRadius:"50%",background:"currentColor"}}),t]}),gs=({view:e,onConnect:t,onCancel:r})=>{switch(e.kind){case"connecting":return n("span",{class:"inline-flex items-center shrink-0",style:{gap:"8px"},children:[n(Le,{token:"--blue",label:"Connecting…"}),n("button",{type:"button",class:"cursor-pointer hover:text-ink",style:{border:0,background:"none",color:"var(--ink-2)",fontSize:"12px"},onClick:r,children:"Cancel"})]});case"not_installed":return n(Le,{token:null,label:"Not installed"});case"error":return n(Le,{token:"--red",label:"Error"});case"local":return n(Le,{token:"--orange",label:"Local"});case"api_key":return n(Le,{token:"--green",label:"API key"});case"connected":return n(Le,{token:"--green",label:"Connected"});case"connect":return n(D,{label:"Connect",size:"sm",onClick:t})}},fn=({children:e})=>n("div",{class:"flex",style:{padding:"0 15px 11px"},children:[n("span",{class:"shrink-0",style:{width:"144px"}}),n("span",{class:"flex flex-col flex-1",style:{gap:"5px",minWidth:0},children:e})]}),vn=({warn:e,children:t})=>n("span",{style:{fontSize:"11.5px",color:e?"var(--orange)":"var(--ink-3)"},children:t}),ms=({account:e,harness:t})=>{const r=Qi(e,t);return!r||r.state==="not_connected"?null:r.state==="expired"?n(fn,{children:n(vn,{warn:!0,children:"Reconnect to see usage limits"})}):r.state==="error"?n(fn,{children:n(vn,{children:["Limits unavailable — ",r.detail??"the request failed"]})}):r.windows.length===0?null:n(fn,{children:[n(ro,{bars:uo(r.windows)}),r.stale&&n(vn,{children:["Last known values — ",r.detail??"the refresh failed"]})]})},ys=3e3,bs=({account:e,harness:t,canUseApiKey:r,onConnected:o,onClose:i})=>{const[a,l]=w(null),[s,p]=w(!1),[d,h]=w(0),[c,m]=w(""),[k,g]=w(!1),b=fe(t).label,f=`/api/cw/accounts/${encodeURIComponent(e)}`,u=`${f}/login/${encodeURIComponent(t)}`,x=X(!1),v=X(!1);F(()=>{let A=!1,L=null;l(null),p(!1),x.current=!1,v.current=!1;const I=()=>{x.current||(x.current=!0,fetch(u,{method:"DELETE"}).catch(()=>{}),P(`${e} is connected to ${b}`,"success"),o())},S=async()=>{var E;const _=await fetch(u).catch(()=>null);if(!(_!=null&&_.ok)||A)return;const{login:N}=await _.json();if(l(N),N.status!=="exited"||(v.current=!0,L&&(clearInterval(L),L=null),N.exitCode!==0))return;p(!0);const O=await ge(!0);A||(O.available&&((E=Ce(O.doctor,e,t))==null?void 0:E.status)==="connected"?I():p(!1))};fetch(`${f}/login`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({harness:t})}).then(_=>_.json()).then(_=>{if(!A){if(!_.ok||!_.login){P(_.error??"Could not start the login","error");return}l(_.login),L=setInterval(S,ys)}}).catch(()=>P("Could not start the login","error"));const z=Fi(_=>{var N;return((N=Ce(_,e,t))==null?void 0:N.status)==="connected"},{onDone:_=>{_&&I()}});return()=>{A=!0,L&&clearInterval(L),z(),v.current||fetch(u,{method:"DELETE"}).catch(()=>{})}},[e,t,d]);const C=()=>{fetch(u,{method:"DELETE"}).catch(()=>{}),i()},y=async()=>{const A=c.trim();if(A){g(!0);try{const I=await(await fetch(`${f}/api-key`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({harness:t,apiKey:A})})).json();I.ok?(m(""),P("API key saved","success"),ge(!0)):P(I.error??"Could not save the API key","error")}catch{P("Could not save the API key","error")}finally{g(!1)}}},R=(a==null?void 0:a.status)==="exited";return n("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:[n("div",{class:"flex items-center",style:{gap:"10px"},children:[n("h3",{style:{fontSize:"14px",fontWeight:650},children:["Connect ",e," on ",b]}),n("span",{class:"flex-1"}),n(D,{label:"Cancel",variant:"secondary",size:"sm",onClick:C})]}),!a&&n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:"Starting the login…"}),a&&!R&&n(Z,{children:[n("div",{class:"flex flex-wrap items-center",style:{gap:"12px"},children:[a.url&&n("a",{href:a.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 ",n("span",{class:"i-lucide-external-link",style:{width:"12px",height:"12px"}})]}),a.code&&n(Z,{children:[n("span",{class:"mono",style:{fontSize:"19px",fontWeight:650,letterSpacing:".12em"},children:a.code}),n(D,{label:"Copy",variant:"secondary",size:"sm",onClick:()=>Jn(a.code??"","Code")})]})]}),a.code&&n("p",{style:{fontSize:"12px",color:"var(--ink-3)"},children:"If the code is rejected, use the one shown in Output."}),n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:a.url||a.code?"Checks every 3 s. The status turns Connected on its own.":"Waiting for the login URL…"})]}),R&&s&&n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:"Checking the connection…"}),R&&!s&&n("div",{class:"flex items-center",style:{gap:"10px",fontSize:"12.5px"},children:[n("span",{style:{color:"var(--red)"},children:"The login ended before connecting."}),n(D,{label:"Retry",variant:"secondary",size:"sm",onClick:()=>h(A=>A+1)})]}),a&&a.output.length>0&&n("details",{style:{fontSize:"12.5px"},children:[n("summary",{class:"cursor-pointer",style:{color:"var(--ink-2)"},children:"Output"}),n("pre",{class:"overflow-x-auto",style:{marginTop:"8px",padding:"10px 12px",borderRadius:"11px",background:"var(--term)",color:"#e3e3e8",fontSize:"11.5px"},children:a.output.join(`
30
- `)})]}),r&&n("div",{class:"flex flex-col",style:{gap:"8px",paddingTop:"12px",borderTop:"1px solid var(--hair)"},children:[n("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--ink-3)"},children:"Or with an API key"}),n("div",{class:"flex items-center",style:{gap:"8px"},children:[n("input",{type:"password",autocomplete:"off","aria-label":"API key",value:c,onInput:A=>m(A.target.value),placeholder:"sk-…",class:"field mono flex-1 min-w-0"}),n(D,{label:"Save",variant:"secondary",size:"sm",loading:k,disabled:!c.trim(),onClick:y})]}),n("p",{style:{fontSize:"12px",color:"var(--ink-3)"},children:"Sent to cw over stdin. Forge never stores or shows it."})]})]})},wt={display:"block",fontSize:"12px",color:"var(--ink-2)",marginBottom:"5px"},ks=({response:e,onCancel:t,onCreated:r})=>{const[o,i]=w(""),[a,l]=w(""),[s,p]=w(""),[d,h]=w(""),[c,m]=w(!1),k=Gt(),g=o.trim(),b=Ni.test(g),f=e!=null&&e.available?e.doctor.harnesses.map(v=>v.name).filter(v=>v!=="claude"):[],u=!!a&&Ee(e,a,"custom_provider"),x=async()=>{if(!(!b||c)){m(!0);try{const C=await(await fetch("/api/cw/accounts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:g,harness:a||void 0,provider:u&&s.trim()||void 0,model:u&&d.trim()||void 0})})).json();C.ok?(P(`Account "${g}" created`,"success"),r()):P(C.error??"Failed to create account","error")}catch{P("Failed to create account","error")}finally{m(!1)}}};return n("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:[n("h2",{style:{fontSize:"17px",fontWeight:700,letterSpacing:"-0.02em"},children:"Add an account"}),n("div",{style:{maxWidth:"360px"},children:[n("label",{style:wt,for:"new-account-name",children:"Account name"}),n("input",{id:"new-account-name",type:"text",value:o,onInput:v=>i(v.target.value),onKeyDown:v=>{v.key==="Enter"&&x()},placeholder:"my-account",class:"field",ref:k}),g&&!b&&n("p",{style:{fontSize:"12px",color:"var(--red)",marginTop:"5px"},children:"Must start with a letter or number. Only letters, numbers, hyphens, and underscores allowed."})]}),f.length>0&&n("div",{children:[n("span",{style:wt,children:"Default harness"}),n(ve,{label:"Default harness",tabs:[{id:"",label:"Claude Code"},...f.map(v=>({id:v,label:fe(v).label}))],active:a,onChange:l}),n("p",{style:{fontSize:"12px",color:"var(--ink-3)",marginTop:"5px"},children:"The default harness cannot be changed later."})]}),u&&n("div",{class:"grid",style:{gridTemplateColumns:"1fr 1fr",gap:"10px",maxWidth:"520px"},children:[n("div",{children:[n("label",{style:wt,children:"Provider · optional"}),n("input",{type:"text",value:s,onInput:v=>p(v.target.value),placeholder:"zai, ollama, openrouter",class:"field"})]}),n("div",{children:[n("label",{style:wt,children:"Model · optional"}),n("input",{type:"text",value:d,onInput:v=>h(v.target.value),placeholder:"glm-5.1",class:"field"})]})]}),n("div",{class:"flex",style:{gap:"8px"},children:[n(D,{label:c?"Creating…":"Add account",variant:"primary",loading:c,disabled:!b,onClick:x}),n(D,{label:"Cancel",variant:"secondary",onClick:t})]})]})},ws=new Set(["localhost","127.0.0.1","::1","[::1]"]),zr={borderRadius:"16px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-m)",overflow:"hidden"},xn={padding:"10px 14px",borderRadius:"12px",fontSize:"12.5px"},_s=({account:e,onRemoved:t})=>{const[r,o]=w(!1),i=async()=>{try{const l=await(await fetch(`/api/cw/accounts/${encodeURIComponent(e)}`,{method:"DELETE"})).json();l.ok?(P(`Account "${e}" removed`,"info"),t()):P(l.error??"Failed to remove account","error")}catch{P("Failed to remove account","error")}finally{o(!1)}};return r?n("span",{class:"flex items-center flex-wrap",style:{gap:"8px"},children:[n("span",{style:{fontSize:"12px",color:"var(--ink-2)"},children:"Deletes the profile and its harness config. Projects stay."}),n(D,{label:"Remove account",variant:"destructive",size:"sm",onClick:i}),n(D,{label:"Cancel",variant:"secondary",size:"sm",onClick:()=>o(!1)})]}):n(D,{label:"Remove",variant:"danger",size:"sm",onClick:()=>o(!0)})},Ss=({projects:e,onOpenSession:t,onAccountsChanged:r})=>{const[o,i]=w(null),[a,l]=w(!1);F(()=>{ge()},[]),F(()=>_o(),[]);const s=We.value,p=!ws.has(window.location.hostname),d=s!=null&&s.available?s.doctor:null,h=()=>{o&&(fetch(`/api/cw/accounts/${encodeURIComponent(o.account)}/login/${encodeURIComponent(o.harness)}`,{method:"DELETE"}).catch(()=>{}),i(null))},c=async(f,u)=>{if(Ee(s,u,"headless_login")){i({account:f,harness:u});return}try{const v=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"login",account:f,harness:u})})).json();v.ok&&v.session?t(v.session):P(v.error??"Could not open the login","error")}catch{P("Could not open the login","error")}},m=d?d.accounts.reduce((f,u)=>f+u.harnesses.filter(x=>x.status==="not_logged_in").length,0):0,k=d?`${d.accounts.length} account${d.accounts.length===1?"":"s"} · ${d.harnesses.length} harnesses · ${m} need${m===1?"s":""} connecting`:"Reading cw doctor…",g=f=>Object.values(e).filter(u=>u.account===f).length,b=(f,u)=>{if(!d)return null;const[x,v]=ao(u),C=g(f.name),y=Ce(d,f.name,f.default_harness),R=[fe(f.default_harness).label,y&&y.provider!=="native"?y.provider:null].filter(Boolean).join(" · ");return n("section",{style:{...zr,animation:`riseIn .36s var(--ease) ${u*90}ms both`},"aria-label":f.name,children:[n("div",{class:"flex items-center flex-wrap",style:{gap:"11px",padding:"12px 15px",borderBottom:"1px solid var(--hair)",background:"var(--elev)"},children:[n("span",{class:"grid place-items-center shrink-0",style:{width:"28px",height:"28px",borderRadius:"9px",background:`linear-gradient(160deg, var(${x}), var(${v}))`,boxShadow:"var(--shadow-s)",color:"#fff",fontSize:"12px",fontWeight:700},children:f.name.charAt(0).toUpperCase()}),n("span",{style:{fontSize:"15px",fontWeight:650,letterSpacing:"-0.01em"},children:f.name}),n("span",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:["Default ",R," · ",C," project",C===1?"":"s"]}),n("span",{class:"flex-1"}),n(_s,{account:f.name,onRemoved:()=>{ge(!0),r()}})]}),d.harnesses.map(A=>{const L=Ce(d,f.name,A.name),I=(o==null?void 0:o.account)===f.name&&o.harness===A.name,S=fe(A.name),z=L?vs(L,I):null;return n("div",{style:{borderBottom:"1px solid var(--hair)"},children:[n("div",{class:"flex items-center flex-wrap",style:{gap:"12px",padding:"11px 15px"},children:[n("span",{class:"inline-flex items-center shrink-0",style:{gap:"6px",width:"132px",fontSize:"13px",fontWeight:600},children:[n("span",{style:{width:"8px",height:"8px",borderRadius:"50%",background:S.color}}),S.label]}),n("span",{class:"flex-1",style:{minWidth:"140px",fontSize:"12.5px",color:"var(--ink-2)"},children:L&&z?xs(z,A.version,Ee(s,A.name,"headless_login"),L):"Not configured for this account"}),z&&n(gs,{view:z,onConnect:()=>{c(f.name,A.name)},onCancel:h})]}),L&&n(ms,{account:f.name,harness:A.name}),I&&n("div",{style:{padding:"0 15px 13px"},children:n(bs,{account:f.name,harness:A.name,canUseApiKey:Ee(s,A.name,"api_key_login"),onConnected:()=>i(null),onClose:()=>i(null)},`${f.name}::${A.name}`)})]},A.name)})]},f.name)};return n(Z,{children:[n(Yn,{title:"Accounts",subtitle:k,children:[n(D,{label:"Refresh",variant:"secondary",onClick:()=>{ge(!0)}}),n(D,{label:"Add account",variant:"primary",onClick:()=>l(!0)})]}),n("div",{class:"flex flex-col w-full",style:{padding:"18px 22px 40px",gap:"14px",maxWidth:"1180px"},children:[a&&n(ks,{response:s,onCancel:()=>l(!1),onCreated:()=>{l(!1),ge(!0),r()}}),s&&!s.available&&n("section",{style:{...zr,padding:"16px 18px"},children:[n("p",{style:{fontSize:"13.5px",marginBottom:"4px"},children:["Harness status is unavailable: ",s.reason]}),n("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."}),n(D,{label:"Retry",variant:"secondary",size:"sm",onClick:()=>{ge(!0)}})]}),d&&p&&n("p",{style:{...xn,background:se("--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."}),d&&d.issues.map(f=>n("p",{style:{...xn,background:se("--red"),color:"var(--ink)"},children:f.message},f.code)),d&&d.warnings.map(f=>n("p",{style:{...xn,background:"var(--elev)",color:"var(--ink-2)"},children:f.message},f.code)),d==null?void 0:d.accounts.map(b)]})]})},jr="flex items-center w-full text-left cursor-pointer transition-colors duration-140 hover:bg-elev",Cs=({sessions:e,openTabKeys:t,onOpenSession:r,onNewTask:o,onClose:i,position:a})=>{const l=X(null);F(()=>{const p=h=>{l.current&&!l.current.contains(h.target)&&i()},d=h=>{h.key==="Escape"&&i()};return document.addEventListener("mousedown",p),document.addEventListener("keydown",d),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",d)}},[i]);const s=e.filter(p=>!t.has(K(p)));return n("div",{ref:l,class:"popover fixed z-[60] flex flex-col",style:{top:`${a.top}px`,left:`${a.left}px`,width:"min(320px, calc(100vw - 16px))",maxHeight:"420px",overflowY:"auto",padding:"6px",borderRadius:"14px"},children:[n("div",{style:{padding:"7px 10px 3px",fontSize:"11px",fontWeight:600,color:"var(--ink-3)"},children:"New"}),Ue.map(p=>n("button",{type:"button",class:jr,style:{gap:"10px",padding:"7px 10px",borderRadius:"10px",border:0,background:"none",color:"var(--ink)",fontSize:"13px"},onClick:()=>{o(p.key),i()},children:[n(zn,{type:p.sessionType,size:22,radius:7,font:10}),n("span",{class:"flex-1",children:Un(p.key)})]},p.key)),s.length>0&&n(Z,{children:[n("div",{style:{padding:"9px 10px 3px",fontSize:"11px",fontWeight:600,color:"var(--ink-3)"},children:"Resume"}),s.map(p=>n("button",{type:"button",class:jr,style:{gap:"10px",padding:"7px 10px",borderRadius:"10px",border:0,background:"none",color:"var(--ink)",fontSize:"13px"},onClick:()=>{r(p),i()},children:[n(zn,{type:p.type,size:22,radius:7,font:10}),n("span",{class:"flex-1 truncate",children:he(p)}),n("span",{class:"mono truncate",style:{fontSize:"10.5px",color:"var(--ink-3)",maxWidth:"110px"},children:ue(p)})]},K(p)))]})]})},$s=({tabs:e,activeIndex:t,onActivate:r,onClose:o,onBack:i,allSessions:a,openTabKeys:l,onOpenSession:s,onNewTask:p})=>{const[d,h]=w(!1),c=X(null),[m,k]=w({top:0,left:0}),g=Y(()=>h(!1),[]),b=()=>{if(!d&&c.current){const f=c.current.getBoundingClientRect();k({top:f.bottom+6,left:Math.max(8,Math.min(f.left,window.innerWidth-328))})}h(!d)};return n(Z,{children:[n("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:[n(Qn,{}),n(Ea,{onClick:i}),e.map((f,u)=>{const x=u===t,v=Te.value[K(f)],C=!x&&Oe(v);return n("div",{role:"tab",tabIndex:0,"aria-selected":x,title:[C?Wt(v):null,u<5?`⌘${u+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:x?"var(--card)":"transparent",border:`1px solid ${x?"var(--hair)":"transparent"}`,boxShadow:x?"var(--shadow-s)":"none"},onClick:()=>r(u),onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.preventDefault(),r(u))},children:[n($e,{size:6,live:f.status==="active",color:C?`var(${$t(v)})`:void 0}),n("span",{style:{fontWeight:600,color:x?"var(--ink)":"var(--ink-2)"},children:he(f)}),n("span",{class:"mono truncate",style:{fontSize:"11px",color:"var(--ink-3)",maxWidth:"110px"},children:ue(f)}),n("button",{type:"button",class:"grid place-items-center cursor-pointer text-ink3 hover:text-red",style:{border:0,background:"none",padding:"0 1px"},onClick:y=>{y.stopPropagation(),o(u)},title:"Close tab (⌘W)","aria-label":`Close ${he(f)}`,children:n("span",{class:"i-lucide-x",style:{width:"13px",height:"13px"}})})]},K(f))}),n("button",{ref:c,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:b,"aria-expanded":d,title:"Open or create a tab","aria-label":"Open or create a tab",children:n("span",{class:"i-lucide-plus",style:{width:"14px",height:"14px"}})})]}),d&&n(Cs,{sessions:a,openTabKeys:l,onOpenSession:s,onNewTask:p,onClose:g,position:m})]})};function Ts(e,t){switch(e){case"uncommitted":{const r=(t==null?void 0:t.uncommitted)??0;return`${r} file${r===1?" has":"s have"} uncommitted changes. Closing deletes them.`}case"unpushed":{const r=t?dt(t):0;return`${r} commit${r===1?" is":"s are"} not pushed. They stay on ${(t==null?void 0:t.branch)??"the task branch"} on this machine only.`}case"pr-open":return`PR #${(t==null?void 0:t.pr.status)==="found"?t.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 Rs=({request:e,onCancel:t,onConfirm:r})=>{if(!e)return null;const o=e.state?e.state.closeWarnings:["state-unknown"],i=o.includes("uncommitted");return n(Bn,{open:!0,title:"Close this task?",onClose:t,footer:n(Z,{children:[n("span",{class:"flex-1"}),n(D,{label:"Cancel",variant:"secondary",onClick:t}),n(D,{label:"Close task",variant:i?"destructive":"primary",onClick:r})]}),width:460,children:[n("ul",{class:"flex flex-col",style:{gap:"8px",fontSize:"13.5px",paddingLeft:"18px"},children:o.map(l=>n("li",{children:Ts(l,e.state)},l))}),e.error&&n("p",{style:{marginTop:"10px",fontSize:"12.5px",color:"var(--ink-2)"},children:e.error})]})},gn="forge-open-tabs";function zs({spaces:e,loading:t,onFetchData:r}){const[o,i]=w([]),[a,l]=w(0),[s,p]=w(!0),d=X(!1),h=X(o);h.current=o,F(()=>{if(!(t||e.length===0||d.current)){d.current=!0;try{const f=sessionStorage.getItem(gn);if(!f)return;const{keys:u,activeIndex:x}=JSON.parse(f),v=[];for(const C of u){const y=e.find(R=>K(R)===C);y&&v.push(y)}v.length>0&&(i(v),l(Math.min(x,v.length-1)))}catch{}}},[t,e]),F(()=>{if(d.current)if(o.length>0){const f=o.map(K);sessionStorage.setItem(gn,JSON.stringify({keys:f,activeIndex:a}))}else sessionStorage.removeItem(gn)},[o,a]);const c=Y(f=>{const u=K(f),x=o.findIndex(v=>K(v)===u);x>=0?l(x):(i(v=>[...v,f]),l(o.length)),p(!1)},[o]),m=Y(async f=>{const u=h.current.find(y=>K(y)===f);if(!u)return;const x=u.sessionDir??(u.type==="review"?`review-pr-${u.pr}`:`task-${u.task}`);try{await fetch("/api/cw/terminal/kill",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:u.project,sessionDir:x})})}catch{}const v=h.current.findIndex(y=>K(y)===f);if(v<0)return;Vi(f);const C=h.current.length-1;i(y=>y.filter(R=>K(R)!==f)),C===0?(p(!0),l(0),r()):l(y=>y>v?y-1:Math.min(y,C-1))},[r]),k=Y(f=>{const u=o[f];return u?m(K(u)):Promise.resolve()},[o,m]),g=Y(()=>{p(!0),r()},[r]);F(()=>{const f=u=>{if(o.length===0||s)return;const x=u.metaKey||u.ctrlKey;if(x&&u.key>="1"&&u.key<="5"){const v=parseInt(u.key)-1;v<o.length&&(u.preventDefault(),l(v));return}if(x&&(u.key==="ArrowLeft"||u.key==="ArrowRight")){u.preventDefault(),l(v=>u.key==="ArrowLeft"?v>0?v-1:o.length-1:v<o.length-1?v+1:0);return}if(x&&u.key==="w"){u.preventDefault(),k(a);return}x&&u.key==="l"&&(u.preventDefault(),g())};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[o,s,a,k,g]);const b=Q(()=>new Set(o.map(K)),[o]);return{openTabs:o,activeTabIndex:a,setActiveTabIndex:l,showList:s,openTab:c,closeTab:k,closeTabByKey:m,goToList:g,openTabKeys:b}}function js({spaces:e,accounts:t,projects:r}){const[o,i]=w(null),[a,l]=w(null),[s,p]=w(null),[d,h]=w(null),[c,m]=w(!1),k=Q(()=>Array.from(new Set(e.map(x=>x.harness??"claude"))).sort(),[e]),g=Q(()=>{if(t.length>0)return t;const x=new Set;for(const v of e)v.account&&x.add(v.account);return Array.from(x).sort()},[t,e]),b=Q(()=>{const x=new Set;for(const v of e)o&&v.account!==o||ue(v)&&x.add(v.project);for(const[v,C]of Object.entries(r))o&&C.account!==o||x.add(v);return Array.from(x).sort()},[e,r,o]),f=x=>{if(i(x),x&&a){const v=r[a];v&&v.account!==x&&l(null)}},u=Q(()=>e.filter(x=>!(o&&x.account!==o||a&&x.project!==a||d&&(x.harness??"claude")!==d||s&&x.type!==Ai(s)||!c&&x.status==="done")),[e,o,a,s,d,c]);return{filterAccount:o,setFilterAccount:f,filterProject:a,setFilterProject:l,filterType:s,setFilterType:p,filterHarness:d,setFilterHarness:h,showDone:c,setShowDone:m,accountNames:g,projectNames:b,harnessNames:k,filteredSpaces:u}}function Ps(){const[e,t]=w([]),[r,o]=w({}),[i,a]=w([]),[l,s]=w(!0),[p,d]=w("list"),[h,c]=w(!1),[m,k]=w(null),[g,b]=w(!1);F(()=>{ge(),jo(),fetch("/api/liveframe/frames").then($=>$.json()).then($=>k($.length)).catch(()=>{})},[]);const f=Y(async()=>{try{const[$,T,W]=await Promise.all([fetch("/api/cw/spaces"),fetch("/api/cw/projects"),fetch("/api/cw/accounts")]);t(await $.json()),o(await T.json()),a(await W.json()),ya()}catch{P("Failed to connect to server","error")}finally{s(!1)}},[]),u=Y(()=>{setTimeout(f,500),setTimeout(f,2500)},[f]);F(()=>{f()},[f]);const x=zs({spaces:e,loading:l,onFetchData:f}),v=js({spaces:e,accounts:i,projects:r}),C=Object.keys(r).length>0,y=$=>{const T=Ue.find(W=>W.key===$);T&&(De.value=T.key),c(!0)},[R,A]=w(null),L=Y(async($,T)=>{try{const H=await(await fetch("/api/cw/done",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:$.project,task:$.type==="review"?$.pr:$.task,type:$.type,sessionDir:$.sessionDir})})).json();if(H.ok)P("Task closed","info"),T==null||T(),u();else{const ne=H.error??"cw --done failed";console.error(`[forge] closing ${$.project}/${$.task??$.pr} failed:
31
- ${ne}`),P(ne.split(`
32
- `)[0],"error")}}catch{P("Failed to close the task","error")}},[u]),I=Y(async($,T)=>{const W=await Rn($,!0);if(W.state&&W.state.closeWarnings.length===0){await L($,T);return}A({session:$,state:W.state,error:W.error,onClosed:T})},[L]),S=n(Rs,{request:R,onCancel:()=>A(null),onConfirm:async()=>{const $=R;if($)try{await L($.session,$.onClosed)}finally{A(null)}}}),z=Y($=>{Se.value=!1,x.showList||x.goToList(),c(!1),d($)},[x.showList,x.goToList]),_=Y(()=>z("list"),[z]),N=Y(()=>c(!1),[]),O=Y($=>{v.setFilterProject(v.filterProject===$?null:$),z("list")},[v.filterProject,v.setFilterProject,z]),E=Y($=>{Se.value=!1,c(!1),x.openTab($)},[x.openTab]),[B,U]=w(!1),M=Y(()=>U(!1),[]),j=Y(()=>U(!0),[]);F(()=>{const $=T=>{const W=T.metaKey||T.ctrlKey,H=T.key.toLowerCase();if(W&&H==="j"){T.preventDefault(),gr();return}if(W&&H==="k"){T.preventDefault(),B?U(!1):j();return}const ne=T.target;ne!=null&&ne.closest('input, textarea, select, [contenteditable="true"]')||W||T.altKey||B||h||g||(T.key==="/"?(T.preventDefault(),j()):H==="n"?(T.preventDefault(),c(!0)):H==="p"&&(T.preventDefault(),b(!0)))};return window.addEventListener("keydown",$),()=>window.removeEventListener("keydown",$)},[B,h,g,j]);const G=Y(async($,T,W,H)=>{try{const re=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"general",account:T,project:W,description:$})})).json();re.ok&&re.session?(E(re.session),u(),P(H,"success")):P(re.error??"Failed to start session","error")}catch{P("Failed to start session","error")}},[E,u]),V=Y(($,T)=>{const W=$==="project"&&r[T]?T:void 0;return{account:$==="account"?T:W?r[W].account:i[0]||"default",project:W}},[i,r]),de=Y(($,T,W)=>{const{account:H,project:ne}=V($,T),re=$==="global"?"~/.claude/skills/":$==="account"?`~/.cw/accounts/${T}/skills/`:`${ne?r[ne].path:"<project>"}/.claude/skills/`,_e=["Use the skill-creator skill to create a new Claude Code skill.","",`The user wants: ${W}`,`Target scope: ${$}${$!=="global"?` (${T})`:""}`,`Save location: ${re}`,"","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(`
33
- `);G(_e,H,ne,"AI skill creation session started")},[r,V,G]),ae=Y($=>{const{account:T,project:W}=V($.scope,$.scopeRef);G(`Use the ${$.name} skill.`,T,W,`Session started with ${$.name}`)},[V,G]),ce=Y(async($,T,W,H)=>{if(!$.project)return!1;try{const re=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"task",project:$.project,task:Va(T),description:Ya($,T,W),account:H,harness:"claude"})})).json();if(re.ok&&re.session)return E(re.session),u(),P(`Proposing a skill in ${$.project}`,"success"),!0;P(re.error??"Failed to start session","error")}catch{P("Failed to start session","error")}return!1},[E,u]);F(()=>{l||xo().catch(()=>{})},[l]);const pe=Q(()=>e.filter($=>$.status==="active"),[e]),ke=Q(()=>x.openTabs.filter($=>$.status==="active"&&$.type!=="login").map($=>({key:K($),session:$})),[x.openTabs]),xe=!x.showList&&x.openTabs.length>0;F(()=>{const $=xe?x.openTabs[x.activeTabIndex]:void 0;br.value=$?K($):null},[xe,x.openTabs,x.activeTabIndex]);const Pe=X({openTabs:x.openTabs,spaces:e,openSession:E});Pe.current={openTabs:x.openTabs,spaces:e,openSession:E},F(()=>ta(($,T)=>{if(document.visibilityState==="visible"&&$===br.value)return;const{openTabs:W,spaces:H,openSession:ne}=Pe.current,re=W.find(_e=>K(_e)===$)??H.find(_e=>K(_e)===$);re&&oa(`${he(re)}: ${Wt(T).toLowerCase()}`,ue(re)||re.account,$,()=>ne(re))}),[]);const Ke=Object.values(Te.value).filter(Oe).length;F(()=>{document.title=Ke>0?`(${Ke}) Forge Console`:"Forge Console"},[Ke]);const Yt=Q(()=>{const $=new Map(Object.entries(r).map(([T,W])=>[T,W.account]));for(const T of e)ue(T)&&!$.has(T.project)&&$.set(T.project,T.account);return Array.from($,([T,W])=>({name:T,account:W||"unassigned",count:pe.filter(H=>H.project===T).length,live:ke.some(H=>H.session.project===T)}))},[r,e,pe,ke]);F(()=>{v.filterProject&&(Ie.value=v.filterProject)},[v.filterProject]);const Qt=Q(()=>Object.keys(r),[r]),er=Y($=>{v.setFilterProject($),z("list")},[v.setFilterProject,z]),ht=xe?"list":p,ft=Q(()=>[{id:"new-task",label:"New task",hint:"N",glyph:"+",token:"--blue",run:()=>y()},{id:"add-project",label:"Add project",hint:"P",glyph:"P",token:"--green",run:()=>b(!0)},...Ro.map($=>({id:$.view,label:$.label,hint:$.view==="list"?"⌘L":"",glyph:$.glyph,token:$.token,run:()=>z($.view)})),{id:"appearance",label:"Toggle appearance",hint:"⌘J",glyph:"◐",token:null,run:gr}],[z]),Zt=n(da,{view:ht,counts:{list:pe.length,accounts:v.accountNames.length,prototypes:m},projects:Yt,accounts:v.accountNames,selectedProject:v.filterProject,live:ke,onNavigate:z,onSelectProject:O,onAddProject:()=>{Se.value=!1,b(!0)},onOpenLive:E,onSearch:j}),Xt=l?n("div",{class:"py-20 text-center text-ink2",children:"Loading…"}):p==="list"&&!C?n("div",{style:{padding:"56px 22px"},children:n(to,{icon:"i-lucide-folder",title:"Welcome to Forge",description:"No projects found in CW. Register a project with 'cw open <project>' or create one with 'cw create' first.",action:{label:"Add project",onClick:()=>b(!0)}})}):p==="list"?n(Wa,{spaces:v.filteredSpaces,allSpaces:e,projects:r,accountNames:v.accountNames,filterAccount:v.filterAccount,filterProject:v.filterProject,onFilterProject:v.setFilterProject,filterType:v.filterType,onFilterType:v.setFilterType,harnessNames:v.harnessNames,filterHarness:v.filterHarness,onFilterHarness:v.setFilterHarness,showDone:v.showDone,onShowDone:v.setShowDone,openTabKeys:x.openTabKeys,onSelectTask:E,onMarkDone:I,onNewTask:()=>y(),onCreateProject:()=>b(!0),onRefresh:()=>f(),onStarted:$=>{$&&E($),u()}}):p==="prototypes"?n(hs,{accounts:v.accountNames,onOpenSession:E,onFramesChanged:k}):p==="accounts"?n(Ss,{projects:r,onOpenSession:E,onAccountsChanged:()=>{f()}}):n(us,{accounts:v.accountNames,projects:r,onCreateWithAI:de,onRunSkill:ae,onProposeSkill:ce});return n(Pi,{sidebar:Zt,children:[!xe&&Xt,x.openTabs.length>0&&n("div",{class:"flex flex-col","aria-hidden":!xe,style:xe?{height:"100vh"}:{position:"absolute",top:0,left:0,right:0,height:"100vh",visibility:"hidden",pointerEvents:"none",zIndex:-1},children:[n($s,{tabs:x.openTabs,activeIndex:x.activeTabIndex,onActivate:x.setActiveTabIndex,onClose:x.closeTab,onBack:_,allSessions:pe,openTabKeys:x.openTabKeys,onOpenSession:E,onNewTask:$=>{_(),y($)}}),n("div",{class:"flex-1 min-h-0 relative",children:x.openTabs.map(($,T)=>{const W=T===x.activeTabIndex,H=W&&xe;return n("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,display:"flex",flexDirection:"column",visibility:H?"visible":"hidden",zIndex:W?1:0,pointerEvents:H?"auto":"none"},children:n(Ba,{session:$,active:H,onDone:()=>I($,()=>{x.closeTabByKey(K($))})})},K($))})})]}),h&&n(Ja,{projects:r,accounts:v.accountNames,initialAccount:v.filterAccount??(Ft.value||void 0),initialProject:Ie.value||void 0,onClose:N,onCreated:$=>{c(!1),$&&E($),u()},onOpenAccounts:()=>z("accounts")}),B&&n(pa,{openTabs:x.openTabs,sessions:e,projects:Qt,commands:ft,onOpenSession:E,onSelectProject:er,onClose:M}),n(fs,{open:g,accounts:v.accountNames,onClose:()=>b(!1),onCreated:$=>{b(!1),$&&E($),u()}}),S]})}ai(n(Ps,{}),document.getElementById("app"));