forge-cw 0.1.7 → 0.1.8
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,36 @@
|
|
|
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 s of a.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&o(s)}).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 un,B,go,xo,ze,Cr,mo,yo,wn,Ut,pt,bo,ar,Mn,Bn,Yt={},Qt=[],Vi=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,$t=Array.isArray;function we(e,t){for(var r in t)e[r]=t[r];return e}function lr(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function yt(e,t,r){var o,i,a,s={};for(a in t)a=="key"?o=t[a]:a=="ref"?i=t[a]:s[a]=t[a];if(arguments.length>2&&(s.children=arguments.length>3?un.call(arguments,2):r),typeof e=="function"&&e.defaultProps!=null)for(a in e.defaultProps)s[a]===void 0&&(s[a]=e.defaultProps[a]);return Ht(e,s,o,i,null)}function Ht(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??++go,__i:-1,__u:0};return i==null&&B.vnode!=null&&B.vnode(a),a}function K(e){return e.children}function be(e,t){this.props=e,this.context=t}function Ke(e,t){if(t==null)return e.__?Ke(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"?Ke(e):null}function Ji(e){if(e.__P&&e.__d){var t=e.__v,r=t.__e,o=[],i=[],a=we({},t);a.__v=t.__v+1,B.vnode&&B.vnode(a),sr(e.__P,a,t,e.__n,e.__P.namespaceURI,32&t.__u?[r]:null,o,r??Ke(t),!!(32&t.__u),i),a.__v=t.__v,a.__.__k[a.__i]=a,So(o,a,i),t.__e=t.__=null,a.__e!=r&&ko(a)}}function ko(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}),ko(e)}function zr(e){(!e.__d&&(e.__d=!0)&&ze.push(e)&&!Zt.__r++||Cr!=B.debounceRendering)&&((Cr=B.debounceRendering)||mo)(Zt)}function Zt(){try{for(var e,t=1;ze.length;)ze.length>t&&ze.sort(yo),e=ze.shift(),t=ze.length,Ji(e)}finally{ze.length=Zt.__r=0}}function _o(e,t,r,o,i,a,s,l,c,d,h){var p,v,b,m,y,u,g,k=o&&o.__k||Qt,f=t.length;for(c=Yi(r,t,k,c,f),p=0;p<f;p++)(b=r.__k[p])!=null&&(v=b.__i!=-1&&k[b.__i]||Yt,b.__i=p,u=sr(e,b,v,i,a,s,l,c,d,h),m=b.__e,b.ref&&v.ref!=b.ref&&(v.ref&&cr(v.ref,null,b),h.push(b.ref,b.__c||m,b)),y==null&&m!=null&&(y=m),(g=!!(4&b.__u))||v.__k===b.__k?(c=wo(b,c,e,g),g&&v.__e&&(v.__e=null)):typeof b.type=="function"&&u!==void 0?c=u:m&&(c=m.nextSibling),b.__u&=-7);return r.__e=y,c}function Yi(e,t,r,o,i){var a,s,l,c,d,h=r.length,p=h,v=0;for(e.__k=new Array(i),a=0;a<i;a++)(s=t[a])!=null&&typeof s!="boolean"&&typeof s!="function"?(typeof s=="string"||typeof s=="number"||typeof s=="bigint"||s.constructor==String?s=e.__k[a]=Ht(null,s,null,null,null):$t(s)?s=e.__k[a]=Ht(K,{children:s},null,null,null):s.constructor===void 0&&s.__b>0?s=e.__k[a]=Ht(s.type,s.props,s.key,s.ref?s.ref:null,s.__v):e.__k[a]=s,c=a+v,s.__=e,s.__b=e.__b+1,l=null,(d=s.__i=Qi(s,r,c,p))!=-1&&(p--,(l=r[d])&&(l.__u|=2)),l==null||l.__v==null?(d==-1&&(i>h?v--:i<h&&v++),typeof s.type!="function"&&(s.__u|=4)):d!=c&&(d==c-1?v--:d==c+1?v++:(d>c?v--:v++,s.__u|=4))):e.__k[a]=null;if(p)for(a=0;a<h;a++)(l=r[a])!=null&&(2&l.__u)==0&&(l.__e==o&&(o=Ke(l)),Co(l,l));return o}function wo(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=wo(i[a],t,r,o));return t}e.__e!=t&&(o&&(t&&e.type&&!t.parentNode&&(t=Ke(e)),r.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function Xt(e,t){return t=t||[],e==null||typeof e=="boolean"||($t(e)?e.some(function(r){Xt(r,t)}):t.push(e)),t}function Qi(e,t,r,o){var i,a,s,l=e.key,c=e.type,d=t[r],h=d!=null&&(2&d.__u)==0;if(d===null&&l==null||h&&l==d.key&&c==d.type)return r;if(o>(h?1:0)){for(i=r-1,a=r+1;i>=0||a<t.length;)if((d=t[s=i>=0?i--:a++])!=null&&(2&d.__u)==0&&l==d.key&&c==d.type)return s}return-1}function Tr(e,t,r){t[0]=="-"?e.setProperty(t,r??""):e[t]=r==null?"":typeof r!="number"||Vi.test(t)?r:r+"px"}function Lt(e,t,r,o,i){var a,s;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||Tr(e.style,t,"");if(r)for(t in r)o&&r[t]==o[t]||Tr(e.style,t,r[t])}else if(t[0]=="o"&&t[1]=="n")a=t!=(t=t.replace(bo,"$1")),s=t.toLowerCase(),t=s in e||t=="onFocusOut"||t=="onFocusIn"?s.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+a]=r,r?o?r[pt]=o[pt]:(r[pt]=ar,e.addEventListener(t,a?Bn:Mn,a)):e.removeEventListener(t,a?Bn: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 Rr(e){return function(t){if(this.l){var r=this.l[t.type+e];if(t[Ut]==null)t[Ut]=ar++;else if(t[Ut]<r[pt])return;return r(B.event?B.event(t):t)}}}function sr(e,t,r,o,i,a,s,l,c,d){var h,p,v,b,m,y,u,g,k,f,C,x,j,R,E,L=t.type;if(t.constructor!==void 0)return null;128&r.__u&&(c=!!(32&r.__u),a=[l=t.__e=r.__e]),(h=B.__b)&&h(t);e:if(typeof L=="function")try{if(g=t.props,k=L.prototype&&L.prototype.render,f=(h=L.contextType)&&o[h.__c],C=h?f?f.props.value:h.__:o,r.__c?u=(p=t.__c=r.__c).__=p.__E:(k?t.__c=p=new L(g,C):(t.__c=p=new be(g,C),p.constructor=L,p.render=Xi),f&&f.sub(p),p.state||(p.state={}),p.__n=o,v=p.__d=!0,p.__h=[],p._sb=[]),k&&p.__s==null&&(p.__s=p.state),k&&L.getDerivedStateFromProps!=null&&(p.__s==p.state&&(p.__s=we({},p.__s)),we(p.__s,L.getDerivedStateFromProps(g,p.__s))),b=p.props,m=p.state,p.__v=t,v)k&&L.getDerivedStateFromProps==null&&p.componentWillMount!=null&&p.componentWillMount(),k&&p.componentDidMount!=null&&p.__h.push(p.componentDidMount);else{if(k&&L.getDerivedStateFromProps==null&&g!==b&&p.componentWillReceiveProps!=null&&p.componentWillReceiveProps(g,C),t.__v==r.__v||!p.__e&&p.shouldComponentUpdate!=null&&p.shouldComponentUpdate(g,p.__s,C)===!1){t.__v!=r.__v&&(p.props=g,p.state=p.__s,p.__d=!1),t.__e=r.__e,t.__k=r.__k,t.__k.some(function(S){S&&(S.__=t)}),Qt.push.apply(p.__h,p._sb),p._sb=[],p.__h.length&&s.push(p);break e}p.componentWillUpdate!=null&&p.componentWillUpdate(g,p.__s,C),k&&p.componentDidUpdate!=null&&p.__h.push(function(){p.componentDidUpdate(b,m,y)})}if(p.context=C,p.props=g,p.__P=e,p.__e=!1,x=B.__r,j=0,k)p.state=p.__s,p.__d=!1,x&&x(t),h=p.render(p.props,p.state,p.context),Qt.push.apply(p.__h,p._sb),p._sb=[];else do p.__d=!1,x&&x(t),h=p.render(p.props,p.state,p.context),p.state=p.__s;while(p.__d&&++j<25);p.state=p.__s,p.getChildContext!=null&&(o=we(we({},o),p.getChildContext())),k&&!v&&p.getSnapshotBeforeUpdate!=null&&(y=p.getSnapshotBeforeUpdate(b,m)),R=h!=null&&h.type===K&&h.key==null?$o(h.props.children):h,l=_o(e,$t(R)?R:[R],t,r,o,i,a,s,l,c,d),p.base=t.__e,t.__u&=-161,p.__h.length&&s.push(p),u&&(p.__E=p.__=null)}catch(S){if(t.__v=null,c||a!=null)if(S.then){for(t.__u|=c?160:128;l&&l.nodeType==8&&l.nextSibling;)l=l.nextSibling;a[a.indexOf(l)]=null,t.__e=l}else{for(E=a.length;E--;)lr(a[E]);Un(t)}else t.__e=r.__e,t.__k=r.__k,S.then||Un(t);B.__e(S,t,r)}else a==null&&t.__v==r.__v?(t.__k=r.__k,t.__e=r.__e):l=t.__e=Zi(r.__e,t,r,o,i,a,s,c,d);return(h=B.diffed)&&h(t),128&t.__u?void 0:l}function Un(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(Un))}function So(e,t,r){for(var o=0;o<r.length;o++)cr(r[o],r[++o],r[++o]);B.__c&&B.__c(t,e),e.some(function(i){try{e=i.__h,i.__h=[],e.some(function(a){a.call(i)})}catch(a){B.__e(a,i.__v)}})}function $o(e){return typeof e!="object"||e==null||e.__b>0?e:$t(e)?e.map($o):we({},e)}function Zi(e,t,r,o,i,a,s,l,c){var d,h,p,v,b,m,y,u=r.props||Yt,g=t.props,k=t.type;if(k=="svg"?i="http://www.w3.org/2000/svg":k=="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((b=a[d])&&"setAttribute"in b==!!k&&(k?b.localName==k:b.nodeType==3)){e=b,a[d]=null;break}}if(e==null){if(k==null)return document.createTextNode(g);e=document.createElementNS(i,k,g.is&&g),l&&(B.__m&&B.__m(t,a),l=!1),a=null}if(k==null)u===g||l&&e.data==g||(e.data=g);else{if(a=a&&un.call(e.childNodes),!l&&a!=null)for(u={},d=0;d<e.attributes.length;d++)u[(b=e.attributes[d]).name]=b.value;for(d in u)b=u[d],d=="dangerouslySetInnerHTML"?p=b:d=="children"||d in g||d=="value"&&"defaultValue"in g||d=="checked"&&"defaultChecked"in g||Lt(e,d,null,b,i);for(d in g)b=g[d],d=="children"?v=b:d=="dangerouslySetInnerHTML"?h=b:d=="value"?m=b:d=="checked"?y=b:l&&typeof b!="function"||u[d]===b||Lt(e,d,b,u[d],i);if(h)l||p&&(h.__html==p.__html||h.__html==e.innerHTML)||(e.innerHTML=h.__html),t.__k=[];else if(p&&(e.innerHTML=""),_o(t.type=="template"?e.content:e,$t(v)?v:[v],t,r,o,k=="foreignObject"?"http://www.w3.org/1999/xhtml":i,a,s,a?a[0]:r.__k&&Ke(r,0),l,c),a!=null)for(d=a.length;d--;)lr(a[d]);l||(d="value",k=="progress"&&m==null?e.removeAttribute("value"):m!=null&&(m!==e[d]||k=="progress"&&!m||k=="option"&&m!=u[d])&&Lt(e,d,m,u[d],i),d="checked",y!=null&&y!=e[d]&&Lt(e,d,y,u[d],i))}return e}function cr(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){B.__e(i,r)}}function Co(e,t,r){var o,i;if(B.unmount&&B.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||cr(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(a){B.__e(a,t)}o.base=o.__P=null}if(o=e.__k)for(i=0;i<o.length;i++)o[i]&&Co(o[i],t,r||typeof e.type!="function");r||lr(e.__e),e.__c=e.__=e.__e=void 0}function Xi(e,t,r){return this.constructor(e,r)}function Hn(e,t,r){var o,i,a,s;t==document&&(t=document.documentElement),B.__&&B.__(e,t),i=(o=!1)?null:t.__k,a=[],s=[],sr(t,e=t.__k=yt(K,null,[e]),i||Yt,Yt,t.namespaceURI,i?null:t.firstChild?un.call(t.childNodes):null,a,i?i.__e:t.firstChild,o,s),So(a,e,s)}un=Qt.slice,B={__e:function(e,t,r,o){for(var i,a,s;t=t.__;)if((i=t.__c)&&!i.__)try{if((a=i.constructor)&&a.getDerivedStateFromError!=null&&(i.setState(a.getDerivedStateFromError(e)),s=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(e,o||{}),s=i.__d),s)return i.__E=i}catch(l){e=l}throw e}},go=0,xo=function(e){return e!=null&&e.constructor===void 0},be.prototype.setState=function(e,t){var r;r=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=we({},this.state),typeof e=="function"&&(e=e(we({},r),this.props)),e&&we(r,e),e!=null&&this.__v&&(t&&this._sb.push(t),zr(this))},be.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),zr(this))},be.prototype.render=K,ze=[],mo=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,yo=function(e,t){return e.__v.__b-t.__v.__b},Zt.__r=0,wn=Math.random().toString(8),Ut="__d"+wn,pt="__a"+wn,bo=/(PointerCapture)$|Capture$/i,ar=0,Mn=Rr(!1),Bn=Rr(!0);var ea=0;function n(e,t,r,o,i,a){t||(t={});var s,l,c=t;if("ref"in c)for(l in c={},t)l=="ref"?s=t[l]:c[l]=t[l];var d={type:e,props:c,key:r,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--ea,__i:-1,__u:0,__source:i,__self:a};if(typeof e=="function"&&(s=e.defaultProps))for(l in s)c[l]===void 0&&(c[l]=s[l]);return B.vnode&&B.vnode(d),d}var bt,ne,Sn,Pr,kt=0,zo=[],oe=B,jr=oe.__b,Ar=oe.__r,Er=oe.diffed,Lr=oe.__c,Nr=oe.unmount,Ir=oe.__;function dr(e,t){oe.__h&&oe.__h(ne,e,kt||t),kt=0;var r=ne.__H||(ne.__H={__:[],__h:[]});return e>=r.__.length&&r.__.push({}),r.__[e]}function w(e){return kt=1,ta(Ro,e)}function ta(e,t,r){var o=dr(bt++,2);if(o.t=e,!o.__c&&(o.__=[r?r(t):Ro(void 0,t),function(l){var c=o.__N?o.__N[0]:o.__[0],d=o.t(c,l);c!==d&&(o.__N=[d,o.__[1]],o.__c.setState({}))}],o.__c=ne,!ne.__f)){var i=function(l,c,d){if(!o.__c.__H)return!0;var h=o.__c.__H.__.filter(function(v){return v.__c});if(h.every(function(v){return!v.__N}))return!a||a.call(this,l,c,d);var p=o.__c.props!==l;return h.some(function(v){if(v.__N){var b=v.__[0];v.__=v.__N,v.__N=void 0,b!==v.__[0]&&(p=!0)}}),a&&a.call(this,l,c,d)||p};ne.__f=!0;var a=ne.shouldComponentUpdate,s=ne.componentWillUpdate;ne.componentWillUpdate=function(l,c,d){if(this.__e){var h=a;a=void 0,i(l,c,d),a=h}s&&s.call(this,l,c,d)},ne.shouldComponentUpdate=i}return o.__N||o.__}function D(e,t){var r=dr(bt++,3);!oe.__s&&To(r.__H,t)&&(r.__=e,r.u=t,ne.__H.__h.push(r))}function ee(e){return kt=5,Z(function(){return{current:e}},[])}function Z(e,t){var r=dr(bt++,7);return To(r.__H,t)&&(r.__=e(),r.__H=t,r.__h=e),r.__}function Y(e,t){return kt=8,Z(function(){return e},t)}function na(){for(var e;e=zo.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Kt),t.__h.some(Kn),t.__h=[]}catch(r){t.__h=[],oe.__e(r,e.__v)}}}oe.__b=function(e){ne=null,jr&&jr(e)},oe.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Ir&&Ir(e,t)},oe.__r=function(e){Ar&&Ar(e),bt=0;var t=(ne=e.__c).__H;t&&(Sn===ne?(t.__h=[],ne.__h=[],t.__.some(function(r){r.__N&&(r.__=r.__N),r.u=r.__N=void 0})):(t.__h.some(Kt),t.__h.some(Kn),t.__h=[],bt=0)),Sn=ne},oe.diffed=function(e){Er&&Er(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(zo.push(t)!==1&&Pr===oe.requestAnimationFrame||((Pr=oe.requestAnimationFrame)||ra)(na)),t.__H.__.some(function(r){r.u&&(r.__H=r.u),r.u=void 0})),Sn=ne=null},oe.__c=function(e,t){t.some(function(r){try{r.__h.some(Kt),r.__h=r.__h.filter(function(o){return!o.__||Kn(o)})}catch(o){t.some(function(i){i.__h&&(i.__h=[])}),t=[],oe.__e(o,r.__v)}}),Lr&&Lr(e,t)},oe.unmount=function(e){Nr&&Nr(e);var t,r=e.__c;r&&r.__H&&(r.__H.__.some(function(o){try{Kt(o)}catch(i){t=i}}),r.__H=void 0,t&&oe.__e(t,r.__v))};var Or=typeof requestAnimationFrame=="function";function ra(e){var t,r=function(){clearTimeout(o),Or&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(r,35);Or&&(t=requestAnimationFrame(r))}function Kt(e){var t=ne,r=e.__c;typeof r=="function"&&(e.__c=void 0,r()),ne=t}function Kn(e){var t=ne;e.__c=e.__(),ne=t}function To(e,t){return!e||e.length!==t.length||t.some(function(r,o){return r!==e[o]})}function Ro(e,t){return typeof t=="function"?t(e):t}var oa=Symbol.for("preact-signals");function hn(){if(Se>1)Se--;else{var e,t=!1;for((function(){var i=tn;for(tn=void 0;i!==void 0;)i.S.v===i.v&&(i.S.i=i.i),i=i.o})();ut!==void 0;){var r=ut;for(ut=void 0,en++;r!==void 0;){var o=r.u;if(r.u=void 0,r.f&=-3,!(8&r.f)&&jo(r))try{r.c()}catch(i){t||(e=i,t=!0)}r=o}}if(en=0,Se--,t)throw e}}function ia(e){if(Se>0)return e();qn=++aa,Se++;try{return e()}finally{hn()}}var Q=void 0;function pr(e){var t=Q;Q=void 0;try{return e()}finally{Q=t}}var ut=void 0,Se=0,en=0,aa=0,qn=0,tn=void 0,nn=0;function Po(e){if(Q!==void 0){var t=e.n;if(t===void 0||t.t!==Q)return t={i:0,S:e,p:Q.s,n:void 0,t:Q,e:void 0,x:void 0,r:t},Q.s!==void 0&&(Q.s.n=t),Q.s=t,e.n=t,32&Q.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=Q.s,t.n=void 0,Q.s.n=t,Q.s=t),t}}function ce(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}ce.prototype.brand=oa;ce.prototype.h=function(){return!0};ce.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:pr(function(){var o;(o=t.W)==null||o.call(t)}))};ce.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&&pr(function(){var i;(i=t.Z)==null||i.call(t)}))}};ce.prototype.subscribe=function(e){var t=this;return Ct(function(){var r=t.value,o=Q;Q=void 0;try{e(r)}finally{Q=o}},{name:"sub"})};ce.prototype.valueOf=function(){return this.value};ce.prototype.toString=function(){return this.value+""};ce.prototype.toJSON=function(){return this.value};ce.prototype.peek=function(){var e=this;return pr(function(){return e.value})};Object.defineProperty(ce.prototype,"value",{get:function(){var e=Po(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(en>100)throw new Error("Cycle detected");(function(r){Se!==0&&en===0&&r.l!==qn&&(r.l=qn,tn={S:r,v:r.v,i:r.i,o:tn})})(this),this.v=e,this.i++,nn++,Se++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{hn()}}}});function X(e,t){return new ce(e,t)}function jo(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 Ao(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 Eo(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 Ie(e,t){ce.call(this,void 0),this.x=e,this.s=void 0,this.g=nn-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}Ie.prototype=new ce;Ie.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===nn))return!0;if(this.g=nn,this.f|=1,this.i>0&&!jo(this))return this.f&=-2,!0;var e=Q;try{Ao(this),Q=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 Q=e,Eo(this),this.f&=-2,!0};Ie.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)}ce.prototype.S.call(this,e)};Ie.prototype.U=function(e){if(this.t!==void 0&&(ce.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)}};Ie.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(Ie.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Po(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function Wr(e,t){return new Ie(e,t)}function Lo(e){var t=e.m;if(e.m=void 0,typeof t=="function"){Se++;var r=Q;Q=void 0;try{t()}catch(o){throw e.f&=-2,e.f|=8,ur(e),o}finally{Q=r,hn()}}}function ur(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Lo(e)}function la(e){if(Q!==this)throw new Error("Out-of-order effect");Eo(this),Q=e,this.f&=-2,8&this.f&&ur(this),hn()}function Ze(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}Ze.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()}};Ze.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Lo(this),Ao(this),Se++;var e=Q;return Q=this,la.bind(this,e)};Ze.prototype.N=function(){2&this.f||(this.f|=2,this.u=ut,ut=this)};Ze.prototype.d=function(){this.f|=8,1&this.f||ur(this)};Ze.prototype.dispose=function(){this.d()};function Ct(e,t){var r=new Ze(e,t);try{r.c()}catch(i){throw r.d(),i}var o=r.d.bind(r);return o[Symbol.dispose]=o,o}var No,Nt,sa=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__,Io=[];Ct(function(){No=this.N})();function Xe(e,t){B[e]=t.bind(null,B[e]||function(){})}function rn(e){if(Nt){var t=Nt;Nt=void 0,t()}Nt=e&&e.S()}function Oo(e){var t=this,r=e.data,o=da(r);o.value=r;var i=Z(function(){for(var l=t,c=t.__v;c=c.__;)if(c.__c){c.__c.__$f|=4;break}var d=Wr(function(){var b=o.value.value;return b===0?0:b===!0?"":b||""}),h=Wr(function(){return!Array.isArray(d.value)&&!xo(d.value)}),p=Ct(function(){if(this.N=Wo,h.value){var b=d.value;l.__v&&l.__v.__e&&l.__v.__e.nodeType===3&&(l.__v.__e.data=b)}}),v=t.__$u.d;return t.__$u.d=function(){p(),v.call(this)},[h,d]},[]),a=i[0],s=i[1];return a.value?s.peek():s.value}Oo.displayName="ReactiveTextNode";Object.defineProperties(ce.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:Oo},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}});Xe("__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 ce&&(r||(t.__np=r={}),r[i]=a,o[i]=a.peek())}}e(t)});Xe("__r",function(e,t){if(e(t),t.type!==K){rn();var r,o=t.__c;o&&(o.__$f&=-2,(r=o.__$u)===void 0&&(o.__$u=r=(function(i,a){var s;return Ct(function(){s=this},{name:a}),s.c=i,s})(function(){var i;sa&&((i=r.y)==null||i.call(r)),o.__$f|=1,o.setState({})},typeof t.type=="function"?t.type.displayName||t.type.name:""))),rn(r)}});Xe("__e",function(e,t,r,o){rn(),e(t,r,o)});Xe("diffed",function(e,t){rn();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 s in a){var l=a[s];l!==void 0&&!(s in o)&&(l.d(),a[s]=void 0)}else a={},r.U=a;for(var c in o){var d=a[c],h=o[c];d===void 0?(d=ca(r,c,h),a[c]=d):d.o(h,i)}for(var p in o)i[p]=o[p]}}e(t)});function ca(e,t,r,o){var i=t in e&&e.ownerSVGElement===void 0,a=X(r),s=r.peek();return{o:function(l,c){a.value=l,s=l.peek()},d:Ct(function(){this.N=Wo;var l=a.value.value;s!==l?(s=void 0,i?e[t]=l:l!=null&&(l!==!1||t[4]==="-")?e.setAttribute(t,l):e.removeAttribute(t)):s=void 0})}}Xe("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 s=t.__c;if(s){var l=s.__$u;l&&(s.__$u=void 0,l.d())}}e(t)});Xe("__h",function(e,t,r,o){(o<3||o===9)&&(t.__$f|=2),e(t,r,o)});be.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 s in e)if(s!=="__source"&&e[s]!==this.props[s])return!0;for(var l in this.props)if(!(l in e))return!0;return!1};function da(e,t){return Z(function(){return X(e,t)},[])}var pa=function(e){queueMicrotask(function(){queueMicrotask(e)})};function ua(){ia(function(){for(var e;e=Io.shift();)No.call(e)})}function Wo(){Io.push(this)===1&&(B.requestAnimationFrame||pa)(ua)}const ha={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"}},Dr={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"}},fa={background:"var(--elev)",color:"var(--ink-3)",border:"1px solid transparent",boxShadow:"none",opacity:".8"},I=({label:e,icon:t,variant:r="primary",size:o="md",block:i,title:a,disabled:s,loading:l,onClick:c})=>{const[d,h]=w(!1),p=l??d,v=!!(s||p),b=async()=>{if(!v){h(!0);try{await c()}finally{h(!1)}}},m=ha[o],y=r==="primary"||r==="destructive",u=s&&!p?{...Dr[r],...fa}:Dr[r];return n("button",{type:"button",class:`inline-flex items-center justify-center gap-1.5 whitespace-nowrap transition-all duration-180 ease-spring ${v?"cursor-not-allowed":`cursor-pointer hover:-translate-y-px hover:shadow-m${y?" hover:brightness-106":""}`}${i?" w-full":""}`,style:{...u,padding:y?m.primaryPad:m.pad,fontSize:m.font,borderRadius:m.radius},disabled:v,title:a,onClick:b,children:[p?n("span",{class:"i-lucide-loader-2 animate-spin"}):t?n("span",{class:t}):null,n("span",{children:e})]})},va="modulepreload",ga=function(e){return"/"+e},Fr={},$n=function(t,r,o){let i=Promise.resolve();if(r&&r.length>0){let s=function(d){return Promise.all(d.map(h=>Promise.resolve(h).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),c=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));i=s(r.map(d=>{if(d=ga(d),d in Fr)return;Fr[d]=!0;const h=d.endsWith(".css"),p=h?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${p}`))return;const v=document.createElement("link");if(v.rel=h?"stylesheet":va,h||(v.as="script"),v.crossOrigin="",v.href=d,c&&v.setAttribute("nonce",c),document.head.appendChild(v),h)return new Promise((b,m)=>{v.addEventListener("load",b),v.addEventListener("error",()=>m(new Error(`Unable to preload CSS for ${d}`)))})}))}function a(s){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=s,window.dispatchEvent(l),!l.defaultPrevented)throw s}return i.then(s=>{for(const l of s||[])l.status==="rejected"&&a(l.reason);return t().catch(a)})},xa='ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace',Cn=e=>({background:e==="dark"?"#0e0e10":"#1c1c1e",foreground:"#e3e3e8",cursor:"#e3e3e8",selectionBackground:"rgba(10,132,255,0.35)"}),ma=({streamUrl:e,content:t,wsUrl:r,height:o=300,onExit:i,onGiveUp:a,onConnectionChange:s,onOutput:l,focused:c=!0,theme:d="dark"})=>{const h=ee(null),p=!!r,v=ee(i);v.current=i;const b=ee(a);b.current=a;const m=ee(s);m.current=s;const y=ee(l);y.current=l;const u=ee(d);u.current=d;const g=ee(c);g.current=c;const k=ee(null);D(()=>{k.current&&(k.current.options.theme=Cn(d))},[d]),D(()=>{var C;p&&c&&((C=k.current)==null||C.focus())},[c,p]),D(()=>{if(!h.current)return;let C=!1,x=null,j=null,R=0;const E=[];return(async()=>{const{Terminal:S}=await $n(async()=>{const{Terminal:J}=await import("./xterm-DlVFs1Kw.js").then(z=>z.x);return{Terminal:J}},[]),{FitAddon:T}=await $n(async()=>{const{FitAddon:J}=await import("./addon-fit-BlxrFPDK.js").then(z=>z.a);return{FitAddon:J}},[]),{WebLinksAddon:$}=await $n(async()=>{const{WebLinksAddon:J}=await import("./addon-web-links-BWjmmSgS.js");return{WebLinksAddon:J}},[]);if(C)return;const N=new S({theme:Cn(u.current),fontSize:13,fontFamily:xa,convertEol:!p,disableStdin:!p,cursorBlink:p,scrollback:1e4});k.current=N;const W=J=>{var z;N.write(J),(z=y.current)==null||z.call(y,J)},O=new T;N.loadAddon(O),N.loadAddon(new $),N.open(h.current),setTimeout(()=>{O.fit(),p&&g.current&&N.focus()},50),t&&!p&&W(t);let F;if(e&&!p&&(F=new EventSource(e),F.addEventListener("output",J=>{const{chunk:z}=JSON.parse(J.data);W(z)}),F.addEventListener("done",J=>{const{exitCode:z}=JSON.parse(J.data);N.write(`\r
|
|
2
|
+
\x1B[${z===0?"32":"31"}m--- Exit code: ${z} ---\x1B[0m\r
|
|
3
|
+
`),F==null||F.close()})),r&&!C){const J=z=>{if(C)return;console.log("[ForgeTerminal] Connecting to:",z),x=new WebSocket(z);const G=[];x.onopen=()=>{var ie;console.log("[ForgeTerminal] WebSocket OPEN"),R=0,(ie=m.current)==null||ie.call(m,!0),O.fit();const{cols:V,rows:le}=N;x.send(JSON.stringify({type:"resize",cols:V,rows:le})),G.push(N.onData(de=>{(x==null?void 0:x.readyState)===WebSocket.OPEN&&x.send(JSON.stringify({type:"input",data:de}))})),G.push(N.onResize(({cols:de,rows:me})=>{(x==null?void 0:x.readyState)===WebSocket.OPEN&&x.send(JSON.stringify({type:"resize",cols:de,rows:me}))}))},x.onmessage=V=>{var le;try{const ie=JSON.parse(V.data);ie.type==="output"||ie.type==="scrollback"?W(ie.data):ie.type==="exit"?(N.write(`\r
|
|
4
|
+
\x1B[33m--- Session ended (code ${ie.code}) ---\x1B[0m\r
|
|
5
|
+
`),(le=v.current)==null||le.call(v,ie.code)):ie.type==="error"&&N.write(`\r
|
|
6
|
+
\x1B[31m--- Error: ${ie.message} ---\x1B[0m\r
|
|
7
|
+
`)}catch{}},x.onclose=V=>{var le,ie,de;if(console.log("[ForgeTerminal] WebSocket CLOSE:",V.code,V.reason),G.forEach(me=>me.dispose()),G.length=0,(le=m.current)==null||le.call(m,!1),!C)if(V.code===4404)N.write(`\r
|
|
8
|
+
\x1B[31m--- Click Restart to try again. ---\x1B[0m\r
|
|
9
|
+
`),(ie=b.current)==null||ie.call(b);else if(R<5){const me=Math.min(2e3*Math.pow(2,R),16e3);R++,N.write(`\r
|
|
10
|
+
\x1B[90m--- Reconnecting (attempt ${R}/5)... ---\x1B[0m\r
|
|
11
|
+
`),j=setTimeout(()=>J(z),me)}else N.write(`\r
|
|
12
|
+
\x1B[31m--- Connection lost. Click Restart to try again. ---\x1B[0m\r
|
|
13
|
+
`),(de=b.current)==null||de.call(b)},x.onerror=V=>{console.error("[ForgeTerminal] WebSocket error:",V)}};J(r)}const U=new ResizeObserver(()=>{C||O.fit()});U.observe(h.current),E.push({dispose:()=>{F==null||F.close(),U.disconnect(),j&&clearTimeout(j),x&&(C=!0,x.close()),N.dispose(),k.current=null}})})(),()=>{C=!0,E.forEach(S=>S.dispose())}},[e,t,r,p]);const f=p?{width:"100%",height:"100%"}:{width:"100%",height:`${o}px`};return n("div",{ref:h,class:"overflow-hidden",style:{...f,background:Cn(d).background}})},dt=X([]);function P(e,t="info"){const r=Math.random().toString(36).slice(2);dt.value=[...dt.value,{id:r,message:e,type:t}],setTimeout(()=>{dt.value=dt.value.filter(o=>o.id!==r)},4e3)}const ya={success:"var(--green)",error:"var(--red)",info:"var(--blue)"},ba=()=>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:dt.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:ya[e.type]}}),e.message]},e.id))}),Do=({label:e,color:t="var(--ink-2)",variant:r="tint",dot:o})=>{const i=r==="tint"?{background:`color-mix(in srgb, ${t} 18%, transparent)`,color:t}:{background:"var(--elev)",color:"var(--ink-2)",border:"1px solid var(--hair)"};return n("span",{class:"inline-flex items-center gap-1.5 whitespace-nowrap shrink-0",style:{...i,padding:"2px 8px",borderRadius:"99px",fontSize:"11px",fontWeight:600},children:[o&&n("span",{style:{width:"6px",height:"6px",borderRadius:"50%",background:t}}),e]})},Fo=({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"}})}),hr=({open:e,title:t,onClose:r,footer:o,width:i=540,children:a})=>(D(()=>{if(!e)return;const s=l=>{l.key==="Escape"&&r()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[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:s=>s.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(Fo,{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),he=({tabs:e,active:t,onChange:r,fill:o,size:i="md",label:a})=>{const s=i!=="md",l=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:s?"10px":"11px",background:"var(--elev)",border:"1px solid var(--hair)"},children:e.map(c=>{const d=t===c.id;return n("button",{type:"button",role:"tab","aria-selected":d,disabled:c.disabled,class:`flex items-center justify-center gap-1.5 whitespace-nowrap transition-all duration-200 ease-spring ${o?"flex-1":""} ${c.disabled?"cursor-not-allowed opacity-50":"cursor-pointer"}`,style:{padding:l?"4px 0":o?s?"5px 6px":"7px 8px":s?"5px 11px":"6px 12px",border:0,borderRadius:s?"7px":"8px",fontSize:l?"11.5px":s?"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(c.id),children:[c.label,c.count!==void 0&&n("span",{class:"mono",style:{fontSize:"11px",fontWeight:400,color:"var(--ink-3)"},children:c.count})]},c.id)})})},qe=({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(I,{label:o.label,variant:"primary",onClick:o.onClick})]}),Mo=({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)"}})}),ka={normal:"--blue",warning:"--orange",critical:"--red"},_a=({bar:e,size:t})=>{const r=`var(${ka[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})]})},Bo=({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(_a,{bar:r,size:t}),r.scope&&t==="md"&&n("span",{style:{paddingLeft:"39px",fontSize:"10.5px",color:"var(--ink-3)"},children:r.scope})]},o))}),Uo="forge-theme",wa=()=>{try{return localStorage.getItem(Uo)==="light"?"light":"dark"}catch{return"dark"}},zt=X(wa());document.documentElement.setAttribute("data-theme",zt.value);const Ho=e=>{zt.value=e,document.documentElement.setAttribute("data-theme",e);try{localStorage.setItem(Uo,e)}catch{}},Pe=X(!1),Mr=()=>Ho(zt.value==="dark"?"light":"dark"),Sa=({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${Pe.value?" open":""}`,onClick:()=>{Pe.value=!1}}),n("div",{class:"min-w-0 flex flex-col relative",style:{minHeight:"100vh"},children:t}),n(ba,{})]}),Br=[["--blue","--purple"],["--teal","--blue"],["--orange","--red"],["--green","--teal"]],Ko=e=>Br[e%Br.length],ae=(e,t=18)=>`color-mix(in srgb, var(${e}) ${t}%, transparent)`,Be={borderRadius:"16px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-m)"},Re={padding:"10px 14px",borderRadius:"12px",fontSize:"12.5px"},$a={personal:"--blue",project:"--green",client:"--green",team:"--purple"},Ge=e=>$a[e??""]??"--ink-2",Ca={decision:"--purple",context:"--teal",playbook:"--green",memory:"--orange",instinct:"--red",rule:"--blue",skill:"--ink-2"},Ur=e=>Ca[e]??"--ink-3",Fe=(e,t,r)=>({label:e,glyph:t,token:r,ink:`var(${r})`,fill:ae(r)}),Gn={task:Fe("Dev","D","--orange"),review:Fe("Review","R","--blue"),loop:Fe("Loop","L","--purple"),general:Fe("General","G","--green")},za={create:Fe("Create","C","--teal"),login:Fe("Login","A","--ink-2")},fr=e=>Gn[e]??za[e]??Gn.task,et=[{key:"dev",sessionType:"task"},{key:"review",sessionType:"review"},{key:"loop",sessionType:"loop"},{key:"general",sessionType:"general"}],vr=e=>{var t;return Gn[((t=et.find(r=>r.key===e))==null?void 0:t.sessionType)??"task"].label},Ta=e=>{var t;return((t=et.find(r=>r.key===e))==null?void 0:t.sessionType)??"task"},gr={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}},Ve=e=>!!(e&&(gr[e.state].attention||e.state==="exited"&&(e.exitCode??0)!==0)),on=e=>e.state==="exited"&&e.exitCode?`Exited with code ${e.exitCode}`:gr[e.state].label,qt=e=>e.state==="exited"&&e.exitCode?"--red":gr[e.state].token,q=e=>e.sessionDir?`${e.project}::${e.sessionDir}`:`${e.project}::${e.task??e.pr}`,pe=e=>e.project==="__general"?"":e.project,fn=e=>e.sessionDir??(e.type==="review"?`review-pr-${e.pr}`:e.type==="loop"?`loop-${e.task}`:`task-${e.task}`),fe=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} · ${ve(e.harness).label}`:e.task??"unknown",Ra={linear:"Linear",notion:"Notion"},xr=e=>{var r;const t=e.source?Ra[e.source]:void 0;return t&&((r=e.source_url)!=null&&r.startsWith("https://"))?{label:t,url:e.source_url}:null},vn=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`},It=(e,t)=>({label:e,color:`var(--forge-harness-${t})`,bg:ae(`--forge-harness-${t}`)}),Pa={claude:It("Claude Code","claude"),codex:It("Codex","codex"),pi:It("Pi","pi"),opencode:It("OpenCode","opencode")},ve=e=>Pa[e??"claude"]??{label:e??"claude",color:"var(--ink-3)",bg:"var(--elev)"},qo=e=>{const t=ve(e.harness).label;return e.provider&&e.provider!=="native"?`${t} · ${e.model||e.provider}`:t},ja=[{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"}],Go=(e,t,r,o)=>{var i,a;return(e?(i=r[e])==null?void 0:i.harness:void 0)??((a=o.accounts.find(s=>s.name===t))==null?void 0:a.default_harness)??"claude"},Ae=(e,t,r)=>{var o;return(o=e.accounts.find(i=>i.name===t))==null?void 0:o.harnesses.find(i=>i.harness===r)},Aa=/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/,Ea=new Intl.DateTimeFormat(void 0,{weekday:"short",hour:"2-digit",minute:"2-digit"}),Vo=(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 ${Ea.format(Math.round(r/6e4)*6e4)}`;const a=o%60;return`resets in ${i} h${a?` ${a} m`:""}`},Jo=e=>e.map(t=>({label:t.label,percent:t.percent,severity:t.severity,scope:t.scope,reset:Vo(t.resetsAt)})),Yo=X(null);async function La(){const e=await fetch("/api/health");Yo.value=(await e.json()).version??null}const ht=X(null);async function Qo(){const e=await fetch("/api/skills");if(!e.ok)throw new Error("fetch failed");ht.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"}})},zn=5,Zo="forge-sidebar-collapsed",Na=()=>{try{const e=localStorage.getItem(Zo);return e?JSON.parse(e):[]}catch{return[]}},Ia=(e,t)=>Number(t.live)-Number(e.live)||t.count-e.count||e.name.localeCompare(t.name),Oa=({projects:e,accounts:t,selected:r,onSelect:o,onAdd:i})=>{const[a,s]=w(""),[l,c]=w(Na),[d,h]=w([]),p=a.trim().toLowerCase(),v=Z(()=>{const m=[...t,...e.map(y=>y.account).filter(y=>!t.includes(y))];return Array.from(new Set(m)).map((y,u)=>({account:y,index:u,items:e.filter(g=>g.account===y&&(!p||g.name.toLowerCase().includes(p))).sort(Ia),active:e.filter(g=>g.account===y).reduce((g,k)=>g+k.count,0)})).filter(y=>y.items.length>0)},[e,t,p]),b=m=>{const y=l.includes(m)?l.filter(u=>u!==m):[...l,m];c(y);try{localStorage.setItem(Zo,JSON.stringify(y))}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:m=>s(m.target.value),onKeyDown:m=>{m.key==="Escape"&&s("")}})]}),n("div",{class:"flex flex-col overflow-y-auto min-h-0",style:{gap:"8px",overscrollBehavior:"contain"},children:[v.length===0&&n("p",{style:{padding:"4px 9px",fontSize:"12px",color:"var(--ink-3)"},children:["No project matches “",a.trim(),"”."]}),v.map(m=>{const y=p!==""||!l.includes(m.account),u=p!==""||d.includes(m.account)||m.items.some((x,j)=>j>=zn&&x.name===r),g=u?m.items:m.items.slice(0,zn),[k,f]=Ko(m.index),C=m.items.some(x=>x.live);return n("div",{class:"flex flex-col shrink-0",style:{gap:"1px"},children:[n("button",{type:"button","aria-expanded":y,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:()=>b(m.account),children:[n("span",{class:"i-lucide-chevron-right shrink-0",style:{width:"11px",height:"11px",color:"var(--ink-3)",transform:y?"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(${k}), var(${f}))`,color:"#fff",fontSize:"9px",fontWeight:700},children:m.account.charAt(0).toUpperCase()}),n("span",{class:"flex-1 truncate",style:{fontSize:"12px",fontWeight:600},children:m.account}),C&&n($e,{size:5,live:!0,glow:!1}),n("span",{class:"mono",style:{fontSize:"10.5px",color:"var(--ink-3)"},title:`${m.items.length} projects · ${m.active} active tasks`,children:m.items.length})]}),y&&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:[g.map(x=>{const j=r===x.name;return n("button",{type:"button","aria-pressed":j,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 ${j?"var(--hair)":"transparent"}`,background:j?"var(--card)":"transparent",boxShadow:j?"var(--shadow-s)":"none"},onClick:()=>o(x.name),children:[n($e,{size:6,live:x.live}),n("span",{class:"flex-1 truncate",style:{fontWeight:j?600:450,opacity:x.count>0||x.live||j?1:.62},children:x.name}),x.count>0&&n("span",{class:"mono",style:{fontSize:"11px",color:"var(--ink-3)"},children:x.count})]},x.name)}),m.items.length>zn&&p===""&&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(u?d.filter(x=>x!==m.account):[...d,m.account]),children:u?"Show less":`Show all ${m.items.length}`})]})]},m.account)})]})]})},Xo={context:null,tokens:null,cost:null},Wa=250,an=new Map,Da=/\x1b\[[0-9;?]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\x1b[@-_]/g,nt=(e,t)=>{let r=null;for(const o of e.matchAll(t))r=o;return r},Tn=e=>{const t=parseFloat(e),r=e.slice(-1).toLowerCase();return r==="k"?t*1e3:r==="m"?t*1e6:t};function Fa(e){const t={},r=nt(e,/(?:ctx|context)[:\s]*(\d{1,3}(?:\.\d+)?)\s*%/gi)??nt(e,/[▓█▒░]+\s*(\d{1,3}(?:\.\d+)?)\s*%/g);r&&(t.context=Math.min(100,parseFloat(r[1])));const o=nt(e,/(\d+(?:\.\d+)?[kKmM]?)\s*↑\s*(\d+(?:\.\d+)?[kKmM]?)\s*↓/g),i=nt(e,/\((\d+(?:\.\d+)?[kKmM])\s*\/\s*\d+(?:\.\d+)?[kKmM]\)/g);o?t.tokens=Tn(o[1])+Tn(o[2]):i&&(t.tokens=Tn(i[1]));const a=nt(e,/\$(\d+\.\d{2})\b/g);return a&&(t.cost=parseFloat(a[1])),t}const ei=e=>{let t=an.get(e);return t||(t={tail:"",timer:null,metrics:X(Xo)},an.set(e,t)),t},ti=e=>ei(e).metrics,Ma=e=>{e.timer=null;const t=e.metrics.value,r={...t,...Fa(e.tail)};(r.context!==t.context||r.tokens!==t.tokens||r.cost!==t.cost)&&(e.metrics.value=r)};function Ba(e,t){const r=ei(e);r.tail=(r.tail+t.slice(-4e3*2).replace(Da,"")).slice(-4e3),r.timer||(r.timer=setTimeout(()=>Ma(r),Wa))}function Ua(e){const t=an.get(e);t&&(t.timer&&clearTimeout(t.timer),t.metrics.value=Xo,an.delete(e))}const ni=e=>e>=1e6?`${(e/1e6).toFixed(e>=1e7?0:1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:String(e),ri=e=>`$${e.toFixed(2)}`,_t=X(null),Ha=6e4;let rt=null,ot=null,Rn=0;function Hr(e=!1){return rt||(rt=fetch(`/api/cw/usage${e?"?fresh=1":""}`).then(t=>t.json()).catch(()=>({available:!1,reason:"Could not reach the Forge server"})).then(t=>(_t.value=t,rt=null,t)),rt)}function oi(){return Rn+=1,Hr(),ot||(ot=setInterval(()=>{document.visibilityState==="visible"&&Hr()},Ha)),()=>{Rn-=1,Rn===0&&ot&&(clearInterval(ot),ot=null)}}const Ka=(e,t)=>{var r;return((r=_t.value)!=null&&r.available?_t.value.usage.find(o=>o.account===e&&o.harness===t):null)??null},Ee=X({}),Kr=X(null),ii=2e3,qa=15e3;let it=null,ai=0,Pn=!1;const Gt=new Set,Ga=(e,t)=>!!e&&Ve(t)&&(e.state!==t.state||e.since!==t.since);async function li(){if(!Pn){Pn=!0,ai=Date.now();try{const e=await fetch("/api/cw/session-states");if(!e.ok)return;const{states:t}=await e.json(),r=Ee.value;Ee.value=t;for(const[o,i]of Object.entries(t))if(Ga(r[o],i))for(const a of Gt)a(o,i)}catch{}finally{Pn=!1}}}const Va=()=>{const e=document.visibilityState==="visible"?ii:qa;Date.now()-ai>=e-100&&li()};function Ja(e){return Gt.add(e),it||(li(),it=setInterval(Va,ii)),()=>{Gt.delete(e),Gt.size===0&&it&&(clearInterval(it),it=null)}}const si="forge.notify-sessions",gn=typeof window<"u"&&"Notification"in window,Ya=()=>{try{return gn&&Notification.permission==="granted"&&localStorage.getItem(si)==="1"}catch{return!1}},mr=X(Ya());async function Qa(e){if(e&&(!gn||(Notification.permission==="default"?await Notification.requestPermission():Notification.permission)!=="granted"))return!1;mr.value=e;try{localStorage.setItem(si,e?"1":"0")}catch{}return!0}function Za(e,t,r,o){if(!mr.value||!gn||Notification.permission!=="granted")return;const i=new Notification(e,{body:t,tag:r});i.onclick=()=>{window.focus(),o(),i.close()}}const ci=[{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"},{view:"qa",label:"QA",glyph:"Q",token:"--teal"},{view:"memory",label:"Memory",glyph:"M",token:"--red"}],Xa="flex items-center w-full text-left cursor-pointer transition-all duration-180 ease-spring hover:bg-elev",el=e=>({borderRadius:"9px",border:`1px solid ${e?"var(--hair)":"transparent"}`,background:e?"var(--card)":"transparent",boxShadow:e?"var(--shadow-s)":"none",color:"var(--ink)"}),di="flex flex-col text-left cursor-pointer transition-all duration-180 ease-spring hover:-translate-y-px hover:shadow-m",Vn={gap:"6px",padding:"9px 10px",borderRadius:"12px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",color:"var(--ink)"},Jn={fontSize:"10.5px",color:"var(--ink-3)"},qr=({children:e})=>n("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--ink-3)",letterSpacing:".02em"},children:e}),tl=({id:e,session:t,index:r,onOpen:o})=>{const i=ti(e).value,a=Ee.value[e],s=Ve(a),l=t.type==="loop",c=(i==null?void 0:i.context)??null,[d,h]=r%2===0?["var(--blue)","var(--purple)"]:["var(--purple)","var(--blue)"],p=s?on(a):l?t.loop_interval?`every ${t.loop_interval}`:"self-paced":i&&(i.tokens!==null||i.cost!==null)?[i.tokens!==null?`${ni(i.tokens)} tokens`:null,i.cost!==null?ri(i.cost):null].filter(Boolean).join(" · "):pe(t)||t.account;return n("button",{type:"button",class:di,style:s?{...Vn,borderColor:`var(${qt(a)})`}:Vn,onClick:o,title:a?on(a):void 0,children:[n("span",{class:"flex items-center w-full",style:{gap:"6px"},children:[n($e,{size:6,color:a?`var(${qt(a)})`:d,live:!a||a.state==="working"||s}),n("span",{class:"truncate",style:{fontSize:"12.5px",fontWeight:600},children:fe(t)}),n("span",{class:"flex-1"}),n("span",{class:"mono",style:{fontSize:"11px",color:"var(--ink-2)"},children:c!==null?`${Math.round(c)}%`:"—"})]}),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:`${c??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:s?{...Jn,color:`var(${qt(a)})`,fontWeight:600}:Jn,children:p})]})},nl=()=>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(Mo,{checked:mr.value,label:"Notify when a session needs me",onChange:e=>{Qa(e).then(t=>{t||P("The browser blocked notifications for Forge","error")})}})]}),rl=({account:e,harness:t,windows:r,stale:o,onOpen:i})=>{const a=r.reduce((l,c)=>c.percent>l.percent?c:l),s=ve(t).label;return n("button",{type:"button",class:di,style:Vn,onClick:i,title:`Usage limits for ${e} on ${s}`,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:s})]}),n(Bo,{bars:Jo(r),size:"sm"}),n("span",{class:"mono truncate w-full",style:Jn,children:o?"last known values":Vo(a.resetsAt)})]})},ol=({view:e,counts:t,projects:r,accounts:o,selectedProject:i,live:a,onNavigate:s,onSelectProject:l,onAddProject:c,onOpenLive:d,onSearch:h})=>{var y;const p=Yo.value,v=ci.map(u=>{var g;return{...u,count:u.view==="skills"?((g=ht.value)==null?void 0:g.length)??null:t[u.view]??null}});D(()=>oi(),[]),D(()=>{La().catch(()=>{})},[]);const b=[...a].sort((u,g)=>Number(Ve(Ee.value[g.key]))-Number(Ve(Ee.value[u.key]))),m=(y=_t.value)!=null&&y.available?_t.value.usage.filter(u=>u.state==="ok"&&u.windows.some(g=>!g.scope)):[];return n("aside",{class:`forge-sidebar flex flex-col${Pe.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:()=>s("list"),onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&s("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"}),p&&n("span",{class:"mono sb-label",style:{fontSize:"10px",color:"var(--ink-3)"},title:"Forge version",children:p})]}),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:v.map(u=>{const g=e===u.view;return n("button",{type:"button","aria-current":g?"page":void 0,title:u.label,class:Xa,style:{...el(g),gap:"9px",height:"32px",padding:"0 9px",fontSize:"13.5px",fontWeight:g?600:450},onClick:()=>s(u.view),children:[n("span",{class:"grid place-items-center shrink-0",style:{width:"18px",height:"18px",borderRadius:"5px",fontSize:"10px",fontWeight:600,background:g?ae(u.token):"var(--elev)",color:g?`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(Oa,{projects:r,accounts:o,selected:i,onSelect:l,onAdd:c}),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(qr,{children:"Live now"})}),b.map((u,g)=>n(tl,{id:u.key,session:u.session,index:g,onOpen:()=>d(u.session)},u.key))]}),m.length>0&&n("div",{class:"flex flex-col sb-section",style:{gap:"8px"},children:[n("span",{style:{padding:"0 9px"},children:n(qr,{children:"Limits"})}),m.map(u=>n(rl,{account:u.account,harness:u.harness,windows:u.windows.filter(g=>!g.scope),stale:u.stale,onOpen:()=>s("accounts")},`${u.account}/${u.harness}`))]}),gn&&n("div",{class:"sb-section",children:n(nl,{})}),n("div",{class:"sb-section",children:n(he,{fill:!0,size:"xs",label:"Appearance",tabs:[{id:"light",label:"Light"},{id:"dark",label:"Dark"}],active:zt.value,onChange:u=>Ho(u==="light"?"light":"dark")})})]})]})};function xn(){const e=ee(null);return D(()=>{var t;(t=e.current)==null||t.focus()},[]),e}const Gr=(e,t,r)=>{const o=fr(e.type);return{id:q(e),label:pe(e)?`${fe(e)} · ${pe(e)}`:fe(e),hint:t,glyph:o.glyph,token:o.token,run:()=>r(e)}},il=({openTabs:e,sessions:t,projects:r,commands:o,onOpenSession:i,onSelectProject:a,onClose:s})=>{const[l,c]=w(""),[d,h]=w(0),p=ee(null),v=xn(),b=Z(()=>{const f=l.trim().toLowerCase(),C=L=>!f||L.label.toLowerCase().includes(f),x=new Set(e.map(q)),j=e.map((L,S)=>Gr(L,S<5?`⌘${S+1}`:"open",i)),R=t.filter(L=>L.status==="active"&&!x.has(q(L))).map(L=>Gr(L,"resume",i)),E=f?r.map(L=>({id:`project:${L}`,label:L,hint:"project",glyph:"P",token:"--green",run:()=>a(L)})):[];return[{name:"Live now",items:j.filter(C)},{name:"Tasks",items:R.filter(C).slice(0,f?12:6)},{name:"Projects",items:E.filter(C).slice(0,6)},{name:"Commands",items:o.filter(C)}].filter(L=>L.items.length>0)},[l,e,t,r,o,i,a]),m=b.flatMap(f=>f.items),y=Math.min(d,m.length-1);D(()=>{var f,C;(C=(f=p.current)==null?void 0:f.querySelector('[data-active="true"]'))==null||C.scrollIntoView({block:"nearest"})},[y]);const u=f=>{f&&(s(),f.run())},g=ee({flat:m,current:y,activate:u});g.current={flat:m,current:y,activate:u},D(()=>{const f=C=>{const{flat:x,current:j,activate:R}=g.current,E=x.length;C.key==="ArrowDown"?(C.preventDefault(),h(L=>E?(Math.min(L,E-1)+1)%E:0)):C.key==="ArrowUp"?(C.preventDefault(),h(L=>E?(Math.min(L,E-1)-1+E)%E:0)):C.key==="Enter"?(C.preventDefault(),R(x[j])):C.key==="Escape"&&(C.preventDefault(),s())};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[s]);let k=-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:s,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:f=>f.stopPropagation(),children:[n("input",{ref:v,role:"combobox","aria-expanded":"true","aria-controls":"palette-list","aria-activedescendant":m[y]?`palette-${m[y].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:l,onInput:f=>{c(f.target.value),h(0)}}),n("div",{id:"palette-list",role:"listbox",ref:p,class:"overflow-auto",style:{padding:"6px"},children:[m.length===0&&n("p",{style:{padding:"14px 10px",fontSize:"13px",color:"var(--ink-2)"},children:["Nothing matches “",l,"”."]}),b.map(f=>n("div",{role:"group","aria-label":f.name,children:[n("div",{style:{padding:"7px 10px 3px",fontSize:"11px",fontWeight:600,color:"var(--ink-3)"},children:f.name}),f.items.map(C=>{k+=1;const x=k,j=x===y;return n("button",{id:`palette-${C.id}`,type:"button",role:"option","aria-selected":j,"data-active":j,tabIndex:-1,class:"flex items-center w-full text-left cursor-pointer",style:{gap:"10px",padding:"8px 10px",borderRadius:"10px",border:0,background:j?"var(--elev)":"transparent",color:"var(--ink)",fontSize:"13px",transition:"background .14s"},onMouseMove:()=>{j||h(x)},onClick:()=>u(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?ae(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)})]},f.name))]}),n("div",{class:"flex shrink-0",style:{gap:"14px",padding:"8px 14px",borderTop:"1px solid var(--hair)"},children:["↑↓ move","↵ open","esc close"].map(f=>n("span",{class:"mono",style:{fontSize:"10.5px",color:"var(--ink-3)"},children:f},f))})]})})},mn=X(null),al=3e3;let at=null;function ye(e=!1){return at||(at=fetch(`/api/cw/harnesses${e?"?fresh=1":""}`).then(t=>t.json()).catch(()=>({available:!1,reason:"Could not reach the Forge server"})).then(t=>(mn.value=t,at=null,t)),at)}const wt=new Set;let ft=null;const pi=()=>{wt.size===0&&ft&&(clearInterval(ft),ft=null)},ll=async()=>{const e=await ye(!0),t=Date.now();for(const r of wt){const o=e.available&&r.check(e.doctor);(o||t>r.deadline)&&(wt.delete(r),r.onDone(o))}pi()};function sl(e,{timeoutMs:t=6e5,onDone:r=()=>{}}={}){const o={check:e,deadline:Date.now()+t,onDone:r};return wt.add(o),ft||(ft=setInterval(ll,al)),()=>{wt.delete(o),pi()}}const Ue=(e,t,r)=>{var o;return!!(e!=null&&e.available&&((o=e.capabilities[t])!=null&&o.includes(r)))},ui=e=>/linear\.app/.test(e)?"linear":/notion\.(so|site)/.test(e)?"notion":null,hi=(e,t,r)=>{const o=ui(r);return!!(e!=null&&e.available&&o&&!Ue(e,t,"mcp")&&!e.contextTokens[o])},Yn=X(null);let jn=null;function fi(){return jn||(jn=fetch("/api/cw/editors").then(e=>e.json()).then(e=>{Yn.value=e}).catch(()=>{Yn.value={enabled:!1,editors:[]}})),jn}async function cl(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:fn(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 St=e=>e.unpushed??e.commits??0,vi={OPEN:"open",MERGED:"merged",CLOSED:"closed"},dl={passing:"✓",failing:"✗",pending:"…",none:""};function pl(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=St(e);if(r>0&&t.push(`${r} unpushed`),e.pr.status==="found"){const o=e.pr.state==="OPEN"&&e.pr.isDraft?"draft":vi[e.pr.state];t.push(`PR #${e.pr.number} ${o}`),e.pr.checks!=="none"&&t.push(`checks ${dl[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 ul={passing:"checks pass",failing:"checks failing",pending:"checks running",none:""},Vr=(e,t)=>`${e} ${t}${e===1?"":"s"}`;function hl(e){if(e.workspace==="missing")return"not created yet";if(e.pr.status==="found"){const o=e.pr.state==="OPEN"&&e.pr.isDraft?"draft":vi[e.pr.state];return[`PR #${e.pr.number} ${o}`,ul[e.pr.checks]].filter(Boolean).join(" · ")}const t=[];e.diff&&e.diff.files>0&&t.push(Vr(e.diff.files,"file")),e.commits&&t.push(Vr(e.commits,"commit"));const r=St(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 Me(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 vt=e=>e instanceof Error?e.message:String(e);function yr(e,t){navigator.clipboard.writeText(e).then(()=>P(`${t} copied`,"info"),()=>P(`Could not copy the ${t.toLowerCase()}`,"error"))}const fl=({session:e,muted:t})=>{const r=ve(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}}),qo(e)]})};function vl(e,t){for(var r in t)e[r]=t[r];return e}function Jr(e,t){for(var r in e)if(r!=="__source"&&!(r in t))return!0;for(var o in t)if(o!=="__source"&&e[o]!==t[o])return!0;return!1}function Yr(e,t){this.props=e,this.context=t}(Yr.prototype=new be).isPureReactComponent=!0,Yr.prototype.shouldComponentUpdate=function(e,t){return Jr(this.props,e)||Jr(this.state,t)};var Qr=B.__b;B.__b=function(e){e.type&&e.type.__f&&e.ref&&(e.props.ref=e.ref,e.ref=null),Qr&&Qr(e)};var gl=B.__e;B.__e=function(e,t,r,o){if(e.then){for(var i,a=t;a=a.__;)if((i=a.__c)&&i.__c)return t.__e==null&&(t.__e=r.__e,t.__k=r.__k),i.__c(e,t)}gl(e,t,r,o)};var Zr=B.unmount;function gi(e,t,r){return e&&(e.__c&&e.__c.__H&&(e.__c.__H.__.forEach(function(o){typeof o.__c=="function"&&o.__c()}),e.__c.__H=null),(e=vl({},e)).__c!=null&&(e.__c.__P===r&&(e.__c.__P=t),e.__c.__e=!0,e.__c=null),e.__k=e.__k&&e.__k.map(function(o){return gi(o,t,r)})),e}function xi(e,t,r){return e&&r&&(e.__v=null,e.__k=e.__k&&e.__k.map(function(o){return xi(o,t,r)}),e.__c&&e.__c.__P===t&&(e.__e&&r.appendChild(e.__e),e.__c.__e=!0,e.__c.__P=r)),e}function An(){this.__u=0,this.o=null,this.__b=null}function mi(e){var t=e.__&&e.__.__c;return t&&t.__a&&t.__a(e)}function Ot(){this.i=null,this.l=null}B.unmount=function(e){var t=e.__c;t&&(t.__z=!0),t&&t.__R&&t.__R(),t&&32&e.__u&&(e.type=null),Zr&&Zr(e)},(An.prototype=new be).__c=function(e,t){var r=t.__c,o=this;o.o==null&&(o.o=[]),o.o.push(r);var i=mi(o.__v),a=!1,s=function(){a||o.__z||(a=!0,r.__R=null,i?i(c):c())};r.__R=s;var l=r.__P;r.__P=null;var c=function(){if(!--o.__u){if(o.state.__a){var d=o.state.__a;o.__v.__k[0]=xi(d,d.__c.__P,d.__c.__O)}var h;for(o.setState({__a:o.__b=null});h=o.o.pop();)h.__P=l,h.forceUpdate()}};o.__u++||32&t.__u||o.setState({__a:o.__b=o.__v.__k[0]}),e.then(s,s)},An.prototype.componentWillUnmount=function(){this.o=[]},An.prototype.render=function(e,t){if(this.__b){if(this.__v.__k){var r=document.createElement("div"),o=this.__v.__k[0].__c;this.__v.__k[0]=gi(this.__b,r,o.__O=o.__P)}this.__b=null}var i=t.__a&&yt(K,null,e.fallback);return i&&(i.__u&=-33),[yt(K,null,t.__a?null:e.children),i]};var Xr=function(e,t,r){if(++r[1]===r[0]&&e.l.delete(t),e.props.revealOrder&&(e.props.revealOrder[0]!=="t"||!e.l.size))for(r=e.i;r;){for(;r.length>3;)r.pop()();if(r[1]<r[0])break;e.i=r=r[2]}};function xl(e){return this.getChildContext=function(){return e.context},e.children}function ml(e){var t=this,r=e.h;if(t.componentWillUnmount=function(){Hn(null,t.v),t.v=null,t.h=null},t.h&&t.h!==r&&t.componentWillUnmount(),!t.v){for(var o=t.__v;o!==null&&!o.__m&&o.__!==null;)o=o.__;t.h=r,t.v={nodeType:1,parentNode:r,childNodes:[],__k:{__m:o.__m},contains:function(){return!0},namespaceURI:r.namespaceURI,insertBefore:function(i,a){this.childNodes.push(i),t.h.insertBefore(i,a)},removeChild:function(i){this.childNodes.splice(this.childNodes.indexOf(i)>>>1,1),t.h.removeChild(i)}}}Hn(yt(xl,{context:t.context},e.__v),t.v)}function yl(e,t){var r=yt(ml,{__v:e,h:t});return r.containerInfo=t,r}(Ot.prototype=new be).__a=function(e){var t=this,r=mi(t.__v),o=t.l.get(e);return o[0]++,function(i){var a=function(){t.props.revealOrder?(o.push(i),Xr(t,e,o)):i()};r?r(a):a()}},Ot.prototype.render=function(e){this.i=null,this.l=new Map;var t=Xt(e.children);e.revealOrder&&e.revealOrder[0]==="b"&&t.reverse();for(var r=t.length;r--;)this.l.set(t[r],this.i=[1,0,this.i]);return e.children},Ot.prototype.componentDidUpdate=Ot.prototype.componentDidMount=function(){var e=this;this.l.forEach(function(t,r){Xr(e,r,t)})};var bl=typeof Symbol<"u"&&Symbol.for&&Symbol.for("react.element")||60103,kl=/^(?:accent|alignment|arabic|baseline|cap|clip(?!PathU)|color|dominant|fill|flood|font|glyph(?!R)|horiz|image(!S)|letter|lighting|marker(?!H|W|U)|overline|paint|pointer|shape|stop|strikethrough|stroke|text(?!L)|transform|underline|unicode|units|v|vector|vert|word|writing|x(?!C))[A-Z]/,_l=/^on(Ani|Tra|Tou|BeforeInp|Compo)/,wl=/[A-Z0-9]/g,Sl=typeof document<"u",$l=function(e){return(typeof Symbol<"u"&&typeof Symbol()=="symbol"?/fil|che|rad/:/fil|che|ra/).test(e)};be.prototype.isReactComponent=!0,["componentWillMount","componentWillReceiveProps","componentWillUpdate"].forEach(function(e){Object.defineProperty(be.prototype,e,{configurable:!0,get:function(){return this["UNSAFE_"+e]},set:function(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,value:t})}})});var eo=B.event;B.event=function(e){return eo&&(e=eo(e)),e.persist=function(){},e.isPropagationStopped=function(){return this.cancelBubble},e.isDefaultPrevented=function(){return this.defaultPrevented},e.nativeEvent=e};var Cl={configurable:!0,get:function(){return this.class}},to=B.vnode;B.vnode=function(e){typeof e.type=="string"&&(function(t){var r=t.props,o=t.type,i={},a=o.indexOf("-")==-1;for(var s in r){var l=r[s];if(!(s==="value"&&"defaultValue"in r&&l==null||Sl&&s==="children"&&o==="noscript"||s==="class"||s==="className")){var c=s.toLowerCase();s==="defaultValue"&&"value"in r&&r.value==null?s="value":s==="download"&&l===!0?l="":c==="translate"&&l==="no"?l=!1:c[0]==="o"&&c[1]==="n"?c==="ondoubleclick"?s="ondblclick":c!=="onchange"||o!=="input"&&o!=="textarea"||$l(r.type)?c==="onfocus"?s="onfocusin":c==="onblur"?s="onfocusout":_l.test(s)&&(s=c):c=s="oninput":a&&kl.test(s)?s=s.replace(wl,"-$&").toLowerCase():l===null&&(l=void 0),c==="oninput"&&i[s=c]&&(s="oninputCapture"),i[s]=l}}o=="select"&&(i.multiple&&Array.isArray(i.value)&&(i.value=Xt(r.children).forEach(function(d){d.props.selected=i.value.indexOf(d.props.value)!=-1})),i.defaultValue!=null&&(i.value=Xt(r.children).forEach(function(d){d.props.selected=i.multiple?i.defaultValue.indexOf(d.props.value)!=-1:i.defaultValue==d.props.value}))),r.class&&!r.className?(i.class=r.class,Object.defineProperty(i,"className",Cl)):r.className&&(i.class=i.className=r.className),t.props=i})(e),e.$$typeof=bl,to&&to(e)};var no=B.__r;B.__r=function(e){no&&no(e),e.__c};var ro=B.diffed;B.diffed=function(e){ro&&ro(e);var t=e.props,r=e.__e;r!=null&&e.type==="textarea"&&"value"in t&&t.value!==r.value&&(r.value=t.value==null?"":t.value)};const Te=X(null),zl=6e4;let lt=null,st=null,En=0;function gt(e=!1){return lt&&!e||(lt=fetch(`/api/kioku/status${e?"?fresh=1":""}`).then(t=>t.json()).then(t=>{JSON.stringify(t)!==JSON.stringify(Te.value)&&(Te.value=t)}).catch(()=>{Te.value??(Te.value={installed:!1,version:null,brains:[],projects:{},activity:[],viewer:null})}).finally(()=>{lt=null})),lt}function yi(){return En+=1,Te.value||gt(),st||(st=setInterval(()=>{document.visibilityState==="visible"&>()},zl)),()=>{En-=1,En===0&&st&&(clearInterval(st),st=null)}}const Le=e=>e.name??e.key,ln=e=>e.reduce((t,r)=>t+r.pages,0);function bi(e){const t=Te.value;return t!=null&&t.installed?(t.projects[e]??[]).flatMap(r=>t.brains.find(o=>Le(o)===r.name)??[]):[]}function ki(e){return D(()=>yi(),[]),bi(e)}const Tl=({project:e})=>{const[t,r]=w(null),o=ki(e);return o.length===0?null:n("span",{class:"inline-flex items-center shrink-0 whitespace-nowrap",style:{gap:"6px",padding:"3px 9px",borderRadius:"99px",background:"var(--elev)",border:"1px solid var(--hair)",color:"var(--ink-2)",fontSize:"11.5px",fontWeight:600},"aria-label":`Memory: ${o.map(Le).join(", ")}`,onMouseEnter:i=>r(i.currentTarget.getBoundingClientRect()),onMouseLeave:()=>r(null),children:[n("span",{class:"inline-flex",children:o.map((i,a)=>n("span",{style:{width:"9px",height:"9px",borderRadius:"50%",background:`var(${Ge(i.tier)})`,border:"2px solid var(--card)",marginLeft:a===0?0:"-4px"}},i.key))}),n("span",{class:"mono",children:ln(o)}),t&&yl(n("span",{class:"flex flex-col",style:{position:"fixed",top:`${t.bottom+8}px`,right:`${window.innerWidth-t.right}px`,zIndex:50,width:"240px",gap:"6px",padding:"10px 12px",borderRadius:"12px",background:"var(--card-2)",border:"1px solid var(--hair-2)",boxShadow:"var(--shadow-l)",animation:"riseIn .2s var(--ease) both"},children:[n("span",{style:{fontSize:"10.5px",fontWeight:600,letterSpacing:".03em",color:"var(--ink-3)"},children:"THIS SESSION REMEMBERS"}),o.map(i=>n("span",{class:"flex items-center",style:{gap:"7px",fontSize:"12px",color:"var(--ink)",fontWeight:500},children:[n($e,{color:`var(${Ge(i.tier)})`}),Le(i),n("span",{style:{color:"var(--ink-3)",fontWeight:400},children:i.tier}),n("span",{class:"flex-1"}),n("span",{class:"mono",style:{color:"var(--ink-2)"},children:i.pages})]},i.key))]}),document.body)]})},Qn=X({}),_i=X(0),Rl=6e4,Wt=new Map,wi=e=>`${e.project}::${fn(e)}`;function Zn(e,t=!1){const r=wi(e),o=Wt.get(r);if(o&&!t)return o;const i=`/api/cw/review-state/${encodeURIComponent(e.project)}/${encodeURIComponent(fn(e))}${t?"?fresh=1":""}`,a=fetch(i).then(async s=>s.ok?{state:await s.json(),error:null}:{state:null,error:`Forge could not read this task (HTTP ${s.status})`}).catch(()=>({state:null,error:"Could not reach the Forge server"})).then(s=>(Qn.value={...Qn.value,[r]:s},Wt.get(r)===a&&Wt.delete(r),s));return Wt.set(r,a),a}function Pl(){_i.value++}function Si(e,{poll:t=!1}={}){const r=wi(e),o=_i.value;return D(()=>{if(Zn(e),!t)return;const i=setInterval(()=>{Zn(e,!0)},Rl);return()=>clearInterval(i)},[r,t,o]),Qn.value[r]??null}const Xn=({type:e,size:t=28,radius:r=9,font:o=11})=>{const i=fr(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})},jl=()=>n("span",{class:"inline-flex items-center shrink-0",style:{gap:"5px",padding:"1px 8px",borderRadius:"99px",background:ae("--green"),color:"var(--green)",fontSize:"11px",fontWeight:600},children:[n($e,{size:5,color:"var(--green)",live:!0,glow:!1}),"live"]}),$i=({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})},Ci=({session:e})=>{const t=xr(e);return t&&n($i,{label:t.label,href:t.url})},Al=({session:e})=>xr(e)?n(Ci,{session:e}):e.source?n("span",{class:"task-chip contents",children:n($i,{label:e.source,href:e.source_url})}):null,zi=e=>e.type==="review"?`review/pr-${e.pr}`:e.type==="loop"?`loop/${e.task??"loop"}`:e.type==="task"?`task/${e.task}`:null,El=({session:e,project:t})=>{var a;const r=Si(e),o=((a=r==null?void 0:r.state)==null?void 0:a.branch)??zi(e),i=r?r.error!==null?"changes unknown":hl(r.state):"checking…";return n(Ti,{branch:o,status:i,project:t})},Ti=({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(),yr(e,"Branch")},onKeyDown:o=>o.stopPropagation(),children:e}),n("span",{class:"whitespace-nowrap truncate",style:{fontSize:"12px",color:"var(--ink-2)"},children:t})]}),Ll=e=>e.type==="loop"?e.loop_interval?`every ${e.loop_interval}`:"self-paced":`${e.opens} session${e.opens===1?"":"s"}`,Ri=({session:e,isOpenInTab:t,onSelect:r,onMarkDone:o,showProject:i})=>{const a=i?pe(e)||"no project":void 0,[s,l]=w(!1),c=e.type==="task"||e.type==="review",d=async()=>{if(!(!o||s)){l(!0);try{await o()}finally{l(!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"} ${fe(e)}`,onKeyDown:h=>{h.target===h.currentTarget&&(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),r())},children:[n(Xn,{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:fe(e)}),t&&e.status==="active"&&n(jl,{}),n(Al,{session:e})]}),c?n(El,{session:e,project:a}):n(Ti,{branch:zi(e),status:Ll(e),project:a})]}),n(Tl,{project:pe(e)}),n(fl,{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:vn(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 ${s?"":"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:s,title:s?"Closing…":"Mark done","aria-label":"Mark done",children:n("span",{class:s?"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"})]})},Nl=({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:[fe(e)," ",n("span",{class:"mono",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:pe(e)})]}),n(Ci,{session:e}),n("span",{class:"mono shrink-0",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:vn(e.closed??e.last_opened)})]}),Il=({project:e,account:t,accounts:r,onDeleted:o,onMoved:i})=>{const[a,s]=w(null),[l,c]=w(null),[d,h]=w(!1),[p,v]=w(!1),[b,m]=w(""),[y,u]=w(!1),g=(r??[]).filter($=>$!==t);D(()=>{let $=!1;return fetch(`/api/cw/mcps?project=${encodeURIComponent(e)}`).then(N=>N.json()).catch(()=>null).then(N=>{$||s(N)}),()=>{$=!0}},[e]);const k=a?Object.keys(a.global):[],f=(a==null?void 0:a.project)??[],C=(a==null?void 0:a.cw)??[],x=(a==null?void 0:a.plugins)??[],j=[...f.map($=>`${$} (project)`),...k,...C.map($=>`${$} (CW)`)],R=$=>{c(l===$?null:$),m(""),h(!1)},E=async()=>{v(!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{v(!1),c(null)}},L=async()=>{if(b){u(!0);try{const N=await(await fetch("/api/cw/move-project",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:e,toAccount:b})})).json();N.ok?(P(`Project "${e}" moved to "${b}"`,"success"),c(null),m(""),i==null||i()):P(N.error??"Failed to move project","error")}catch{P("Failed to move project","error")}finally{u(!1)}}};if(!a)return null;const S={padding:"12px 15px",borderTop:"1px solid var(--hair)",display:"flex",flexDirection:"column",gap:"10px"},T=($,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:[j.length>0&&n("span",{class:"truncate",title:j.join(", "),children:["MCP · ",j.join(", ")]}),x.length>0&&n("span",{class:"truncate",title:x.join(", "),children:["Plugins · ",x.join(", ")]}),j.length===0&&x.length===0&&n("span",{children:"No MCPs or plugins for this project"})]}),g.length>0&&n("button",{type:"button",class:"cursor-pointer",style:T("ink",l==="move"),"aria-expanded":l==="move",onClick:()=>R("move"),children:"Move to account"}),n("button",{type:"button",class:"cursor-pointer",style:T("red",l==="delete"),"aria-expanded":l==="delete",onClick:()=>R("delete"),children:"Delete project"})]}),l==="move"&&n("div",{style:S,children:[n("p",{style:{fontSize:"13px"},children:['Move "',e,'" to a different account.']}),n("select",{class:"field",value:b,onChange:$=>m($.target.value),children:[n("option",{value:"",children:"Select account…"}),g.map($=>n("option",{value:$,children:$},$))]}),n("div",{class:"flex",style:{gap:"8px"},children:[n(I,{label:y?"Moving…":"Move project",variant:"primary",size:"sm",loading:y,disabled:!b,onClick:L}),n(I,{label:"Cancel",variant:"secondary",size:"sm",onClick:()=>{c(null),m("")}})]})]}),l==="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(I,{label:p?"Deleting…":d?"Delete project and files":"Unregister project",variant:"destructive",size:"sm",loading:p,onClick:E}),n(I,{label:"Cancel",variant:"secondary",size:"sm",onClick:()=>{c(null),h(!1)}})]})]})]})},Pi=e=>e.trim().replace(/\s+/g,"-").toLowerCase();function yn(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:Pi(t)}:null}const Ol="A PR link becomes a review. A Linear or Notion link becomes a dev task with its notes.";function Wl(e,t){const r=yn(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:Ol,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 br=(e,t)=>{var r;return t??((r=yn(e))==null?void 0:r.type)??"dev"},ke=X(""),Je=X(null),He=X(""),sn=X(""),cn=e=>{ke.value=e,Je.value=null},kr=(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,Dl=(e,t,r,o,i)=>{var l;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=(l=e.harnesses.find(c=>c.name===t))==null?void 0:l.version,s=r==null?void 0:r.model;return[o?"Default":a,s].filter(Boolean).join(" · ")||(o?"Default":"")},Fl=({doctor:e,account:t,value:r,defaultHarness:o,isLoop:i,onChange:a,onOpenAccounts:s})=>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(l=>{const c=Ae(e,t,l.name),d=kr(l.name,c,i),h=ve(l.name),p=r===l.name,v=(c==null?void 0:c.status)==="not_logged_in",b=Dl(e,l.name,c,l.name===o,d);return n("div",{role:"radio","aria-checked":p,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 ${p?"var(--blue)":"var(--hair)"}`,background:p?ae("--blue"):"var(--card)",boxShadow:p?"var(--shadow-s)":"none",opacity:d?.45:1},onClick:()=>{d||a(l.name)},onKeyDown:m=>{!d&&(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),a(l.name))},children:[n("span",{class:"shrink-0",style:{width:"8px",height:"8px",borderRadius:"50%",marginTop:"5px",background:h.color,boxShadow:p?`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:b,children:b}),v&&s&&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:m=>{m.stopPropagation(),s()},onKeyDown:m=>m.stopPropagation(),children:"Connect"})]})]},l.name)})})]}),Ml=({options:e,value:t,label:r,onPick:o,onClose:i})=>{const[a,s]=w(""),[l,c]=w(0),d=xn(),h=ee(null),p=a.trim().toLowerCase(),v=Z(()=>e.filter(y=>{var u;return!p||y.label.toLowerCase().includes(p)||((u=y.group)==null?void 0:u.toLowerCase().includes(p))}),[e,p]);D(()=>{const y=v.findIndex(u=>u.value===t);c(y>=0&&!p?y:0)},[p]),D(()=>{var y,u;(u=(y=h.current)==null?void 0:y.querySelector('[data-active="true"]'))==null||u.scrollIntoView({block:"nearest"})},[l]);const b=y=>{if(y.key==="ArrowDown")y.preventDefault(),c(u=>Math.min(u+1,v.length-1));else if(y.key==="ArrowUp")y.preventDefault(),c(u=>Math.max(u-1,0));else if(y.key==="Enter"){y.preventDefault();const u=v[l];u&&o(u.value)}else y.key==="Escape"&&(y.preventDefault(),y.stopPropagation(),i())};let m;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:b,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:y=>s(y.target.value)})]}),n("div",{ref:h,role:"listbox","aria-label":r,class:"overflow-y-auto min-h-0",style:{marginTop:"6px"},children:[v.length===0&&n("p",{style:{padding:"8px 10px",fontSize:"12.5px",color:"var(--ink-3)"},children:["No match for “",a.trim(),"”."]}),v.map((y,u)=>{const g=y.group&&y.group!==m?y.group:null;m=y.group;const k=u===l,f=y.value===t;return n("div",{children:[g&&n("div",{style:{padding:"7px 9px 3px",fontSize:"11px",fontWeight:600,color:"var(--ink-3)"},children:g}),n("button",{type:"button",role:"option","aria-selected":f,"data-active":k,tabIndex:-1,class:"flex items-center w-full text-left cursor-pointer",style:{gap:"8px",padding:"6px 9px",borderRadius:"8px",border:0,background:k?"var(--elev)":"transparent",color:"var(--ink)",fontSize:"13px"},onMouseMove:()=>{k||c(u)},onClick:()=>o(y.value),children:[n("span",{class:"flex-1 truncate",style:{fontWeight:f?600:400,color:y.value?"var(--ink)":"var(--ink-2)"},children:y.label}),f&&n("span",{class:"i-lucide-check shrink-0",style:{width:"13px",height:"13px",color:"var(--blue)"}})]})]},y.value||"__empty")})]})]})},ji=({label:e,value:t,options:r,onChange:o,placeholder:i="Choose…",size:a="sm",width:s})=>{const[l,c]=w(!1),d=ee(null),h=r.find(v=>v.value===t);return D(()=>{if(!l)return;const v=b=>{d.current&&!d.current.contains(b.target)&&c(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[l]),n("div",{ref:d,class:"relative",style:{width:s},children:[n("button",{type:"button","aria-haspopup":"listbox","aria-expanded":l,"aria-label":e,class:"field flex items-center text-left cursor-pointer",style:a==="sm"?{width:s??"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:()=>c(v=>!v),onKeyDown:v=>{v.key==="ArrowDown"&&(v.preventDefault(),c(!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)"}})]}),l&&n(Ml,{options:r,value:t,label:e,onPick:v=>{o(v),c(!1)},onClose:()=>c(!1)})]})},er=(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}))},Ai=({ctx:e,size:t="md"})=>{const{text:r,ready:o}=Wl(ke.value,{...e,harness:ve(e.harness).label}),i=o&&(e.type==="general"||yn(ke.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:ae("--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})]})},Ei=({fill:e})=>n(he,{fill:e,label:"Task type",tabs:et.map(t=>({id:t.key,label:vr(t.key)})),active:br(ke.value,Je.value),onChange:t=>{Je.value=t}}),Bl={width:"auto",maxWidth:"180px",height:"30px",padding:"0 26px 0 10px",borderRadius:"9px",fontSize:"12.5px",background:"var(--bg-2)"},Ul=({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:Bl,value:t,onChange:i=>r(i.target.value),children:o.map(i=>n("option",{value:i.value,children:i.label},i.value))})]}),Hl=({projects:e,accounts:t,onStarted:r,onOpenDrawer:o})=>{var f,C;const[i,a]=w(!1),s=mn.value,l=s!=null&&s.available?s.doctor:null,c=br(ke.value,Je.value),d=c==="general",h=He.value,p=Object.keys(e).sort(),v=d?sn.value||((f=e[h])==null?void 0:f.account)||t[0]||"":((C=e[h])==null?void 0:C.account)??"",b=p.filter(x=>e[x].account===v),m=c==="loop"?"claude":l?Go(h||void 0,v,e,l):"claude",y=ke.value.trim(),u=i||(d?!v:!y||!h),g=async()=>{if(u)return;const x=l?Ae(l,v,m):void 0,j=l?kr(m,x,c==="loop"):null,R=!d&&hi(s,m,y);if(c==="loop"||j||R||(x==null?void 0:x.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:c,account:v,project:h||void 0,harness:l?m:void 0}:{type:c,project:h,task:y,account:v||void 0,harness:l?m:void 0})})).json();S.ok?(P(d?"Session started":c==="review"?"Review started":"Task started","success"),d||cn(""),r(S.session)):P(S.error??"Failed to start","error")}catch{P("Failed to start","error")}finally{a(!1)}},k=x=>{var j;sn.value=x,h&&((j=e[h])==null?void 0:j.account)!==x&&(He.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:ke.value,onInput:x=>cn(x.target.value),onKeyDown:x=>{x.key==="Enter"&&g()}}),n(Ei,{}),n("button",{type:"button",disabled:u,class:u?"":"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:u&&!i?"var(--elev)":"linear-gradient(180deg, var(--blue-2), var(--blue))",color:u&&!i?"var(--ink-3)":"#fff",boxShadow:u&&!i?"none":"var(--shadow-m)",opacity:u&&!i?.8:1,cursor:u?"not-allowed":"pointer"},onClick:()=>void g(),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(Ai,{ctx:{type:c,project:h,account:v,harness:m}})}),d&&n(Ul,{label:"Account",value:v,onChange:k,options:t.map(x=>({value:x,label:x}))}),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(ji,{label:"Project",value:h,onChange:x=>{He.value=x},placeholder:d?"No project":"Choose…",options:d?[{value:"",label:"No project"},...er(e,t,b)]:er(e,t,p)})]})]})]})},Tt=({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(_r,{}),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})]}),Kl=({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]}),_r=()=>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:()=>{Pe.value=!0},children:n("span",{class:"i-lucide-menu",style:{width:"15px",height:"15px"}})}),tr=X({}),oo=new Set;function ql(e){!e||oo.has(e)||(oo.add(e),fetch(`/api/cw/detect/${encodeURIComponent(e)}`).then(t=>t.ok?t.json():null).catch(()=>null).then(t=>{tr.value={...tr.value,[e]:t}}))}const Li=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 Ni(e){return D(()=>{ql(e)},[e]),tr.value[e]}const io=10,Ii="forge-task-layout",Gl=()=>{try{return localStorage.getItem(Ii)==="project"?"project":"recent"}catch{return"recent"}},Vt={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)"},Vl=({project:e,account:t,sessions:r,index:o,openTabKeys:i,onSelectTask:a,onMarkDone:s})=>{const l=Li(Ni(e)),c=r.some(d=>i.has(q(d)));return n("section",{style:{...Vt,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:c}),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,l.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(Ri,{session:d,isOpenInTab:i.has(q(d)),onSelect:()=>a(d),onMarkDone:d.type==="login"?void 0:()=>s(d)},q(d)))]})},Jl=({spaces:e,allSpaces:t,projects:r,accountNames:o,filterAccount:i,filterProject:a,onFilterProject:s,filterType:l,onFilterType:c,harnessNames:d,filterHarness:h,onFilterHarness:p,showDone:v,onShowDone:b,openTabKeys:m,onSelectTask:y,onMarkDone:u,onNewTask:g,onCreateProject:k,onRefresh:f,onStarted:C})=>{var U,J;const[x,j]=w(Gl),R=z=>{j(z);try{localStorage.setItem(Ii,z)}catch{}},E=Z(()=>e.filter(z=>z.status==="active"),[e]),L=Z(()=>e.filter(z=>z.status==="done"),[e]),S=Z(()=>t.filter(z=>z.status==="active").length,[t]),T=Z(()=>t.filter(z=>z.status==="done").length,[t]),$=Z(()=>t.filter(z=>z.status==="active"&&m.has(q(z))).length,[t,m]),N=Z(()=>t.filter(z=>z.status==="active"&&(!i||z.account===i)&&(!a||z.project===a)&&(!h||(z.harness??"claude")===h)),[t,i,a,h]),W=Z(()=>{const z=new Map;for(const G of E){const V=pe(G),le=z.get(V)??[];le.push(G),z.set(V,le)}return Array.from(z,([G,V])=>({project:G,sessions:V}))},[E]),O=a?((U=r[a])==null?void 0:U.account)??((J=E[0])==null?void 0:J.account):void 0,F=a?`${O?`${O} · `:""}${N.length} active`:`${S} active · ${T} done · ${$} agent${$===1?"":"s"} working`;return n(K,{children:[n(Tt,{title:a??"Tasks",subtitle:F,children:[n(I,{label:"Add project",variant:"secondary",onClick:k}),n(I,{label:"New task",variant:"primary",onClick:g})]}),n("div",{class:"flex flex-col w-full",style:{padding:"18px 22px 40px",gap:"16px",maxWidth:"1180px"},children:[n(Hl,{projects:r,accounts:o,onStarted:C,onOpenDrawer:g}),n("div",{class:"flex items-center flex-wrap",style:{gap:"12px"},children:[n(he,{label:"Filter by type",tabs:[{id:"all",label:"All",count:N.length},...et.map(z=>({id:z.key,label:vr(z.key),count:N.filter(G=>G.type===z.sessionType).length}))],active:l??"all",onChange:z=>c(z==="all"?null:z)}),d.length>1&&n(he,{label:"Filter by harness",tabs:[{id:"all",label:"Any harness"},...d.map(z=>({id:z,label:ve(z).label}))],active:h??"all",onChange:z=>p(z==="all"?null:z)}),n("span",{class:"flex-1"}),!a&&n(he,{size:"sm",label:"Order tasks",tabs:[{id:"recent",label:"Recent"},{id:"project",label:"By project"}],active:x,onChange:z=>R(z==="project"?"project":"recent")}),n("button",{type:"button","aria-pressed":v,class:"cursor-pointer transition-all duration-180 ease-spring",style:{padding:"6px 12px",borderRadius:"9px",border:"1px solid var(--hair)",background:v?"var(--card)":"transparent",color:v?"var(--ink)":"var(--ink-2)",fontSize:"12.5px",fontWeight:500,boxShadow:v?"var(--shadow-s)":"none"},onClick:()=>b(!v),children:v?"Hide done":"Show done"})]}),a&&n(Il,{project:a,account:O,accounts:o,onDeleted:()=>{s(null),f()},onMoved:f}),x==="recent"&&!a&&E.length>0&&n("section",{style:{...Vt,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:[E.length," task",E.length===1?"":"s"]})]}),E.map(z=>n(Ri,{session:z,showProject:!0,isOpenInTab:m.has(q(z)),onSelect:()=>y(z),onMarkDone:z.type==="login"?void 0:()=>u(z)},q(z)))]}),(x==="project"||a)&&W.map((z,G)=>{var V;return n(Vl,{project:z.project,account:((V=r[z.project])==null?void 0:V.account)??z.sessions[0].account,sessions:z.sessions,index:G,openTabKeys:m,onSelectTask:y,onMarkDone:u},z.project)}),W.length===0&&n("section",{style:{...Vt,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:l||h?"No active tasks match these filters.":a?`No active tasks on ${a}.`:"No active tasks. Start something new."}),n(I,{label:"New task",variant:"primary",onClick:g})]})]}),v&&L.length>0&&n("section",{style:{...Vt,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(io,L.length)," of ",L.length]}),L.slice(0,io).map(z=>n(Nl,{session:z,onSelect:()=>y(z)},q(z)))]})]})]})},Ne={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"},Ye="inline-flex items-center gap-1 cursor-pointer transition-all duration-180 ease-spring hover:-translate-y-px hover:shadow-m hover:text-ink",Oi={...Ne,color:"var(--ink-3)",boxShadow:"none"},Wi=({href:e,title:t,children:r})=>n("a",{class:Ye,style:Ne,href:e,target:"_blank",rel:"noopener noreferrer",title:t,children:[r," ",n("span",{class:"i-lucide-external-link",style:{width:"12px",height:"12px"}})]}),Yl=({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:Oi,disabled:!0,title:o,children:["GitHub ",n("span",{class:"i-lucide-external-link",style:{width:"12px",height:"12px"}})]})}return n(Wi,{href:t.url,title:t.label,children:"GitHub"})},Ql=({session:e})=>{const t=xr(e);return t&&n(Wi,{href:t.url,title:t.url,children:t.label})},Zl=({session:e,entry:t})=>{var d;const[r,o]=w(!1),i=ee(null);D(()=>{fi()},[]),D(()=>{if(!r)return;const h=p=>{i.current&&!i.current.contains(p.target)&&o(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[r]);const a=Yn.value,s=a!=null&&a.enabled?a.editors:[];if(s.length===0)return null;const l=(d=t==null?void 0:t.state)==null?void 0:d.workspace;if(l!=="ready")return n("button",{type:"button",class:"cursor-not-allowed",style:Oi,disabled:!0,title:t?l==="missing"?"Workspace not created yet":"This session has no worktree":"Checking the worktree…",children:["Open in ",s.length===1?s[0].label:"editor"]});const c=async h=>{o(!1);try{await cl(e,h)}catch(p){P(p.message,"error")}};return s.length===1?n("button",{type:"button",class:Ye,style:Ne,onClick:()=>c(s[0].id),children:["Open in ",s[0].label]}):n("div",{class:"relative",ref:i,children:[n("button",{type:"button",class:Ye,style:Ne,"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:s.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:()=>c(h.id),children:h.label},h.id))})]})},Xl={"--orange":"--red","--blue":"--purple","--purple":"--blue","--green":"--teal"},ct=({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)"}})})]}),es=({project:e,onOpen:t})=>{const r=ki(e);return r.length===0?null:n("div",{class:"min-w-0",style:{gridColumn:"span 2",padding:"10px 12px",borderRadius:"13px",background:"var(--card)",border:"1px solid var(--hair)",boxShadow:"var(--shadow-s)",animation:"riseIn .34s var(--ease) 360ms both"},children:[n("div",{style:{fontSize:"11.5px",color:"var(--ink-2)"},children:["Memory · ",ln(r)," pages"]}),n("div",{class:"flex items-center flex-wrap",style:{gap:"4px",marginTop:"6px"},children:r.map((o,i)=>n("span",{class:"inline-flex items-center",style:{gap:"4px"},children:[i>0&&n("span",{style:{color:"var(--ink-3)",fontSize:"11px"},children:"→"}),n("button",{type:"button",class:"cursor-pointer transition-all duration-180 ease-spring hover:-translate-y-px",style:{padding:"2px 9px",borderRadius:"99px",fontSize:"12px",fontWeight:600,border:0,background:ae(Ge(o.tier)),color:`var(${Ge(o.tier)})`},title:`${o.tier??"brain"} · ${o.pages} pages`,onClick:()=>t==null?void 0:t(e),children:Le(o)})]},o.key))})]})},Ln=({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?ae(r):"var(--elev)",color:r&&!i.muted?`var(${r})`:"var(--ink-2)",opacity:i.muted?.6:1},children:i.name},i.name))]})]}),ts=({session:e,active:t,onDone:r,onOpenMemory:o})=>{const[i,a]=w(""),[s,l]=w(!1),[c,d]=w(!1),[h,p]=w(0),[v,b]=w(null),[m,y]=w(!1),u=q(e),g=fn(e),k=e.type==="task"||e.type==="review",f=Si(e,{poll:t&&e.type==="task"}),C=fr(e.type),x=e.type==="login",j=Li(Ni(x?"":pe(e))),R=ti(u).value,E=encodeURIComponent(e.project),L=encodeURIComponent(g),T=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws/terminal/${E}/${L}?k=${h}`;D(()=>{if(x)return;let z=!1;return Promise.all([fetch(`/api/cw/tools?project=${E}`).then(G=>G.json()).catch(()=>null),fetch(`/api/cw/git/branch/${E}/${L}`).then(G=>G.json()).catch(()=>null)]).then(([G,V])=>{z||(G&&b(G),a((V==null?void 0:V.branch)||e.task||e.pr||""))}),()=>{z=!0}},[u]);const $=()=>{l(!1),p(z=>z+1)},N=(v==null?void 0:v.mcps)??[],W=(v==null?void 0:v.plugins)??[],O=(f==null?void 0:f.state)??null,F=(O==null?void 0:O.branch)??i,U=f?f.error!==null?"Changes unknown":pl(f.state):"Checking changes…",J=[pe(e)||"no project",e.account,[qo(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(${C.token}), var(${Xl[C.token]??C.token}))`,boxShadow:"var(--shadow-m)",color:"#fff",fontSize:"13px",fontWeight:700},"aria-hidden":"true",children:C.glyph}),n("div",{class:"min-w-0",children:[n("h1",{class:"truncate",style:{fontSize:"19px",fontWeight:700,letterSpacing:"-0.02em"},children:fe(e)}),n("p",{class:"truncate",style:{marginTop:"1px",fontSize:"12.5px",color:"var(--ink-2)"},children:J}),!x&&n("p",{class:"mono truncate",style:{marginTop:"2px",fontSize:"11.5px",color:"var(--ink-3)"},title:U,children:U})]}),n("span",{style:{flex:"1 1 60px"}}),n("div",{class:"flex flex-wrap items-center",style:{gap:"7px"},children:[!x&&n("button",{type:"button",class:Ye,style:Ne,"aria-expanded":m,onClick:()=>y(z=>!z),children:m?"Hide context":`Context · ${N.length} MCP, ${W.length} plugins`}),!x&&n(Ql,{session:e}),!x&&n(Yl,{entry:f}),!x&&n(Zl,{session:e,entry:f}),s&&n(I,{label:"Restart",variant:"secondary",size:"sm",onClick:$}),e.status==="active"&&!x&&n(I,{label:"Mark done",variant:"primary",size:"sm",onClick:r})]})]}),!x&&n("div",{class:"grid",style:{gridTemplateColumns:"repeat(auto-fit, minmax(138px, 1fr))",gap:"9px"},children:[n(ct,{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(ct,{index:1,label:"Tokens",children:(R==null?void 0:R.tokens)!=null?ni(R.tokens):"—"}),n(ct,{index:2,label:"Cost",color:"var(--green)",children:(R==null?void 0:R.cost)!=null?ri(R.cost):"—"}),k&&n(ct,{index:3,label:"Commits",children:(O==null?void 0:O.commits)??"—"}),k&&n(ct,{index:4,label:"Unpushed",color:O&&St(O)>0?"var(--orange)":"var(--ink)",children:O?St(O):"—"}),n(es,{project:pe(e),onOpen:o}),F&&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:()=>yr(F,"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:F})]})]}),m&&n("div",{class:"grid",style:{gridTemplateColumns:"repeat(auto-fit, minmax(230px, 1fr))",gap:"9px",animation:"riseIn .3s var(--ease) both"},children:[n(Ln,{title:`MCP · ${N.length}`,tone:"--blue",empty:"No MCP servers",items:N.map(z=>({name:z.name,title:`${z.type} · ${z.source}`}))}),n(Ln,{title:`Plugins · ${W.length}`,tone:"--green",empty:"No plugins",items:W.map(z=>({name:z.name,muted:!z.enabled,title:`${z.enabled?"enabled":"disabled"} · ${z.marketplace}${z.hasMcp?` · MCP ${z.mcpName??""}`:""}`}))}),n(Ln,{title:"Stack",tone:null,empty:"Nothing detected",items:j.map(z=>({name:z}))})]})]}),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:[F||fe(e)," — ",e.harness??"claude"]}),n("span",{class:"flex-1"}),n("span",{class:"mono",style:{fontSize:"11px",color:c?"#30d158":"#8a8a92"},children:c?"connected":s?"exited":"offline"})]}),n("div",{class:"relative flex-1 min-h-0",style:{padding:"12px 6px 6px 14px"},children:[n(ma,{wsUrl:T,theme:zt.value,focused:t,onOutput:z=>Ba(u,z),onExit:()=>l(!0),onGiveUp:()=>l(!0),onConnectionChange:d}),!c&&!s&&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…"})})]})]})})]})},Qe={fontSize:"12px",color:"var(--ink-2)"},te=({label:e,plain:t,children:r})=>n(t?"div":"label",{class:"flex flex-col min-w-0",style:{gap:"5px"},children:[n("span",{style:Qe,children:e}),r]}),ao={dev:"New dev task",review:"Review a pull request",loop:"New loop",general:"New session"},ns={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."},rs={dev:"Task name or ticket URL",review:"Pull request number or URL",loop:"Loop prompt",general:""},os={dev:"fix-auth or https://linear.app/…",review:"42 or https://github.com/…/pull/42",loop:"Babysit my open PRs…",general:""},is=[{id:"",label:"Auto"},{id:"feature",label:"feature"},{id:"bugfix",label:"bugfix"},{id:"refactor",label:"refactor"}],Nn={boxShadow:"var(--shadow-s)"},Dt=e=>/^[\w./:#-]+$/.test(e)?e:`"${e.replace(/"/g,'\\"')}"`,as=({projects:e,accounts:t,initialAccount:r,initialProject:o,onClose:i,onCreated:a,onOpenAccounts:s})=>{var Et;const l=br(ke.value,Je.value),[c,d]=w(""),[h,p]=w(""),[v,b]=w(""),[m,y]=w(""),[u,g]=w(""),[k,f]=w(!1),[C,x]=w(!1),[j,R]=w(""),[E,L]=w("claude"),S=xn();D(()=>{ye()},[]),D(()=>{const _=A=>{A.key==="Escape"&&i()};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[i]);const T=mn.value,$=T!=null&&T.available?T.doctor:null,N=Object.keys(e),W=l==="general",O=l==="review",F=l==="loop",U=ke.value,J=!j.trim()||/^\d+[smh]$/.test(j.trim()),z=t.length>0?t:Array.from(new Set(Object.values(e).map(_=>_.account).filter(Boolean))).sort(),G=c?N.filter(_=>{var A;return((A=e[_])==null?void 0:A.account)===c}):N;D(()=>{const _=o&&!r&&e[o]?e[o].account:void 0,A=r??_,M=A&&z.includes(A)?A:z[0]??"";d(M);const H=M?N.filter(re=>{var Ce;return((Ce=e[re])==null?void 0:Ce.account)===M}):N,se=o&&H.includes(o)?o:!W&&H.length>0?H[0]:"";se&&p(se)},[]);const V=ee(!1);D(()=>{if(!V.current){V.current=!0;return}!W&&!h&&G.length>0&&p(G[0])},[W]);const le=_=>{d(_);const A=N.filter(M=>{var H;return((H=e[M])==null?void 0:H.account)===_});!W&&A.length>0&&!A.includes(h)?p(A[0]):W&&h&&!A.includes(h)&&p("")},ie=$?Go(h||void 0,c,e,$):"claude";D(()=>{!$||!c||L(F?"claude":ie)},[T==null?void 0:T.available,c,h,F]);const de=$?Ae($,c,E):void 0,me=!$||Ue(T,E,"skip_permissions"),_e=!$||E==="claude",We=_e||!W,ge=$?kr(E,de,F):null,Pt=ve(E).label;D(()=>{me||f(!1),g(_e?"":(de==null?void 0:de.model)??"")},[E]),D(()=>{_e||g((de==null?void 0:de.model)??"")},[c]);const tt=ui(U),bn=hi(T,E,U),jt=!W&&!U.trim()||F&&!J||!W&&!h||!!ge,At=async()=>{if(!jt){x(!0);try{const _={type:l,account:c||void 0,skipPermissions:k||void 0};$&&(_.harness=E),F?(_.project=h,_.loopPrompt=U.trim(),_.loopInterval=j.trim()||void 0):W?h&&(_.project=h):(_.project=h,_.task=U.trim(),_.description=v.trim()||void 0,_.workflow=m||void 0),_.model=We&&u||void 0;const M=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(_)})).json();M.ok?(P(W?"Session started":F?"Loop started":"Task started","success"),W||cn(""),a(M.session)):P(M.error??"Failed to start","error")}catch{P("Failed to start","error")}finally{x(!1)}}},kn=c||z[0]||"default",_n=W?`cw launch ${Dt(kn)}`:F?`cw loop ${h||"<project>"} ${Dt(U.trim()||"<prompt>")}${j.trim()?` --every ${j.trim()}`:""}`:O?`cw review ${h||"<project>"} ${Dt(U.trim()||"<pr>")}`:`cw work ${h||"<project>"} ${U.trim()?Dt(((Et=yn(U))==null?void 0:Et.kind)==="name"?Pi(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":ao[l],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:_=>_.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:ao[l]}),n("span",{class:"flex-1"}),n(Fo,{onClick:i})]}),n("div",{class:"flex flex-col",style:{padding:"16px 18px 24px",gap:"14px"},children:[n(Ei,{fill:!0}),n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)",lineHeight:1.5},children:ns[l]}),!W&&n("div",{class:"flex flex-col",style:{gap:"5px"},children:[n(te,{label:rs[l],children:n("input",{class:"field",style:{...Nn,fontSize:"14px"},placeholder:os[l],value:U,ref:S,onInput:_=>{const A=_.target.value;F?ke.value=A:cn(A)},onKeyDown:_=>{_.key==="Enter"&&At()}})}),!F&&n(Ai,{ctx:{type:l,project:h,account:c,harness:E},size:"sm"})]}),n("div",{class:"grid",style:{gridTemplateColumns:"1fr 1fr",gap:"10px"},children:[n(te,{label:"Account",children:n("select",{class:"field",value:c,onChange:_=>{const A=_.target.value;le(A),sn.value=A},children:z.map(_=>n("option",{value:_,children:_},_))})}),n(te,{plain:!0,label:W?"Project · optional":"Project",children:n(ji,{label:"Project",size:"md",width:"100%",value:h,placeholder:W?"No project":"Choose…",onChange:_=>{p(_),He.value=_},options:[...W?[{value:"",label:"No project"}]:[],...er(e,z,G)]})})]}),F&&n(te,{label:"Interval · optional",children:[n("input",{class:"field mono",style:{...Nn,borderColor:J?void 0:"var(--red)"},value:j,placeholder:"auto — Claude decides the pace",onInput:_=>R(_.target.value)}),!J&&n("span",{style:{fontSize:"12px",color:"var(--red)"},children:"Use forms like 30s, 5m, 2h — or leave it empty to self-pace"})]}),(l==="dev"||O)&&n(te,{label:"Description (optional)",children:n("textarea",{class:"field",rows:3,style:Nn,placeholder:"Context the agent reads first…",value:v,onInput:_=>b(_.target.value)})}),$&&n(Fl,{doctor:$,account:c,value:E,defaultHarness:ie,isLoop:F,onChange:L,onOpenAccounts:s}),We&&n("div",{class:"grid",style:{gridTemplateColumns:l==="dev"?"1fr 1fr":"1fr",gap:"10px"},children:[n("div",{class:"flex flex-col min-w-0",style:{gap:"5px"},children:[n("span",{style:Qe,children:"Model"}),_e?n(he,{fill:!0,size:"sm",label:"Model",tabs:ja.map(_=>({id:_.id,label:_.label})),active:u,onChange:g}):n("input",{class:"field mono",style:{height:"32px",fontSize:"12.5px"},value:u,placeholder:"the account's model","aria-label":"Model",onInput:_=>g(_.target.value)})]}),l==="dev"&&n("div",{class:"flex flex-col min-w-0",style:{gap:"5px"},children:[n("span",{style:Qe,children:"Workflow"}),n(he,{fill:!0,size:"sm",label:"Workflow",tabs:is,active:m,onChange:y})]})]}),me&&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(Mo,{checked:k,onChange:f,label:"Bypass permissions"})]}),bn&&n("p",{style:{fontSize:"12.5px",padding:"10px 12px",borderRadius:"12px",background:ae("--orange"),color:"var(--ink)"},children:[Pt," has no MCP and CW has no ",tt==="linear"?"LINEAR_API_KEY":"NOTION_TOKEN",", so the ticket will not reach TASK_NOTES.md. The task still starts, without the ticket."]}),n(I,{label:C?"Starting…":W?"Launch session":F?"Start loop":O?"Start review":"Start task",variant:"primary",size:"lg",block:!0,loading:C,disabled:jt,onClick:At}),ge&&n("p",{style:{fontSize:"12px",color:"var(--red)",textAlign:"center"},children:ge}),n("p",{class:"mono",style:{fontSize:"11.5px",color:"var(--ink-3)",textAlign:"center",overflowWrap:"anywhere"},children:_n})]})]})})},dn=X(null),nr=X(null);async function wr(){const e=await fetch("/api/skills/plugins");if(!e.ok)throw new Error("fetch failed");dn.value=await e.json()}async function rr(){const e=await fetch("/api/skills/marketplaces");if(!e.ok)throw new Error("fetch failed");nr.value=await e.json()}const Oe=({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 ls(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 ss(e){return`add-skill-${e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,30).replace(/-+$/,"")||Date.now()}`}function cs(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 Di=e=>`/api/skills/plugins/${encodeURIComponent(e)}`;async function Sr(e,t){try{return await Me(e,t)}catch(r){return P(vt(r),"error"),null}}async function Fi(e,t,r){await Sr("/api/skills/plugins/install",{id:e,account:r})&&(P(`${t} installed in ${r} · applies to new sessions`,"success"),await Promise.all([wr(),rr()]).catch(()=>{}))}const Mi=(e,t)=>t?e.skills.filter(r=>r.name.toLowerCase().includes(t)||r.description.toLowerCase().includes(t)):e.skills,ds=({list:e,query:t,selected:r,onSelect:o})=>{const i=e.flatMap(a=>{const s=Mi(a,t).length;return!t||s>0||a.name.toLowerCase().includes(t)?[{p:a,count:s}]:[]});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:s})=>{const l=r===a.id;return n("button",{type:"button","aria-current":l?"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 ${l?"var(--hair)":"transparent"}`,background:l?"var(--card)":"transparent",boxShadow:l?"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:s})]},a.id)})]})},lo={fontSize:"12px",fontWeight:600,color:"var(--ink-2)",margin:"0 0 8px"},Bi={gap:"10px",padding:"9px 12px",borderRadius:"11px",border:"1px solid var(--hair)",background:"var(--card)"},ps=({plugin:e,install:t})=>{const[r,o]=w(!1),i=t.scope==="global"?"global":t.scopeRef,a=async()=>{o(!0);const s=await Sr(`${Di(e.id)}/update`,{scope:t.scope,scopeRef:t.scopeRef});o(!1),s&&(P(`${e.name} ${s.version??""} · applies to new sessions`,"success"),wr().catch(()=>{}))};return n("div",{class:"flex items-center",style:Bi,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(I,{label:r?"Updating…":"Update",variant:"secondary",size:"sm",loading:r,onClick:a})]})},us=({plugin:e,account:t})=>{const[r,o]=w(!1);return n("div",{class:"flex items-center",style:Bi,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(I,{label:r?"Installing…":"Install",variant:"secondary",size:"sm",loading:r,onClick:async()=>{o(!0),await Fi(e.id,e.name,t),o(!1)}})]})},hs=({plugin:e,name:t,onBack:r})=>{const[o,i]=w(null),[a,s]=w(!1);return D(()=>{let l=!1;return i(null),s(!1),fetch(`${Di(e.id)}/skills/${encodeURIComponent(t)}`).then(c=>c.ok?c.json():Promise.reject(new Error("not found"))).then(c=>{l||i(c.content)}).catch(()=>{l||s(!0)}),()=>{l=!0}},[e.id,t]),n(K,{children:[n(Oe,{title:t,sub:`${e.name} · read-only`,children:n(I,{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})]})]})},fs=({plugin:e,accounts:t,query:r,onSelectSkill:o,onPropose:i})=>{const a=new Set(e.installs.map(l=>l.scopeRef)),s=t.filter(l=>!a.has(l));return n(K,{children:[n(Oe,{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(I,{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:lo,children:"Accounts"}),n("div",{class:"flex flex-col",style:{gap:"6px"},children:[e.installs.map(l=>n(ps,{plugin:e,install:l},`${l.scope}/${l.scopeRef}`)),s.map(l=>n(us,{plugin:e,account:l},l))]})]}),n("section",{children:[n("h3",{style:lo,children:["Skills (",e.skills.length,")"]}),n("div",{class:"flex flex-col",style:{gap:"4px"},children:Mi(e,r).map(l=>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(l.name),children:[n("span",{class:"shrink-0",style:{fontSize:"13px",fontWeight:600},children:l.name}),n("span",{class:"flex-1 min-w-0 truncate",style:{fontSize:"12px",color:"var(--ink-2)"},children:l.description}),n("span",{class:"i-lucide-chevron-right shrink-0",style:{width:"13px",height:"13px",color:"var(--ink-3)"}})]},l.name))})]})]})})]})},vs=({accounts:e})=>{const[t,r]=w(""),o=e.includes(t)?t:e[0]??"",[i,a]=w(""),[s,l]=w(""),[c,d]=w(""),[h,p]=w(!1),[v,b]=w(null);D(()=>{nr.value===null&&rr().catch(()=>P("Failed to load marketplaces","error"))},[]);const m=nr.value,y=(m==null?void 0:m.find(x=>x.name===i))??(m==null?void 0:m[0]),u=new Set((dn.value??[]).flatMap(x=>x.installs.some(j=>j.scope==="account"&&j.scopeRef===o)?[x.id]:[])),g=s.trim().toLowerCase(),k=((y==null?void 0:y.plugins)??[]).filter(x=>!g||x.name.toLowerCase().includes(g)||x.description.toLowerCase().includes(g)),f=async()=>{p(!0);const x=await Sr("/api/skills/marketplaces",{source:c.trim(),account:o});p(!1),x&&(P(`Marketplace added to ${o}`,"success"),d(""),await rr().catch(()=>{}))},C=async(x,j)=>{b(x),await Fi(x,j,o),b(null)};return n(K,{children:[n(Oe,{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(te,{label:"Account",children:n("select",{class:"field",value:o,onChange:x=>r(x.target.value),children:e.map(x=>n("option",{value:x,children:x},x))})}),m&&m.length>0&&n(te,{label:"Marketplace",children:n("select",{class:"field",value:y==null?void 0:y.name,onChange:x=>a(x.target.value),children:m.map(x=>n("option",{value:x.name,children:[x.name," · ",x.source]},x.name))})}),n(te,{label:"Add a marketplace",children:n("div",{class:"flex",style:{gap:"8px"},children:[n("input",{class:"field flex-1",value:c,placeholder:"owner/repo, git URL or path",onInput:x=>d(x.target.value),onKeyDown:x=>{x.key==="Enter"&&c.trim()&&f()}}),n(I,{label:h?"Adding…":"Add",variant:"secondary",size:"sm",loading:h,disabled:!c.trim()||!o,onClick:f})]})}),y&&y.plugins.length>0&&n("input",{class:"field",type:"search","aria-label":"Filter plugins",value:s,placeholder:`Filter ${y.plugins.length} plugins`,onInput:x=>l(x.target.value)})]}),m===null&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:"Loading marketplaces…"}),(m==null?void 0:m.length)===0&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:"No marketplace yet. Add one above."}),y&&k.length===0&&n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:g?"No plugin matches.":"This marketplace lists no plugins."}),k.map((x,j)=>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(j,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:x.name}),x.category&&n("span",{class:"mono shrink-0",style:{fontSize:"11px",color:"var(--ink-3)"},children:x.category})]}),x.description&&n("div",{class:"truncate",style:{fontSize:"12px",color:"var(--ink-2)"},title:x.description,children:x.description})]}),u.has(x.id)?n("span",{style:{fontSize:"12px",color:"var(--green)"},children:"Installed"}):n(I,{label:v===x.id?"Installing…":"Install",variant:"secondary",size:"sm",loading:v===x.id,disabled:v!==null||!o,onClick:()=>C(x.id,x.name)})]},x.id))]})]})},gs=({plugin:e,accounts:t,onSubmit:r,onCancel:o})=>{const i=ls(e),a=e.installs.filter(u=>u.scope==="account").map(u=>u.scopeRef),s=t.find(u=>a.includes(u))??t[0]??"",[l,c]=w(""),[d,h]=w(i[0]??""),[p,v]=w(s),[b,m]=w(!1),y=async()=>{m(!0);try{await r(l.trim(),i.length>1?d:void 0,p)}finally{m(!1)}};return n(K,{children:[n(Oe,{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(te,{label:"What the skill does and when to use it",children:n("textarea",{class:"field",rows:4,value:l,placeholder:"Summarize a release's merged PRs into notes when someone asks for a changelog",onInput:u=>c(u.target.value)})}),i.length>1&&n(te,{label:"Area",children:n("select",{class:"field",value:d,onChange:u=>h(u.target.value),children:i.map(u=>n("option",{value:u,children:u},u))})}),t.length>0&&n(te,{label:"Account",children:n("select",{class:"field",value:p,onChange:u=>v(u.target.value),children:t.map(u=>n("option",{value:u,children:u},u))})}),n("div",{class:"flex flex-wrap",style:{gap:"8px"},children:[n(I,{label:b?"Starting…":"Start task",variant:"primary",loading:b,disabled:!l.trim()||!p,onClick:y}),n(I,{label:"Cancel",variant:"secondary",onClick:o})]})]})})]})},xs={global:"--blue",account:"--orange",project:"--green"},Ft=e=>`${e.scope}/${e.scopeRef}/${e.dirName}`;function ms(e,t){return e==="global"?"global":e==="account"?`account/${encodeURIComponent(t)}`:`project/${encodeURIComponent(t)}`}const xt=e=>e.scope==="global"?"Global":`${e.scope==="account"?"Account":"Project"} · ${e.scopeRef}`,ys=e=>e.scope==="global"?`~/.claude/skills/${e.dirName}`:e.scope==="account"?`~/.cw/accounts/${e.scopeRef}/skills/${e.dirName}`:`<${e.scopeRef}>/.claude/skills/${e.dirName}`,bs={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."},Ui=e=>e[0]?{scope:"account",scopeRef:e[0]}:{scope:"global",scopeRef:"global"},or=e=>e.scope==="global"||e.scopeRef!=="",Hi=({accounts:e,projects:t,value:r,onChange:o})=>{const i=a=>{const s=a==="account"?e:t;o({scope:a,scopeRef:a==="global"?"global":s.includes(r.scopeRef)?r.scopeRef:s[0]??""})};return n(K,{children:[n("div",{class:"flex flex-col",style:{gap:"5px"},children:[n("span",{style:Qe,children:"Scope"}),n(he,{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:bs[r.scope]})]}),r.scope!=="global"&&n(te,{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))})})]})},ks=(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),Ki=(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(...Ki(i,t+" "))):r.push(`${t}${o}: ${String(i??"")}`);return r},_s=({skill:e,accounts:t,projects:r,onDeleted:o,onCopied:i,onRun:a})=>{const[s,l]=w(null),[c,d]=w(!0),[h,p]=w("SKILL.md"),[v,b]=w(""),[m,y]=w({}),[u,g]=w(!1),k=`/api/skills/${ms(e.scope,e.scopeRef)}/${encodeURIComponent(e.dirName)}`;D(()=>{let S=!1;return d(!0),p("SKILL.md"),fetch(k).then(T=>{if(!T.ok)throw new Error("fetch failed");return T.json()}).then(T=>{if(S)return;l(T);const $=Ki(T.frontmatter);b($.length>0?`---
|
|
15
|
+
${$.join(`
|
|
16
|
+
`)}
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
${T.body}`:T.body),y(Object.fromEntries(T.references.map(N=>[N.name,N.content])))}).catch(()=>{S||(l(null),P("Failed to load skill","error"))}).finally(()=>{S||d(!1)}),()=>{S=!0}},[k]);const f=async()=>{g(!0);const S=h==="SKILL.md";try{const $=await(await fetch(S?k:`${k}/references/${encodeURIComponent(h)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:S?v:m[h]??""})})).json();$.ok?P(S?"Skill saved":"Reference saved","success"):P($.error??"Failed to save","error")}catch{P("Failed to save","error")}finally{g(!1)}},C=async()=>{if(confirm(`Delete the skill "${e.name}" permanently?`))try{const T=await(await fetch(k,{method:"DELETE"})).json();T.ok?(P("Skill deleted","info"),o()):P(T.error??"Failed to delete","error")}catch{P("Failed to delete","error")}},x=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 ${xt(S)}`,"success"),i()):P($.error??"Failed to copy","error")}catch{P("Failed to copy","error")}},j=async()=>{const S=prompt("Reference filename (e.g. examples.md):");if(!(S!=null&&S.trim()))return;const T=S.trim(),$=`# ${T}
|
|
20
|
+
`;try{const W=await(await fetch(`${k}/references/${encodeURIComponent(T)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:$})})).json();W.ok?(y(O=>({...O,[T]:$})),l(O=>O&&{...O,references:[...O.references,{name:T,content:$}]}),p(T),P("Reference added","success")):P(W.error??"Failed to add reference","error")}catch{P("Failed to add reference","error")}},R=async S=>{if(confirm(`Delete reference "${S}"?`))try{const $=await(await fetch(`${k}/references/${encodeURIComponent(S)}`,{method:"DELETE"})).json();$.ok?(y(N=>{const{[S]:W,...O}=N;return O}),l(N=>N&&{...N,references:N.references.filter(W=>W.name!==S)}),h===S&&p("SKILL.md"),P("Reference deleted","info")):P($.error??"Failed to delete reference","error")}catch{P("Failed to delete reference","error")}},E=["SKILL.md",...(s==null?void 0:s.references.map(S=>S.name))??[]],L=ks(e,t,r);return n(K,{children:[n(Oe,{title:e.name,sub:`${xt(e)} · ${ys(e)}`,children:[n(I,{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:!s,onChange:S=>{const T=S.target,$=L[Number(T.value)];T.value="",$&&x($)},children:[n("option",{value:"",disabled:!0,children:"Copy to…"}),L.map((S,T)=>n("option",{value:T,children:xt(S)},`${S.scope}/${S.scopeRef}`))]}),n(I,{label:"Run in session",variant:"secondary",size:"sm",onClick:a}),n(I,{label:u?"Saving…":"Save",variant:"primary",size:"sm",loading:u,disabled:!s,onClick:f})]}),n("div",{class:"flex items-center flex-wrap shrink-0",style:{gap:"6px",padding:"10px 20px 0"},role:"tablist","aria-label":"Files",children:[E.map(S=>{const T=h===S;return n("span",{class:"inline-flex items-center",style:{gap:"4px",padding:T?"5px 8px 5px 11px":"5px 11px",borderRadius:"9px",background:T?"var(--card)":"transparent",border:`1px solid ${T?"var(--hair)":"transparent"}`,boxShadow:T?"var(--shadow-s)":"none"},children:[n("button",{type:"button",role:"tab","aria-selected":T,class:"mono cursor-pointer",style:{border:0,background:"none",padding:0,fontSize:"12px",fontWeight:T?600:400,color:T?"var(--ink)":"var(--ink-3)"},onClick:()=>p(S),children:S}),T&&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:()=>R(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:j,disabled:!s,children:"+ Reference"})]}),n("div",{class:"flex-1 min-h-0",style:{padding:"12px 20px 20px"},children:c?n("p",{style:{padding:"24px 0",textAlign:"center",fontSize:"13px",color:"var(--ink-2)"},children:"Loading skill…"}):s?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"?v:m[h]??"",onInput:S=>{const T=S.target.value;h==="SKILL.md"?b(T):y($=>({...$,[h]:T}))}}):n("p",{style:{padding:"24px 0",textAlign:"center",fontSize:"13px",color:"var(--ink-2)"},children:"Skill not found."})})]})},ws=({query:e,accounts:t,projects:r,onInstalled:o})=>{const[i,a]=w(null),[s,l]=w(null),[c,d]=w(()=>Ui(t));D(()=>{let p=!1;return a(null),fetch(`/api/skills/explore?q=${encodeURIComponent(e)}`).then(v=>{if(!v.ok)throw new Error("search failed");return v.json()}).then(v=>{p||a(v.results)}).catch(()=>{p||(a([]),P("Failed to search skills","error"))}),()=>{p=!0}},[e]);const h=async p=>{l(p.slug);try{const b=await(await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({repo:p.repo,skill:p.skillId,...c})})).json();b.ok?(P(`Installed in ${xt(c)}`,"success"),o()):P(b.error??"Failed to install","error")}catch{P("Failed to install","error")}finally{l(null)}};return n(K,{children:[n(Oe,{title:`skills.sh · “${e}”`,sub:`Installs into ${xt(c)}`}),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(Hi,{accounts:t,projects:r,value:c,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((p,v)=>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(v,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:p.name}),n("div",{class:"mono truncate",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:[p.repo," · ",p.installs," installs"]})]}),n(I,{label:s===p.slug?"Installing…":"Install",variant:"secondary",size:"sm",loading:s===p.slug,disabled:!or(c),onClick:()=>h(p)})]},p.slug))]})]})},Ss=({accounts:e,projects:t,onCreated:r,onCreateWithAI:o})=>{const[i,a]=w(()=>Ui(e)),[s,l]=w(""),[c,d]=w(""),[h,p]=w(!1),{scope:v,scopeRef:b}=i,m=async()=>{if(!s.trim())return;p(!0);const y=`---
|
|
21
|
+
name: ${s.trim()}
|
|
22
|
+
description: ${c.trim()}
|
|
23
|
+
domain: general
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
# ${s.trim()}
|
|
27
|
+
|
|
28
|
+
${c.trim()}
|
|
29
|
+
`;try{const g=await(await fetch("/api/skills",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scope:v,scopeRef:b,name:s.trim(),content:y})})).json();g.ok?(P("Skill created","success"),r()):P(g.error??"Failed to create skill","error")}catch{P("Failed to create skill","error")}finally{p(!1)}};return n(K,{children:[n(Oe,{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(Hi,{accounts:e,projects:Object.keys(t),value:i,onChange:a}),n(te,{label:"Name",children:n("input",{class:"field",value:s,placeholder:"my-skill",onInput:y=>l(y.target.value)})}),n(te,{label:"Description",children:n("textarea",{class:"field",rows:3,value:c,placeholder:"What does this skill do?",onInput:y=>d(y.target.value)})}),n("div",{class:"flex flex-wrap",style:{gap:"8px"},children:[n(I,{label:h?"Creating…":"Create",variant:"primary",loading:h,disabled:!s.trim()||!or(i),onClick:m}),o&&n(I,{label:"Create with AI",variant:"secondary",disabled:!c.trim()||!or(i),title:"Starts a session that drafts the skill",onClick:()=>o(v,b,c.trim())})]})]})})]})},$s=({accounts:e,projects:t,onCreateWithAI:r,onRunSkill:o,onProposeSkill:i})=>{const[a,s]=w(""),[l,c]=w({kind:"empty"}),[d,h]=w(ht.value===null),p=Object.keys(t),v=Y(async()=>{try{await Promise.all([Qo(),wr()])}catch{P("Failed to load skills","error")}finally{h(!1)}},[]);D(()=>{(ht.value===null||dn.value===null)&&v()},[v]);const b=ht.value??[],m=a.trim().toLowerCase(),y=m?b.filter(f=>f.name.toLowerCase().includes(m)||f.description.toLowerCase().includes(m)):b,u=dn.value??[],g=l.kind==="plugin"||l.kind==="propose"?u.find(f=>f.id===l.id):void 0;D(()=>{l.kind==="empty"&&b.length>0&&c({kind:"editor",skill:b[0]})},[b.length]);const k=l.kind==="editor"?Ft(l.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(_r,{}),n("h1",{style:{fontSize:"18px",fontWeight:700,letterSpacing:"-0.02em"},children:"Skills"}),n("span",{class:"mono",style:{fontSize:"11px",color:"var(--ink-3)"},children:b.length}),n("span",{class:"flex-1"}),n(I,{label:"New",variant:"primary",size:"sm",onClick:()=>c({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:f=>s(f.target.value),onKeyDown:f=>{f.key==="Enter"&&a.trim()&&c({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&&y.length===0&&u.length===0&&n("p",{style:{padding:"12px",fontSize:"12.5px",color:"var(--ink-2)"},children:m?"No installed skill matches.":"No skills yet."}),y.map(f=>{const C=k===Ft(f);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:()=>c({kind:"editor",skill:f}),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(${xs[f.scope]})`}}),n("span",{class:"flex-1 min-w-0 truncate",style:{fontSize:"13px",fontWeight:600},children:f.name}),n("span",{class:"truncate",style:{fontSize:"11px",color:"var(--ink-3)",maxWidth:"90px"},children:f.scope==="global"?"global":f.scopeRef})]}),f.description&&n("span",{class:"block truncate",style:{fontSize:"12px",color:"var(--ink-2)",marginTop:"2px"},children:f.description})]},Ft(f))}),n(ds,{list:u,query:m,selected:l.kind==="plugin"||l.kind==="propose"?l.id:null,onSelect:f=>c({kind:"plugin",id:f})}),!m&&n("button",{type:"button","aria-current":l.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:()=>c({kind:"plugins"}),children:[n("span",{class:"i-lucide-plus shrink-0",style:{width:"13px",height:"13px"}}),n("span",{class:"truncate",children:"Add a plugin"})]}),m&&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:()=>c({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:[l.kind==="editor"&&n(_s,{skill:l.skill,accounts:e,projects:p,onCopied:()=>{v()},onRun:()=>o(l.skill),onDeleted:()=>{c({kind:"empty"}),v()}},Ft(l.skill)),l.kind==="create"&&n(Ss,{accounts:e,projects:t,onCreateWithAI:r,onCreated:()=>{c({kind:"empty"}),v()}}),l.kind==="explore"&&n(ws,{query:l.query,accounts:e,projects:p,onInstalled:()=>{v()}}),l.kind==="plugins"&&n(vs,{accounts:e}),l.kind==="plugin"&&g&&!l.skill&&n(fs,{plugin:g,accounts:e,query:m,onSelectSkill:f=>c({kind:"plugin",id:g.id,skill:f}),onPropose:()=>c({kind:"propose",id:g.id})}),l.kind==="plugin"&&g&&l.skill&&n(hs,{plugin:g,name:l.skill,onBack:()=>c({kind:"plugin",id:g.id})},l.skill),l.kind==="propose"&&g&&n(gs,{plugin:g,accounts:e,onCancel:()=>c({kind:"plugin",id:g.id}),onSubmit:async(f,C,x)=>{await i(g,f,C,x)&&c({kind:"plugin",id:g.id})}}),l.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(I,{label:"New skill",variant:"primary",onClick:()=>c({kind:"create"})})]})})]})]})};const In={auto:"qa:auto",escalated:"qa:needs-human",blocked:"qa:blocked"},so="<!-- qa-pilot:decision",Cs="-->",zs=["auto","escalate","blocked"],Ts=["pass","fail","warn"],Rs=["journey","file","severity","artifact"],je=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),ue=e=>typeof e=="string",mt=e=>typeof e=="number"&&Number.isFinite(e);function Ps(e){return je(e)&&ue(e.id)&&ue(e.reason)}function js(e){return!je(e)||!ue(e.check)||!ue(e.kind)||!ue(e.message)?!1:Rs.every(t=>e[t]===void 0||ue(e[t]))}function As(e){if(!je(e)||e.version!==1||!ue(e.decision)||!zs.includes(e.decision)||!ue(e.sha)||!Array.isArray(e.gates)||!e.gates.every(Ps))return!1;const t=e.diff;return!je(t)||!mt(t.files)||!mt(t.added)||!mt(t.removed)||!je(e.checks)||!Object.values(e.checks).every(r=>ue(r)&&Ts.includes(r))?!1:Array.isArray(e.findings)&&e.findings.every(js)}function Es(e){const t=e.lastIndexOf(so);if(t===-1)return null;const r=t+so.length,o=e.indexOf(Cs,r);if(o===-1)return null;try{const i=JSON.parse(e.slice(r,o));return As(i)?i:null}catch{return null}}const Ls=["github-actions[bot]","github-actions"];function Ns(e){var r;const t=(r=e.author)==null?void 0:r.login;return typeof t=="string"&&Ls.includes(t)}function Is(e){for(let t=e.length-1;t>=0;t--){if(!Ns(e[t]))continue;const r=Es(e[t].body);if(r)return r}return null}function Os(e){const t={total:e.length,auto:0,escalated:0,blocked:0};for(const r of e){const o=new Set((r.labels??[]).map(i=>i.name));o.has(In.auto)&&t.auto++,o.has(In.escalated)&&t.escalated++,o.has(In.blocked)&&t.blocked++}return t}function Ws(e,t){return e.sha!==t}const Ds=/^https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/raw\/([0-9a-f]{40})\/(pr-\d+\/[0-9a-f]{7}\/)$/,Fs=/^artifacts\/[A-Za-z0-9._-]+\.png$/;function Ms(e){const t=e.change;if(!je(t)||!mt(t.pixels)||!mt(t.percent)||!ue(t.zone))return;const r=`${t.percent<.1?"menos de 0,1 %":`${String(t.percent).replace(".",",")} %`} de la captura`;return`${Array.isArray(e.elements)&&e.elements.every(ue)&&e.elements.length?`${e.elements.join(", ")} · `:""}${r} · ${t.zone}`}function Bs(e){const t=Ds.exec(e.evidence??"");if(!t)return[];const[,r,o]=t,i=s=>ue(s)&&Fs.test(s)?{ref:r,path:o+s}:void 0,a=[];for(const s of e.findings)if(Array.isArray(s.images))for(const l of s.images){if(!je(l)||!ue(l.name))continue;const c={name:l.name};s.journey&&(c.journey=s.journey),ue(l.ai)&&l.ai&&(c.ai=l.ai.slice(0,200));const d=Ms(l);d&&(c.summary=d);const h=i(l.expected),p=i(l.marked)??i(l.actual),v=i(l.diff);h&&(c.before=h),p&&(c.after=p),v&&(c.diff=v),(h||p||v)&&a.push(c)}return a}function ir(e){const t=pn(e);if(!t.ok)return t;const r=t.data;try{return{ok:!0,data:JSON.parse(r)}}catch{return{ok:!1,message:r||"gh no devolvió JSON"}}}function pn(e){if("error"in e)return{ok:!1,message:e.error};const t=e.output.trim();return e.timedOut?{ok:!1,message:"gh no respondió a tiempo"}:e.exitCode!==0?{ok:!1,message:t||`gh terminó con código ${e.exitCode}`}:{ok:!0,data:t}}function Us(e,t=Date.now()){const r=Date.parse(e);if(Number.isNaN(r))return"";const o=Math.floor((t-r)/6e4);if(o<1)return"ahora";if(o<60)return`hace ${o} min`;const i=Math.floor(o/60);return i<24?`hace ${i} h`:`hace ${Math.floor(i/24)} d`}const Hs={pass:"✓",fail:"✗",warn:"!"};function Ks(e){return Hs[e]}const qs=/^iVBORw0KGgo[A-Za-z0-9+/]*={0,2}$/;function Gs(e){const t=pn(e);if(!t.ok){const r=t.message.split(`
|
|
30
|
+
`).find(o=>/HTTP \d{3}|gh: /.test(o));return{ok:!1,message:(r==null?void 0:r.trim())??t.message.split(`
|
|
31
|
+
`)[0]}}return qs.test(t.data)?{ok:!0,data:`data:image/png;base64,${t.data}`}:{ok:!1,message:"la imagen no es un PNG"}}const Rt=(e,t=16)=>`color-mix(in srgb, var(${e}) ${t}%, transparent)`,xe={background:"var(--card)",border:"1px solid var(--hair)",borderRadius:"12px"},Vs={pass:"--green",fail:"--red",warn:"--orange"};function Js(e,t,r){return Y(async(o,i)=>{try{return await(await fetch(`/api/actions/${e}/${o}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectId:t,...r?{cwProject:r}:{},params:i})})).json()}catch(a){return{error:a instanceof Error?a.message:"Forge no respondió"}}},[e,t,r])}function qi({message:e,onRetry:t}){return n("div",{style:{...xe,padding:"18px 20px",borderColor:Rt("--red",50)},children:[n("h3",{style:{fontSize:"15px",fontWeight:700,marginBottom:"6px"},children:"No se pudo leer GitHub"}),n("p",{style:{fontSize:"13px",color:"var(--ink-2)",marginBottom:"10px"},children:["Ejecuta ",n("code",{style:{fontFamily:"var(--mono)"},children:"gh auth login"})," en una terminal y comprueba que el proyecto es un repositorio de GitHub."]}),n("pre",{style:{fontFamily:"var(--mono)",fontSize:"11.5px",color:"var(--ink-3)",whiteSpace:"pre-wrap",marginBottom:"12px"},children:e}),n(I,{label:"Reintentar",variant:"secondary",size:"sm",onClick:t})]})}function Ys({stats:e}){const t=o=>e.state==="ok"?String(o(e.data)):"–",r=[{label:"PRs esta semana",value:t(o=>o.total),tone:"--ink"},{label:"Aprobados solos",value:t(o=>o.auto),tone:"--green"},{label:"Escalados",value:t(o=>o.escalated),tone:"--orange"},{label:"Bloqueados",value:t(o=>o.blocked),tone:"--red"}];return n("div",{class:"grid gap-2.5 mb-3.5",style:{gridTemplateColumns:"repeat(auto-fit, minmax(140px, 1fr))"},children:r.map(o=>n("div",{style:{...xe,borderRadius:"10px",padding:"10px 12px",minWidth:0},children:[n("span",{style:{fontSize:"11.5px",color:"var(--ink-2)"},children:o.label}),n("b",{style:{display:"block",fontSize:"20px",fontVariantNumeric:"tabular-nums",color:`var(${o.tone})`},children:o.value})]},o.label))})}function co({label:e,tone:t}){return n("span",{style:{fontSize:"11.5px",borderRadius:"6px",padding:"3px 8px",border:`1px solid ${t?`var(${t})`:"var(--hair)"}`,color:t?`var(${t})`:"var(--ink)",background:t?Rt(t):"var(--elev)"},children:e})}function Qs({decision:e}){return n(K,{children:[n("div",{class:"flex flex-wrap gap-1.5",children:[e.gates.map(t=>n(co,{label:`${t.id} · ${t.reason}`,tone:"--orange"},t.id+t.reason)),Object.entries(e.checks).map(([t,r])=>n(co,{label:`${t} ${Ks(r)}`,tone:r==="pass"?void 0:Vs[r]},t))]}),e.findings.length>0&&n("div",{children:[n("div",{style:{fontSize:"12px",fontWeight:600,color:"var(--ink-2)",marginBottom:"6px"},children:"Hallazgos"}),n("ul",{class:"flex flex-col gap-1.5",style:{listStyle:"none",padding:0,margin:0},children:e.findings.map((t,r)=>n("li",{style:{...xe,borderRadius:"8px",padding:"8px 10px",fontSize:"12.5px"},children:[n("div",{class:"flex flex-wrap gap-1.5 mb-1",style:{fontSize:"11px",color:"var(--ink-3)"},children:[n("span",{children:t.check}),n("span",{children:["· ",t.kind]}),t.journey&&n("span",{children:["· ",t.journey]}),t.severity&&n("span",{children:["· ",t.severity]})]}),n("div",{children:t.message}),(t.file||t.artifact)&&n("code",{style:{fontFamily:"var(--mono)",fontSize:"11px",color:"var(--ink-2)"},children:t.file??t.artifact})]},r))})]})]})}function On({file:e,label:t,run:r,onOpen:o}){const[i,a]=w({state:"loading"});D(()=>{if(!e)return;let l=!0;return a({state:"loading"}),r("get-evidence",{REF:e.ref,PATH:e.path}).then(c=>{const d=Gs(c);l&&a(d.ok?{state:"ok",data:d.data}:{state:"error",message:d.message})}),()=>{l=!1}},[e==null?void 0:e.ref,e==null?void 0:e.path,r]);const s={...xe,borderRadius:"8px",overflow:"hidden",aspectRatio:"4 / 3",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--elev)"};return n("figure",{style:{margin:0,minWidth:0},children:[n("figcaption",{style:{fontSize:"11.5px",color:"var(--ink-2)",marginBottom:"4px"},children:t}),e?i.state==="loading"?n("div",{style:s,class:"animate-pulse"}):i.state==="error"?n("div",{style:{...s,fontSize:"11.5px",color:"var(--ink-3)",padding:"8px",textAlign:"center"},children:i.message}):n("button",{type:"button",onClick:()=>o(i.data,t),class:"cursor-zoom-in",style:{...s,padding:0},title:"Ver en grande",children:n("img",{src:i.data,alt:t,style:{width:"100%",height:"100%",objectFit:"contain"}})}):n("div",{style:{...s,fontSize:"12px",color:"var(--ink-3)"},children:"—"})]})}function Zs({changes:e,run:t}){const[r,o]=w(null);D(()=>{if(!r)return;const a=s=>{s.key==="Escape"&&o(null)};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[r]);const i=(a,s)=>o({src:a,label:s});return n("div",{children:[n("div",{style:{fontSize:"12px",fontWeight:600,color:"var(--ink-2)",marginBottom:"6px"},children:"Cambios visuales"}),n("ul",{class:"flex flex-col gap-2.5",style:{listStyle:"none",padding:0,margin:0},children:e.map(a=>n("li",{style:{...xe,borderRadius:"10px",padding:"10px 12px"},children:[n("div",{style:{fontSize:"12.5px",fontWeight:600},children:[a.name,a.journey?` · ${a.journey}`:""]}),a.ai&&n("p",{style:{fontSize:"13px",margin:"4px 0 0"},children:[a.ai," ",n("span",{title:"Descripción hecha por Claude mirando Antes y Después; puede equivocarse",style:{fontSize:"10.5px",padding:"1px 5px",borderRadius:"4px",background:Rt("--purple"),color:"var(--purple)"},children:"IA"})]}),a.summary&&n("p",{style:{fontSize:"12px",color:"var(--ink-2)",margin:"3px 0 0"},children:["Cambió: ",a.summary]}),n("div",{class:"grid gap-2 mt-2",style:{gridTemplateColumns:"repeat(3, minmax(0, 1fr))"},children:[n(On,{file:a.before,label:"Antes",run:t,onOpen:i}),n(On,{file:a.after,label:"Después",run:t,onOpen:i}),n(On,{file:a.diff,label:"Diferencia",run:t,onOpen:i})]})]},a.name))}),n("p",{style:{fontSize:"11.5px",color:"var(--ink-3)",marginTop:"6px"},children:"El recuadro rojo en Después marca la zona que cambió. En Diferencia, lo rojo son los píxeles distintos y lo amarillo, bordes suavizados que no cuentan."}),r&&n("div",{role:"dialog","aria-label":r.label,onClick:()=>o(null),class:"cursor-zoom-out",style:{position:"fixed",inset:0,zIndex:50,background:"color-mix(in srgb, black 70%, transparent)",display:"flex",alignItems:"center",justifyContent:"center",padding:"24px"},children:n("img",{src:r.src,alt:r.label,style:{maxWidth:"100%",maxHeight:"100%",borderRadius:"8px",background:"white"}})})]})}function Xs({pr:e,run:t,onDone:r}){var C;const[o,i]=w({state:"loading"}),[a,s]=w(!1),[l,c]=w(""),[d,h]=w("Esperando tu decisión."),p=Y(async()=>{i({state:"loading"});const x=ir(await t("get-decision",{PR:String(e.number)}));i(x.ok?{state:"ok",data:x.data}:{state:"error",message:x.message})},[e.number,t]);if(D(()=>{s(!1),c(""),h("Esperando tu decisión."),p()},[p]),o.state==="loading")return n("div",{style:{...xe,height:"220px"},class:"animate-pulse"});if(o.state==="error")return n(qi,{message:o.message,onRetry:p});const v=o.data,b=Is(v.comments),m=b?Ws(b,v.headRefOid):!1,y=b!==null&&b.decision==="escalate"&&!m,u=b?Bs(b):[],g=(b==null?void 0:b.diff)??{files:v.changedFiles,added:v.additions,removed:v.deletions},k=async()=>{const x=pn(await t("approve",{PR:String(e.number)}));h(x.ok?"Aprobado: qa-pilot pone el status en verde y activa el auto-merge.":`No se pudo aprobar: ${x.message}`),x.ok&&r()},f=async()=>{const x=pn(await t("request-changes",{PR:String(e.number),MSG:l.trim()}));x.ok?(h("Comentario publicado en el PR."),s(!1),c("")):h(x.message.startsWith("Param MSG")?"El mensaje admite letras, números, espacios y puntuación básica, en una línea y sin < > $ ` \\ [ ].":`No se pudo comentar: ${x.message}`)};return n("div",{class:"flex flex-col gap-3.5",style:{...xe,padding:"16px 18px",minWidth:0},children:[n("div",{children:[n("h3",{style:{fontSize:"15px",fontWeight:700,letterSpacing:"-0.01em"},children:["#",v.number," · ",v.title]}),n("div",{style:{fontSize:"12px",color:"var(--ink-2)",marginTop:"2px"},children:[(C=v.author)!=null&&C.login?`abierto por ${v.author.login} en `:"rama ",n("code",{style:{fontFamily:"var(--mono)"},children:v.headRefName}),` · ${g.files} archivos, +${g.added} −${g.removed}`]})]}),b===null?n("p",{style:{fontSize:"13px",color:"var(--ink-2)"},children:"Este PR no tiene un comentario de decisión de qa-pilot legible. Revisa el workflow antes de aprobar."}):n(K,{children:[m&&n("p",{style:{fontSize:"12.5px",padding:"8px 10px",borderRadius:"8px",background:Rt("--orange"),color:"var(--orange)"},children:["La decisión es del commit ",n("code",{children:b.sha.slice(0,7)})," y el PR ya está en ",n("code",{children:v.headRefOid.slice(0,7)}),". Espera la nueva corrida."]}),n(Qs,{decision:b}),u.length>0&&n(Zs,{changes:u,run:t})]}),a&&n("div",{class:"flex flex-col gap-2",children:[n("textarea",{value:l,maxLength:500,rows:3,placeholder:"Qué debe cambiar (una línea, sin < > $ ni comillas invertidas)",onInput:x=>c(x.target.value.replace(/\s*\n\s*/g," ")),style:{...xe,borderRadius:"8px",padding:"8px 10px",fontSize:"13px",color:"var(--ink)",fontFamily:"var(--font)",resize:"vertical"}}),n("div",{class:"flex gap-2",children:[n(I,{label:"Enviar comentario",size:"sm",disabled:l.trim()==="",onClick:f}),n(I,{label:"Cancelar",variant:"secondary",size:"sm",onClick:()=>s(!1)})]})]}),n("div",{class:"flex flex-wrap gap-2",children:[!a&&n(I,{label:"Pedir cambios",variant:"secondary",icon:"i-lucide-message-square",onClick:()=>s(!0)}),n(I,{label:"Aprobar",icon:"i-lucide-check",disabled:!y,title:y?"Añade qa:approved al PR":"Solo se aprueba una decisión escalada y vigente",onClick:k}),n("a",{href:v.url,target:"_blank",rel:"noreferrer",class:"inline-flex items-center gap-1.5",style:{...xe,borderRadius:"9px",padding:"7px 13px",fontSize:"13px",color:"var(--ink)",textDecoration:"none"},children:[n("span",{class:"i-lucide-external-link"})," Abrir PR"]})]}),n("p",{style:{fontSize:"12px",color:"var(--ink-3)"},"aria-live":"polite",children:d})]})}function ec({moduleId:e,projectId:t,cwProject:r}){const o=Js(e,t,r),i=!!(t||r),[a,s]=w({state:"loading"}),[l,c]=w({state:"loading"}),[d,h]=w(null),p=Y(async()=>{s({state:"loading"});const[b,m]=await Promise.all([o("list-escalations").then(y=>ir(y)),o("week-stats").then(y=>ir(y))]);s(b.ok?{state:"ok",data:b.data}:{state:"error",message:b.message}),c(m.ok?{state:"ok",data:Os(m.data)}:{state:"error",message:m.message}),b.ok&&h(y=>{var u;return b.data.some(g=>g.number===y)?y:((u=b.data[0])==null?void 0:u.number)??null})},[o]);if(D(()=>{i&&p()},[i,p]),!i)return n(qe,{icon:"i-lucide-folder-search",title:"Elige un proyecto",description:"Los escalamientos se leen del repositorio de GitHub del proyecto."});const v=a.state==="ok"?a.data.find(b=>b.number===d):void 0;return n("div",{children:[n("div",{class:"flex items-center justify-between mb-3.5",children:[n("h2",{style:{fontSize:"15px",fontWeight:700},children:"Escalamientos"}),n(I,{label:"Actualizar",variant:"secondary",size:"sm",icon:"i-lucide-refresh-cw",loading:a.state==="loading",onClick:p})]}),n(Ys,{stats:l}),a.state==="loading"?n("div",{style:{...xe,height:"160px"},class:"animate-pulse"}):a.state==="error"?n(qi,{message:a.message,onRetry:p}):a.data.length===0?n(qe,{icon:"i-lucide-inbox",title:"Nada te necesita",description:"No hay PRs abiertos con qa:needs-human. Lo que pasó los checks y las reglas se aprobó solo."}):n("div",{class:"grid gap-3.5",style:{gridTemplateColumns:"repeat(auto-fit, minmax(min(100%, 260px), 1fr))",alignItems:"start"},children:[n("div",{class:"flex flex-col gap-2",role:"listbox","aria-label":"PRs escalados",children:a.data.map(b=>{var m;return n("button",{type:"button",role:"option","aria-selected":b.number===d,onClick:()=>h(b.number),class:"text-left cursor-pointer",style:{...xe,borderRadius:"10px",padding:"10px 12px",color:"var(--ink)",borderColor:b.number===d?"var(--blue)":"var(--hair)",background:b.number===d?Rt("--blue",10):"var(--card)"},children:[n("div",{class:"flex justify-between gap-2",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:[n("span",{children:["#",b.number," · ",Us(b.updatedAt)]}),((m=b.author)==null?void 0:m.login)&&n("span",{children:b.author.login})]}),n("b",{style:{display:"block",fontSize:"13px",marginTop:"2px"},children:b.title})]},b.number)})}),v&&n(Xs,{pr:v,run:o,onDone:p},v.number)]})]})}const tc={id:"escalations",title:"Escalamientos",component:ec},Gi="forge.qa.project",nc="mod-qa";function po(){try{return localStorage.getItem(Gi)??""}catch{return""}}const rc=({projects:e,preferred:t})=>{const r=Object.keys(e).sort(),o=c=>r.includes(c)?c:r[0]??"",[i,a]=w(()=>o(t||po()));D(()=>{r.includes(i)||a(o(t||po()))},[r.join(`
|
|
32
|
+
`),t]);const s=c=>{a(c);try{localStorage.setItem(Gi,c)}catch{}},l=tc.component;return n("div",{class:"flex flex-col min-h-full",children:[n(Tt,{title:"QA",subtitle:"PRs que qa-pilot escaló a una persona, con la evidencia para decidir",children:r.length>0&&n("label",{class:"inline-flex items-center gap-2",style:{fontSize:"12.5px",color:"var(--ink-2)"},children:["Proyecto",n("select",{class:"field",value:i,onChange:c=>s(c.target.value),style:{minWidth:"160px"},children:r.map(c=>n("option",{value:c,children:c},c))})]})}),n("div",{style:{padding:"18px 22px",maxWidth:"1180px",width:"100%"},children:r.length===0?n(qe,{icon:"i-lucide-folder-search",title:"No hay proyectos",description:"Agrega un proyecto de CW para ver sus PRs escalados."}):n(l,{moduleId:nc,projectId:null,cwProject:i},i)})]})},Mt=e=>e.target.value,oc=({accounts:e,onOpenSession:t,onFramesChanged:r})=>{const[o,i]=w(null),[a,s]=w(null),[l,c]=w(""),[d,h]=w(""),[p,v]=w(""),[b,m]=w(null),[y,u]=w(""),g=Y(async()=>{try{const S=await(await fetch("/api/liveframe/frames")).json();s(S),r(S.length)}catch{s([])}},[r]);D(()=>{g(),fetch("/api/liveframe/status").then(S=>S.json()).then(i).catch(()=>{})},[g]);const k=async S=>{if(o)try{const T=await Me("/api/cw/start",{type:"general",account:o.account,directory:S.dir,task:`Liveframe: ${S.project}/${S.frame}`});t(T.session)}catch(T){P(vt(T),"error")}},f=async(S,T)=>{try{const $=await S;return P(T,"success"),g(),await k($),!0}catch($){return P(vt($),"error"),!1}},C=async()=>{await f(Me("/api/liveframe/frames",{project:l,name:d}),`Frame "${d}" created`)&&h("")},x=async()=>{await f(Me("/api/liveframe/pull",{target:p}),`Pulled ${p}`)&&v("")},j=async()=>{if(b)try{const{url:S}=await Me(`/api/liveframe/frames/${b.project}/${b.frame}/push`,{note:y});P(`Published: ${S}`,"success"),m(null)}catch(S){P(vt(S),"error")}},R=o!==null&&!e.includes(o.account),E=(o==null?void 0:o.installed)!==!1&&!R,L=(a??[]).reduce((S,T)=>{var $;return(S[$=T.project]??(S[$]=[])).push(T),S},{});return n(K,{children:[n(Tt,{title:"Prototypes",subtitle:o?`Liveframe frames in ${o.root} · agents run on ${o.account}`:"Liveframe frames",children:[o&&n("a",{class:Ye,style:Ne,href:o.api,target:"_blank",rel:"noopener noreferrer",children:["Liveframe gallery ",n("span",{class:"i-lucide-external-link",style:{width:"12px",height:"12px"}})]}),n(I,{label:"Refresh",variant:"secondary",onClick:g})]}),n("div",{class:"flex flex-col w-full",style:{padding:"18px 22px 40px",gap:"14px",maxWidth:"1180px"},children:[o&&!o.installed&&n("p",{style:{...Re,background:ae("--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"}),"."]}),R&&n("p",{style:{...Re,background:ae("--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:{...Re,background:ae("--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:{...Be,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(te,{label:"Liveframe project · created if missing",children:n("input",{type:"text",class:"field",value:l,placeholder:"Reservas",onInput:S=>c(Mt(S))})}),n(te,{label:"Frame name",children:n("input",{type:"text",class:"field",value:d,placeholder:"Checkout ideas",onInput:S=>h(Mt(S))})}),n("div",{class:"flex justify-end",children:n(I,{label:"Create and open agent",variant:"primary",size:"sm",disabled:!E||!l.trim()||!d.trim(),onClick:C})})]}),n("div",{class:"flex flex-col",style:{...Be,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(te,{label:"project/frame",children:n("input",{type:"text",class:"field",value:p,placeholder:"reservas/checkout-flow",onInput:S=>v(Mt(S))})}),n("div",{class:"flex justify-end",children:n(I,{label:"Pull and open agent",variant:"secondary",size:"sm",disabled:!E||!p.includes("/"),onClick:x})})]})]}),a&&a.length===0&&n(qe,{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(L).map(([S,T])=>n("section",{style:{...Be,overflow:"hidden"},children:[n("h2",{style:{padding:"12px 18px",fontSize:"13px",fontWeight:600,borderBottom:"1px solid var(--hair)"},children:S}),T.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:Ye,style:Ne,href:$.url,target:"_blank",rel:"noopener noreferrer",children:["Live ",n("span",{class:"i-lucide-external-link",style:{width:"12px",height:"12px"}})]}),n(I,{label:"Push",variant:"secondary",size:"sm",disabled:!E,onClick:()=>{u(""),m($)}}),n(I,{label:"Open agent",variant:"primary",size:"sm",disabled:!o||R,onClick:()=>k($)})]},$.dir))]},S))]}),n(hr,{open:b!==null,title:`Push ${b==null?void 0:b.project}/${b==null?void 0:b.frame}`,onClose:()=>m(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(te,{label:"What changed · optional",children:n("input",{type:"text",class:"field",value:y,placeholder:"wallet-first layout",onInput:S=>u(Mt(S))})}),n("div",{class:"flex justify-end pt-1",children:n(I,{label:"Push",variant:"primary",onClick:j})})]})})]})},ic=[{label:"Personal",tiers:["personal"]},{label:"Projects",tiers:["project","client"]},{label:"Team",tiers:["team"]}],ac={save:"--green",update:"--blue",supersede:"--blue",evolve:"--purple",link:"--teal",confirm:"--green",retire:"--red",forget:"--red"},lc=({brain:e})=>{const t=Object.entries(e.kinds).filter(([,r])=>r>0).sort((r,o)=>o[1]-r[1]);return n(K,{children:[n("div",{class:"flex overflow-hidden",style:{height:"6px",borderRadius:"99px",background:"var(--elev)"},children:t.map(([r,o])=>n("span",{title:`${r} ${o}`,style:{width:`${o/e.pages*100}%`,background:`var(${Ur(r)})`}},r))}),n("div",{class:"flex flex-wrap",style:{gap:"3px 10px",fontSize:"11px",color:"var(--ink-2)"},children:t.slice(0,3).map(([r,o])=>n("span",{class:"inline-flex items-center",style:{gap:"4px"},children:[n($e,{color:`var(${Ur(r)})`}),r," ",o]},r))})]})},uo=({brain:e,usedBy:t,showTier:r})=>{const o=Ge(e.tier);return n("div",{class:"flex flex-col min-w-0",style:{...Be,gap:"9px",padding:"14px 16px",borderTop:`3px solid var(${o})`},children:[n("div",{class:"flex items-center",style:{gap:"8px"},children:[r&&n("span",{style:{fontSize:"10.5px",fontWeight:700,letterSpacing:".04em",textTransform:"uppercase",color:`var(${o})`},children:e.tier}),n("span",{class:"truncate",style:{fontSize:"14.5px",fontWeight:600},title:e.folder,children:Le(e)}),n("span",{class:"flex-1"}),n("span",{style:{fontSize:"11.5px",color:"var(--ink-3)"},children:e.onDisk?e.touched?vn(e.touched):"quiet":"not on disk"})]}),n("div",{style:{fontSize:"26px",fontWeight:700,lineHeight:1},children:[e.pages," ",n("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--ink-3)"},children:"pages"})]}),e.pages>0&&n(lc,{brain:e}),t&&n("div",{class:"flex flex-wrap",style:{gap:"4px"},children:e.tier==="personal"?n("span",{style:{fontSize:"11.5px",color:"var(--ink-3)"},children:"loads in every session"}):t.length===0?n("span",{style:{fontSize:"11.5px",color:"var(--ink-3)"},children:"no CW project loads it"}):t.map(i=>n(Do,{label:i,variant:"neutral"},i))})]})},sc=({writes:e})=>n("section",{style:{...Be,overflow:"hidden"},children:[n("h2",{style:{padding:"12px 16px 6px",fontSize:"11px",fontWeight:600,letterSpacing:".02em",color:"var(--ink-3)"},children:"RECENT ACTIVITY · LAST 2 WEEKS"}),e.length===0&&n("p",{style:{padding:"4px 16px 14px",fontSize:"12.5px",color:"var(--ink-3)"},children:"Nothing written lately."}),e.map(t=>n("div",{class:"flex items-center",style:{gap:"10px",padding:"9px 16px",borderTop:"1px solid var(--hair)",fontSize:"12.5px"},children:[n("span",{class:"shrink-0 flex justify-center",style:{width:"76px"},children:n(Do,{label:t.verb,color:`var(${ac[t.verb]??"--ink-2"})`})}),n("span",{class:"truncate flex-1",title:t.path,children:t.title}),n("span",{class:"shrink-0",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:[t.brain,t.author?` · ${t.author}`:""," · ",vn(t.date)]})]},`${t.brain}:${t.path}:${t.date}:${t.verb}`))]}),cc=({project:e,onProject:t})=>{const[r,o]=w(!1);D(()=>yi(),[]);const i=Te.value,a=async()=>{const y=window.open("","_blank");o(!0);try{const{address:u}=await Me("/api/kioku/viewer",{});y?y.location.href=u:P(`Viewer running at ${u}`,"info"),gt()}catch(u){y==null||y.close(),P(vt(u),"error")}finally{o(!1)}},s=async()=>{await fetch("/api/kioku/viewer",{method:"DELETE"}).catch(()=>{}),gt()},l=(i==null?void 0:i.brains)??[],c=(i==null?void 0:i.projects)??{},d=Object.keys(c).filter(y=>c[y].some(u=>u.tier!=="personal")).sort();e&&!d.includes(e)&&d.unshift(e);const h=e?bi(e):[],p=y=>Object.keys(c).filter(u=>c[u].some(g=>g.name===Le(y))).sort(),v=new Set(h.map(Le)),b=((i==null?void 0:i.activity)??[]).filter(y=>!e||v.has(y.brain)).slice(0,15),m=i!=null&&i.installed?e?`${e} · ${ln(h)} pages its sessions can recall`:`Kioku ${i.version??""} · ${ln(l)} pages in ${l.length} brain${l.length===1?"":"s"}`:"Kioku brains on this machine";return n(K,{children:[n(Tt,{title:"Memory",subtitle:m,children:[(i==null?void 0:i.viewer)&&n(I,{label:"Stop viewer",variant:"secondary",onClick:s}),n(I,{label:"Refresh",variant:"secondary",onClick:()=>gt(!0)}),n(I,{label:i!=null&&i.viewer?"Viewer open ↗":"Open viewer",variant:"primary",disabled:!(i!=null&&i.installed)||r,onClick:a})]}),n("div",{class:"flex flex-col w-full",style:{padding:"18px 22px 40px",gap:"14px",maxWidth:"1180px"},children:[i&&!i.installed&&n("p",{style:{...Re,background:ae("--red")},children:["Kioku is not installed. Install it from ",n("code",{children:"monoku/kioku"})," with its ",n("code",{children:"install.sh"}),", which puts ",n("code",{children:"kioku"})," in ",n("code",{children:"~/.local/bin"}),"."]}),(i==null?void 0:i.installed)&&l.length===0&&n(qe,{icon:"i-lucide-brain",title:"No brains yet",description:"Create your personal brain with 'kioku brain create <name> --tier personal' in a terminal, or run 'kioku init' in a repository."}),l.length>0&&d.length>0&&n("div",{class:"flex",children:n(he,{size:"sm",label:"Project",tabs:[{id:"",label:"All"},...d.map(y=>({id:y,label:y}))],active:e??"",onChange:y=>t(y||null)})}),l.length>0&&!e&&n("div",{class:"flex flex-wrap",style:{gap:"14px 12px"},children:ic.map(y=>{const u=l.filter(g=>y.tiers.includes(g.tier??""));return u.length===0?null:n("section",{class:"flex flex-col min-w-0",style:{gap:"8px",flex:`${u.length} 1 ${u.length*250}px`},children:[n("h2",{class:"flex items-center",style:{gap:"8px",fontSize:"11px",fontWeight:600,letterSpacing:".03em",color:`var(${Ge(y.tiers[0])})`},children:["● ",y.label.toUpperCase(),u.length>1&&n("span",{style:{color:"var(--ink-3)"},children:u.length})]}),n("div",{class:"grid",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))",gap:"12px"},children:u.map(g=>n(uo,{brain:g,usedBy:p(g)},g.key))})]},y.label)})}),e&&h.length>0&&n("div",{class:"grid items-center",style:{gridTemplateColumns:h.map(()=>"minmax(0, 1fr)").join(" 24px ")},children:h.map((y,u)=>n(K,{children:[u>0&&n("span",{style:{textAlign:"center",color:"var(--ink-3)",fontSize:"16px"},children:"→"}),n(uo,{brain:y,showTier:!0})]},y.key))}),e&&(i==null?void 0:i.installed)&&!h.some(y=>y.tier!=="personal")&&n("p",{style:{...Re,background:"var(--elev)",color:"var(--ink-2)"},children:[e," has no project or team brain. Run ",n("code",{children:"kioku init"})," in its repository to give it one."]}),l.length>0&&n(sc,{writes:b}),(i==null?void 0:i.installed)&&n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:["Open viewer starts ",n("code",{children:"kioku web"}),": the graph of every page, each page with its history, lint and the latest changes. It opens in its own tab and stops with Forge."]})]})]})},ho=({value:e,onChange:t,initialPath:r,requireGit:o=!0})=>{const[i,a]=w(r??"~"),[s,l]=w(i),[c,d]=w([]),[h,p]=w(null),[v,b]=w(null),[m,y]=w(""),[u,g]=w(!1),[k,f]=w(!1),[C,x]=w(null);D(()=>{let W=!1;return(async()=>{f(!0),x(null);try{const U=await(await fetch(`/api/cw/browse-dirs?path=${encodeURIComponent(i)}`)).json();if(W)return;if(!U.ok){x(U.error??"Failed to load directory"),d([]);return}d(U.entries??[]),p(U.parent??null),b(U.home??null),y(U.path??i),g(!!U.isGitRepo)}catch{W||(x("Network error"),d([]))}finally{W||f(!1)}})(),()=>{W=!0}},[i]);const j=W=>{a(W),l(W)},R=e===m,E=o&&!u,L=m?v&&m===v?"~":v&&m.startsWith(v+"/")?"~"+m.slice(v.length):m:i,S={width:"24px",height:"24px",borderRadius:"7px",border:0,background:"var(--card)",color:"var(--ink-2)",boxShadow:"var(--shadow-s)"},T="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:ae("--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&&j(h),disabled:!h||k,title:"Parent folder","aria-label":"Parent folder",children:"←"}),n("button",{type:"button",class:"grid place-items-center cursor-pointer",style:S,onClick:()=>j("~"),title:"Home","aria-label":"Home",children:"~"}),n("input",{type:"text",value:s,"aria-label":"Path",onInput:W=>l(W.target.value),onBlur:()=>a(s),onKeyDown:W=>{W.key==="Enter"&&a(s)},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:ae("--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:k?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(K,{children:[n("button",{type:"button",class:T,style:{...$,background:R?"var(--elev)":"none",fontWeight:600},onClick:()=>t(m,u),disabled:E,title:E?"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:L})]}),u?n("span",{style:N,children:"git"}):E?n("span",{style:{fontSize:"11px",color:"var(--ink-3)"},children:"no .git"}):null]}),c.length===0?n("p",{style:{padding:"12px",fontSize:"12.5px",color:"var(--ink-3)"},children:"No subfolders"}):c.map(W=>n("button",{type:"button",class:T,style:$,onClick:()=>j(W.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:W.name}),W.isGitRepo&&n("span",{style:N,children:"git"})]},W.path))]})})]})},dc=({open:e,accounts:t,onClose:r,onCreated:o})=>{const[i,a]=w("create"),[s,l]=w(""),[c,d]=w(""),[h,p]=w(""),[v,b]=w(""),[m,y]=w(""),[u,g]=w(""),[k,f]=w(!1),[C,x]=w(""),[j,R]=w(!1);D(()=>{e&&t.length>0&&!s&&l(t[0])},[e,t]),D(()=>{e||(a("create"),d(""),p(""),b(""),y(""),g(""),f(!1),x(""),R(!1))},[e]);const E=s.trim().length>0&&c.trim().length>0&&v.trim().length>0,L=s.trim().length>0&&u.length>0&&k,S=async()=>{if(E){R(!0);try{const F=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"create",project:c.trim(),task:c.trim(),description:v.trim(),account:s.trim()||void 0,directory:h.trim()||void 0,model:m||void 0})})).json();F.ok?(P("Project creation started in terminal","success"),o(F.session)):P(F.error??"Failed to create project","error")}catch{P("Failed to create project","error")}finally{R(!1)}}},T=async()=>{if(L){R(!0);try{const F=await(await fetch("/api/cw/register-project",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:u,account:s.trim(),alias:C.trim()||void 0})})).json();F.ok?(P(`Project "${F.project}" registered`,"success"),o()):P(F.error??"Failed to register project","error")}catch{P("Failed to register project","error")}finally{R(!1)}}},$=i==="create";return n(hr,{open:e,title:"Add a project",onClose:r,footer:n(K,{children:[n("span",{class:"mono flex-1 truncate",style:{fontSize:"11.5px",color:"var(--ink-3)"},children:$?"cw create":"cw project register"}),n(I,{label:"Cancel",variant:"secondary",onClick:r}),n(I,{label:$?j?"Creating…":"Create":j?"Registering…":"Register",variant:"primary",loading:j,disabled:!($?E:L),onClick:$?S:T})]}),children:n("div",{class:"flex flex-col",style:{gap:"13px"},children:[n(he,{fill:!0,label:"Mode",tabs:[{id:"create",label:"Create new"},{id:"existing",label:"Register existing"}],active:i,onChange:O=>a(O)}),n("div",{class:"grid",style:{gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:"10px"},children:[n(te,{label:"Account",children:t.length>0?n("select",{class:"field",value:s,onChange:O=>l(O.target.value),children:t.map(O=>n("option",{value:O,children:O},O))}):n("input",{type:"text",class:"field",value:s,placeholder:"account-name",onInput:O=>l(O.target.value)})}),$?n(te,{label:"Project name",children:n("input",{type:"text",class:"field",value:c,placeholder:"my-new-project",onInput:O=>d(O.target.value)})}):n(te,{label:"Alias",children:n("input",{type:"text",class:"field",value:C,placeholder:"defaults to folder name",onInput:O=>x(O.target.value)})})]}),n("div",{class:"flex flex-col",style:{gap:"5px"},children:[n("span",{style:Qe,children:$?"Parent folder · optional":"Repository · must contain .git"}),$?n(ho,{value:h,onChange:p,requireGit:!1},"dir-create"):n(ho,{value:u,onChange:(O,F)=>{g(O),f(F)}},"dir-existing")]}),$&&n(K,{children:[n(te,{label:"Description",children:n("textarea",{rows:2,class:"field",value:v,placeholder:"A SaaS platform for…",onInput:O=>b(O.target.value)})}),n("div",{class:"flex flex-col",style:{gap:"5px"},children:[n("span",{style:Qe,children:"Model"}),n(he,{size:"sm",label:"Model",tabs:[{id:"",label:"Auto"},{id:"haiku",label:"Haiku"},{id:"sonnet",label:"Sonnet"},{id:"opus",label:"Opus"}],active:m,onChange:y})]})]})]})})},pc=(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"}},uc=(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(" · ")},De=({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?ae(e):"var(--elev)",color:e?`var(${e})`:"var(--ink-3)"},children:[n("span",{style:{width:"6px",height:"6px",borderRadius:"50%",background:"currentColor"}}),t]}),hc=({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(De,{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(De,{token:null,label:"Not installed"});case"error":return n(De,{token:"--red",label:"Error"});case"local":return n(De,{token:"--orange",label:"Local"});case"api_key":return n(De,{token:"--green",label:"API key"});case"connected":return n(De,{token:"--green",label:"Connected"});case"connect":return n(I,{label:"Connect",size:"sm",onClick:t})}},Wn=({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})]}),Dn=({warn:e,children:t})=>n("span",{style:{fontSize:"11.5px",color:e?"var(--orange)":"var(--ink-3)"},children:t}),fc=({account:e,harness:t})=>{const r=Ka(e,t);return!r||r.state==="not_connected"?null:r.state==="expired"?n(Wn,{children:n(Dn,{warn:!0,children:"Reconnect to see usage limits"})}):r.state==="error"?n(Wn,{children:n(Dn,{children:["Limits unavailable — ",r.detail??"the request failed"]})}):r.windows.length===0?null:n(Wn,{children:[n(Bo,{bars:Jo(r.windows)}),r.stale&&n(Dn,{children:["Last known values — ",r.detail??"the refresh failed"]})]})},vc=3e3,gc=({account:e,harness:t,canUseApiKey:r,onConnected:o,onClose:i})=>{const[a,s]=w(null),[l,c]=w(!1),[d,h]=w(0),[p,v]=w(""),[b,m]=w(!1),y=ve(t).label,u=`/api/cw/accounts/${encodeURIComponent(e)}`,g=`${u}/login/${encodeURIComponent(t)}`,k=ee(!1),f=ee(!1);D(()=>{let R=!1,E=null;s(null),c(!1),k.current=!1,f.current=!1;const L=()=>{k.current||(k.current=!0,fetch(g,{method:"DELETE"}).catch(()=>{}),P(`${e} is connected to ${y}`,"success"),o())},S=async()=>{var O;const $=await fetch(g).catch(()=>null);if(!($!=null&&$.ok)||R)return;const{login:N}=await $.json();if(s(N),N.status!=="exited"||(f.current=!0,E&&(clearInterval(E),E=null),N.exitCode!==0))return;c(!0);const W=await ye(!0);R||(W.available&&((O=Ae(W.doctor,e,t))==null?void 0:O.status)==="connected"?L():c(!1))};fetch(`${u}/login`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({harness:t})}).then($=>$.json()).then($=>{if(!R){if(!$.ok||!$.login){P($.error??"Could not start the login","error");return}s($.login),E=setInterval(S,vc)}}).catch(()=>P("Could not start the login","error"));const T=sl($=>{var N;return((N=Ae($,e,t))==null?void 0:N.status)==="connected"},{onDone:$=>{$&&L()}});return()=>{R=!0,E&&clearInterval(E),T(),f.current||fetch(g,{method:"DELETE"}).catch(()=>{})}},[e,t,d]);const C=()=>{fetch(g,{method:"DELETE"}).catch(()=>{}),i()},x=async()=>{const R=p.trim();if(R){m(!0);try{const L=await(await fetch(`${u}/api-key`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({harness:t,apiKey:R})})).json();L.ok?(v(""),P("API key saved","success"),ye(!0)):P(L.error??"Could not save the API key","error")}catch{P("Could not save the API key","error")}finally{m(!1)}}},j=(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 ",y]}),n("span",{class:"flex-1"}),n(I,{label:"Cancel",variant:"secondary",size:"sm",onClick:C})]}),!a&&n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:"Starting the login…"}),a&&!j&&n(K,{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(K,{children:[n("span",{class:"mono",style:{fontSize:"19px",fontWeight:650,letterSpacing:".12em"},children:a.code}),n(I,{label:"Copy",variant:"secondary",size:"sm",onClick:()=>yr(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…"})]}),j&&l&&n("p",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:"Checking the connection…"}),j&&!l&&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(I,{label:"Retry",variant:"secondary",size:"sm",onClick:()=>h(R=>R+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(`
|
|
33
|
+
`)})]}),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:p,onInput:R=>v(R.target.value),placeholder:"sk-…",class:"field mono flex-1 min-w-0"}),n(I,{label:"Save",variant:"secondary",size:"sm",loading:b,disabled:!p.trim(),onClick:x})]}),n("p",{style:{fontSize:"12px",color:"var(--ink-3)"},children:"Sent to cw over stdin. Forge never stores or shows it."})]})]})},Bt={display:"block",fontSize:"12px",color:"var(--ink-2)",marginBottom:"5px"},xc=({response:e,onCancel:t,onCreated:r})=>{const[o,i]=w(""),[a,s]=w(""),[l,c]=w(""),[d,h]=w(""),[p,v]=w(!1),b=xn(),m=o.trim(),y=Aa.test(m),u=e!=null&&e.available?e.doctor.harnesses.map(f=>f.name).filter(f=>f!=="claude"):[],g=!!a&&Ue(e,a,"custom_provider"),k=async()=>{if(!(!y||p)){v(!0);try{const C=await(await fetch("/api/cw/accounts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:m,harness:a||void 0,provider:g&&l.trim()||void 0,model:g&&d.trim()||void 0})})).json();C.ok?(P(`Account "${m}" created`,"success"),r()):P(C.error??"Failed to create account","error")}catch{P("Failed to create account","error")}finally{v(!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:Bt,for:"new-account-name",children:"Account name"}),n("input",{id:"new-account-name",type:"text",value:o,onInput:f=>i(f.target.value),onKeyDown:f=>{f.key==="Enter"&&k()},placeholder:"my-account",class:"field",ref:b}),m&&!y&&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."})]}),u.length>0&&n("div",{children:[n("span",{style:Bt,children:"Default harness"}),n(he,{label:"Default harness",tabs:[{id:"",label:"Claude Code"},...u.map(f=>({id:f,label:ve(f).label}))],active:a,onChange:s}),n("p",{style:{fontSize:"12px",color:"var(--ink-3)",marginTop:"5px"},children:"The default harness cannot be changed later."})]}),g&&n("div",{class:"grid",style:{gridTemplateColumns:"1fr 1fr",gap:"10px",maxWidth:"520px"},children:[n("div",{children:[n("label",{style:Bt,children:"Provider · optional"}),n("input",{type:"text",value:l,onInput:f=>c(f.target.value),placeholder:"zai, ollama, openrouter",class:"field"})]}),n("div",{children:[n("label",{style:Bt,children:"Model · optional"}),n("input",{type:"text",value:d,onInput:f=>h(f.target.value),placeholder:"glm-5.1",class:"field"})]})]}),n("div",{class:"flex",style:{gap:"8px"},children:[n(I,{label:p?"Creating…":"Add account",variant:"primary",loading:p,disabled:!y,onClick:k}),n(I,{label:"Cancel",variant:"secondary",onClick:t})]})]})},mc=new Set(["localhost","127.0.0.1","::1","[::1]"]),fo={...Be,overflow:"hidden"},yc=({account:e,onRemoved:t})=>{const[r,o]=w(!1),i=async()=>{try{const s=await(await fetch(`/api/cw/accounts/${encodeURIComponent(e)}`,{method:"DELETE"})).json();s.ok?(P(`Account "${e}" removed`,"info"),t()):P(s.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(I,{label:"Remove account",variant:"destructive",size:"sm",onClick:i}),n(I,{label:"Cancel",variant:"secondary",size:"sm",onClick:()=>o(!1)})]}):n(I,{label:"Remove",variant:"danger",size:"sm",onClick:()=>o(!0)})},bc=({projects:e,onOpenSession:t,onAccountsChanged:r})=>{const[o,i]=w(null),[a,s]=w(!1);D(()=>{ye()},[]),D(()=>oi(),[]);const l=mn.value,c=!mc.has(window.location.hostname),d=l!=null&&l.available?l.doctor:null,h=()=>{o&&(fetch(`/api/cw/accounts/${encodeURIComponent(o.account)}/login/${encodeURIComponent(o.harness)}`,{method:"DELETE"}).catch(()=>{}),i(null))},p=async(u,g)=>{if(Ue(l,g,"headless_login")){i({account:u,harness:g});return}try{const f=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"login",account:u,harness:g})})).json();f.ok&&f.session?t(f.session):P(f.error??"Could not open the login","error")}catch{P("Could not open the login","error")}},v=d?d.accounts.reduce((u,g)=>u+g.harnesses.filter(k=>k.status==="not_logged_in").length,0):0,b=d?`${d.accounts.length} account${d.accounts.length===1?"":"s"} · ${d.harnesses.length} harnesses · ${v} need${v===1?"s":""} connecting`:"Reading cw doctor…",m=u=>Object.values(e).filter(g=>g.account===u).length,y=(u,g)=>{if(!d)return null;const[k,f]=Ko(g),C=m(u.name),x=Ae(d,u.name,u.default_harness),j=[ve(u.default_harness).label,x&&x.provider!=="native"?x.provider:null].filter(Boolean).join(" · ");return n("section",{style:{...fo,animation:`riseIn .36s var(--ease) ${g*90}ms both`},"aria-label":u.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(${k}), var(${f}))`,boxShadow:"var(--shadow-s)",color:"#fff",fontSize:"12px",fontWeight:700},children:u.name.charAt(0).toUpperCase()}),n("span",{style:{fontSize:"15px",fontWeight:650,letterSpacing:"-0.01em"},children:u.name}),n("span",{style:{fontSize:"12.5px",color:"var(--ink-2)"},children:["Default ",j," · ",C," project",C===1?"":"s"]}),n("span",{class:"flex-1"}),n(yc,{account:u.name,onRemoved:()=>{ye(!0),r()}})]}),d.harnesses.map(R=>{const E=Ae(d,u.name,R.name),L=(o==null?void 0:o.account)===u.name&&o.harness===R.name,S=ve(R.name),T=E?pc(E,L):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:E&&T?uc(T,R.version,Ue(l,R.name,"headless_login"),E):"Not configured for this account"}),T&&n(hc,{view:T,onConnect:()=>{p(u.name,R.name)},onCancel:h})]}),E&&n(fc,{account:u.name,harness:R.name}),L&&n("div",{style:{padding:"0 15px 13px"},children:n(gc,{account:u.name,harness:R.name,canUseApiKey:Ue(l,R.name,"api_key_login"),onConnected:()=>i(null),onClose:()=>i(null)},`${u.name}::${R.name}`)})]},R.name)})]},u.name)};return n(K,{children:[n(Tt,{title:"Accounts",subtitle:b,children:[n(I,{label:"Refresh",variant:"secondary",onClick:()=>{ye(!0)}}),n(I,{label:"Add account",variant:"primary",onClick:()=>s(!0)})]}),n("div",{class:"flex flex-col w-full",style:{padding:"18px 22px 40px",gap:"14px",maxWidth:"1180px"},children:[a&&n(xc,{response:l,onCancel:()=>s(!1),onCreated:()=>{s(!1),ye(!0),r()}}),l&&!l.available&&n("section",{style:{...fo,padding:"16px 18px"},children:[n("p",{style:{fontSize:"13.5px",marginBottom:"4px"},children:["Harness status is unavailable: ",l.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(I,{label:"Retry",variant:"secondary",size:"sm",onClick:()=>{ye(!0)}})]}),d&&c&&n("p",{style:{...Re,background:ae("--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(u=>n("p",{style:{...Re,background:ae("--red"),color:"var(--ink)"},children:u.message},u.code)),d&&d.warnings.map(u=>n("p",{style:{...Re,background:"var(--elev)",color:"var(--ink-2)"},children:u.message},u.code)),d==null?void 0:d.accounts.map(y)]})]})},vo="flex items-center w-full text-left cursor-pointer transition-colors duration-140 hover:bg-elev",kc=({sessions:e,openTabKeys:t,onOpenSession:r,onNewTask:o,onClose:i,position:a})=>{const s=ee(null);D(()=>{const c=h=>{s.current&&!s.current.contains(h.target)&&i()},d=h=>{h.key==="Escape"&&i()};return document.addEventListener("mousedown",c),document.addEventListener("keydown",d),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("keydown",d)}},[i]);const l=e.filter(c=>!t.has(q(c)));return n("div",{ref:s,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"}),et.map(c=>n("button",{type:"button",class:vo,style:{gap:"10px",padding:"7px 10px",borderRadius:"10px",border:0,background:"none",color:"var(--ink)",fontSize:"13px"},onClick:()=>{o(c.key),i()},children:[n(Xn,{type:c.sessionType,size:22,radius:7,font:10}),n("span",{class:"flex-1",children:vr(c.key)})]},c.key)),l.length>0&&n(K,{children:[n("div",{style:{padding:"9px 10px 3px",fontSize:"11px",fontWeight:600,color:"var(--ink-3)"},children:"Resume"}),l.map(c=>n("button",{type:"button",class:vo,style:{gap:"10px",padding:"7px 10px",borderRadius:"10px",border:0,background:"none",color:"var(--ink)",fontSize:"13px"},onClick:()=>{r(c),i()},children:[n(Xn,{type:c.type,size:22,radius:7,font:10}),n("span",{class:"flex-1 truncate",children:fe(c)}),n("span",{class:"mono truncate",style:{fontSize:"10.5px",color:"var(--ink-3)",maxWidth:"110px"},children:pe(c)})]},q(c)))]})]})},_c=({tabs:e,activeIndex:t,onActivate:r,onClose:o,onBack:i,allSessions:a,openTabKeys:s,onOpenSession:l,onNewTask:c})=>{const[d,h]=w(!1),p=ee(null),[v,b]=w({top:0,left:0}),m=Y(()=>h(!1),[]),y=()=>{if(!d&&p.current){const u=p.current.getBoundingClientRect();b({top:u.bottom+6,left:Math.max(8,Math.min(u.left,window.innerWidth-328))})}h(!d)};return n(K,{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(_r,{}),n(Kl,{onClick:i}),e.map((u,g)=>{const k=g===t,f=Ee.value[q(u)],C=!k&&Ve(f);return n("div",{role:"tab",tabIndex:0,"aria-selected":k,title:[C?on(f):null,g<5?`⌘${g+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:k?"var(--card)":"transparent",border:`1px solid ${k?"var(--hair)":"transparent"}`,boxShadow:k?"var(--shadow-s)":"none"},onClick:()=>r(g),onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),r(g))},children:[n($e,{size:6,live:u.status==="active",color:C?`var(${qt(f)})`:void 0}),n("span",{style:{fontWeight:600,color:k?"var(--ink)":"var(--ink-2)"},children:fe(u)}),n("span",{class:"mono truncate",style:{fontSize:"11px",color:"var(--ink-3)",maxWidth:"110px"},children:pe(u)}),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:x=>{x.stopPropagation(),o(g)},title:"Close tab (⌘W)","aria-label":`Close ${fe(u)}`,children:n("span",{class:"i-lucide-x",style:{width:"13px",height:"13px"}})})]},q(u))}),n("button",{ref:p,type:"button",class:"grid place-items-center shrink-0 cursor-pointer text-ink2 hover:text-ink",style:{width:"26px",height:"26px",borderRadius:"8px",border:"1px solid var(--hair)",background:"var(--card)"},onClick:y,"aria-expanded":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(kc,{sessions:a,openTabKeys:s,onOpenSession:l,onNewTask:c,onClose:m,position:v})]})};function wc(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?St(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 Sc=({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(hr,{open:!0,title:"Close this task?",onClose:t,footer:n(K,{children:[n("span",{class:"flex-1"}),n(I,{label:"Cancel",variant:"secondary",onClick:t}),n(I,{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(s=>n("li",{children:wc(s,e.state)},s))}),e.error&&n("p",{style:{marginTop:"10px",fontSize:"12.5px",color:"var(--ink-2)"},children:e.error})]})},Fn="forge-open-tabs";function $c({spaces:e,loading:t,onFetchData:r}){const[o,i]=w([]),[a,s]=w(0),[l,c]=w(!0),d=ee(!1),h=ee(o);h.current=o,D(()=>{if(!(t||e.length===0||d.current)){d.current=!0;try{const u=sessionStorage.getItem(Fn);if(!u)return;const{keys:g,activeIndex:k}=JSON.parse(u),f=[];for(const C of g){const x=e.find(j=>q(j)===C);x&&f.push(x)}f.length>0&&(i(f),s(Math.min(k,f.length-1)))}catch{}}},[t,e]),D(()=>{if(d.current)if(o.length>0){const u=o.map(q);sessionStorage.setItem(Fn,JSON.stringify({keys:u,activeIndex:a}))}else sessionStorage.removeItem(Fn)},[o,a]);const p=Y(u=>{const g=q(u),k=o.findIndex(f=>q(f)===g);k>=0?s(k):(i(f=>[...f,u]),s(o.length)),c(!1)},[o]),v=Y(async u=>{const g=h.current.find(x=>q(x)===u);if(!g)return;const k=g.sessionDir??(g.type==="review"?`review-pr-${g.pr}`:`task-${g.task}`);try{await fetch("/api/cw/terminal/kill",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:g.project,sessionDir:k})})}catch{}const f=h.current.findIndex(x=>q(x)===u);if(f<0)return;Ua(u);const C=h.current.length-1;i(x=>x.filter(j=>q(j)!==u)),C===0?(c(!0),s(0),r()):s(x=>x>f?x-1:Math.min(x,C-1))},[r]),b=Y(u=>{const g=o[u];return g?v(q(g)):Promise.resolve()},[o,v]),m=Y(()=>{c(!0),r()},[r]);D(()=>{const u=g=>{if(o.length===0||l)return;const k=g.metaKey||g.ctrlKey;if(k&&g.key>="1"&&g.key<="5"){const f=parseInt(g.key)-1;f<o.length&&(g.preventDefault(),s(f));return}if(k&&(g.key==="ArrowLeft"||g.key==="ArrowRight")){g.preventDefault(),s(f=>g.key==="ArrowLeft"?f>0?f-1:o.length-1:f<o.length-1?f+1:0);return}if(k&&g.key==="w"){g.preventDefault(),b(a);return}k&&g.key==="l"&&(g.preventDefault(),m())};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[o,l,a,b,m]);const y=Z(()=>new Set(o.map(q)),[o]);return{openTabs:o,activeTabIndex:a,setActiveTabIndex:s,showList:l,openTab:p,closeTab:b,closeTabByKey:v,goToList:m,openTabKeys:y}}function Cc({spaces:e,accounts:t,projects:r}){const[o,i]=w(null),[a,s]=w(null),[l,c]=w(null),[d,h]=w(null),[p,v]=w(!1),b=Z(()=>Array.from(new Set(e.map(k=>k.harness??"claude"))).sort(),[e]),m=Z(()=>{if(t.length>0)return t;const k=new Set;for(const f of e)f.account&&k.add(f.account);return Array.from(k).sort()},[t,e]),y=Z(()=>{const k=new Set;for(const f of e)o&&f.account!==o||pe(f)&&k.add(f.project);for(const[f,C]of Object.entries(r))o&&C.account!==o||k.add(f);return Array.from(k).sort()},[e,r,o]),u=k=>{if(i(k),k&&a){const f=r[a];f&&f.account!==k&&s(null)}},g=Z(()=>e.filter(k=>!(o&&k.account!==o||a&&k.project!==a||d&&(k.harness??"claude")!==d||l&&k.type!==Ta(l)||!p&&k.status==="done")),[e,o,a,l,d,p]);return{filterAccount:o,setFilterAccount:u,filterProject:a,setFilterProject:s,filterType:l,setFilterType:c,filterHarness:d,setFilterHarness:h,showDone:p,setShowDone:v,accountNames:m,projectNames:y,harnessNames:b,filteredSpaces:g}}function zc(){const[e,t]=w([]),[r,o]=w({}),[i,a]=w([]),[s,l]=w(!0),[c,d]=w("list"),[h,p]=w(!1),[v,b]=w(null),[m,y]=w(!1);D(()=>{ye(),fi(),fetch("/api/liveframe/frames").then(_=>_.json()).then(_=>b(_.length)).catch(()=>{})},[]);const u=Y(async()=>{try{const[_,A,M]=await Promise.all([fetch("/api/cw/spaces"),fetch("/api/cw/projects"),fetch("/api/cw/accounts")]);t(await _.json()),o(await A.json()),a(await M.json()),Pl()}catch{P("Failed to connect to server","error")}finally{l(!1)}},[]),g=Y(()=>{setTimeout(u,500),setTimeout(u,2500)},[u]);D(()=>{u()},[u]);const k=$c({spaces:e,loading:s,onFetchData:u}),f=Cc({spaces:e,accounts:i,projects:r}),C=Object.keys(r).length>0,x=_=>{const A=et.find(M=>M.key===_);A&&(Je.value=A.key),p(!0)},[j,R]=w(null),E=Y(async(_,A)=>{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"),A==null||A(),g();else{const se=H.error??"cw --done failed";console.error(`[forge] closing ${_.project}/${_.task??_.pr} failed:
|
|
34
|
+
${se}`),P(se.split(`
|
|
35
|
+
`)[0],"error")}}catch{P("Failed to close the task","error")}},[g]),L=Y(async(_,A)=>{const M=await Zn(_,!0);if(M.state&&M.state.closeWarnings.length===0){await E(_,A);return}R({session:_,state:M.state,error:M.error,onClosed:A})},[E]),S=n(Sc,{request:j,onCancel:()=>R(null),onConfirm:async()=>{const _=j;if(_)try{await E(_.session,_.onClosed)}finally{R(null)}}}),T=Y(_=>{Pe.value=!1,k.showList||k.goToList(),p(!1),d(_)},[k.showList,k.goToList]),$=Y(()=>T("list"),[T]),N=Y(()=>p(!1),[]),W=Y(_=>{f.setFilterProject(f.filterProject===_?null:_),T(c==="memory"?"memory":"list")},[f.filterProject,f.setFilterProject,T,c]),O=Y(_=>{f.setFilterProject(_),T("memory")},[f.setFilterProject,T]),F=Y(_=>{Pe.value=!1,p(!1),k.openTab(_)},[k.openTab]),[U,J]=w(!1),z=Y(()=>J(!1),[]),G=Y(()=>J(!0),[]);D(()=>{const _=A=>{const M=A.metaKey||A.ctrlKey,H=A.key.toLowerCase();if(M&&H==="j"){A.preventDefault(),Mr();return}if(M&&H==="k"){A.preventDefault(),U?J(!1):G();return}const se=A.target;se!=null&&se.closest('input, textarea, select, [contenteditable="true"]')||M||A.altKey||U||h||m||(A.key==="/"?(A.preventDefault(),G()):H==="n"?(A.preventDefault(),p(!0)):H==="p"&&(A.preventDefault(),y(!0)))};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[U,h,m,G]);const V=Y(async(_,A,M,H)=>{try{const re=await(await fetch("/api/cw/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"general",account:A,project:M,description:_})})).json();re.ok&&re.session?(F(re.session),g(),P(H,"success")):P(re.error??"Failed to start session","error")}catch{P("Failed to start session","error")}},[F,g]),le=Y((_,A)=>{const M=_==="project"&&r[A]?A:void 0;return{account:_==="account"?A:M?r[M].account:i[0]||"default",project:M}},[i,r]),ie=Y((_,A,M)=>{const{account:H,project:se}=le(_,A),re=_==="global"?"~/.claude/skills/":_==="account"?`~/.cw/accounts/${A}/skills/`:`${se?r[se].path:"<project>"}/.claude/skills/`,Ce=["Use the skill-creator skill to create a new Claude Code skill.","",`The user wants: ${M}`,`Target scope: ${_}${_!=="global"?` (${A})`:""}`,`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(`
|
|
36
|
+
`);V(Ce,H,se,"AI skill creation session started")},[r,le,V]),de=Y(_=>{const{account:A,project:M}=le(_.scope,_.scopeRef);V(`Use the ${_.name} skill.`,A,M,`Session started with ${_.name}`)},[le,V]),me=Y(async(_,A,M,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:ss(A),description:cs(_,A,M),account:H,harness:"claude"})})).json();if(re.ok&&re.session)return F(re.session),g(),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},[F,g]);D(()=>{s||Qo().catch(()=>{})},[s]);const _e=Z(()=>e.filter(_=>_.status==="active"),[e]),We=Z(()=>k.openTabs.filter(_=>_.status==="active"&&_.type!=="login").map(_=>({key:q(_),session:_})),[k.openTabs]),ge=!k.showList&&k.openTabs.length>0;D(()=>{const _=ge?k.openTabs[k.activeTabIndex]:void 0;Kr.value=_?q(_):null},[ge,k.openTabs,k.activeTabIndex]);const Pt=ee({openTabs:k.openTabs,spaces:e,openSession:F});Pt.current={openTabs:k.openTabs,spaces:e,openSession:F},D(()=>Ja((_,A)=>{if(document.visibilityState==="visible"&&_===Kr.value)return;const{openTabs:M,spaces:H,openSession:se}=Pt.current,re=M.find(Ce=>q(Ce)===_)??H.find(Ce=>q(Ce)===_);re&&Za(`${fe(re)}: ${on(A).toLowerCase()}`,pe(re)||re.account,_,()=>se(re))}),[]);const tt=Object.values(Ee.value).filter(Ve).length;D(()=>{document.title=tt>0?`(${tt}) Forge Console`:"Forge Console"},[tt]);const bn=Z(()=>{const _=new Map(Object.entries(r).map(([A,M])=>[A,M.account]));for(const A of e)pe(A)&&!_.has(A.project)&&_.set(A.project,A.account);return Array.from(_,([A,M])=>({name:A,account:M||"unassigned",count:_e.filter(H=>H.project===A).length,live:We.some(H=>H.session.project===A)}))},[r,e,_e,We]);D(()=>{f.filterProject&&(He.value=f.filterProject)},[f.filterProject]);const $r=Z(()=>Object.keys(r),[r]),jt=Y(_=>{f.setFilterProject(_),T("list")},[f.setFilterProject,T]),At=ge?"list":c,kn=Z(()=>[{id:"new-task",label:"New task",hint:"N",glyph:"+",token:"--blue",run:()=>x()},{id:"add-project",label:"Add project",hint:"P",glyph:"P",token:"--green",run:()=>y(!0)},...ci.map(_=>({id:_.view,label:_.label,hint:_.view==="list"?"⌘L":"",glyph:_.glyph,token:_.token,run:()=>T(_.view)})),{id:"appearance",label:"Toggle appearance",hint:"⌘J",glyph:"◐",token:null,run:Mr}],[T]),_n=n(ol,{view:At,counts:{list:_e.length,accounts:f.accountNames.length,prototypes:v},projects:bn,accounts:f.accountNames,selectedProject:f.filterProject,live:We,onNavigate:T,onSelectProject:W,onAddProject:()=>{Pe.value=!1,y(!0)},onOpenLive:F,onSearch:G}),Et=s?n("div",{class:"py-20 text-center text-ink2",children:"Loading…"}):c==="list"&&!C?n("div",{style:{padding:"56px 22px"},children:n(qe,{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:()=>y(!0)}})}):c==="list"?n(Jl,{spaces:f.filteredSpaces,allSpaces:e,projects:r,accountNames:f.accountNames,filterAccount:f.filterAccount,filterProject:f.filterProject,onFilterProject:f.setFilterProject,filterType:f.filterType,onFilterType:f.setFilterType,harnessNames:f.harnessNames,filterHarness:f.filterHarness,onFilterHarness:f.setFilterHarness,showDone:f.showDone,onShowDone:f.setShowDone,openTabKeys:k.openTabKeys,onSelectTask:F,onMarkDone:L,onNewTask:()=>x(),onCreateProject:()=>y(!0),onRefresh:()=>u(),onStarted:_=>{_&&F(_),g()}}):c==="qa"?n(rc,{projects:r,preferred:f.filterProject??void 0}):c==="memory"?n(cc,{project:f.filterProject,onProject:f.setFilterProject}):c==="prototypes"?n(oc,{accounts:f.accountNames,onOpenSession:F,onFramesChanged:b}):c==="accounts"?n(bc,{projects:r,onOpenSession:F,onAccountsChanged:()=>{u()}}):n($s,{accounts:f.accountNames,projects:r,onCreateWithAI:ie,onRunSkill:de,onProposeSkill:me});return n(Sa,{sidebar:_n,children:[!ge&&Et,k.openTabs.length>0&&n("div",{class:"flex flex-col","aria-hidden":!ge,style:ge?{height:"100vh"}:{position:"absolute",top:0,left:0,right:0,height:"100vh",visibility:"hidden",pointerEvents:"none",zIndex:-1},children:[n(_c,{tabs:k.openTabs,activeIndex:k.activeTabIndex,onActivate:k.setActiveTabIndex,onClose:k.closeTab,onBack:$,allSessions:_e,openTabKeys:k.openTabKeys,onOpenSession:F,onNewTask:_=>{$(),x(_)}}),n("div",{class:"flex-1 min-h-0 relative",children:k.openTabs.map((_,A)=>{const M=A===k.activeTabIndex,H=M&≥return n("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,display:"flex",flexDirection:"column",visibility:H?"visible":"hidden",zIndex:M?1:0,pointerEvents:H?"auto":"none"},children:n(ts,{session:_,active:H,onDone:()=>L(_,()=>{k.closeTabByKey(q(_))}),onOpenMemory:O})},q(_))})})]}),h&&n(as,{projects:r,accounts:f.accountNames,initialAccount:f.filterAccount??(sn.value||void 0),initialProject:He.value||void 0,onClose:N,onCreated:_=>{p(!1),_&&F(_),g()},onOpenAccounts:()=>T("accounts")}),U&&n(il,{openTabs:k.openTabs,sessions:e,projects:$r,commands:kn,onOpenSession:F,onSelectProject:jt,onClose:z}),n(dc,{open:m,accounts:f.accountNames,onClose:()=>y(!1),onCreated:_=>{y(!1),_&&F(_),g()}}),S]})}Hn(n(zc,{}),document.getElementById("app"));
|