octiqflow-linux-x64 0.2.12 → 0.2.13

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.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./index-jqMjQWrX.js","./index-b8TsQBuQ.js","./index-C9mDGzna.js","./index-y2CSEYBe.js","./index-_DD02urZ.js","./index-Cy-oeOwN.js","./index-CCTszXv6.js","./index-BrrKATvL.js","./index-CCcxHg-5.js","./index-Bzmn7TfA.js","./index-BOHzLyXg.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./index-DFb3ZQNl.js","./index-BvUCyCk6.js","./index-DccHPcI7.js","./index-DDDo2fll.js","./index-CL4rlsj9.js","./index-CpTTNC9j.js","./index-DytcrdWN.js","./index-M3sz0pDr.js","./index-Bd1cE973.js","./index-Cqu5NxcW.js","./index-BVlTDuBl.js"])))=>i.map(i=>d[i]);
2
2
  (function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))i(s);new MutationObserver(s=>{for(const r of s)if(r.type==="childList")for(const a of r.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&i(a)}).observe(document,{childList:!0,subtree:!0});function n(s){const r={};return s.integrity&&(r.integrity=s.integrity),s.referrerPolicy&&(r.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?r.credentials="include":s.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function i(s){if(s.ep)return;s.ep=!0;const r=n(s);fetch(s.href,r)}})();function QT(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var I_={exports:{}},Ep={};var O5;function M$(){if(O5)return Ep;O5=1;var t=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function n(i,s,r){var a=null;if(r!==void 0&&(a=""+r),s.key!==void 0&&(a=""+s.key),"key"in s){r={};for(var c in s)c!=="key"&&(r[c]=s[c])}else r=s;return s=r.ref,{$$typeof:t,type:i,key:a,ref:s!==void 0?s:null,props:r}}return Ep.Fragment=e,Ep.jsx=n,Ep.jsxs=n,Ep}var I5;function L$(){return I5||(I5=1,I_.exports=M$()),I_.exports}var o=L$(),$_={exports:{}},Dt={};var $5;function T$(){if($5)return Dt;$5=1;var t=Symbol.for("react.transitional.element"),e=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),r=Symbol.for("react.consumer"),a=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),d=Symbol.for("react.memo"),p=Symbol.for("react.lazy"),m=Symbol.for("react.activity"),v=Symbol.iterator;function x(U){return U===null||typeof U!="object"?null:(U=v&&U[v]||U["@@iterator"],typeof U=="function"?U:null)}var y={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},k=Object.assign,S={};function C(U,Z,R){this.props=U,this.context=Z,this.refs=S,this.updater=R||y}C.prototype.isReactComponent={},C.prototype.setState=function(U,Z){if(typeof U!="object"&&typeof U!="function"&&U!=null)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,U,Z,"setState")},C.prototype.forceUpdate=function(U){this.updater.enqueueForceUpdate(this,U,"forceUpdate")};function A(){}A.prototype=C.prototype;function N(U,Z,R){this.props=U,this.context=Z,this.refs=S,this.updater=R||y}var E=N.prototype=new A;E.constructor=N,k(E,C.prototype),E.isPureReactComponent=!0;var M=Array.isArray;function L(){}var $={H:null,A:null,T:null,S:null},V=Object.prototype.hasOwnProperty;function X(U,Z,R){var K=R.ref;return{$$typeof:t,type:U,key:Z,ref:K!==void 0?K:null,props:R}}function D(U,Z){return X(U.type,Z,U.props)}function Q(U){return typeof U=="object"&&U!==null&&U.$$typeof===t}function P(U){var Z={"=":"=0",":":"=2"};return"$"+U.replace(/[=:]/g,function(R){return Z[R]})}var z=/\/+/g;function H(U,Z){return typeof U=="object"&&U!==null&&U.key!=null?P(""+U.key):Z.toString(36)}function W(U){switch(U.status){case"fulfilled":return U.value;case"rejected":throw U.reason;default:switch(typeof U.status=="string"?U.then(L,L):(U.status="pending",U.then(function(Z){U.status==="pending"&&(U.status="fulfilled",U.value=Z)},function(Z){U.status==="pending"&&(U.status="rejected",U.reason=Z)})),U.status){case"fulfilled":return U.value;case"rejected":throw U.reason}}throw U}function F(U,Z,R,K,O){var ie=typeof U;(ie==="undefined"||ie==="boolean")&&(U=null);var re=!1;if(U===null)re=!0;else switch(ie){case"bigint":case"string":case"number":re=!0;break;case"object":switch(U.$$typeof){case t:case e:re=!0;break;case p:return re=U._init,F(re(U._payload),Z,R,K,O)}}if(re)return O=O(U),re=K===""?"."+H(U,0):K,M(O)?(R="",re!=null&&(R=re.replace(z,"$&/")+"/"),F(O,Z,R,"",function(Re){return Re})):O!=null&&(Q(O)&&(O=D(O,R+(O.key==null||U&&U.key===O.key?"":(""+O.key).replace(z,"$&/")+"/")+re)),Z.push(O)),1;re=0;var ve=K===""?".":K+":";if(M(U))for(var le=0;le<U.length;le++)K=U[le],ie=ve+H(K,le),re+=F(K,Z,R,ie,O);else if(le=x(U),typeof le=="function")for(U=le.call(U),le=0;!(K=U.next()).done;)K=K.value,ie=ve+H(K,le++),re+=F(K,Z,R,ie,O);else if(ie==="object"){if(typeof U.then=="function")return F(W(U),Z,R,K,O);throw Z=String(U),Error("Objects are not valid as a React child (found: "+(Z==="[object Object]"?"object with keys {"+Object.keys(U).join(", ")+"}":Z)+"). If you meant to render a collection of children, use an array instead.")}return re}function Y(U,Z,R){if(U==null)return U;var K=[],O=0;return F(U,K,"","",function(ie){return Z.call(R,ie,O++)}),K}function J(U){if(U._status===-1){var Z=U._result;Z=Z(),Z.then(function(R){(U._status===0||U._status===-1)&&(U._status=1,U._result=R)},function(R){(U._status===0||U._status===-1)&&(U._status=2,U._result=R)}),U._status===-1&&(U._status=0,U._result=Z)}if(U._status===1)return U._result.default;throw U._result}var te=typeof reportError=="function"?reportError:function(U){if(typeof window=="object"&&typeof window.ErrorEvent=="function"){var Z=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:typeof U=="object"&&U!==null&&typeof U.message=="string"?String(U.message):String(U),error:U});if(!window.dispatchEvent(Z))return}else if(typeof process=="object"&&typeof process.emit=="function"){process.emit("uncaughtException",U);return}console.error(U)},I={map:Y,forEach:function(U,Z,R){Y(U,function(){Z.apply(this,arguments)},R)},count:function(U){var Z=0;return Y(U,function(){Z++}),Z},toArray:function(U){return Y(U,function(Z){return Z})||[]},only:function(U){if(!Q(U))throw Error("React.Children.only expected to receive a single React element child.");return U}};return Dt.Activity=m,Dt.Children=I,Dt.Component=C,Dt.Fragment=n,Dt.Profiler=s,Dt.PureComponent=N,Dt.StrictMode=i,Dt.Suspense=u,Dt.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=$,Dt.__COMPILER_RUNTIME={__proto__:null,c:function(U){return $.H.useMemoCache(U)}},Dt.cache=function(U){return function(){return U.apply(null,arguments)}},Dt.cacheSignal=function(){return null},Dt.cloneElement=function(U,Z,R){if(U==null)throw Error("The argument must be a React element, but you passed "+U+".");var K=k({},U.props),O=U.key;if(Z!=null)for(ie in Z.key!==void 0&&(O=""+Z.key),Z)!V.call(Z,ie)||ie==="key"||ie==="__self"||ie==="__source"||ie==="ref"&&Z.ref===void 0||(K[ie]=Z[ie]);var ie=arguments.length-2;if(ie===1)K.children=R;else if(1<ie){for(var re=Array(ie),ve=0;ve<ie;ve++)re[ve]=arguments[ve+2];K.children=re}return X(U.type,O,K)},Dt.createContext=function(U){return U={$$typeof:a,_currentValue:U,_currentValue2:U,_threadCount:0,Provider:null,Consumer:null},U.Provider=U,U.Consumer={$$typeof:r,_context:U},U},Dt.createElement=function(U,Z,R){var K,O={},ie=null;if(Z!=null)for(K in Z.key!==void 0&&(ie=""+Z.key),Z)V.call(Z,K)&&K!=="key"&&K!=="__self"&&K!=="__source"&&(O[K]=Z[K]);var re=arguments.length-2;if(re===1)O.children=R;else if(1<re){for(var ve=Array(re),le=0;le<re;le++)ve[le]=arguments[le+2];O.children=ve}if(U&&U.defaultProps)for(K in re=U.defaultProps,re)O[K]===void 0&&(O[K]=re[K]);return X(U,ie,O)},Dt.createRef=function(){return{current:null}},Dt.forwardRef=function(U){return{$$typeof:c,render:U}},Dt.isValidElement=Q,Dt.lazy=function(U){return{$$typeof:p,_payload:{_status:-1,_result:U},_init:J}},Dt.memo=function(U,Z){return{$$typeof:d,type:U,compare:Z===void 0?null:Z}},Dt.startTransition=function(U){var Z=$.T,R={};$.T=R;try{var K=U(),O=$.S;O!==null&&O(R,K),typeof K=="object"&&K!==null&&typeof K.then=="function"&&K.then(L,te)}catch(ie){te(ie)}finally{Z!==null&&R.types!==null&&(Z.types=R.types),$.T=Z}},Dt.unstable_useCacheRefresh=function(){return $.H.useCacheRefresh()},Dt.use=function(U){return $.H.use(U)},Dt.useActionState=function(U,Z,R){return $.H.useActionState(U,Z,R)},Dt.useCallback=function(U,Z){return $.H.useCallback(U,Z)},Dt.useContext=function(U){return $.H.useContext(U)},Dt.useDebugValue=function(){},Dt.useDeferredValue=function(U,Z){return $.H.useDeferredValue(U,Z)},Dt.useEffect=function(U,Z){return $.H.useEffect(U,Z)},Dt.useEffectEvent=function(U){return $.H.useEffectEvent(U)},Dt.useId=function(){return $.H.useId()},Dt.useImperativeHandle=function(U,Z,R){return $.H.useImperativeHandle(U,Z,R)},Dt.useInsertionEffect=function(U,Z){return $.H.useInsertionEffect(U,Z)},Dt.useLayoutEffect=function(U,Z){return $.H.useLayoutEffect(U,Z)},Dt.useMemo=function(U,Z){return $.H.useMemo(U,Z)},Dt.useOptimistic=function(U,Z){return $.H.useOptimistic(U,Z)},Dt.useReducer=function(U,Z,R){return $.H.useReducer(U,Z,R)},Dt.useRef=function(U){return $.H.useRef(U)},Dt.useState=function(U){return $.H.useState(U)},Dt.useSyncExternalStore=function(U,Z,R){return $.H.useSyncExternalStore(U,Z,R)},Dt.useTransition=function(){return $.H.useTransition()},Dt.version="19.2.8",Dt}var P5;function oS(){return P5||(P5=1,$_.exports=T$()),$_.exports}var _=oS(),P_={exports:{}},Mp={},z_={exports:{}},F_={};var z5;function R$(){return z5||(z5=1,(function(t){function e(F,Y){var J=F.length;F.push(Y);e:for(;0<J;){var te=J-1>>>1,I=F[te];if(0<s(I,Y))F[te]=Y,F[J]=I,J=te;else break e}}function n(F){return F.length===0?null:F[0]}function i(F){if(F.length===0)return null;var Y=F[0],J=F.pop();if(J!==Y){F[0]=J;e:for(var te=0,I=F.length,U=I>>>1;te<U;){var Z=2*(te+1)-1,R=F[Z],K=Z+1,O=F[K];if(0>s(R,J))K<I&&0>s(O,R)?(F[te]=O,F[K]=J,te=K):(F[te]=R,F[Z]=J,te=Z);else if(K<I&&0>s(O,J))F[te]=O,F[K]=J,te=K;else break e}}return Y}function s(F,Y){var J=F.sortIndex-Y.sortIndex;return J!==0?J:F.id-Y.id}if(t.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var r=performance;t.unstable_now=function(){return r.now()}}else{var a=Date,c=a.now();t.unstable_now=function(){return a.now()-c}}var u=[],d=[],p=1,m=null,v=3,x=!1,y=!1,k=!1,S=!1,C=typeof setTimeout=="function"?setTimeout:null,A=typeof clearTimeout=="function"?clearTimeout:null,N=typeof setImmediate<"u"?setImmediate:null;function E(F){for(var Y=n(d);Y!==null;){if(Y.callback===null)i(d);else if(Y.startTime<=F)i(d),Y.sortIndex=Y.expirationTime,e(u,Y);else break;Y=n(d)}}function M(F){if(k=!1,E(F),!y)if(n(u)!==null)y=!0,L||(L=!0,P());else{var Y=n(d);Y!==null&&W(M,Y.startTime-F)}}var L=!1,$=-1,V=5,X=-1;function D(){return S?!0:!(t.unstable_now()-X<V)}function Q(){if(S=!1,L){var F=t.unstable_now();X=F;var Y=!0;try{e:{y=!1,k&&(k=!1,A($),$=-1),x=!0;var J=v;try{t:{for(E(F),m=n(u);m!==null&&!(m.expirationTime>F&&D());){var te=m.callback;if(typeof te=="function"){m.callback=null,v=m.priorityLevel;var I=te(m.expirationTime<=F);if(F=t.unstable_now(),typeof I=="function"){m.callback=I,E(F),Y=!0;break t}m===n(u)&&i(u),E(F)}else i(u);m=n(u)}if(m!==null)Y=!0;else{var U=n(d);U!==null&&W(M,U.startTime-F),Y=!1}}break e}finally{m=null,v=J,x=!1}Y=void 0}}finally{Y?P():L=!1}}}var P;if(typeof N=="function")P=function(){N(Q)};else if(typeof MessageChannel<"u"){var z=new MessageChannel,H=z.port2;z.port1.onmessage=Q,P=function(){H.postMessage(null)}}else P=function(){C(Q,0)};function W(F,Y){$=C(function(){F(t.unstable_now())},Y)}t.unstable_IdlePriority=5,t.unstable_ImmediatePriority=1,t.unstable_LowPriority=4,t.unstable_NormalPriority=3,t.unstable_Profiling=null,t.unstable_UserBlockingPriority=2,t.unstable_cancelCallback=function(F){F.callback=null},t.unstable_forceFrameRate=function(F){0>F||125<F?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):V=0<F?Math.floor(1e3/F):5},t.unstable_getCurrentPriorityLevel=function(){return v},t.unstable_next=function(F){switch(v){case 1:case 2:case 3:var Y=3;break;default:Y=v}var J=v;v=Y;try{return F()}finally{v=J}},t.unstable_requestPaint=function(){S=!0},t.unstable_runWithPriority=function(F,Y){switch(F){case 1:case 2:case 3:case 4:case 5:break;default:F=3}var J=v;v=F;try{return Y()}finally{v=J}},t.unstable_scheduleCallback=function(F,Y,J){var te=t.unstable_now();switch(typeof J=="object"&&J!==null?(J=J.delay,J=typeof J=="number"&&0<J?te+J:te):J=te,F){case 1:var I=-1;break;case 2:I=250;break;case 5:I=1073741823;break;case 4:I=1e4;break;default:I=5e3}return I=J+I,F={id:p++,callback:Y,priorityLevel:F,startTime:J,expirationTime:I,sortIndex:-1},J>te?(F.sortIndex=J,e(d,F),n(u)===null&&F===n(d)&&(k?(A($),$=-1):k=!0,W(M,J-te))):(F.sortIndex=I,e(u,F),y||x||(y=!0,L||(L=!0,P()))),F},t.unstable_shouldYield=D,t.unstable_wrapCallback=function(F){var Y=v;return function(){var J=v;v=Y;try{return F.apply(this,arguments)}finally{v=J}}}})(F_)),F_}var F5;function D$(){return F5||(F5=1,z_.exports=R$()),z_.exports}var H_={exports:{}},$s={};var H5;function B$(){if(H5)return $s;H5=1;var t=oS();function e(u){var d="https://react.dev/errors/"+u;if(1<arguments.length){d+="?args[]="+encodeURIComponent(arguments[1]);for(var p=2;p<arguments.length;p++)d+="&args[]="+encodeURIComponent(arguments[p])}return"Minified React error #"+u+"; visit "+d+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function n(){}var i={d:{f:n,r:function(){throw Error(e(522))},D:n,C:n,L:n,m:n,X:n,S:n,M:n},p:0,findDOMNode:null},s=Symbol.for("react.portal");function r(u,d,p){var m=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:s,key:m==null?null:""+m,children:u,containerInfo:d,implementation:p}}var a=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function c(u,d){if(u==="font")return"";if(typeof d=="string")return d==="use-credentials"?d:""}return $s.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,$s.createPortal=function(u,d){var p=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!d||d.nodeType!==1&&d.nodeType!==9&&d.nodeType!==11)throw Error(e(299));return r(u,d,null,p)},$s.flushSync=function(u){var d=a.T,p=i.p;try{if(a.T=null,i.p=2,u)return u()}finally{a.T=d,i.p=p,i.d.f()}},$s.preconnect=function(u,d){typeof u=="string"&&(d?(d=d.crossOrigin,d=typeof d=="string"?d==="use-credentials"?d:"":void 0):d=null,i.d.C(u,d))},$s.prefetchDNS=function(u){typeof u=="string"&&i.d.D(u)},$s.preinit=function(u,d){if(typeof u=="string"&&d&&typeof d.as=="string"){var p=d.as,m=c(p,d.crossOrigin),v=typeof d.integrity=="string"?d.integrity:void 0,x=typeof d.fetchPriority=="string"?d.fetchPriority:void 0;p==="style"?i.d.S(u,typeof d.precedence=="string"?d.precedence:void 0,{crossOrigin:m,integrity:v,fetchPriority:x}):p==="script"&&i.d.X(u,{crossOrigin:m,integrity:v,fetchPriority:x,nonce:typeof d.nonce=="string"?d.nonce:void 0})}},$s.preinitModule=function(u,d){if(typeof u=="string")if(typeof d=="object"&&d!==null){if(d.as==null||d.as==="script"){var p=c(d.as,d.crossOrigin);i.d.M(u,{crossOrigin:p,integrity:typeof d.integrity=="string"?d.integrity:void 0,nonce:typeof d.nonce=="string"?d.nonce:void 0})}}else d==null&&i.d.M(u)},$s.preload=function(u,d){if(typeof u=="string"&&typeof d=="object"&&d!==null&&typeof d.as=="string"){var p=d.as,m=c(p,d.crossOrigin);i.d.L(u,p,{crossOrigin:m,integrity:typeof d.integrity=="string"?d.integrity:void 0,nonce:typeof d.nonce=="string"?d.nonce:void 0,type:typeof d.type=="string"?d.type:void 0,fetchPriority:typeof d.fetchPriority=="string"?d.fetchPriority:void 0,referrerPolicy:typeof d.referrerPolicy=="string"?d.referrerPolicy:void 0,imageSrcSet:typeof d.imageSrcSet=="string"?d.imageSrcSet:void 0,imageSizes:typeof d.imageSizes=="string"?d.imageSizes:void 0,media:typeof d.media=="string"?d.media:void 0})}},$s.preloadModule=function(u,d){if(typeof u=="string")if(d){var p=c(d.as,d.crossOrigin);i.d.m(u,{as:typeof d.as=="string"&&d.as!=="script"?d.as:void 0,crossOrigin:p,integrity:typeof d.integrity=="string"?d.integrity:void 0})}else i.d.m(u)},$s.requestFormReset=function(u){i.d.r(u)},$s.unstable_batchedUpdates=function(u,d){return u(d)},$s.useFormState=function(u,d,p){return a.H.useFormState(u,d,p)},$s.useFormStatus=function(){return a.H.useHostTransitionStatus()},$s.version="19.2.8",$s}var W5;function ZT(){if(W5)return H_.exports;W5=1;function t(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(t)}catch(e){console.error(e)}}return t(),H_.exports=B$(),H_.exports}var q5;function O$(){if(q5)return Mp;q5=1;var t=D$(),e=oS(),n=ZT();function i(l){var h="https://react.dev/errors/"+l;if(1<arguments.length){h+="?args[]="+encodeURIComponent(arguments[1]);for(var f=2;f<arguments.length;f++)h+="&args[]="+encodeURIComponent(arguments[f])}return"Minified React error #"+l+"; visit "+h+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function s(l){return!(!l||l.nodeType!==1&&l.nodeType!==9&&l.nodeType!==11)}function r(l){var h=l,f=l;if(l.alternate)for(;h.return;)h=h.return;else{l=h;do h=l,(h.flags&4098)!==0&&(f=h.return),l=h.return;while(l)}return h.tag===3?f:null}function a(l){if(l.tag===13){var h=l.memoizedState;if(h===null&&(l=l.alternate,l!==null&&(h=l.memoizedState)),h!==null)return h.dehydrated}return null}function c(l){if(l.tag===31){var h=l.memoizedState;if(h===null&&(l=l.alternate,l!==null&&(h=l.memoizedState)),h!==null)return h.dehydrated}return null}function u(l){if(r(l)!==l)throw Error(i(188))}function d(l){var h=l.alternate;if(!h){if(h=r(l),h===null)throw Error(i(188));return h!==l?null:l}for(var f=l,g=h;;){var b=f.return;if(b===null)break;var w=b.alternate;if(w===null){if(g=b.return,g!==null){f=g;continue}break}if(b.child===w.child){for(w=b.child;w;){if(w===f)return u(b),l;if(w===g)return u(b),h;w=w.sibling}throw Error(i(188))}if(f.return!==g.return)f=b,g=w;else{for(var T=!1,q=b.child;q;){if(q===f){T=!0,f=b,g=w;break}if(q===g){T=!0,g=b,f=w;break}q=q.sibling}if(!T){for(q=w.child;q;){if(q===f){T=!0,f=w,g=b;break}if(q===g){T=!0,g=w,f=b;break}q=q.sibling}if(!T)throw Error(i(189))}}if(f.alternate!==g)throw Error(i(190))}if(f.tag!==3)throw Error(i(188));return f.stateNode.current===f?l:h}function p(l){var h=l.tag;if(h===5||h===26||h===27||h===6)return l;for(l=l.child;l!==null;){if(h=p(l),h!==null)return h;l=l.sibling}return null}var m=Object.assign,v=Symbol.for("react.element"),x=Symbol.for("react.transitional.element"),y=Symbol.for("react.portal"),k=Symbol.for("react.fragment"),S=Symbol.for("react.strict_mode"),C=Symbol.for("react.profiler"),A=Symbol.for("react.consumer"),N=Symbol.for("react.context"),E=Symbol.for("react.forward_ref"),M=Symbol.for("react.suspense"),L=Symbol.for("react.suspense_list"),$=Symbol.for("react.memo"),V=Symbol.for("react.lazy"),X=Symbol.for("react.activity"),D=Symbol.for("react.memo_cache_sentinel"),Q=Symbol.iterator;function P(l){return l===null||typeof l!="object"?null:(l=Q&&l[Q]||l["@@iterator"],typeof l=="function"?l:null)}var z=Symbol.for("react.client.reference");function H(l){if(l==null)return null;if(typeof l=="function")return l.$$typeof===z?null:l.displayName||l.name||null;if(typeof l=="string")return l;switch(l){case k:return"Fragment";case C:return"Profiler";case S:return"StrictMode";case M:return"Suspense";case L:return"SuspenseList";case X:return"Activity"}if(typeof l=="object")switch(l.$$typeof){case y:return"Portal";case N:return l.displayName||"Context";case A:return(l._context.displayName||"Context")+".Consumer";case E:var h=l.render;return l=l.displayName,l||(l=h.displayName||h.name||"",l=l!==""?"ForwardRef("+l+")":"ForwardRef"),l;case $:return h=l.displayName||null,h!==null?h:H(l.type)||"Memo";case V:h=l._payload,l=l._init;try{return H(l(h))}catch{}}return null}var W=Array.isArray,F=e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Y=n.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,J={pending:!1,data:null,method:null,action:null},te=[],I=-1;function U(l){return{current:l}}function Z(l){0>I||(l.current=te[I],te[I]=null,I--)}function R(l,h){I++,te[I]=l.current,l.current=h}var K=U(null),O=U(null),ie=U(null),re=U(null);function ve(l,h){switch(R(ie,h),R(O,l),R(K,null),h.nodeType){case 9:case 11:l=(l=h.documentElement)&&(l=l.namespaceURI)?r5(l):0;break;default:if(l=h.tagName,h=h.namespaceURI)h=r5(h),l=a5(h,l);else switch(l){case"svg":l=1;break;case"math":l=2;break;default:l=0}}Z(K),R(K,l)}function le(){Z(K),Z(O),Z(ie)}function Re(l){l.memoizedState!==null&&R(re,l);var h=K.current,f=a5(h,l.type);h!==f&&(R(O,l),R(K,f))}function De(l){O.current===l&&(Z(K),Z(O)),re.current===l&&(Z(re),Cp._currentValue=J)}var Ke,xe;function Te(l){if(Ke===void 0)try{throw Error()}catch(f){var h=f.stack.trim().match(/\n( *(at )?)/);Ke=h&&h[1]||"",xe=-1<f.stack.indexOf(`
3
3
  at`)?" (<anonymous>)":-1<f.stack.indexOf("@")?"@unknown:0:0":""}return`
4
4
  `+Ke+l+xe}var vt=!1;function Bt(l,h){if(!l||vt)return"";vt=!0;var f=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var g={DetermineComponentFrameRoot:function(){try{if(h){var je=function(){throw Error()};if(Object.defineProperty(je.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(je,[])}catch(ge){var pe=ge}Reflect.construct(l,[],je)}else{try{je.call()}catch(ge){pe=ge}l.call(je.prototype)}}else{try{throw Error()}catch(ge){pe=ge}(je=l())&&typeof je.catch=="function"&&je.catch(function(){})}}catch(ge){if(ge&&pe&&typeof ge.stack=="string")return[ge.stack,pe.stack]}return[null,null]}};g.DetermineComponentFrameRoot.displayName="DetermineComponentFrameRoot";var b=Object.getOwnPropertyDescriptor(g.DetermineComponentFrameRoot,"name");b&&b.configurable&&Object.defineProperty(g.DetermineComponentFrameRoot,"name",{value:"DetermineComponentFrameRoot"});var w=g.DetermineComponentFrameRoot(),T=w[0],q=w[1];if(T&&q){var ne=T.split(`
@@ -65,7 +65,7 @@ ${s}
65
65
  --Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\uFEFF-]`,Rw),HY={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let Sb=null;function WY(){var t;if(Sb==null&&typeof document<"u"&&document.body){let e=document.body.style;Sb=((t=e.tabSize)!==null&&t!==void 0?t:e.MozTabSize)!=null}return Sb||!1}const y0=nt.define({combine(t){let e=Ah(t,{render:null,specialChars:FY,addSpecialChars:null});return(e.replaceTabs=!WY())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,Rw)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,Rw)),e}});function qY(t={}){return[y0.of(t),UY()]}let cE=null;function UY(){return cE||(cE=hr.fromClass(class{constructor(t){this.view=t,this.decorations=Kt.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(t.state.facet(y0)),this.decorations=this.decorator.createDeco(t)}makeDecorator(t){return new zY({regexp:t.specialChars,decoration:(e,n,i)=>{let{doc:s}=n.state,r=QS(e[0],0);if(r==9){let a=s.lineAt(i),c=n.state.tabSize,u=wf(a.text,c,i-a.from);return Kt.replace({widget:new YY((c-u%c)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=Kt.replace({widget:new GY(t,r)}))},boundary:t.replaceTabs?void 0:/[^]/})}update(t){let e=t.state.facet(y0);t.startState.facet(y0)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(t.view)):this.decorations=this.decorator.updateDeco(t,this.decorations)}},{decorations:t=>t.decorations}))}const VY="•";function KY(t){return t>=32?VY:t==10?"␤":String.fromCharCode(9216+t)}class GY extends kf{constructor(e,n){super(),this.options=e,this.code=n}eq(e){return e.code==this.code}toDOM(e){let n=KY(this.code),i=e.state.phrase("Control character")+" "+(HY[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,i,n);if(s)return s;let r=document.createElement("span");return r.textContent=n,r.title=i,r.setAttribute("aria-label",i),r.className="cm-specialChar",r}ignoreEvent(){return!1}}class YY extends kf{constructor(e){super(),this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent=" ",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}}function XY(){return ZY}const QY=Kt.line({class:"cm-activeLine"}),ZY=hr.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.docChanged||t.selectionSet)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=-1,n=[];for(let i of t.state.selection.ranges){let s=t.lineBlockAt(i.head);s.from>e&&(n.push(QY.range(s.from)),e=s.from)}return Kt.set(n)}},{decorations:t=>t.decorations}),Dw=2e3;function JY(t,e,n){let i=Math.min(e.line,n.line),s=Math.max(e.line,n.line),r=[];if(e.off>Dw||n.off>Dw||e.col<0||n.col<0){let a=Math.min(e.off,n.off),c=Math.max(e.off,n.off);for(let u=i;u<=s;u++){let d=t.doc.line(u);d.length<=c&&r.push(Ne.range(d.from+a,d.to+c))}}else{let a=Math.min(e.col,n.col),c=Math.max(e.col,n.col);for(let u=i;u<=s;u++){let d=t.doc.line(u),p=fw(d.text,a,t.tabSize,!0);if(p<0)r.push(Ne.cursor(d.to));else{let m=fw(d.text,c,t.tabSize);r.push(Ne.range(d.from+p,d.from+m))}}}return r}function eX(t,e){let n=t.coordsAtPos(t.viewport.from);return n?Math.round(Math.abs((n.left-e)/t.defaultCharacterWidth)):-1}function uE(t,e){let n=t.posAtCoords({x:e.clientX,y:e.clientY},!1),i=t.state.doc.lineAt(n),s=n-i.from,r=s>Dw?-1:s==i.length?eX(t,e.clientX):wf(i.text,t.state.tabSize,n-i.from);return{line:i.number,col:r,off:s}}function tX(t,e){let n=uE(t,e),i=t.state.selection;return n?{update(s){if(s.docChanged){let r=s.changes.mapPos(s.startState.doc.line(n.line).from),a=s.state.doc.lineAt(r);n={line:a.number,col:n.col,off:Math.min(n.off,a.length)},i=i.map(s.changes)}},get(s,r,a){let c=uE(t,s);if(!c)return i;let u=JY(t.state,n,c);return u.length?a?Ne.create(u.concat(i.ranges)):Ne.create(u):i}}:null}function nX(t){let e=(n=>n.altKey&&n.button==0);return ct.mouseSelectionStyle.of((n,i)=>e(i)?tX(n,i):null)}const hE=nt.define({combine(t){let e,n;for(let i of t)e=e||i.topContainer,n=n||i.bottomContainer;return{topContainer:e,bottomContainer:n}}});function CD(t,e){let n=t.plugin(jD),i=n?n.specs.indexOf(e):-1;return i>-1?n.panels[i]:null}const jD=hr.fromClass(class{constructor(t){this.input=t.state.facet(ux),this.specs=this.input.filter(n=>n),this.panels=this.specs.map(n=>n(t));let e=t.state.facet(hE);this.top=new Ov(t,!0,e.topContainer),this.bottom=new Ov(t,!1,e.bottomContainer),this.top.sync(this.panels.filter(n=>n.top)),this.bottom.sync(this.panels.filter(n=>!n.top));for(let n of this.panels)n.dom.classList.add("cm-panel"),n.mount&&n.mount()}update(t){let e=t.state.facet(hE);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new Ov(t.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new Ov(t.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let n=t.state.facet(ux);if(n!=this.input){let i=n.filter(u=>u),s=[],r=[],a=[],c=[];for(let u of i){let d=this.specs.indexOf(u),p;d<0?(p=u(t.view),c.push(p)):(p=this.panels[d],p.update&&p.update(t)),s.push(p),(p.top?r:a).push(p)}this.specs=i,this.panels=s,this.top.sync(r),this.bottom.sync(a);for(let u of c)u.dom.classList.add("cm-panel"),u.mount&&u.mount()}else for(let i of this.panels)i.update&&i.update(t)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:t=>ct.scrollMargins.of(e=>{let n=e.plugin(t);return n&&{top:n.top.scrollMargin(),bottom:n.bottom.scrollMargin()}})});class Ov{constructor(e,n,i){this.view=e,this.top=n,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let n of this.panels)n.destroy&&e.indexOf(n)<0&&n.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom";let n=this.container||this.view.dom;n.insertBefore(this.dom,this.top?n.firstChild:null)}let e=this.dom.firstChild;for(let n of this.panels)if(n.dom.parentNode==this.dom){for(;e!=n.dom;)e=dE(e);e=e.nextSibling}else this.dom.insertBefore(n.dom,e);for(;e;)e=dE(e)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}}function dE(t){let e=t.nextSibling;return t.remove(),e}const ux=nt.define({enables:jD});function iX(t,e){let n,i=new Promise(a=>n=a),s=a=>sX(a,e,n);t.state.field(Cb,!1)?t.dispatch({effects:AD.of(s)}):t.dispatch({effects:Gn.appendConfig.of(Cb.init(()=>[s]))});let r=ND.of(s);return{close:r,result:i.then(a=>((t.win.queueMicrotask||(u=>t.win.setTimeout(u,10)))(()=>{t.state.field(Cb).indexOf(s)>-1&&t.dispatch({effects:r})}),a))}}const Cb=tl.define({create(){return[]},update(t,e){for(let n of e.effects)n.is(AD)?t=[n.value].concat(t):n.is(ND)&&(t=t.filter(i=>i!=n.value));return t},provide:t=>ux.computeN([t],e=>e.field(t))}),AD=Gn.define(),ND=Gn.define();function sX(t,e,n){let i=e.content?e.content(t,()=>a(null)):null;if(!i){if(i=fs("form"),e.input){let c=fs("input",e.input);/^(text|password|number|email|tel|url)$/.test(c.type)&&c.classList.add("cm-textfield"),c.name||(c.name="input"),i.appendChild(fs("label",(e.label||"")+": ",c))}else i.appendChild(document.createTextNode(e.label||""));i.appendChild(document.createTextNode(" ")),i.appendChild(fs("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let s=i.nodeName=="FORM"?[i]:i.querySelectorAll("form");for(let c=0;c<s.length;c++){let u=s[c];u.addEventListener("keydown",d=>{d.keyCode==27?(d.preventDefault(),a(null)):d.keyCode==13&&(d.preventDefault(),a(u))}),u.addEventListener("submit",d=>{d.preventDefault(),a(u)})}let r=fs("div",i,fs("button",{onclick:()=>a(null),"aria-label":t.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));e.class&&(r.className=e.class),r.classList.add("cm-dialog");function a(c){r.contains(r.ownerDocument.activeElement)&&t.focus(),n(c)}return{dom:r,top:e.top,mount:()=>{if(e.focus){let c;typeof e.focus=="string"?c=i.querySelector(e.focus):c=i.querySelector("input")||i.querySelector("button"),c&&"select"in c?c.select():c&&"focus"in c&&c.focus()}}}}class Qc extends gh{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}Qc.prototype.elementClass="";Qc.prototype.toDOM=void 0;Qc.prototype.mapMode=na.TrackBefore;Qc.prototype.startSide=Qc.prototype.endSide=-1;Qc.prototype.point=!0;const _0=nt.define(),rX=nt.define(),b0=nt.define(),fE=nt.define({combine:t=>t.some(e=>e)});function aX(t){return[oX]}const oX=hr.fromClass(class{constructor(t){this.view=t,this.domAfter=null,this.prevViewport=t.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=t.state.facet(b0).map(e=>new mE(t,e)),this.fixed=!t.state.facet(fE);for(let e of this.gutters)e.config.side=="after"?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(t){if(this.updateGutters(t)){let e=this.prevViewport,n=t.view.viewport,i=Math.min(e.to,n.to)-Math.max(e.from,n.from);this.syncGutters(i<(n.to-n.from)*.8)}if(t.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(fE)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let n=dn.iter(this.view.state.facet(_0),this.view.viewport.from),i=[],s=this.gutters.map(r=>new lX(r,this.view.viewport,-this.view.documentPadding.top));for(let r of this.view.viewportLineBlocks)if(i.length&&(i=[]),Array.isArray(r.type)){let a=!0;for(let c of r.type)if(c.type==Bs.Text&&a){Bw(n,i,c.from);for(let u of s)u.line(this.view,c,i);a=!1}else if(c.widget)for(let u of s)u.widget(this.view,c)}else if(r.type==Bs.Text){Bw(n,i,r.from);for(let a of s)a.line(this.view,r,i)}else if(r.widget)for(let a of s)a.widget(this.view,r);for(let r of s)r.finish();t&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(t){let e=t.startState.facet(b0),n=t.state.facet(b0),i=t.docChanged||t.heightChanged||t.viewportChanged||!dn.eq(t.startState.facet(_0),t.state.facet(_0),t.view.viewport.from,t.view.viewport.to);if(e==n)for(let s of this.gutters)s.update(t)&&(i=!0);else{i=!0;let s=[];for(let r of n){let a=e.indexOf(r);a<0?s.push(new mE(this.view,r)):(this.gutters[a].update(t),s.push(this.gutters[a]))}for(let r of this.gutters)r.dom.remove(),s.indexOf(r)<0&&r.destroy();for(let r of s)r.config.side=="after"?this.getDOMAfter().appendChild(r.dom):this.dom.appendChild(r.dom);this.gutters=s}return i}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:t=>ct.scrollMargins.of(e=>{let n=e.plugin(t);if(!n||n.gutters.length==0||!n.fixed)return null;let i=n.dom.offsetWidth*e.scaleX,s=n.domAfter?n.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==di.LTR?{left:i,right:s}:{right:i,left:s}})});function pE(t){return Array.isArray(t)?t:[t]}function Bw(t,e,n){for(;t.value&&t.from<=n;)t.from==n&&e.push(t.value),t.next()}class lX{constructor(e,n,i){this.gutter=e,this.height=i,this.i=0,this.cursor=dn.iter(e.markers,n.from)}addElement(e,n,i){let{gutter:s}=this,r=(n.top-this.height)/e.scaleY,a=n.height/e.scaleY;if(this.i==s.elements.length){let c=new ED(e,a,r,i);s.elements.push(c),s.dom.appendChild(c.dom)}else s.elements[this.i].update(e,a,r,i);this.height=n.bottom,this.i++}line(e,n,i){let s=[];Bw(this.cursor,s,n.from),i.length&&(s=s.concat(i));let r=this.gutter.config.lineMarker(e,n,s);r&&s.unshift(r);let a=this.gutter;s.length==0&&!a.config.renderEmptyElements||this.addElement(e,n,s)}widget(e,n){let i=this.gutter.config.widgetMarker(e,n.widget,n),s=i?[i]:null;for(let r of e.state.facet(rX)){let a=r(e,n.widget,n);a&&(s||(s=[])).push(a)}s&&this.addElement(e,n,s)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let n=e.elements.pop();e.dom.removeChild(n.dom),n.destroy()}}}class mE{constructor(e,n){this.view=e,this.config=n,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in n.domEventHandlers)this.dom.addEventListener(i,s=>{let r=s.target,a;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let u=r.getBoundingClientRect();a=(u.top+u.bottom)/2}else a=s.clientY;let c=e.lineBlockAtHeight(a-e.documentTop);n.domEventHandlers[i](e,c,s)&&s.preventDefault()});this.markers=pE(n.markers(e)),n.initialSpacer&&(this.spacer=new ED(e,0,0,[n.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let n=this.markers;if(this.markers=pE(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let s=this.config.updateSpacer(this.spacer.markers[0],e);s!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[s])}let i=e.view.viewport;return!dn.eq(this.markers,n,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}}class ED{constructor(e,n,i,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,n,i,s)}update(e,n,i,s){this.height!=n&&(this.height=n,this.dom.style.height=n+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),cX(this.markers,s)||this.setMarkers(e,s)}setMarkers(e,n){let i="cm-gutterElement",s=this.dom.firstChild;for(let r=0,a=0;;){let c=a,u=r<n.length?n[r++]:null,d=!1;if(u){let p=u.elementClass;p&&(i+=" "+p);for(let m=a;m<this.markers.length;m++)if(this.markers[m].compare(u)){c=m,d=!0;break}}else c=this.markers.length;for(;a<c;){let p=this.markers[a++];if(p.toDOM){p.destroy(s);let m=s.nextSibling;s.remove(),s=m}}if(!u)break;u.toDOM&&(d?s=s.nextSibling:this.dom.insertBefore(u.toDOM(e),s)),d&&a++}this.dom.className=i,this.markers=n}destroy(){this.setMarkers(null,[])}}function cX(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(!t[n].compare(e[n]))return!1;return!0}const uX=nt.define(),hX=nt.define(),Fd=nt.define({combine(t){return Ah(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,n){let i=Object.assign({},e);for(let s in n){let r=i[s],a=n[s];i[s]=r?(c,u,d)=>r(c,u,d)||a(c,u,d):a}return i}})}});class jb extends Qc{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function Ab(t,e){return t.state.facet(Fd).formatNumber(e,t.state)}const dX=b0.compute([Fd],t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(uX)},lineMarker(e,n,i){return i.some(s=>s.toDOM)?null:new jb(Ab(e,e.state.doc.lineAt(n.from).number))},widgetMarker:(e,n,i)=>{for(let s of e.state.facet(hX)){let r=s(e,n,i);if(r)return r}return null},lineMarkerChange:e=>e.startState.facet(Fd)!=e.state.facet(Fd),initialSpacer(e){return new jb(Ab(e,gE(e.state.doc.lines)))},updateSpacer(e,n){let i=Ab(n.view,gE(n.view.state.doc.lines));return i==e.number?e:new jb(i)},domEventHandlers:t.facet(Fd).domEventHandlers,side:"before"}));function fX(t={}){return[Fd.of(t),aX(),dX]}function gE(t){let e=9;for(;e<t;)e=e*10+9;return e}const pX=new class extends Qc{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},mX=_0.compute(["selection"],t=>{let e=[],n=-1;for(let i of t.selection.ranges){let s=t.doc.lineAt(i.head).from;s>n&&(n=s,e.push(pX.range(s)))}return dn.of(e)});function gX(){return mX}const vX=1024;let xX=0;class ja{constructor(e,n){this.from=e,this.to=n}}class Xt{constructor(e={}){this.id=xX++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=fr.match(e)),n=>{let i=e(n);return i===void 0?null:[this,i]}}}Xt.closedBy=new Xt({deserialize:t=>t.split(" ")});Xt.openedBy=new Xt({deserialize:t=>t.split(" ")});Xt.group=new Xt({deserialize:t=>t.split(" ")});Xt.isolate=new Xt({deserialize:t=>{if(t&&t!="rtl"&&t!="ltr"&&t!="auto")throw new RangeError("Invalid value for isolate: "+t);return t||"auto"}});Xt.contextHash=new Xt({perNode:!0});Xt.lookAhead=new Xt({perNode:!0});Xt.mounted=new Xt({perNode:!0});class Zd{constructor(e,n,i,s=!1){this.tree=e,this.overlay=n,this.parser=i,this.bracketed=s}static get(e){return e&&e.props&&e.props[Xt.mounted.id]}}const yX=Object.create(null);class fr{constructor(e,n,i,s=0){this.name=e,this.props=n,this.id=i,this.flags=s}static define(e){let n=e.props&&e.props.length?Object.create(null):yX,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),s=new fr(e.name||"",n,e.id,i);if(e.props){for(let r of e.props)if(Array.isArray(r)||(r=r(s)),r){if(r[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");n[r[0].id]=r[1]}}return s}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let n=this.prop(Xt.group);return n?n.indexOf(e)>-1:!1}return this.id==e}static match(e){let n=Object.create(null);for(let i in e)for(let s of i.split(" "))n[s]=e[i];return i=>{for(let s=i.prop(Xt.group),r=-1;r<(s?s.length:0);r++){let a=n[r<0?i.name:s[r]];if(a)return a}}}}fr.none=new fr("",Object.create(null),0,8);class dC{constructor(e){this.types=e;for(let n=0;n<e.length;n++)if(e[n].id!=n)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let n=[];for(let i of this.types){let s=null;for(let r of e){let a=r(i);if(a){s||(s=Object.assign({},i.props));let c=a[1],u=a[0];u.combine&&u.id in s&&(c=u.combine(s[u.id],c)),s[u.id]=c}}n.push(s?new fr(i.name,s,i.id,i.flags):i)}return new dC(n)}}const Iv=new WeakMap,vE=new WeakMap;var Kn;(function(t){t[t.ExcludeBuffers=1]="ExcludeBuffers",t[t.IncludeAnonymous=2]="IncludeAnonymous",t[t.IgnoreMounts=4]="IgnoreMounts",t[t.IgnoreOverlays=8]="IgnoreOverlays",t[t.EnterBracketed=16]="EnterBracketed"})(Kn||(Kn={}));class Yn{constructor(e,n,i,s,r){if(this.type=e,this.children=n,this.positions=i,this.length=s,this.props=null,r&&r.length){this.props=Object.create(null);for(let[a,c]of r)this.props[typeof a=="number"?a:a.id]=c}}toString(){let e=Zd.get(this);if(e&&!e.overlay)return e.tree.toString();let n="";for(let i of this.children){let s=i.toString();s&&(n&&(n+=","),n+=s)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(n.length?"("+n+")":""):n}cursor(e=0){return new hx(this.topNode,e)}cursorAt(e,n=0,i=0){let s=Iv.get(this)||this.topNode,r=new hx(s);return r.moveTo(e,n),Iv.set(this,r._tree),r}get topNode(){return new Ws(this,0,0,null)}resolve(e,n=0){let i=Dm(Iv.get(this)||this.topNode,e,n,!1);return Iv.set(this,i),i}resolveInner(e,n=0){let i=Dm(vE.get(this)||this.topNode,e,n,!0);return vE.set(this,i),i}resolveStack(e,n=0){return wX(this,e,n)}iterate(e){let{enter:n,leave:i,from:s=0,to:r=this.length}=e,a=e.mode||0,c=(a&Kn.IncludeAnonymous)>0;for(let u=this.cursor(a|Kn.IncludeAnonymous);;){let d=!1;if(u.from<=r&&u.to>=s&&(!c&&u.type.isAnonymous||n(u)!==!1)){if(u.firstChild())continue;d=!0}for(;d&&i&&(c||!u.type.isAnonymous)&&i(u),!u.nextSibling();){if(!u.parent())return;d=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let n in this.props)e.push([+n,this.props[n]]);return e}balance(e={}){return this.children.length<=8?this:mC(fr.none,this.children,this.positions,0,this.children.length,0,this.length,(n,i,s)=>new Yn(this.type,n,i,s,this.propValues),e.makeTree||((n,i,s)=>new Yn(fr.none,n,i,s)))}static build(e){return kX(e)}}Yn.empty=new Yn(fr.none,[],[],0);class fC{constructor(e,n){this.buffer=e,this.index=n}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new fC(this.buffer,this.index)}}class Zc{constructor(e,n,i){this.buffer=e,this.length=n,this.set=i}get type(){return fr.none}toString(){let e=[];for(let n=0;n<this.buffer.length;)e.push(this.childString(n)),n=this.buffer[n+3];return e.join(",")}childString(e){let n=this.buffer[e],i=this.buffer[e+3],s=this.set.types[n],r=s.name;if(/\W/.test(r)&&!s.isError&&(r=JSON.stringify(r)),e+=4,i==e)return r;let a=[];for(;e<i;)a.push(this.childString(e)),e=this.buffer[e+3];return r+"("+a.join(",")+")"}findChild(e,n,i,s,r){let{buffer:a}=this,c=-1;for(let u=e;u!=n&&!(MD(r,s,a[u+1],a[u+2])&&(c=u,i>0));u=a[u+3]);return c}slice(e,n,i){let s=this.buffer,r=new Uint16Array(n-e),a=0;for(let c=e,u=0;c<n;){r[u++]=s[c++],r[u++]=s[c++]-i;let d=r[u++]=s[c++]-i;r[u++]=s[c++]-e,a=Math.max(a,d)}return new Zc(r,a,this.set)}}function MD(t,e,n,i){switch(t){case-2:return n<e;case-1:return i>=e&&n<e;case 0:return n<e&&i>e;case 1:return n<=e&&i>e;case 2:return i>e;case 4:return!0}}function Dm(t,e,n,i){for(var s;t.from==t.to||(n<1?t.from>=e:t.from>e)||(n>-1?t.to<=e:t.to<e);){let a=!i&&t instanceof Ws&&t.index<0?null:t.parent;if(!a)return t;t=a}let r=i?0:Kn.IgnoreOverlays;if(i)for(let a=t,c=a.parent;c;a=c,c=a.parent)a instanceof Ws&&a.index<0&&((s=c.enter(e,n,r))===null||s===void 0?void 0:s.from)!=a.from&&(t=c);for(;;){let a=t.enter(e,n,r);if(!a)return t;t=a}}class LD{cursor(e=0){return new hx(this,e)}getChild(e,n=null,i=null){let s=xE(this,e,n,i);return s.length?s[0]:null}getChildren(e,n=null,i=null){return xE(this,e,n,i)}resolve(e,n=0){return Dm(this,e,n,!1)}resolveInner(e,n=0){return Dm(this,e,n,!0)}matchContext(e){return Ow(this.parent,e)}enterUnfinishedNodesBefore(e){let n=this.childBefore(e),i=this;for(;n;){let s=n.lastChild;if(!s||s.to!=n.to)break;s.type.isError&&s.from==s.to?(i=n,n=s.prevSibling):n=s}return i}get node(){return this}get next(){return this.parent}}class Ws extends LD{constructor(e,n,i,s){super(),this._tree=e,this.from=n,this.index=i,this._parent=s}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,n,i,s,r=0){for(let a=this;;){for(let{children:c,positions:u}=a._tree,d=n>0?c.length:-1;e!=d;e+=n){let p=c[e],m=u[e]+a.from,v;if(!(!(r&Kn.EnterBracketed&&p instanceof Yn&&(v=Zd.get(p))&&!v.overlay&&v.bracketed&&i>=m&&i<=m+p.length)&&!MD(s,i,m,m+p.length))){if(p instanceof Zc){if(r&Kn.ExcludeBuffers)continue;let x=p.findChild(0,p.buffer.length,n,i-m,s);if(x>-1)return new Ho(new _X(a,p,e,m),null,x)}else if(r&Kn.IncludeAnonymous||!p.type.isAnonymous||pC(p)){let x;if(!(r&Kn.IgnoreMounts)&&(x=Zd.get(p))&&!x.overlay)return new Ws(x.tree,m,e,a);let y=new Ws(p,m,e,a);return r&Kn.IncludeAnonymous||!y.type.isAnonymous?y:y.nextChild(n<0?p.children.length-1:0,n,i,s,r)}}}if(r&Kn.IncludeAnonymous||!a.type.isAnonymous||(a.index>=0?e=a.index+n:e=n<0?-1:a._parent._tree.children.length,a=a._parent,!a))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,n,i=0){let s;if(!(i&Kn.IgnoreOverlays)&&(s=Zd.get(this._tree))&&s.overlay){let r=e-this.from,a=i&Kn.EnterBracketed&&s.bracketed;for(let{from:c,to:u}of s.overlay)if((n>0||a?c<=r:c<r)&&(n<0||a?u>=r:u>r))return new Ws(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,n,i)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function xE(t,e,n,i){let s=t.cursor(),r=[];if(!s.firstChild())return r;if(n!=null){for(let a=!1;!a;)if(a=s.type.is(n),!s.nextSibling())return r}for(;;){if(i!=null&&s.type.is(i))return r;if(s.type.is(e)&&r.push(s.node),!s.nextSibling())return i==null?r:[]}}function Ow(t,e,n=e.length-1){for(let i=t;n>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(e[n]&&e[n]!=i.name)return!1;n--}}return!0}class _X{constructor(e,n,i,s){this.parent=e,this.buffer=n,this.index=i,this.start=s}}class Ho extends LD{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,n,i){super(),this.context=e,this._parent=n,this.index=i,this.type=e.buffer.set.types[e.buffer.buffer[i]]}child(e,n,i){let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],e,n-this.context.start,i);return r<0?null:new Ho(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,n,i=0){if(i&Kn.ExcludeBuffers)return null;let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],n>0?1:-1,e-this.context.start,n);return r<0?null:new Ho(this.context,this,r)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,n=e.buffer[this.index+3];return n<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new Ho(this.context,this._parent,n):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,n=this._parent?this._parent.index+4:0;return this.index==n?this.externalSibling(-1):new Ho(this.context,this._parent,e.findChild(n,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],n=[],{buffer:i}=this.context,s=this.index+4,r=i.buffer[this.index+3];if(r>s){let a=i.buffer[this.index+1];e.push(i.slice(s,r,a)),n.push(0)}return new Yn(this.type,e,n,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function TD(t){if(!t.length)return null;let e=0,n=t[0];for(let r=1;r<t.length;r++){let a=t[r];(a.from>n.from||a.to<n.to)&&(n=a,e=r)}let i=n instanceof Ws&&n.index<0?null:n.parent,s=t.slice();return i?s[e]=i:s.splice(e,1),new bX(s,n)}class bX{constructor(e,n){this.heads=e,this.node=n}get next(){return TD(this.heads)}}function wX(t,e,n){let i=t.resolveInner(e,n),s=null;for(let r=i instanceof Ws?i:i.context.parent;r;r=r.parent)if(r.index<0){let a=r.parent;(s||(s=[i])).push(a.resolve(e,n)),r=a}else{let a=Zd.get(r.tree);if(a&&a.overlay&&a.overlay[0].from<=e&&a.overlay[a.overlay.length-1].to>=e){let c=new Ws(a.tree,a.overlay[0].from+r.from,-1,r);(s||(s=[i])).push(Dm(c,e,n,!1))}}return s?TD(s):i}class hx{get name(){return this.type.name}constructor(e,n=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=n&~Kn.EnterBracketed,e instanceof Ws)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let i=e._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,n){this.index=e;let{start:i,buffer:s}=this.buffer;return this.type=n||s.set.types[s.buffer[e]],this.from=i+s.buffer[e+1],this.to=i+s.buffer[e+2],!0}yield(e){return e?e instanceof Ws?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,n,i){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,n,i,this.mode));let{buffer:s}=this.buffer,r=s.findChild(this.index+4,s.buffer[this.index+3],e,n-this.buffer.start,i);return r<0?!1:(this.stack.push(this.index),this.yieldBuf(r))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,n,i=this.mode){return this.buffer?i&Kn.ExcludeBuffers?!1:this.enterChild(1,e,n):this.yield(this._tree.enter(e,n,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&Kn.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&Kn.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:n}=this.buffer,i=this.stack.length-1;if(e<0){let s=i<0?0:this.stack[i]+4;if(this.index!=s)return this.yieldBuf(n.findChild(s,this.index,-1,0,4))}else{let s=n.buffer[this.index+3];if(s<(i<0?n.buffer.length:n.buffer[this.stack[i]+3]))return this.yieldBuf(s)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let n,i,{buffer:s}=this;if(s){if(e>0){if(this.index<s.buffer.buffer.length)return!1}else for(let r=0;r<this.index;r++)if(s.buffer.buffer[r+3]<this.index)return!1;({index:n,parent:i}=s)}else({index:n,_parent:i}=this._tree);for(;i;{index:n,_parent:i}=i)if(n>-1)for(let r=n+e,a=e<0?-1:i._tree.children.length;r!=a;r+=e){let c=i._tree.children[r];if(this.mode&Kn.IncludeAnonymous||c instanceof Zc||!c.type.isAnonymous||pC(c))return!1}return!0}move(e,n){if(n&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,n=0){for(;(this.from==this.to||(n<1?this.from>=e:this.from>e)||(n>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,n););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,n=null,i=0;if(e&&e.context==this.buffer)e:for(let s=this.index,r=this.stack.length;r>=0;){for(let a=e;a;a=a._parent)if(a.index==s){if(s==this.index)return a;n=a,i=r+1;break e}s=this.stack[--r]}for(let s=i;s<this.stack.length;s++)n=new Ho(this.buffer,n,this.stack[s]);return this.bufferNode=new Ho(this.buffer,n,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,n){for(let i=0;;){let s=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(s=!0)}for(;;){if(s&&n&&n(this),s=this.type.isAnonymous,!i)return;if(this.nextSibling())break;this.parent(),i--,s=!0}}}matchContext(e){if(!this.buffer)return Ow(this.node.parent,e);let{buffer:n}=this.buffer,{types:i}=n.set;for(let s=e.length-1,r=this.stack.length-1;s>=0;r--){if(r<0)return Ow(this._tree,e,s);let a=i[n.buffer[this.stack[r]]];if(!a.isAnonymous){if(e[s]&&e[s]!=a.name)return!1;s--}}return!0}}function pC(t){return t.children.some(e=>e instanceof Zc||!e.type.isAnonymous||pC(e))}function kX(t){var e;let{buffer:n,nodeSet:i,maxBufferLength:s=vX,reused:r=[],minRepeatType:a=i.types.length}=t,c=Array.isArray(n)?new fC(n,n.length):n,u=i.types,d=0,p=0;function m(M,L,$,V,X,D){let{id:Q,start:P,end:z,size:H}=c,W=p,F=d;if(H<0)if(c.next(),H==-1){let U=r[Q];$.push(U),V.push(P-M);return}else if(H==-3){d=Q;return}else if(H==-4){p=Q;return}else throw new RangeError(`Unrecognized record size: ${H}`);let Y=u[Q],J,te,I=P-M;if(z-P<=s&&(te=S(c.pos-L,X))){let U=new Uint16Array(te.size-te.skip),Z=c.pos-te.size,R=U.length;for(;c.pos>Z;)R=C(te.start,U,R);J=new Zc(U,z-te.start,i),I=te.start-M}else{let U=c.pos-H;c.next();let Z=[],R=[],K=Q>=a?Q:-1,O=0,ie=z;for(;c.pos>U;)K>=0&&c.id==K&&c.size>=0?(c.end<=ie-s&&(y(Z,R,P,O,c.end,ie,K,W,F),O=Z.length,ie=c.end),c.next()):D>2500?v(P,U,Z,R):m(P,U,Z,R,K,D+1);if(K>=0&&O>0&&O<Z.length&&y(Z,R,P,O,P,ie,K,W,F),Z.reverse(),R.reverse(),K>-1&&O>0){let re=x(Y,F);J=mC(Y,Z,R,0,Z.length,0,z-P,re,re)}else J=k(Y,Z,R,z-P,W-z,F)}$.push(J),V.push(I)}function v(M,L,$,V){let X=[],D=0,Q=-1;for(;c.pos>L;){let{id:P,start:z,end:H,size:W}=c;if(W>4)c.next();else{if(Q>-1&&z<Q)break;Q<0&&(Q=H-s),X.push(P,z,H),D++,c.next()}}if(D){let P=new Uint16Array(D*4),z=X[X.length-2];for(let H=X.length-3,W=0;H>=0;H-=3)P[W++]=X[H],P[W++]=X[H+1]-z,P[W++]=X[H+2]-z,P[W++]=W;$.push(new Zc(P,X[2]-z,i)),V.push(z-M)}}function x(M,L){return($,V,X)=>{let D=0,Q=$.length-1,P,z;if(Q>=0&&(P=$[Q])instanceof Yn){if(!Q&&P.type==M&&P.length==X)return P;(z=P.prop(Xt.lookAhead))&&(D=V[Q]+P.length+z)}return k(M,$,V,X,D,L)}}function y(M,L,$,V,X,D,Q,P,z){let H=[],W=[];for(;M.length>V;)H.push(M.pop()),W.push(L.pop()+$-X);M.push(k(i.types[Q],H,W,D-X,P-D,z)),L.push(X-$)}function k(M,L,$,V,X,D,Q){if(D){let P=[Xt.contextHash,D];Q=Q?[P].concat(Q):[P]}if(X>25){let P=[Xt.lookAhead,X];Q=Q?[P].concat(Q):[P]}return new Yn(M,L,$,V,Q)}function S(M,L){let $=c.fork(),V=0,X=0,D=0,Q=$.end-s,P={size:0,start:0,skip:0};e:for(let z=$.pos-M;$.pos>z;){let H=$.size;if($.id==L&&H>=0){P.size=V,P.start=X,P.skip=D,D+=4,V+=4,$.next();continue}let W=$.pos-H;if(H<0||W<z||$.start<Q)break;let F=$.id>=a?4:0,Y=$.start;for($.next();$.pos>W;){if($.size<0)if($.size==-3||$.size==-4)F+=4;else break e;else $.id>=a&&(F+=4);$.next()}X=Y,V+=H,D+=F}return(L<0||V==M)&&(P.size=V,P.start=X,P.skip=D),P.size>4?P:void 0}function C(M,L,$){let{id:V,start:X,end:D,size:Q}=c;if(c.next(),Q>=0&&V<a){let P=$;if(Q>4){let z=c.pos-(Q-4);for(;c.pos>z;)$=C(M,L,$)}L[--$]=P,L[--$]=D-M,L[--$]=X-M,L[--$]=V}else Q==-3?d=V:Q==-4&&(p=V);return $}let A=[],N=[];for(;c.pos>0;)m(t.start||0,t.bufferStart||0,A,N,-1,0);let E=(e=t.length)!==null&&e!==void 0?e:A.length?N[0]+A[0].length:0;return new Yn(u[t.topID],A.reverse(),N.reverse(),E)}const yE=new WeakMap;function w0(t,e){if(!t.isAnonymous||e instanceof Zc||e.type!=t)return 1;let n=yE.get(e);if(n==null){n=1;for(let i of e.children){if(i.type!=t||!(i instanceof Yn)){n=1;break}n+=w0(t,i)}yE.set(e,n)}return n}function mC(t,e,n,i,s,r,a,c,u){let d=0;for(let y=i;y<s;y++)d+=w0(t,e[y]);let p=Math.ceil(d*1.5/8),m=[],v=[];function x(y,k,S,C,A){for(let N=S;N<C;){let E=N,M=k[N],L=w0(t,y[N]);for(N++;N<C;N++){let $=w0(t,y[N]);if(L+$>=p)break;L+=$}if(N==E+1){if(L>p){let $=y[E];x($.children,$.positions,0,$.children.length,k[E]+A);continue}m.push(y[E])}else{let $=k[N-1]+y[N-1].length-M;m.push(mC(t,y,k,E,N,M,$,null,u))}v.push(M+A-r)}}return x(e,n,i,s,0),(c||u)(m,v,a)}class Dme{constructor(){this.map=new WeakMap}setBuffer(e,n,i){let s=this.map.get(e);s||this.map.set(e,s=new Map),s.set(n,i)}getBuffer(e,n){let i=this.map.get(e);return i&&i.get(n)}set(e,n){e instanceof Ho?this.setBuffer(e.context.buffer,e.index,n):e instanceof Ws&&this.map.set(e.tree,n)}get(e){return e instanceof Ho?this.getBuffer(e.context.buffer,e.index):e instanceof Ws?this.map.get(e.tree):void 0}cursorSet(e,n){e.buffer?this.setBuffer(e.buffer.buffer,e.index,n):this.map.set(e.tree,n)}cursorGet(e){return e.buffer?this.getBuffer(e.buffer.buffer,e.index):this.map.get(e.tree)}}class Wl{constructor(e,n,i,s,r=!1,a=!1){this.from=e,this.to=n,this.tree=i,this.offset=s,this.open=(r?1:0)|(a?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,n=[],i=!1){let s=[new Wl(0,e.length,e,0,!1,i)];for(let r of n)r.to>e.length&&s.push(r);return s}static applyChanges(e,n,i=128){if(!n.length)return e;let s=[],r=1,a=e.length?e[0]:null;for(let c=0,u=0,d=0;;c++){let p=c<n.length?n[c]:null,m=p?p.fromA:1e9;if(m-u>=i)for(;a&&a.from<m;){let v=a;if(u>=v.from||m<=v.to||d){let x=Math.max(v.from,u)-d,y=Math.min(v.to,m)-d;v=x>=y?null:new Wl(x,y,v.tree,v.offset+d,c>0,!!p)}if(v&&s.push(v),a.to>m)break;a=r<e.length?e[r++]:null}if(!p)break;u=p.toA,d=p.toA-p.toB}return s}}class RD{startParse(e,n,i){return typeof e=="string"&&(e=new SX(e)),i=i?i.length?i.map(s=>new ja(s.from,s.to)):[new ja(0,0)]:[new ja(0,e.length)],this.createParse(e,n||[],i)}parse(e,n,i){let s=this.startParse(e,n,i);for(;;){let r=s.advance();if(r)return r}}}class SX{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,n){return this.string.slice(e,n)}}function Bme(t){return(e,n,i,s)=>new jX(e,t,n,i,s)}class _E{constructor(e,n,i,s,r,a){this.parser=e,this.parse=n,this.overlay=i,this.bracketed=s,this.target=r,this.from=a}}function bE(t){if(!t.length||t.some(e=>e.from>=e.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(t))}class CX{constructor(e,n,i,s,r,a,c,u){this.parser=e,this.predicate=n,this.mounts=i,this.index=s,this.start=r,this.bracketed=a,this.target=c,this.prev=u,this.depth=0,this.ranges=[]}}const Iw=new Xt({perNode:!0});class jX{constructor(e,n,i,s,r){this.nest=n,this.input=i,this.fragments=s,this.ranges=r,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}advance(){if(this.baseParse){let i=this.baseParse.advance();if(!i)return null;if(this.baseParse=null,this.baseTree=i,this.startInner(),this.stoppedAt!=null)for(let s of this.inner)s.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let i=this.baseTree;return this.stoppedAt!=null&&(i=new Yn(i.type,i.children,i.positions,i.length,i.propValues.concat([[Iw,this.stoppedAt]]))),i}let e=this.inner[this.innerDone],n=e.parse.advance();if(n){this.innerDone++;let i=Object.assign(Object.create(null),e.target.props);i[Xt.mounted.id]=new Zd(n,e.overlay,e.parser,e.bracketed),e.target.props=i}return null}get parsedPos(){if(this.baseParse)return 0;let e=this.input.length;for(let n=this.innerDone;n<this.inner.length;n++)this.inner[n].from<e&&(e=Math.min(e,this.inner[n].parse.parsedPos));return e}stopAt(e){if(this.stoppedAt=e,this.baseParse)this.baseParse.stopAt(e);else for(let n=this.innerDone;n<this.inner.length;n++)this.inner[n].parse.stopAt(e)}startInner(){let e=new EX(this.fragments),n=null,i=null,s=new hx(new Ws(this.baseTree,this.ranges[0].from,0,null),Kn.IncludeAnonymous|Kn.IgnoreMounts);e:for(let r,a;;){let c=!0,u;if(this.stoppedAt!=null&&s.from>=this.stoppedAt)c=!1;else if(e.hasNode(s)){if(n){let d=n.mounts.find(p=>p.frag.from<=s.from&&p.frag.to>=s.to&&p.mount.overlay);if(d)for(let p of d.mount.overlay){let m=p.from+d.pos,v=p.to+d.pos;m>=s.from&&v<=s.to&&!n.ranges.some(x=>x.from<v&&x.to>m)&&n.ranges.push({from:m,to:v})}}c=!1}else if(i&&(a=AX(i.ranges,s.from,s.to)))c=a!=2;else if(!s.type.isAnonymous&&(r=this.nest(s,this.input))&&(s.from<s.to||!r.overlay)){s.tree||(NX(s),n&&n.depth++,i&&i.depth++);let d=e.findMounts(s.from,r.parser);if(typeof r.overlay=="function")n=new CX(r.parser,r.overlay,d,this.inner.length,s.from,!!r.bracketed,s.tree,n);else{let p=SE(this.ranges,r.overlay||(s.from<s.to?[new ja(s.from,s.to)]:[]));p.length&&bE(p),(p.length||!r.overlay)&&this.inner.push(new _E(r.parser,p.length?r.parser.startParse(this.input,CE(d,p),p):r.parser.startParse(""),r.overlay?r.overlay.map(m=>new ja(m.from-s.from,m.to-s.from)):null,!!r.bracketed,s.tree,p.length?p[0].from:s.from)),r.overlay?p.length&&(i={ranges:p,depth:0,prev:i}):c=!1}}else if(n&&(u=n.predicate(s))&&(u===!0&&(u=new ja(s.from,s.to)),u.from<u.to)){let d=n.ranges.length-1;d>=0&&n.ranges[d].to==u.from?n.ranges[d]={from:n.ranges[d].from,to:u.to}:n.ranges.push(u)}if(c&&s.firstChild())n&&n.depth++,i&&i.depth++;else for(;!s.nextSibling();){if(!s.parent())break e;if(n&&!--n.depth){let d=SE(this.ranges,n.ranges);d.length&&(bE(d),this.inner.splice(n.index,0,new _E(n.parser,n.parser.startParse(this.input,CE(n.mounts,d),d),n.ranges.map(p=>new ja(p.from-n.start,p.to-n.start)),n.bracketed,n.target,d[0].from))),n=n.prev}i&&!--i.depth&&(i=i.prev)}}}}function AX(t,e,n){for(let i of t){if(i.from>=n)break;if(i.to>e)return i.from<=e&&i.to>=n?2:1}return 0}function wE(t,e,n,i,s,r){if(e<n){let a=t.buffer[e+1];i.push(t.slice(e,n,a)),s.push(a-r)}}function NX(t){let{node:e}=t,n=[],i=e.context.buffer;do n.push(t.index),t.parent();while(!t.tree);let s=t.tree,r=s.children.indexOf(i),a=s.children[r],c=a.buffer,u=[r];function d(p,m,v,x,y,k){let S=n[k],C=[],A=[];wE(a,p,S,C,A,x);let N=c[S+1],E=c[S+2];u.push(C.length);let M=k?d(S+4,c[S+3],a.set.types[c[S]],N,E-N,k-1):e.toTree();return C.push(M),A.push(N-x),wE(a,c[S+3],m,C,A,x),new Yn(v,C,A,y)}s.children[r]=d(0,c.length,fr.none,0,a.length,n.length-1);for(let p of u){let m=t.tree.children[p],v=t.tree.positions[p];t.yield(new Ws(m,v+t.from,p,t._tree))}}class kE{constructor(e,n){this.offset=n,this.done=!1,this.cursor=e.cursor(Kn.IncludeAnonymous|Kn.IgnoreMounts)}moveTo(e){let{cursor:n}=this,i=e-this.offset;for(;!this.done&&n.from<i;)if(!(n.to>=e&&n.enter(i,1,Kn.IgnoreOverlays|Kn.ExcludeBuffers)))if(n.to<=e)n.next(!1)||(this.done=!0);else break}hasNode(e){if(this.moveTo(e.from),!this.done&&this.cursor.from+this.offset==e.from&&this.cursor.tree)for(let n=this.cursor.tree;;){if(n==e.tree)return!0;if(n.children.length&&n.positions[0]==0&&n.children[0]instanceof Yn)n=n.children[0];else break}return!1}}class EX{constructor(e){var n;if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let i=this.curFrag=e[0];this.curTo=(n=i.tree.prop(Iw))!==null&&n!==void 0?n:i.to,this.inner=new kE(i.tree,-i.offset)}else this.curFrag=this.inner=null}hasNode(e){for(;this.curFrag&&e.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=e.from&&this.curTo>=e.to&&this.inner.hasNode(e)}nextFrag(){var e;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let n=this.curFrag=this.fragments[this.fragI];this.curTo=(e=n.tree.prop(Iw))!==null&&e!==void 0?e:n.to,this.inner=new kE(n.tree,-n.offset)}}findMounts(e,n){var i;let s=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let r=this.inner.cursor.node;r;r=r.parent){let a=(i=r.tree)===null||i===void 0?void 0:i.prop(Xt.mounted);if(a&&a.parser==n)for(let c=this.fragI;c<this.fragments.length;c++){let u=this.fragments[c];if(u.from>=r.to)break;u.tree==this.curFrag.tree&&s.push({frag:u,pos:r.from-u.offset,mount:a})}}}return s}}function SE(t,e){let n=null,i=e;for(let s=1,r=0;s<t.length;s++){let a=t[s-1].to,c=t[s].from;for(;r<i.length;r++){let u=i[r];if(u.from>=c)break;u.to<=a||(n||(i=n=e.slice()),u.from<a?(n[r]=new ja(u.from,a),u.to>c&&n.splice(r+1,0,new ja(c,u.to))):u.to>c?n[r--]=new ja(c,u.to):n.splice(r--,1))}}return i}function MX(t,e,n,i){let s=0,r=0,a=!1,c=!1,u=-1e9,d=[];for(;;){let p=s==t.length?1e9:a?t[s].to:t[s].from,m=r==e.length?1e9:c?e[r].to:e[r].from;if(a!=c){let v=Math.max(u,n),x=Math.min(p,m,i);v<x&&d.push(new ja(v,x))}if(u=Math.min(p,m),u==1e9)break;p==u&&(a?(a=!1,s++):a=!0),m==u&&(c?(c=!1,r++):c=!0)}return d}function CE(t,e){let n=[];for(let{pos:i,mount:s,frag:r}of t){let a=i+(s.overlay?s.overlay[0].from:0),c=a+s.tree.length,u=Math.max(r.from,a),d=Math.min(r.to,c);if(s.overlay){let p=s.overlay.map(v=>new ja(v.from+i,v.to+i)),m=MX(e,p,u,d);for(let v=0,x=u;;v++){let y=v==m.length,k=y?d:m[v].from;if(k>x&&n.push(new Wl(x,k,s.tree,-a,r.from>=x||r.openStart,r.to<=k||r.openEnd)),y)break;x=m[v].to}}else n.push(new Wl(u,d,s.tree,-a,r.from>=a||r.openStart,r.to<=c||r.openEnd))}return n}let LX=0;class ka{constructor(e,n,i,s){this.name=e,this.set=n,this.base=i,this.modified=s,this.id=LX++}toString(){let{name:e}=this;for(let n of this.modified)n.name&&(e=`${n.name}(${e})`);return e}static define(e,n){let i=typeof e=="string"?e:"?";if(e instanceof ka&&(n=e),n?.base)throw new Error("Can not derive from a modified tag");let s=new ka(i,[],null,[]);if(s.set.push(s),n)for(let r of n.set)s.set.push(r);return s}static defineModifier(e){let n=new dx(e);return i=>i.modified.indexOf(n)>-1?i:dx.get(i.base||i,i.modified.concat(n).sort((s,r)=>s.id-r.id))}}let TX=0;class dx{constructor(e){this.name=e,this.instances=[],this.id=TX++}static get(e,n){if(!n.length)return e;let i=n[0].instances.find(c=>c.base==e&&RX(n,c.modified));if(i)return i;let s=[],r=new ka(e.name,s,e,n);for(let c of n)c.instances.push(r);let a=DX(n);for(let c of e.set)if(!c.modified.length)for(let u of a)s.push(dx.get(c,u));return r}}function RX(t,e){return t.length==e.length&&t.every((n,i)=>n==e[i])}function DX(t){let e=[[]];for(let n=0;n<t.length;n++)for(let i=0,s=e.length;i<s;i++)e.push(e[i].concat(t[n]));return e.sort((n,i)=>i.length-n.length)}function BX(t){let e=Object.create(null);for(let n in t){let i=t[n];Array.isArray(i)||(i=[i]);for(let s of n.split(" "))if(s){let r=[],a=2,c=s;for(let m=0;;){if(c=="..."&&m>0&&m+3==s.length){a=1;break}let v=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(c);if(!v)throw new RangeError("Invalid path: "+s);if(r.push(v[0]=="*"?"":v[0][0]=='"'?JSON.parse(v[0]):v[0]),m+=v[0].length,m==s.length)break;let x=s[m++];if(m==s.length&&x=="!"){a=0;break}if(x!="/")throw new RangeError("Invalid path: "+s);c=s.slice(m)}let u=r.length-1,d=r[u];if(!d)throw new RangeError("Invalid path: "+s);let p=new Bm(i,a,u>0?r.slice(0,u):null);e[d]=p.sort(e[d])}}return DD.add(e)}const DD=new Xt({combine(t,e){let n,i,s;for(;t||e;){if(!t||e&&t.depth>=e.depth?(s=e,e=e.next):(s=t,t=t.next),n&&n.mode==s.mode&&!s.context&&!n.context)continue;let r=new Bm(s.tags,s.mode,s.context);n?n.next=r:i=r,n=r}return i}});class Bm{constructor(e,n,i,s){this.tags=e,this.mode=n,this.context=i,this.next=s}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}}Bm.empty=new Bm([],2,null);function BD(t,e){let n=Object.create(null);for(let r of t)if(!Array.isArray(r.tag))n[r.tag.id]=r.class;else for(let a of r.tag)n[a.id]=r.class;let{scope:i,all:s=null}=e||{};return{style:r=>{let a=s;for(let c of r)for(let u of c.set){let d=n[u.id];if(d){a=a?a+" "+d:d;break}}return a},scope:i}}function OX(t,e){let n=null;for(let i of t){let s=i.style(e);s&&(n=n?n+" "+s:s)}return n}function IX(t,e,n,i=0,s=t.length){let r=new $X(i,Array.isArray(e)?e:[e],n);r.highlightRange(t.cursor(),i,s,"",r.highlighters),r.flush(s)}class $X{constructor(e,n,i){this.at=e,this.highlighters=n,this.span=i,this.class=""}startSpan(e,n){n!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=n)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,n,i,s,r){let{type:a,from:c,to:u}=e;if(c>=i||u<=n)return;a.isTop&&(r=this.highlighters.filter(x=>!x.scope||x.scope(a)));let d=s,p=PX(e)||Bm.empty,m=OX(r,p.tags);if(m&&(d&&(d+=" "),d+=m,p.mode==1&&(s+=(s?" ":"")+m)),this.startSpan(Math.max(n,c),d),p.opaque)return;let v=e.tree&&e.tree.prop(Xt.mounted);if(v&&v.overlay){let x=e.node.enter(v.overlay[0].from+c,1),y=this.highlighters.filter(S=>!S.scope||S.scope(v.tree.type)),k=e.firstChild();for(let S=0,C=c;;S++){let A=S<v.overlay.length?v.overlay[S]:null,N=A?A.from+c:u,E=Math.max(n,C),M=Math.min(i,N);if(E<M&&k)for(;e.from<M&&(this.highlightRange(e,E,M,s,r),this.startSpan(Math.min(M,e.to),d),!(e.to>=N||!e.nextSibling())););if(!A||N>i)break;C=A.to+c,C>n&&(this.highlightRange(x.cursor(),Math.max(n,A.from+c),Math.min(i,C),"",y),this.startSpan(Math.min(i,C),d))}k&&e.parent()}else if(e.firstChild()){v&&(s="");do if(!(e.to<=n)){if(e.from>=i)break;this.highlightRange(e,n,i,s,r),this.startSpan(Math.min(i,e.to),d)}while(e.nextSibling());e.parent()}}}function PX(t){let e=t.type.prop(DD);for(;e&&e.context&&!t.matchContext(e.context);)e=e.next;return e||null}const Ue=ka.define,$v=Ue(),Dc=Ue(),jE=Ue(Dc),AE=Ue(Dc),Bc=Ue(),Pv=Ue(Bc),Nb=Ue(Bc),Do=Ue(),zu=Ue(Do),Eo=Ue(),Mo=Ue(),$w=Ue(),Fp=Ue($w),zv=Ue(),He={comment:$v,lineComment:Ue($v),blockComment:Ue($v),docComment:Ue($v),name:Dc,variableName:Ue(Dc),typeName:jE,tagName:Ue(jE),propertyName:AE,attributeName:Ue(AE),className:Ue(Dc),labelName:Ue(Dc),namespace:Ue(Dc),macroName:Ue(Dc),literal:Bc,string:Pv,docString:Ue(Pv),character:Ue(Pv),attributeValue:Ue(Pv),number:Nb,integer:Ue(Nb),float:Ue(Nb),bool:Ue(Bc),regexp:Ue(Bc),escape:Ue(Bc),color:Ue(Bc),url:Ue(Bc),keyword:Eo,self:Ue(Eo),null:Ue(Eo),atom:Ue(Eo),unit:Ue(Eo),modifier:Ue(Eo),operatorKeyword:Ue(Eo),controlKeyword:Ue(Eo),definitionKeyword:Ue(Eo),moduleKeyword:Ue(Eo),operator:Mo,derefOperator:Ue(Mo),arithmeticOperator:Ue(Mo),logicOperator:Ue(Mo),bitwiseOperator:Ue(Mo),compareOperator:Ue(Mo),updateOperator:Ue(Mo),definitionOperator:Ue(Mo),typeOperator:Ue(Mo),controlOperator:Ue(Mo),punctuation:$w,separator:Ue($w),bracket:Fp,angleBracket:Ue(Fp),squareBracket:Ue(Fp),paren:Ue(Fp),brace:Ue(Fp),content:Do,heading:zu,heading1:Ue(zu),heading2:Ue(zu),heading3:Ue(zu),heading4:Ue(zu),heading5:Ue(zu),heading6:Ue(zu),contentSeparator:Ue(Do),list:Ue(Do),quote:Ue(Do),emphasis:Ue(Do),strong:Ue(Do),link:Ue(Do),monospace:Ue(Do),strikethrough:Ue(Do),inserted:Ue(),deleted:Ue(),changed:Ue(),invalid:Ue(),meta:zv,documentMeta:Ue(zv),annotation:Ue(zv),processingInstruction:Ue(zv),definition:ka.defineModifier("definition"),constant:ka.defineModifier("constant"),function:ka.defineModifier("function"),standard:ka.defineModifier("standard"),local:ka.defineModifier("local"),special:ka.defineModifier("special")};for(let t in He){let e=He[t];e instanceof ka&&(e.name=t)}BD([{tag:He.link,class:"tok-link"},{tag:He.heading,class:"tok-heading"},{tag:He.emphasis,class:"tok-emphasis"},{tag:He.strong,class:"tok-strong"},{tag:He.keyword,class:"tok-keyword"},{tag:He.atom,class:"tok-atom"},{tag:He.bool,class:"tok-bool"},{tag:He.url,class:"tok-url"},{tag:He.labelName,class:"tok-labelName"},{tag:He.inserted,class:"tok-inserted"},{tag:He.deleted,class:"tok-deleted"},{tag:He.literal,class:"tok-literal"},{tag:He.string,class:"tok-string"},{tag:He.number,class:"tok-number"},{tag:[He.regexp,He.escape,He.special(He.string)],class:"tok-string2"},{tag:He.variableName,class:"tok-variableName"},{tag:He.local(He.variableName),class:"tok-variableName tok-local"},{tag:He.definition(He.variableName),class:"tok-variableName tok-definition"},{tag:He.special(He.variableName),class:"tok-variableName2"},{tag:He.definition(He.propertyName),class:"tok-propertyName tok-definition"},{tag:He.typeName,class:"tok-typeName"},{tag:He.namespace,class:"tok-namespace"},{tag:He.className,class:"tok-className"},{tag:He.macroName,class:"tok-macroName"},{tag:He.propertyName,class:"tok-propertyName"},{tag:He.operator,class:"tok-operator"},{tag:He.comment,class:"tok-comment"},{tag:He.meta,class:"tok-meta"},{tag:He.invalid,class:"tok-invalid"},{tag:He.punctuation,class:"tok-punctuation"}]);var Eb;const th=new Xt;function OD(t){return nt.define({combine:t?e=>e.concat(t):void 0})}const zX=new Xt;class Aa{constructor(e,n,i=[],s=""){this.data=e,this.name=s,vn.prototype.hasOwnProperty("tree")||Object.defineProperty(vn.prototype,"tree",{get(){return Yo(this)}}),this.parser=n,this.extension=[mf.of(this),vn.languageData.of((r,a,c)=>{let u=NE(r,a,c),d=u.type.prop(th);if(!d)return[];let p=r.facet(d),m=u.type.prop(zX);if(m){let v=u.resolve(a-u.from,c);for(let x of m)if(x.test(v,r)){let y=r.facet(x.facet);return x.type=="replace"?y:y.concat(p)}}return p})].concat(i)}isActiveAt(e,n,i=-1){return NE(e,n,i).type.prop(th)==this.data}findRegions(e){let n=e.facet(mf);if(n?.data==this.data)return[{from:0,to:e.doc.length}];if(!n||!n.allowsNesting)return[];let i=[],s=(r,a)=>{if(r.prop(th)==this.data){i.push({from:a,to:a+r.length});return}let c=r.prop(Xt.mounted);if(c){if(c.tree.prop(th)==this.data){if(c.overlay)for(let u of c.overlay)i.push({from:u.from+a,to:u.to+a});else i.push({from:a,to:a+r.length});return}else if(c.overlay){let u=i.length;if(s(c.tree,c.overlay[0].from+a),i.length>u)return}}for(let u=0;u<r.children.length;u++){let d=r.children[u];d instanceof Yn&&s(d,r.positions[u]+a)}};return s(Yo(e),0),i}get allowsNesting(){return!0}}Aa.setState=Gn.define();function NE(t,e,n){let i=t.facet(mf),s=Yo(t).topNode;if(!i||i.allowsNesting)for(let r=s;r;r=r.enter(e,n,Kn.ExcludeBuffers|Kn.EnterBracketed))r.type.isTop&&(s=r);return s}class Pw extends Aa{constructor(e,n,i){super(e,n,[],i),this.parser=n}static define(e){let n=OD(e.languageData);return new Pw(n,e.parser.configure({props:[th.add(i=>i.isTop?n:void 0)]}),e.name)}configure(e,n){return new Pw(this.data,this.parser.configure(e),n||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function Yo(t){let e=t.field(Aa.state,!1);return e?e.tree:Yn.empty}class FX{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,n){let i=this.cursorPos-this.string.length;return e<i||n>=this.cursorPos?this.doc.sliceString(e,n):this.string.slice(e-i,n-i)}}let Hp=null;class ff{constructor(e,n,i=[],s,r,a,c,u){this.parser=e,this.state=n,this.fragments=i,this.tree=s,this.treeLen=r,this.viewport=a,this.skipped=c,this.scheduleOn=u,this.parse=null,this.tempSkipped=[]}static create(e,n,i){return new ff(e,n,[],Yn.empty,0,i,[],null)}startParse(){return this.parser.startParse(new FX(this.state.doc),this.fragments)}work(e,n){return n!=null&&n>=this.state.doc.length&&(n=void 0),this.tree!=Yn.empty&&this.isDone(n??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof e=="number"){let s=Date.now()+e;e=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),n!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>n)&&n<this.state.doc.length&&this.parse.stopAt(n);;){let s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped(Wl.addTree(s,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(i=this.parse.stoppedAt)!==null&&i!==void 0?i:this.state.doc.length,this.tree=s,this.parse=null,this.treeLen<(n??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,n;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(n=this.parse.advance()););}),this.treeLen=e,this.tree=n,this.fragments=this.withoutTempSkipped(Wl.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let n=Hp;Hp=this;try{return e()}finally{Hp=n}}withoutTempSkipped(e){for(let n;n=this.tempSkipped.pop();)e=EE(e,n.from,n.to);return e}changes(e,n){let{fragments:i,tree:s,treeLen:r,viewport:a,skipped:c}=this;if(this.takeTree(),!e.empty){let u=[];if(e.iterChangedRanges((d,p,m,v)=>u.push({fromA:d,toA:p,fromB:m,toB:v})),i=Wl.applyChanges(i,u),s=Yn.empty,r=0,a={from:e.mapPos(a.from,-1),to:e.mapPos(a.to,1)},this.skipped.length){c=[];for(let d of this.skipped){let p=e.mapPos(d.from,1),m=e.mapPos(d.to,-1);p<m&&c.push({from:p,to:m})}}}return new ff(this.parser,n,i,s,r,a,c,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let n=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:s,to:r}=this.skipped[i];s<e.to&&r>e.from&&(this.fragments=EE(this.fragments,s,r),this.skipped.splice(i--,1))}return this.skipped.length>=n?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,n){this.skipped.push({from:e,to:n})}static getSkippingParser(e){return new class extends RD{createParse(n,i,s){let r=s[0].from,a=s[s.length-1].to;return{parsedPos:r,advance(){let u=Hp;if(u){for(let d of s)u.tempSkipped.push(d);e&&(u.scheduleOn=u.scheduleOn?Promise.all([u.scheduleOn,e]):e)}return this.parsedPos=a,new Yn(fr.none,[],[],a-r)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let n=this.fragments;return this.treeLen>=e&&n.length&&n[0].from==0&&n[0].to>=e}static get(){return Hp}}function EE(t,e,n){return Wl.applyChanges(t,[{fromA:e,toA:n,fromB:e,toB:n}])}class pf{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let n=this.context.changes(e.changes,e.state),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),n.viewport.to);return n.work(20,i)||n.takeTree(),new pf(n)}static init(e){let n=Math.min(3e3,e.doc.length),i=ff.create(e.facet(mf).parser,e,{from:0,to:n});return i.work(20,n)||i.takeTree(),new pf(i)}}Aa.state=tl.define({create:pf.init,update(t,e){for(let n of e.effects)if(n.is(Aa.setState))return n.value;return e.startState.facet(mf)!=e.state.facet(mf)?pf.init(e.state):t.apply(e)}});let ID=t=>{let e=setTimeout(()=>t(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(ID=t=>{let e=-1,n=setTimeout(()=>{e=requestIdleCallback(t,{timeout:400})},100);return()=>e<0?clearTimeout(n):cancelIdleCallback(e)});const Mb=typeof navigator<"u"&&(!((Eb=navigator.scheduling)===null||Eb===void 0)&&Eb.isInputPending)?()=>navigator.scheduling.isInputPending():null,HX=hr.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let n=this.view.state.field(Aa.state).context;(n.updateViewport(e.view.viewport)||this.view.viewport.to>n.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(n)}scheduleWork(){if(this.working)return;let{state:e}=this.view,n=e.field(Aa.state);(n.tree!=n.context.tree||!n.context.isDone(e.doc.length))&&(this.working=ID(this.work))}work(e){this.working=null;let n=Date.now();if(this.chunkEnd<n&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=n+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:s}}=this.view,r=i.field(Aa.state);if(r.tree==r.context.tree&&r.context.isDone(s+1e5))return;let a=Date.now()+Math.min(this.chunkBudget,100,e&&!Mb?Math.max(25,e.timeRemaining()-5):1e9),c=r.context.treeLen<s&&i.doc.length>s+1e3,u=r.context.work(()=>Mb&&Mb()||Date.now()>a,s+(c?0:1e5));this.chunkBudget-=Date.now()-n,(u||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Aa.setState.of(new pf(r.context))})),this.chunkBudget>0&&!(u&&!c)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(n=>Fo(this.view.state,n)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),mf=nt.define({combine(t){return t.length?t[0]:null},enables:t=>[Aa.state,HX,ct.contentAttributes.compute([t],e=>{let n=e.facet(t);return n&&n.name?{"data-language":n.name}:{}})]});class Ime{constructor(e,n=[]){this.language=e,this.support=n,this.extension=[e,n]}}class $D{constructor(e,n,i,s,r,a=void 0){this.name=e,this.alias=n,this.extensions=i,this.filename=s,this.loadFunc=r,this.support=a,this.loading=null}load(){return this.loading||(this.loading=this.loadFunc().then(e=>this.support=e,e=>{throw this.loading=null,e}))}static of(e){let{load:n,support:i}=e;if(!n){if(!i)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");n=()=>Promise.resolve(i)}return new $D(e.name,(e.alias||[]).concat(e.name).map(s=>s.toLowerCase()),e.extensions||[],e.filename,n,i)}static matchFilename(e,n){for(let s of e)if(s.filename&&s.filename.test(n))return s;let i=/\.([^.]+)$/.exec(n);if(i){for(let s of e)if(s.extensions.indexOf(i[1])>-1)return s}return null}static matchLanguageName(e,n,i=!0){n=n.toLowerCase();for(let s of e)if(s.alias.some(r=>r==n))return s;if(i)for(let s of e)for(let r of s.alias){let a=n.indexOf(r);if(a>-1&&(r.length>2||!/\w/.test(n[a-1])&&!/\w/.test(n[a+r.length])))return s}return null}}const WX=nt.define(),Zx=nt.define({combine:t=>{if(!t.length)return" ";let e=t[0];if(!e||/\S/.test(e)||Array.from(e).some(n=>n!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(t[0]));return e}});function bh(t){let e=t.facet(Zx);return e.charCodeAt(0)==9?t.tabSize*e.length:e.length}function Om(t,e){let n="",i=t.tabSize,s=t.facet(Zx)[0];if(s==" "){for(;e>=i;)n+=" ",e-=i;s=" "}for(let r=0;r<e;r++)n+=s;return n}function gC(t,e){t instanceof vn&&(t=new Jx(t));for(let i of t.state.facet(WX)){let s=i(t,e);if(s!==void 0)return s}let n=Yo(t.state);return n.length>=e?qX(t,n,e):null}class Jx{constructor(e,n={}){this.state=e,this.options=n,this.unit=bh(e)}lineAt(e,n=1){let i=this.state.doc.lineAt(e),{simulateBreak:s,simulateDoubleBreak:r}=this.options;return s!=null&&s>=i.from&&s<=i.to?r&&s==e?{text:"",from:e}:(n<0?s<e:s<=e)?{text:i.text.slice(s-i.from),from:s}:{text:i.text.slice(0,s-i.from),from:i.from}:i}textAfterPos(e,n=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:i,from:s}=this.lineAt(e,n);return i.slice(e-s,Math.min(i.length,e+100-s))}column(e,n=1){let{text:i,from:s}=this.lineAt(e,n),r=this.countColumn(i,e-s),a=this.options.overrideIndentation?this.options.overrideIndentation(s):-1;return a>-1&&(r+=a-this.countColumn(i,i.search(/\S|$/))),r}countColumn(e,n=e.length){return wf(e,this.state.tabSize,n)}lineIndent(e,n=1){let{text:i,from:s}=this.lineAt(e,n),r=this.options.overrideIndentation;if(r){let a=r(s);if(a>-1)return a}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const PD=new Xt;function qX(t,e,n){let i=e.resolveStack(n),s=e.resolveInner(n,-1).resolve(n,0).enterUnfinishedNodesBefore(n);if(s!=i.node){let r=[];for(let a=s;a&&!(a.from<i.node.from||a.to>i.node.to||a.from==i.node.from&&a.type==i.node.type);a=a.parent)r.push(a);for(let a=r.length-1;a>=0;a--)i={node:r[a],next:i}}return zD(i,t,n)}function zD(t,e,n){for(let i=t;i;i=i.next){let s=VX(i.node);if(s)return s(vC.create(e,n,i))}return 0}function UX(t){return t.pos==t.options.simulateBreak&&t.options.simulateDoubleBreak}function VX(t){let e=t.type.prop(PD);if(e)return e;let n=t.firstChild,i;if(n&&(i=n.type.prop(Xt.closedBy))){let s=t.lastChild,r=s&&i.indexOf(s.name)>-1;return a=>FD(a,!0,1,void 0,r&&!UX(a)?s.from:void 0)}return t.parent==null?KX:null}function KX(){return 0}class vC extends Jx{constructor(e,n,i){super(e.state,e.options),this.base=e,this.pos=n,this.context=i}get node(){return this.context.node}static create(e,n,i){return new vC(e,n,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let n=this.state.doc.lineAt(e.from);for(;;){let i=e.resolve(n.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(GX(i,e))break;n=this.state.doc.lineAt(i.from)}return this.lineIndent(n.from)}continue(){return zD(this.context.next,this.base,this.pos)}}function GX(t,e){for(let n=e;n;n=n.parent)if(t==n)return!0;return!1}function YX(t){let e=t.node,n=e.childAfter(e.from),i=e.lastChild;if(!n)return null;let s=t.options.simulateBreak,r=t.state.doc.lineAt(n.from),a=s==null||s<=r.from?r.to:Math.min(r.to,s);for(let c=n.to;;){let u=e.childAfter(c);if(!u||u==i)return null;if(!u.type.isSkipped){if(u.from>=a)return null;let d=/^ */.exec(r.text.slice(n.to-r.from))[0].length;return{from:n.from,to:n.to+d}}c=u.to}}function $me({closing:t,align:e=!0,units:n=1}){return i=>FD(i,e,n,t)}function FD(t,e,n,i,s){let r=t.textAfter,a=r.match(/^\s*/)[0].length,c=i&&r.slice(a,a+i.length)==i||s==t.pos+a,u=e?YX(t):null;return u?c?t.column(u.from):t.column(u.to):t.baseIndent+(c?0:t.unit*n)}const Pme=t=>t.baseIndent;function zme({except:t,units:e=1}={}){return n=>{let i=t&&t.test(n.textAfter);return n.baseIndent+(i?0:e*n.unit)}}const XX=200;function QX(){return vn.transactionFilter.of(t=>{if(!t.docChanged||!t.isUserEvent("input.type")&&!t.isUserEvent("input.complete"))return t;let e=t.startState.languageDataAt("indentOnInput",t.startState.selection.main.head);if(!e.length)return t;let n=t.newDoc,{head:i}=t.newSelection.main,s=n.lineAt(i);if(i>s.from+XX)return t;let r=n.sliceString(s.from,i);if(!e.some(d=>d.test(r)))return t;let{state:a}=t,c=-1,u=[];for(let{head:d}of a.selection.ranges){let p=a.doc.lineAt(d);if(p.from==c)continue;c=p.from;let m=gC(a,p.from);if(m==null)continue;let v=/^\s*/.exec(p.text)[0],x=Om(a,m);v!=x&&u.push({from:p.from,to:p.from+v.length,insert:x})}return u.length?[t,{changes:u,sequential:!0}]:t})}const Fme=nt.define(),Hme=new Xt;function Wme(t){let e=t.firstChild,n=t.lastChild;return e&&e.to<n.from?{from:e.to,to:n.type.isError?t.to:n.from}:null}class ey{constructor(e,n){this.specs=e;let i;function s(c){let u=Gc.newName();return(i||(i=Object.create(null)))["."+u]=c,u}const r=typeof n.all=="string"?n.all:n.all?s(n.all):void 0,a=n.scope;this.scope=a instanceof Aa?c=>c.prop(th)==a.data:a?c=>c==a:void 0,this.style=BD(e.map(c=>({tag:c.tag,class:c.class||s(Object.assign({},c,{tag:null}))})),{all:r}).style,this.module=i?new Gc(i):null,this.themeType=n.themeType}static define(e,n){return new ey(e,n||{})}}const zw=nt.define(),ZX=nt.define({combine(t){return t.length?[t[0]]:null}});function Lb(t){let e=t.facet(zw);return e.length?e:t.facet(ZX)}function JX(t,e){let n=[tQ],i;return t instanceof ey&&(t.module&&n.push(ct.styleModule.of(t.module)),i=t.themeType),i?n.push(zw.computeN([ct.darkTheme],s=>s.facet(ct.darkTheme)==(i=="dark")?[t]:[])):n.push(zw.of(t)),n}class eQ{constructor(e){this.markCache=Object.create(null),this.tree=Yo(e.state),this.decorations=this.buildDeco(e,Lb(e.state)),this.decoratedTo=e.viewport.to}update(e){let n=Yo(e.state),i=Lb(e.state),s=i!=Lb(e.startState),{viewport:r}=e.view,a=e.changes.mapPos(this.decoratedTo,1);n.length<r.to&&!s&&n.type==this.tree.type&&a>=r.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=a):(n!=this.tree||e.viewportChanged||s)&&(this.tree=n,this.decorations=this.buildDeco(e.view,i),this.decoratedTo=r.to)}buildDeco(e,n){if(!n||!this.tree.length)return Kt.none;let i=new vh;for(let{from:s,to:r}of e.visibleRanges)IX(this.tree,n,(a,c,u)=>{i.add(a,c,this.markCache[u]||(this.markCache[u]=Kt.mark({class:u})))},s,r);return i.finish()}}const tQ=Zm.high(hr.fromClass(eQ,{decorations:t=>t.decorations})),nQ=ct.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),HD=1e4,WD="()[]{}",qD=nt.define({combine(t){return Ah(t,{afterCursor:!0,brackets:WD,maxScanDistance:HD,renderMatch:rQ})}}),iQ=Kt.mark({class:"cm-matchingBracket"}),sQ=Kt.mark({class:"cm-nonmatchingBracket"});function rQ(t){let e=[],n=t.matched?iQ:sQ;return e.push(n.range(t.start.from,t.start.to)),t.end&&e.push(n.range(t.end.from,t.end.to)),e}function ME(t){let e=[],n=t.facet(qD);for(let i of t.selection.ranges){if(!i.empty)continue;let s=Wo(t,i.head,-1,n)||i.head>0&&Wo(t,i.head-1,1,n)||n.afterCursor&&(Wo(t,i.head,1,n)||i.head<t.doc.length&&Wo(t,i.head+1,-1,n));s&&(e=e.concat(n.renderMatch(s,t)))}return Kt.set(e,!0)}const aQ=hr.fromClass(class{constructor(t){this.paused=!1,this.decorations=ME(t.state)}update(t){(t.docChanged||t.selectionSet||this.paused)&&(t.view.composing?(this.decorations=this.decorations.map(t.changes),this.paused=!0):(this.decorations=ME(t.state),this.paused=!1))}},{decorations:t=>t.decorations}),oQ=[aQ,nQ];function lQ(t={}){return[qD.of(t),oQ]}const cQ=new Xt;function Fw(t,e,n){let i=t.prop(e<0?Xt.openedBy:Xt.closedBy);if(i)return i;if(t.name.length==1){let s=n.indexOf(t.name);if(s>-1&&s%2==(e<0?1:0))return[n[s+e]]}return null}function Hw(t){let e=t.type.prop(cQ);return e?e(t.node):t}function Wo(t,e,n,i={}){let s=i.maxScanDistance||HD,r=i.brackets||WD,a=Yo(t),c=a.resolveInner(e,n);for(let u=c;u;u=u.parent){let d=Fw(u.type,n,r);if(d&&u.from<u.to){let p=Hw(u);if(p&&(n>0?e>=p.from&&e<p.to:e>p.from&&e<=p.to))return uQ(t,e,n,u,p,d,r)}}return hQ(t,e,n,a,c.type,s,r)}function uQ(t,e,n,i,s,r,a){let c=i.parent,u={from:s.from,to:s.to},d=0,p=c?.cursor();if(p&&(n<0?p.childBefore(i.from):p.childAfter(i.to)))do if(n<0?p.to<=i.from:p.from>=i.to){if(d==0&&r.indexOf(p.type.name)>-1&&p.from<p.to){let m=Hw(p);return{start:u,end:m?{from:m.from,to:m.to}:void 0,matched:!0}}else if(Fw(p.type,n,a))d++;else if(Fw(p.type,-n,a)){if(d==0){let m=Hw(p);return{start:u,end:m&&m.from<m.to?{from:m.from,to:m.to}:void 0,matched:!1}}d--}}while(n<0?p.prevSibling():p.nextSibling());return{start:u,matched:!1}}function hQ(t,e,n,i,s,r,a){if(n<0?!e:e==t.doc.length)return null;let c=n<0?t.sliceDoc(e-1,e):t.sliceDoc(e,e+1),u=a.indexOf(c);if(u<0||u%2==0!=n>0)return null;let d={from:n<0?e-1:e,to:n>0?e+1:e},p=t.doc.iterRange(e,n>0?t.doc.length:0),m=0;for(let v=0;!p.next().done&&v<=r;){let x=p.value;n<0&&(v+=x.length);let y=e+v*n;for(let k=n>0?0:x.length-1,S=n>0?x.length:-1;k!=S;k+=n){let C=a.indexOf(x[k]);if(!(C<0||i.resolveInner(y+k,1).type!=s))if(C%2==0==n>0)m++;else{if(m==1)return{start:d,end:{from:y+k,to:y+k+1},matched:C>>1==u>>1};m--}}n>0&&(v+=x.length)}return p.done?{start:d,matched:!1}:null}function LE(t,e,n,i=0,s=0){e==null&&(e=t.search(/[^\s\u00a0]/),e==-1&&(e=t.length));let r=s;for(let a=i;a<e;a++)t.charCodeAt(a)==9?r+=n-r%n:r++;return r}class UD{constructor(e,n,i,s){this.string=e,this.tabSize=n,this.indentUnit=i,this.overrideIndent=s,this.pos=0,this.start=0,this.lastColumnPos=0,this.lastColumnValue=0}eol(){return this.pos>=this.string.length}sol(){return this.pos==0}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)}eat(e){let n=this.string.charAt(this.pos),i;if(typeof e=="string"?i=n==e:i=n&&(e instanceof RegExp?e.test(n):e(n)),i)return++this.pos,n}eatWhile(e){let n=this.pos;for(;this.eat(e););return this.pos>n}eatSpace(){let e=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e}skipToEnd(){this.pos=this.string.length}skipTo(e){let n=this.string.indexOf(e,this.pos);if(n>-1)return this.pos=n,!0}backUp(e){this.pos-=e}column(){return this.lastColumnPos<this.start&&(this.lastColumnValue=LE(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue}indentation(){var e;return(e=this.overrideIndent)!==null&&e!==void 0?e:LE(this.string,null,this.tabSize)}match(e,n,i){if(typeof e=="string"){let s=a=>i?a.toLowerCase():a,r=this.string.substr(this.pos,e.length);return s(r)==s(e)?(n!==!1&&(this.pos+=e.length),!0):null}else{let s=this.string.slice(this.pos).match(e);return s&&s.index>0?null:(s&&n!==!1&&(this.pos+=s[0].length),s)}}current(){return this.string.slice(this.start,this.pos)}}function dQ(t){return{name:t.name||"",token:t.token,blankLine:t.blankLine||(()=>{}),startState:t.startState||(()=>!0),copyState:t.copyState||fQ,indent:t.indent||(()=>null),languageData:t.languageData||{},tokenTable:t.tokenTable||_C,mergeTokens:t.mergeTokens!==!1}}function fQ(t){if(typeof t!="object")return t;let e={};for(let n in t){let i=t[n];e[n]=i instanceof Array?i.slice():i}return e}const TE=new WeakMap;class xC extends Aa{constructor(e){let n=OD(e.languageData),i=dQ(e),s,r=new class extends RD{createParse(a,c,u){return new mQ(s,a,c,u)}};super(n,r,[],e.name),this.topNode=xQ(n,this),s=this,this.streamParser=i,this.stateAfter=new Xt({perNode:!0}),this.tokenTable=e.tokenTable?new YD(i.tokenTable):vQ}static define(e){return new xC(e)}getIndent(e){let n,{overrideIndentation:i}=e.options;i&&(n=TE.get(e.state),n!=null&&n<e.pos-1e4&&(n=void 0));let s=yC(this,e.node.tree,e.node.from,e.node.from,n??e.pos),r,a;if(s?(a=s.state,r=s.pos+1):(a=this.streamParser.startState(e.unit),r=e.node.from),e.pos-r>1e4)return null;for(;r<e.pos;){let u=e.state.doc.lineAt(r),d=Math.min(e.pos,u.to);if(u.length){let p=i?i(u.from):-1,m=new UD(u.text,e.state.tabSize,e.unit,p<0?void 0:p);for(;m.pos<d-u.from;)KD(this.streamParser.token,m,a)}else this.streamParser.blankLine(a,e.unit);if(d==e.pos)break;r=u.to+1}let c=e.lineAt(e.pos);return i&&n==null&&TE.set(e.state,c.from),this.streamParser.indent(a,/^\s*(.*)/.exec(c.text)[1],e)}get allowsNesting(){return!1}}function yC(t,e,n,i,s){let r=n>=i&&n+e.length<=s&&e.prop(t.stateAfter);if(r)return{state:t.streamParser.copyState(r),pos:n+e.length};for(let a=e.children.length-1;a>=0;a--){let c=e.children[a],u=n+e.positions[a],d=c instanceof Yn&&u<s&&yC(t,c,u,i,s);if(d)return d}return null}function VD(t,e,n,i,s){if(s&&n<=0&&i>=e.length)return e;!s&&n==0&&e.type==t.topNode&&(s=!0);for(let r=e.children.length-1;r>=0;r--){let a=e.positions[r],c=e.children[r],u;if(a<i&&c instanceof Yn){if(!(u=VD(t,c,n-a,i-a,s)))break;return s?new Yn(e.type,e.children.slice(0,r).concat(u),e.positions.slice(0,r+1),a+u.length):u}}return null}function pQ(t,e,n,i,s){for(let r of e){let a=r.from+(r.openStart?25:0),c=r.to-(r.openEnd?25:0),u=a<=n&&c>n&&yC(t,r.tree,0-r.offset,n,c),d;if(u&&u.pos<=i&&(d=VD(t,r.tree,n+r.offset,u.pos+r.offset,!1)))return{state:u.state,tree:d}}return{state:t.streamParser.startState(s?bh(s):4),tree:Yn.empty}}class mQ{constructor(e,n,i,s){this.lang=e,this.input=n,this.fragments=i,this.ranges=s,this.stoppedAt=null,this.chunks=[],this.chunkPos=[],this.chunk=[],this.chunkReused=void 0,this.rangeIndex=0,this.to=s[s.length-1].to;let r=ff.get(),a=s[0].from,{state:c,tree:u}=pQ(e,i,a,this.to,r?.state);this.state=c,this.parsedPos=this.chunkStart=a+u.length;for(let d=0;d<u.children.length;d++)this.chunks.push(u.children[d]),this.chunkPos.push(u.positions[d]);r&&this.parsedPos<r.viewport.from-1e5&&s.some(d=>d.from<=r.viewport.from&&d.to>=r.viewport.from)&&(this.state=this.lang.streamParser.startState(bh(r.state)),r.skipUntilInView(this.parsedPos,r.viewport.from),this.parsedPos=r.viewport.from),this.moveRangeIndex()}advance(){let e=ff.get(),n=this.stoppedAt==null?this.to:Math.min(this.to,this.stoppedAt),i=Math.min(n,this.chunkStart+512);for(e&&(i=Math.min(i,e.viewport.to));this.parsedPos<i;)this.parseLine(e);return this.chunkStart<this.parsedPos&&this.finishChunk(),this.parsedPos>=n?this.finish():e&&this.parsedPos>=e.viewport.to?(e.skipUntilInView(this.parsedPos,n),this.finish()):null}stopAt(e){this.stoppedAt=e}lineAfter(e){let n=this.input.chunk(e);if(this.input.lineChunks)n==`
66
66
  `&&(n="");else{let i=n.indexOf(`
67
67
  `);i>-1&&(n=n.slice(0,i))}return e+n.length<=this.to?n:n.slice(0,this.to-e)}nextLine(){let e=this.parsedPos,n=this.lineAfter(e),i=e+n.length;for(let s=this.rangeIndex;;){let r=this.ranges[s].to;if(r>=i||(n=n.slice(0,r-(i-n.length)),s++,s==this.ranges.length))break;let a=this.ranges[s].from,c=this.lineAfter(a);n+=c,i=a+c.length}return{line:n,end:i}}skipGapsTo(e,n,i){for(;;){let s=this.ranges[this.rangeIndex].to,r=e+n;if(i>0?s>r:s>=r)break;let a=this.ranges[++this.rangeIndex].from;n+=a-s}return n}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(e,n,i,s){let r=4;if(this.ranges.length>1){s=this.skipGapsTo(n,s,1),n+=s;let c=this.chunk.length;s=this.skipGapsTo(i,s,-1),i+=s,r+=this.chunk.length-c}let a=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&r==4&&a>=0&&this.chunk[a]==e&&this.chunk[a+2]==n?this.chunk[a+2]=i:this.chunk.push(e,n,i,r),s}parseLine(e){let{line:n,end:i}=this.nextLine(),s=0,{streamParser:r}=this.lang,a=new UD(n,e?e.state.tabSize:4,e?bh(e.state):2);if(a.eol())r.blankLine(this.state,a.indentUnit);else for(;!a.eol();){let c=KD(r.token,a,this.state);if(c&&(s=this.emitToken(this.lang.tokenTable.resolve(c),this.parsedPos+a.start,this.parsedPos+a.pos,s)),a.start>1e4)break}this.parsedPos=i,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let e=Yn.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:gQ,topID:0,maxBufferLength:512,reused:this.chunkReused});e=new Yn(e.type,e.children,e.positions,e.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(e),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new Yn(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function KD(t,e,n){e.start=e.pos;for(let i=0;i<10;i++){let s=t(e,n);if(e.pos>e.start)return s}throw new Error("Stream parser failed to advance stream.")}const _C=Object.create(null),Im=[fr.none],gQ=new dC(Im),RE=[],DE=Object.create(null),GD=Object.create(null);for(let[t,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])GD[t]=XD(_C,e);class YD{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),GD)}resolve(e){return e?this.table[e]||(this.table[e]=XD(this.extra,e)):0}}const vQ=new YD(_C);function Tb(t,e){RE.indexOf(t)>-1||(RE.push(t),console.warn(e))}function XD(t,e){let n=[];for(let c of e.split(" ")){let u=[];for(let d of c.split(".")){let p=t[d]||He[d];p?typeof p=="function"?u.length?u=u.map(p):Tb(d,`Modifier ${d} used at start of tag`):u.length?Tb(d,`Tag ${d} used as modifier`):u=Array.isArray(p)?p:[p]:Tb(d,`Unknown highlighting tag ${d}`)}for(let d of u)n.push(d)}if(!n.length)return 0;let i=e.replace(/ /g,"_"),s=i+" "+n.map(c=>c.id),r=DE[s];if(r)return r.id;let a=DE[s]=fr.define({id:Im.length,name:i,props:[BX({[i]:n})]});return Im.push(a),a.id}function xQ(t,e){let n=fr.define({id:Im.length,name:"Document",props:[th.add(()=>t),PD.add(()=>i=>e.getIndent(i))],top:!0});return Im.push(n),n}di.RTL,di.LTR;const yQ=t=>{let{state:e}=t,n=e.doc.lineAt(e.selection.main.from),i=wC(t.state,n.from);return i.line?_Q(t):i.block?wQ(t):!1};function bC(t,e){return({state:n,dispatch:i})=>{if(n.readOnly)return!1;let s=t(e,n);return s?(i(n.update(s)),!0):!1}}const _Q=bC(CQ,0),bQ=bC(QD,0),wQ=bC((t,e)=>QD(t,e,SQ(e)),0);function wC(t,e){let n=t.languageDataAt("commentTokens",e,1);return n.length?n[0]:{}}const Wp=50;function kQ(t,{open:e,close:n},i,s){let r=t.sliceDoc(i-Wp,i),a=t.sliceDoc(s,s+Wp),c=/\s*$/.exec(r)[0].length,u=/^\s*/.exec(a)[0].length,d=r.length-c;if(r.slice(d-e.length,d)==e&&a.slice(u,u+n.length)==n)return{open:{pos:i-c,margin:c&&1},close:{pos:s+u,margin:u&&1}};let p,m;s-i<=2*Wp?p=m=t.sliceDoc(i,s):(p=t.sliceDoc(i,i+Wp),m=t.sliceDoc(s-Wp,s));let v=/^\s*/.exec(p)[0].length,x=/\s*$/.exec(m)[0].length,y=m.length-x-n.length;return p.slice(v,v+e.length)==e&&m.slice(y,y+n.length)==n?{open:{pos:i+v+e.length,margin:/\s/.test(p.charAt(v+e.length))?1:0},close:{pos:s-x-n.length,margin:/\s/.test(m.charAt(y-1))?1:0}}:null}function SQ(t){let e=[];for(let n of t.selection.ranges){let i=t.doc.lineAt(n.from),s=n.to<=i.to?i:t.doc.lineAt(n.to);s.from>i.from&&s.from==n.to&&(s=n.to==i.to+1?i:t.doc.lineAt(n.to-1));let r=e.length-1;r>=0&&e[r].to>i.from?e[r].to=s.to:e.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:s.to})}return e}function QD(t,e,n=e.selection.ranges){let i=n.map(r=>wC(e,r.from).block);if(!i.every(r=>r))return null;let s=n.map((r,a)=>kQ(e,i[a],r.from,r.to));if(t!=2&&!s.every(r=>r))return{changes:e.changes(n.map((r,a)=>s[a]?[]:[{from:r.from,insert:i[a].open+" "},{from:r.to,insert:" "+i[a].close}]))};if(t!=1&&s.some(r=>r)){let r=[];for(let a=0,c;a<s.length;a++)if(c=s[a]){let u=i[a],{open:d,close:p}=c;r.push({from:d.pos-u.open.length,to:d.pos+d.margin},{from:p.pos-p.margin,to:p.pos+u.close.length})}return{changes:r}}return null}function CQ(t,e,n=e.selection.ranges){let i=[],s=-1;e:for(let{from:r,to:a}of n){let c=i.length,u=1e9,d;for(let p=r;p<=a;){let m=e.doc.lineAt(p);if(d==null&&(d=wC(e,m.from).line,!d))continue e;if(m.from>s&&(r==a||a>m.from)){s=m.from;let v=/^\s*/.exec(m.text)[0].length,x=v==m.length,y=m.text.slice(v,v+d.length)==d?v:-1;v<m.text.length&&v<u&&(u=v),i.push({line:m,comment:y,token:d,indent:v,empty:x,single:!1})}p=m.to+1}if(u<1e9)for(let p=c;p<i.length;p++)i[p].indent<i[p].line.text.length&&(i[p].indent=u);i.length==c+1&&(i[c].single=!0)}if(t!=2&&i.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:c,token:u,indent:d,empty:p,single:m}of i)(m||!p)&&r.push({from:c.from+d,insert:u+" "});let a=e.changes(r);return{changes:a,selection:e.selection.map(a,1)}}else if(t!=1&&i.some(r=>r.comment>=0)){let r=[];for(let{line:a,comment:c,token:u}of i)if(c>=0){let d=a.from+c,p=d+u.length;a.text[p-a.from]==" "&&p++,r.push({from:d,to:p})}return{changes:r}}return null}const Ww=nu.define(),jQ=nu.define(),AQ=nt.define(),ZD=nt.define({combine(t){return Ah(t,{minDepth:100,newGroupDelay:500,joinToEvent:(e,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,n)=>(i,s)=>e(i,s)||n(i,s)})}}),JD=tl.define({create(){return qo.empty},update(t,e){let n=e.state.facet(ZD),i=e.annotation(Ww);if(i){let u=Lr.fromTransaction(e,i.selection),d=i.side,p=d==0?t.undone:t.done;return u?p=fx(p,p.length,n.minDepth,u):p=n6(p,e.startState.selection),new qo(d==0?i.rest:p,d==0?p:i.rest)}let s=e.annotation(jQ);if((s=="full"||s=="before")&&(t=t.isolate()),e.annotation(os.addToHistory)===!1)return e.changes.empty?t:t.addMapping(e.changes.desc);let r=Lr.fromTransaction(e),a=e.annotation(os.time),c=e.annotation(os.userEvent);return r?t=t.addChanges(r,a,c,n,e):e.selection&&(t=t.addSelection(e.startState.selection,a,c,n.newGroupDelay)),(s=="full"||s=="after")&&(t=t.isolate()),t},toJSON(t){return{done:t.done.map(e=>e.toJSON()),undone:t.undone.map(e=>e.toJSON())}},fromJSON(t){return new qo(t.done.map(Lr.fromJSON),t.undone.map(Lr.fromJSON))}});function NQ(t={}){return[JD,ZD.of(t),ct.domEventHandlers({beforeinput(e,n){let i=e.inputType=="historyUndo"?e6:e.inputType=="historyRedo"?qw:null;return i?(e.preventDefault(),i(n)):!1}})]}function ty(t,e){return function({state:n,dispatch:i}){if(!e&&n.readOnly)return!1;let s=n.field(JD,!1);if(!s)return!1;let r=s.pop(t,n,e);return r?(i(r),!0):!1}}const e6=ty(0,!1),qw=ty(1,!1),EQ=ty(0,!0),MQ=ty(1,!0);class Lr{constructor(e,n,i,s,r){this.changes=e,this.effects=n,this.mapped=i,this.startSelection=s,this.selectionsAfter=r}setSelAfter(e){return new Lr(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,n,i;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(n=this.mapped)===null||n===void 0?void 0:n.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(s=>s.toJSON())}}static fromJSON(e){return new Lr(e.changes&&as.fromJSON(e.changes),[],e.mapped&&Vo.fromJSON(e.mapped),e.startSelection&&Ne.fromJSON(e.startSelection),e.selectionsAfter.map(Ne.fromJSON))}static fromTransaction(e,n){let i=Na;for(let s of e.startState.facet(AQ)){let r=s(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new Lr(e.changes.invert(e.startState.doc),i,void 0,n||e.startState.selection,Na)}static selection(e){return new Lr(void 0,Na,void 0,void 0,e)}}function fx(t,e,n,i){let s=e+1>n+20?e-n-1:0,r=t.slice(s,e);return r.push(i),r}function LQ(t,e){let n=[],i=!1;return t.iterChangedRanges((s,r)=>n.push(s,r)),e.iterChangedRanges((s,r,a,c)=>{for(let u=0;u<n.length;){let d=n[u++],p=n[u++];c>=d&&a<=p&&(i=!0)}}),i}function TQ(t,e){return t.ranges.length==e.ranges.length&&t.ranges.filter((n,i)=>n.empty!=e.ranges[i].empty).length===0}function t6(t,e){return t.length?e.length?t.concat(e):t:e}const Na=[],RQ=200;function n6(t,e){if(t.length){let n=t[t.length-1],i=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-RQ));return i.length&&i[i.length-1].eq(e)?t:(i.push(e),fx(t,t.length-1,1e9,n.setSelAfter(i)))}else return[Lr.selection([e])]}function DQ(t){let e=t[t.length-1],n=t.slice();return n[t.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),n}function Rb(t,e){if(!t.length)return t;let n=t.length,i=Na;for(;n;){let s=BQ(t[n-1],e,i);if(s.changes&&!s.changes.empty||s.effects.length){let r=t.slice(0,n);return r[n-1]=s,r}else e=s.mapped,n--,i=s.selectionsAfter}return i.length?[Lr.selection(i)]:Na}function BQ(t,e,n){let i=t6(t.selectionsAfter.length?t.selectionsAfter.map(c=>c.map(e)):Na,n);if(!t.changes)return Lr.selection(i);let s=t.changes.map(e),r=e.mapDesc(t.changes,!0),a=t.mapped?t.mapped.composeDesc(r):r;return new Lr(s,Gn.mapEffects(t.effects,e),a,t.startSelection.map(r),i)}const OQ=/^(input\.type|delete)($|\.)/;class qo{constructor(e,n,i=0,s=void 0){this.done=e,this.undone=n,this.prevTime=i,this.prevUserEvent=s}isolate(){return this.prevTime?new qo(this.done,this.undone):this}addChanges(e,n,i,s,r){let a=this.done,c=a[a.length-1];return c&&c.changes&&!c.changes.empty&&e.changes&&(!i||OQ.test(i))&&(!c.selectionsAfter.length&&n-this.prevTime<s.newGroupDelay&&s.joinToEvent(r,LQ(c.changes,e.changes))||i=="input.type.compose")?a=fx(a,a.length-1,s.minDepth,new Lr(e.changes.compose(c.changes),t6(Gn.mapEffects(e.effects,c.changes),c.effects),c.mapped,c.startSelection,Na)):a=fx(a,a.length,s.minDepth,e),new qo(a,Na,n,i)}addSelection(e,n,i,s){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:Na;return r.length>0&&n-this.prevTime<s&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&TQ(r[r.length-1],e)?this:new qo(n6(this.done,e),this.undone,n,i)}addMapping(e){return new qo(Rb(this.done,e),Rb(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,n,i){let s=e==0?this.done:this.undone;if(s.length==0)return null;let r=s[s.length-1],a=r.selectionsAfter[0]||(r.startSelection?r.startSelection.map(r.changes.invertedDesc,1):n.selection);if(i&&r.selectionsAfter.length)return n.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:Ww.of({side:e,rest:DQ(s),selection:a}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let c=s.length==1?Na:s.slice(0,s.length-1);return r.mapped&&(c=Rb(c,r.mapped)),n.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:Ww.of({side:e,rest:c,selection:a}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}qo.empty=new qo(Na,Na);const IQ=[{key:"Mod-z",run:e6,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:qw,preventDefault:!0},{linux:"Ctrl-Shift-z",run:qw,preventDefault:!0},{key:"Mod-u",run:EQ,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:MQ,preventDefault:!0}];function Sf(t,e){return Ne.create(t.ranges.map(e),t.mainIndex)}function ro(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function ao({state:t,dispatch:e},n){let i=Sf(t.selection,n);return i.eq(t.selection,!0)?!1:(e(ro(t,i)),!0)}function ny(t,e){return Ne.cursor(e?t.to:t.from)}function i6(t,e){return ao(t,n=>n.empty?t.moveByChar(n,e):ny(n,e))}function Us(t){return t.textDirectionAt(t.state.selection.main.head)==di.LTR}const s6=t=>i6(t,!Us(t)),r6=t=>i6(t,Us(t));function a6(t,e){return ao(t,n=>n.empty?t.moveByGroup(n,e):ny(n,e))}const $Q=t=>a6(t,!Us(t)),PQ=t=>a6(t,Us(t));function zQ(t,e,n){if(e.type.prop(n))return!0;let i=e.to-e.from;return i&&(i>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function iy(t,e,n){let i=Yo(t).resolveInner(e.head),s=n?Xt.closedBy:Xt.openedBy;for(let u=e.head;;){let d=n?i.childAfter(u):i.childBefore(u);if(!d)break;zQ(t,d,s)?i=d:u=n?d.to:d.from}let r=i.type.prop(s),a,c;return r&&(a=n?Wo(t,i.from,1):Wo(t,i.to,-1))&&a.matched?c=n?a.end.to:a.end.from:c=n?i.to:i.from,Ne.cursor(c,n?-1:1)}const FQ=t=>ao(t,e=>iy(t.state,e,!Us(t))),HQ=t=>ao(t,e=>iy(t.state,e,Us(t)));function o6(t,e){return ao(t,n=>{if(!n.empty)return ny(n,e);let i=t.moveVertically(n,e);return i.head!=n.head?i:t.moveToLineBoundary(n,e)})}const l6=t=>o6(t,!1),c6=t=>o6(t,!0);function u6(t){let e=t.scrollDOM.clientHeight<t.scrollDOM.scrollHeight-2,n=0,i=0,s;if(e){for(let r of t.state.facet(ct.scrollMargins)){let a=r(t);a?.top&&(n=Math.max(a?.top,n)),a?.bottom&&(i=Math.max(a?.bottom,i))}s=t.scrollDOM.clientHeight-n-i}else s=(t.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:i,selfScroll:e,height:Math.max(t.defaultLineHeight,s-5)}}function h6(t,e){let n=u6(t),{state:i}=t,s=Sf(i.selection,a=>a.empty?t.moveVertically(a,e,n.height):ny(a,e));if(s.eq(i.selection))return!1;let r;if(n.selfScroll){let a=t.coordsAtPos(i.selection.main.head),c=t.scrollDOM.getBoundingClientRect(),u=c.top+n.marginTop,d=c.bottom-n.marginBottom;a&&a.top>u&&a.bottom<d&&(r=ct.scrollIntoView(s.main.head,{y:"start",yMargin:a.top-u}))}return t.dispatch(ro(i,s),{effects:r}),!0}const BE=t=>h6(t,!1),Uw=t=>h6(t,!0);function iu(t,e,n){let i=t.lineBlockAt(e.head),s=t.moveToLineBoundary(e,n);if(s.head==e.head&&s.head!=(n?i.to:i.from)&&(s=t.moveToLineBoundary(e,n,!1)),!n&&s.head==i.from&&i.length){let r=/^\s*/.exec(t.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;r&&e.head!=i.from+r&&(s=Ne.cursor(i.from+r))}return s}const WQ=t=>ao(t,e=>iu(t,e,!0)),qQ=t=>ao(t,e=>iu(t,e,!1)),UQ=t=>ao(t,e=>iu(t,e,!Us(t))),VQ=t=>ao(t,e=>iu(t,e,Us(t))),KQ=t=>ao(t,e=>Ne.cursor(t.lineBlockAt(e.head).from,1)),GQ=t=>ao(t,e=>Ne.cursor(t.lineBlockAt(e.head).to,-1));function YQ(t,e,n){let i=!1,s=Sf(t.selection,r=>{let a=Wo(t,r.head,-1)||Wo(t,r.head,1)||r.head>0&&Wo(t,r.head-1,1)||r.head<t.doc.length&&Wo(t,r.head+1,-1);if(!a||!a.end)return r;i=!0;let c=a.start.from==r.head?a.end.to:a.end.from;return Ne.cursor(c)});return i?(e(ro(t,s)),!0):!1}const XQ=({state:t,dispatch:e})=>YQ(t,e);function La(t,e,n){let i=Sf(t.state.selection,s=>{s.undirectional&&s.head>=s.anchor!=e&&(s=Ne.range(s.head,s.anchor));let r=n(s);return Ne.range(s.anchor,r.head,r.goalColumn,r.bidiLevel||void 0,r.assoc)});return i.eq(t.state.selection)?!1:(t.dispatch(ro(t.state,i)),!0)}function d6(t,e){return La(t,e,n=>t.moveByChar(n,e))}const f6=t=>d6(t,!Us(t)),p6=t=>d6(t,Us(t));function m6(t,e){return La(t,e,n=>t.moveByGroup(n,e))}const QQ=t=>m6(t,!Us(t)),ZQ=t=>m6(t,Us(t)),JQ=t=>{let e=!Us(t);return La(t,e,n=>iy(t.state,n,e))},eZ=t=>{let e=Us(t);return La(t,e,n=>iy(t.state,n,e))};function g6(t,e){return La(t,e,n=>t.moveVertically(n,e))}const v6=t=>g6(t,!1),x6=t=>g6(t,!0);function y6(t,e){return La(t,e,n=>t.moveVertically(n,e,u6(t).height))}const OE=t=>y6(t,!1),IE=t=>y6(t,!0),tZ=t=>La(t,!0,e=>iu(t,e,!0)),nZ=t=>La(t,!1,e=>iu(t,e,!1)),iZ=t=>{let e=!Us(t);return La(t,e,n=>iu(t,n,e))},sZ=t=>{let e=Us(t);return La(t,e,n=>iu(t,n,e))},rZ=t=>La(t,!1,e=>Ne.cursor(t.lineBlockAt(e.head).from)),aZ=t=>La(t,!0,e=>Ne.cursor(t.lineBlockAt(e.head).to)),$E=({state:t,dispatch:e})=>(e(ro(t,{anchor:0})),!0),PE=({state:t,dispatch:e})=>(e(ro(t,{anchor:t.doc.length})),!0),zE=({state:t,dispatch:e})=>(e(ro(t,{anchor:t.selection.main.anchor,head:0})),!0),FE=({state:t,dispatch:e})=>(e(ro(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0),oZ=({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0),lZ=({state:t,dispatch:e})=>{let n=sy(t).map(({from:i,to:s})=>Ne.undirectionalRange(i,Math.min(s+1,t.doc.length)));return e(t.update({selection:Ne.create(n),userEvent:"select"})),!0},cZ=({state:t,dispatch:e})=>{let n=Sf(t.selection,i=>{let s=Yo(t),r=s.resolveStack(i.from,1);if(i.empty){let a=s.resolveStack(i.from,-1);a.node.from>=r.node.from&&a.node.to<=r.node.to&&(r=a)}for(let a=r;a;a=a.next){let{node:c}=a;if((c.from<i.from&&c.to>=i.to||c.to>i.to&&c.from<=i.from)&&a.next)return Ne.undirectionalRange(c.from,c.to)}return i});return n.eq(t.selection)?!1:(e(ro(t,n)),!0)};function _6(t,e){let{state:n}=t,i=n.selection,s=n.selection.ranges.slice();for(let r of n.selection.ranges){let a=n.doc.lineAt(r.head);if(e?a.to<t.state.doc.length:a.from>0)for(let c=r;;){let u=t.moveVertically(c,e);if(u.head<a.from||u.head>a.to){s.some(d=>d.head==u.head)||s.push(u);break}else{if(u.head==c.head)break;c=u}}}return s.length==i.ranges.length?!1:(t.dispatch(ro(n,Ne.create(s,s.length-1))),!0)}const uZ=t=>_6(t,!1),hZ=t=>_6(t,!0),dZ=({state:t,dispatch:e})=>{let n=t.selection,i=null;return n.ranges.length>1?i=Ne.create([n.main]):n.main.empty||(i=Ne.create([Ne.cursor(n.main.head)])),i?(e(ro(t,i)),!0):!1};function ig(t,e){if(t.state.readOnly)return!1;let n="delete.selection",{state:i}=t,s=i.changeByRange(r=>{let{from:a,to:c}=r;if(a==c){let u=e(r);u<a?(n="delete.backward",u=Fv(t,u,!1)):u>a&&(n="delete.forward",u=Fv(t,u,!0)),a=Math.min(a,u),c=Math.max(c,u)}else a=Fv(t,a,!1),c=Fv(t,c,!0);return a==c?{range:r}:{changes:{from:a,to:c},range:Ne.cursor(a,a<r.head?-1:1)}});return s.changes.empty?!1:(t.dispatch(i.update(s,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?ct.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function Fv(t,e,n){if(t instanceof ct)for(let i of t.state.facet(ct.atomicRanges).map(s=>s(t)))i.between(e,e,(s,r)=>{s<e&&r>e&&(e=n?r:s)});return e}const b6=(t,e,n)=>ig(t,i=>{let s=i.from,{state:r}=t,a=r.doc.lineAt(s),c,u;if(n&&!e&&s>a.from&&s<a.from+200&&!/[^ \t]/.test(c=a.text.slice(0,s-a.from))){if(c[c.length-1]==" ")return s-1;let d=wf(c,r.tabSize),p=d%bh(r)||bh(r);for(let m=0;m<p&&c[c.length-1-m]==" ";m++)s--;u=s}else u=bs(a.text,s-a.from,e,e)+a.from,u==s&&a.number!=(e?r.doc.lines:1)?u+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(a.text.slice(u-a.from,s-a.from))&&(u=bs(a.text,u-a.from,!1,!1)+a.from);return u}),Vw=t=>b6(t,!1,!0),w6=t=>b6(t,!0,!1),k6=(t,e)=>ig(t,n=>{let i=n.head,{state:s}=t,r=s.doc.lineAt(i),a=s.charCategorizer(i);for(let c=null;;){if(i==(e?r.to:r.from)){i==n.head&&r.number!=(e?s.doc.lines:1)&&(i+=e?1:-1);break}let u=bs(r.text,i-r.from,e)+r.from,d=r.text.slice(Math.min(i,u)-r.from,Math.max(i,u)-r.from),p=a(d);if(c!=null&&p!=c)break;(d!=" "||i!=n.head)&&(c=p),i=u}return i}),S6=t=>k6(t,!1),fZ=t=>k6(t,!0),pZ=t=>ig(t,e=>{let n=t.lineBlockAt(e.head).to;return e.head<n?n:Math.min(t.state.doc.length,e.head+1)}),mZ=t=>ig(t,e=>{let n=t.moveToLineBoundary(e,!1).head;return e.head>n?n:Math.max(0,e.head-1)}),gZ=t=>ig(t,e=>{let n=t.moveToLineBoundary(e,!0).head;return e.head<n?n:Math.min(t.state.doc.length,e.head+1)}),vZ=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=t.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:jn.of(["",""])},range:Ne.cursor(i.from)}));return e(t.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},xZ=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=t.changeByRange(i=>{if(!i.empty||i.from==0||i.from==t.doc.length)return{range:i};let s=i.from,r=t.doc.lineAt(s),a=s==r.from?s-1:bs(r.text,s-r.from,!1)+r.from,c=s==r.to?s+1:bs(r.text,s-r.from,!0)+r.from;return{changes:{from:a,to:c,insert:t.doc.slice(s,c).append(t.doc.slice(a,s))},range:Ne.cursor(c)}});return n.changes.empty?!1:(e(t.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function sy(t){let e=[],n=-1;for(let i of t.selection.ranges){let s=t.doc.lineAt(i.from),r=t.doc.lineAt(i.to);if(!i.empty&&i.to==r.from&&(r=t.doc.lineAt(i.to-1)),n>=s.number){let a=e[e.length-1];a.to=r.to,a.ranges.push(i)}else e.push({from:s.from,to:r.to,ranges:[i]});n=r.number+1}return e}function C6(t,e,n){if(t.readOnly)return!1;let i=[],s=[];for(let r of sy(t)){if(n?r.to==t.doc.length:r.from==0)continue;let a=t.doc.lineAt(n?r.to+1:r.from-1),c=a.length+1;if(n){i.push({from:r.to,to:a.to},{from:r.from,insert:a.text+t.lineBreak});for(let u of r.ranges)s.push(Ne.range(Math.min(t.doc.length,u.anchor+c),Math.min(t.doc.length,u.head+c)))}else{i.push({from:a.from,to:r.from},{from:r.to,insert:t.lineBreak+a.text});for(let u of r.ranges)s.push(Ne.range(u.anchor-c,u.head-c))}}return i.length?(e(t.update({changes:i,scrollIntoView:!0,selection:Ne.create(s,t.selection.mainIndex),userEvent:"move.line"})),!0):!1}const yZ=({state:t,dispatch:e})=>C6(t,e,!1),_Z=({state:t,dispatch:e})=>C6(t,e,!0);function j6(t,e,n){if(t.readOnly)return!1;let i=[];for(let r of sy(t))n?i.push({from:r.from,insert:t.doc.slice(r.from,r.to)+t.lineBreak}):i.push({from:r.to,insert:t.lineBreak+t.doc.slice(r.from,r.to)});let s=t.changes(i);return e(t.update({changes:s,selection:t.selection.map(s,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const bZ=({state:t,dispatch:e})=>j6(t,e,!1),wZ=({state:t,dispatch:e})=>j6(t,e,!0),kZ=t=>{if(t.state.readOnly)return!1;let{state:e}=t,n=e.changes(sy(e).map(({from:s,to:r})=>(s>0?s--:r<e.doc.length&&r++,{from:s,to:r}))),i=Sf(e.selection,s=>{let r;if(t.lineWrapping){let a=t.lineBlockAt(s.head),c=t.coordsAtPos(s.head,s.assoc||1);c&&(r=a.bottom+t.documentTop-c.bottom+t.defaultLineHeight/2)}return t.moveVertically(s,!0,r)}).map(n);return t.dispatch({changes:n,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function SZ(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let n=Yo(t).resolveInner(e),i=n.childBefore(e),s=n.childAfter(e),r;return i&&s&&i.to<=e&&s.from>=e&&(r=i.type.prop(Xt.closedBy))&&r.indexOf(s.name)>-1&&t.doc.lineAt(i.to).from==t.doc.lineAt(s.from).from&&!/\S/.test(t.sliceDoc(i.to,s.from))?{from:i.to,to:s.from}:null}const HE=A6(!1),CZ=A6(!0);function A6(t){return({state:e,dispatch:n})=>{if(e.readOnly)return!1;let i=e.changeByRange(s=>{let{from:r,to:a}=s,c=e.doc.lineAt(r),u=!t&&r==a&&SZ(e,r);t&&(r=a=(a<=c.to?c:e.doc.lineAt(a)).to);let d=new Jx(e,{simulateBreak:r,simulateDoubleBreak:!!u}),p=gC(d,r);for(p==null&&(p=wf(/^\s*/.exec(e.doc.lineAt(r).text)[0],e.tabSize));a<c.to&&/\s/.test(c.text[a-c.from]);)a++;u?{from:r,to:a}=u:r>c.from&&r<c.from+100&&!/\S/.test(c.text.slice(0,r))&&(r=c.from);let m=["",Om(e,p)];return u&&m.push(Om(e,d.lineIndent(c.from,-1))),{changes:{from:r,to:a,insert:jn.of(m)},range:Ne.cursor(r+1+m[1].length)}});return n(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function kC(t,e){let n=-1;return t.changeByRange(i=>{let s=[];for(let a=i.from;a<=i.to;){let c=t.doc.lineAt(a);c.number>n&&(i.empty||i.to>c.from)&&(e(c,s,i),n=c.number),a=c.to+1}let r=t.changes(s);return{changes:s,range:Ne.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}const jZ=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=Object.create(null),i=new Jx(t,{overrideIndentation:r=>{let a=n[r];return a??-1}}),s=kC(t,(r,a,c)=>{let u=gC(i,r.from);if(u==null)return;/\S/.test(r.text)||(u=0);let d=/^\s*/.exec(r.text)[0],p=Om(t,u);(d!=p||c.from<r.from+d.length)&&(n[r.from]=u,a.push({from:r.from,to:r.from+d.length,insert:p}))});return s.changes.empty||e(t.update(s,{userEvent:"indent"})),!0},N6=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(kC(t,(n,i)=>{i.push({from:n.from,insert:t.facet(Zx)})}),{userEvent:"input.indent"})),!0),E6=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(kC(t,(n,i)=>{let s=/^\s*/.exec(n.text)[0];if(!s)return;let r=wf(s,t.tabSize),a=0,c=Om(t,Math.max(0,r-bh(t)));for(;a<s.length&&a<c.length&&s.charCodeAt(a)==c.charCodeAt(a);)a++;i.push({from:n.from+a,to:n.from+s.length,insert:c.slice(a)})}),{userEvent:"delete.dedent"})),!0),AZ=t=>(t.setTabFocusMode(),!0),NZ=[{key:"Ctrl-b",run:s6,shift:f6,preventDefault:!0},{key:"Ctrl-f",run:r6,shift:p6},{key:"Ctrl-p",run:l6,shift:v6},{key:"Ctrl-n",run:c6,shift:x6},{key:"Ctrl-a",run:KQ,shift:rZ},{key:"Ctrl-e",run:GQ,shift:aZ},{key:"Ctrl-d",run:w6},{key:"Ctrl-h",run:Vw},{key:"Ctrl-k",run:pZ},{key:"Ctrl-Alt-h",run:S6},{key:"Ctrl-o",run:vZ},{key:"Ctrl-t",run:xZ},{key:"Ctrl-v",run:Uw}],EZ=[{key:"ArrowLeft",run:s6,shift:f6,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:$Q,shift:QQ,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:UQ,shift:iZ,preventDefault:!0},{key:"ArrowRight",run:r6,shift:p6,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:PQ,shift:ZQ,preventDefault:!0},{mac:"Cmd-ArrowRight",run:VQ,shift:sZ,preventDefault:!0},{key:"ArrowUp",run:l6,shift:v6,preventDefault:!0},{mac:"Cmd-ArrowUp",run:$E,shift:zE},{mac:"Ctrl-ArrowUp",run:BE,shift:OE},{key:"ArrowDown",run:c6,shift:x6,preventDefault:!0},{mac:"Cmd-ArrowDown",run:PE,shift:FE},{mac:"Ctrl-ArrowDown",run:Uw,shift:IE},{key:"PageUp",run:BE,shift:OE},{key:"PageDown",run:Uw,shift:IE},{key:"Home",run:qQ,shift:nZ,preventDefault:!0},{key:"Mod-Home",run:$E,shift:zE},{key:"End",run:WQ,shift:tZ,preventDefault:!0},{key:"Mod-End",run:PE,shift:FE},{key:"Enter",run:HE,shift:HE},{key:"Mod-a",run:oZ},{key:"Backspace",run:Vw,shift:Vw,preventDefault:!0},{key:"Delete",run:w6,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:S6,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:fZ,preventDefault:!0},{mac:"Mod-Backspace",run:mZ,preventDefault:!0},{mac:"Mod-Delete",run:gZ,preventDefault:!0}].concat(NZ.map(t=>({mac:t.key,run:t.run,shift:t.shift}))),MZ=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:FQ,shift:JQ},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:HQ,shift:eZ},{key:"Alt-ArrowUp",run:yZ},{key:"Shift-Alt-ArrowUp",run:bZ},{key:"Alt-ArrowDown",run:_Z},{key:"Shift-Alt-ArrowDown",run:wZ},{key:"Mod-Alt-ArrowUp",run:uZ},{key:"Mod-Alt-ArrowDown",run:hZ},{key:"Escape",run:dZ},{key:"Mod-Enter",run:CZ},{key:"Alt-l",mac:"Ctrl-l",run:lZ},{key:"Mod-i",run:cZ,preventDefault:!0},{key:"Mod-[",run:E6},{key:"Mod-]",run:N6},{key:"Mod-Alt-\\",run:jZ},{key:"Shift-Mod-k",run:kZ},{key:"Shift-Mod-\\",run:XQ},{key:"Mod-/",run:yQ},{key:"Alt-A",mac:"Ctrl-A",run:bQ},{key:"Ctrl-m",mac:"Shift-Alt-m",run:AZ}].concat(EZ),LZ={key:"Tab",run:N6,shift:E6},WE=typeof String.prototype.normalize=="function"?t=>t.normalize("NFKD"):t=>t;class gf{constructor(e,n,i=0,s=e.length,r,a){this.test=a,this.value={from:0,to:0,precise:!1},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,s),this.bufferStart=i,this.normalize=r?c=>r(WE(c)):WE,this.query=this.normalize(n)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return QS(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let n=NK(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=u3(e);let s=this.normalize(n);if(s.length)for(let r=0,a=i,c=!0;;r++){let u=s.charCodeAt(r),d=this.match(u,a,c,this.bufferPos+this.bufferStart,r==s.length-1);if(d)return this.value=d,this;if(r==s.length-1)break;c&&r<n.length&&n.charCodeAt(r)==u?a++:c=!1}}}match(e,n,i,s,r){let a=null;for(let c=0;c<this.matches.length;){let u=this.matches[c],d=!1;this.query.charCodeAt(u.index)==e&&(u.index==this.query.length-1?a={from:u.from,to:s,precise:r&&u.precise}:(u.index++,d=!0)),d?c++:this.matches.splice(c,1)}return this.query.charCodeAt(0)==e&&(this.query.length==1?a={from:n,to:s,precise:i&&r}:this.matches.push({from:n,index:1,precise:i})),a&&this.test&&!this.test(a.from,a.to,this.buffer,this.bufferStart)&&(a=null),a}}typeof Symbol<"u"&&(gf.prototype[Symbol.iterator]=function(){return this});const M6={from:-1,to:-1,match:/.*/.exec(""),precise:!0},SC="gm"+(/x/.unicode==null?"":"u");class L6{constructor(e,n,i,s=0,r=e.length){if(this.text=e,this.to=r,this.curLine="",this.done=!1,this.value=M6,/\\[sWDnr]|\n|\r|\[\^/.test(n))return new T6(e,n,i,s,r);this.re=new RegExp(n,SC+(i?.ignoreCase?"i":"")),this.test=i?.test,this.iter=e.iter();let a=e.lineAt(s);this.curLineStart=a.from,this.matchPos=px(e,s),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let n=this.matchPos<=this.to&&this.re.exec(this.curLine);if(n){let i=this.curLineStart+n.index,s=i+n[0].length;if(this.matchPos=px(this.text,s+(i==s?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<s||i>this.value.to)&&(!this.test||this.test(i,s,n)))return this.value={from:i,to:s,precise:!0,match:n},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const Db=new WeakMap;class Jd{constructor(e,n){this.from=e,this.text=n}get to(){return this.from+this.text.length}static get(e,n,i){let s=Db.get(e);if(!s||s.from>=i||s.to<=n){let c=new Jd(n,e.sliceString(n,i));return Db.set(e,c),c}if(s.from==n&&s.to==i)return s;let{text:r,from:a}=s;return a>n&&(r=e.sliceString(n,a)+r,a=n),s.to<i&&(r+=e.sliceString(s.to,i)),Db.set(e,new Jd(a,r)),new Jd(n,r.slice(n-a,i-a))}}class T6{constructor(e,n,i,s,r){this.text=e,this.to=r,this.done=!1,this.value=M6,this.matchPos=px(e,s),this.re=new RegExp(n,SC+(i?.ignoreCase?"i":"")),this.test=i?.test,this.flat=Jd.get(e,s,this.chunkEnd(s+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,n=this.re.exec(this.flat.text);if(n&&!n[0]&&n.index==e&&(this.re.lastIndex=e+1,n=this.re.exec(this.flat.text)),n){let i=this.flat.from+n.index,s=i+n[0].length;if((this.flat.to>=this.to||n.index+n[0].length<=this.flat.text.length-10)&&(!this.test||this.test(i,s,n)))return this.value={from:i,to:s,precise:!0,match:n},this.matchPos=px(this.text,s+(i==s?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Jd.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(L6.prototype[Symbol.iterator]=T6.prototype[Symbol.iterator]=function(){return this});function TZ(t){try{return new RegExp(t,SC),!0}catch{return!1}}function px(t,e){if(e>=t.length)return e;let n=t.lineAt(e),i;for(;e<n.to&&(i=n.text.charCodeAt(e-n.from))>=56320&&i<57344;)e++;return e}const RZ=t=>{let{state:e}=t,n=String(e.doc.lineAt(t.state.selection.main.head).number),{close:i,result:s}=iX(t,{label:e.phrase("Go to line"),input:{type:"text",name:"line",value:n},focus:!0,submitLabel:e.phrase("go")});return s.then(r=>{let a=r&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(r.elements.line.value);if(!a){t.dispatch({effects:i});return}let c=e.doc.lineAt(e.selection.main.head),[,u,d,p,m]=a,v=p?+p.slice(1):0,x=d?+d:c.number;if(d&&m){let S=x/100;u&&(S=S*(u=="-"?-1:1)+c.number/e.doc.lines),x=Math.round(e.doc.lines*S)}else d&&u&&(x=x*(u=="-"?-1:1)+c.number);let y=e.doc.line(Math.max(1,Math.min(e.doc.lines,x))),k=Ne.cursor(y.from+Math.max(0,Math.min(v,y.length)));t.dispatch({effects:[i,ct.scrollIntoView(k.from,{y:"center"})],selection:k})}),!0},DZ={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},BZ=nt.define({combine(t){return Ah(t,DZ,{highlightWordAroundCursor:(e,n)=>e||n,minSelectionLength:Math.min,maxMatches:Math.min})}});function OZ(t){return[FZ,zZ]}const IZ=Kt.mark({class:"cm-selectionMatch"}),$Z=Kt.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function qE(t,e,n,i){return(n==0||t(e.sliceDoc(n-1,n))!=Di.Word)&&(i==e.doc.length||t(e.sliceDoc(i,i+1))!=Di.Word)}function PZ(t,e,n,i){return t(e.sliceDoc(n,n+1))==Di.Word&&t(e.sliceDoc(i-1,i))==Di.Word}const zZ=hr.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.selectionSet||t.docChanged||t.viewportChanged)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=t.state.facet(BZ),{state:n}=t,i=n.selection;if(i.ranges.length>1)return Kt.none;let s=i.main,r,a=null;if(s.empty){if(!e.highlightWordAroundCursor)return Kt.none;let u=n.wordAt(s.head);if(!u)return Kt.none;a=n.charCategorizer(s.head),r=n.sliceDoc(u.from,u.to)}else{let u=s.to-s.from;if(u<e.minSelectionLength||u>200)return Kt.none;if(e.wholeWords){if(r=n.sliceDoc(s.from,s.to),a=n.charCategorizer(s.head),!(qE(a,n,s.from,s.to)&&PZ(a,n,s.from,s.to)))return Kt.none}else if(r=n.sliceDoc(s.from,s.to),!r)return Kt.none}let c=[];for(let u of t.visibleRanges){let d=new gf(n.doc,r,u.from,u.to);for(;!d.next().done;){let{from:p,to:m}=d.value;if((!a||qE(a,n,p,m))&&(s.empty&&p<=s.from&&m>=s.to?c.push($Z.range(p,m)):(p>=s.to||m<=s.from)&&c.push(IZ.range(p,m)),c.length>e.maxMatches))return Kt.none}}return Kt.set(c)}},{decorations:t=>t.decorations}),FZ=ct.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),HZ=({state:t,dispatch:e})=>{let{selection:n}=t,i=Ne.create(n.ranges.map(s=>t.wordAt(s.head)||Ne.cursor(s.head)),n.mainIndex);return i.eq(n)?!1:(e(t.update({selection:i})),!0)};function WZ(t,e){let{main:n,ranges:i}=t.selection,s=t.wordAt(n.head),r=s&&s.from==n.from&&s.to==n.to;for(let a=!1,c=new gf(t.doc,e,i[i.length-1].to);;)if(c.next(),c.done){if(a)return null;c=new gf(t.doc,e,0,Math.max(0,i[i.length-1].from-1)),a=!0}else{if(a&&i.some(u=>u.from==c.value.from))continue;if(r){let u=t.wordAt(c.value.from);if(!u||u.from!=c.value.from||u.to!=c.value.to)continue}return c.value}}const qZ=({state:t,dispatch:e})=>{let{ranges:n}=t.selection;if(n.some(r=>r.from===r.to))return HZ({state:t,dispatch:e});let i=t.sliceDoc(n[0].from,n[0].to);if(t.selection.ranges.some(r=>t.sliceDoc(r.from,r.to)!=i))return!1;let s=WZ(t,i);return s?(e(t.update({selection:t.selection.addRange(Ne.range(s.from,s.to),!1),effects:ct.scrollIntoView(s.to)})),!0):!1},Nh=nt.define({combine(t){return Ah(t,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new rJ(e),scrollToMatch:e=>ct.scrollIntoView(e)})}});function UZ(t){return t?[Nh.of(t),Gw]:Gw}class R6{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||TZ(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(n,i)=>i=="n"?`
68
- `:i=="r"?"\r":i=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new QZ(this):new GZ(this)}getCursor(e,n=0,i){let s=e.doc?e:vn.create({doc:e});return i==null&&(i=s.doc.length),this.regexp?Bd(this,s,n,i):Dd(this,s,n,i)}}class D6{constructor(e){this.spec=e}}function VZ(t,e,n){return(i,s,r,a)=>{if(n&&!n(i,s,r,a))return!1;let c=i>=a&&s<=a+r.length?r.slice(i-a,s-a):e.doc.sliceString(i,s);return t(c,e,i,s)}}function Dd(t,e,n,i){let s;return t.wholeWord&&(s=KZ(e.doc,e.charCategorizer(e.selection.main.head))),t.test&&(s=VZ(t.test,e,s)),new gf(e.doc,t.unquoted,n,i,t.caseSensitive?void 0:r=>r.toLowerCase(),s)}function KZ(t,e){return(n,i,s,r)=>((r>n||r+s.length<i)&&(r=Math.max(0,n-2),s=t.sliceString(r,Math.min(t.length,i+2))),(e(mx(s,n-r))!=Di.Word||e(gx(s,n-r))!=Di.Word)&&(e(gx(s,i-r))!=Di.Word||e(mx(s,i-r))!=Di.Word))}class GZ extends D6{constructor(e){super(e)}nextMatch(e,n,i){let s=Dd(this.spec,e,i,e.doc.length).nextOverlapping();if(s.done){let r=Math.min(e.doc.length,n+this.spec.unquoted.length);s=Dd(this.spec,e,0,r).nextOverlapping()}return s.done||s.value.from==n&&s.value.to==i?null:s.value}prevMatchInRange(e,n,i){for(let s=i;;){let r=Math.max(n,s-1e4-this.spec.unquoted.length),a=Dd(this.spec,e,r,s),c=null;for(;!a.nextOverlapping().done;)c=a.value;if(c)return c;if(r==n)return null;s-=1e4}}prevMatch(e,n,i){let s=this.prevMatchInRange(e,0,n);return s||(s=this.prevMatchInRange(e,Math.max(0,i-this.spec.unquoted.length),e.doc.length)),s&&(s.from!=n||s.to!=i)?s:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,n){let i=Dd(this.spec,e,0,e.doc.length),s=[];for(;!i.next().done;){if(s.length>=n)return null;s.push(i.value)}return s}highlight(e,n,i,s){let r=Dd(this.spec,e,Math.max(0,n-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,e.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}function YZ(t,e,n){return(i,s,r)=>(!n||n(i,s,r))&&t(r[0],e,i,s)}function Bd(t,e,n,i){let s;return t.wholeWord&&(s=XZ(e.charCategorizer(e.selection.main.head))),t.test&&(s=YZ(t.test,e,s)),new L6(e.doc,t.search,{ignoreCase:!t.caseSensitive,test:s},n,i)}function mx(t,e){return t.slice(bs(t,e,!1),e)}function gx(t,e){return t.slice(e,bs(t,e))}function XZ(t){return(e,n,i)=>!i[0].length||(t(mx(i.input,i.index))!=Di.Word||t(gx(i.input,i.index))!=Di.Word)&&(t(gx(i.input,i.index+i[0].length))!=Di.Word||t(mx(i.input,i.index+i[0].length))!=Di.Word)}class QZ extends D6{nextMatch(e,n,i){let s=Bd(this.spec,e,i,e.doc.length).next();return s.done&&(s=Bd(this.spec,e,0,n).next()),s.done?null:s.value}prevMatchInRange(e,n,i){for(let s=1;;s++){let r=Math.max(n,i-s*1e4),a=Bd(this.spec,e,r,i),c=null;for(;!a.next().done;)c=a.value;if(c&&(r==n||c.from>r+10))return c;if(r==n)return null}}prevMatch(e,n,i){return this.prevMatchInRange(e,0,n)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(n,i)=>{if(i=="&")return e.match[0];if(i=="$")return"$";for(let s=i.length;s>0;s--){let r=+i.slice(0,s);if(r>0&&r<e.match.length)return e.match[r]+i.slice(s)}return n})}matchAll(e,n){let i=Bd(this.spec,e,0,e.doc.length),s=[];for(;!i.next().done;){if(s.length>=n)return null;s.push(i.value)}return s}highlight(e,n,i,s){let r=Bd(this.spec,e,Math.max(0,n-250),Math.min(i+250,e.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}const $m=Gn.define(),CC=Gn.define(),Vc=tl.define({create(t){return new Bb(Kw(t).create(),null)},update(t,e){for(let n of e.effects)n.is($m)?t=new Bb(n.value.create(),t.panel):n.is(CC)&&(t=new Bb(t.query,n.value?jC:null));return t},provide:t=>ux.from(t,e=>e.panel)});class Bb{constructor(e,n){this.query=e,this.panel=n}}const ZZ=Kt.mark({class:"cm-searchMatch"}),JZ=Kt.mark({class:"cm-searchMatch cm-searchMatch-selected"}),eJ=hr.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(Vc))}update(t){let e=t.state.field(Vc);(e!=t.startState.field(Vc)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return Kt.none;let{view:n}=this,i=new vh;for(let s=0,r=n.visibleRanges,a=r.length;s<a;s++){let{from:c,to:u}=r[s];for(;s<a-1&&u>r[s+1].from-500;)u=r[++s].to;t.highlight(n.state,c,u,(d,p)=>{let m=n.state.selection.ranges.some(v=>v.from==d&&v.to==p);i.add(d,p,m?JZ:ZZ)})}return i.finish()}},{decorations:t=>t.decorations});function sg(t){return e=>{let n=e.state.field(Vc,!1);return n&&n.query.spec.valid?t(e,n):I6(e)}}const vx=sg((t,{query:e})=>{let{to:n}=t.state.selection.main,i=e.nextMatch(t.state,n,n);if(!i)return!1;let s=Ne.single(i.from,i.to),r=t.state.facet(Nh);return t.dispatch({selection:s,effects:[AC(t,i),r.scrollToMatch(s.main,t)],userEvent:"select.search"}),O6(t),!0}),xx=sg((t,{query:e})=>{let{state:n}=t,{from:i}=n.selection.main,s=e.prevMatch(n,i,i);if(!s)return!1;let r=Ne.single(s.from,s.to),a=t.state.facet(Nh);return t.dispatch({selection:r,effects:[AC(t,s),a.scrollToMatch(r.main,t)],userEvent:"select.search"}),O6(t),!0}),tJ=sg((t,{query:e})=>{let n=e.matchAll(t.state,1e3);return!n||!n.length?!1:(t.dispatch({selection:Ne.create(n.map(i=>Ne.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),nJ=({state:t,dispatch:e})=>{let n=t.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:i,to:s}=n.main,r=[],a=0;for(let c=new gf(t.doc,t.sliceDoc(i,s));!c.next().done;){if(r.length>1e3)return!1;c.value.from==i&&(a=r.length),r.push(Ne.range(c.value.from,c.value.to))}return e(t.update({selection:Ne.create(r,a),userEvent:"select.search.matches"})),!0},UE=sg((t,{query:e})=>{let{state:n}=t,{from:i,to:s}=n.selection.main;if(n.readOnly)return!1;let r=e.nextMatch(n,i,i);if(!r)return!1;let a=r,c=[],u,d,p=[];a.precise?a.from==i&&a.to==s&&(d=n.toText(e.getReplacement(a)),c.push({from:a.from,to:a.to,insert:d}),a=e.nextMatch(n,a.from,a.to),p.push(ct.announce.of(n.phrase("replaced match on line $",n.doc.lineAt(i).number)+"."))):a=e.nextMatch(n,a.from,a.to);let m=t.state.changes(c);return a&&(u=Ne.single(a.from,a.to).map(m),p.push(AC(t,a)),p.push(n.facet(Nh).scrollToMatch(u.main,t))),t.dispatch({changes:m,selection:u,effects:p,userEvent:"input.replace"}),!0}),iJ=sg((t,{query:e})=>{if(t.state.readOnly)return!1;let n=[];for(let s of e.matchAll(t.state,1e9)){let{from:r,to:a,precise:c}=s;c&&n.push({from:r,to:a,insert:e.getReplacement(s)})}if(!n.length)return!1;let i=t.state.phrase("replaced $ matches",n.length)+".";return t.dispatch({changes:n,effects:ct.announce.of(i),userEvent:"input.replace.all"}),!0});function jC(t){return t.state.facet(Nh).createPanel(t)}function Kw(t,e){var n,i,s,r,a;let c=t.selection.main,u=c.empty||c.to>c.from+100?"":t.sliceDoc(c.from,c.to);if(e&&!u)return e;let d=t.facet(Nh);return new R6({search:((n=e?.literal)!==null&&n!==void 0?n:d.literal)?u:u.replace(/\n/g,"\\n"),caseSensitive:(i=e?.caseSensitive)!==null&&i!==void 0?i:d.caseSensitive,literal:(s=e?.literal)!==null&&s!==void 0?s:d.literal,regexp:(r=e?.regexp)!==null&&r!==void 0?r:d.regexp,wholeWord:(a=e?.wholeWord)!==null&&a!==void 0?a:d.wholeWord})}function B6(t){let e=CD(t,jC);return e&&e.dom.querySelector("[main-field]")}function O6(t){let e=B6(t);e&&e==t.root.activeElement&&e.select()}const I6=t=>{let e=t.state.field(Vc,!1);if(e&&e.panel){let n=B6(t);if(n&&n!=t.root.activeElement){let i=Kw(t.state,e.query.spec);i.valid&&t.dispatch({effects:$m.of(i)}),n.focus(),n.select()}}else t.dispatch({effects:[CC.of(!0),e?$m.of(Kw(t.state,e.query.spec)):Gn.appendConfig.of(Gw)]});return!0},$6=t=>{let e=t.state.field(Vc,!1);if(!e||!e.panel)return!1;let n=CD(t,jC);return n&&n.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:CC.of(!1)}),!0},sJ=[{key:"Mod-f",run:I6,scope:"editor search-panel"},{key:"F3",run:vx,shift:xx,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:vx,shift:xx,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:$6,scope:"editor search-panel"},{key:"Mod-Shift-l",run:nJ},{key:"Mod-Alt-g",run:RZ},{key:"Mod-d",run:qZ,preventDefault:!0}];class rJ{constructor(e){this.view=e;let n=this.query=e.state.field(Vc).query.spec;this.commit=this.commit.bind(this),this.searchField=fs("input",{value:n.search,placeholder:Kr(e,"Find"),"aria-label":Kr(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=fs("input",{value:n.replace,placeholder:Kr(e,"Replace"),"aria-label":Kr(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=fs("input",{type:"checkbox",name:"case",form:"",checked:n.caseSensitive,onchange:this.commit}),this.reField=fs("input",{type:"checkbox",name:"re",form:"",checked:n.regexp,onchange:this.commit}),this.wordField=fs("input",{type:"checkbox",name:"word",form:"",checked:n.wholeWord,onchange:this.commit});function i(s,r,a){return fs("button",{class:"cm-button",name:s,onclick:r,type:"button"},a)}this.dom=fs("div",{onkeydown:s=>this.keydown(s),class:"cm-search"},[this.searchField,i("next",()=>vx(e),[Kr(e,"next")]),i("prev",()=>xx(e),[Kr(e,"previous")]),i("select",()=>tJ(e),[Kr(e,"all")]),fs("label",null,[this.caseField,Kr(e,"match case")]),fs("label",null,[this.reField,Kr(e,"regexp")]),fs("label",null,[this.wordField,Kr(e,"by word")]),...e.state.readOnly?[]:[fs("br"),this.replaceField,i("replace",()=>UE(e),[Kr(e,"replace")]),i("replaceAll",()=>iJ(e),[Kr(e,"replace all")])],fs("button",{name:"close",onclick:()=>$6(e),"aria-label":Kr(e,"close"),type:"button"},["×"])])}commit(){let e=new R6({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:$m.of(e)}))}keydown(e){NY(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?xx:vx)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),UE(this.view))}update(e){for(let n of e.transactions)for(let i of n.effects)i.is($m)&&!i.value.eq(this.query)&&this.setQuery(i.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Nh).top}}function Kr(t,e){return t.state.phrase(e)}const Hv=30,Wv=/[\s\.,:;?!]/;function AC(t,{from:e,to:n}){let i=t.state.doc.lineAt(e),s=t.state.doc.lineAt(n).to,r=Math.max(i.from,e-Hv),a=Math.min(s,n+Hv),c=t.state.sliceDoc(r,a);if(r!=i.from){for(let u=0;u<Hv;u++)if(!Wv.test(c[u+1])&&Wv.test(c[u])){c=c.slice(u);break}}if(a!=s){for(let u=c.length-1;u>c.length-Hv;u--)if(!Wv.test(c[u-1])&&Wv.test(c[u])){c=c.slice(0,u);break}}return ct.announce.of(`${t.state.phrase("current match")}. ${c} ${t.state.phrase("on line")} ${i.number}.`)}const aJ=ct.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),Gw=[Vc,Zm.low(eJ),aJ],oJ="modulepreload",lJ=function(t,e){return new URL(t,e).href},VE={},mt=function(e,n,i){let s=Promise.resolve();if(n&&n.length>0){let d=function(p){return Promise.all(p.map(m=>Promise.resolve(m).then(v=>({status:"fulfilled",value:v}),v=>({status:"rejected",reason:v}))))};const a=document.getElementsByTagName("link"),c=document.querySelector("meta[property=csp-nonce]"),u=c?.nonce||c?.getAttribute("nonce");s=d(n.map(p=>{if(p=lJ(p,i),p in VE)return;VE[p]=!0;const m=p.endsWith(".css"),v=m?'[rel="stylesheet"]':"";if(i)for(let y=a.length-1;y>=0;y--){const k=a[y];if(k.href===p&&(!m||k.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${p}"]${v}`))return;const x=document.createElement("link");if(x.rel=m?"stylesheet":oJ,m||(x.as="script"),x.crossOrigin="",x.href=p,u&&x.setAttribute("nonce",u),document.head.appendChild(x),m)return new Promise((y,k)=>{x.addEventListener("load",y),x.addEventListener("error",()=>k(new Error(`Unable to preload CSS for ${p}`)))})}))}function r(a){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=a,window.dispatchEvent(c),!c.defaultPrevented)throw a}return s.then(a=>{for(const c of a||[])c.status==="rejected"&&r(c.reason);return e().catch(r)})},_n=t=>xC.define(t),cJ={js:()=>mt(()=>import("./index-jqMjQWrX.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript()),mjs:()=>mt(()=>import("./index-jqMjQWrX.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript()),cjs:()=>mt(()=>import("./index-jqMjQWrX.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript()),jsx:()=>mt(()=>import("./index-jqMjQWrX.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({jsx:!0})),ts:()=>mt(()=>import("./index-jqMjQWrX.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({typescript:!0})),mts:()=>mt(()=>import("./index-jqMjQWrX.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({typescript:!0})),cts:()=>mt(()=>import("./index-jqMjQWrX.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({typescript:!0})),tsx:()=>mt(()=>import("./index-jqMjQWrX.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({jsx:!0,typescript:!0})),json:()=>mt(()=>import("./index-y2CSEYBe.js"),__vite__mapDeps([3,1]),import.meta.url).then(t=>t.json()),jsonc:()=>mt(()=>import("./index-y2CSEYBe.js"),__vite__mapDeps([3,1]),import.meta.url).then(t=>t.json()),md:()=>mt(()=>import("./index-_DD02urZ.js"),__vite__mapDeps([4,2,5,1,6,0]),import.meta.url).then(t=>t.markdown()),markdown:()=>mt(()=>import("./index-_DD02urZ.js"),__vite__mapDeps([4,2,5,1,6,0]),import.meta.url).then(t=>t.markdown()),mdx:()=>mt(()=>import("./index-_DD02urZ.js"),__vite__mapDeps([4,2,5,1,6,0]),import.meta.url).then(t=>t.markdown()),html:()=>mt(()=>import("./index-Cy-oeOwN.js"),__vite__mapDeps([5,1,6,0,2]),import.meta.url).then(t=>t.html()),htm:()=>mt(()=>import("./index-Cy-oeOwN.js"),__vite__mapDeps([5,1,6,0,2]),import.meta.url).then(t=>t.html()),cshtml:()=>mt(()=>import("./index-Cy-oeOwN.js"),__vite__mapDeps([5,1,6,0,2]),import.meta.url).then(t=>t.html()),vue:()=>mt(()=>import("./index-Cy-oeOwN.js"),__vite__mapDeps([5,1,6,0,2]),import.meta.url).then(t=>t.html()),css:()=>mt(()=>import("./index-CCTszXv6.js"),__vite__mapDeps([6,1]),import.meta.url).then(t=>t.css()),scss:()=>mt(()=>import("./index-CCTszXv6.js"),__vite__mapDeps([6,1]),import.meta.url).then(t=>t.css()),less:()=>mt(()=>import("./index-CCTszXv6.js"),__vite__mapDeps([6,1]),import.meta.url).then(t=>t.css()),rs:()=>mt(()=>import("./index-BrrKATvL.js"),__vite__mapDeps([7,1]),import.meta.url).then(t=>t.rust()),py:()=>mt(()=>import("./index-CCcxHg-5.js"),__vite__mapDeps([8,1,2]),import.meta.url).then(t=>t.python()),pyi:()=>mt(()=>import("./index-CCcxHg-5.js"),__vite__mapDeps([8,1,2]),import.meta.url).then(t=>t.python()),sql:()=>mt(()=>import("./index-Bzmn7TfA.js"),__vite__mapDeps([9,1,2]),import.meta.url).then(t=>t.sql()),yaml:()=>mt(()=>import("./index-BOHzLyXg.js"),__vite__mapDeps([10,1]),import.meta.url).then(t=>t.yaml()),yml:()=>mt(()=>import("./index-BOHzLyXg.js"),__vite__mapDeps([10,1]),import.meta.url).then(t=>t.yaml()),sh:()=>mt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>_n(t.shell)),bash:()=>mt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>_n(t.shell)),zsh:()=>mt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>_n(t.shell)),fish:()=>mt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>_n(t.shell)),cs:()=>mt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>_n(t.csharp)),c:()=>mt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>_n(t.c)),h:()=>mt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>_n(t.c)),cpp:()=>mt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>_n(t.cpp)),hpp:()=>mt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>_n(t.cpp)),java:()=>mt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>_n(t.java)),kt:()=>mt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>_n(t.kotlin)),swift:()=>mt(()=>import("./swift-BzpIVaGY.js"),[],import.meta.url).then(t=>_n(t.swift)),go:()=>mt(()=>import("./go-CTD25R5P.js"),[],import.meta.url).then(t=>_n(t.go)),rb:()=>mt(()=>import("./ruby-B2Rjki9n.js"),[],import.meta.url).then(t=>_n(t.ruby)),lua:()=>mt(()=>import("./lua-VAEuO923.js"),[],import.meta.url).then(t=>_n(t.lua)),toml:()=>mt(()=>import("./toml-Bm5Em-hy.js"),[],import.meta.url).then(t=>_n(t.toml)),xml:()=>mt(()=>import("./xml-BQQZnNBQ.js"),[],import.meta.url).then(t=>_n(t.xml)),svg:()=>mt(()=>import("./xml-BQQZnNBQ.js"),[],import.meta.url).then(t=>_n(t.xml)),xaml:()=>mt(()=>import("./xml-BQQZnNBQ.js"),[],import.meta.url).then(t=>_n(t.xml)),csproj:()=>mt(()=>import("./xml-BQQZnNBQ.js"),[],import.meta.url).then(t=>_n(t.xml)),diff:()=>mt(()=>import("./diff-DbItnlRl.js"),[],import.meta.url).then(t=>_n(t.diff)),patch:()=>mt(()=>import("./diff-DbItnlRl.js"),[],import.meta.url).then(t=>_n(t.diff)),ps1:()=>mt(()=>import("./powershell-CFHJl5sT.js"),[],import.meta.url).then(t=>_n(t.powerShell)),properties:()=>mt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>_n(t.properties)),ini:()=>mt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>_n(t.properties)),env:()=>mt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>_n(t.properties))},KE={dockerfile:()=>mt(()=>import("./dockerfile-ZL4hHokT.js"),[],import.meta.url).then(t=>_n(t.dockerFile)),makefile:()=>mt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>_n(t.shell)),".env":()=>mt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>_n(t.properties)),".gitignore":()=>mt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>_n(t.properties)),".dockerignore":()=>mt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>_n(t.properties)),".editorconfig":()=>mt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>_n(t.properties))};async function uJ(t){const e=(t.split("/").pop()??t).toLowerCase(),n=KE[e]??KE[e.slice(0,e.indexOf(".",1))];if(n)return n();const i=e.lastIndexOf(".");if(i<=0)return null;const s=cJ[e.slice(i+1)];return s?s():null}const hJ=ey.define([{tag:[He.comment,He.lineComment,He.blockComment,He.docComment],color:"var(--syntax-comment)",fontStyle:"italic"},{tag:[He.keyword,He.modifier,He.controlKeyword,He.moduleKeyword],color:"var(--syntax-keyword)"},{tag:[He.string,He.special(He.string),He.regexp],color:"var(--syntax-string)"},{tag:[He.number,He.bool,He.null,He.atom],color:"var(--syntax-number)"},{tag:[He.function(He.variableName),He.function(He.propertyName),He.labelName],color:"var(--syntax-function)"},{tag:[He.typeName,He.className,He.namespace,He.self],color:"var(--syntax-type)"},{tag:[He.propertyName,He.attributeName],color:"var(--syntax-property)"},{tag:[He.variableName,He.definition(He.variableName)],color:"var(--fg-1)"},{tag:[He.operator,He.punctuation,He.separator,He.bracket],color:"var(--fg-2)"},{tag:[He.tagName],color:"var(--syntax-property)"},{tag:[He.heading],color:"var(--syntax-function)",fontWeight:"600"},{tag:[He.link,He.url],color:"var(--link)",textDecoration:"underline"},{tag:[He.emphasis],fontStyle:"italic"},{tag:[He.strong],fontWeight:"600"},{tag:[He.invalid],color:"var(--syntax-property)"}]),dJ=ct.theme({"&":{height:"100%",fontSize:"var(--ws-code-size)",backgroundColor:"var(--bg-0)",color:"var(--fg-1)"},".cm-scroller":{fontFamily:"var(--mono)",lineHeight:"1.7",overflow:"auto",paddingBottom:"calc(28px + env(safe-area-inset-bottom))"},".cm-content":{caretColor:"var(--accent)",padding:"10px 0 0"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"var(--accent)",borderLeftWidth:"2px"},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:"color-mix(in srgb, var(--focus) 25%, transparent)"},".cm-gutters":{backgroundColor:"var(--bg-0)",color:"var(--fg-3)",border:"0",paddingRight:"4px"},".cm-activeLine":{backgroundColor:"color-mix(in srgb, var(--fg-0) 4%, transparent)"},".cm-activeLineGutter":{backgroundColor:"transparent",color:"var(--fg-2)"},".cm-selectionMatch":{backgroundColor:"color-mix(in srgb, var(--warn) 20%, transparent)"},".cm-matchingBracket, &.cm-focused .cm-matchingBracket":{backgroundColor:"color-mix(in srgb, var(--focus) 24%, transparent)",outline:"0"},".cm-panels":{backgroundColor:"var(--bg-sunken)",color:"var(--fg-1)"},".cm-panels input, .cm-panels button":{backgroundColor:"var(--bg-1)",color:"var(--fg-1)",border:"1px solid var(--border)",borderRadius:"var(--r-sm)",padding:"3px 6px",font:"inherit"}},{dark:!0});function fJ({path:t,initialDoc:e,readOnly:n=!1,onChange:i,onSave:s,onSelect:r}){const a=_.useRef(null),c=_.useRef(null),u=_.useRef(i),d=_.useRef(s),p=_.useRef(r);return u.current=i,d.current=s,p.current=r,_.useEffect(()=>{const m=a.current;if(!m)return;const v=new Jm,x=vn.create({doc:e,extensions:[fX(),gX(),XY(),qY(),NQ(),DY(),nX(),QX(),lQ(),OZ(),UZ({top:!0}),ct.lineWrapping,Zx.of(" "),JX(hJ),dJ,v.of([]),vn.readOnly.of(n),ct.editable.of(!n),ct.contentAttributes.of({autocapitalize:"off",autocorrect:"off",spellcheck:"false"}),yD.of([{key:"Mod-s",preventDefault:!0,run:()=>(d.current(),!0)},{key:"Escape",run:A=>(A.contentDOM.blur(),!0)},...sJ,...IQ,...MZ,LZ]),ct.updateListener.of(A=>{if(A.docChanged&&u.current(A.state.doc.toString()),A.selectionSet||A.docChanged){const{from:N,to:E}=A.state.selection.main;p.current?.({from:N,to:E,text:N===E?"":A.state.doc.sliceString(N,E)})}})]}),y=new ct({state:x,parent:m});c.current=y;const k=t3(Z0("code",t));k&&y.dispatch({effects:k});const S=()=>e3(Z0("code",t),y.scrollSnapshot());y.scrollDOM.addEventListener("scroll",S,{passive:!0});let C=!0;return uJ(t).then(A=>{!C||!A||y.dispatch({effects:v.reconfigure(A)})}).catch(()=>{}),()=>{C=!1,y.scrollDOM.removeEventListener("scroll",S),y.destroy(),c.current=null}},[t,n]),_.useEffect(()=>{const m=a.current;if(!m||typeof IntersectionObserver>"u")return;const v=new IntersectionObserver(x=>{x.some(y=>y.isIntersecting)&&c.current?.requestMeasure()});return v.observe(m),()=>v.disconnect()},[]),o.jsx("div",{className:"ws-cm",ref:a})}function P6({children:t}){return o.jsx("div",{className:"prose-table",children:o.jsx("table",{children:t})})}const pJ={a:KS,table:P6};function mJ(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} kB`:`${(t/(1024*1024)).toFixed(1)} MB`}function gJ({path:t,preview:e,draft:n,onDraft:i,onSave:s,raw:r,generation:a,onProseRef:c,onSelect:u}){if(!e)return o.jsx("div",{className:"dots","aria-label":"loading"});const d=YS(t,e),p=r&&(d==="prose"||d==="page")?"code":d;return p==="image"?o.jsx(xJ,{path:t}):p==="video"?o.jsx(yJ,{path:t,size:e.size},`${t}:${a??0}`):p==="none"?o.jsx(F6,{path:t,preview:e}):p==="page"?o.jsx(vJ,{path:t,html:n}):p==="prose"?o.jsx("div",{className:"prose panel-prose",ref:c,children:o.jsx(PS,{remarkPlugins:[WS],components:pJ,children:n})}):o.jsx(fJ,{path:t,initialDoc:e.content,readOnly:e.truncated,onChange:i,onSave:()=>s?.(),onSelect:u},`${t}:${a??0}`)}function z6({path:t}){const[e,n]=_.useState(!1),[i,s]=_.useState(null),[r,a]=_.useState(!1);async function c(){n(!0),s(null),a(!1);try{await ae.invoke("open_file_native",{path:t}),a(!0)}catch(u){s(u instanceof Error?u.message:String(u))}finally{n(!1)}}return o.jsxs("div",{className:"native-open",children:[o.jsx("button",{className:"native-open-btn",type:"button",disabled:e,onClick:()=>{c()},children:e?"Opening…":"Open in default app"}),o.jsx("p",{className:"native-open-note",children:"On the computer running OctiqFlow"}),r&&o.jsx("p",{className:"native-open-status",role:"status",children:"Opened."}),i&&o.jsx("p",{className:"native-open-error",role:"alert",children:i})]})}function F6({path:t,preview:e,reason:n="Preview unavailable"}){const i=e.kind==="pdf"?"PDF document":"File";return o.jsxs("div",{className:"panel-unsupported",children:[o.jsxs("div",{className:"panel-unsupported-copy",children:[o.jsx("strong",{children:n}),o.jsxs("span",{children:[i," · ",o.jsx(Lt,{children:mJ(e.size)})]})]}),o.jsx(z6,{path:t},t)]})}function vJ({path:t,html:e}){return o.jsx("iframe",{className:"panel-page",title:`${Ri(t)} — preview`,srcDoc:e,sandbox:"allow-scripts allow-popups",referrerPolicy:"no-referrer"})}function xJ({path:t}){const[e,n]=_.useState(null),[i,s]=_.useState(null),r=_.useRef(null);return _.useEffect(()=>{let a=!0;return ae.fetchFile(t).then(c=>{a&&(r.current=URL.createObjectURL(c),n(r.current))}).catch(c=>a&&s(c.message)),()=>{a=!1,r.current&&URL.revokeObjectURL(r.current)}},[t]),i?o.jsx("div",{className:"panel-error",children:i}):e?o.jsx("div",{className:"ws-image",children:o.jsx("img",{src:e,alt:Ri(t)})}):o.jsx("div",{className:"dots","aria-label":"loading"})}function yJ({path:t,size:e}){const[n,i]=_.useState(!1);return n?o.jsx(F6,{path:t,preview:{kind:"video",content:"",truncated:!1,size:e},reason:"This video can’t play in this browser"}):o.jsx("div",{className:"ws-video",children:o.jsx("video",{src:ae.fileUrl(t),controls:!0,playsInline:!0,preload:"metadata","aria-label":Ri(t),onError:()=>i(!0)})})}function _J(t,e){const[n,i]=_.useState("closed"),[s,r]=_.useState(null),a=_.useRef(null),c=_.useRef(!1),u=_.useRef(null);_.useLayoutEffect(()=>i("closed"),[e]),_.useLayoutEffect(()=>{const x=document.getElementById("dock"),y=x?.querySelector(".main:not([hidden])"),k=x?.closest(".app"),S=window.matchMedia("(max-width: 700px)");if(!x||!y||!t){r(null);return}const C=y.inert,A=window.visualViewport,N=()=>{S.matches&&A&&k?.style.setProperty("--reader-viewport-height",`${A.height}px`)},E=()=>{r(S.matches?y:null),S.matches?(x.dataset.readerChat=n,k?.classList.add("is-file-reading"),y.inert=n==="closed",N()):(delete x.dataset.readerChat,k?.classList.remove("is-file-reading"),y.inert=C)};return E(),S.addEventListener("change",E),A?.addEventListener("resize",N),()=>{S.removeEventListener("change",E),A?.removeEventListener("resize",N),y.inert=C,delete x.dataset.readerChat,k?.classList.remove("is-file-reading"),k?.style.removeProperty("--reader-viewport-height")}},[t,n]);function d(){s&&Ea.flushSync(()=>i("half"))}function p(){document.activeElement instanceof HTMLElement&&s?.contains(document.activeElement)&&document.activeElement.blur(),Ea.flushSync(()=>i("closed")),u.current?.focus({preventScroll:!0})}const m=s&&n!=="closed"?Ea.createPortal(o.jsxs("header",{className:"reader-chat-head",children:[o.jsxs("button",{className:"reader-chat-resize",type:"button","aria-label":n==="large"?"Make chat smaller":"Expand chat","aria-expanded":n==="large",onClick:()=>{if(c.current){c.current=!1;return}i(n==="large"?"half":"large")},onPointerDown:x=>{c.current=!1,a.current=x.clientY,x.currentTarget.setPointerCapture(x.pointerId)},onPointerUp:x=>{const y=x.clientY-(a.current??x.clientY);a.current=null,!(Math.abs(y)<30)&&(c.current=!0,x.preventDefault(),y>0?p():i("large"))},onPointerCancel:()=>{a.current=null},children:[o.jsx("span",{className:"reader-chat-grip"}),"Chat"]}),o.jsxs("button",{type:"button",onClick:p,children:["Continue reading ",o.jsx("span",{"aria-hidden":"true",children:"⌄"})]})]}),s):null;return{show:d,collapse:p,size:n,controls:m,launcher:s&&n==="closed"?o.jsxs("button",{ref:u,className:"reader-chat-launch",type:"button",onClick:d,children:[o.jsx("span",{children:"Ask agent / discuss this file"}),o.jsx("span",{"aria-hidden":"true",children:"⌃"})]}):null}}function Ob(t,e){const n=t.getBoundingClientRect().top,i=Array.from(e.children),s=Math.max(0,i.findIndex(a=>a.getBoundingClientRect().bottom>n)),r=[s,s+1,s-1];return{scrollTop:t.scrollTop,blocks:r.flatMap(a=>{const c=i[a];return c?[{text:c.textContent??"",index:a,offset:c.getBoundingClientRect().top-n}]:[]})}}function bJ(t,e,n){const i=Array.from(e.children);for(const s of n.blocks){if(!s.text)continue;const r=i.map((a,c)=>({el:a,index:c})).filter(({el:a})=>a.textContent===s.text).sort((a,c)=>Math.abs(a.index-s.index)-Math.abs(c.index-s.index))[0];if(r){t.scrollTop+=r.el.getBoundingClientRect().top-t.getBoundingClientRect().top-s.offset;return}}t.scrollTop=n.scrollTop}const wJ="octiq.v2.fileWidth",kJ={initial:480,min:320,max:760},SJ="dock";function GE(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} kB`:`${(t/(1024*1024)).toFixed(1)} MB`}function CJ({path:t,open:e,onClose:n}){const[i,s]=_.useState(null),[r,a]=_.useState(null),[c,u]=_.useState(""),[d,p]=_.useState(!1),[m,v]=_.useState(!1),[x,y]=_.useState(!1),[k,S]=_.useState(!1),[C,A]=_.useState(null),[N,E]=_.useState(0),M=_J(e,t),L=_.useRef(null),$=_.useRef(null),V=_.useRef(0),X=XS(),{width:D,startDrag:Q,entered:P}=of(wJ,kJ),z=_.useRef(null),H=_.useRef(null),W=_.useRef(null),F=_.useRef(null),Y=!!i&&c!==i.content,J=_.useRef(c),te=_.useRef(i?.content??"");J.current=c,te.current=i?.content??"";const I=!!i&&i.kind==="text"&&!i.truncated&&Y,U=!!i&&!d&&YS(t,i)==="prose",Z=_.useCallback(async le=>{const Re=++V.current,De=J.current;try{const Ke=await ae.invoke("read_file_preview",{path:t});if(Re!==V.current)return;if(le&&J.current!==De){S(!0);return}le&&W.current&&H.current&&(L.current=Ob(W.current,H.current)),s(Ke),u(Ke.content??""),E(xe=>xe+1),A(null),S(!1),a(null),le||p(!1)}catch(Ke){if(Re!==V.current)return;a(String(Ke.message??Ke))}},[t]);_.useEffect(()=>(s(null),a(null),p(!1),A(null),L.current=null,$.current=null,Z(!1),()=>{V.current++}),[t,Z]),_.useLayoutEffect(()=>{const le=W.current;if(!le||!U)return;const Re=t3(Z0("prose",t));Re&&(le.scrollTop=Re)},[t,U]),_.useLayoutEffect(()=>{U&&W.current&&H.current&&L.current&&bJ(W.current,H.current,L.current)},[N,U,M.size]),_.useEffect(()=>{if(M.size!=="closed"||!$.current||!H.current)return;const le=Array.from(H.current.children).find(De=>De.textContent?.includes($.current));if(!le)return;le.classList.add("reader-return-highlight");const Re=setTimeout(()=>le.classList.remove("reader-return-highlight"),1800);return()=>{clearTimeout(Re),le.classList.remove("reader-return-highlight")}},[M.size]),_.useEffect(()=>{ae.invoke("file_watch_paths",{paths:[t]}).catch(()=>{});const le=ae.on("file-changed",Re=>{if(!(!Array.isArray(Re)||!Re.includes(t))){if(J.current!==te.current){S(!0);return}Z(!0)}});return()=>{le(),ae.invoke("file_watch_paths",{paths:[]}).catch(()=>{})}},[t,Z]);const R=_.useCallback(()=>{const le=window.getSelection();if(!le||le.isCollapsed||le.rangeCount===0)return A(null);const Re=le.getRangeAt(0),De=H.current;if(!De||!De.contains(Re.commonAncestorContainer))return A(null);const Ke=le.toString();if(!Ke.trim())return A(null);const xe=J.current.indexOf(Ke),vt=xe>=0&&J.current.lastIndexOf(Ke)===xe?vN(J.current,xe,xe+Ke.length):{from:0,to:0},Bt=Re.getBoundingClientRect();A({quote:{path:t,text:Ke,...vt},x:Bt.left+Bt.width/2,y:Bt.top})},[t]);_.useEffect(()=>{const le=()=>{requestAnimationFrame(R)};return document.addEventListener("selectionchange",le),()=>document.removeEventListener("selectionchange",le)},[R]);const K=_.useCallback(le=>{if(!le.text.trim())return A(null);const Re=J.current,De=F.current??jJ(z.current);A({quote:{path:t,text:le.text,...vN(Re,le.from,le.to)},...De})},[t]),O=_.useCallback(()=>{C&&($.current=C.quote.text,W.current&&H.current&&(L.current=Ob(W.current,H.current)),M.show(),gK(C.quote),A(null))},[C,M]);_.useEffect(()=>{const le=()=>{const De=document.activeElement;return!De||De===document.body||!!z.current?.contains(De)},Re=De=>{if(le()){if(De.key==="Escape"){if(C)return A(null);if(M.size!=="closed")return M.collapse();Y||n()}De.key==="s"&&(De.metaKey||De.ctrlKey)&&(De.preventDefault(),ie())}};return window.addEventListener("keydown",Re),()=>window.removeEventListener("keydown",Re)});async function ie(){if(!(!I||m)){v(!0),a(null);try{await ae.invoke("write_file",{path:t,content:c}),s(le=>le&&{...le,content:c}),y(!0),setTimeout(()=>y(!1),1600)}catch(le){a(String(le.message??le))}finally{v(!1)}}}async function re(){Y&&!await X({title:"Close without saving?",body:`Your changes to ${Ri(t)} will be lost.`,confirmLabel:"Discard changes",danger:!0})||n()}const ve=typeof document>"u"?null:document.getElementById(SJ);return ve?o.jsxs(o.Fragment,{children:[Ea.createPortal(o.jsxs(o.Fragment,{children:[o.jsx("div",{className:`fpanel-scrim ${P&&e?"is-open":""}`,onClick:()=>{re()},"aria-hidden":"true"}),o.jsxs("aside",{ref:z,className:`fpanel ${P&&e?"is-open":""}`,"aria-label":Ri(t),style:{"--gitp-w":`${D}px`},onPointerUp:le=>{F.current={x:le.clientX,y:le.clientY},R()},children:[o.jsx("div",{className:"gitp-resizer",role:"separator","aria-orientation":"vertical","aria-label":"Resize the file panel",onPointerDown:Q}),o.jsxs("header",{className:"panel-head",children:[o.jsxs("div",{className:"panel-id",children:[o.jsxs("div",{className:"panel-name",children:[Ri(t),Y&&o.jsx("span",{className:"panel-dirty",title:"Unsaved changes"})]}),o.jsx("div",{className:"panel-path",children:o.jsx("bdi",{children:t})})]}),o.jsxs("span",{className:"panel-acts",children:[o.jsx(Y0,{className:"panel-act",icon:o.jsx(Vx,{}),idle:"Copy the path",done:"Path copied",read:()=>({text:t})}),i?.kind==="text"&&o.jsx(Y0,{className:"panel-act",icon:o.jsx(G4,{}),idle:"Copy the whole file",done:"File copied",empty:"Nothing to copy — this file is empty",partial:"Copied what is on screen — the rest of the file was never read",read:()=>({text:c,partial:i.truncated})})]}),cK(t,i)&&o.jsx("button",{className:"panel-btn",type:"button",onClick:()=>p(le=>!le),children:d?"Preview":"Edit"}),i?.kind==="text"&&!i.truncated&&o.jsx("button",{className:"panel-btn is-primary",type:"button",onClick:ie,disabled:!I||m,children:m?"Saving…":x?"Saved":"Save"}),o.jsx("button",{className:"panel-close",type:"button",onClick:()=>{re()},"aria-label":"Close",children:"✕"})]}),r&&o.jsxs("div",{className:"panel-error",children:[r,o.jsx(z6,{path:t},t)]}),k&&o.jsxs("div",{className:"panel-warn is-stale",children:["This file changed on disk while you were editing it.",o.jsx("button",{className:"panel-inline-btn",type:"button",onClick:()=>{Z(!0)},children:"Reload and lose my changes"})]}),i?.truncated&&o.jsxs("div",{className:"panel-warn",children:["Showing the first ",o.jsx(Lt,{children:GE(i.content.length)})," of"," ",o.jsx(Lt,{children:GE(i.size)}),". Saving is off for this file — writing back what is on screen would cut the rest away."]}),o.jsxs("div",{className:"panel-body",ref:W,onScroll:le=>{U&&(e3(Z0("prose",t),le.currentTarget.scrollTop),H.current&&(L.current=Ob(le.currentTarget,H.current)))},children:[!i&&!r&&o.jsx("div",{className:"dots","aria-label":"loading"}),i&&o.jsx(gJ,{path:t,preview:i,draft:c,raw:d,generation:N,onDraft:u,onSave:()=>{ie()},onSelect:K,onProseRef:le=>{H.current=le}})]}),M.launcher]})]}),ve),M.controls,C&&vK()&&Ea.createPortal(o.jsxs("button",{className:"quote-btn reader-quote",type:"button",style:{left:`${C.x}px`,top:`${C.y}px`},onMouseDown:le=>le.preventDefault(),onPointerDown:le=>le.preventDefault(),onClick:O,children:[o.jsx("span",{className:"quote-btn-plus","aria-hidden":"true",children:"+"}),"Add to chat",C.quote.from>0&&o.jsx("span",{className:"quote-btn-at",children:C.quote.to>C.quote.from?`${C.quote.from}–${C.quote.to}`:C.quote.from})]}),document.body)]}):null}function jJ(t){if(!t)return{x:24,y:80};const e=t.getBoundingClientRect();return{x:e.left+e.width/2,y:e.top+40}}const $l=1,H6=8,YE=[1,1.5,2,3,4,6,8],AJ=400;function NC(t){return Number.isFinite(t)?Math.min(H6,Math.max($l,t)):$l}function qv(t,e){const n=NC(t);return(e>0?YE.find(s=>s>n+1e-6):[...YE].reverse().find(s=>s<n-1e-6))??n}function NJ(t,e){return NC(t*Math.exp(-e/AJ))}function EJ(t,e,n,i){const s=i/n;return{x:e.x-(e.x-t.x)*s,y:e.y-(e.y-t.y)*s}}function MJ(t,e,n,i){const s=(c,u)=>Math.max(0,(u*i-c)/2),r=s(e.w,n.w),a=s(e.h,n.h);return{x:Math.min(r,Math.max(-r,t.x)),y:Math.min(a,Math.max(-a,t.y))}}const k0={x:0,y:0},XE=4,Uv={scale:$l,pan:k0};function W6({path:t,onClose:e}){const[n,i]=_.useState(null),[s,r]=_.useState(null),[a,c]=_.useState(Uv),u=_.useRef(null),d=_.useRef(null),p=Z4(t);_.useEffect(()=>{let $=!0,V=null;return c(Uv),ae.fetchFile(t).then(X=>{$&&(V=URL.createObjectURL(X),i(V))}).catch(X=>$&&r(X.message)),()=>{$=!1,V&&URL.revokeObjectURL(V)}},[t]);const m=_.useCallback(($,V,X)=>{const D=NC(V),Q=u.current,P=d.current,z={w:Q?.clientWidth??0,h:Q?.clientHeight??0},H={w:P?.offsetWidth??0,h:P?.offsetHeight??0};return{scale:D,pan:MJ(EJ($.pan,X,$.scale,D),z,H,D)}},[]),v=_.useCallback(($,V=k0)=>c(X=>m(X,$(X.scale),V)),[m]),x=_.useCallback(($,V)=>{const X=u.current?.getBoundingClientRect();return X?{x:$-(X.left+X.width/2),y:V-(X.top+X.height/2)}:k0},[]);_.useEffect(()=>{const $=u.current;if(!$||p)return;const V=X=>{X.preventDefault();const D=X.ctrlKey?X.deltaY*3:X.deltaY;v(Q=>NJ(Q,D),x(X.clientX,X.clientY))};return $.addEventListener("wheel",V,{passive:!1}),()=>$.removeEventListener("wheel",V)},[x,p,n,v]),_.useEffect(()=>{const $=V=>{if(V.key==="Escape")return e();if(p||V.metaKey||V.ctrlKey||V.altKey)return;const X=V.target;X&&(X.tagName==="INPUT"||X.tagName==="TEXTAREA"||X.isContentEditable)||(V.key==="+"||V.key==="="?v(D=>qv(D,1)):V.key==="-"||V.key==="_"?v(D=>qv(D,-1)):V.key==="0"&&c(Uv))};return window.addEventListener("keydown",$),()=>window.removeEventListener("keydown",$)},[e,p,v]);const y=_.useRef(new Map),k=_.useRef(null),S=_.useRef(null),C=_.useRef(!1),A=()=>{const[$,V]=[...y.current.values()];return Math.hypot($.x-V.x,$.y-V.y)},N=()=>{const[$,V]=[...y.current.values()];return x(($.x+V.x)/2,($.y+V.y)/2)};function E($){if(!p){if(y.current.size===0&&(C.current=!1),y.current.set($.pointerId,{x:$.clientX,y:$.clientY}),y.current.size===2){k.current=null,S.current=A(),C.current=!0;return}y.current.size>2||a.scale<=$l||($.target.setPointerCapture?.($.pointerId),k.current={id:$.pointerId,from:{x:$.clientX,y:$.clientY},pan:a.pan})}}function M($){if(!y.current.has($.pointerId))return;if(y.current.set($.pointerId,{x:$.clientX,y:$.clientY}),S.current!==null&&y.current.size===2){const Q=A(),P=S.current>0?Q/S.current:1;S.current=Q,v(z=>z*P,N());return}const V=k.current;if(!V||V.id!==$.pointerId)return;const X=$.clientX-V.from.x,D=$.clientY-V.from.y;(Math.abs(X)>XE||Math.abs(D)>XE)&&(C.current=!0),c(Q=>m({...Q,pan:{x:V.pan.x+X,y:V.pan.y+D}},Q.scale,k0))}function L($){y.current.delete($.pointerId),y.current.size<2&&(S.current=null),k.current?.id===$.pointerId&&(k.current=null)}return Ea.createPortal(o.jsxs("div",{className:"viewer",onClick:()=>C.current?C.current=!1:e(),children:[o.jsxs("div",{className:"viewer-bar",onClick:$=>$.stopPropagation(),children:[o.jsx("span",{className:"viewer-name",children:Ri(t)}),!p&&n&&o.jsxs("div",{className:"viewer-zoom",children:[o.jsx("button",{className:"viewer-btn",type:"button",onClick:()=>v($=>qv($,-1)),disabled:a.scale<=$l,"aria-label":"Zoom out",title:"Zoom out (−)",children:"−"}),o.jsx("button",{className:"viewer-level",type:"button",onClick:()=>c(Uv),disabled:a.scale<=$l,title:"Fit to screen (0)",children:o.jsx(Lt,{children:`${Math.round(a.scale*10)/10}×`})}),o.jsx("button",{className:"viewer-btn",type:"button",onClick:()=>v($=>qv($,1)),disabled:a.scale>=H6,"aria-label":"Zoom in",title:"Zoom in (+)",children:"+"})]}),o.jsx("button",{className:"viewer-close",type:"button",onClick:e,"aria-label":"Close",children:"✕"})]}),s?o.jsx("div",{className:"viewer-error",children:s}):n?p?o.jsx("iframe",{className:"viewer-pdf",src:n,title:Ri(t)}):o.jsx("div",{className:`viewer-stage ${a.scale>$l?"is-zoomed":""}`,ref:u,onPointerDown:E,onPointerMove:M,onPointerUp:L,onPointerCancel:L,onDoubleClick:$=>v(V=>V>$l?$l:2,x($.clientX,$.clientY)),children:o.jsx("img",{className:"viewer-img",ref:d,src:n,alt:Ri(t),draggable:!1,style:{transform:`translate(${a.pan.x}px, ${a.pan.y}px) scale(${a.scale})`},onClick:$=>$.stopPropagation()})}):o.jsx("div",{className:"dots","aria-label":"loading"})]}),document.body)}const LJ=220;function TJ({children:t}){const[e,n]=_.useState(null),[i,s]=_.useState(null),[r,a]=_.useState(null),c=_.useCallback(()=>{n(null),s(null)},[]),u=_.useCallback(d=>{if(tK(d)){s(null),n(null),ae.openFileInBrowser(d);return}GS(d)||Z4(d)?(s(null),n(d)):(n(null),s(d),a(d))},[]);return _.useEffect(()=>{if(i)return;const d=setTimeout(()=>a(null),LJ);return()=>clearTimeout(d)},[i]),o.jsx(V4.Provider,{value:u,children:o.jsxs(K4.Provider,{value:c,children:[t,e&&o.jsx(W6,{path:e,onClose:()=>n(null)}),r&&o.jsx(CJ,{path:r,open:!!i,onClose:()=>s(null)})]})})}function q6({attachment:t}){const[e,n]=_.useState(t.url??null);return _.useEffect(()=>{if(t.url){n(t.url);return}let i=!0,s=null;return ae.fetchFile(t.path).then(r=>{i&&(s=URL.createObjectURL(r),n(s))}).catch(()=>i&&n(null)),()=>{i=!1,s&&URL.revokeObjectURL(s)}},[t.path,t.url]),e?o.jsx("img",{className:"chip-thumb",src:e,alt:""}):o.jsx(DJ,{})}function RJ({files:t}){const e=Ux();return t.length===0?null:o.jsx("div",{className:"sent-files",children:t.map(n=>o.jsxs("button",{className:`chip ${n.isImage?"is-image":""}`,type:"button",title:`${n.path} — click to open`,onClick:()=>e(n.path),children:[n.isImage?o.jsx(q6,{attachment:n}):o.jsx(BJ,{}),o.jsx("span",{className:"chip-name",children:n.name})]},n.path))})}function DJ(){return o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2.5"}),o.jsx("circle",{cx:"8.5",cy:"9.5",r:"1.6"}),o.jsx("path",{d:"m4 17 4.5-4.5a2 2 0 0 1 2.8 0L16 17"}),o.jsx("path",{d:"m14 14 1.8-1.8a2 2 0 0 1 2.8 0L21 14.5"})]})}function BJ(){return o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8Z"}),o.jsx("path",{d:"M14 3v5h5"})]})}function Ib(t){const e=Math.round(t/1e3);return e>=1e3?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${e}k`:String(Math.max(0,Math.round(t)))}const OJ=42,IJ=2.5,$J=320,QE=1500;function PJ(){return window.matchMedia?.("(prefers-reduced-motion: reduce)").matches??!1}function zJ(t,e){const[n,i]=_.useState(()=>e?0:t.length),s=_.useRef(n),r=_.useRef(0),a=_.useRef(0),c=_.useRef(0),u=_.useRef(e);return s.current=n,e&&(u.current=!0),_.useEffect(()=>{if(PJ()||!u.current){s.current!==t.length&&i(t.length);return}if(s.current>t.length){i(t.length);return}const d=p=>{const m=t.length-s.current;if(m<=0){a.current=0,r.current=0;return}const v=a.current?Math.min(p-a.current,100):16;if(a.current=p,m>QE){s.current=t.length-QE,i(s.current),c.current=requestAnimationFrame(d);return}const x=Math.min($J,Math.max(OJ,m/IJ));r.current+=x*v/1e3;const y=Math.floor(r.current);y>=1&&(r.current-=y,s.current=Math.min(t.length,s.current+y),i(s.current)),c.current=requestAnimationFrame(d)};return c.current=requestAnimationFrame(d),()=>cancelAnimationFrame(c.current)},[t,e]),t.slice(0,n)}const U6=/^\s{0,3}(`{3,}|~{3,})(.*)$/;function FJ(t){if(!t)return[];const e=t.split(`
68
+ `:i=="r"?"\r":i=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new QZ(this):new GZ(this)}getCursor(e,n=0,i){let s=e.doc?e:vn.create({doc:e});return i==null&&(i=s.doc.length),this.regexp?Bd(this,s,n,i):Dd(this,s,n,i)}}class D6{constructor(e){this.spec=e}}function VZ(t,e,n){return(i,s,r,a)=>{if(n&&!n(i,s,r,a))return!1;let c=i>=a&&s<=a+r.length?r.slice(i-a,s-a):e.doc.sliceString(i,s);return t(c,e,i,s)}}function Dd(t,e,n,i){let s;return t.wholeWord&&(s=KZ(e.doc,e.charCategorizer(e.selection.main.head))),t.test&&(s=VZ(t.test,e,s)),new gf(e.doc,t.unquoted,n,i,t.caseSensitive?void 0:r=>r.toLowerCase(),s)}function KZ(t,e){return(n,i,s,r)=>((r>n||r+s.length<i)&&(r=Math.max(0,n-2),s=t.sliceString(r,Math.min(t.length,i+2))),(e(mx(s,n-r))!=Di.Word||e(gx(s,n-r))!=Di.Word)&&(e(gx(s,i-r))!=Di.Word||e(mx(s,i-r))!=Di.Word))}class GZ extends D6{constructor(e){super(e)}nextMatch(e,n,i){let s=Dd(this.spec,e,i,e.doc.length).nextOverlapping();if(s.done){let r=Math.min(e.doc.length,n+this.spec.unquoted.length);s=Dd(this.spec,e,0,r).nextOverlapping()}return s.done||s.value.from==n&&s.value.to==i?null:s.value}prevMatchInRange(e,n,i){for(let s=i;;){let r=Math.max(n,s-1e4-this.spec.unquoted.length),a=Dd(this.spec,e,r,s),c=null;for(;!a.nextOverlapping().done;)c=a.value;if(c)return c;if(r==n)return null;s-=1e4}}prevMatch(e,n,i){let s=this.prevMatchInRange(e,0,n);return s||(s=this.prevMatchInRange(e,Math.max(0,i-this.spec.unquoted.length),e.doc.length)),s&&(s.from!=n||s.to!=i)?s:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,n){let i=Dd(this.spec,e,0,e.doc.length),s=[];for(;!i.next().done;){if(s.length>=n)return null;s.push(i.value)}return s}highlight(e,n,i,s){let r=Dd(this.spec,e,Math.max(0,n-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,e.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}function YZ(t,e,n){return(i,s,r)=>(!n||n(i,s,r))&&t(r[0],e,i,s)}function Bd(t,e,n,i){let s;return t.wholeWord&&(s=XZ(e.charCategorizer(e.selection.main.head))),t.test&&(s=YZ(t.test,e,s)),new L6(e.doc,t.search,{ignoreCase:!t.caseSensitive,test:s},n,i)}function mx(t,e){return t.slice(bs(t,e,!1),e)}function gx(t,e){return t.slice(e,bs(t,e))}function XZ(t){return(e,n,i)=>!i[0].length||(t(mx(i.input,i.index))!=Di.Word||t(gx(i.input,i.index))!=Di.Word)&&(t(gx(i.input,i.index+i[0].length))!=Di.Word||t(mx(i.input,i.index+i[0].length))!=Di.Word)}class QZ extends D6{nextMatch(e,n,i){let s=Bd(this.spec,e,i,e.doc.length).next();return s.done&&(s=Bd(this.spec,e,0,n).next()),s.done?null:s.value}prevMatchInRange(e,n,i){for(let s=1;;s++){let r=Math.max(n,i-s*1e4),a=Bd(this.spec,e,r,i),c=null;for(;!a.next().done;)c=a.value;if(c&&(r==n||c.from>r+10))return c;if(r==n)return null}}prevMatch(e,n,i){return this.prevMatchInRange(e,0,n)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(n,i)=>{if(i=="&")return e.match[0];if(i=="$")return"$";for(let s=i.length;s>0;s--){let r=+i.slice(0,s);if(r>0&&r<e.match.length)return e.match[r]+i.slice(s)}return n})}matchAll(e,n){let i=Bd(this.spec,e,0,e.doc.length),s=[];for(;!i.next().done;){if(s.length>=n)return null;s.push(i.value)}return s}highlight(e,n,i,s){let r=Bd(this.spec,e,Math.max(0,n-250),Math.min(i+250,e.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}const $m=Gn.define(),CC=Gn.define(),Vc=tl.define({create(t){return new Bb(Kw(t).create(),null)},update(t,e){for(let n of e.effects)n.is($m)?t=new Bb(n.value.create(),t.panel):n.is(CC)&&(t=new Bb(t.query,n.value?jC:null));return t},provide:t=>ux.from(t,e=>e.panel)});class Bb{constructor(e,n){this.query=e,this.panel=n}}const ZZ=Kt.mark({class:"cm-searchMatch"}),JZ=Kt.mark({class:"cm-searchMatch cm-searchMatch-selected"}),eJ=hr.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(Vc))}update(t){let e=t.state.field(Vc);(e!=t.startState.field(Vc)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return Kt.none;let{view:n}=this,i=new vh;for(let s=0,r=n.visibleRanges,a=r.length;s<a;s++){let{from:c,to:u}=r[s];for(;s<a-1&&u>r[s+1].from-500;)u=r[++s].to;t.highlight(n.state,c,u,(d,p)=>{let m=n.state.selection.ranges.some(v=>v.from==d&&v.to==p);i.add(d,p,m?JZ:ZZ)})}return i.finish()}},{decorations:t=>t.decorations});function sg(t){return e=>{let n=e.state.field(Vc,!1);return n&&n.query.spec.valid?t(e,n):I6(e)}}const vx=sg((t,{query:e})=>{let{to:n}=t.state.selection.main,i=e.nextMatch(t.state,n,n);if(!i)return!1;let s=Ne.single(i.from,i.to),r=t.state.facet(Nh);return t.dispatch({selection:s,effects:[AC(t,i),r.scrollToMatch(s.main,t)],userEvent:"select.search"}),O6(t),!0}),xx=sg((t,{query:e})=>{let{state:n}=t,{from:i}=n.selection.main,s=e.prevMatch(n,i,i);if(!s)return!1;let r=Ne.single(s.from,s.to),a=t.state.facet(Nh);return t.dispatch({selection:r,effects:[AC(t,s),a.scrollToMatch(r.main,t)],userEvent:"select.search"}),O6(t),!0}),tJ=sg((t,{query:e})=>{let n=e.matchAll(t.state,1e3);return!n||!n.length?!1:(t.dispatch({selection:Ne.create(n.map(i=>Ne.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),nJ=({state:t,dispatch:e})=>{let n=t.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:i,to:s}=n.main,r=[],a=0;for(let c=new gf(t.doc,t.sliceDoc(i,s));!c.next().done;){if(r.length>1e3)return!1;c.value.from==i&&(a=r.length),r.push(Ne.range(c.value.from,c.value.to))}return e(t.update({selection:Ne.create(r,a),userEvent:"select.search.matches"})),!0},UE=sg((t,{query:e})=>{let{state:n}=t,{from:i,to:s}=n.selection.main;if(n.readOnly)return!1;let r=e.nextMatch(n,i,i);if(!r)return!1;let a=r,c=[],u,d,p=[];a.precise?a.from==i&&a.to==s&&(d=n.toText(e.getReplacement(a)),c.push({from:a.from,to:a.to,insert:d}),a=e.nextMatch(n,a.from,a.to),p.push(ct.announce.of(n.phrase("replaced match on line $",n.doc.lineAt(i).number)+"."))):a=e.nextMatch(n,a.from,a.to);let m=t.state.changes(c);return a&&(u=Ne.single(a.from,a.to).map(m),p.push(AC(t,a)),p.push(n.facet(Nh).scrollToMatch(u.main,t))),t.dispatch({changes:m,selection:u,effects:p,userEvent:"input.replace"}),!0}),iJ=sg((t,{query:e})=>{if(t.state.readOnly)return!1;let n=[];for(let s of e.matchAll(t.state,1e9)){let{from:r,to:a,precise:c}=s;c&&n.push({from:r,to:a,insert:e.getReplacement(s)})}if(!n.length)return!1;let i=t.state.phrase("replaced $ matches",n.length)+".";return t.dispatch({changes:n,effects:ct.announce.of(i),userEvent:"input.replace.all"}),!0});function jC(t){return t.state.facet(Nh).createPanel(t)}function Kw(t,e){var n,i,s,r,a;let c=t.selection.main,u=c.empty||c.to>c.from+100?"":t.sliceDoc(c.from,c.to);if(e&&!u)return e;let d=t.facet(Nh);return new R6({search:((n=e?.literal)!==null&&n!==void 0?n:d.literal)?u:u.replace(/\n/g,"\\n"),caseSensitive:(i=e?.caseSensitive)!==null&&i!==void 0?i:d.caseSensitive,literal:(s=e?.literal)!==null&&s!==void 0?s:d.literal,regexp:(r=e?.regexp)!==null&&r!==void 0?r:d.regexp,wholeWord:(a=e?.wholeWord)!==null&&a!==void 0?a:d.wholeWord})}function B6(t){let e=CD(t,jC);return e&&e.dom.querySelector("[main-field]")}function O6(t){let e=B6(t);e&&e==t.root.activeElement&&e.select()}const I6=t=>{let e=t.state.field(Vc,!1);if(e&&e.panel){let n=B6(t);if(n&&n!=t.root.activeElement){let i=Kw(t.state,e.query.spec);i.valid&&t.dispatch({effects:$m.of(i)}),n.focus(),n.select()}}else t.dispatch({effects:[CC.of(!0),e?$m.of(Kw(t.state,e.query.spec)):Gn.appendConfig.of(Gw)]});return!0},$6=t=>{let e=t.state.field(Vc,!1);if(!e||!e.panel)return!1;let n=CD(t,jC);return n&&n.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:CC.of(!1)}),!0},sJ=[{key:"Mod-f",run:I6,scope:"editor search-panel"},{key:"F3",run:vx,shift:xx,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:vx,shift:xx,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:$6,scope:"editor search-panel"},{key:"Mod-Shift-l",run:nJ},{key:"Mod-Alt-g",run:RZ},{key:"Mod-d",run:qZ,preventDefault:!0}];class rJ{constructor(e){this.view=e;let n=this.query=e.state.field(Vc).query.spec;this.commit=this.commit.bind(this),this.searchField=fs("input",{value:n.search,placeholder:Kr(e,"Find"),"aria-label":Kr(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=fs("input",{value:n.replace,placeholder:Kr(e,"Replace"),"aria-label":Kr(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=fs("input",{type:"checkbox",name:"case",form:"",checked:n.caseSensitive,onchange:this.commit}),this.reField=fs("input",{type:"checkbox",name:"re",form:"",checked:n.regexp,onchange:this.commit}),this.wordField=fs("input",{type:"checkbox",name:"word",form:"",checked:n.wholeWord,onchange:this.commit});function i(s,r,a){return fs("button",{class:"cm-button",name:s,onclick:r,type:"button"},a)}this.dom=fs("div",{onkeydown:s=>this.keydown(s),class:"cm-search"},[this.searchField,i("next",()=>vx(e),[Kr(e,"next")]),i("prev",()=>xx(e),[Kr(e,"previous")]),i("select",()=>tJ(e),[Kr(e,"all")]),fs("label",null,[this.caseField,Kr(e,"match case")]),fs("label",null,[this.reField,Kr(e,"regexp")]),fs("label",null,[this.wordField,Kr(e,"by word")]),...e.state.readOnly?[]:[fs("br"),this.replaceField,i("replace",()=>UE(e),[Kr(e,"replace")]),i("replaceAll",()=>iJ(e),[Kr(e,"replace all")])],fs("button",{name:"close",onclick:()=>$6(e),"aria-label":Kr(e,"close"),type:"button"},["×"])])}commit(){let e=new R6({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:$m.of(e)}))}keydown(e){NY(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?xx:vx)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),UE(this.view))}update(e){for(let n of e.transactions)for(let i of n.effects)i.is($m)&&!i.value.eq(this.query)&&this.setQuery(i.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Nh).top}}function Kr(t,e){return t.state.phrase(e)}const Hv=30,Wv=/[\s\.,:;?!]/;function AC(t,{from:e,to:n}){let i=t.state.doc.lineAt(e),s=t.state.doc.lineAt(n).to,r=Math.max(i.from,e-Hv),a=Math.min(s,n+Hv),c=t.state.sliceDoc(r,a);if(r!=i.from){for(let u=0;u<Hv;u++)if(!Wv.test(c[u+1])&&Wv.test(c[u])){c=c.slice(u);break}}if(a!=s){for(let u=c.length-1;u>c.length-Hv;u--)if(!Wv.test(c[u-1])&&Wv.test(c[u])){c=c.slice(0,u);break}}return ct.announce.of(`${t.state.phrase("current match")}. ${c} ${t.state.phrase("on line")} ${i.number}.`)}const aJ=ct.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),Gw=[Vc,Zm.low(eJ),aJ],oJ="modulepreload",lJ=function(t,e){return new URL(t,e).href},VE={},mt=function(e,n,i){let s=Promise.resolve();if(n&&n.length>0){let d=function(p){return Promise.all(p.map(m=>Promise.resolve(m).then(v=>({status:"fulfilled",value:v}),v=>({status:"rejected",reason:v}))))};const a=document.getElementsByTagName("link"),c=document.querySelector("meta[property=csp-nonce]"),u=c?.nonce||c?.getAttribute("nonce");s=d(n.map(p=>{if(p=lJ(p,i),p in VE)return;VE[p]=!0;const m=p.endsWith(".css"),v=m?'[rel="stylesheet"]':"";if(i)for(let y=a.length-1;y>=0;y--){const k=a[y];if(k.href===p&&(!m||k.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${p}"]${v}`))return;const x=document.createElement("link");if(x.rel=m?"stylesheet":oJ,m||(x.as="script"),x.crossOrigin="",x.href=p,u&&x.setAttribute("nonce",u),document.head.appendChild(x),m)return new Promise((y,k)=>{x.addEventListener("load",y),x.addEventListener("error",()=>k(new Error(`Unable to preload CSS for ${p}`)))})}))}function r(a){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=a,window.dispatchEvent(c),!c.defaultPrevented)throw a}return s.then(a=>{for(const c of a||[])c.status==="rejected"&&r(c.reason);return e().catch(r)})},_n=t=>xC.define(t),cJ={js:()=>mt(()=>import("./index-DFb3ZQNl.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript()),mjs:()=>mt(()=>import("./index-DFb3ZQNl.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript()),cjs:()=>mt(()=>import("./index-DFb3ZQNl.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript()),jsx:()=>mt(()=>import("./index-DFb3ZQNl.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({jsx:!0})),ts:()=>mt(()=>import("./index-DFb3ZQNl.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({typescript:!0})),mts:()=>mt(()=>import("./index-DFb3ZQNl.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({typescript:!0})),cts:()=>mt(()=>import("./index-DFb3ZQNl.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({typescript:!0})),tsx:()=>mt(()=>import("./index-DFb3ZQNl.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({jsx:!0,typescript:!0})),json:()=>mt(()=>import("./index-DDDo2fll.js"),__vite__mapDeps([3,1]),import.meta.url).then(t=>t.json()),jsonc:()=>mt(()=>import("./index-DDDo2fll.js"),__vite__mapDeps([3,1]),import.meta.url).then(t=>t.json()),md:()=>mt(()=>import("./index-CL4rlsj9.js"),__vite__mapDeps([4,2,5,1,6,0]),import.meta.url).then(t=>t.markdown()),markdown:()=>mt(()=>import("./index-CL4rlsj9.js"),__vite__mapDeps([4,2,5,1,6,0]),import.meta.url).then(t=>t.markdown()),mdx:()=>mt(()=>import("./index-CL4rlsj9.js"),__vite__mapDeps([4,2,5,1,6,0]),import.meta.url).then(t=>t.markdown()),html:()=>mt(()=>import("./index-CpTTNC9j.js"),__vite__mapDeps([5,1,6,0,2]),import.meta.url).then(t=>t.html()),htm:()=>mt(()=>import("./index-CpTTNC9j.js"),__vite__mapDeps([5,1,6,0,2]),import.meta.url).then(t=>t.html()),cshtml:()=>mt(()=>import("./index-CpTTNC9j.js"),__vite__mapDeps([5,1,6,0,2]),import.meta.url).then(t=>t.html()),vue:()=>mt(()=>import("./index-CpTTNC9j.js"),__vite__mapDeps([5,1,6,0,2]),import.meta.url).then(t=>t.html()),css:()=>mt(()=>import("./index-DytcrdWN.js"),__vite__mapDeps([6,1]),import.meta.url).then(t=>t.css()),scss:()=>mt(()=>import("./index-DytcrdWN.js"),__vite__mapDeps([6,1]),import.meta.url).then(t=>t.css()),less:()=>mt(()=>import("./index-DytcrdWN.js"),__vite__mapDeps([6,1]),import.meta.url).then(t=>t.css()),rs:()=>mt(()=>import("./index-M3sz0pDr.js"),__vite__mapDeps([7,1]),import.meta.url).then(t=>t.rust()),py:()=>mt(()=>import("./index-Bd1cE973.js"),__vite__mapDeps([8,1,2]),import.meta.url).then(t=>t.python()),pyi:()=>mt(()=>import("./index-Bd1cE973.js"),__vite__mapDeps([8,1,2]),import.meta.url).then(t=>t.python()),sql:()=>mt(()=>import("./index-Cqu5NxcW.js"),__vite__mapDeps([9,1,2]),import.meta.url).then(t=>t.sql()),yaml:()=>mt(()=>import("./index-BVlTDuBl.js"),__vite__mapDeps([10,1]),import.meta.url).then(t=>t.yaml()),yml:()=>mt(()=>import("./index-BVlTDuBl.js"),__vite__mapDeps([10,1]),import.meta.url).then(t=>t.yaml()),sh:()=>mt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>_n(t.shell)),bash:()=>mt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>_n(t.shell)),zsh:()=>mt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>_n(t.shell)),fish:()=>mt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>_n(t.shell)),cs:()=>mt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>_n(t.csharp)),c:()=>mt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>_n(t.c)),h:()=>mt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>_n(t.c)),cpp:()=>mt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>_n(t.cpp)),hpp:()=>mt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>_n(t.cpp)),java:()=>mt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>_n(t.java)),kt:()=>mt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>_n(t.kotlin)),swift:()=>mt(()=>import("./swift-BzpIVaGY.js"),[],import.meta.url).then(t=>_n(t.swift)),go:()=>mt(()=>import("./go-CTD25R5P.js"),[],import.meta.url).then(t=>_n(t.go)),rb:()=>mt(()=>import("./ruby-B2Rjki9n.js"),[],import.meta.url).then(t=>_n(t.ruby)),lua:()=>mt(()=>import("./lua-VAEuO923.js"),[],import.meta.url).then(t=>_n(t.lua)),toml:()=>mt(()=>import("./toml-Bm5Em-hy.js"),[],import.meta.url).then(t=>_n(t.toml)),xml:()=>mt(()=>import("./xml-BQQZnNBQ.js"),[],import.meta.url).then(t=>_n(t.xml)),svg:()=>mt(()=>import("./xml-BQQZnNBQ.js"),[],import.meta.url).then(t=>_n(t.xml)),xaml:()=>mt(()=>import("./xml-BQQZnNBQ.js"),[],import.meta.url).then(t=>_n(t.xml)),csproj:()=>mt(()=>import("./xml-BQQZnNBQ.js"),[],import.meta.url).then(t=>_n(t.xml)),diff:()=>mt(()=>import("./diff-DbItnlRl.js"),[],import.meta.url).then(t=>_n(t.diff)),patch:()=>mt(()=>import("./diff-DbItnlRl.js"),[],import.meta.url).then(t=>_n(t.diff)),ps1:()=>mt(()=>import("./powershell-CFHJl5sT.js"),[],import.meta.url).then(t=>_n(t.powerShell)),properties:()=>mt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>_n(t.properties)),ini:()=>mt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>_n(t.properties)),env:()=>mt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>_n(t.properties))},KE={dockerfile:()=>mt(()=>import("./dockerfile-ZL4hHokT.js"),[],import.meta.url).then(t=>_n(t.dockerFile)),makefile:()=>mt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>_n(t.shell)),".env":()=>mt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>_n(t.properties)),".gitignore":()=>mt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>_n(t.properties)),".dockerignore":()=>mt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>_n(t.properties)),".editorconfig":()=>mt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>_n(t.properties))};async function uJ(t){const e=(t.split("/").pop()??t).toLowerCase(),n=KE[e]??KE[e.slice(0,e.indexOf(".",1))];if(n)return n();const i=e.lastIndexOf(".");if(i<=0)return null;const s=cJ[e.slice(i+1)];return s?s():null}const hJ=ey.define([{tag:[He.comment,He.lineComment,He.blockComment,He.docComment],color:"var(--syntax-comment)",fontStyle:"italic"},{tag:[He.keyword,He.modifier,He.controlKeyword,He.moduleKeyword],color:"var(--syntax-keyword)"},{tag:[He.string,He.special(He.string),He.regexp],color:"var(--syntax-string)"},{tag:[He.number,He.bool,He.null,He.atom],color:"var(--syntax-number)"},{tag:[He.function(He.variableName),He.function(He.propertyName),He.labelName],color:"var(--syntax-function)"},{tag:[He.typeName,He.className,He.namespace,He.self],color:"var(--syntax-type)"},{tag:[He.propertyName,He.attributeName],color:"var(--syntax-property)"},{tag:[He.variableName,He.definition(He.variableName)],color:"var(--fg-1)"},{tag:[He.operator,He.punctuation,He.separator,He.bracket],color:"var(--fg-2)"},{tag:[He.tagName],color:"var(--syntax-property)"},{tag:[He.heading],color:"var(--syntax-function)",fontWeight:"600"},{tag:[He.link,He.url],color:"var(--link)",textDecoration:"underline"},{tag:[He.emphasis],fontStyle:"italic"},{tag:[He.strong],fontWeight:"600"},{tag:[He.invalid],color:"var(--syntax-property)"}]),dJ=ct.theme({"&":{height:"100%",fontSize:"var(--ws-code-size)",backgroundColor:"var(--bg-0)",color:"var(--fg-1)"},".cm-scroller":{fontFamily:"var(--mono)",lineHeight:"1.7",overflow:"auto",paddingBottom:"calc(28px + env(safe-area-inset-bottom))"},".cm-content":{caretColor:"var(--accent)",padding:"10px 0 0"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"var(--accent)",borderLeftWidth:"2px"},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:"color-mix(in srgb, var(--focus) 25%, transparent)"},".cm-gutters":{backgroundColor:"var(--bg-0)",color:"var(--fg-3)",border:"0",paddingRight:"4px"},".cm-activeLine":{backgroundColor:"color-mix(in srgb, var(--fg-0) 4%, transparent)"},".cm-activeLineGutter":{backgroundColor:"transparent",color:"var(--fg-2)"},".cm-selectionMatch":{backgroundColor:"color-mix(in srgb, var(--warn) 20%, transparent)"},".cm-matchingBracket, &.cm-focused .cm-matchingBracket":{backgroundColor:"color-mix(in srgb, var(--focus) 24%, transparent)",outline:"0"},".cm-panels":{backgroundColor:"var(--bg-sunken)",color:"var(--fg-1)"},".cm-panels input, .cm-panels button":{backgroundColor:"var(--bg-1)",color:"var(--fg-1)",border:"1px solid var(--border)",borderRadius:"var(--r-sm)",padding:"3px 6px",font:"inherit"}},{dark:!0});function fJ({path:t,initialDoc:e,readOnly:n=!1,onChange:i,onSave:s,onSelect:r}){const a=_.useRef(null),c=_.useRef(null),u=_.useRef(i),d=_.useRef(s),p=_.useRef(r);return u.current=i,d.current=s,p.current=r,_.useEffect(()=>{const m=a.current;if(!m)return;const v=new Jm,x=vn.create({doc:e,extensions:[fX(),gX(),XY(),qY(),NQ(),DY(),nX(),QX(),lQ(),OZ(),UZ({top:!0}),ct.lineWrapping,Zx.of(" "),JX(hJ),dJ,v.of([]),vn.readOnly.of(n),ct.editable.of(!n),ct.contentAttributes.of({autocapitalize:"off",autocorrect:"off",spellcheck:"false"}),yD.of([{key:"Mod-s",preventDefault:!0,run:()=>(d.current(),!0)},{key:"Escape",run:A=>(A.contentDOM.blur(),!0)},...sJ,...IQ,...MZ,LZ]),ct.updateListener.of(A=>{if(A.docChanged&&u.current(A.state.doc.toString()),A.selectionSet||A.docChanged){const{from:N,to:E}=A.state.selection.main;p.current?.({from:N,to:E,text:N===E?"":A.state.doc.sliceString(N,E)})}})]}),y=new ct({state:x,parent:m});c.current=y;const k=t3(Z0("code",t));k&&y.dispatch({effects:k});const S=()=>e3(Z0("code",t),y.scrollSnapshot());y.scrollDOM.addEventListener("scroll",S,{passive:!0});let C=!0;return uJ(t).then(A=>{!C||!A||y.dispatch({effects:v.reconfigure(A)})}).catch(()=>{}),()=>{C=!1,y.scrollDOM.removeEventListener("scroll",S),y.destroy(),c.current=null}},[t,n]),_.useEffect(()=>{const m=a.current;if(!m||typeof IntersectionObserver>"u")return;const v=new IntersectionObserver(x=>{x.some(y=>y.isIntersecting)&&c.current?.requestMeasure()});return v.observe(m),()=>v.disconnect()},[]),o.jsx("div",{className:"ws-cm",ref:a})}function P6({children:t}){return o.jsx("div",{className:"prose-table",children:o.jsx("table",{children:t})})}const pJ={a:KS,table:P6};function mJ(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} kB`:`${(t/(1024*1024)).toFixed(1)} MB`}function gJ({path:t,preview:e,draft:n,onDraft:i,onSave:s,raw:r,generation:a,onProseRef:c,onSelect:u}){if(!e)return o.jsx("div",{className:"dots","aria-label":"loading"});const d=YS(t,e),p=r&&(d==="prose"||d==="page")?"code":d;return p==="image"?o.jsx(xJ,{path:t}):p==="video"?o.jsx(yJ,{path:t,size:e.size},`${t}:${a??0}`):p==="none"?o.jsx(F6,{path:t,preview:e}):p==="page"?o.jsx(vJ,{path:t,html:n}):p==="prose"?o.jsx("div",{className:"prose panel-prose",ref:c,children:o.jsx(PS,{remarkPlugins:[WS],components:pJ,children:n})}):o.jsx(fJ,{path:t,initialDoc:e.content,readOnly:e.truncated,onChange:i,onSave:()=>s?.(),onSelect:u},`${t}:${a??0}`)}function z6({path:t}){const[e,n]=_.useState(!1),[i,s]=_.useState(null),[r,a]=_.useState(!1);async function c(){n(!0),s(null),a(!1);try{await ae.invoke("open_file_native",{path:t}),a(!0)}catch(u){s(u instanceof Error?u.message:String(u))}finally{n(!1)}}return o.jsxs("div",{className:"native-open",children:[o.jsx("button",{className:"native-open-btn",type:"button",disabled:e,onClick:()=>{c()},children:e?"Opening…":"Open in default app"}),o.jsx("p",{className:"native-open-note",children:"On the computer running OctiqFlow"}),r&&o.jsx("p",{className:"native-open-status",role:"status",children:"Opened."}),i&&o.jsx("p",{className:"native-open-error",role:"alert",children:i})]})}function F6({path:t,preview:e,reason:n="Preview unavailable"}){const i=e.kind==="pdf"?"PDF document":"File";return o.jsxs("div",{className:"panel-unsupported",children:[o.jsxs("div",{className:"panel-unsupported-copy",children:[o.jsx("strong",{children:n}),o.jsxs("span",{children:[i," · ",o.jsx(Lt,{children:mJ(e.size)})]})]}),o.jsx(z6,{path:t},t)]})}function vJ({path:t,html:e}){return o.jsx("iframe",{className:"panel-page",title:`${Ri(t)} — preview`,srcDoc:e,sandbox:"allow-scripts allow-popups",referrerPolicy:"no-referrer"})}function xJ({path:t}){const[e,n]=_.useState(null),[i,s]=_.useState(null),r=_.useRef(null);return _.useEffect(()=>{let a=!0;return ae.fetchFile(t).then(c=>{a&&(r.current=URL.createObjectURL(c),n(r.current))}).catch(c=>a&&s(c.message)),()=>{a=!1,r.current&&URL.revokeObjectURL(r.current)}},[t]),i?o.jsx("div",{className:"panel-error",children:i}):e?o.jsx("div",{className:"ws-image",children:o.jsx("img",{src:e,alt:Ri(t)})}):o.jsx("div",{className:"dots","aria-label":"loading"})}function yJ({path:t,size:e}){const[n,i]=_.useState(!1);return n?o.jsx(F6,{path:t,preview:{kind:"video",content:"",truncated:!1,size:e},reason:"This video can’t play in this browser"}):o.jsx("div",{className:"ws-video",children:o.jsx("video",{src:ae.fileUrl(t),controls:!0,playsInline:!0,preload:"metadata","aria-label":Ri(t),onError:()=>i(!0)})})}function _J(t,e){const[n,i]=_.useState("closed"),[s,r]=_.useState(null),a=_.useRef(null),c=_.useRef(!1),u=_.useRef(null);_.useLayoutEffect(()=>i("closed"),[e]),_.useLayoutEffect(()=>{const x=document.getElementById("dock"),y=x?.querySelector(".main:not([hidden])"),k=x?.closest(".app"),S=window.matchMedia("(max-width: 700px)");if(!x||!y||!t){r(null);return}const C=y.inert,A=window.visualViewport,N=()=>{S.matches&&A&&k?.style.setProperty("--reader-viewport-height",`${A.height}px`)},E=()=>{r(S.matches?y:null),S.matches?(x.dataset.readerChat=n,k?.classList.add("is-file-reading"),y.inert=n==="closed",N()):(delete x.dataset.readerChat,k?.classList.remove("is-file-reading"),y.inert=C)};return E(),S.addEventListener("change",E),A?.addEventListener("resize",N),()=>{S.removeEventListener("change",E),A?.removeEventListener("resize",N),y.inert=C,delete x.dataset.readerChat,k?.classList.remove("is-file-reading"),k?.style.removeProperty("--reader-viewport-height")}},[t,n]);function d(){s&&Ea.flushSync(()=>i("half"))}function p(){document.activeElement instanceof HTMLElement&&s?.contains(document.activeElement)&&document.activeElement.blur(),Ea.flushSync(()=>i("closed")),u.current?.focus({preventScroll:!0})}const m=s&&n!=="closed"?Ea.createPortal(o.jsxs("header",{className:"reader-chat-head",children:[o.jsxs("button",{className:"reader-chat-resize",type:"button","aria-label":n==="large"?"Make chat smaller":"Expand chat","aria-expanded":n==="large",onClick:()=>{if(c.current){c.current=!1;return}i(n==="large"?"half":"large")},onPointerDown:x=>{c.current=!1,a.current=x.clientY,x.currentTarget.setPointerCapture(x.pointerId)},onPointerUp:x=>{const y=x.clientY-(a.current??x.clientY);a.current=null,!(Math.abs(y)<30)&&(c.current=!0,x.preventDefault(),y>0?p():i("large"))},onPointerCancel:()=>{a.current=null},children:[o.jsx("span",{className:"reader-chat-grip"}),"Chat"]}),o.jsxs("button",{type:"button",onClick:p,children:["Continue reading ",o.jsx("span",{"aria-hidden":"true",children:"⌄"})]})]}),s):null;return{show:d,collapse:p,size:n,controls:m,launcher:s&&n==="closed"?o.jsxs("button",{ref:u,className:"reader-chat-launch",type:"button",onClick:d,children:[o.jsx("span",{children:"Ask agent / discuss this file"}),o.jsx("span",{"aria-hidden":"true",children:"⌃"})]}):null}}function Ob(t,e){const n=t.getBoundingClientRect().top,i=Array.from(e.children),s=Math.max(0,i.findIndex(a=>a.getBoundingClientRect().bottom>n)),r=[s,s+1,s-1];return{scrollTop:t.scrollTop,blocks:r.flatMap(a=>{const c=i[a];return c?[{text:c.textContent??"",index:a,offset:c.getBoundingClientRect().top-n}]:[]})}}function bJ(t,e,n){const i=Array.from(e.children);for(const s of n.blocks){if(!s.text)continue;const r=i.map((a,c)=>({el:a,index:c})).filter(({el:a})=>a.textContent===s.text).sort((a,c)=>Math.abs(a.index-s.index)-Math.abs(c.index-s.index))[0];if(r){t.scrollTop+=r.el.getBoundingClientRect().top-t.getBoundingClientRect().top-s.offset;return}}t.scrollTop=n.scrollTop}const wJ="octiq.v2.fileWidth",kJ={initial:480,min:320,max:760},SJ="dock";function GE(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} kB`:`${(t/(1024*1024)).toFixed(1)} MB`}function CJ({path:t,open:e,onClose:n}){const[i,s]=_.useState(null),[r,a]=_.useState(null),[c,u]=_.useState(""),[d,p]=_.useState(!1),[m,v]=_.useState(!1),[x,y]=_.useState(!1),[k,S]=_.useState(!1),[C,A]=_.useState(null),[N,E]=_.useState(0),M=_J(e,t),L=_.useRef(null),$=_.useRef(null),V=_.useRef(0),X=XS(),{width:D,startDrag:Q,entered:P}=of(wJ,kJ),z=_.useRef(null),H=_.useRef(null),W=_.useRef(null),F=_.useRef(null),Y=!!i&&c!==i.content,J=_.useRef(c),te=_.useRef(i?.content??"");J.current=c,te.current=i?.content??"";const I=!!i&&i.kind==="text"&&!i.truncated&&Y,U=!!i&&!d&&YS(t,i)==="prose",Z=_.useCallback(async le=>{const Re=++V.current,De=J.current;try{const Ke=await ae.invoke("read_file_preview",{path:t});if(Re!==V.current)return;if(le&&J.current!==De){S(!0);return}le&&W.current&&H.current&&(L.current=Ob(W.current,H.current)),s(Ke),u(Ke.content??""),E(xe=>xe+1),A(null),S(!1),a(null),le||p(!1)}catch(Ke){if(Re!==V.current)return;a(String(Ke.message??Ke))}},[t]);_.useEffect(()=>(s(null),a(null),p(!1),A(null),L.current=null,$.current=null,Z(!1),()=>{V.current++}),[t,Z]),_.useLayoutEffect(()=>{const le=W.current;if(!le||!U)return;const Re=t3(Z0("prose",t));Re&&(le.scrollTop=Re)},[t,U]),_.useLayoutEffect(()=>{U&&W.current&&H.current&&L.current&&bJ(W.current,H.current,L.current)},[N,U,M.size]),_.useEffect(()=>{if(M.size!=="closed"||!$.current||!H.current)return;const le=Array.from(H.current.children).find(De=>De.textContent?.includes($.current));if(!le)return;le.classList.add("reader-return-highlight");const Re=setTimeout(()=>le.classList.remove("reader-return-highlight"),1800);return()=>{clearTimeout(Re),le.classList.remove("reader-return-highlight")}},[M.size]),_.useEffect(()=>{ae.invoke("file_watch_paths",{paths:[t]}).catch(()=>{});const le=ae.on("file-changed",Re=>{if(!(!Array.isArray(Re)||!Re.includes(t))){if(J.current!==te.current){S(!0);return}Z(!0)}});return()=>{le(),ae.invoke("file_watch_paths",{paths:[]}).catch(()=>{})}},[t,Z]);const R=_.useCallback(()=>{const le=window.getSelection();if(!le||le.isCollapsed||le.rangeCount===0)return A(null);const Re=le.getRangeAt(0),De=H.current;if(!De||!De.contains(Re.commonAncestorContainer))return A(null);const Ke=le.toString();if(!Ke.trim())return A(null);const xe=J.current.indexOf(Ke),vt=xe>=0&&J.current.lastIndexOf(Ke)===xe?vN(J.current,xe,xe+Ke.length):{from:0,to:0},Bt=Re.getBoundingClientRect();A({quote:{path:t,text:Ke,...vt},x:Bt.left+Bt.width/2,y:Bt.top})},[t]);_.useEffect(()=>{const le=()=>{requestAnimationFrame(R)};return document.addEventListener("selectionchange",le),()=>document.removeEventListener("selectionchange",le)},[R]);const K=_.useCallback(le=>{if(!le.text.trim())return A(null);const Re=J.current,De=F.current??jJ(z.current);A({quote:{path:t,text:le.text,...vN(Re,le.from,le.to)},...De})},[t]),O=_.useCallback(()=>{C&&($.current=C.quote.text,W.current&&H.current&&(L.current=Ob(W.current,H.current)),M.show(),gK(C.quote),A(null))},[C,M]);_.useEffect(()=>{const le=()=>{const De=document.activeElement;return!De||De===document.body||!!z.current?.contains(De)},Re=De=>{if(le()){if(De.key==="Escape"){if(C)return A(null);if(M.size!=="closed")return M.collapse();Y||n()}De.key==="s"&&(De.metaKey||De.ctrlKey)&&(De.preventDefault(),ie())}};return window.addEventListener("keydown",Re),()=>window.removeEventListener("keydown",Re)});async function ie(){if(!(!I||m)){v(!0),a(null);try{await ae.invoke("write_file",{path:t,content:c}),s(le=>le&&{...le,content:c}),y(!0),setTimeout(()=>y(!1),1600)}catch(le){a(String(le.message??le))}finally{v(!1)}}}async function re(){Y&&!await X({title:"Close without saving?",body:`Your changes to ${Ri(t)} will be lost.`,confirmLabel:"Discard changes",danger:!0})||n()}const ve=typeof document>"u"?null:document.getElementById(SJ);return ve?o.jsxs(o.Fragment,{children:[Ea.createPortal(o.jsxs(o.Fragment,{children:[o.jsx("div",{className:`fpanel-scrim ${P&&e?"is-open":""}`,onClick:()=>{re()},"aria-hidden":"true"}),o.jsxs("aside",{ref:z,className:`fpanel ${P&&e?"is-open":""}`,"aria-label":Ri(t),style:{"--gitp-w":`${D}px`},onPointerUp:le=>{F.current={x:le.clientX,y:le.clientY},R()},children:[o.jsx("div",{className:"gitp-resizer",role:"separator","aria-orientation":"vertical","aria-label":"Resize the file panel",onPointerDown:Q}),o.jsxs("header",{className:"panel-head",children:[o.jsxs("div",{className:"panel-id",children:[o.jsxs("div",{className:"panel-name",children:[Ri(t),Y&&o.jsx("span",{className:"panel-dirty",title:"Unsaved changes"})]}),o.jsx("div",{className:"panel-path",children:o.jsx("bdi",{children:t})})]}),o.jsxs("span",{className:"panel-acts",children:[o.jsx(Y0,{className:"panel-act",icon:o.jsx(Vx,{}),idle:"Copy the path",done:"Path copied",read:()=>({text:t})}),i?.kind==="text"&&o.jsx(Y0,{className:"panel-act",icon:o.jsx(G4,{}),idle:"Copy the whole file",done:"File copied",empty:"Nothing to copy — this file is empty",partial:"Copied what is on screen — the rest of the file was never read",read:()=>({text:c,partial:i.truncated})})]}),cK(t,i)&&o.jsx("button",{className:"panel-btn",type:"button",onClick:()=>p(le=>!le),children:d?"Preview":"Edit"}),i?.kind==="text"&&!i.truncated&&o.jsx("button",{className:"panel-btn is-primary",type:"button",onClick:ie,disabled:!I||m,children:m?"Saving…":x?"Saved":"Save"}),o.jsx("button",{className:"panel-close",type:"button",onClick:()=>{re()},"aria-label":"Close",children:"✕"})]}),r&&o.jsxs("div",{className:"panel-error",children:[r,o.jsx(z6,{path:t},t)]}),k&&o.jsxs("div",{className:"panel-warn is-stale",children:["This file changed on disk while you were editing it.",o.jsx("button",{className:"panel-inline-btn",type:"button",onClick:()=>{Z(!0)},children:"Reload and lose my changes"})]}),i?.truncated&&o.jsxs("div",{className:"panel-warn",children:["Showing the first ",o.jsx(Lt,{children:GE(i.content.length)})," of"," ",o.jsx(Lt,{children:GE(i.size)}),". Saving is off for this file — writing back what is on screen would cut the rest away."]}),o.jsxs("div",{className:"panel-body",ref:W,onScroll:le=>{U&&(e3(Z0("prose",t),le.currentTarget.scrollTop),H.current&&(L.current=Ob(le.currentTarget,H.current)))},children:[!i&&!r&&o.jsx("div",{className:"dots","aria-label":"loading"}),i&&o.jsx(gJ,{path:t,preview:i,draft:c,raw:d,generation:N,onDraft:u,onSave:()=>{ie()},onSelect:K,onProseRef:le=>{H.current=le}})]}),M.launcher]})]}),ve),M.controls,C&&vK()&&Ea.createPortal(o.jsxs("button",{className:"quote-btn reader-quote",type:"button",style:{left:`${C.x}px`,top:`${C.y}px`},onMouseDown:le=>le.preventDefault(),onPointerDown:le=>le.preventDefault(),onClick:O,children:[o.jsx("span",{className:"quote-btn-plus","aria-hidden":"true",children:"+"}),"Add to chat",C.quote.from>0&&o.jsx("span",{className:"quote-btn-at",children:C.quote.to>C.quote.from?`${C.quote.from}–${C.quote.to}`:C.quote.from})]}),document.body)]}):null}function jJ(t){if(!t)return{x:24,y:80};const e=t.getBoundingClientRect();return{x:e.left+e.width/2,y:e.top+40}}const $l=1,H6=8,YE=[1,1.5,2,3,4,6,8],AJ=400;function NC(t){return Number.isFinite(t)?Math.min(H6,Math.max($l,t)):$l}function qv(t,e){const n=NC(t);return(e>0?YE.find(s=>s>n+1e-6):[...YE].reverse().find(s=>s<n-1e-6))??n}function NJ(t,e){return NC(t*Math.exp(-e/AJ))}function EJ(t,e,n,i){const s=i/n;return{x:e.x-(e.x-t.x)*s,y:e.y-(e.y-t.y)*s}}function MJ(t,e,n,i){const s=(c,u)=>Math.max(0,(u*i-c)/2),r=s(e.w,n.w),a=s(e.h,n.h);return{x:Math.min(r,Math.max(-r,t.x)),y:Math.min(a,Math.max(-a,t.y))}}const k0={x:0,y:0},XE=4,Uv={scale:$l,pan:k0};function W6({path:t,onClose:e}){const[n,i]=_.useState(null),[s,r]=_.useState(null),[a,c]=_.useState(Uv),u=_.useRef(null),d=_.useRef(null),p=Z4(t);_.useEffect(()=>{let $=!0,V=null;return c(Uv),ae.fetchFile(t).then(X=>{$&&(V=URL.createObjectURL(X),i(V))}).catch(X=>$&&r(X.message)),()=>{$=!1,V&&URL.revokeObjectURL(V)}},[t]);const m=_.useCallback(($,V,X)=>{const D=NC(V),Q=u.current,P=d.current,z={w:Q?.clientWidth??0,h:Q?.clientHeight??0},H={w:P?.offsetWidth??0,h:P?.offsetHeight??0};return{scale:D,pan:MJ(EJ($.pan,X,$.scale,D),z,H,D)}},[]),v=_.useCallback(($,V=k0)=>c(X=>m(X,$(X.scale),V)),[m]),x=_.useCallback(($,V)=>{const X=u.current?.getBoundingClientRect();return X?{x:$-(X.left+X.width/2),y:V-(X.top+X.height/2)}:k0},[]);_.useEffect(()=>{const $=u.current;if(!$||p)return;const V=X=>{X.preventDefault();const D=X.ctrlKey?X.deltaY*3:X.deltaY;v(Q=>NJ(Q,D),x(X.clientX,X.clientY))};return $.addEventListener("wheel",V,{passive:!1}),()=>$.removeEventListener("wheel",V)},[x,p,n,v]),_.useEffect(()=>{const $=V=>{if(V.key==="Escape")return e();if(p||V.metaKey||V.ctrlKey||V.altKey)return;const X=V.target;X&&(X.tagName==="INPUT"||X.tagName==="TEXTAREA"||X.isContentEditable)||(V.key==="+"||V.key==="="?v(D=>qv(D,1)):V.key==="-"||V.key==="_"?v(D=>qv(D,-1)):V.key==="0"&&c(Uv))};return window.addEventListener("keydown",$),()=>window.removeEventListener("keydown",$)},[e,p,v]);const y=_.useRef(new Map),k=_.useRef(null),S=_.useRef(null),C=_.useRef(!1),A=()=>{const[$,V]=[...y.current.values()];return Math.hypot($.x-V.x,$.y-V.y)},N=()=>{const[$,V]=[...y.current.values()];return x(($.x+V.x)/2,($.y+V.y)/2)};function E($){if(!p){if(y.current.size===0&&(C.current=!1),y.current.set($.pointerId,{x:$.clientX,y:$.clientY}),y.current.size===2){k.current=null,S.current=A(),C.current=!0;return}y.current.size>2||a.scale<=$l||($.target.setPointerCapture?.($.pointerId),k.current={id:$.pointerId,from:{x:$.clientX,y:$.clientY},pan:a.pan})}}function M($){if(!y.current.has($.pointerId))return;if(y.current.set($.pointerId,{x:$.clientX,y:$.clientY}),S.current!==null&&y.current.size===2){const Q=A(),P=S.current>0?Q/S.current:1;S.current=Q,v(z=>z*P,N());return}const V=k.current;if(!V||V.id!==$.pointerId)return;const X=$.clientX-V.from.x,D=$.clientY-V.from.y;(Math.abs(X)>XE||Math.abs(D)>XE)&&(C.current=!0),c(Q=>m({...Q,pan:{x:V.pan.x+X,y:V.pan.y+D}},Q.scale,k0))}function L($){y.current.delete($.pointerId),y.current.size<2&&(S.current=null),k.current?.id===$.pointerId&&(k.current=null)}return Ea.createPortal(o.jsxs("div",{className:"viewer",onClick:()=>C.current?C.current=!1:e(),children:[o.jsxs("div",{className:"viewer-bar",onClick:$=>$.stopPropagation(),children:[o.jsx("span",{className:"viewer-name",children:Ri(t)}),!p&&n&&o.jsxs("div",{className:"viewer-zoom",children:[o.jsx("button",{className:"viewer-btn",type:"button",onClick:()=>v($=>qv($,-1)),disabled:a.scale<=$l,"aria-label":"Zoom out",title:"Zoom out (−)",children:"−"}),o.jsx("button",{className:"viewer-level",type:"button",onClick:()=>c(Uv),disabled:a.scale<=$l,title:"Fit to screen (0)",children:o.jsx(Lt,{children:`${Math.round(a.scale*10)/10}×`})}),o.jsx("button",{className:"viewer-btn",type:"button",onClick:()=>v($=>qv($,1)),disabled:a.scale>=H6,"aria-label":"Zoom in",title:"Zoom in (+)",children:"+"})]}),o.jsx("button",{className:"viewer-close",type:"button",onClick:e,"aria-label":"Close",children:"✕"})]}),s?o.jsx("div",{className:"viewer-error",children:s}):n?p?o.jsx("iframe",{className:"viewer-pdf",src:n,title:Ri(t)}):o.jsx("div",{className:`viewer-stage ${a.scale>$l?"is-zoomed":""}`,ref:u,onPointerDown:E,onPointerMove:M,onPointerUp:L,onPointerCancel:L,onDoubleClick:$=>v(V=>V>$l?$l:2,x($.clientX,$.clientY)),children:o.jsx("img",{className:"viewer-img",ref:d,src:n,alt:Ri(t),draggable:!1,style:{transform:`translate(${a.pan.x}px, ${a.pan.y}px) scale(${a.scale})`},onClick:$=>$.stopPropagation()})}):o.jsx("div",{className:"dots","aria-label":"loading"})]}),document.body)}const LJ=220;function TJ({children:t}){const[e,n]=_.useState(null),[i,s]=_.useState(null),[r,a]=_.useState(null),c=_.useCallback(()=>{n(null),s(null)},[]),u=_.useCallback(d=>{if(tK(d)){s(null),n(null),ae.openFileInBrowser(d);return}GS(d)||Z4(d)?(s(null),n(d)):(n(null),s(d),a(d))},[]);return _.useEffect(()=>{if(i)return;const d=setTimeout(()=>a(null),LJ);return()=>clearTimeout(d)},[i]),o.jsx(V4.Provider,{value:u,children:o.jsxs(K4.Provider,{value:c,children:[t,e&&o.jsx(W6,{path:e,onClose:()=>n(null)}),r&&o.jsx(CJ,{path:r,open:!!i,onClose:()=>s(null)})]})})}function q6({attachment:t}){const[e,n]=_.useState(t.url??null);return _.useEffect(()=>{if(t.url){n(t.url);return}let i=!0,s=null;return ae.fetchFile(t.path).then(r=>{i&&(s=URL.createObjectURL(r),n(s))}).catch(()=>i&&n(null)),()=>{i=!1,s&&URL.revokeObjectURL(s)}},[t.path,t.url]),e?o.jsx("img",{className:"chip-thumb",src:e,alt:""}):o.jsx(DJ,{})}function RJ({files:t}){const e=Ux();return t.length===0?null:o.jsx("div",{className:"sent-files",children:t.map(n=>o.jsxs("button",{className:`chip ${n.isImage?"is-image":""}`,type:"button",title:`${n.path} — click to open`,onClick:()=>e(n.path),children:[n.isImage?o.jsx(q6,{attachment:n}):o.jsx(BJ,{}),o.jsx("span",{className:"chip-name",children:n.name})]},n.path))})}function DJ(){return o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2.5"}),o.jsx("circle",{cx:"8.5",cy:"9.5",r:"1.6"}),o.jsx("path",{d:"m4 17 4.5-4.5a2 2 0 0 1 2.8 0L16 17"}),o.jsx("path",{d:"m14 14 1.8-1.8a2 2 0 0 1 2.8 0L21 14.5"})]})}function BJ(){return o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8Z"}),o.jsx("path",{d:"M14 3v5h5"})]})}function Ib(t){const e=Math.round(t/1e3);return e>=1e3?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${e}k`:String(Math.max(0,Math.round(t)))}const OJ=42,IJ=2.5,$J=320,QE=1500;function PJ(){return window.matchMedia?.("(prefers-reduced-motion: reduce)").matches??!1}function zJ(t,e){const[n,i]=_.useState(()=>e?0:t.length),s=_.useRef(n),r=_.useRef(0),a=_.useRef(0),c=_.useRef(0),u=_.useRef(e);return s.current=n,e&&(u.current=!0),_.useEffect(()=>{if(PJ()||!u.current){s.current!==t.length&&i(t.length);return}if(s.current>t.length){i(t.length);return}const d=p=>{const m=t.length-s.current;if(m<=0){a.current=0,r.current=0;return}const v=a.current?Math.min(p-a.current,100):16;if(a.current=p,m>QE){s.current=t.length-QE,i(s.current),c.current=requestAnimationFrame(d);return}const x=Math.min($J,Math.max(OJ,m/IJ));r.current+=x*v/1e3;const y=Math.floor(r.current);y>=1&&(r.current-=y,s.current=Math.min(t.length,s.current+y),i(s.current)),c.current=requestAnimationFrame(d)};return c.current=requestAnimationFrame(d),()=>cancelAnimationFrame(c.current)},[t,e]),t.slice(0,n)}const U6=/^\s{0,3}(`{3,}|~{3,})(.*)$/;function FJ(t){if(!t)return[];const e=t.split(`
69
69
  `),n=[];let i=[],s=null;const r=()=>{i.length&&(n.push(i.join(`
70
70
  `)),i=[])};for(const a of e){const c=U6.exec(a);if(s){i.push(a),c&&c[1][0]===s.marker&&c[1].length>=s.length&&!c[2].trim()&&(s=null,r());continue}if(c){r(),s={marker:c[1][0],length:c[1].length},i.push(a);continue}if(!a.trim()){r();continue}i.push(a)}return r(),n}function HJ(t){const e=t.split(`
71
71
  `);let n=null;for(const i of e){const s=U6.exec(i);s&&(n?s[1][0]===n.marker&&s[1].length>=n.length&&!s[2].trim()&&(n=null):n={marker:s[1][0],length:s[1].length})}return n?`${t}
@@ -77,7 +77,7 @@ ${n.marker.repeat(n.length)}`:t}function WJ(t){const e=t.match(/\S+\s*|\s+/g);re
77
77
  `).find(n=>n.trim())??"").replace(/^\s*(?:#+|[-*+]|\d+[.)])\s+/,"").replace(/[*_`]/g,"").trim()}function Gee(t){return t.length>8?t.slice(0,8):t}function Yee({block:t}){const[e,n]=_.useState(t.text.length<=Vee),i=t.source==="handback"?`subagent ${Gee(t.from)} reported back`:`${t.from||"another session"} sent a message`,s=Kee(t.text);return o.jsxs("div",{className:`peer-note ${e?"is-open":""}`,"data-peer":t.source,children:[o.jsxs("button",{type:"button",className:"peer-note-head","aria-expanded":e,onClick:()=>n(!e),children:[o.jsx(uB,{open:e}),o.jsx("span",{className:"peer-note-who",children:i}),!e&&s&&o.jsx("span",{className:"peer-note-opening",children:s})]}),e&&o.jsx("div",{className:"peer-note-body",children:o.jsx(wh,{text:t.text,animate:!1})})]})}function Xee({block:t}){const[e,n]=_.useState(!1),i=!!t.text.trim(),s=[t.trigger==="manual"?"you asked":t.trigger?"context filled up":"",t.preTokens&&t.postTokens?`${Ib(t.preTokens)} → ${Ib(t.postTokens)} tokens`:t.preTokens?`${Ib(t.preTokens)} tokens summarised`:"",t.durationMs?`${Math.max(1,Math.round(t.durationMs/1e3))}s`:""].filter(Boolean);return o.jsxs("div",{className:`compacted ${e?"is-open":""}`,children:[o.jsx(cB,{children:i?o.jsxs("button",{type:"button",className:"compacted-label is-button","aria-expanded":e,onClick:()=>n(!e),children:[o.jsx(uB,{open:e}),"history summarised to make room",s.length>0&&o.jsx("span",{className:"compacted-facts",children:o.jsx(Lt,{children:s.join(" · ")})})]}):o.jsxs("span",{className:"compacted-label",children:["history summarised to make room",s.length>0&&o.jsx("span",{className:"compacted-facts",children:o.jsx(Lt,{children:s.join(" · ")})})]})}),e&&i&&o.jsx("div",{className:"compacted-body",children:o.jsx(wh,{text:t.text,animate:!1})})]})}function cB({children:t,running:e}){const n=`compacted-line ${e?"is-running":""}`;return o.jsxs("div",{className:"compacted-bar",children:[o.jsx("span",{className:n,"aria-hidden":"true",children:e&&o.jsx(Qee,{})}),t,o.jsx("span",{className:n,"aria-hidden":"true"})]})}function Qee(){return o.jsx("span",{className:"compacting-truck","aria-hidden":"true",children:o.jsxs("svg",{className:"compacting-truck-art",viewBox:"0 0 32 16",width:"28",height:"14",children:[o.jsxs("g",{className:"compacting-truck-load",fill:"currentColor",children:[o.jsx("rect",{x:"1.8",y:"4.6",width:"7.2",height:"5.8",rx:"0.7",opacity:"0.62"}),o.jsx("rect",{x:"9.6",y:"6.6",width:"6",height:"3.8",rx:"0.6",opacity:"0.85"})]}),o.jsx("rect",{x:"0.8",y:"10.4",width:"15.8",height:"1.5",rx:"0.5",fill:"currentColor"}),o.jsx("path",{d:"M16.2 11.9V6.2h5l4.4 4v1.7z",fill:"currentColor"}),o.jsx("path",{d:"M20.2 7.4h.9l2.9 2.6h-3.8z",fill:"var(--bg-1)"}),o.jsx("circle",{cx:"6.4",cy:"13.2",r:"1.8",fill:"currentColor"}),o.jsx("circle",{cx:"21.4",cy:"13.2",r:"1.8",fill:"currentColor"}),o.jsx("circle",{cx:"6.4",cy:"13.2",r:"0.65",fill:"var(--bg-1)"}),o.jsx("circle",{cx:"21.4",cy:"13.2",r:"0.65",fill:"var(--bg-1)"})]})})}function Zee({since:t}){const[,e]=_.useState(0);_.useEffect(()=>{const i=setInterval(()=>e(s=>s+1),1e3);return()=>clearInterval(i)},[]);const n=Math.max(0,Math.round((Date.now()-t)/1e3));return o.jsx("div",{className:"compacted is-running",role:"status",children:o.jsx(cB,{running:!0,children:o.jsxs("span",{className:"compacted-label",children:["summarising history to make room",o.jsx("span",{className:"compacted-facts",children:o.jsx(Lt,{children:`${n}s`})})]})})})}function uB({open:t}){return o.jsx("svg",{className:`compacted-chev ${t?"is-open":""}`,width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"m9 6 6 6-6 6"})})}function Jee({text:t}){const[e,n]=_.useState(!1),{head:i,clipped:s}=_.useMemo(()=>JJ(t),[t]);return s?o.jsxs("div",{className:`clip ${e?"is-open":"is-cut"}`,children:[o.jsx(wh,{text:e?t:i,animate:!1}),o.jsx("button",{className:"clip-more",type:"button","aria-expanded":e,onClick:()=>n(!e),children:e?"show less":"show more"})]}):o.jsx(wh,{text:t,animate:!1})}function ete(){return o.jsxs("div",{className:"stopmark",role:"separator",children:[o.jsx("span",{className:"stopmark-rule","aria-hidden":"true"}),o.jsxs("span",{className:"stopmark-label",children:[o.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:o.jsx("rect",{x:"5",y:"5",width:"14",height:"14",rx:"3"})}),"You stopped this"]}),o.jsx("span",{className:"stopmark-rule","aria-hidden":"true"})]})}function tte({messages:t,kids:e,agentByTool:n,onOpenAgent:i,last:s,busy:r,tints:a,fresh:c,mapTurnId:u,hostName:d,hostPersona:p,onCancelQueued:m,onStartQueued:v,onRestoreUnsent:x,onDismissUnsent:y}){const k=t[0].role,S=t[0].speaker,C=t[0].to,A=t[0].relay,N=t[0].ranSkill,E=t.find(U=>U.replyTo)?.replyTo,M=t.some(U=>U.streaming),L=t.flatMap(U=>U.blocks),$=t.flatMap(U=>U.progress??[]),V=[...t].reverse().find(U=>U.codexCandidate)?.codexCandidate,X=U=>k==="user"?I1(U)?.task??U:U,D=k==="user"?L.map(U=>U.kind==="text"?I1(U.text)?.lead:void 0).find(Boolean):void 0,Q=L.filter(U=>U.kind==="text").map(U=>X(U.text)).join(`
78
78
 
79
79
  `).trim(),P=t[0],z=k==="user"&&t.some(U=>U.queueLost&&!U.echo&&!U.takenUp),H=k==="user"&&!z&&!P.echo&&!P.takenUp&&P.delivery==="queued",W=H?P.turnId:void 0,F=m&&W?()=>m(W):void 0,Y=v&&W?()=>v(W):void 0,J=L.length>0&&L.every(U=>U.kind==="compacted"||U.kind==="notice"||U.kind==="peer"||U.kind==="memory"),te=_.useMemo(()=>{const U=new Map;for(const Z of t)for(const R of Z.attachments??[])U.set(R.path,R);return[...U.values()]},[t]);if(A)return o.jsxs("article",{className:"msg msg-relay",children:[o.jsx("span",{"aria-hidden":"true",children:"↳"})," ",A]});const I=S?a?.get(rB(S)):void 0;return o.jsxs("article",{className:`msg msg-${k} ${S?"msg-seat":""} ${H?"is-queued":""} ${c?"is-new":""}`,"data-tint":I,"data-map-turn":u,children:[k==="user"&&C&&o.jsxs("div",{className:"msg-to",children:["to ",C.name]}),D&&o.jsxs("div",{className:"msg-to",children:["task for ",D]}),k==="user"&&N&&o.jsx("div",{className:"msg-ran",title:"The skill this command resolved to",children:N}),k==="assistant"&&!J&&o.jsx("div",{className:"msg-role",children:S?o.jsxs(o.Fragment,{children:[o.jsx(af,{agent:S.agent==="claude"?"claude":"codex",size:13}),S.name]}):p?o.jsxs(o.Fragment,{children:[o.jsx(ws,{name:p.name,avatar:p.avatar,id:p.id??p.name,size:16,removed:p.removed,decorative:!0}),p.name]}):d??"Claude"}),k==="assistant"&&E&&o.jsxs("div",{className:"msg-reply",title:`Replying to: ${E.preview}`,children:[o.jsx("span",{className:"msg-reply-label",children:"Replying to"}),o.jsx("span",{className:"msg-reply-preview",children:E.preview})]}),o.jsxs(Ree,{user:k==="user",message:P,onStart:Y,onCancel:F,onRestore:(z||P.delivery==="unknown")&&!P.echo&&!P.takenUp&&x&&P.turnId?()=>x(P.turnId):void 0,onDismiss:z&&y&&P.turnId?()=>y(P.turnId):void 0,footer:k==="user"&&Q?o.jsx(aM,{text:Q,what:"message"}):void 0,children:[o.jsx(RJ,{files:te}),k==="assistant"&&o.jsx(Pee,{updates:$,candidate:V,streaming:M}),k==="user"&&L.every(U=>U.kind==="text")?L.map((U,Z)=>o.jsx(Jee,{text:X(U.text)},Z)):o.jsx(oB,{blocks:L,streaming:M,kids:e,agentByTool:n,onOpenAgent:i}),M&&L.length===0&&o.jsx("div",{className:"dots","aria-label":p?`${p.name} is working`:"working"}),k==="assistant"&&!M&&!(r&&s)&&Q&&o.jsx("div",{className:"msg-foot",children:o.jsx(aM,{text:Q,what:"reply"})})]})]})}function aM({text:t,what:e}){const[n,i]=_.useState("idle");return o.jsx("div",{className:"msg-actions",children:o.jsxs("button",{className:`msg-copy ${n==="done"?"is-done":""}`,type:"button",title:`Copy this ${e}`,onClick:async()=>{const s=await tu(t);i(s?"done":"failed"),setTimeout(()=>i("idle"),1600)},children:[n==="done"?o.jsx(ite,{}):o.jsx(nte,{}),n==="done"?"copied":n==="failed"?"could not copy":"copy"]})})}function nte(){return o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("rect",{x:"9",y:"9",width:"12",height:"12",rx:"2"}),o.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}function ite(){return o.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"m20 6-11 11-5-5"})})}function ste(t){const e=[];for(const n of t){const i=e[e.length-1],s=n.role==="user"&&i?.[0].role==="user",r=n.replyTo?.id!==i?.[0].replyTo?.id&&(!!n.replyTo||!!i?.[0].replyTo);!(!!n.relay||!!i?.[0].relay||s||r)&&i&&i[0].role===n.role&&i[0].speaker?.id===n.speaker?.id?i.push(n):e.push([n])}return e}function rte(t){const e=_.useRef(null),n=_.useRef(new Set),i=_.useRef(0),s=t.map(c=>c[0].id),r=e.current;e.current=s;const a=ate(r,s);return a&&(n.current.add(a),i.current++),{fresh:n.current,nth:i.current}}function ate(t,e){if(!t||e.length!==t.length+1)return null;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return null;return e[e.length-1]}const ote=280,lte=t=>1-Math.pow(1-t,5);function cte(t,e,n){const i=n<0?0:n>1?1:n;return t+(e-t)*lte(i)}const ute=8;function hte(){return typeof window>"u"?!1:!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches}const Up=80;function dte(t){return!!t?.closest?.(".jump")}const fte=400,oM=6e3;function Vp(t){const e=t.getBoundingClientRect(),n=[];for(const i of t.querySelectorAll("[data-map-turn]")){const s=i.dataset.mapTurn;s&&n.push({id:s,offset:t.scrollTop+i.getBoundingClientRect().top-e.top})}return n}const pte=function({messages:e,busy:n,stoppedAt:i,compactingSince:s,conversationId:r,onSetting:a,agentByTool:c,onOpenAgent:u,hostName:d,hostPersona:p,onCancelQueued:m,onStartQueued:v,onRestoreUnsent:x,onDismissUnsent:y,hasEarlier:k=!1,loadingEarlier:S=!1,earlierError:C,onLoadEarlier:A,tail:N}){const E=_.useRef(null),M=_.useRef(null),L=_.useRef(null),$=_.useRef(()=>{}),V=_.useRef(!1),X=_.useRef(null),D=_.useRef(!0),Q=_.useRef(!1),[P,z]=_.useState(!1),H=_.useRef(0),W=_.useRef(r),F=_.useRef(null),Y=_.useRef(0),J=_.useRef(null),te=()=>{H.current&&cancelAnimationFrame(H.current),H.current=0},I=()=>{window.clearTimeout(Y.current),Y.current=0;const ke=F.current;F.current=null,ke&&(ke.at?mz(ke.id,ke.at):MR(ke.id))},U=()=>{const ke=M.current,Je=W.current;if(!ke||!Je||H.current||J.current)return;const at=ke.scrollHeight-ke.scrollTop-ke.clientHeight<Up;!at&&D.current||(F.current={id:Je,at:at?null:dA(ke.scrollTop,Vp(ke))},window.clearTimeout(Y.current),Y.current=window.setTimeout(I,fte))},Z=()=>{const ke=M.current;if(!ke)return;te();const Je=ke.scrollHeight-ke.clientHeight,at=Math.max(ke.clientHeight*1.5,400),it=Math.max(ke.scrollTop,Je-at);if(Je-it<ute||hte()){ke.scrollTop=ke.scrollHeight;return}it!==ke.scrollTop&&(ke.scrollTop=it);const We=performance.now(),pn=ke.closest(".focus-mode")?440:ote,he=Me=>{const ze=(Me-We)/pn;if(ke.scrollTop=cte(it,ke.scrollHeight-ke.clientHeight,ze),ze<1){H.current=requestAnimationFrame(he);return}H.current=0,D.current&&(ke.scrollTop=ke.scrollHeight)};H.current=requestAnimationFrame(he)},R=()=>{D.current=!0,z(!1),J.current=null,W.current&&(F.current={id:W.current,at:null}),I(),Z()};_.useEffect(()=>{const ke=M.current;if(!ke)return;let Je=0;const at=pn=>{dte(pn?.target??null)||(Q.current=!0,te(),J.current=null,window.clearTimeout(Je),Je=window.setTimeout(()=>Q.current=!1,400))},it=()=>{if(!Q.current){U();return}at();const pn=ke.scrollHeight-ke.scrollTop-ke.clientHeight<Up;D.current=pn,z(!pn),U(),ke.scrollTop<160&&$.current()},We=()=>I();return ke.addEventListener("scroll",it,{passive:!0}),window.addEventListener("pagehide",We),ke.addEventListener("wheel",at,{passive:!0}),ke.addEventListener("touchstart",at,{passive:!0}),ke.addEventListener("touchmove",at,{passive:!0}),ke.addEventListener("pointerdown",at,{passive:!0}),ke.addEventListener("keydown",at),()=>{window.clearTimeout(Je),te(),I(),window.removeEventListener("pagehide",We),ke.removeEventListener("scroll",it),ke.removeEventListener("wheel",at),ke.removeEventListener("touchstart",at),ke.removeEventListener("touchmove",at),ke.removeEventListener("pointerdown",at),ke.removeEventListener("keydown",at)}},[]),_.useLayoutEffect(()=>{const ke=M.current;if(I(),W.current=r,!ke)return;Q.current=!1,te();const Je=r?hA(r):void 0;if(!Je){D.current=!0,z(!1),J.current=null,ke.scrollTop=ke.scrollHeight;return}D.current=!1,J.current={at:Je,until:performance.now()+oM},ke.scrollTop=K_(Je,Vp(ke),ke.scrollHeight-ke.clientHeight),z(ke.scrollHeight-ke.scrollTop-ke.clientHeight>=Up)},[r]),_.useEffect(()=>{const ke=M.current,Je=L.current;if(!ke||!Je||typeof ResizeObserver>"u")return;const at=new ResizeObserver(()=>{if(D.current&&!H.current){ke.scrollTop=ke.scrollHeight;return}const it=J.current;it&&(performance.now()>it.until?J.current=null:ke.scrollTop=K_(it.at,Vp(ke),ke.scrollHeight-ke.clientHeight)),H.current||z(ke.scrollHeight-ke.scrollTop-ke.clientHeight>=Up)});return at.observe(Je),()=>at.disconnect()},[]);const{turns:K,kids:O}=_.useMemo(()=>{const ke=new Map,Je=[];for(const at of e){if(!at.parent){Je.push(at);continue}const it=ke.get(at.parent);it?it.push(at):ke.set(at.parent,[at])}return{turns:ste(Je),kids:ke}},[e]),ie=()=>({id:r,ready:K.length>0,first:Dee(K,r?hA(r)?.turn:void 0)});let[re,ve]=_.useState(ie);(re.id!==r||!re.ready&&K.length>0)&&(re=ie(),ve(re),X.current=null);const le=Bee(K,re.first),Re=_.useMemo(()=>K.slice(le),[K,le]),De=le>0||k,Ke=async()=>{if(!De||S||V.current)return;const ke=M.current;if(!ke)return;const Je=r,at=Vp(ke);let it=dA(ke.scrollTop,at);if(!it.turn&&at[0]&&(it={top:ke.scrollTop,turn:at[0].id,delta:ke.scrollTop-at[0].offset}),X.current={id:Je,first:Re[0]?.[0].id,at:it},te(),D.current=!1,le>0){ve({id:Je,ready:!0,first:K[Math.max(0,le-aB)][0].id});return}V.current=!0;try{await A?.(),W.current===Je&&ve({id:Je,ready:!0,first:null})}finally{V.current=!1}};$.current=()=>{C||Ke()},_.useLayoutEffect(()=>{const ke=X.current,Je=M.current;!ke||ke.id!==r||!Je||ke.first===Re[0]?.[0].id||(X.current=null,Je.scrollTop=K_(ke.at,Vp(Je),Je.scrollHeight-Je.clientHeight),J.current={at:ke.at,until:performance.now()+oM},z(Je.scrollHeight-Je.scrollTop-Je.clientHeight>=Up))},[Re,r]);const xe=_.useMemo(()=>Aee(e),[e]),{fresh:Te,nth:vt}=rte(K),Bt=_.useMemo(()=>Nee(Re),[Re]),Ot=()=>{te(),J.current=null,D.current=!1,z(!0)};_.useLayoutEffect(()=>{vt&&D.current&&Z()},[vt]);const At=_.useMemo(()=>{const ke=[];for(const Je of e.slice(-40))if(Je.role==="assistant")for(const at of Je.blocks){if(at.kind!=="text")continue;const it=at.text.trim();it&&it.length<=120&&ke.push(it)}return ke},[e]),nn=_.useMemo(()=>({say:a??(()=>{}),said:At}),[a,At]);return o.jsxs("div",{className:"msgs",ref:M,children:[o.jsx(Tee,{turns:Bt,scrollerRef:M,innerRef:L,onJump:Ot}),o.jsxs(oee,{say:nn.say,said:nn.said,readOnly:!a,children:[o.jsxs("div",{className:"msgs-inner",ref:L,children:[De&&o.jsxs("div",{className:"history-more",children:[o.jsx("button",{type:"button",disabled:S,onClick:()=>{Ke()},children:S?"Loading earlier messages…":"Load earlier messages"}),C&&o.jsx("span",{role:"alert",children:"Could not load earlier messages. Try again."})]}),Re.map((ke,Je)=>o.jsxs(_.Fragment,{children:[o.jsx(tte,{messages:ke,kids:O,agentByTool:c,onOpenAgent:u,last:Je===Re.length-1,busy:n,tints:xe,fresh:Te.has(ke[0].id),mapTurnId:ke[0].role==="user"?ke[0].id:void 0,hostName:d,hostPersona:p,onCancelQueued:m,onStartQueued:v,onRestoreUnsent:x,onDismissUnsent:y}),!!i&&ke.some(at=>at.id===i)&&o.jsx(ete,{})]},ke[0].id)),s!==void 0&&o.jsx(Zee,{since:s}),N,o.jsx("div",{ref:E})]}),o.jsx("div",{className:"jump-slot","aria-hidden":!P,children:o.jsx("button",{type:"button",className:`jump ${P?"is-on":""}`,onClick:R,tabIndex:P?0:-1,title:"Jump to the end","aria-label":"Jump to the end",children:o.jsx(mte,{})})})]})]})},hB=_.memo(pte);function mte(){return o.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"m6 9 6 6 6-6"})})}function gte({messages:t,parent:e}){const n=new Map;for(const s of t){if(!s.parent)continue;const r=n.get(s.parent);r?r.push(s):n.set(s.parent,[s])}const i=n.get(e);return i?.length?o.jsx(lB,{messages:i,kids:n}):null}function vte(t){const[e,n]=_.useState({loading:!1});return _.useEffect(()=>{if(!t){n({loading:!1});return}let i=!0;return n({loading:!0}),ae.invoke("read_file_preview",{path:t}).then(s=>{if(i){if(s.kind!=="text"){n({loading:!1,error:`the run's output is ${s.kind}, not text`});return}n({loading:!1,text:s.content,truncated:s.truncated})}}).catch(s=>{i&&n({loading:!1,error:s instanceof Error?s.message:String(s)})}),()=>{i=!1}},[t]),e}function xte({label:t,value:e,rolling:n=!1}){return o.jsxs("div",{className:"focus-stat",children:[o.jsx("span",{className:"focus-stat-label",children:t}),o.jsx("span",{className:"focus-stat-value",children:n?o.jsx(Lt,{children:e}):e})]})}function yte({run:t}){const e=vte(t.outputFile),n=t.workers??[];return o.jsxs(o.Fragment,{children:[o.jsx("p",{className:"focus-note",children:"A workflow's agents run in their own processes, so their working is not on this conversation's stream. What they reported is below."}),n.length>0&&o.jsx("ul",{className:"focus-workers",children:n.map(i=>o.jsxs("li",{className:`focus-worker ${i.state==="done"?"is-done":"is-running"}`,children:[o.jsxs("div",{className:"focus-worker-head",children:[o.jsx("span",{className:"focus-worker-label",children:i.label||`agent ${i.index}`}),i.tokens!==void 0&&o.jsx("span",{className:"focus-worker-cost",children:o.jsx(Lt,{children:`${i.tokens.toLocaleString()} tok`})})]}),i.resultPreview&&o.jsx("div",{className:"focus-worker-result",children:i.resultPreview})]},i.id))}),o.jsx("h4",{className:"focus-heading",children:"Result"}),e.loading&&o.jsx("div",{className:"focus-muted",children:"reading the run's output…"}),e.error&&o.jsxs("div",{className:"focus-muted",children:["could not read the output file — ",e.error]}),e.text!==void 0&&o.jsxs(o.Fragment,{children:[o.jsx("pre",{className:"focus-output",children:e.text}),e.truncated&&o.jsx("div",{className:"focus-muted",children:"…output truncated"})]}),!t.outputFile&&!e.loading&&o.jsx("div",{className:"focus-muted",children:t.summary??"this run wrote no output file"})]})}function _te({run:t,messages:e}){const n=t.toolUseId?o.jsx(gte,{messages:e,parent:t.toolUseId}):null;return n||o.jsxs("div",{className:"focus-muted",children:[t.status==="running"?"this agent has not written anything yet":"this agent sent no transcript — only its result came back",t.summary&&o.jsx("pre",{className:"focus-output",children:t.summary})]})}function bte({run:t,messages:e,onBack:n}){const i=[t.detail?{label:"kind",value:t.detail,rolling:!1}:void 0,t.tokens!==void 0?{label:"tokens",value:t.tokens.toLocaleString(),rolling:!0}:void 0,t.toolCalls!==void 0?{label:"tools",value:`${t.toolCalls}`,rolling:!0}:void 0,t.durationMs!==void 0?{label:"took",value:`${(t.durationMs/1e3).toFixed(1)}s`,rolling:!0}:void 0].filter(s=>!!s);return o.jsxs("div",{className:"focus",children:[o.jsxs("div",{className:"focus-bar",children:[o.jsx("button",{className:"focus-back",onClick:n,type:"button",children:"← conversation"}),o.jsx("span",{className:`focus-status is-${t.status}`,children:t.status})]}),o.jsxs("div",{className:"focus-scroll",children:[o.jsx("h3",{className:"focus-title",children:t.label}),i.length>0&&o.jsx("div",{className:"focus-stats",children:i.map(s=>o.jsx(xte,{label:s.label,value:s.value,rolling:s.rolling},s.label))}),t.kind==="local_workflow"?o.jsx(yte,{run:t}):o.jsx(_te,{run:t,messages:e})]})]})}function lM(t){const e=new Set,n=[];for(const i of t){const s=i.trim().replace(/^\/+/,"");!s||/\s/.test(s)||e.has(s.toLowerCase())||(e.add(s.toLowerCase()),n.push({id:s,label:`/${s}`,insert:`/${s} `}))}return n}const zm={claude:{id:"claude",name:"Claude",models:[{id:"claude:opus",agent:"claude",name:"Claude",model:"Opus latest",flag:"opus",hint:"for complex work · moving alias opus",composerStyle:"opus"},{id:"claude:sonnet",agent:"claude",name:"Claude",model:"Sonnet latest",flag:"sonnet",hint:"the everyday balance · moving alias sonnet",composerStyle:"sonnet"},{id:"claude:haiku",agent:"claude",name:"Claude",model:"Haiku latest",flag:"haiku",hint:"fastest for quick answers · moving alias haiku",composerStyle:"haiku"},{id:"claude:fable",agent:"claude",name:"Claude",model:"Fable latest",flag:"fable",hint:"for the toughest problems · moving alias fable",composerStyle:"fable"},{id:"claude:opus-5-5",agent:"claude",name:"Claude",model:"Opus 5.5",flag:"claude-opus-5-5",hint:"claude-opus-5-5",composerStyle:"opus"},{id:"claude:opus-5",agent:"claude",name:"Claude",model:"Opus 5",flag:"claude-opus-5",hint:"claude-opus-5",composerStyle:"opus"},{id:"claude:opus-4-8",agent:"claude",name:"Claude",model:"Opus 4.8",flag:"claude-opus-4-8",hint:"claude-opus-4-8",composerStyle:"opus"},{id:"claude:opus-4-7",agent:"claude",name:"Claude",model:"Opus 4.7",flag:"claude-opus-4-7",hint:"claude-opus-4-7",composerStyle:"opus"},{id:"claude:opus-4-6",agent:"claude",name:"Claude",model:"Opus 4.6",flag:"claude-opus-4-6",hint:"claude-opus-4-6",composerStyle:"opus"},{id:"claude:opus-4-5-20251101",agent:"claude",name:"Claude",model:"Opus 4.5",flag:"claude-opus-4-5-20251101",hint:"claude-opus-4-5-20251101",composerStyle:"opus"},{id:"claude:sonnet-5-5",agent:"claude",name:"Claude",model:"Sonnet 5.5",flag:"claude-sonnet-5-5",hint:"claude-sonnet-5-5",composerStyle:"sonnet"},{id:"claude:sonnet-5",agent:"claude",name:"Claude",model:"Sonnet 5",flag:"claude-sonnet-5",hint:"claude-sonnet-5",composerStyle:"sonnet"},{id:"claude:sonnet-4-6",agent:"claude",name:"Claude",model:"Sonnet 4.6",flag:"claude-sonnet-4-6",hint:"claude-sonnet-4-6",composerStyle:"sonnet"},{id:"claude:sonnet-4-5-20250929",agent:"claude",name:"Claude",model:"Sonnet 4.5",flag:"claude-sonnet-4-5-20250929",hint:"claude-sonnet-4-5-20250929",composerStyle:"sonnet"},{id:"claude:haiku-4-5-20251001",agent:"claude",name:"Claude",model:"Haiku 4.5",flag:"claude-haiku-4-5-20251001",hint:"claude-haiku-4-5-20251001",composerStyle:"haiku"},{id:"claude:default",agent:"claude",name:"Claude",model:"Default",flag:"",hint:"whatever the CLI picks",composerStyle:"claude"}],access:[{id:"read",label:"Plan",hint:"create a plan before making changes"},{id:"manual",label:"Manual",hint:"always ask before making changes"},{id:"edits",label:"Accept edits",hint:"automatically accept all file edits"},{id:"auto",label:"Auto",hint:"Claude handles permission decisions"},{id:"full",label:"Bypass permissions",hint:"run anything without asking",bypass:!0}],efforts:[{id:"low",label:"Low",short:"Low",hint:"quick answers, least thinking"},{id:"medium",label:"Medium",short:"Med",hint:"the usual balance"},{id:"high",label:"High",short:"High",hint:"thinks longer, costs more"},{id:"xhigh",label:"Very high",short:"V.high",hint:"for problems worth the wait"},{id:"max",label:"Max",short:"Max",hint:"everything it has"},{id:"ultracode",label:"Ultracode",short:"Ultra",hint:"max, and it fans work out to subagents"},{id:"auto",label:"Auto",short:"Auto",hint:"it picks the level itself, per turn"}],capabilities:{commands:"reported",liveSettings:{model:!0,effort:!0},cleanStart:!0},commands:lM,liveSettingCommand(t,e){if(e)return t==="model"?`/model ${e}`:`/effort ${e}`}},codex:{id:"codex",name:"Codex",models:[{id:"codex:astra",agent:"codex",name:"Codex",model:"Astra",flag:"gpt-6-astra",hint:"the frontier one",composerStyle:"astra"},{id:"codex:sol",agent:"codex",name:"Codex",model:"Sol",flag:"gpt-5.6-sol",hint:"the reliable workhorse",composerStyle:"sol"},{id:"codex:terra",agent:"codex",name:"Codex",model:"Terra",flag:"gpt-5.6-terra",hint:"the everyday balance",composerStyle:"terra"},{id:"codex:luna",agent:"codex",name:"Codex",model:"Luna",flag:"gpt-5.6-luna",hint:"fast and cheap",composerStyle:"luna"},{id:"codex:default",agent:"codex",name:"Codex",model:"Default",flag:"",hint:"whatever the CLI picks",composerStyle:"codex"}],access:[{id:"read",label:"Read-only",hint:"sandboxed, no writes"},{id:"auto",label:"Workspace write",hint:"writes in the project, asks when unsure"},{id:"full",label:"Danger: full access",hint:"no sandbox, no approvals"}],efforts:[{id:"low",label:"Low",short:"Low",hint:"quick answers"},{id:"medium",label:"Medium",short:"Med",hint:"the usual balance"},{id:"high",label:"High",short:"High",hint:"thinks longer, costs more"},{id:"xhigh",label:"Very high",short:"V.high",hint:"for problems worth the wait"},{id:"max",label:"Max",short:"Max",hint:"everything it has"}],capabilities:{commands:"loaded",liveSettings:{model:!1,effort:!1},cleanStart:!1},commands:lM,liveSettingCommand(){}},pi:{id:"pi",name:"pi.dev",models:[{id:"pi:astra",agent:"pi",name:"pi.dev",model:"Astra",flag:"gpt-6-astra",hint:"Codex through pi.dev",composerStyle:"pi-astra"},{id:"pi:sol",agent:"pi",name:"pi.dev",model:"Sol",flag:"gpt-5.6-sol",hint:"Codex through pi.dev",composerStyle:"pi-sol"},{id:"pi:terra",agent:"pi",name:"pi.dev",model:"Terra",flag:"gpt-5.6-terra",hint:"Codex through pi.dev",composerStyle:"pi-terra"},{id:"pi:luna",agent:"pi",name:"pi.dev",model:"Luna",flag:"gpt-5.6-luna",hint:"Codex through pi.dev",composerStyle:"pi-luna"},{id:"pi:default",agent:"pi",name:"pi.dev",model:"Default",flag:"",hint:"whatever Pi picks",composerStyle:"pi"}],access:[{id:"read",label:"Read-only",hint:"only read, search and list tools"},{id:"full",label:"Full access",hint:"Pi can run commands and edit files",bypass:!0}],efforts:[{id:"minimal",label:"Minimal",short:"Min",hint:"the least reasoning"},{id:"low",label:"Low",short:"Low",hint:"quick answers"},{id:"medium",label:"Medium",short:"Med",hint:"the usual balance"},{id:"high",label:"High",short:"High",hint:"thinks longer, costs more"},{id:"xhigh",label:"Very high",short:"V.high",hint:"for problems worth the wait"},{id:"max",label:"Max",short:"Max",hint:"everything it has"}],capabilities:{commands:"none",liveSettings:{model:!1,effort:!1},cleanStart:!1},commands(){return[]},liveSettingCommand(){}}};function hi(t){return zm[t]}const Eh=Object.values(zm),ya=Eh.flatMap(t=>t.models),Xo=Object.fromEntries(Eh.map(t=>[t.id,t.name])),cM=Object.fromEntries(Eh.map(t=>[t.id,t.access])),Pb=Object.fromEntries(Eh.map(t=>[t.id,t.efforts])),Qw=":model:";function wte(t){return/^[A-Za-z0-9._-]{1,64}$/.test(t)}function zb(t){return/^gpt$/i.test(t)?"GPT":t&&t[0].toUpperCase()+t.slice(1)}function dB(t,e,n){if(n?.trim())return n.trim().replace(/^Claude\s+/i,"");if(t==="claude"){const s=e.replace(/^claude-/,"").replace(/-\d{8}$/,"").split("-"),r=zb(s.shift()??e);return s.length?`${r} ${s.join(".")}`:r}const i=e.split("-");if(/^gpt$/i.test(i[0]??"")){const s=zb(i.shift()),r=i.shift()??"";return[s+(r?`-${r}`:""),...i.map(zb)].join(" ")}return e}function fB(t){const e=t.trim().toLowerCase().replace(/\[[^\]]*\]$/,"");if(/^(claude-)?(opus|sonnet|haiku|fable)(-\d+)*$/.test(e))return dB("claude",e)}function kte(t,e){const n=e.toLowerCase();return t==="claude"?n.includes("opus")?"opus":n.includes("sonnet")?"sonnet":n.includes("haiku")?"haiku":n.includes("fable")?"fable":"claude":t==="codex"?n.includes("astra")?"astra":n.includes("sol")?"sol":n.includes("terra")?"terra":n.includes("luna")?"luna":"codex":n.includes("astra")?"pi-astra":n.includes("sol")?"pi-sol":n.includes("terra")?"pi-terra":n.includes("luna")?"pi-luna":"pi"}function ay(t,e,n,i){const s=e.trim();if(!wte(s))return;const r=hi(t).models.find(a=>a.flag===s);return r||{id:`${t}${Qw}${encodeURIComponent(s)}`,agent:t,name:hi(t).name,model:dB(t,s,n),flag:s,hint:i?.trim()||s,composerStyle:kte(t,s)}}function Mc(t){if(!t)return;const e=ya.find(s=>s.id===t);if(e)return e;const n=t.split(":")[0],i=t.indexOf(Qw);if(zm[n]&&i>0)try{return ay(n,decodeURIComponent(t.slice(i+Qw.length)))}catch{return}return zm[n]?.models[0]}function bx(t,e){const n=e.trim();return n?hi(t).models.filter(r=>r.flag).find(r=>r.flag===n)??ay(t,n):hi(t).models.find(r=>!r.flag)}function Ku(t,e){const n=hi(t).access;return n.some(i=>i.id===e)?e:n[0].id}function uM(t,e){return hi(t).access.find(n=>n.id===e)?.label??e}function pB(t){return hi(t).efforts.filter(e=>e.id!=="auto")}function Zw(t,e){const n=hi(t).efforts;return n.some(i=>i.id===e)?e:n[0].id}function Ste(t,e){return hi(t).commands(e)}function Cte(t,e,n){return hi(t).liveSettingCommand(e,n)}function jte(t){if(!t||typeof t!="object"||Array.isArray(t))return{};const e={};for(const[n,i]of Object.entries(t)){if(Array.isArray(i)){const r=i.filter(a=>typeof a=="string");r.length&&(e[n]={claude:r});continue}if(!i||typeof i!="object"||Array.isArray(i))continue;const s={};for(const r of Object.keys(zm)){const a=i[r];if(Array.isArray(a)){const c=a.filter(u=>typeof u=="string");c.length&&(s[r]=c)}}Object.keys(s).length&&(e[n]=s)}return e}function Jw(t){if(t<6e4)return`${(t/1e3).toFixed(1)}s`;const e=Math.round(t/1e3);return`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`}function Ate(t){return t<1e3?`${t}`:`${(t/1e3).toFixed(t<1e4?1:0)}k`}function Nte(t){return fB(t)??/opus|sonnet|haiku|fable|gpt|codex/i.exec(t)?.[0].toLowerCase()??t}function Ete(t){const[e,n]=_.useState(()=>Date.now());return _.useEffect(()=>{if(!t)return;n(Date.now());const i=setInterval(()=>n(Date.now()),1e3);return()=>clearInterval(i)},[t]),e}function mB(t,e,n,i,s){return t?n?Jw(Math.max(0,e-n)):"running…":[i!==void 0?Ate(i):void 0,s!==void 0?Jw(s):void 0].filter(Boolean).join(" · ")}function hM({worker:t,now:e}){const n=t.state!=="done",i=t.queuedAt&&t.startedAt&&t.startedAt-t.queuedAt>=1e3?t.startedAt-t.queuedAt:void 0;return o.jsxs("li",{className:`rail-row is-worker ${n?"is-running":"is-completed"}`,children:[o.jsx("span",{className:"rail-dot","aria-hidden":"true"}),o.jsxs("span",{className:"rail-body",children:[o.jsx("span",{className:"rail-label",children:t.label||`agent ${t.index}`}),o.jsxs("span",{className:"rail-meta",children:[t.model&&o.jsx("span",{className:"rail-kind rail-model",children:Nte(t.model)}),t.attempt!==void 0&&t.attempt>1&&o.jsx("span",{className:"rail-retry",children:o.jsx(Lt,{children:`retry ${t.attempt}`})}),i&&o.jsx("span",{className:"rail-kind",children:o.jsx(Lt,{children:`queued ${Jw(i)}`})}),o.jsx("span",{className:n?"rail-live":"rail-stats",children:o.jsx(Lt,{children:mB(n,e,t.startedAt,t.tokens,t.durationMs)})})]})]})]})}function Mte({run:t,now:e}){const n=t.workers??[],i=t.phases??[],s=n.filter(r=>!i.some(a=>a.index===r.phaseIndex));return o.jsxs(o.Fragment,{children:[i.map(r=>{const a=n.filter(u=>u.phaseIndex===r.index);if(a.length===0)return null;const c=a.filter(u=>u.state!=="done").length;return o.jsxs("li",{className:"rail-phase",children:[o.jsxs("div",{className:"rail-phase-head",children:[o.jsx("span",{className:"rail-phase-title",children:r.title}),o.jsx("span",{className:"rail-phase-count",children:o.jsx(Lt,{children:c>0?`${c}/${a.length}`:`${a.length}`})})]}),o.jsx("ul",{className:"rail-sub",children:a.map(u=>o.jsx(hM,{worker:u,now:e},u.id))})]},r.index)}),s.length>0&&o.jsxs("li",{className:"rail-phase",children:[o.jsx("div",{className:"rail-phase-head",children:o.jsx("span",{className:"rail-phase-title",children:"other"})}),o.jsx("ul",{className:"rail-sub",children:s.map(r=>o.jsx(hM,{worker:r,now:e},r.id))})]})]})}function Lte({run:t,now:e,onOpen:n}){const i=t.status==="running";return o.jsxs("li",{className:`rail-run is-${t.status}`,children:[o.jsxs("button",{className:"rail-row",type:"button",onClick:()=>n?.(t.id),children:[o.jsx("span",{className:"rail-dot","aria-hidden":"true"}),o.jsxs("span",{className:"rail-body",children:[o.jsx("span",{className:"rail-label",children:t.label}),o.jsxs("span",{className:"rail-meta",children:[t.detail&&o.jsx("span",{className:"rail-kind",children:t.detail}),o.jsx("span",{className:i?"rail-live":"rail-stats",children:o.jsx(Lt,{children:mB(i,e,t.startedAt,t.tokens,t.durationMs)})})]})]})]}),(t.workers?.length??0)>0&&o.jsx("ul",{className:"rail-tree",children:o.jsx(Mte,{run:t,now:e})})]})}function Tte({count:t,open:e,onToggle:n}){return t===0?null:o.jsxs("button",{className:`icon-btn rail-toggle ${e?"is-on":""}`,type:"button","aria-expanded":e,"aria-label":`Agents in this chat — ${t}`,title:`${t} agent${t===1?"":"s"} this chat has started`,onClick:n,children:[o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M11 3l1.7 4.3L17 9l-4.3 1.7L11 15l-1.7-4.3L5 9l4.3-1.7z"}),o.jsx("path",{d:"M18 14.5l.7 1.8 1.8.7-1.8.7-.7 1.8-.7-1.8-1.8-.7 1.8-.7z"})]}),o.jsx("span",{className:"topbar-action-label",children:"Agents"}),o.jsx("span",{className:"rail-count",children:o.jsx(cr,{value:t})})]})}function Rte({agents:t,onOpen:e,onClose:n}){const i=t.filter(r=>r.status==="running").length,s=Ete(i>0);return t.length===0?null:o.jsxs("aside",{className:"rail","aria-label":"agents",children:[o.jsxs("header",{className:"rail-head",children:[o.jsx("span",{className:"rail-title",children:"Agents"}),n&&o.jsx("button",{className:"rail-close",type:"button","aria-label":"Hide agents",onClick:n,children:"✕"})]}),o.jsx("ul",{className:"rail-list",children:t.map(r=>o.jsx(Lte,{run:r,now:s,onOpen:e},r.id))}),o.jsx("div",{className:"rail-foot",children:o.jsx(Lt,{children:i>0?`${i} running`:`${t.length} finished`})})]})}function gB(t){if(t.parent||t.relay)return;const e=t.blocks.flatMap(n=>n.kind==="text"?[n.text]:[]).join(`
80
- `).trim()||(t.attachments?.length?"[Attachment]":"");if(e)return{id:t.id,speaker:t.role==="user"?"You":t.speaker?.name??"Assistant",text:e.length>420?`${e.slice(0,420).trimEnd()}…`:e}}function Dte(t){const e=[];for(let n=t.length-1;n>=0&&e.length<3;n--){const i=t[n],s=gB(i);s&&e.unshift(s)}return e}function ek(t){for(let e=t.length-1;e>=0;e--){if(t[e].role==="user")continue;const n=gB(t[e]);if(n)return n}}function EC(t){const e=[],n=s=>`${e.push(s)-1}`;return t.replace(/\\([\\`*_{}[\]()#+\-.!~|<>])/g,(s,r)=>n(r)).replace(/^[ \t]*(```|~~~)[^\n]*$/gm,"").replace(/^[ \t]{0,3}#{1,6}[ \t]+/gm,"").replace(/^[ \t]*(>[ \t]?)+/gm,"").replace(/^[ \t]*([-*_])([ \t]*\1){2,}[ \t]*$/gm,"").replace(/^[ \t]*[-*+][ \t]+(\[[ xX]\][ \t]+)?/gm,"").replace(/^[ \t]*\|?[ \t]*:?-{3,}:?[ \t]*(\|[ \t]*:?-{3,}:?[ \t]*)*\|?[ \t]*$/gm,"").replace(/^[ \t]*\|(.*?)\|?[ \t]*$/gm,(s,r)=>r.split("|").map(a=>a.trim()).filter(Boolean).join(" · ")).replace(/(`+)([^`]*?)\1/g,(s,r,a)=>n(a.trim())).replace(/`+/g,"").replace(/!\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/\[([^\]]+)\]\([^)]*\)/g,"$1").replace(/<((?:https?|mailto):[^>\s]+)>/g,"$1").replace(/\*\*(?=\S)([^\n]*?\S)\*\*/g,"$1").replace(/~~(?=\S)([^\n]*?\S)~~/g,"$1").replace(/(^|[^\w*])\*(?=[^\s*])([^*\n]*?[^\s*])\*(?![\w*])/g,"$1$2").replace(/(^|\s)(__?)(?=\S)([^\n]*?\S)\2(?=\s|$|[,;:!?)])/g,"$1$3").replace(/\*\*|~~/g,"").replace(/\s+/g," ").trim().replace(/(\d+)/g,(s,r)=>e[Number(r)])}async function Bte(t,e,n){const i=await t();if(n())return[];if(!i.events.length)return e;let s=await ah(Uc(),i.context,0,n);return s=await ah(s,i.events,0,n),s.messages}const vB=[{value:"auto",label:"Auto",description:"Isolate writing tasks; let read-only workers use this checkout."},{value:"worktree",label:"New worktree",description:"Give each task an isolated branch and keep it through review."},{value:"direct",label:"Current checkout",description:"Modify this folder directly, one worker at a time."}];function Ote(t){if(t.state==="cleaned")return t.abandoned?"Abandoned · workspace removed":"Merged · workspace removed";if(t.state==="cleaning")return"Removing workspace";const e=t.delivery;return e?e.dirty?"Uncommitted changes":e.merged?"Merged":e.reviewState?`Review · ${e.reviewState.toLowerCase().replaceAll("_"," ")}`:e.pullRequest?"Pull request open":e.pushed?"Pushed · awaiting review":e.hasCommits?"Committed, not pushed":"No new commits":"Not checked yet"}function Ite(t){if(t.state==="cleaned")return t.abandoned?"quiet":"ok";const e=t.delivery;return e?e.merged?"ok":e.dirty||e.hasCommits&&!e.pushed?"warn":"quiet":"quiet"}const Qo={runs:[],tasks:[],attempts:[],gates:[],messages:[]};function $te(t){const e=new Map(t.runs.map(i=>[i.id,i.coordinatorChatKey])),n=new Map;for(const i of t.attempts){const s=e.get(i.runId);if(!s?.startsWith("chat:")||!i.workerChatKey.startsWith("chat:"))continue;const r=i.workerChatKey.slice(5),a=s.slice(5);r&&a&&r!==a&&n.set(r,a)}return n}function Hd(t,e){return!!t&&(t.startsWith("orch-")||e.has(t))}function MC(t,e){return t.filter(n=>!Hd(n.id,e))}function tk(t,e){if(!t||!e.has(t))return null;const n=new Set([t]);let i=e.get(t);for(;e.has(i);){if(n.has(i))return null;n.add(i),i=e.get(i)}return n.has(i)?null:i}function LC(t,e){if(t.status==="loading")return"work projects loading";if(t.status==="discussion")return"discussion, no tasks yet";if(t.status==="unknown")return"work project unknown";if(t.status==="home")return e(t.homeProjectId??"","Unknown project");const n=t.destinations.map(s=>e(s.projectId,s.projectName)),i=t.unknownTaskCount?`, ${t.unknownTaskCount} ${t.unknownTaskCount===1?"task has":"tasks have"} no confirmed project`:"";return`${n.join(", ")}${i}, ${t.taskCount} ${t.taskCount===1?"task":"tasks"}`}function xB(t,e){const n=t.status==="home"?t.homeProjectId:t.status==="projects"&&t.destinations.length===1?t.destinations[0].projectId:void 0;return n&&e(n)?n:null}function oy(t,e,n,i=!1){const s=`chat:${t.id}`;if(!e)return n&&!n.has(s)?{status:"home",destinations:[],taskCount:0,unknownTaskCount:0,homeProjectId:t.projectId}:{status:i?"unknown":"loading",destinations:[],taskCount:0,unknownTaskCount:0};const r=e.runs.filter(m=>m.coordinatorChatKey===s);if(r.length===0&&n===null)return{status:i?"unknown":"loading",destinations:[],taskCount:0,unknownTaskCount:0};if(!(r.length>0||!!n?.has(s)))return{status:"home",destinations:[],taskCount:0,unknownTaskCount:0,homeProjectId:t.projectId};const c=new Set(r.map(m=>m.id)),u=e.tasks.filter(m=>c.has(m.runId)).sort((m,v)=>v.updatedAt-m.updatedAt||m.id.localeCompare(v.id));if(u.length===0)return{status:"discussion",destinations:[],taskCount:0,unknownTaskCount:0};const d=new Map;let p=0;for(const m of u){if(!m.destination){p+=1;continue}d.has(m.destination.projectId)||d.set(m.destination.projectId,m.destination)}return d.size===0?{status:"unknown",destinations:[],taskCount:u.length,unknownTaskCount:p}:{status:"projects",destinations:[...d.values()],taskCount:u.length,unknownTaskCount:p}}function Pte(t,e,n,i){return t.filter(s=>{const r=oy(s,n,i);return r.status==="home"?r.homeProjectId===e:r.destinations.some(a=>a.projectId===e)}).sort((s,r)=>r.updatedAt-s.updatedAt)}function zte(t,e,n){const i=new Map;for(const s of t){const r=oy(s,e,n),a=r.status==="home"?r.homeProjectId?[r.homeProjectId]:[]:r.destinations.map(c=>c.projectId);for(const c of new Set(a))i.set(c,(i.get(c)??0)+1)}return i}const yB=new Set;function Fte(t,e,n=Qo,i=yB){return Pte(t,e,n,i)}function Hte(t,e=Qo,n=yB){return zte(t,e,n)}const dM=["#f87171","#fb923c","#fbbf24","#a3e635","#34d399","#22d3ee","#60a5fa","#a78bfa","#f472b6","#94a3b8"];function fM(t){const e=t.trim();if(!e)return"";const n=e.startsWith("#")?e.slice(1):e;return/^[0-9a-f]{6}$/i.test(n)?`#${n.toLowerCase()}`:null}function ly(t){const e=t.color?.trim();if(e&&/^#[0-9a-f]{6}$/i.test(e))return e;const n=t.name||t.id;let i=0;for(let s=0;s<n.length;s+=1)i=i*31+n.charCodeAt(s)>>>0;return dM[i%dM.length]}function Wte(t){const e=[...(t.initial??"").trim()].slice(0,2).join("");return e?e.toLocaleUpperCase():[...t.name.trim()][0]?.toLocaleUpperCase()??"?"}function Jc({project:t,size:e="small",className:n=""}){const i=t.icon?.trim(),s={"--project-color":ly(t)};return o.jsx("span",{className:["project-avatar",`is-${e}`,i?"has-icon":"",n].filter(Boolean).join(" "),style:s,"aria-hidden":"true",children:i?o.jsx("img",{className:"project-avatar-image",src:i,alt:""}):o.jsx("span",{className:"project-avatar-text",children:Wte(t)})})}function pM(t,e){const n=new Map(t.map((c,u)=>[c.id,{chat:c,children:[],descendants:[],rank:u}])),i=new Map;for(const c of t){const u=e.get(c.id);if(!u||u===c.id||!n.has(u))continue;let d=u;for(;d&&d!==c.id;)d=i.get(d);d||i.set(c.id,u)}const s=[];for(const c of n.values()){const u=i.get(c.chat.id);u?n.get(u).children.push(c):s.push(c)}const r=c=>n.get(c.chat.id).rank,a=c=>{c.children.forEach(a),c.children.sort((u,d)=>r(u)-r(d)),c.descendants=c.children.flatMap(u=>[u.chat,...u.descendants]);for(const u of c.children)n.get(c.chat.id).rank=Math.min(r(c),r(u))};return s.forEach(a),s.sort((c,u)=>r(c)-r(u))}function nk(t,e){const n=t.tasks.find(s=>s.id===e.taskId);if(!n||n.status!=="completed"||t.attempts.some(s=>s.taskId===n.id&&["preparing","running"].includes(s.status)))return"Complete the task and settle its workers before archiving.";if(t.gates.some(s=>s.runId===n.runId&&s.status==="open"&&(!s.taskId||s.taskId===n.id)))return"Resolve the open decision before archiving.";const i=n.workspace;return i?.abandoned?"Only workers for merged tasks can be archived.":!i||!["retained","cleaned"].includes(i.state)||!i.delivery?.merged||i.delivery.dirty?"Refresh delivery status to verify a clean, merged task before archiving.":null}function ik(t,e,n=!1){const i=new Set(e.attempts.filter(s=>s.archivedAt!=null).map(s=>s.workerChatKey.replace(/^chat:/,"")));return t.filter(s=>i.has(s.id)===n)}const to=t=>["planning","running","waiting"].includes(t.status);function Fm(t,e){if(!e)return Qo;const n=t.runs.filter(s=>s.coordinatorChatKey===e).sort((s,r)=>Number(to(r))-Number(to(s))||r.createdAt-s.createdAt),i=new Set(n.map(s=>s.id));return{runs:n,reports:t.reports,tasks:t.tasks.filter(s=>i.has(s.runId)),attempts:t.attempts.filter(s=>i.has(s.runId)),gates:t.gates.filter(s=>i.has(s.runId)),messages:t.messages.filter(s=>i.has(s.runId)),notifications:t.notifications?.filter(s=>i.has(s.runId))}}function qte(t,e){const n=t.tasks.filter(a=>a.runId===e.id),i=t.gates.filter(a=>a.runId===e.id&&a.status==="open"),s=`${n.filter(a=>a.status==="completed").length}/${n.length} done`;return i.length?`Needs decision · ${s}`:n.some(a=>a.status==="blocked"||a.status==="failed")&&to(e)?`Needs attention · ${s}`:`${e.status.charAt(0).toUpperCase()+e.status.slice(1)} · ${s}`}function Ute(t,e){const n=qte(t,e),i=t.tasks.length,s=t.tasks.filter(r=>r.runId===e.id).length;return t.runs.length<2||i===s?n:`${n} · ${i} ${i===1?"task":"tasks"} in ${t.runs.length} runs`}function Vte(t,e,n){const i=new Set(t.map(a=>a.id)),s=new Map(e.runs.map(a=>[a.id,a])),r=new Set;for(const a of e.tasks){const c=e.attempts.filter(p=>p.taskId===a.id).sort((p,m)=>m.number-p.number),u=c.find(p=>p.id===a.activeAttemptId)??c[0],d=s.get(a.runId)?.coordinatorChatKey.replace(/^chat:/,"");if(!(!u||!d||!i.has(d)||!i.has(u.workerChatKey.replace(/^chat:/,""))))for(const p of c)p.id!==u.id&&r.add(p.workerChatKey.replace(/^chat:/,""))}return ik(t,e).filter(a=>a.id===n||!r.has(a.id))}function _B(t){const e=new Set(t.map(c=>c.id)),n=(c,u)=>c.name.localeCompare(u.name),i=c=>t.filter(u=>u.reportsTo===c).sort(n),s=[],r=new Set,a=(c,u)=>{if(!r.has(c.id)){r.add(c.id),s.push({agent:c,depth:u});for(const d of i(c.id))a(d,u+1)}};for(const c of t.filter(u=>!u.reportsTo||!e.has(u.reportsTo)).sort(n))a(c,0);return s}const sk={working:"Working",needs_you:"Needs you",blocked:"Blocked",stalled:"Stalled",queued:"Queued",idle:"Idle",unknown:"Unknown"},rk=["working","needs_you","blocked","stalled","queued","unknown","idle"],mM=["needs_you","blocked","stalled","working","queued","unknown","idle"],Kte=["planning","running","waiting"];function bB(t,e){const n=t.attempts.filter(i=>i.taskId===e.id);return n.find(i=>i.id===e.activeAttemptId)??[...n].sort((i,s)=>s.number-i.number)[0]}function wB(t,e,n,i,s){if(!e||e.archivedAt||!Kte.includes(e.status)||t.status==="completed"||t.status==="cancelled")return null;if(s>0)return{state:"needs_you",label:"Needs your approval"};if(i)return{state:"needs_you",label:"Waiting on a decision"};if(t.status==="failed")return{state:"blocked",label:"Failed"};if(t.status==="blocked")return{state:"blocked",label:"Blocked"};if(t.status==="pending"||t.status==="ready")return e.planApproval?.status==="pending"?{state:"queued",label:"Waiting for plan approval"}:{state:"queued",label:t.status==="ready"?"Ready to start":"Queued"};if(!n)return{state:"queued",label:"Starting"};const r=n.execution?.state;if(r)switch(r){case"executing":return{state:"working",label:"Executing"};case"waiting_tool":return{state:"working",label:"Running a tool"};case"queued":return{state:"queued",label:"Queued"};case"retrying":return{state:"stalled",label:"Retrying"};case"stalled":return{state:"stalled",label:"Stalled"};case"awaiting_report":return{state:"stalled",label:"Awaiting its report"};case"capacity_blocked":return{state:"blocked",label:"At capacity"};case"blocked":return{state:"blocked",label:"Blocked"};case"failed":return{state:"blocked",label:"Failed"};case"disconnected":return{state:"unknown",label:"Disconnected"};default:return{state:"unknown",label:"Settling"}}switch(n.status){case"preparing":return{state:"queued",label:"Preparing workspace"};case"running":return{state:"working",label:"Working"};case"blocked":return{state:"blocked",label:"Blocked"};case"failed":return{state:"blocked",label:"Failed"};default:return{state:"unknown",label:"Settling"}}}function Gte(t,e){const n=new Map(t.runs.map(s=>[s.id,s])),i=new Set(t.gates.filter(s=>s.status==="open"&&s.taskId).map(s=>s.taskId));return t.tasks.filter(s=>{const r=bB(t,s),a=e(s.id);return wB(s,n.get(s.runId),r,i.has(s.id),a)?.state==="working"}).length}function Yte(t,e,n){return e?{state:"needs_you",label:"Plan awaiting approval"}:n>0?{state:"needs_you",label:"Needs your answer"}:t==="busy"?{state:"working",label:"In conversation"}:t==="unknown"?{state:"unknown",label:"Session open"}:null}const Gv=(t,e)=>t.indexOf(e);function Xte(t){const{team:e,leads:n,snapshot:i,projects:s}=t;if(!e)return[];const r=new Map(s.map(S=>[S.id,S])),a=new Map((i?.runs??[]).map(S=>[S.id,S])),c=new Set((i?.gates??[]).filter(S=>S.status==="open"&&S.taskId).map(S=>S.taskId)),u=new Map,d=new Map,p=(S,C)=>{u.set(S,[...u.get(S)??[],C])},m=(S,C,A,N)=>{const E=d.get(S);(!E||E.at<N)&&d.set(S,{chatKey:C,title:A,at:N})};for(const S of i?.tasks??[]){const C=S.assignee?.id;if(!C||!i)continue;const A=a.get(S.runId),N=bB(i,S);N&&t.chatExists(N.workerChatKey)&&m(C,N.workerChatKey,S.title,N.updatedAt);const E=wB(S,A,N,c.has(S.id),N?t.waitingOn(N.workerChatKey):0);if(!E)continue;const M=S.destination;p(C,{key:`task:${S.id}`,kind:"task",...E,title:S.title,project:M?{id:M.projectId,name:r.get(M.projectId)?.name??M.projectName}:null,chatKey:N?.workerChatKey??null,runId:S.runId,taskId:S.id,at:N?.updatedAt??S.updatedAt})}for(const S of n){if(!t.chatExists(S.chatKey))continue;const C=i?kB(i,S.chatKey):null,A=i?.runs.filter(M=>M.coordinatorChatKey===S.chatKey&&!M.archivedAt).sort((M,L)=>L.updatedAt-M.updatedAt)[0],N=t.chatTitle(S.chatKey)??A?.objective??"Conversation";m(S.leadId,S.chatKey,N,Math.max(S.createdAt,A?.updatedAt??0));const E=Yte(t.leadActivity(S.chatKey),!!C,t.waitingOn(S.chatKey));E&&p(S.leadId,{key:`lead:${S.chatKey}`,kind:"lead",...E,title:N,project:S.crossProject?null:r.get(S.projectId)??null,crossProject:!!S.crossProject,chatKey:S.chatKey,runId:C?.run.id??A?.id,at:A?.updatedAt??S.createdAt})}const v=S=>{const C=[...u.get(S.id)??[]].sort((L,$)=>Gv(mM,L.state)-Gv(mM,$.state)||$.at-L.at),A={};for(const L of C)A[L.state]=(A[L.state]??0)+1;const N=[...C].sort((L,$)=>Gv(rk,L.state)-Gv(rk,$.state))[0],E=N?.state??(i?"idle":"unknown"),M=N?.label??(i?"Nothing in progress":"Work not loaded");return{...S,state:E,stateLabel:M,activities:C,counts:A,recent:d.get(S.id)??null}},x=_B(e).map(({agent:S,depth:C})=>v({id:S.id,name:S.name,avatar:S.avatar,detail:t.providerLabel(S),role:S.role,scope:S.projectId?r.get(S.projectId)??{id:S.projectId,name:"Unknown project"}:null,depth:C,removed:!1})),y=new Set(e.map(S=>S.id)),k=new Map;for(const S of i?.tasks??[])S.assignee&&!y.has(S.assignee.id)&&k.set(S.assignee.id,S.assignee.name);for(const S of n)y.has(S.leadId)||k.set(S.leadId,S.leadName);for(const[S,C]of k)u.get(S)?.length&&x.push(v({id:S,name:C,detail:"No longer registered",role:"",scope:null,depth:0,removed:!0}));return x}function Qte(t){const e=new Map;for(const n of t)e.set(n.state,(e.get(n.state)??0)+1);return rk.filter(n=>e.has(n)).map(n=>({state:n,count:e.get(n)}))}function kB(t,e){if(!e)return null;const n=t.runs.find(i=>i.coordinatorChatKey===e&&i.planApproval?.status==="pending"&&!["stopped","completed","failed"].includes(i.status));return n?{run:n,tasks:t.tasks.filter(i=>i.runId===n.id)}:null}const Zte={top:0,range:null,direction:null,travel:0,floating:!1,hidden:!1},Jte=2,ene=18,tne=12;function nne(t,e){const n=Math.max(0,e.range),i=Math.min(Math.max(0,e.top),n),s=i-t.top;if(i<=Jte)return{top:i,range:n,direction:null,travel:0,floating:!1,hidden:!1};const a=t.floating||i>=Math.max(1,e.menuHeight);if(e.preserve)return{top:i,range:n,direction:null,travel:0,floating:a,hidden:!1};const c=t.range===null?0:n-t.range,u=c!==0&&Math.sign(s)===Math.sign(c)&&Math.abs(s)<=Math.abs(c)+1;if(Math.abs(s)<1||u)return{...t,top:i,range:n,floating:a};const d=s>0?"down":"up",p=t.direction===d?t.travel+Math.abs(s):Math.abs(s);let m=t.hidden;return a?d==="down"&&p>=ene?m=!0:d==="up"&&p>=tne&&(m=!1):m=!1,{top:i,range:n,direction:d,travel:p,floating:a,hidden:m}}const TC=_.createContext([]),SB=_.createContext(()=>null);function RC(t){const e=_.useContext(TC);return t?e.find(n=>n.id===t):void 0}function ine({deleting:t,disabled:e=!1,deleteMs:n,onDelete:i}){const s=t?"Cancel delete":"Delete this chat";return o.jsxs("button",{className:`icon-btn topbar-delete ${t?"is-going":""}`,type:"button","aria-label":s,title:s,disabled:e,onClick:i,children:[t?o.jsx(CB,{ms:n}):o.jsx(sne,{}),o.jsx("span",{className:"topbar-action-label",children:s})]})}function CB({ms:t}){return o.jsxs("svg",{className:"chat-drain",width:"17",height:"17",viewBox:"0 0 16 16","aria-hidden":"true",children:[o.jsx("circle",{className:"chat-drain-track",cx:"8",cy:"8",r:"6.6"}),o.jsx("circle",{className:"chat-drain-arc",cx:"8",cy:"8",r:"6.6",style:{animationDuration:`${t}ms`}}),o.jsx("path",{className:"chat-drain-x",d:"M9.9 6.1 6.1 9.9M6.1 6.1l3.8 3.8"})]})}function sne(){return o.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M4 7h16"}),o.jsx("path",{d:"M9 7V4h6v3"}),o.jsx("path",{d:"m6 7 1 13h10l1-13"}),o.jsx("path",{d:"M10 11v5M14 11v5"})]})}function rne({chat:t,enabled:e,busy:n,getPreviewMessages:i,loadPreview:s,...r}){const a=_.useRef(null),c=_.useRef(void 0),[u,d]=_.useState(!1),p=_.useId(),m=()=>{clearTimeout(c.current),c.current=void 0},v=()=>{m(),d(!1)},x=()=>{m(),e&&(c.current=setTimeout(()=>d(!0),1500))},y=()=>{m(),c.current=setTimeout(()=>d(!1),160)};return _.useEffect(()=>(e||(clearTimeout(c.current),d(!1)),()=>clearTimeout(c.current)),[e]),_.useEffect(()=>{const k=S=>{S.key==="Escape"&&v()};return u&&document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[u]),o.jsxs(o.Fragment,{children:[o.jsx("button",{...r,ref:a,"aria-describedby":u&&e?p:void 0,onPointerEnter:k=>{k.pointerType==="mouse"&&x()},onPointerLeave:y,onFocus:k=>{k.currentTarget.matches(":focus-visible")&&x()},onBlur:v,onClick:k=>{v(),r.onClick?.(k)}}),u&&e&&o.jsx(ane,{id:p,chat:t,anchor:a.current,messages:i?.(t.id),loadPreview:s,busy:n,onEnter:m,onLeave:y,onClose:v},t.id)]})}function ane({id:t,chat:e,anchor:n,messages:i,loadPreview:s,busy:r,onEnter:a,onLeave:c,onClose:u}){const d=_.useRef(null),[p,m]=_.useState(e.messages),[v,x]=_.useState(i===void 0&&s?"loading":"ready"),[y,k]=_.useState({left:0,top:0}),S=i!==void 0;_.useEffect(()=>{if(S||!s){x("ready");return}let A=!1;x("loading");const N=setTimeout(()=>{A=!0,x("error")},8e3);return s(e,()=>A).then(E=>{A||(m(E),x("ready"))}).catch(()=>{A||x("error")}).finally(()=>clearTimeout(N)),()=>{A=!0,clearTimeout(N)}},[e.id,S,s]),_.useLayoutEffect(()=>{const A=()=>{const M=(n.closest(".chat")??n).getBoundingClientRect(),L=d.current.getBoundingClientRect(),$=M.right+12,V=$+L.width<=window.innerWidth-12?$:M.left-L.width-12;k({left:Math.max(12,Math.min(V,window.innerWidth-L.width-12)),top:Math.max(12,Math.min(M.top,window.innerHeight-L.height-12))})};A();const N=new ResizeObserver(A);N.observe(d.current),window.addEventListener("resize",u);const E=M=>{d.current?.contains(M.target)||u()};return document.addEventListener("scroll",E,!0),()=>{N.disconnect(),window.removeEventListener("resize",u),document.removeEventListener("scroll",E,!0)}},[n,u]);const C=Dte(i??p);return Ea.createPortal(o.jsxs("div",{ref:d,id:t,role:"tooltip",className:"chat-preview",style:y,onPointerEnter:a,onPointerLeave:c,children:[o.jsxs("div",{className:"chat-preview-head",children:[o.jsx("strong",{children:e.title}),r&&o.jsx("span",{children:"Working…"})]}),o.jsx("div",{className:"chat-preview-label",children:"Latest conversation"}),C.map(A=>o.jsxs("div",{className:"chat-preview-message",children:[o.jsx("span",{children:A.speaker}),o.jsx("p",{children:A.text})]},A.id)),v==="loading"&&o.jsx("p",{className:"chat-preview-note",children:"Loading latest messages…"}),v==="error"&&o.jsx("p",{className:"chat-preview-note",children:"Preview unavailable. Open the chat to try again."}),v==="ready"&&!C.length&&o.jsx("p",{className:"chat-preview-note",children:"No messages yet."}),o.jsx("div",{className:"chat-preview-foot",children:"Click chat to open · Use ••• for actions"})]}),document.body)}function jB({info:t,projects:e,limit:n=2,taskCount:i=!0}){const s=new Map(e.map(m=>[m.id,m]));if(t.status==="loading")return o.jsx("span",{className:"conversation-projects is-quiet","aria-label":"Work projects loading",children:"Projects loading…"});if(t.status==="discussion")return o.jsx("span",{className:"conversation-projects is-quiet",children:"Discussion"});if(t.status==="unknown")return o.jsx("span",{className:"conversation-projects is-quiet",children:"Project unknown"});if(t.status!=="projects")return null;const r=t.destinations.map(m=>{const v=s.get(m.projectId);return{id:m.projectId,name:v?.name??m.projectName??"Unknown project",style:v?{"--conversation-project-color":ly(v)}:void 0}}),a=r.slice(0,Math.max(1,n)),c=r.length-a.length,u=t.unknownTaskCount,d=LC(t,(m,v)=>s.get(m)?.name??v??"Unknown project"),p=`${t.taskCount} ${t.taskCount===1?"task":"tasks"}`;return o.jsxs("span",{className:"conversation-projects",title:d,"aria-label":`Work projects: ${d}`,children:[o.jsxs("span",{className:"conversation-project-chips","aria-hidden":"true",children:[a.map(m=>o.jsx("span",{className:`conversation-project-chip${m.style?" is-registered":""}`,style:m.style,children:m.name},m.id)),c>0&&o.jsxs("span",{className:"conversation-project-overflow",children:["+",c]}),u>0&&o.jsx("span",{className:"conversation-project-unknown",children:"+?"})]}),i&&o.jsx("span",{className:"conversation-project-task-count","aria-hidden":"true",children:p})]})}function AB({info:t,projects:e}){const n=new Map(e.map(c=>[c.id,c])),i=xB(t,c=>n.has(c)),s=i?n.get(i):void 0;if(s)return o.jsx(Jc,{project:s,size:"medium"});const r=t.status==="projects"&&t.destinations.length>1,a=t.status==="discussion";return o.jsx("span",{className:`project-avatar is-medium is-neutral${r?" is-several":""}${a?" is-discussion":""}`,"aria-hidden":"true",children:r?o.jsx(cne,{}):a?o.jsx(one,{}):t.status==="loading"?null:"?"})}function one(){return o.jsx("svg",{viewBox:"0 0 16 16",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"M3 3.5h10a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H7l-3 2.5v-2.5H3a1 1 0 0 1-1-1v-6a1 1 0 0 1 1-1Z"})})}function lne(t,e){const n=xB(t,s=>e.some(r=>r.id===s)),i=e.find(s=>s.id===n);return i?{"--chat-project-color":ly(i)}:void 0}function cne(){return o.jsxs("svg",{viewBox:"0 0 16 16",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("rect",{x:"2.5",y:"5.5",width:"8",height:"8",rx:"2"}),o.jsx("path",{d:"M5.5 3.5V3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-.5.5h-.5"})]})}function gM({label:t,items:e,open:n,onOpenChange:i,className:s="",disabled:r=!1,icon:a}){const c=_.useRef(null),u=_.useId();return o.jsxs(o.Fragment,{children:[o.jsx("button",{ref:c,className:`sidebar-menu-trigger ${s}`,type:"button","aria-label":t,title:t,"aria-haspopup":"menu","aria-expanded":n,"aria-controls":n?u:void 0,disabled:r,onClick:d=>{d.currentTarget.focus(),i(!n)},onKeyDown:d=>{(d.key==="ArrowDown"||d.key==="ArrowUp")&&(d.preventDefault(),i(!0))},children:a??o.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[o.jsx("circle",{cx:"5",cy:"12",r:"1.7"}),o.jsx("circle",{cx:"12",cy:"12",r:"1.7"}),o.jsx("circle",{cx:"19",cy:"12",r:"1.7"})]})}),n&&!r&&o.jsx(une,{id:u,label:t,anchor:c,items:e,onClose:()=>i(!1)})]})}function une({id:t,label:e,anchor:n,items:i,onClose:s}){const r=_.useRef(null),a=_.useRef(!1),c=_.useRef(s);c.current=s,_.useLayoutEffect(()=>{const d=r.current,p=n.current;p.focus({preventScroll:!0}),d.showModal(),(d.querySelector('button[aria-checked="true"]:not(:disabled)')??d.querySelector("button:not(:disabled)"))?.focus({preventScroll:!0});const m=()=>{const k=p.getBoundingClientRect(),S=window.visualViewport,C=S?.offsetLeft??0,A=S?.offsetTop??0,N=S?.width??window.innerWidth,E=S?.height??window.innerHeight,M=d.getBoundingClientRect();d.style.left=`${Math.max(C+8,Math.min(k.right-M.width,C+N-M.width-8))}px`;const L=k.bottom+4,$=L+M.height<=A+E-8?L:k.top-M.height-4;d.style.top=`${Math.max(A+8,Math.min($,A+E-M.height-8))}px`};m();const v=new ResizeObserver(m);v.observe(d);const x=()=>c.current(),y=k=>{(!(k.target instanceof Node)||!d.contains(k.target))&&x()};return window.addEventListener("resize",x),window.addEventListener("scroll",y,!0),window.visualViewport?.addEventListener("resize",x),()=>{v.disconnect(),d.close(),window.removeEventListener("resize",x),window.removeEventListener("scroll",y,!0),window.visualViewport?.removeEventListener("resize",x)}},[n]);const u=()=>{r.current?.close(),s()};return Ea.createPortal(o.jsx("dialog",{ref:r,id:t,className:"sidebar-dropdown",role:"menu","aria-label":e,onCancel:d=>{d.preventDefault(),u()},onPointerDown:d=>{a.current=d.target===d.currentTarget},onClick:d=>{a.current&&d.target===d.currentTarget&&u(),a.current=!1},onKeyDown:d=>{if(d.key==="Tab"){u();return}if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;d.preventDefault();const p=[...d.currentTarget.querySelectorAll("button:not(:disabled)")],m=p.indexOf(document.activeElement),v=d.key==="Home"?0:d.key==="End"?p.length-1:(m+(d.key==="ArrowDown"?1:-1)+p.length)%p.length;p[v]?.focus()},children:i.map(d=>o.jsxs("button",{type:"button",tabIndex:-1,role:d.checked===void 0?"menuitem":"menuitemradio","aria-checked":d.checked,className:[d.danger?"is-danger":"",d.checked?"is-checked":"",d.separator?"has-separator":""].filter(Boolean).join(" ")||void 0,disabled:d.disabled,title:d.title,onClick:()=>{d.keepOpen||u(),d.onSelect()},children:[d.icon,o.jsx("span",{children:d.label})]},d.id))}),document.body)}function hne(t){const e=new Set(t.map(r=>r.id)),n=new Set,i=[];let s=t;for(;s.length;){const r=s.filter(a=>a.dependsOn.every(c=>!e.has(c)||n.has(c)));if(!r.length){i.push({tasks:s,blocked:!0});break}i.push({tasks:r,blocked:!1});for(const a of r)n.add(a.id);s=s.filter(a=>!n.has(a.id))}return i}function dne(t){return new Map(t.flatMap(e=>e.tasks).map((e,n)=>[e.id,n+1]))}function fne(t){return t.assignee?{agent:t.worker?.agent,label:t.assignee.name}:t.worker?{agent:t.worker.agent,label:t.worker.model??""}:{label:"Chosen at dispatch"}}function NB(t,e,n){const i=t.destination?.repository??e.rootPath;return{project:t.destination?.projectName??n?.(e.workspaceId)??"This project",repository:mne(i),path:i}}function pne(t){return t.filter(e=>!e.parentTaskId&&!e.approvedAt&&e.status!=="cancelled").map(e=>e.id)}function EB(t){return t.filter(e=>e.status!=="cancelled"||!!e.approvedAt)}function mne(t){return t.split(/[\\/]/).filter(Boolean).pop()??t}function MB(t){const e=new Map;for(const n of t){if(!n?.id)continue;const i=n.batch||n.id;n.status===void 0||n.status==="pending"?e.set(i,"question"):n.status==="failed"&&!e.has(i)&&e.set(i,"delivery")}return e}const gne=new Set(["planning","running","waiting"]),vM={permission:0,safety:1,outage:2,question:3,delivery:4,gate:5,plan:6},Fb=t=>t?.startsWith("chat:")&&t.slice(5)||null;function vne(t){const{orchestration:e,parents:n}=t,i=new Map,s=p=>{i.has(p.key)||i.set(p.key,p)},r=p=>tk(p,n)??p,a=new Map;for(const p of e.attempts){const m=Fb(p.workerChatKey),v=m?a.get(m):void 0;m&&(!v||p.number>v.number)&&a.set(m,{runId:p.runId,taskId:p.taskId,number:p.number})}const c=(p,m,v,x=p)=>{const y=r(v),k=a.get(v);s({key:`${x}:${m}`,kind:p,rowId:y,openChatId:k?y:v,surface:"chat",runId:k?.runId,taskId:k?.taskId})},u=(p,m)=>{for(const[v,x]of Object.entries(m??{}))for(const y of x??[])y?.id&&c(p==="safety"&&y.kind==="outage"?"outage":p,y.id,v,p)};u("permission",t.asks),u("safety",t.safetyBlocks);for(const[p,m]of Object.entries(t.questions??{}))if(r(p)===p)for(const[v,x]of MB(m??[]))c(x,v,p);const d=new Map(e.runs.map(p=>[p.id,p]));for(const p of e.gates){const m=d.get(p.runId),v=Fb(m?.coordinatorChatKey);p.status!=="open"||!m||!v||m.archivedAt!=null||s({key:`gate:${p.id}`,kind:"gate",rowId:r(v),openChatId:v,surface:"run",runId:m.id,taskId:p.taskId})}for(const p of e.runs){const m=Fb(p.coordinatorChatKey);!m||p.planApproval?.status!=="pending"||!gne.has(p.status)||p.archivedAt!=null||EB(e.tasks.filter(v=>v.runId===p.id)).length!==0&&s({key:`plan:${p.id}:${p.planApproval.revision??0}`,kind:"plan",rowId:r(m),openChatId:m,surface:"chat",runId:p.id})}return[...i.values()].sort((p,m)=>vM[p.kind]-vM[m.kind])}function xne(t){const e=new Map;for(const n of t){const i=e.get(n.rowId);i?i.push(n):e.set(n.rowId,[n])}return e}function yne(t){const e=new Map;for(const n of t){if(!n.taskId)continue;const i=e.get(n.taskId);i?i.push(n):e.set(n.taskId,[n])}return e}const _ne={permission:"Permission needed",safety:"Review needed",outage:"Safety check was down",question:"Answer needed",delivery:"Delivery failed",gate:"Decision needed",plan:"Plan approval"},bne={permission:["permission request","permission requests"],safety:["blocked action to review","blocked actions to review"],outage:["safety check outage","safety check outages"],question:["question to answer","questions to answer"],delivery:["failed answer delivery","failed answer deliveries"],gate:["decision","decisions"],plan:["plan to approve","plans to approve"]};function cy(t){return t.length===0?"":t.length===1?_ne[t[0].kind]:`Action needed · ${t.length}`}function wne(t){const e=new Map;for(const n of t)e.set(n.kind,(e.get(n.kind)??0)+1);return[...e].map(([n,i])=>`${i} ${bne[n][i===1?0:1]}`).join(", ")}function kne(t){return`[data-pending-keys~="${t.replace(/["\\]/g,"\\$&")}"]`}const xM=[],Sne={forRow:()=>xM,forTask:()=>xM,reveal:()=>{}},LB=_.createContext(Sne);function rg(){return _.useContext(LB)}function uy({actions:t,subject:e,className:n=""}){const{reveal:i}=rg();if(t.length===0)return null;const s=cy(t),r=wne(t),a=t.length>1;return o.jsxs("button",{type:"button",className:`pending-action-badge${n?` ${n}`:""}`,"data-kind":a?"several":t[0].kind,"aria-label":`${s} for ${e}: ${r}. Show ${a?"the first one":"it"}`,title:`${r}. Click to show ${a?"the first one":"it"}.`,onClick:c=>{c.stopPropagation(),i(t[0])},children:[o.jsx(jne,{}),o.jsx("span",{className:"pending-action-text",children:s})]})}function Cne(t,e=document){const n=[...e.querySelectorAll(kne(t))].map(s=>s.classList.contains("pending-target")?s.firstElementChild:s).find(s=>!!s&&s.getClientRects().length>0);if(!n)return!1;const i=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;return n.scrollIntoView?.({block:"center",behavior:i?"auto":"smooth"}),n.tabIndex<0&&!n.hasAttribute("tabindex")&&n.setAttribute("tabindex","-1"),n.focus({preventScroll:!0}),n.classList.remove("pending-revealed"),n.offsetWidth,n.classList.add("pending-revealed"),window.setTimeout(()=>n.classList.remove("pending-revealed"),1700),!0}function jne(){return o.jsxs("svg",{className:"pending-action-icon",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"12",cy:"12",r:"9"}),o.jsx("path",{d:"M12 7.5v5.5"}),o.jsx("path",{d:"M12 16.5h.01"})]})}const Hb=new Set,Ane=new Map,TB="octiq.chat.collapsed-agents",RB="octiq.chat.filter";function Nne(){const t=ar(RB);return uz(t)?t:"active"}function Ene(){try{const t=JSON.parse(ar(TB)??"[]");return new Set(Array.isArray(t)?t.filter(e=>typeof e=="string"):[])}catch{return new Set}}function Mne({orchestration:t=Qo,ledgerSnapshot:e,ledgerUnavailable:n=!1,coordinatorChatKeys:i=Hb,projects:s,shelved:r,deletedCount:a=0,onShowDeleted:c,conversations:u,currentConversation:d,running:p,busy:m,deleting:v=Hb,leaving:x=Hb,deleteMs:y=2e3,onPickConversation:k,getPreviewMessages:S,loadPreview:C,onNewChat:A,newLabel:N="New task",allowEmptyCreate:E=!0,onDelete:M,onPin:L,onToggleDone:$,onRename:V,onArchiveWorker:X,branches:D={},chatParents:Q=Ane,onResize:P,onCollapse:z,onSearch:H,onSettings:W,onAgents:F,onProjects:Y,onPullRequests:J,activeView:te=null}){const I=_.useMemo(()=>MC(u,Q),[u,Q]),[U,Z]=_.useState(Ene),[R,K]=_.useState(Nne),[O,ie]=_.useState(()=>new Set),[re,ve]=_.useState(!1),[le,Re]=_.useState(null),[De,Ke]=_.useState(null),[xe,Te]=_.useState(!1),[vt,Bt]=_.useState(!1),[Ot,At]=_.useState(null),[nn,ke]=_.useState(Zte),Je=_.useContext(SB),at=rg(),it=_.useRef(null),We=_.useRef(void 0),pn=_.useRef({x:0,y:0}),he=_.useRef(!1),Me=_.useRef(null),ze=_.useRef(new Set(I.map(ye=>ye.id))),ut=[...s,...r],de=e===void 0?t:e,st=new Map(ut.map(ye=>[ye.id,ye])),Tn=new Map(I.map(ye=>[ye.id,ye])),qt=ik(I,t,!0),on=ik(I,t);_.useEffect(()=>{ie(ye=>{const jt=new Set(ye);for(const Yt of ye){const Zn=Tn.get(Yt);(!Zn||(R==="active"?!Pc(Zn):R!=="done"||Pc(Zn)))&&jt.delete(Yt)}return jt.size===ye.size?ye:jt})},[I,R]);const An=xe?qt:$1(on,R,d,O),kt=_.useMemo(()=>Vte(I,t,d),[I,t,d]),bn=_.useMemo(()=>pM($1(kt,R,d,O),Q),[kt,Q,d,R,O]),Nn=_.useMemo(()=>pM(kt,Q),[kt,Q]),Ss=ye=>!!ye.chat.pinned||ye.descendants.some(jt=>jt.pinned),ti=xe?[]:Nn.filter(Ss),cs=xe?qt.map(ye=>({chat:ye,children:[],descendants:[]})):bn.filter(ye=>!Ss(ye)),Qn=new Set;let xt=d?Q.get(d):void 0;for(;xt&&!Qn.has(xt);)Qn.add(xt),xt=Q.get(xt);const Ft=JSON.stringify([...Qn]);_.useEffect(()=>{const ye=JSON.parse(Ft);Z(jt=>ye.some(Yt=>jt.has(Yt))?new Set([...jt].filter(Yt=>!ye.includes(Yt))):jt)},[d,Ft]),_.useEffect(()=>{Ln(TB,JSON.stringify([...U]))},[U]),_.useEffect(()=>{Ln(RB,R)},[R]),_.useEffect(()=>{ze.current=new Set(I.map(ye=>ye.id))},[I]),_.useEffect(()=>()=>clearTimeout(We.current),[]);const On=()=>clearTimeout(We.current),_e=async(ye,jt)=>{if(!(!X||vt)){Bt(!0),At(null);try{await X(ye,jt)}catch(Yt){At(Yt instanceof Error?Yt.message:String(Yt))}finally{Bt(!1)}}},Ye=ye=>{ie(new Set),K(ye)},St=ye=>{const jt=Pc(ye),Yt=R==="active"&&!jt||R==="done"&&jt;ie(Zn=>{const ni=new Set(Zn);return Yt?ni.add(ye.id):ni.delete(ye.id),ni}),$(ye.id)},ot=({chat:ye,children:jt,descendants:Yt})=>{const Zn=!U.has(ye.id),ni=Yt.filter(Qe=>m.has(Qe.id)).length,wn=Yt.filter(Qe=>q0(Qe,d)).length,Ht=`chat-agents-${ye.id}`,Tt=Tn.get(Q.get(ye.id)??""),ii=v.has(ye.id),Rt=x.has(ye.id),gt=q0(ye,d),Xi=Pc(ye),be=st.get(ye.projectId),Fe=oy(ye,de,i,n),dt=LC(Fe,(Qe,Oi)=>st.get(Qe)?.name??Oi??"Unknown project"),Pt=lne(Fe,ut),mn=be?.name??"Unknown project",ln=t.attempts.find(Qe=>Qe.workerChatKey===`chat:${ye.id}`),gn=ln&&t.tasks.find(Qe=>Qe.id===ln.taskId),Vs=ln?.archivedAt!=null,Ks=ln&&!Vs?nk(t,ln):null,Ni=Fm(t,`chat:${ye.id}`),Qi=Ni.runs.find(Qe=>Qe.archivedAt==null)??Ni.runs[0],Gs=!xe&&Ni.runs.length>0,Cs=new Set(Ni.attempts.map(Qe=>Qe.workerChatKey)),Bi=Gs?jt.filter(Qe=>!Cs.has(`chat:${Qe.chat.id}`)):jt,Rr=Bi.length>0,Ta=Gs&&Cs.has(`chat:${d}`),me=Gte(Ni,Qe=>at.forTask(Qe).length),qe=gn?`${gn.title} · ${Vs?"archived":ln?.status}`:Qi?Ute(Ni,Qi):null,ft=Fe.status==="home"?ln?.branch||(Tt?"":D[ye.projectId]):"",kn=ft?`${mn} | ${ft}`:mn,cn=Mc(ye.modelId??null),bi=Je(`chat:${ye.id}`),Ys=ek(S?.(ye.id)??ye.messages),Xs=xe?[]:at.forRow(ye.id),su=ii?"Deleting…":Ys?.text??ye.latestResponse??(m.has(ye.id)?"Working…":"No response yet");return o.jsxs(Rne,{entering:!ze.current.has(ye.id),leaving:Rt,children:[o.jsxs("div",{className:["chat",ye.id===d?"is-on":"",p.has(ye.id)?"is-live":"",m.has(ye.id)?"is-busy":"",me>0?"is-tasks-running":"",ii?"is-going":"",Rt?"is-leaving":"",ye.pinned?"is-pinned":"",le===ye.id?"is-renaming":"",gt?"is-unread":"",Xi?"is-done":"",Ta?"is-worker-on":"",Xs.length?"has-pending":""].filter(Boolean).join(" "),style:Pt,children:[le===ye.id?o.jsx("form",{className:"chat-rename",onSubmit:Qe=>{Qe.preventDefault();const Oi=Qe.currentTarget.elements.namedItem("chat-title");Oi instanceof HTMLInputElement&&Oi.value.trim()&&V(ye.id,Oi.value),Re(null)},children:o.jsx("input",{name:"chat-title",className:"chat-rename-input",defaultValue:ye.title,"aria-label":"Chat title",maxLength:48,autoFocus:!0,onFocus:Qe=>Qe.currentTarget.select(),onBlur:Qe=>{Qe.currentTarget.value.trim()&&V(ye.id,Qe.currentTarget.value),Re(null)},onKeyDown:Qe=>{Qe.key==="Escape"&&(Qe.preventDefault(),Re(null))}})}):o.jsx(rne,{chat:ye,enabled:!ii&&!Rt&&!De,busy:m.has(ye.id),getPreviewMessages:S,loadPreview:C,className:"chat-btn",type:"button","aria-label":`${gt?"Unread, ":""}${ye.title}, ${dt}${ft?`, branch ${ft}`:""}${bi?`, with ${bi.name}`:cn?`, ${cn.name} ${cn.model}`:""}${m.has(ye.id)?", working":p.has(ye.id)?", session running":""}${me>0?`, ${me} ${me===1?"task":"tasks"} running`:""}${Xs.length?`, ${cy(Xs)}`:""}${Xi?", done":""}${ye.pinned?", pinned":""}`,disabled:Rt,"aria-current":ye.id===d?"page":void 0,"aria-description":`${Tt?`Agent chat under ${Tt.title}. `:""}Hover to preview. Hold for chat actions.`,onPointerDown:Qe=>{On(),he.current=!1,!(Qe.pointerType==="mouse"||ii||Rt||!window.matchMedia("(max-width: 859.98px), (pointer: coarse)").matches)&&(pn.current={x:Qe.clientX,y:Qe.clientY},We.current=setTimeout(()=>{he.current=!0,Ke(ye.id)},500))},onPointerMove:Qe=>{Math.hypot(Qe.clientX-pn.current.x,Qe.clientY-pn.current.y)>10&&On()},onPointerUp:On,onPointerCancel:On,onContextMenu:Qe=>{window.matchMedia("(max-width: 859.98px), (pointer: coarse)").matches&&(Qe.preventDefault(),On(),!ii&&!Rt&&Ke(ye.id))},onClick:()=>{if(he.current){he.current=!1;return}k(ye)},children:o.jsxs("span",{className:"chat-summary",children:[o.jsxs("span",{className:"chat-heading",children:[gt&&o.jsx("span",{className:"chat-unread-dot","aria-hidden":"true"}),o.jsx("span",{className:"chat-title",children:ye.title}),o.jsx("time",{className:"chat-time",dateTime:new Date(ye.updatedAt).toISOString(),title:new Date(ye.updatedAt).toLocaleString(),children:DC(ye.updatedAt)})]}),o.jsx("span",{className:"chat-snippet",children:EC(su)}),qe&&o.jsx("span",{className:"chat-workflow-status",title:qe,children:qe}),o.jsxs("span",{className:"chat-meta",children:[Fe.status==="home"?o.jsx("span",{className:"chat-project",children:o.jsx("span",{className:"chat-project-name",title:kn,children:kn})}):o.jsx(jB,{info:Fe,projects:ut,taskCount:!Qi}),bi?o.jsxs("span",{className:"chat-model chat-persona",title:`${bi.name}${cn?` · ${cn.name} ${cn.model}`:""}`,children:[o.jsx(ws,{name:bi.name,avatar:bi.avatar,id:bi.id??bi.name,size:14,removed:bi.removed,decorative:!0}),o.jsx("span",{children:bi.name})]}):cn&&o.jsxs("span",{className:"chat-model",title:`Active model: ${cn.name} · ${cn.model}`,children:[o.jsx(af,{agent:cn.agent,size:10}),o.jsx("span",{children:cn.model})]})]})]})}),le!==ye.id&&Xs.length>0&&o.jsx(uy,{className:"chat-pending",actions:Xs,subject:ye.title}),o.jsxs("button",{className:"chat-badge",type:"button","aria-pressed":Xi,title:Xi?"Double-click or double-tap to mark not done":"Double-click or double-tap to mark done","aria-label":`${Xi?"Mark not done":"Mark done"}: ${ye.title}`,"aria-description":"Double-click or double-tap. With a keyboard, press Enter or Space.",disabled:ii||Rt,onBlur:()=>{Me.current=null},onClick:Qe=>{Qe.stopPropagation();const Oi=Me.current;Me.current=null,Qe.detail===0||Oi?.chatId===ye.id&&Qe.timeStamp-Oi.at<=500?St(ye):Me.current={chatId:ye.id,at:Qe.timeStamp}},children:[o.jsx(AB,{info:Fe,projects:ut}),o.jsxs("svg",{className:"chat-badge-ring",viewBox:"0 0 32 32","aria-hidden":"true",children:[o.jsx("rect",{className:"chat-badge-track",x:"1",y:"1",width:"30",height:"30",rx:"8"}),o.jsx("rect",{className:"chat-badge-snake",x:"1",y:"1",width:"30",height:"30",rx:"8"}),o.jsx("rect",{className:"chat-badge-pellet",x:"1",y:"1",width:"30",height:"30",rx:"8"})]}),o.jsx("span",{className:"chat-badge-tick","aria-hidden":"true",children:o.jsx(Lne,{done:Xi})}),Xi&&o.jsx("span",{className:"chat-badge-check","aria-hidden":"true",children:o.jsx(Tne,{})}),ye.pinned&&o.jsx("span",{className:"chat-badge-pin","aria-hidden":"true",children:o.jsx(bM,{})})]}),le!==ye.id&&o.jsx(gM,{className:"chat-actions-trigger",label:`Actions for ${ye.title}`,open:De===ye.id,onOpenChange:Qe=>Ke(Qe?ye.id:null),disabled:Rt,icon:ii?o.jsx(CB,{ms:y}):void 0,items:[{id:"rename",label:"Rename chat",icon:o.jsx(Hne,{}),disabled:ii,onSelect:()=>Re(ye.id)},{id:"pin",label:ye.pinned?"Unpin chat":"Pin chat",icon:o.jsx(bM,{}),disabled:ii,onSelect:()=>L(ye.id)},...ln&&X?[{id:"archive",label:Vs?"Restore worker":"Archive worker",icon:o.jsx(yM,{}),disabled:vt||!!Ks||!Vs&&m.has(ye.id),title:Ks??(Vs?"Return this worker to the chat list.":"Hide this worker; its chat and task history are kept."),onSelect:()=>{_e(ln.id,!Vs)}}]:[],...Hd(ye.id,Q)?[]:[{id:"delete",label:ii?"Cancel delete":"Delete chat",icon:o.jsx(_M,{}),danger:!0,keepOpen:!ii,onSelect:()=>M(ye.id)}]]}),Rr&&o.jsxs("button",{className:"chat-children-toggle",type:"button","aria-label":`${Zn?"Collapse":"Expand"} agent chats for ${ye.title}`,"aria-expanded":Zn,"aria-controls":Ht,disabled:Rt,onClick:()=>Z(Qe=>{const Oi=new Set(Qe);return Oi.has(ye.id)?Oi.delete(ye.id):Oi.add(ye.id),Oi}),children:[o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"m9 5 7 7-7 7"})}),o.jsx("span",{children:`${Bi.length} ${Bi.length===1?"agent":"agents"}`}),ni>0&&o.jsxs("span",{className:"chat-children-working",children:[ni," working"]}),wn>0&&o.jsxs("span",{className:"chat-children-unread",children:[wn," unread"]})]})]}),Rr&&o.jsx("div",{id:Ht,hidden:!Zn,children:Zn&&Bi.length>0&&o.jsx("ul",{className:"chat-children","aria-label":`Agent chats for ${ye.title}`,children:Bi.map(ot)})})]},ye.id)},In=()=>{Te(!1),ie(new Set)},ht=[...dz(on,R).map(ye=>({id:ye.filter,label:ye.label,checked:!xe&&ye.checked,onSelect:()=>{In(),Ye(ye.filter)}})),...qt.length||xe?[{id:"archived",label:`Archived workers (${qt.length})`,icon:o.jsx(yM,{}),checked:xe,separator:!0,onSelect:()=>{Te(!0),ie(new Set)}}]:[],...a&&c?[{id:"trash",label:`Deleted chats (${a})`,icon:o.jsx(_M,{}),separator:!(qt.length||xe),onSelect:c}]:[]],Et=xe?"Archived":P1[R];return o.jsxs("nav",{className:"sidebar task-sidebar","aria-label":"Chats",children:[o.jsxs("div",{className:"task-chat-scroll",onScroll:ye=>{const jt=ye.currentTarget,Yt=!!it.current?.contains(document.activeElement),Zn={top:jt.scrollTop,range:jt.scrollHeight-jt.clientHeight,menuHeight:it.current?.offsetHeight??0,preserve:Yt};ke(ni=>nne(ni,Zn))},children:[o.jsxs("div",{ref:it,id:"chats-navigation",className:`sidebar-toolbar${nn.floating?" is-floating":""}${nn.hidden?" is-hidden":""}`,onFocusCapture:()=>ke(ye=>({...ye,hidden:!1,direction:null,travel:0})),children:[o.jsxs("div",{className:"sidebar-head",children:[o.jsx("img",{className:"sidebar-logo",src:"./icon-192.png",alt:"","aria-hidden":"true"}),o.jsxs("span",{className:"sidebar-title",children:["OctiqFlow ",o.jsxs("span",{className:"sidebar-version",children:["v","0.2.12"]})]}),z&&o.jsx("button",{className:"sidebar-collapse",type:"button",onClick:z,"aria-label":"Hide sidebar",title:"Hide sidebar",children:o.jsx(Bne,{})})]}),o.jsxs("ul",{className:"sidebar-places","aria-label":"App",children:[o.jsx("li",{children:o.jsxs("button",{className:"sidebar-place sidebar-new-chat",type:"button",onClick:A,children:[o.jsx(One,{}),o.jsx("span",{children:N})]})}),H&&o.jsx("li",{children:o.jsxs("button",{className:"sidebar-place",type:"button",onClick:H,"aria-current":te==="search"?"page":void 0,children:[o.jsx(Dne,{}),o.jsx("span",{children:"Search chats"})]})}),Y&&o.jsx("li",{children:o.jsxs("button",{className:"sidebar-place",type:"button",onClick:Y,"aria-current":te==="projects"?"page":void 0,children:[o.jsx(Fne,{}),o.jsx("span",{children:"Projects"})]})}),F&&o.jsx("li",{children:o.jsxs("button",{className:"sidebar-place",type:"button",onClick:F,"aria-current":te==="agents"?"page":void 0,children:[o.jsx(Pne,{}),o.jsx("span",{children:"Agents"})]})}),J&&o.jsx("li",{children:o.jsxs("button",{className:"sidebar-place",type:"button",onClick:J,"aria-current":te==="pulls"?"page":void 0,children:[o.jsx(zne,{}),o.jsx("span",{children:"Pull requests"})]})}),W&&o.jsx("li",{children:o.jsxs("button",{className:"sidebar-place",type:"button",onClick:W,"aria-current":te==="settings"?"page":void 0,children:[o.jsx($ne,{}),o.jsx("span",{children:"Settings"})]})})]})]}),Ot&&o.jsxs("div",{className:"sidebar-archive-error",role:"alert",children:[Ot,o.jsx("button",{type:"button",onClick:()=>At(null),children:"Dismiss"})]}),I.length>0||xe?o.jsxs("div",{className:"task-chat-content",children:[ti.length>0&&o.jsxs("section",{className:"sidebar-chat-section","aria-labelledby":"sidebar-pinned-heading",children:[o.jsx("h2",{id:"sidebar-pinned-heading",className:"sidebar-section-heading",children:"Pinned"}),o.jsx("ul",{className:"chat-list task-chat-list",children:ti.map(ot)})]}),o.jsxs("section",{className:"sidebar-chat-section","aria-labelledby":"sidebar-recent-heading",children:[o.jsxs("div",{className:"sidebar-section-head",children:[o.jsx("h2",{id:"sidebar-recent-heading",className:"sidebar-section-heading",children:xe?"Archived workers":"Recent"}),o.jsx(gM,{className:"sidebar-filter-trigger",label:`Show chats: ${Et}`,open:re,onOpenChange:ve,icon:o.jsxs(o.Fragment,{children:[o.jsx("span",{children:Et}),o.jsx(Ine,{})]}),items:ht})]}),cs.length>0?o.jsx("ul",{className:"chat-list task-chat-list",children:cs.map(ot)}):En()]})]}):o.jsxs("div",{className:"sidebar-empty",children:[o.jsx("span",{children:"No chats yet"}),E&&o.jsx("button",{type:"button",onClick:A,children:"Start your first chat"})]})]}),P&&o.jsx("span",{className:"nav-resizer",onPointerDown:P,role:"separator","aria-orientation":"vertical","aria-label":"Resize the chat column"})]});function En(){return xe?o.jsxs("div",{className:"sidebar-empty",role:"status",children:[o.jsx("span",{children:"No archived workers."}),o.jsx("button",{type:"button",onClick:In,children:"Show active chats"})]}):R!=="active"?o.jsxs("div",{className:"sidebar-empty",role:"status",children:[o.jsx("span",{children:R==="done"?"No chats are ticked off.":"Every chat is pinned."}),o.jsx("button",{type:"button",onClick:()=>Ye("active"),children:"Show active chats"})]}):on.some(jt=>Pc(jt)&&!jt.pinned)&&!An.some(jt=>!jt.pinned)?o.jsxs("div",{className:"sidebar-empty",role:"status",children:[o.jsx("span",{children:"Every chat is ticked off."}),o.jsx("button",{type:"button",onClick:()=>Ye("done"),children:"Show done chats"})]}):o.jsx("div",{className:"sidebar-empty",role:"status",children:o.jsx("span",{children:ti.length>0?"Every active chat is pinned.":"No active chats."})})}}function Lne({done:t}){return o.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:t?2.4:1.8,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"12",cy:"12",r:"9"}),t&&o.jsx("path",{d:"m8 12 2.8 2.8L16 9.6"})]})}function Tne(){return o.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"m5 12.5 4.5 4.5L19 7"})})}function DC(t){const e=new Date(t),n=new Date;return e.toDateString()===n.toDateString()?e.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):(n.setDate(n.getDate()-1),e.toDateString()===n.toDateString()?"Yesterday":e.toLocaleDateString([],{month:"short",day:"numeric",...e.getFullYear()!==n.getFullYear()?{year:"numeric"}:{}}))}function Rne({entering:t,leaving:e,children:n}){const[i,s]=_.useState(()=>t&&!(typeof window<"u"&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches));return _.useEffect(()=>{if(!i)return;const r=requestAnimationFrame(()=>s(!1));return()=>cancelAnimationFrame(r)},[i]),o.jsx("li",{className:["chat-row",i?"is-entering":"",e?"is-leaving":""].filter(Boolean).join(" "),children:o.jsx("div",{className:"chat-row-content",children:n})})}function Dne(){return o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"11",cy:"11",r:"7"}),o.jsx("path",{d:"m20 20-4-4"})]})}function Bne(){return o.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),o.jsx("path",{d:"M9 4v16M15 10l-2 2 2 2"})]})}function One(){return o.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M20 12.5V18a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h5.5"}),o.jsx("path",{d:"m12 12 7.5-7.5a2.12 2.12 0 0 1 3 3L15 15l-4 1 1-4Z"})]})}function yM(){return o.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M4 7h16"}),o.jsx("path",{d:"M6 7v12h12V7"}),o.jsx("path",{d:"M3 4h18v3H3z"}),o.jsx("path",{d:"M10 11h4"})]})}function _M(){return o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M3 6h18"}),o.jsx("path",{d:"M8 6V4h8v2"}),o.jsx("path",{d:"m6 6 1 14h10l1-14"}),o.jsx("path",{d:"M10 10v6M14 10v6"})]})}function bM(){return o.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M12 17v5"}),o.jsx("path",{d:"M5 17h14v-1.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V6h1a2 2 0 0 0 0-4H8a2 2 0 0 0 0 4h1v4.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24Z"})]})}function Ine(){return o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"m6 9 6 6 6-6"})})}function $ne(){return o.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"12",cy:"12",r:"3"}),o.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.6 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.6a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function Pne(){return o.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("rect",{x:"9",y:"3",width:"6",height:"5",rx:"1"}),o.jsx("rect",{x:"3",y:"16",width:"6",height:"5",rx:"1"}),o.jsx("rect",{x:"15",y:"16",width:"6",height:"5",rx:"1"}),o.jsx("path",{d:"M12 8v4M6 16v-2h12v2"})]})}function zne(){return o.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"6",cy:"5",r:"2"}),o.jsx("circle",{cx:"18",cy:"7",r:"2"}),o.jsx("circle",{cx:"6",cy:"19",r:"2"}),o.jsx("path",{d:"M6 7v10M8 5h4a6 6 0 0 1 6 6v-2"})]})}function Fne(){return o.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"})})}function Hne(){return o.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M12 20h9"}),o.jsx("path",{d:"M16.5 3.5a2.1 2.1 0 0 1 3 3L8 18l-4 1 1-4Z"})]})}const DB=_.createContext(null);function ak(t){return _.useContext(DB)?.[t]??null}function kh({title:t,back:e,actions:n,root:i=!1,className:s}){const r=ak("heading"),a=ak("actions"),c=o.jsxs(o.Fragment,{children:[e&&o.jsxs("button",{type:"button",className:`workspace-back${i?" is-root":""}`,onClick:e.onClick,"aria-label":e.ariaLabel??`Back to ${e.label}`,title:e.ariaLabel??`Back to ${e.label}`,children:[o.jsx(Wne,{}),o.jsx("span",{children:e.label})]}),o.jsx("div",{className:"workspace-heading",children:t})]}),u=n?o.jsx("div",{className:"workspace-actions",children:n}):null;return r?o.jsxs(o.Fragment,{children:[Ea.createPortal(c,r),n&&(a?Ea.createPortal(u,a):o.jsx("div",{className:"workspace-actions is-inline",children:n}))]}):o.jsxs("header",{className:`workspace-header${s?` ${s}`:""}`,children:[c,u]})}function Wne(){return o.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"m15 18-6-6 6-6"})})}function qne({projects:t,shelved:e,conversations:n,selectedProjectId:i,busy:s,chatParents:r,ledgerSnapshot:a=Qo,coordinatorChatKeys:c=new Set,allowNewTask:u=!0,onSelectProject:d,onOpenChat:p,onNewTask:m,onNewProject:v,onProjectSettings:x,onClose:y,onShowShelved:k,onRestoreProject:S}){const C=rg(),A=_.useRef(null),N=_.useRef(!0),[E,M]=_.useState(!1),[L,$]=_.useState(null);_.useEffect(()=>{if(N.current){N.current=!1;return}A.current?.focus({preventScroll:!0}),$(null)},[i]);const V=MC(n,r),X=[...t,...e],D=i===null?null:X.find(z=>z.id===i)??null;if(i!==null){const z=D?Fte(V,D.id,a,c??new Set):[],H=!!D&&e.some(W=>W.id===D.id);return o.jsxs("section",{className:"projects-page","aria-label":D?`${D.name} tasks`:"Project",children:[o.jsx(kh,{back:{label:"Projects",ariaLabel:"Back to projects",onClick:()=>d(null)},title:o.jsxs(o.Fragment,{children:[D&&o.jsx(Jc,{project:D,size:"small"}),o.jsx("h1",{ref:A,tabIndex:-1,children:D?.name??"Project unavailable"})]}),actions:D&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"projects-page-secondary",onClick:()=>x(D.id),children:"Project settings"}),H&&S&&o.jsx("button",{type:"button",className:"projects-page-primary",disabled:E,onClick:async()=>{M(!0),$(null);try{await S(D.id)}catch(W){$(W instanceof Error?W.message:String(W))}finally{M(!1)}},children:o.jsx("span",{children:E?"Restoring…":"Restore project"})}),u&&!H&&o.jsxs("button",{type:"button",className:"projects-page-primary",onClick:()=>m(D.id),children:[o.jsx(wM,{}),o.jsx("span",{children:"New task"})]})]})}),L&&o.jsx("p",{className:"projects-page-error",role:"alert",children:L}),o.jsxs("div",{className:"projects-page-body",children:[D&&(D.primary_path||H)&&o.jsxs("p",{className:"projects-page-meta",title:D.primary_path,children:[D.primary_path??"Shelved",D.primary_path&&H?" · Shelved":""]}),D?z.length===0?o.jsxs("div",{className:"projects-page-empty",role:"status",children:[o.jsxs("p",{children:["No tasks in ",D.name," yet."]}),u&&!H&&o.jsx("button",{type:"button",onClick:()=>m(D.id),children:"Start a task"})]}):o.jsxs(o.Fragment,{children:[o.jsx("h2",{className:"projects-page-count",children:z.length===1?"1 task":`${z.length} tasks`}),o.jsx("ul",{className:"projects-task-list","aria-label":`Tasks in ${D.name}`,children:z.map(W=>{const F=s.has(W.id),Y=Pc(W),J=C.forRow(W.id),te=[F&&"Working",Y&&"Done",W.pinned&&"Pinned"].filter(I=>!!I);return o.jsxs("li",{children:[o.jsxs("button",{type:"button",className:"projects-task",onClick:()=>p(W),"aria-label":[W.title,...J.length?[cy(J)]:[],...te].join(", "),children:[o.jsxs("span",{className:"projects-task-line",children:[o.jsx("span",{className:"projects-task-title",children:W.title}),o.jsx("time",{dateTime:new Date(W.updatedAt).toISOString(),children:DC(W.updatedAt)})]}),o.jsxs("span",{className:"projects-task-line",children:[o.jsx("span",{className:"projects-task-snippet",children:EC(W.latestResponse??(F?"Working…":"No response yet"))}),te.length>0&&o.jsx("span",{className:"projects-task-states","aria-hidden":"true",children:te.map(I=>o.jsx("span",{className:`is-${I.toLowerCase()}`,children:I},I))})]})]}),o.jsx(uy,{className:"projects-task-pending",actions:J,subject:W.title})]},W.id)})})]}):o.jsxs("div",{className:"projects-page-empty",role:"status",children:[o.jsx("p",{children:"This project was removed or is no longer in this profile."}),o.jsx("button",{type:"button",onClick:()=>d(null),children:"Show all projects"})]})]})]})}const Q=Hte(V,a,c??new Set),P=z=>{const H=Q.get(z.id)??0;return o.jsx("li",{children:o.jsxs("button",{type:"button",className:"projects-row",onClick:()=>d(z.id),"aria-label":`${z.name}, ${H===1?"1 task":`${H} tasks`}`,children:[o.jsx(Jc,{project:z,size:"medium"}),o.jsxs("span",{className:"projects-row-text",children:[o.jsx("span",{className:"projects-row-name",children:z.name}),z.primary_path&&o.jsx("span",{className:"projects-row-path",children:z.primary_path})]}),o.jsx("span",{className:"projects-row-count","aria-hidden":"true",children:H}),o.jsx(Une,{})]})},z.id)};return o.jsxs("section",{className:"projects-page","aria-label":"Projects",children:[o.jsx(kh,{root:!0,back:{label:"Chat",ariaLabel:"Back to chat",onClick:y},title:o.jsx("h1",{ref:A,tabIndex:-1,children:"Projects"}),actions:o.jsxs("button",{type:"button",className:"projects-page-primary",onClick:v,children:[o.jsx(wM,{}),o.jsx("span",{children:"New project"})]})}),o.jsx("div",{className:"projects-page-body",children:X.length===0?o.jsxs("div",{className:"projects-page-empty",role:"status",children:[o.jsx("p",{children:"No projects yet."}),o.jsx("button",{type:"button",onClick:v,children:"Add a project"})]}):o.jsxs(o.Fragment,{children:[t.length>0&&o.jsx("h2",{className:"projects-page-count",children:t.length===1?"1 project":`${t.length} projects`}),t.length>0&&o.jsx("ul",{className:"projects-list","aria-label":"Projects",children:t.map(P)}),e.length>0&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"projects-page-subhead",children:[o.jsx("h2",{className:"projects-page-count",children:"Shelved"}),k&&o.jsx("button",{type:"button",className:"projects-page-link",onClick:k,children:"Restore shelved projects"})]}),o.jsx("ul",{className:"projects-list","aria-label":"Shelved projects",children:e.map(P)})]})]})})]})}function Une(){return o.jsx("svg",{className:"projects-row-go",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"m9 18 6-6-6-6"})})}function wM(){return o.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:o.jsx("path",{d:"M12 5v14M5 12h14"})})}const BB=t=>t.replace(/\s+/g," ").trim();function Vne(t){const e=/^\d{4}-\d{2}-\d{2}T\S+\s+(?:ERROR|WARN|WARNING)\s+(.+)$/is.exec(t.trim());return e?BB(e[1]):null}function Kne(t){const e=BB(t);if(/collab spawn failed:.*agent thread limit reached/i.test(e))return{key:"agent-thread-limit",title:"A background agent could not start",detail:"The agent thread limit was reached. The current chat can keep going.",technical:t.trim()};if(/responses_websocket:.*failed to connect to websocket:.*504 Gateway Timeout/i.test(e))return{key:"codex-connection-timeout",title:"The Codex connection timed out",detail:"This was recorded in diagnostics. If the turn stops, send the message again.",technical:t.trim()};const n=Vne(t);if(n){const i=n.replace(/^[\w.-]+(?:::[\w.-]+)*:\s*/,"");return{key:`provider:${i.toLocaleLowerCase()}`,title:"The agent reported a background issue",detail:i,technical:t.trim()}}return{key:`message:${e.toLocaleLowerCase()}`,title:e}}function Gne(t){const e=new Map;for(const n of t){const i=Kne(n),s=e.get(i.key);s?e.set(i.key,{...s,detail:i.detail??s.detail,technical:i.technical??s.technical,count:s.count+1}):e.set(i.key,{...i,count:1})}return[...e.values()]}function Yne(){return o.jsxs("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.5","aria-hidden":"true",children:[o.jsx("circle",{cx:"10",cy:"10",r:"7.25"}),o.jsx("path",{d:"M10 8.6v4.2",strokeLinecap:"round"}),o.jsx("circle",{cx:"10",cy:"5.9",r:".65",fill:"currentColor",stroke:"none"})]})}function Xne(){return o.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5","aria-hidden":"true",children:o.jsx("path",{d:"m4.5 6 3.5 3.5L11.5 6",strokeLinecap:"round",strokeLinejoin:"round"})})}function Qne({notices:t,onClear:e}){const[n,i]=_.useState(!1),s=_.useMemo(()=>Gne(t),[t]);if(s.length===0)return null;const r=t.length,a=s.every(d=>!!d.technical),c=r===1?s[0].title:`${r} ${a?"background notices":"notices"}`,u=r===1&&s[0].detail?s[0].detail:`${s.length} ${s.length===1?"kind":"kinds"}, grouped quietly`;return o.jsxs("section",{className:`chat-notices ${n?"is-open":""}`,"aria-label":"Background notices",children:[o.jsxs("div",{className:"chat-notices-bar",children:[o.jsxs("button",{className:"chat-notices-toggle",type:"button","aria-expanded":n,onClick:()=>i(d=>!d),children:[o.jsx("span",{className:"chat-notices-icon",children:o.jsx(Yne,{})}),o.jsxs("span",{className:"chat-notices-copy",children:[o.jsx("span",{className:"chat-notices-title",children:c}),o.jsx("span",{className:"chat-notices-hint",children:u})]}),o.jsx("span",{className:"chat-notices-chevron",children:o.jsx(Xne,{})})]}),o.jsx("button",{className:"chat-notices-clear",type:"button","aria-label":"Clear all background notices",title:"Clear all",onClick:e,children:"×"})]}),n&&o.jsx("div",{className:"chat-notices-panel",children:s.map(d=>o.jsxs("article",{className:"chat-notice-item",children:[o.jsxs("div",{className:"chat-notice-head",children:[o.jsx("span",{children:d.title}),d.count>1&&o.jsxs("span",{className:"chat-notice-count",children:[d.count," times"]})]}),d.detail&&o.jsx("p",{children:d.detail}),d.technical&&o.jsxs("details",{className:"chat-notice-technical",children:[o.jsx("summary",{children:"Technical details"}),o.jsx("pre",{children:d.technical})]})]},d.key))})]})}function Wb(t){const[e,n]=_.useState(()=>typeof window>"u"?!1:window.matchMedia(t).matches);return _.useEffect(()=>{const i=window.matchMedia(t);n(i.matches);const s=r=>n(r.matches);return i.addEventListener("change",s),()=>i.removeEventListener("change",s)},[t]),e}const Zne="(min-width: 701px)",kM="(max-width: 859.98px)",Jne="(min-width: 1181px)",OB=18,eie=10,tie=24,SM=1.5,nie=350,iie=.4,CM=.5,sie=72;function rie(t,e){return!e.open&&t.x>OB?null:{phase:"watching",opening:!e.open,from:t,at:t,width:e.width}}function aie(t,e){if(t.phase==="dropped")return t;const n={...t,at:e};if(t.phase==="swiping")return n;const i=e.x-t.from.x,s=e.y-t.from.y;if(e.t-t.from.t>nie)return{...n,phase:"dropped"};const r=Math.abs(i),a=Math.abs(s);return a>eie&&r<a*SM?{...n,phase:"dropped"}:r<tie?n:(t.opening?i<0:i>0)?{...n,phase:"dropped"}:r<a*SM?{...n,phase:"dropped"}:{...n,phase:"swiping"}}function IB(t){const e=t.at.x-t.from.x,n=t.opening?e/t.width:1+e/t.width;return Math.min(1,Math.max(0,n))}function oie(t){if(t.phase!=="swiping")return null;const e=t.at.x-t.from.x,n=t.at.t-t.from.t,i=n>0?e/n:0;if(Math.abs(e)>=sie){if(i>CM)return"open";if(i<-CM)return"close"}return IB(t)>iie?"open":"close"}function lie({enabled:t,open:e,onChange:n}){const i=_.useRef(e);i.current=e;const s=_.useRef(n);return s.current=n,_.useCallback(r=>{if(!(!r||!t))return cie(r,()=>i.current,a=>s.current(a))},[t])}function cie(t,e,n){let i=null,s=0;const r=()=>{i?.phase==="swiping"&&(s=Date.now()+700),i=null,t.removeAttribute("data-drawer-swiping"),t.style.removeProperty("--swipe-p")},a=m=>{if(r(),m.touches.length!==1)return;s=0;const v=m.touches[0],x=e();if(x){const k=window.getSelection();if(k&&k.rangeCount>0&&!k.isCollapsed)return}const y=t.querySelector(".sidebar")?.offsetWidth||t.clientWidth;i=rie({x:v.clientX,y:v.clientY,t:m.timeStamp},{open:x,width:y}),i&&v.clientX<=OB&&m.cancelable&&m.preventDefault()},c=m=>{if(!i)return;if(m.touches.length!==1||!m.cancelable)return r();const v=m.touches[0];if(i=aie(i,{x:v.clientX,y:v.clientY,t:m.timeStamp}),i.phase==="dropped")return r();i.phase==="swiping"&&(m.preventDefault(),t.setAttribute("data-drawer-swiping",""),t.style.setProperty("--swipe-p",String(IB(i))))},u=m=>{const v=i&&oie(i);v&&m.cancelable&&m.preventDefault(),r(),v&&v==="open"!==e()&&n(v==="open")},d=m=>{i?.phase!=="swiping"&&Date.now()>=s||(m.preventDefault(),m.stopImmediatePropagation())},p=m=>{i?.phase!=="swiping"&&(m.key==="Enter"||m.key===" ")&&(s=0)};return t.addEventListener("touchstart",a,{passive:!1}),t.addEventListener("touchmove",c,{passive:!1}),t.addEventListener("touchend",u,{passive:!1}),t.addEventListener("touchcancel",r,{passive:!0}),t.addEventListener("click",d,!0),t.addEventListener("dblclick",d,!0),t.addEventListener("keydown",p,!0),()=>{t.removeEventListener("touchstart",a),t.removeEventListener("touchmove",c),t.removeEventListener("touchend",u),t.removeEventListener("touchcancel",r),t.removeEventListener("click",d,!0),t.removeEventListener("dblclick",d,!0),t.removeEventListener("keydown",p,!0),r()}}let Oc,S0=0;function ok(t,e){const n=++S0;Oc?.skipTransition(),Oc=void 0;const i=document.documentElement;delete i.dataset.zenTransition;let s=!1;const r=()=>{n!==S0||s||(s=!0,Ea.flushSync(e))},a=()=>{n===S0&&(Oc=void 0,delete i.dataset.zenTransition)},c=window.matchMedia("(prefers-reduced-motion: reduce)").matches;if(c||!document.startViewTransition){r(),c||document.querySelector(".app .main")?.animate?.([{opacity:.75},{opacity:1}],{duration:320,easing:"ease-out"});return}i.dataset.zenTransition=t;try{Oc=document.startViewTransition(r),Oc.ready.catch(()=>{}),Oc.finished.then(a,()=>{r(),a()})}catch{r(),a()}}function jM(){S0++,Oc?.skipTransition(),Oc=void 0,delete document.documentElement.dataset.zenTransition}const uie={opus:{color:"#b99cff",width:1.42,roundness:.42,bodyWidth:.96,beat:1.3},sonnet:{color:"#e07a59",width:1.46,roundness:.28,bodyWidth:.94,beat:1.05},haiku:{color:"#59c9c5",width:1.32,roundness:.24,bodyWidth:.76,beat:.8},fable:{color:"#e48db7",width:1.38,roundness:.16,bodyWidth:.9,beat:1.2},claude:{color:"#d97757",width:1.48,roundness:.38,bodyWidth:1.02,beat:1.15},astra:{color:"#d76bf0",width:1.4,roundness:.12,bodyWidth:.88,beat:.95},sol:{color:"#f1b84b",width:1.38,roundness:.45,bodyWidth:.98,beat:.9},terra:{color:"#78c892",width:1.56,roundness:.12,bodyWidth:1.12,beat:1.25},luna:{color:"#84a9ff",width:1.4,roundness:.4,bodyWidth:.8,beat:1.4},codex:{color:"#8eb3c3",width:1.44,roundness:.16,bodyWidth:.94,beat:1.1}};function hie(t){return t==="pi"?"codex":t.startsWith("pi-")?t.slice(3):t}const die={opus:{ears:"M 17 43 Q 5 30 11 16 Q 28 18 34 31 Z M 66 31 Q 72 18 89 16 Q 95 30 83 43 Z",inner:"M 19 34 L 16 23 Q 26 25 28 31 Z M 72 31 Q 74 25 84 23 L 81 34 Z",fringe:"M 15 48 Q 10 27 28 21 L 29 9 L 42 19 L 50 5 L 58 19 L 72 9 L 72 22 Q 91 30 85 49 L 74 41 L 72 46 Q 63 41 60 32 Q 53 43 43 46 L 45 35 Q 33 46 25 42 L 23 49 Z",shine:"M 25 29 Q 35 25 41 28 M 59 25 L 65 28",mark:"M 50 17 L 54 24 L 50 31 L 46 24 Z"},sonnet:{ears:"M 16 46 Q 5 31 9 8 Q 29 13 37 32 Z M 63 32 Q 71 13 91 8 Q 95 31 84 46 Z",inner:"M 19 34 L 15 17 Q 27 21 29 31 Z M 71 31 Q 73 21 85 17 L 81 34 Z",fringe:"M 15 49 Q 10 28 29 21 Q 40 18 45 11 L 45 19 Q 55 16 59 8 Q 65 14 63 21 Q 89 24 85 49 L 74 42 L 72 48 Q 60 42 57 33 Q 49 44 37 45 L 41 35 Q 31 43 24 42 L 22 50 Z",shine:"M 25 30 Q 33 26 39 27 M 64 27 L 70 29",mark:"M 48 27 Q 44 22 48 19 Q 48 23 51 23 Q 55 18 55 17 Q 60 26 54 29 Q 51 31 48 27 Z"},haiku:{ears:"M 33 29 Q 8 33 7 8 Q 31 6 36 27 Z M 64 27 Q 68 6 93 8 Q 92 32 67 29 Z",inner:"M 16 16 Q 27 16 30 26 Q 20 26 16 16 Z M 70 26 Q 74 16 84 16 Q 80 26 70 26 Z",fringe:"M 15 48 Q 10 23 36 21 Q 42 12 55 13 L 51 20 Q 83 15 87 40 L 84 50 L 74 41 Q 64 47 55 37 Q 50 46 43 46 L 44 36 Q 35 48 24 42 L 21 49 Z",shine:"M 24 31 Q 33 25 40 28 M 65 29 L 72 32",mark:"M 50 32 Q 38 29 41 20 Q 52 21 50 32 Q 49 19 61 20 Q 61 30 50 32 Z"},fable:{ears:"M 20 40 Q 5 24 16 4 Q 31 9 34 30 Z M 66 30 Q 70 8 84 4 Q 96 24 80 40 Z",inner:"M 21 27 Q 16 17 19 12 Q 26 17 27 28 Z M 73 28 Q 74 17 81 12 Q 84 17 79 27 Z",fringe:"M 15 49 Q 9 28 30 21 Q 36 17 42 21 Q 51 13 61 20 Q 90 22 86 50 L 77 44 L 74 51 Q 59 44 53 34 Q 46 45 34 45 L 36 36 Q 29 42 23 44 L 22 51 Z",shine:"M 24 31 Q 31 27 36 28 M 61 27 Q 68 26 73 31",mark:"M 50 31 C 34 22 44 15 50 22 C 56 15 67 22 50 31 Z"},claude:{ears:"M 23 43 C 3 45 2 27 13 24 C 6 13 22 7 30 20 L 37 32 Z M 63 32 L 70 20 C 78 7 94 13 87 24 C 98 27 97 45 77 43 Z",inner:"M 16 30 Q 13 19 24 23 L 28 32 Z M 72 32 L 76 23 Q 87 19 84 30 Z",fringe:"M 15 49 Q 8 35 18 26 Q 22 16 36 21 Q 44 10 53 20 Q 64 13 71 23 Q 91 23 86 49 L 76 42 L 74 49 Q 62 46 58 35 Q 50 45 41 46 L 42 36 Q 30 46 25 43 L 23 50 Z",shine:"M 24 31 Q 30 27 36 29 M 62 28 L 69 30",mark:"M 50 19 V 30 M 44 22 L 56 27 M 45 28 L 55 21"},astra:{ears:"M 15 44 L 7 11 L 24 18 L 31 13 L 37 32 Z M 63 32 L 69 13 L 76 18 L 93 11 L 85 44 Z",inner:"M 19 34 L 15 22 L 27 28 Z M 73 28 L 85 22 L 81 34 Z",fringe:"M 15 50 Q 11 27 32 21 L 39 12 L 47 18 L 57 9 L 60 19 Q 88 21 87 48 L 78 42 L 75 50 Q 62 44 61 31 Q 50 48 38 46 L 42 34 Q 31 45 25 41 L 22 51 Z",shine:"M 24 31 L 35 27 M 66 27 L 74 32",mark:"M 52 16 L 55 22 L 62 24 L 55 27 L 52 34 L 49 27 L 42 24 L 49 22 Z"},sol:{ears:"M 22 45 L 6 36 L 13 28 L 7 14 L 24 18 L 31 9 L 38 30 Z M 62 30 L 69 9 L 76 18 L 93 14 L 87 28 L 94 36 L 78 45 Z",inner:"M 19 32 L 17 24 L 28 27 L 27 35 Z M 73 35 L 72 27 L 83 24 L 81 32 Z",fringe:"M 14 49 L 10 38 L 18 33 Q 18 22 35 21 L 41 12 L 46 19 L 56 7 L 60 20 L 69 16 L 70 23 Q 86 26 86 40 L 89 50 L 76 43 L 75 50 Q 61 45 56 34 Q 52 43 43 46 L 44 36 Q 32 47 25 43 L 22 51 Z",shine:"M 25 31 L 36 27 M 65 29 L 71 31",mark:"M 54 25 A 5 5 0 1 0 44 25 A 5 5 0 1 0 54 25 Z M 49 16 V 17 M 49 33 V 34 M 40 25 H 41 M 57 25 H 58"},terra:{ears:"M 31 33 Q 7 30 6 11 Q 30 8 38 29 Z M 62 29 Q 70 8 94 11 Q 93 30 69 33 Z",inner:"M 15 17 Q 26 16 31 28 Q 20 26 15 17 Z M 69 28 Q 74 16 85 17 Q 80 26 69 28 Z",fringe:"M 13 49 Q 8 24 31 22 L 31 17 L 42 20 Q 46 12 58 13 L 56 20 Q 82 16 89 39 L 86 51 L 75 43 L 74 50 Q 59 47 55 34 Q 48 45 36 46 L 39 35 Q 29 44 23 43 L 21 52 Z",shine:"M 23 32 Q 29 27 35 29 M 65 27 L 73 32",mark:"M 47 32 Q 41 19 59 19 Q 61 32 47 32 Z M 47 32 L 55 24"},luna:{ears:"M 23 40 Q 5 22 20 5 Q 24 19 37 29 Z M 63 29 Q 76 19 80 5 Q 95 22 77 40 Z",inner:"M 24 29 Q 17 22 20 15 Q 24 24 29 27 Z M 71 27 Q 76 24 80 15 Q 83 22 76 29 Z",fringe:"M 15 49 Q 10 24 34 20 Q 45 13 61 20 Q 88 22 86 49 L 75 43 L 74 50 Q 57 45 57 32 Q 49 46 35 47 L 40 34 Q 31 44 24 42 L 22 50 Z",shine:"M 24 30 Q 31 26 37 28 M 65 28 L 72 31",mark:"M 54 17 A 8 8 0 1 0 59 30 A 9 9 0 0 1 54 17 Z"},codex:{ears:"M 17 44 L 8 32 L 8 16 L 24 16 L 35 31 Z M 65 31 L 76 16 L 92 16 L 92 32 L 83 44 Z",inner:"M 16 23 H 22 L 28 31 L 21 33 L 16 29 Z M 72 31 L 78 23 H 84 V 29 L 79 33 Z",fringe:"M 14 49 Q 12 26 31 22 L 36 15 L 47 20 L 57 13 L 63 22 Q 86 23 86 48 L 76 42 L 74 49 Q 61 44 57 33 Q 48 45 37 45 L 40 35 Q 30 44 24 42 L 22 50 Z",shine:"M 24 31 L 35 28 M 64 28 L 72 31",mark:"M 45 20 L 39 25 L 45 30 M 55 20 L 61 25 L 55 30 M 52 20 L 48 30"}},fie={idle:"M 43 75 Q 50 78 57 75 Q 56 84 50 84 Q 44 84 43 75 Z",still:"M 45 78 Q 50 81 55 78",think:"M 48 79 Q 53 76 58 78",work:"M 44 78 Q 49 81 56 76",asleep:"M 48 79 C 48 75 53 75 53 79 C 53 83 48 83 48 79 Z"};function BC({robot:t="sonnet",size:e=28,alert:n=!1,mood:i="idle",asleep:s=!1}){const r=hie(t),a=die[r],c=`mascot-iris-${_.useId()}`,u=s?"asleep":i,d=u==="think",p=u==="work",m=p?8:r==="haiku"||r==="luna"||r==="fable"?12:11;return o.jsxs("span",{className:`mascot${n?" is-alert":""}${s?" is-asleep":""}`,"data-robot":t,"data-mood":i,"data-expression":u,style:{width:e,height:e,"--mascot-size":`${e}px`,"--robot-accent":uie[r].color},"aria-hidden":"true",children:[o.jsxs("svg",{className:"mascot-avatar",viewBox:"0 0 100 100",width:e,height:e,fill:"none",focusable:"false",children:[o.jsx("defs",{children:o.jsxs("linearGradient",{id:c,x1:"0",y1:"0",x2:"0",y2:"1",children:[o.jsx("stop",{className:"mascot-iris-dark",offset:"0"}),o.jsx("stop",{className:"mascot-iris-color",offset:".65"}),o.jsx("stop",{className:"mascot-iris-light",offset:"1"})]})}),o.jsxs("g",{className:"mascot-avatar-character",children:[o.jsx("path",{className:"mascot-fur mascot-ears",d:a.ears}),o.jsx("path",{className:"mascot-ear-inner",d:a.inner}),o.jsx("path",{className:"mascot-collar",d:"M 33 81 Q 50 77 67 81 L 74 94 Q 51 101 26 94 Z"}),o.jsx("path",{className:"mascot-collar-fold",d:"M 32 84 L 48 92 L 41 97 L 28 92 Z M 68 84 L 52 92 L 59 97 L 72 92 Z"}),o.jsx("path",{className:"mascot-collar-gem",d:"M 50 87 L 54 92 L 50 97 L 46 92 Z"}),o.jsx("path",{className:"mascot-avatar-base",d:"M 16 49 C 14 28 29 20 50 20 C 71 20 86 28 84 49 L 89 63 L 82 65 L 85 73 L 77 73 C 72 85 61 91 50 91 C 39 91 28 85 23 73 L 15 73 L 18 65 L 11 63 Z"}),o.jsx("path",{className:"mascot-face-shadow",d:"M 14 61 L 20 64 L 18 70 L 26 70 Q 34 84 50 85 Q 68 85 78 71 L 83 72 L 77 73 C 72 85 61 91 50 91 C 39 91 28 85 23 73 L 15 73 L 18 65 L 11 63 Z"}),o.jsx("path",{className:"mascot-brow-shadow",d:"M 19 47 Q 25 34 50 34 Q 75 34 82 48 L 73 47 Q 62 49 55 42 Q 43 52 32 47 L 25 51 Z"}),o.jsx("path",{className:"mascot-fur mascot-fringe",d:a.fringe}),o.jsx("path",{className:"mascot-hair-shine",d:a.shine}),o.jsx("g",{className:`mascot-avatar-mark${r==="claude"||r==="codex"?" mascot-mark-lines":""}`,children:o.jsx("path",{d:a.mark})}),o.jsxs("g",{className:"mascot-avatar-face",strokeLinecap:"round",strokeLinejoin:"round",children:[o.jsxs("g",{className:"mascot-avatar-cheeks",children:[o.jsx("ellipse",{cx:"23",cy:"71",rx:"7",ry:"3.5"}),o.jsx("ellipse",{cx:"77",cy:"71",rx:"7",ry:"3.5"}),o.jsx("path",{className:"mascot-blush-lines",d:"M 20 70 L 19 72 M 24 70 L 23 72 M 76 70 L 75 72 M 80 70 L 79 72"})]}),o.jsx("g",{className:"mascot-avatar-eyes",children:s?o.jsxs("g",{className:"mascot-sleep-eyes",children:[o.jsx("path",{d:"M 25 59 Q 33 67 41 59 M 59 59 Q 67 67 75 59"}),o.jsx("path",{className:"mascot-lower-lash",d:"M 26 61 L 24 63 M 74 61 L 76 63"})]}):[33,67].map((v,x)=>{const y=d?57+x*2:59,k=v+(d?2:0);return o.jsxs("g",{children:[o.jsx("ellipse",{className:"mascot-eye-white",cx:v,cy:y,rx:"10",ry:m+1}),o.jsx("ellipse",{className:"mascot-avatar-eye",cx:k,cy:y+1,rx:"7.7",ry:m,fill:`url(#${c})`}),o.jsx("ellipse",{className:"mascot-pupil",cx:k,cy:y,rx:"3.4",ry:m*.66}),o.jsx("path",{className:"mascot-iris-glow",d:`M ${k-4.5} ${y+m-3} Q ${k} ${y+m} ${k+4.5} ${y+m-3}`}),o.jsx("ellipse",{className:"mascot-eye-glint",cx:k-2.7,cy:y-m*.43,rx:"3",ry:"3.4"}),o.jsx("circle",{className:"mascot-eye-glint mascot-eye-glint-small",cx:k+3.5,cy:y+4,r:"1.4"}),o.jsx("path",{className:"mascot-upper-lash",d:`M ${v-10} ${y-3} Q ${v-8} ${y-m-3} ${v+1} ${y-m-1} Q ${v+7} ${y-m} ${v+10} ${y-4}`}),o.jsx("path",{className:"mascot-lower-lash",d:`M ${v-6} ${y+m} Q ${v} ${y+m+2} ${v+5} ${y+m}`})]},v)})}),(d||p)&&o.jsxs("g",{className:"mascot-eyebrows",children:[o.jsx("path",{d:d?"M 26 43 Q 32 39 39 42":"M 26 45 L 39 48"}),o.jsx("path",{d:d?"M 61 45 Q 67 42 74 44":"M 61 48 L 74 45"})]}),o.jsx("path",{className:"mascot-nose",d:"M 48.5 71 Q 50 70 51.5 71 L 50 72 Z"}),o.jsx("path",{className:"mascot-avatar-mouth",d:fie[u]}),u==="idle"&&o.jsx("path",{className:"mascot-tongue",d:"M 47 81 Q 50 78 53 81 Q 50 84 47 81 Z"})]})]})]}),t.startsWith("pi")&&o.jsx("span",{className:"mascot-provider-badge","data-provider-mark":"pi",children:"P"}),s&&o.jsx("span",{className:"mascot-z",children:"z"}),n&&o.jsx("span",{className:"mascot-task-dot"})]})}function $B(t){if(/^[A-Za-z]:[\\/]/.test(t))return t.slice(0,3);const e=/^(?:\\\\|\/\/)[^\\/]+[\\/][^\\/]+/.exec(t);return e?e[0]:t.startsWith("/")?"/":null}function AM(t){return $B(t)!==null}function NM(t){const e=$B(t);if(!e)return null;const n=t.replace(e==="/"?/\/+$/:/[\\/]+$/,"");if(n.length<=e.length)return null;const i=e==="/"?n.lastIndexOf("/"):Math.max(n.lastIndexOf("/"),n.lastIndexOf("\\"));return i<e.length?e:n.slice(0,i)}function pie(t,e){return t.filter(n=>n.is_dir?!n.is_hidden&&!n.name.startsWith("."):e)}function OC({start:t,title:e,onPick:n,onClose:i,files:s=!1}){const[r,a]=_.useState(t),[c,u]=_.useState(t),[d,p]=_.useState([]),[m,v]=_.useState(null),[x,y]=_.useState(!0),k=_.useCallback(C=>{a(C),u(C)},[]);_.useEffect(()=>{let C=!0;return y(!0),ae.invoke("list_dir",{path:r}).then(A=>{if(!C)return;p(pie(A??[],s)),v(null);const N=(A??[])[0];if(N&&!AM(r)){const E=NM(N.path);E&&(a(E),u(E))}}).catch(A=>{C&&(p([]),v(A.message))}).finally(()=>C&&y(!1)),()=>{C=!1}},[r,s]),_.useEffect(()=>{const C=A=>A.key==="Escape"&&i();return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[i]);const S=NM(r);return o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"panel-scrim",onClick:i}),o.jsxs("div",{className:"fp-picker",role:"dialog","aria-label":e,children:[o.jsxs("header",{className:"fp-picker-head",children:[o.jsx("span",{className:"fp-picker-title",children:e}),o.jsx("button",{className:"panel-close",type:"button",onClick:i,"aria-label":"Close",children:"✕"})]}),o.jsxs("form",{className:"fp-picker-path",onSubmit:C=>{C.preventDefault(),k(c.trim())},children:[o.jsx("input",{className:"fp-picker-input",value:c,spellCheck:!1,autoCapitalize:"off",autoCorrect:"off",placeholder:"Folder path",onChange:C=>u(C.target.value)}),o.jsx("button",{className:"panel-btn",type:"submit",children:"Go"})]}),m&&o.jsx("div",{className:"panel-error",children:m}),o.jsxs("div",{className:"fp-picker-body",children:[S&&o.jsxs("button",{className:"fp-picker-row is-up",type:"button",onClick:()=>k(S),children:[o.jsx(EM,{}),o.jsx("span",{className:"fp-picker-name",children:".."})]}),x&&d.length===0&&!m&&o.jsx("div",{className:"dots","aria-label":"loading"}),!x&&d.length===0&&!m&&o.jsx("div",{className:"fp-picker-empty",children:s?"No files or visible folders in here.":"No visible folders in here."}),d.map(C=>o.jsxs("button",{className:`fp-picker-row ${C.is_dir?"":"is-file"}`,type:"button",onClick:()=>C.is_dir?k(C.path):n(C.path),children:[C.is_dir?o.jsx(EM,{}):o.jsx(mie,{}),o.jsx("span",{className:"fp-picker-name",children:C.name})]},C.path))]}),o.jsxs("footer",{className:"fp-picker-foot",children:[o.jsx("div",{className:"fp-picker-here",title:r,children:o.jsx("bdi",{children:r})}),!s&&o.jsx("button",{className:"panel-btn is-primary",type:"button",disabled:!AM(r),onClick:()=>n(r),children:"Use this folder"})]})]})]})}function EM(){return o.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"M3 7a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.7.9l.8 1.2a2 2 0 0 0 1.7.9H19a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"})})}function mie(){return o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z"}),o.jsx("path",{d:"M14 2v6h6"})]})}function gie({onReference:t,onUpload:e}){return o.jsxs(o.Fragment,{children:[o.jsxs("button",{type:"button",role:"menuitem",className:"picker-item",onClick:t,children:[o.jsx("span",{className:"picker-name",children:"Reference a file"}),o.jsx("span",{className:"picker-model",children:"on the machine running the agents"})]}),o.jsxs("button",{type:"button",role:"menuitem",className:"picker-item",onClick:e,children:[o.jsx("span",{className:"picker-name",children:"Upload a file"}),o.jsx("span",{className:"picker-model",children:"from this device — up to 12 MB per file"})]})]})}function Ol(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}const vie={isRepo:!1,current:"",branches:[],isWorktree:!1};function xie({projects:t,projectId:e,onProject:n,branch:i,branches:s=vie,onBranch:r,newWorktree:a,onNewWorktree:c,useSandbox:u=!1,onUseSandbox:d}){const p=t.filter(x=>Ol(x.name)!=="general"),m=i&&!s.branches.includes(i)?[i,...s.branches]:s.branches,v=s.loading?"Finding branches…":s.error?"Branches unavailable":s.isRepo?i||s.current||"No branch":"No Git repository";return o.jsxs("div",{className:"work-location","aria-label":"Work location",children:[o.jsxs("label",{className:"work-location-field",title:"Project",children:[o.jsx(yie,{}),o.jsx("span",{className:"sr-only",children:"Project"}),o.jsxs("select",{"aria-label":"Project",value:e??"",onChange:x=>n(x.target.value||null),children:[o.jsx("option",{value:"",children:"General"}),p.map(x=>o.jsx("option",{value:x.id,children:x.name},x.id))]})]}),o.jsx("span",{className:"work-location-divider","aria-hidden":"true"}),o.jsxs("label",{className:`work-location-field is-branch ${s.isRepo?"":"is-muted"}`,title:a?"Base branch":"Branch",children:[o.jsx(_ie,{}),o.jsx("span",{className:"sr-only",children:a?"Base branch":"Branch"}),o.jsxs("select",{"aria-label":a?"Base branch":"Branch",value:i,disabled:s.loading||!s.isRepo,onChange:x=>r(x.target.value),children:[!m.length&&o.jsx("option",{value:"",children:v}),m.map(x=>o.jsx("option",{value:x,children:x},x))]})]}),o.jsx("span",{className:"work-location-spacer"}),o.jsxs("label",{className:`worktree-choice ${s.isWorktree?"is-active":""}`,title:s.isWorktree?"This chat runs in a linked worktree":"Create a task branch in a new linked worktree",children:[o.jsx("input",{type:"checkbox",checked:a,disabled:!s.isRepo,onChange:x=>c(x.target.checked)}),o.jsx(bie,{}),o.jsx("span",{children:"New worktree"})]}),o.jsxs("label",{className:"worktree-choice sandbox-choice",title:"Prepare local test services and a separate database for this chat",children:[o.jsx("input",{type:"checkbox",checked:u,onChange:x=>d?.(x.target.checked)}),o.jsx("span",{children:"Use sandbox"})]}),s.error&&o.jsx("span",{className:"work-location-error",role:"status",children:s.error})]})}function yie(){return o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M3 7.5h7l2 2h9v9.5H3z"}),o.jsx("path",{d:"M3 7.5V5h7l2 2h9v2.5"})]})}function _ie(){return o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"6",cy:"5",r:"2"}),o.jsx("circle",{cx:"18",cy:"7",r:"2"}),o.jsx("circle",{cx:"6",cy:"19",r:"2"}),o.jsx("path",{d:"M6 7v10M8 10h4a6 6 0 0 0 6-1"})]})}function bie(){return o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"6",cy:"6",r:"2"}),o.jsx("circle",{cx:"18",cy:"6",r:"2"}),o.jsx("circle",{cx:"12",cy:"18",r:"2"}),o.jsx("path",{d:"M6 8v2a4 4 0 0 0 4 4h2M18 8v2a4 4 0 0 1-4 4h-2v2"})]})}function wie(t){return`pasted.${(t.split("/")[1]||"png").replace("jpeg","jpg")}`}function PB(t){const e=t;return e?.message||e?.name||String(t??"no reason given")}function kie(t){return t?.name==="NotAllowedError"?"Tap it again, then tap “Paste” when the browser asks. Or hold the box and choose Paste.":`The browser would not read the clipboard (${PB(t)}). Hold the box and choose Paste.`}async function Sie(t){const e=[];let n="";for(const i of t){const s=i.types.find(r=>r.startsWith("image/"));if(s){const r=await i.getType(s);e.push(new File([r],wie(s),{type:s}));continue}i.types.includes("text/plain")&&(n+=await(await i.getType("text/plain")).text())}return{files:e,text:n}}const qb="blank:new",Cie=()=>({text:"",attached:[]});class zB{held=new Map;keep(e,n){const i=e??qb;if(!n.text.trim()&&n.attached.length===0){this.held.delete(i);return}this.held.set(i,{text:n.text,attached:[...n.attached]})}take(e){const n=e??qb,i=this.held.get(n);return this.held.delete(n),i??Cie()}forget(e){this.held.delete(e??qb)}}function MM(t,e,n,i){const s=t.slice(n,i),r=(e==="codex"?/^([/$])(\S*)$/:/^(\/)(\S*)$/).exec(s);if(r)return{trigger:r[1],query:r[2],start:n,end:i}}function LM(t,e,n=t.length){const i=Math.max(0,Math.min(n,t.length));let s=i;for(;s>0&&!/\s/.test(t[s-1]);)s-=1;const r=t.slice(i).search(/\s/),a=r<0?t.length:i+r,c=MM(t,e,s,a);if(e==="claude")return s===0&&a===t.length?c:void 0;if(c)return c;let u=s;for(;u>0;){for(;u>0&&/\s/.test(t[u-1]);)u-=1;const d=u;for(;u>0&&!/\s/.test(t[u-1]);)u-=1;const p=MM(t,e,u,d);if(p)return p}}function TM(t,e){return e==="$"?t.replace(/^\//,"$"):t}function jie(t,e,n){const i=e.end<t.length&&/\s/.test(t[e.end])?n.trimEnd():n;return{text:t.slice(0,e.start)+i+t.slice(e.end),caret:e.start+i.length}}function Aie(t,e){const n=hi(t).models.filter(u=>u.flag),i=t==="claude"?n.filter(u=>["opus","sonnet","haiku","fable"].includes(u.flag)):[],s=e.models.flatMap(u=>{const d=ay(t,u.model,u.displayName,u.description??u.model);return d?[d]:[]}),r=[],a=new Set,c=e.source==="bundled"?n:[];for(const u of[...i,...s,...c]){const d=u.flag.toLowerCase();!d||a.has(d)||(a.add(d),r.push(u))}return r}const Ub=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches,Nie=8e3,Eie=typeof navigator<"u"&&!!navigator.clipboard&&!!(navigator.clipboard.read||navigator.clipboard.readText);function Mie(t,e){const[n,i]=_.useState({}),[s,r]=_.useState({}),a=_.useRef(new Set),c=_.useCallback((p,m=!1)=>{p==="pi"||!m&&a.current.has(p)||(a.current.add(p),r(v=>({...v,[p]:{...v[p],loading:!0,error:void 0}})),ae.invoke("agent_models",{agent:p}).then(v=>{i(x=>({...x,[p]:Aie(p,v)})),r(x=>({...x,[p]:{loading:!1,note:v.note??void 0}}))}).catch(v=>{r(x=>({...x,[p]:{loading:!1,error:String(v?.message??v)}}))}))},[]);_.useEffect(()=>{if(t)for(const p of["claude","codex"])e&&!e.includes(p)||c(p)},[t,e,c]);const u=_.useMemo(()=>Eh.flatMap(p=>n[p.id]??p.models),[n]),d=_.useCallback(p=>{a.current.delete(p),c(p,!0)},[c]);return{models:u,status:s,reload:d}}function FB({list:t,access:e,onPick:n}){const i=t.filter(a=>!a.bypass),s=t.find(a=>a.bypass),r=_.useRef(e===s?.id?i[i.length-1].id:e);return e!==s?.id&&(r.current=e),o.jsxs(o.Fragment,{children:[i.map(a=>o.jsxs("button",{type:"button",role:"menuitem",className:`picker-item ${a.id===e?"is-on":""}`,onClick:()=>n(a.id),children:[o.jsx("span",{className:"picker-name",children:a.label}),o.jsx("span",{className:"picker-model",children:a.hint}),a.id===e&&o.jsx("span",{className:"picker-tick","aria-hidden":"true",children:"✓"})]},a.id)),s&&o.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":e===s.id,className:`picker-item is-bypass ${e===s.id?"is-on":""}`,title:s.hint,onClick:()=>n(e===s.id?r.current:s.id),children:[o.jsx("span",{className:"picker-name",children:s.label}),o.jsx("span",{className:"picker-switch",children:e===s.id?"Enabled":"Enable"})]})]})}const RM=/\.(png|jpe?g|gif|webp)$/i,Lie=100;function HB(t){return`octiq.v2.history:${t||"new"}`}function DM(t){try{const e=JSON.parse(localStorage.getItem(HB(t))||"[]");return Array.isArray(e)?e.filter(n=>typeof n=="string"):[]}catch{return[]}}function Tie(t,e){try{localStorage.setItem(HB(t),JSON.stringify(e))}catch{}}function Rie(t,e,n,i,s){if(s==="older"){if(!t.length)return{index:e,text:n,draft:i};const a=Math.min(e+1,t.length-1);return{index:a,text:t[a],draft:e===-1?n:i}}if(e<0)return{index:e,text:n,draft:i};const r=e-1;return{index:r,text:r<0?i:t[r],draft:i}}function Die(t,e){return[t.trim(),...e.map(n=>n.trim())].filter(Boolean).join(`
80
+ `).trim()||(t.attachments?.length?"[Attachment]":"");if(e)return{id:t.id,speaker:t.role==="user"?"You":t.speaker?.name??"Assistant",text:e.length>420?`${e.slice(0,420).trimEnd()}…`:e}}function Dte(t){const e=[];for(let n=t.length-1;n>=0&&e.length<3;n--){const i=t[n],s=gB(i);s&&e.unshift(s)}return e}function ek(t){for(let e=t.length-1;e>=0;e--){if(t[e].role==="user")continue;const n=gB(t[e]);if(n)return n}}function EC(t){const e=[],n=s=>`${e.push(s)-1}`;return t.replace(/\\([\\`*_{}[\]()#+\-.!~|<>])/g,(s,r)=>n(r)).replace(/^[ \t]*(```|~~~)[^\n]*$/gm,"").replace(/^[ \t]{0,3}#{1,6}[ \t]+/gm,"").replace(/^[ \t]*(>[ \t]?)+/gm,"").replace(/^[ \t]*([-*_])([ \t]*\1){2,}[ \t]*$/gm,"").replace(/^[ \t]*[-*+][ \t]+(\[[ xX]\][ \t]+)?/gm,"").replace(/^[ \t]*\|?[ \t]*:?-{3,}:?[ \t]*(\|[ \t]*:?-{3,}:?[ \t]*)*\|?[ \t]*$/gm,"").replace(/^[ \t]*\|(.*?)\|?[ \t]*$/gm,(s,r)=>r.split("|").map(a=>a.trim()).filter(Boolean).join(" · ")).replace(/(`+)([^`]*?)\1/g,(s,r,a)=>n(a.trim())).replace(/`+/g,"").replace(/!\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/\[([^\]]+)\]\([^)]*\)/g,"$1").replace(/<((?:https?|mailto):[^>\s]+)>/g,"$1").replace(/\*\*(?=\S)([^\n]*?\S)\*\*/g,"$1").replace(/~~(?=\S)([^\n]*?\S)~~/g,"$1").replace(/(^|[^\w*])\*(?=[^\s*])([^*\n]*?[^\s*])\*(?![\w*])/g,"$1$2").replace(/(^|\s)(__?)(?=\S)([^\n]*?\S)\2(?=\s|$|[,;:!?)])/g,"$1$3").replace(/\*\*|~~/g,"").replace(/\s+/g," ").trim().replace(/(\d+)/g,(s,r)=>e[Number(r)])}async function Bte(t,e,n){const i=await t();if(n())return[];if(!i.events.length)return e;let s=await ah(Uc(),i.context,0,n);return s=await ah(s,i.events,0,n),s.messages}const vB=[{value:"auto",label:"Auto",description:"Isolate writing tasks; let read-only workers use this checkout."},{value:"worktree",label:"New worktree",description:"Give each task an isolated branch and keep it through review."},{value:"direct",label:"Current checkout",description:"Modify this folder directly, one worker at a time."}];function Ote(t){if(t.state==="cleaned")return t.abandoned?"Abandoned · workspace removed":"Merged · workspace removed";if(t.state==="cleaning")return"Removing workspace";const e=t.delivery;return e?e.dirty?"Uncommitted changes":e.merged?"Merged":e.reviewState?`Review · ${e.reviewState.toLowerCase().replaceAll("_"," ")}`:e.pullRequest?"Pull request open":e.pushed?"Pushed · awaiting review":e.hasCommits?"Committed, not pushed":"No new commits":"Not checked yet"}function Ite(t){if(t.state==="cleaned")return t.abandoned?"quiet":"ok";const e=t.delivery;return e?e.merged?"ok":e.dirty||e.hasCommits&&!e.pushed?"warn":"quiet":"quiet"}const Qo={runs:[],tasks:[],attempts:[],gates:[],messages:[]};function $te(t){const e=new Map(t.runs.map(i=>[i.id,i.coordinatorChatKey])),n=new Map;for(const i of t.attempts){const s=e.get(i.runId);if(!s?.startsWith("chat:")||!i.workerChatKey.startsWith("chat:"))continue;const r=i.workerChatKey.slice(5),a=s.slice(5);r&&a&&r!==a&&n.set(r,a)}return n}function Hd(t,e){return!!t&&(t.startsWith("orch-")||e.has(t))}function MC(t,e){return t.filter(n=>!Hd(n.id,e))}function tk(t,e){if(!t||!e.has(t))return null;const n=new Set([t]);let i=e.get(t);for(;e.has(i);){if(n.has(i))return null;n.add(i),i=e.get(i)}return n.has(i)?null:i}function LC(t,e){if(t.status==="loading")return"work projects loading";if(t.status==="discussion")return"discussion, no tasks yet";if(t.status==="unknown")return"work project unknown";if(t.status==="home")return e(t.homeProjectId??"","Unknown project");const n=t.destinations.map(s=>e(s.projectId,s.projectName)),i=t.unknownTaskCount?`, ${t.unknownTaskCount} ${t.unknownTaskCount===1?"task has":"tasks have"} no confirmed project`:"";return`${n.join(", ")}${i}, ${t.taskCount} ${t.taskCount===1?"task":"tasks"}`}function xB(t,e){const n=t.status==="home"?t.homeProjectId:t.status==="projects"&&t.destinations.length===1?t.destinations[0].projectId:void 0;return n&&e(n)?n:null}function oy(t,e,n,i=!1){const s=`chat:${t.id}`;if(!e)return n&&!n.has(s)?{status:"home",destinations:[],taskCount:0,unknownTaskCount:0,homeProjectId:t.projectId}:{status:i?"unknown":"loading",destinations:[],taskCount:0,unknownTaskCount:0};const r=e.runs.filter(m=>m.coordinatorChatKey===s);if(r.length===0&&n===null)return{status:i?"unknown":"loading",destinations:[],taskCount:0,unknownTaskCount:0};if(!(r.length>0||!!n?.has(s)))return{status:"home",destinations:[],taskCount:0,unknownTaskCount:0,homeProjectId:t.projectId};const c=new Set(r.map(m=>m.id)),u=e.tasks.filter(m=>c.has(m.runId)).sort((m,v)=>v.updatedAt-m.updatedAt||m.id.localeCompare(v.id));if(u.length===0)return{status:"discussion",destinations:[],taskCount:0,unknownTaskCount:0};const d=new Map;let p=0;for(const m of u){if(!m.destination){p+=1;continue}d.has(m.destination.projectId)||d.set(m.destination.projectId,m.destination)}return d.size===0?{status:"unknown",destinations:[],taskCount:u.length,unknownTaskCount:p}:{status:"projects",destinations:[...d.values()],taskCount:u.length,unknownTaskCount:p}}function Pte(t,e,n,i){return t.filter(s=>{const r=oy(s,n,i);return r.status==="home"?r.homeProjectId===e:r.destinations.some(a=>a.projectId===e)}).sort((s,r)=>r.updatedAt-s.updatedAt)}function zte(t,e,n){const i=new Map;for(const s of t){const r=oy(s,e,n),a=r.status==="home"?r.homeProjectId?[r.homeProjectId]:[]:r.destinations.map(c=>c.projectId);for(const c of new Set(a))i.set(c,(i.get(c)??0)+1)}return i}const yB=new Set;function Fte(t,e,n=Qo,i=yB){return Pte(t,e,n,i)}function Hte(t,e=Qo,n=yB){return zte(t,e,n)}const dM=["#f87171","#fb923c","#fbbf24","#a3e635","#34d399","#22d3ee","#60a5fa","#a78bfa","#f472b6","#94a3b8"];function fM(t){const e=t.trim();if(!e)return"";const n=e.startsWith("#")?e.slice(1):e;return/^[0-9a-f]{6}$/i.test(n)?`#${n.toLowerCase()}`:null}function ly(t){const e=t.color?.trim();if(e&&/^#[0-9a-f]{6}$/i.test(e))return e;const n=t.name||t.id;let i=0;for(let s=0;s<n.length;s+=1)i=i*31+n.charCodeAt(s)>>>0;return dM[i%dM.length]}function Wte(t){const e=[...(t.initial??"").trim()].slice(0,2).join("");return e?e.toLocaleUpperCase():[...t.name.trim()][0]?.toLocaleUpperCase()??"?"}function Jc({project:t,size:e="small",className:n=""}){const i=t.icon?.trim(),s={"--project-color":ly(t)};return o.jsx("span",{className:["project-avatar",`is-${e}`,i?"has-icon":"",n].filter(Boolean).join(" "),style:s,"aria-hidden":"true",children:i?o.jsx("img",{className:"project-avatar-image",src:i,alt:""}):o.jsx("span",{className:"project-avatar-text",children:Wte(t)})})}function pM(t,e){const n=new Map(t.map((c,u)=>[c.id,{chat:c,children:[],descendants:[],rank:u}])),i=new Map;for(const c of t){const u=e.get(c.id);if(!u||u===c.id||!n.has(u))continue;let d=u;for(;d&&d!==c.id;)d=i.get(d);d||i.set(c.id,u)}const s=[];for(const c of n.values()){const u=i.get(c.chat.id);u?n.get(u).children.push(c):s.push(c)}const r=c=>n.get(c.chat.id).rank,a=c=>{c.children.forEach(a),c.children.sort((u,d)=>r(u)-r(d)),c.descendants=c.children.flatMap(u=>[u.chat,...u.descendants]);for(const u of c.children)n.get(c.chat.id).rank=Math.min(r(c),r(u))};return s.forEach(a),s.sort((c,u)=>r(c)-r(u))}function nk(t,e){const n=t.tasks.find(s=>s.id===e.taskId);if(!n||n.status!=="completed"||t.attempts.some(s=>s.taskId===n.id&&["preparing","running"].includes(s.status)))return"Complete the task and settle its workers before archiving.";if(t.gates.some(s=>s.runId===n.runId&&s.status==="open"&&(!s.taskId||s.taskId===n.id)))return"Resolve the open decision before archiving.";const i=n.workspace;return i?.abandoned?"Only workers for merged tasks can be archived.":!i||!["retained","cleaned"].includes(i.state)||!i.delivery?.merged||i.delivery.dirty?"Refresh delivery status to verify a clean, merged task before archiving.":null}function ik(t,e,n=!1){const i=new Set(e.attempts.filter(s=>s.archivedAt!=null).map(s=>s.workerChatKey.replace(/^chat:/,"")));return t.filter(s=>i.has(s.id)===n)}const to=t=>["planning","running","waiting"].includes(t.status);function Fm(t,e){if(!e)return Qo;const n=t.runs.filter(s=>s.coordinatorChatKey===e).sort((s,r)=>Number(to(r))-Number(to(s))||r.createdAt-s.createdAt),i=new Set(n.map(s=>s.id));return{runs:n,reports:t.reports,tasks:t.tasks.filter(s=>i.has(s.runId)),attempts:t.attempts.filter(s=>i.has(s.runId)),gates:t.gates.filter(s=>i.has(s.runId)),messages:t.messages.filter(s=>i.has(s.runId)),notifications:t.notifications?.filter(s=>i.has(s.runId))}}function qte(t,e){const n=t.tasks.filter(a=>a.runId===e.id),i=t.gates.filter(a=>a.runId===e.id&&a.status==="open"),s=`${n.filter(a=>a.status==="completed").length}/${n.length} done`;return i.length?`Needs decision · ${s}`:n.some(a=>a.status==="blocked"||a.status==="failed")&&to(e)?`Needs attention · ${s}`:`${e.status.charAt(0).toUpperCase()+e.status.slice(1)} · ${s}`}function Ute(t,e){const n=qte(t,e),i=t.tasks.length,s=t.tasks.filter(r=>r.runId===e.id).length;return t.runs.length<2||i===s?n:`${n} · ${i} ${i===1?"task":"tasks"} in ${t.runs.length} runs`}function Vte(t,e,n){const i=new Set(t.map(a=>a.id)),s=new Map(e.runs.map(a=>[a.id,a])),r=new Set;for(const a of e.tasks){const c=e.attempts.filter(p=>p.taskId===a.id).sort((p,m)=>m.number-p.number),u=c.find(p=>p.id===a.activeAttemptId)??c[0],d=s.get(a.runId)?.coordinatorChatKey.replace(/^chat:/,"");if(!(!u||!d||!i.has(d)||!i.has(u.workerChatKey.replace(/^chat:/,""))))for(const p of c)p.id!==u.id&&r.add(p.workerChatKey.replace(/^chat:/,""))}return ik(t,e).filter(a=>a.id===n||!r.has(a.id))}function _B(t){const e=new Set(t.map(c=>c.id)),n=(c,u)=>c.name.localeCompare(u.name),i=c=>t.filter(u=>u.reportsTo===c).sort(n),s=[],r=new Set,a=(c,u)=>{if(!r.has(c.id)){r.add(c.id),s.push({agent:c,depth:u});for(const d of i(c.id))a(d,u+1)}};for(const c of t.filter(u=>!u.reportsTo||!e.has(u.reportsTo)).sort(n))a(c,0);return s}const sk={working:"Working",needs_you:"Needs you",blocked:"Blocked",stalled:"Stalled",queued:"Queued",idle:"Idle",unknown:"Unknown"},rk=["working","needs_you","blocked","stalled","queued","unknown","idle"],mM=["needs_you","blocked","stalled","working","queued","unknown","idle"],Kte=["planning","running","waiting"];function bB(t,e){const n=t.attempts.filter(i=>i.taskId===e.id);return n.find(i=>i.id===e.activeAttemptId)??[...n].sort((i,s)=>s.number-i.number)[0]}function wB(t,e,n,i,s){if(!e||e.archivedAt||!Kte.includes(e.status)||t.status==="completed"||t.status==="cancelled")return null;if(s>0)return{state:"needs_you",label:"Needs your approval"};if(i)return{state:"needs_you",label:"Waiting on a decision"};if(t.status==="failed")return{state:"blocked",label:"Failed"};if(t.status==="blocked")return{state:"blocked",label:"Blocked"};if(t.status==="pending"||t.status==="ready")return e.planApproval?.status==="pending"?{state:"queued",label:"Waiting for plan approval"}:{state:"queued",label:t.status==="ready"?"Ready to start":"Queued"};if(!n)return{state:"queued",label:"Starting"};const r=n.execution?.state;if(r)switch(r){case"executing":return{state:"working",label:"Executing"};case"waiting_tool":return{state:"working",label:"Running a tool"};case"queued":return{state:"queued",label:"Queued"};case"retrying":return{state:"stalled",label:"Retrying"};case"stalled":return{state:"stalled",label:"Stalled"};case"awaiting_report":return{state:"stalled",label:"Awaiting its report"};case"capacity_blocked":return{state:"blocked",label:"At capacity"};case"blocked":return{state:"blocked",label:"Blocked"};case"failed":return{state:"blocked",label:"Failed"};case"disconnected":return{state:"unknown",label:"Disconnected"};default:return{state:"unknown",label:"Settling"}}switch(n.status){case"preparing":return{state:"queued",label:"Preparing workspace"};case"running":return{state:"working",label:"Working"};case"blocked":return{state:"blocked",label:"Blocked"};case"failed":return{state:"blocked",label:"Failed"};default:return{state:"unknown",label:"Settling"}}}function Gte(t,e){const n=new Map(t.runs.map(s=>[s.id,s])),i=new Set(t.gates.filter(s=>s.status==="open"&&s.taskId).map(s=>s.taskId));return t.tasks.filter(s=>{const r=bB(t,s),a=e(s.id);return wB(s,n.get(s.runId),r,i.has(s.id),a)?.state==="working"}).length}function Yte(t,e,n){return e?{state:"needs_you",label:"Plan awaiting approval"}:n>0?{state:"needs_you",label:"Needs your answer"}:t==="busy"?{state:"working",label:"In conversation"}:t==="unknown"?{state:"unknown",label:"Session open"}:null}const Gv=(t,e)=>t.indexOf(e);function Xte(t){const{team:e,leads:n,snapshot:i,projects:s}=t;if(!e)return[];const r=new Map(s.map(S=>[S.id,S])),a=new Map((i?.runs??[]).map(S=>[S.id,S])),c=new Set((i?.gates??[]).filter(S=>S.status==="open"&&S.taskId).map(S=>S.taskId)),u=new Map,d=new Map,p=(S,C)=>{u.set(S,[...u.get(S)??[],C])},m=(S,C,A,N)=>{const E=d.get(S);(!E||E.at<N)&&d.set(S,{chatKey:C,title:A,at:N})};for(const S of i?.tasks??[]){const C=S.assignee?.id;if(!C||!i)continue;const A=a.get(S.runId),N=bB(i,S);N&&t.chatExists(N.workerChatKey)&&m(C,N.workerChatKey,S.title,N.updatedAt);const E=wB(S,A,N,c.has(S.id),N?t.waitingOn(N.workerChatKey):0);if(!E)continue;const M=S.destination;p(C,{key:`task:${S.id}`,kind:"task",...E,title:S.title,project:M?{id:M.projectId,name:r.get(M.projectId)?.name??M.projectName}:null,chatKey:N?.workerChatKey??null,runId:S.runId,taskId:S.id,at:N?.updatedAt??S.updatedAt})}for(const S of n){if(!t.chatExists(S.chatKey))continue;const C=i?kB(i,S.chatKey):null,A=i?.runs.filter(M=>M.coordinatorChatKey===S.chatKey&&!M.archivedAt).sort((M,L)=>L.updatedAt-M.updatedAt)[0],N=t.chatTitle(S.chatKey)??A?.objective??"Conversation";m(S.leadId,S.chatKey,N,Math.max(S.createdAt,A?.updatedAt??0));const E=Yte(t.leadActivity(S.chatKey),!!C,t.waitingOn(S.chatKey));E&&p(S.leadId,{key:`lead:${S.chatKey}`,kind:"lead",...E,title:N,project:S.crossProject?null:r.get(S.projectId)??null,crossProject:!!S.crossProject,chatKey:S.chatKey,runId:C?.run.id??A?.id,at:A?.updatedAt??S.createdAt})}const v=S=>{const C=[...u.get(S.id)??[]].sort((L,$)=>Gv(mM,L.state)-Gv(mM,$.state)||$.at-L.at),A={};for(const L of C)A[L.state]=(A[L.state]??0)+1;const N=[...C].sort((L,$)=>Gv(rk,L.state)-Gv(rk,$.state))[0],E=N?.state??(i?"idle":"unknown"),M=N?.label??(i?"Nothing in progress":"Work not loaded");return{...S,state:E,stateLabel:M,activities:C,counts:A,recent:d.get(S.id)??null}},x=_B(e).map(({agent:S,depth:C})=>v({id:S.id,name:S.name,avatar:S.avatar,detail:t.providerLabel(S),role:S.role,scope:S.projectId?r.get(S.projectId)??{id:S.projectId,name:"Unknown project"}:null,depth:C,removed:!1})),y=new Set(e.map(S=>S.id)),k=new Map;for(const S of i?.tasks??[])S.assignee&&!y.has(S.assignee.id)&&k.set(S.assignee.id,S.assignee.name);for(const S of n)y.has(S.leadId)||k.set(S.leadId,S.leadName);for(const[S,C]of k)u.get(S)?.length&&x.push(v({id:S,name:C,detail:"No longer registered",role:"",scope:null,depth:0,removed:!0}));return x}function Qte(t){const e=new Map;for(const n of t)e.set(n.state,(e.get(n.state)??0)+1);return rk.filter(n=>e.has(n)).map(n=>({state:n,count:e.get(n)}))}function kB(t,e){if(!e)return null;const n=t.runs.find(i=>i.coordinatorChatKey===e&&i.planApproval?.status==="pending"&&!["stopped","completed","failed"].includes(i.status));return n?{run:n,tasks:t.tasks.filter(i=>i.runId===n.id)}:null}const Zte={top:0,range:null,direction:null,travel:0,floating:!1,hidden:!1},Jte=2,ene=18,tne=12;function nne(t,e){const n=Math.max(0,e.range),i=Math.min(Math.max(0,e.top),n),s=i-t.top;if(i<=Jte)return{top:i,range:n,direction:null,travel:0,floating:!1,hidden:!1};const a=t.floating||i>=Math.max(1,e.menuHeight);if(e.preserve)return{top:i,range:n,direction:null,travel:0,floating:a,hidden:!1};const c=t.range===null?0:n-t.range,u=c!==0&&Math.sign(s)===Math.sign(c)&&Math.abs(s)<=Math.abs(c)+1;if(Math.abs(s)<1||u)return{...t,top:i,range:n,floating:a};const d=s>0?"down":"up",p=t.direction===d?t.travel+Math.abs(s):Math.abs(s);let m=t.hidden;return a?d==="down"&&p>=ene?m=!0:d==="up"&&p>=tne&&(m=!1):m=!1,{top:i,range:n,direction:d,travel:p,floating:a,hidden:m}}const TC=_.createContext([]),SB=_.createContext(()=>null);function RC(t){const e=_.useContext(TC);return t?e.find(n=>n.id===t):void 0}function ine({deleting:t,disabled:e=!1,deleteMs:n,onDelete:i}){const s=t?"Cancel delete":"Delete this chat";return o.jsxs("button",{className:`icon-btn topbar-delete ${t?"is-going":""}`,type:"button","aria-label":s,title:s,disabled:e,onClick:i,children:[t?o.jsx(CB,{ms:n}):o.jsx(sne,{}),o.jsx("span",{className:"topbar-action-label",children:s})]})}function CB({ms:t}){return o.jsxs("svg",{className:"chat-drain",width:"17",height:"17",viewBox:"0 0 16 16","aria-hidden":"true",children:[o.jsx("circle",{className:"chat-drain-track",cx:"8",cy:"8",r:"6.6"}),o.jsx("circle",{className:"chat-drain-arc",cx:"8",cy:"8",r:"6.6",style:{animationDuration:`${t}ms`}}),o.jsx("path",{className:"chat-drain-x",d:"M9.9 6.1 6.1 9.9M6.1 6.1l3.8 3.8"})]})}function sne(){return o.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M4 7h16"}),o.jsx("path",{d:"M9 7V4h6v3"}),o.jsx("path",{d:"m6 7 1 13h10l1-13"}),o.jsx("path",{d:"M10 11v5M14 11v5"})]})}function rne({chat:t,enabled:e,busy:n,getPreviewMessages:i,loadPreview:s,...r}){const a=_.useRef(null),c=_.useRef(void 0),[u,d]=_.useState(!1),p=_.useId(),m=()=>{clearTimeout(c.current),c.current=void 0},v=()=>{m(),d(!1)},x=()=>{m(),e&&(c.current=setTimeout(()=>d(!0),1500))},y=()=>{m(),c.current=setTimeout(()=>d(!1),160)};return _.useEffect(()=>(e||(clearTimeout(c.current),d(!1)),()=>clearTimeout(c.current)),[e]),_.useEffect(()=>{const k=S=>{S.key==="Escape"&&v()};return u&&document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[u]),o.jsxs(o.Fragment,{children:[o.jsx("button",{...r,ref:a,"aria-describedby":u&&e?p:void 0,onPointerEnter:k=>{k.pointerType==="mouse"&&x()},onPointerLeave:y,onFocus:k=>{k.currentTarget.matches(":focus-visible")&&x()},onBlur:v,onClick:k=>{v(),r.onClick?.(k)}}),u&&e&&o.jsx(ane,{id:p,chat:t,anchor:a.current,messages:i?.(t.id),loadPreview:s,busy:n,onEnter:m,onLeave:y,onClose:v},t.id)]})}function ane({id:t,chat:e,anchor:n,messages:i,loadPreview:s,busy:r,onEnter:a,onLeave:c,onClose:u}){const d=_.useRef(null),[p,m]=_.useState(e.messages),[v,x]=_.useState(i===void 0&&s?"loading":"ready"),[y,k]=_.useState({left:0,top:0}),S=i!==void 0;_.useEffect(()=>{if(S||!s){x("ready");return}let A=!1;x("loading");const N=setTimeout(()=>{A=!0,x("error")},8e3);return s(e,()=>A).then(E=>{A||(m(E),x("ready"))}).catch(()=>{A||x("error")}).finally(()=>clearTimeout(N)),()=>{A=!0,clearTimeout(N)}},[e.id,S,s]),_.useLayoutEffect(()=>{const A=()=>{const M=(n.closest(".chat")??n).getBoundingClientRect(),L=d.current.getBoundingClientRect(),$=M.right+12,V=$+L.width<=window.innerWidth-12?$:M.left-L.width-12;k({left:Math.max(12,Math.min(V,window.innerWidth-L.width-12)),top:Math.max(12,Math.min(M.top,window.innerHeight-L.height-12))})};A();const N=new ResizeObserver(A);N.observe(d.current),window.addEventListener("resize",u);const E=M=>{d.current?.contains(M.target)||u()};return document.addEventListener("scroll",E,!0),()=>{N.disconnect(),window.removeEventListener("resize",u),document.removeEventListener("scroll",E,!0)}},[n,u]);const C=Dte(i??p);return Ea.createPortal(o.jsxs("div",{ref:d,id:t,role:"tooltip",className:"chat-preview",style:y,onPointerEnter:a,onPointerLeave:c,children:[o.jsxs("div",{className:"chat-preview-head",children:[o.jsx("strong",{children:e.title}),r&&o.jsx("span",{children:"Working…"})]}),o.jsx("div",{className:"chat-preview-label",children:"Latest conversation"}),C.map(A=>o.jsxs("div",{className:"chat-preview-message",children:[o.jsx("span",{children:A.speaker}),o.jsx("p",{children:A.text})]},A.id)),v==="loading"&&o.jsx("p",{className:"chat-preview-note",children:"Loading latest messages…"}),v==="error"&&o.jsx("p",{className:"chat-preview-note",children:"Preview unavailable. Open the chat to try again."}),v==="ready"&&!C.length&&o.jsx("p",{className:"chat-preview-note",children:"No messages yet."}),o.jsx("div",{className:"chat-preview-foot",children:"Click chat to open · Use ••• for actions"})]}),document.body)}function jB({info:t,projects:e,limit:n=2,taskCount:i=!0}){const s=new Map(e.map(m=>[m.id,m]));if(t.status==="loading")return o.jsx("span",{className:"conversation-projects is-quiet","aria-label":"Work projects loading",children:"Projects loading…"});if(t.status==="discussion")return o.jsx("span",{className:"conversation-projects is-quiet",children:"Discussion"});if(t.status==="unknown")return o.jsx("span",{className:"conversation-projects is-quiet",children:"Project unknown"});if(t.status!=="projects")return null;const r=t.destinations.map(m=>{const v=s.get(m.projectId);return{id:m.projectId,name:v?.name??m.projectName??"Unknown project",style:v?{"--conversation-project-color":ly(v)}:void 0}}),a=r.slice(0,Math.max(1,n)),c=r.length-a.length,u=t.unknownTaskCount,d=LC(t,(m,v)=>s.get(m)?.name??v??"Unknown project"),p=`${t.taskCount} ${t.taskCount===1?"task":"tasks"}`;return o.jsxs("span",{className:"conversation-projects",title:d,"aria-label":`Work projects: ${d}`,children:[o.jsxs("span",{className:"conversation-project-chips","aria-hidden":"true",children:[a.map(m=>o.jsx("span",{className:`conversation-project-chip${m.style?" is-registered":""}`,style:m.style,children:m.name},m.id)),c>0&&o.jsxs("span",{className:"conversation-project-overflow",children:["+",c]}),u>0&&o.jsx("span",{className:"conversation-project-unknown",children:"+?"})]}),i&&o.jsx("span",{className:"conversation-project-task-count","aria-hidden":"true",children:p})]})}function AB({info:t,projects:e}){const n=new Map(e.map(c=>[c.id,c])),i=xB(t,c=>n.has(c)),s=i?n.get(i):void 0;if(s)return o.jsx(Jc,{project:s,size:"medium"});const r=t.status==="projects"&&t.destinations.length>1,a=t.status==="discussion";return o.jsx("span",{className:`project-avatar is-medium is-neutral${r?" is-several":""}${a?" is-discussion":""}`,"aria-hidden":"true",children:r?o.jsx(cne,{}):a?o.jsx(one,{}):t.status==="loading"?null:"?"})}function one(){return o.jsx("svg",{viewBox:"0 0 16 16",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"M3 3.5h10a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H7l-3 2.5v-2.5H3a1 1 0 0 1-1-1v-6a1 1 0 0 1 1-1Z"})})}function lne(t,e){const n=xB(t,s=>e.some(r=>r.id===s)),i=e.find(s=>s.id===n);return i?{"--chat-project-color":ly(i)}:void 0}function cne(){return o.jsxs("svg",{viewBox:"0 0 16 16",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("rect",{x:"2.5",y:"5.5",width:"8",height:"8",rx:"2"}),o.jsx("path",{d:"M5.5 3.5V3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-.5.5h-.5"})]})}function gM({label:t,items:e,open:n,onOpenChange:i,className:s="",disabled:r=!1,icon:a}){const c=_.useRef(null),u=_.useId();return o.jsxs(o.Fragment,{children:[o.jsx("button",{ref:c,className:`sidebar-menu-trigger ${s}`,type:"button","aria-label":t,title:t,"aria-haspopup":"menu","aria-expanded":n,"aria-controls":n?u:void 0,disabled:r,onClick:d=>{d.currentTarget.focus(),i(!n)},onKeyDown:d=>{(d.key==="ArrowDown"||d.key==="ArrowUp")&&(d.preventDefault(),i(!0))},children:a??o.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[o.jsx("circle",{cx:"5",cy:"12",r:"1.7"}),o.jsx("circle",{cx:"12",cy:"12",r:"1.7"}),o.jsx("circle",{cx:"19",cy:"12",r:"1.7"})]})}),n&&!r&&o.jsx(une,{id:u,label:t,anchor:c,items:e,onClose:()=>i(!1)})]})}function une({id:t,label:e,anchor:n,items:i,onClose:s}){const r=_.useRef(null),a=_.useRef(!1),c=_.useRef(s);c.current=s,_.useLayoutEffect(()=>{const d=r.current,p=n.current;p.focus({preventScroll:!0}),d.showModal(),(d.querySelector('button[aria-checked="true"]:not(:disabled)')??d.querySelector("button:not(:disabled)"))?.focus({preventScroll:!0});const m=()=>{const k=p.getBoundingClientRect(),S=window.visualViewport,C=S?.offsetLeft??0,A=S?.offsetTop??0,N=S?.width??window.innerWidth,E=S?.height??window.innerHeight,M=d.getBoundingClientRect();d.style.left=`${Math.max(C+8,Math.min(k.right-M.width,C+N-M.width-8))}px`;const L=k.bottom+4,$=L+M.height<=A+E-8?L:k.top-M.height-4;d.style.top=`${Math.max(A+8,Math.min($,A+E-M.height-8))}px`};m();const v=new ResizeObserver(m);v.observe(d);const x=()=>c.current(),y=k=>{(!(k.target instanceof Node)||!d.contains(k.target))&&x()};return window.addEventListener("resize",x),window.addEventListener("scroll",y,!0),window.visualViewport?.addEventListener("resize",x),()=>{v.disconnect(),d.close(),window.removeEventListener("resize",x),window.removeEventListener("scroll",y,!0),window.visualViewport?.removeEventListener("resize",x)}},[n]);const u=()=>{r.current?.close(),s()};return Ea.createPortal(o.jsx("dialog",{ref:r,id:t,className:"sidebar-dropdown",role:"menu","aria-label":e,onCancel:d=>{d.preventDefault(),u()},onPointerDown:d=>{a.current=d.target===d.currentTarget},onClick:d=>{a.current&&d.target===d.currentTarget&&u(),a.current=!1},onKeyDown:d=>{if(d.key==="Tab"){u();return}if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;d.preventDefault();const p=[...d.currentTarget.querySelectorAll("button:not(:disabled)")],m=p.indexOf(document.activeElement),v=d.key==="Home"?0:d.key==="End"?p.length-1:(m+(d.key==="ArrowDown"?1:-1)+p.length)%p.length;p[v]?.focus()},children:i.map(d=>o.jsxs("button",{type:"button",tabIndex:-1,role:d.checked===void 0?"menuitem":"menuitemradio","aria-checked":d.checked,className:[d.danger?"is-danger":"",d.checked?"is-checked":"",d.separator?"has-separator":""].filter(Boolean).join(" ")||void 0,disabled:d.disabled,title:d.title,onClick:()=>{d.keepOpen||u(),d.onSelect()},children:[d.icon,o.jsx("span",{children:d.label})]},d.id))}),document.body)}function hne(t){const e=new Set(t.map(r=>r.id)),n=new Set,i=[];let s=t;for(;s.length;){const r=s.filter(a=>a.dependsOn.every(c=>!e.has(c)||n.has(c)));if(!r.length){i.push({tasks:s,blocked:!0});break}i.push({tasks:r,blocked:!1});for(const a of r)n.add(a.id);s=s.filter(a=>!n.has(a.id))}return i}function dne(t){return new Map(t.flatMap(e=>e.tasks).map((e,n)=>[e.id,n+1]))}function fne(t){return t.assignee?{agent:t.worker?.agent,label:t.assignee.name}:t.worker?{agent:t.worker.agent,label:t.worker.model??""}:{label:"Chosen at dispatch"}}function NB(t,e,n){const i=t.destination?.repository??e.rootPath;return{project:t.destination?.projectName??n?.(e.workspaceId)??"This project",repository:mne(i),path:i}}function pne(t){return t.filter(e=>!e.parentTaskId&&!e.approvedAt&&e.status!=="cancelled").map(e=>e.id)}function EB(t){return t.filter(e=>e.status!=="cancelled"||!!e.approvedAt)}function mne(t){return t.split(/[\\/]/).filter(Boolean).pop()??t}function MB(t){const e=new Map;for(const n of t){if(!n?.id)continue;const i=n.batch||n.id;n.status===void 0||n.status==="pending"?e.set(i,"question"):n.status==="failed"&&!e.has(i)&&e.set(i,"delivery")}return e}const gne=new Set(["planning","running","waiting"]),vM={permission:0,safety:1,outage:2,question:3,delivery:4,gate:5,plan:6},Fb=t=>t?.startsWith("chat:")&&t.slice(5)||null;function vne(t){const{orchestration:e,parents:n}=t,i=new Map,s=p=>{i.has(p.key)||i.set(p.key,p)},r=p=>tk(p,n)??p,a=new Map;for(const p of e.attempts){const m=Fb(p.workerChatKey),v=m?a.get(m):void 0;m&&(!v||p.number>v.number)&&a.set(m,{runId:p.runId,taskId:p.taskId,number:p.number})}const c=(p,m,v,x=p)=>{const y=r(v),k=a.get(v);s({key:`${x}:${m}`,kind:p,rowId:y,openChatId:k?y:v,surface:"chat",runId:k?.runId,taskId:k?.taskId})},u=(p,m)=>{for(const[v,x]of Object.entries(m??{}))for(const y of x??[])y?.id&&c(p==="safety"&&y.kind==="outage"?"outage":p,y.id,v,p)};u("permission",t.asks),u("safety",t.safetyBlocks);for(const[p,m]of Object.entries(t.questions??{}))if(r(p)===p)for(const[v,x]of MB(m??[]))c(x,v,p);const d=new Map(e.runs.map(p=>[p.id,p]));for(const p of e.gates){const m=d.get(p.runId),v=Fb(m?.coordinatorChatKey);p.status!=="open"||!m||!v||m.archivedAt!=null||s({key:`gate:${p.id}`,kind:"gate",rowId:r(v),openChatId:v,surface:"run",runId:m.id,taskId:p.taskId})}for(const p of e.runs){const m=Fb(p.coordinatorChatKey);!m||p.planApproval?.status!=="pending"||!gne.has(p.status)||p.archivedAt!=null||EB(e.tasks.filter(v=>v.runId===p.id)).length!==0&&s({key:`plan:${p.id}:${p.planApproval.revision??0}`,kind:"plan",rowId:r(m),openChatId:m,surface:"chat",runId:p.id})}return[...i.values()].sort((p,m)=>vM[p.kind]-vM[m.kind])}function xne(t){const e=new Map;for(const n of t){const i=e.get(n.rowId);i?i.push(n):e.set(n.rowId,[n])}return e}function yne(t){const e=new Map;for(const n of t){if(!n.taskId)continue;const i=e.get(n.taskId);i?i.push(n):e.set(n.taskId,[n])}return e}const _ne={permission:"Permission needed",safety:"Review needed",outage:"Safety check was down",question:"Answer needed",delivery:"Delivery failed",gate:"Decision needed",plan:"Plan approval"},bne={permission:["permission request","permission requests"],safety:["blocked action to review","blocked actions to review"],outage:["safety check outage","safety check outages"],question:["question to answer","questions to answer"],delivery:["failed answer delivery","failed answer deliveries"],gate:["decision","decisions"],plan:["plan to approve","plans to approve"]};function cy(t){return t.length===0?"":t.length===1?_ne[t[0].kind]:`Action needed · ${t.length}`}function wne(t){const e=new Map;for(const n of t)e.set(n.kind,(e.get(n.kind)??0)+1);return[...e].map(([n,i])=>`${i} ${bne[n][i===1?0:1]}`).join(", ")}function kne(t){return`[data-pending-keys~="${t.replace(/["\\]/g,"\\$&")}"]`}const xM=[],Sne={forRow:()=>xM,forTask:()=>xM,reveal:()=>{}},LB=_.createContext(Sne);function rg(){return _.useContext(LB)}function uy({actions:t,subject:e,className:n=""}){const{reveal:i}=rg();if(t.length===0)return null;const s=cy(t),r=wne(t),a=t.length>1;return o.jsxs("button",{type:"button",className:`pending-action-badge${n?` ${n}`:""}`,"data-kind":a?"several":t[0].kind,"aria-label":`${s} for ${e}: ${r}. Show ${a?"the first one":"it"}`,title:`${r}. Click to show ${a?"the first one":"it"}.`,onClick:c=>{c.stopPropagation(),i(t[0])},children:[o.jsx(jne,{}),o.jsx("span",{className:"pending-action-text",children:s})]})}function Cne(t,e=document){const n=[...e.querySelectorAll(kne(t))].map(s=>s.classList.contains("pending-target")?s.firstElementChild:s).find(s=>!!s&&s.getClientRects().length>0);if(!n)return!1;const i=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;return n.scrollIntoView?.({block:"center",behavior:i?"auto":"smooth"}),n.tabIndex<0&&!n.hasAttribute("tabindex")&&n.setAttribute("tabindex","-1"),n.focus({preventScroll:!0}),n.classList.remove("pending-revealed"),n.offsetWidth,n.classList.add("pending-revealed"),window.setTimeout(()=>n.classList.remove("pending-revealed"),1700),!0}function jne(){return o.jsxs("svg",{className:"pending-action-icon",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"12",cy:"12",r:"9"}),o.jsx("path",{d:"M12 7.5v5.5"}),o.jsx("path",{d:"M12 16.5h.01"})]})}const Hb=new Set,Ane=new Map,TB="octiq.chat.collapsed-agents",RB="octiq.chat.filter";function Nne(){const t=ar(RB);return uz(t)?t:"active"}function Ene(){try{const t=JSON.parse(ar(TB)??"[]");return new Set(Array.isArray(t)?t.filter(e=>typeof e=="string"):[])}catch{return new Set}}function Mne({orchestration:t=Qo,ledgerSnapshot:e,ledgerUnavailable:n=!1,coordinatorChatKeys:i=Hb,projects:s,shelved:r,deletedCount:a=0,onShowDeleted:c,conversations:u,currentConversation:d,running:p,busy:m,deleting:v=Hb,leaving:x=Hb,deleteMs:y=2e3,onPickConversation:k,getPreviewMessages:S,loadPreview:C,onNewChat:A,newLabel:N="New task",allowEmptyCreate:E=!0,onDelete:M,onPin:L,onToggleDone:$,onRename:V,onArchiveWorker:X,branches:D={},chatParents:Q=Ane,onResize:P,onCollapse:z,onSearch:H,onSettings:W,onAgents:F,onProjects:Y,onPullRequests:J,activeView:te=null}){const I=_.useMemo(()=>MC(u,Q),[u,Q]),[U,Z]=_.useState(Ene),[R,K]=_.useState(Nne),[O,ie]=_.useState(()=>new Set),[re,ve]=_.useState(!1),[le,Re]=_.useState(null),[De,Ke]=_.useState(null),[xe,Te]=_.useState(!1),[vt,Bt]=_.useState(!1),[Ot,At]=_.useState(null),[nn,ke]=_.useState(Zte),Je=_.useContext(SB),at=rg(),it=_.useRef(null),We=_.useRef(void 0),pn=_.useRef({x:0,y:0}),he=_.useRef(!1),Me=_.useRef(null),ze=_.useRef(new Set(I.map(ye=>ye.id))),ut=[...s,...r],de=e===void 0?t:e,st=new Map(ut.map(ye=>[ye.id,ye])),Tn=new Map(I.map(ye=>[ye.id,ye])),qt=ik(I,t,!0),on=ik(I,t);_.useEffect(()=>{ie(ye=>{const jt=new Set(ye);for(const Yt of ye){const Zn=Tn.get(Yt);(!Zn||(R==="active"?!Pc(Zn):R!=="done"||Pc(Zn)))&&jt.delete(Yt)}return jt.size===ye.size?ye:jt})},[I,R]);const An=xe?qt:$1(on,R,d,O),kt=_.useMemo(()=>Vte(I,t,d),[I,t,d]),bn=_.useMemo(()=>pM($1(kt,R,d,O),Q),[kt,Q,d,R,O]),Nn=_.useMemo(()=>pM(kt,Q),[kt,Q]),Ss=ye=>!!ye.chat.pinned||ye.descendants.some(jt=>jt.pinned),ti=xe?[]:Nn.filter(Ss),cs=xe?qt.map(ye=>({chat:ye,children:[],descendants:[]})):bn.filter(ye=>!Ss(ye)),Qn=new Set;let xt=d?Q.get(d):void 0;for(;xt&&!Qn.has(xt);)Qn.add(xt),xt=Q.get(xt);const Ft=JSON.stringify([...Qn]);_.useEffect(()=>{const ye=JSON.parse(Ft);Z(jt=>ye.some(Yt=>jt.has(Yt))?new Set([...jt].filter(Yt=>!ye.includes(Yt))):jt)},[d,Ft]),_.useEffect(()=>{Ln(TB,JSON.stringify([...U]))},[U]),_.useEffect(()=>{Ln(RB,R)},[R]),_.useEffect(()=>{ze.current=new Set(I.map(ye=>ye.id))},[I]),_.useEffect(()=>()=>clearTimeout(We.current),[]);const On=()=>clearTimeout(We.current),_e=async(ye,jt)=>{if(!(!X||vt)){Bt(!0),At(null);try{await X(ye,jt)}catch(Yt){At(Yt instanceof Error?Yt.message:String(Yt))}finally{Bt(!1)}}},Ye=ye=>{ie(new Set),K(ye)},St=ye=>{const jt=Pc(ye),Yt=R==="active"&&!jt||R==="done"&&jt;ie(Zn=>{const ni=new Set(Zn);return Yt?ni.add(ye.id):ni.delete(ye.id),ni}),$(ye.id)},ot=({chat:ye,children:jt,descendants:Yt})=>{const Zn=!U.has(ye.id),ni=Yt.filter(Qe=>m.has(Qe.id)).length,wn=Yt.filter(Qe=>q0(Qe,d)).length,Ht=`chat-agents-${ye.id}`,Tt=Tn.get(Q.get(ye.id)??""),ii=v.has(ye.id),Rt=x.has(ye.id),gt=q0(ye,d),Xi=Pc(ye),be=st.get(ye.projectId),Fe=oy(ye,de,i,n),dt=LC(Fe,(Qe,Oi)=>st.get(Qe)?.name??Oi??"Unknown project"),Pt=lne(Fe,ut),mn=be?.name??"Unknown project",ln=t.attempts.find(Qe=>Qe.workerChatKey===`chat:${ye.id}`),gn=ln&&t.tasks.find(Qe=>Qe.id===ln.taskId),Vs=ln?.archivedAt!=null,Ks=ln&&!Vs?nk(t,ln):null,Ni=Fm(t,`chat:${ye.id}`),Qi=Ni.runs.find(Qe=>Qe.archivedAt==null)??Ni.runs[0],Gs=!xe&&Ni.runs.length>0,Cs=new Set(Ni.attempts.map(Qe=>Qe.workerChatKey)),Bi=Gs?jt.filter(Qe=>!Cs.has(`chat:${Qe.chat.id}`)):jt,Rr=Bi.length>0,Ta=Gs&&Cs.has(`chat:${d}`),me=Gte(Ni,Qe=>at.forTask(Qe).length),qe=gn?`${gn.title} · ${Vs?"archived":ln?.status}`:Qi?Ute(Ni,Qi):null,ft=Fe.status==="home"?ln?.branch||(Tt?"":D[ye.projectId]):"",kn=ft?`${mn} | ${ft}`:mn,cn=Mc(ye.modelId??null),bi=Je(`chat:${ye.id}`),Ys=ek(S?.(ye.id)??ye.messages),Xs=xe?[]:at.forRow(ye.id),su=ii?"Deleting…":Ys?.text??ye.latestResponse??(m.has(ye.id)?"Working…":"No response yet");return o.jsxs(Rne,{entering:!ze.current.has(ye.id),leaving:Rt,children:[o.jsxs("div",{className:["chat",ye.id===d?"is-on":"",p.has(ye.id)?"is-live":"",m.has(ye.id)?"is-busy":"",me>0?"is-tasks-running":"",ii?"is-going":"",Rt?"is-leaving":"",ye.pinned?"is-pinned":"",le===ye.id?"is-renaming":"",gt?"is-unread":"",Xi?"is-done":"",Ta?"is-worker-on":"",Xs.length?"has-pending":""].filter(Boolean).join(" "),style:Pt,children:[le===ye.id?o.jsx("form",{className:"chat-rename",onSubmit:Qe=>{Qe.preventDefault();const Oi=Qe.currentTarget.elements.namedItem("chat-title");Oi instanceof HTMLInputElement&&Oi.value.trim()&&V(ye.id,Oi.value),Re(null)},children:o.jsx("input",{name:"chat-title",className:"chat-rename-input",defaultValue:ye.title,"aria-label":"Chat title",maxLength:48,autoFocus:!0,onFocus:Qe=>Qe.currentTarget.select(),onBlur:Qe=>{Qe.currentTarget.value.trim()&&V(ye.id,Qe.currentTarget.value),Re(null)},onKeyDown:Qe=>{Qe.key==="Escape"&&(Qe.preventDefault(),Re(null))}})}):o.jsx(rne,{chat:ye,enabled:!ii&&!Rt&&!De,busy:m.has(ye.id),getPreviewMessages:S,loadPreview:C,className:"chat-btn",type:"button","aria-label":`${gt?"Unread, ":""}${ye.title}, ${dt}${ft?`, branch ${ft}`:""}${bi?`, with ${bi.name}`:cn?`, ${cn.name} ${cn.model}`:""}${m.has(ye.id)?", working":p.has(ye.id)?", session running":""}${me>0?`, ${me} ${me===1?"task":"tasks"} running`:""}${Xs.length?`, ${cy(Xs)}`:""}${Xi?", done":""}${ye.pinned?", pinned":""}`,disabled:Rt,"aria-current":ye.id===d?"page":void 0,"aria-description":`${Tt?`Agent chat under ${Tt.title}. `:""}Hover to preview. Hold for chat actions.`,onPointerDown:Qe=>{On(),he.current=!1,!(Qe.pointerType==="mouse"||ii||Rt||!window.matchMedia("(max-width: 859.98px), (pointer: coarse)").matches)&&(pn.current={x:Qe.clientX,y:Qe.clientY},We.current=setTimeout(()=>{he.current=!0,Ke(ye.id)},500))},onPointerMove:Qe=>{Math.hypot(Qe.clientX-pn.current.x,Qe.clientY-pn.current.y)>10&&On()},onPointerUp:On,onPointerCancel:On,onContextMenu:Qe=>{window.matchMedia("(max-width: 859.98px), (pointer: coarse)").matches&&(Qe.preventDefault(),On(),!ii&&!Rt&&Ke(ye.id))},onClick:()=>{if(he.current){he.current=!1;return}k(ye)},children:o.jsxs("span",{className:"chat-summary",children:[o.jsxs("span",{className:"chat-heading",children:[gt&&o.jsx("span",{className:"chat-unread-dot","aria-hidden":"true"}),o.jsx("span",{className:"chat-title",children:ye.title}),o.jsx("time",{className:"chat-time",dateTime:new Date(ye.updatedAt).toISOString(),title:new Date(ye.updatedAt).toLocaleString(),children:DC(ye.updatedAt)})]}),o.jsx("span",{className:"chat-snippet",children:EC(su)}),qe&&o.jsx("span",{className:"chat-workflow-status",title:qe,children:qe}),o.jsxs("span",{className:"chat-meta",children:[Fe.status==="home"?o.jsx("span",{className:"chat-project",children:o.jsx("span",{className:"chat-project-name",title:kn,children:kn})}):o.jsx(jB,{info:Fe,projects:ut,taskCount:!Qi}),bi?o.jsxs("span",{className:"chat-model chat-persona",title:`${bi.name}${cn?` · ${cn.name} ${cn.model}`:""}`,children:[o.jsx(ws,{name:bi.name,avatar:bi.avatar,id:bi.id??bi.name,size:14,removed:bi.removed,decorative:!0}),o.jsx("span",{children:bi.name})]}):cn&&o.jsxs("span",{className:"chat-model",title:`Active model: ${cn.name} · ${cn.model}`,children:[o.jsx(af,{agent:cn.agent,size:10}),o.jsx("span",{children:cn.model})]})]})]})}),le!==ye.id&&Xs.length>0&&o.jsx(uy,{className:"chat-pending",actions:Xs,subject:ye.title}),o.jsxs("button",{className:"chat-badge",type:"button","aria-pressed":Xi,title:Xi?"Double-click or double-tap to mark not done":"Double-click or double-tap to mark done","aria-label":`${Xi?"Mark not done":"Mark done"}: ${ye.title}`,"aria-description":"Double-click or double-tap. With a keyboard, press Enter or Space.",disabled:ii||Rt,onBlur:()=>{Me.current=null},onClick:Qe=>{Qe.stopPropagation();const Oi=Me.current;Me.current=null,Qe.detail===0||Oi?.chatId===ye.id&&Qe.timeStamp-Oi.at<=500?St(ye):Me.current={chatId:ye.id,at:Qe.timeStamp}},children:[o.jsx(AB,{info:Fe,projects:ut}),o.jsxs("svg",{className:"chat-badge-ring",viewBox:"0 0 32 32","aria-hidden":"true",children:[o.jsx("rect",{className:"chat-badge-track",x:"1",y:"1",width:"30",height:"30",rx:"8"}),o.jsx("rect",{className:"chat-badge-snake",x:"1",y:"1",width:"30",height:"30",rx:"8"}),o.jsx("rect",{className:"chat-badge-pellet",x:"1",y:"1",width:"30",height:"30",rx:"8"})]}),o.jsx("span",{className:"chat-badge-tick","aria-hidden":"true",children:o.jsx(Lne,{done:Xi})}),Xi&&o.jsx("span",{className:"chat-badge-check","aria-hidden":"true",children:o.jsx(Tne,{})}),ye.pinned&&o.jsx("span",{className:"chat-badge-pin","aria-hidden":"true",children:o.jsx(bM,{})})]}),le!==ye.id&&o.jsx(gM,{className:"chat-actions-trigger",label:`Actions for ${ye.title}`,open:De===ye.id,onOpenChange:Qe=>Ke(Qe?ye.id:null),disabled:Rt,icon:ii?o.jsx(CB,{ms:y}):void 0,items:[{id:"rename",label:"Rename chat",icon:o.jsx(Hne,{}),disabled:ii,onSelect:()=>Re(ye.id)},{id:"pin",label:ye.pinned?"Unpin chat":"Pin chat",icon:o.jsx(bM,{}),disabled:ii,onSelect:()=>L(ye.id)},...ln&&X?[{id:"archive",label:Vs?"Restore worker":"Archive worker",icon:o.jsx(yM,{}),disabled:vt||!!Ks||!Vs&&m.has(ye.id),title:Ks??(Vs?"Return this worker to the chat list.":"Hide this worker; its chat and task history are kept."),onSelect:()=>{_e(ln.id,!Vs)}}]:[],...Hd(ye.id,Q)?[]:[{id:"delete",label:ii?"Cancel delete":"Delete chat",icon:o.jsx(_M,{}),danger:!0,keepOpen:!ii,onSelect:()=>M(ye.id)}]]}),Rr&&o.jsxs("button",{className:"chat-children-toggle",type:"button","aria-label":`${Zn?"Collapse":"Expand"} agent chats for ${ye.title}`,"aria-expanded":Zn,"aria-controls":Ht,disabled:Rt,onClick:()=>Z(Qe=>{const Oi=new Set(Qe);return Oi.has(ye.id)?Oi.delete(ye.id):Oi.add(ye.id),Oi}),children:[o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"m9 5 7 7-7 7"})}),o.jsx("span",{children:`${Bi.length} ${Bi.length===1?"agent":"agents"}`}),ni>0&&o.jsxs("span",{className:"chat-children-working",children:[ni," working"]}),wn>0&&o.jsxs("span",{className:"chat-children-unread",children:[wn," unread"]})]})]}),Rr&&o.jsx("div",{id:Ht,hidden:!Zn,children:Zn&&Bi.length>0&&o.jsx("ul",{className:"chat-children","aria-label":`Agent chats for ${ye.title}`,children:Bi.map(ot)})})]},ye.id)},In=()=>{Te(!1),ie(new Set)},ht=[...dz(on,R).map(ye=>({id:ye.filter,label:ye.label,checked:!xe&&ye.checked,onSelect:()=>{In(),Ye(ye.filter)}})),...qt.length||xe?[{id:"archived",label:`Archived workers (${qt.length})`,icon:o.jsx(yM,{}),checked:xe,separator:!0,onSelect:()=>{Te(!0),ie(new Set)}}]:[],...a&&c?[{id:"trash",label:`Deleted chats (${a})`,icon:o.jsx(_M,{}),separator:!(qt.length||xe),onSelect:c}]:[]],Et=xe?"Archived":P1[R];return o.jsxs("nav",{className:"sidebar task-sidebar","aria-label":"Chats",children:[o.jsxs("div",{className:"task-chat-scroll",onScroll:ye=>{const jt=ye.currentTarget,Yt=!!it.current?.contains(document.activeElement),Zn={top:jt.scrollTop,range:jt.scrollHeight-jt.clientHeight,menuHeight:it.current?.offsetHeight??0,preserve:Yt};ke(ni=>nne(ni,Zn))},children:[o.jsxs("div",{ref:it,id:"chats-navigation",className:`sidebar-toolbar${nn.floating?" is-floating":""}${nn.hidden?" is-hidden":""}`,onFocusCapture:()=>ke(ye=>({...ye,hidden:!1,direction:null,travel:0})),children:[o.jsxs("div",{className:"sidebar-head",children:[o.jsx("img",{className:"sidebar-logo",src:"./icon-192.png",alt:"","aria-hidden":"true"}),o.jsxs("span",{className:"sidebar-title",children:["OctiqFlow ",o.jsxs("span",{className:"sidebar-version",children:["v","0.2.13"]})]}),z&&o.jsx("button",{className:"sidebar-collapse",type:"button",onClick:z,"aria-label":"Hide sidebar",title:"Hide sidebar",children:o.jsx(Bne,{})})]}),o.jsxs("ul",{className:"sidebar-places","aria-label":"App",children:[o.jsx("li",{children:o.jsxs("button",{className:"sidebar-place sidebar-new-chat",type:"button",onClick:A,children:[o.jsx(One,{}),o.jsx("span",{children:N})]})}),H&&o.jsx("li",{children:o.jsxs("button",{className:"sidebar-place",type:"button",onClick:H,"aria-current":te==="search"?"page":void 0,children:[o.jsx(Dne,{}),o.jsx("span",{children:"Search chats"})]})}),Y&&o.jsx("li",{children:o.jsxs("button",{className:"sidebar-place",type:"button",onClick:Y,"aria-current":te==="projects"?"page":void 0,children:[o.jsx(Fne,{}),o.jsx("span",{children:"Projects"})]})}),F&&o.jsx("li",{children:o.jsxs("button",{className:"sidebar-place",type:"button",onClick:F,"aria-current":te==="agents"?"page":void 0,children:[o.jsx(Pne,{}),o.jsx("span",{children:"Agents"})]})}),J&&o.jsx("li",{children:o.jsxs("button",{className:"sidebar-place",type:"button",onClick:J,"aria-current":te==="pulls"?"page":void 0,children:[o.jsx(zne,{}),o.jsx("span",{children:"Pull requests"})]})}),W&&o.jsx("li",{children:o.jsxs("button",{className:"sidebar-place",type:"button",onClick:W,"aria-current":te==="settings"?"page":void 0,children:[o.jsx($ne,{}),o.jsx("span",{children:"Settings"})]})})]})]}),Ot&&o.jsxs("div",{className:"sidebar-archive-error",role:"alert",children:[Ot,o.jsx("button",{type:"button",onClick:()=>At(null),children:"Dismiss"})]}),I.length>0||xe?o.jsxs("div",{className:"task-chat-content",children:[ti.length>0&&o.jsxs("section",{className:"sidebar-chat-section","aria-labelledby":"sidebar-pinned-heading",children:[o.jsx("h2",{id:"sidebar-pinned-heading",className:"sidebar-section-heading",children:"Pinned"}),o.jsx("ul",{className:"chat-list task-chat-list",children:ti.map(ot)})]}),o.jsxs("section",{className:"sidebar-chat-section","aria-labelledby":"sidebar-recent-heading",children:[o.jsxs("div",{className:"sidebar-section-head",children:[o.jsx("h2",{id:"sidebar-recent-heading",className:"sidebar-section-heading",children:xe?"Archived workers":"Recent"}),o.jsx(gM,{className:"sidebar-filter-trigger",label:`Show chats: ${Et}`,open:re,onOpenChange:ve,icon:o.jsxs(o.Fragment,{children:[o.jsx("span",{children:Et}),o.jsx(Ine,{})]}),items:ht})]}),cs.length>0?o.jsx("ul",{className:"chat-list task-chat-list",children:cs.map(ot)}):En()]})]}):o.jsxs("div",{className:"sidebar-empty",children:[o.jsx("span",{children:"No chats yet"}),E&&o.jsx("button",{type:"button",onClick:A,children:"Start your first chat"})]})]}),P&&o.jsx("span",{className:"nav-resizer",onPointerDown:P,role:"separator","aria-orientation":"vertical","aria-label":"Resize the chat column"})]});function En(){return xe?o.jsxs("div",{className:"sidebar-empty",role:"status",children:[o.jsx("span",{children:"No archived workers."}),o.jsx("button",{type:"button",onClick:In,children:"Show active chats"})]}):R!=="active"?o.jsxs("div",{className:"sidebar-empty",role:"status",children:[o.jsx("span",{children:R==="done"?"No chats are ticked off.":"Every chat is pinned."}),o.jsx("button",{type:"button",onClick:()=>Ye("active"),children:"Show active chats"})]}):on.some(jt=>Pc(jt)&&!jt.pinned)&&!An.some(jt=>!jt.pinned)?o.jsxs("div",{className:"sidebar-empty",role:"status",children:[o.jsx("span",{children:"Every chat is ticked off."}),o.jsx("button",{type:"button",onClick:()=>Ye("done"),children:"Show done chats"})]}):o.jsx("div",{className:"sidebar-empty",role:"status",children:o.jsx("span",{children:ti.length>0?"Every active chat is pinned.":"No active chats."})})}}function Lne({done:t}){return o.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:t?2.4:1.8,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"12",cy:"12",r:"9"}),t&&o.jsx("path",{d:"m8 12 2.8 2.8L16 9.6"})]})}function Tne(){return o.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"m5 12.5 4.5 4.5L19 7"})})}function DC(t){const e=new Date(t),n=new Date;return e.toDateString()===n.toDateString()?e.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):(n.setDate(n.getDate()-1),e.toDateString()===n.toDateString()?"Yesterday":e.toLocaleDateString([],{month:"short",day:"numeric",...e.getFullYear()!==n.getFullYear()?{year:"numeric"}:{}}))}function Rne({entering:t,leaving:e,children:n}){const[i,s]=_.useState(()=>t&&!(typeof window<"u"&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches));return _.useEffect(()=>{if(!i)return;const r=requestAnimationFrame(()=>s(!1));return()=>cancelAnimationFrame(r)},[i]),o.jsx("li",{className:["chat-row",i?"is-entering":"",e?"is-leaving":""].filter(Boolean).join(" "),children:o.jsx("div",{className:"chat-row-content",children:n})})}function Dne(){return o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"11",cy:"11",r:"7"}),o.jsx("path",{d:"m20 20-4-4"})]})}function Bne(){return o.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),o.jsx("path",{d:"M9 4v16M15 10l-2 2 2 2"})]})}function One(){return o.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M20 12.5V18a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h5.5"}),o.jsx("path",{d:"m12 12 7.5-7.5a2.12 2.12 0 0 1 3 3L15 15l-4 1 1-4Z"})]})}function yM(){return o.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M4 7h16"}),o.jsx("path",{d:"M6 7v12h12V7"}),o.jsx("path",{d:"M3 4h18v3H3z"}),o.jsx("path",{d:"M10 11h4"})]})}function _M(){return o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M3 6h18"}),o.jsx("path",{d:"M8 6V4h8v2"}),o.jsx("path",{d:"m6 6 1 14h10l1-14"}),o.jsx("path",{d:"M10 10v6M14 10v6"})]})}function bM(){return o.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M12 17v5"}),o.jsx("path",{d:"M5 17h14v-1.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V6h1a2 2 0 0 0 0-4H8a2 2 0 0 0 0 4h1v4.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24Z"})]})}function Ine(){return o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"m6 9 6 6 6-6"})})}function $ne(){return o.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"12",cy:"12",r:"3"}),o.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.6 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.6a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function Pne(){return o.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("rect",{x:"9",y:"3",width:"6",height:"5",rx:"1"}),o.jsx("rect",{x:"3",y:"16",width:"6",height:"5",rx:"1"}),o.jsx("rect",{x:"15",y:"16",width:"6",height:"5",rx:"1"}),o.jsx("path",{d:"M12 8v4M6 16v-2h12v2"})]})}function zne(){return o.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"6",cy:"5",r:"2"}),o.jsx("circle",{cx:"18",cy:"7",r:"2"}),o.jsx("circle",{cx:"6",cy:"19",r:"2"}),o.jsx("path",{d:"M6 7v10M8 5h4a6 6 0 0 1 6 6v-2"})]})}function Fne(){return o.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"})})}function Hne(){return o.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M12 20h9"}),o.jsx("path",{d:"M16.5 3.5a2.1 2.1 0 0 1 3 3L8 18l-4 1 1-4Z"})]})}const DB=_.createContext(null);function ak(t){return _.useContext(DB)?.[t]??null}function kh({title:t,back:e,actions:n,root:i=!1,className:s}){const r=ak("heading"),a=ak("actions"),c=o.jsxs(o.Fragment,{children:[e&&o.jsxs("button",{type:"button",className:`workspace-back${i?" is-root":""}`,onClick:e.onClick,"aria-label":e.ariaLabel??`Back to ${e.label}`,title:e.ariaLabel??`Back to ${e.label}`,children:[o.jsx(Wne,{}),o.jsx("span",{children:e.label})]}),o.jsx("div",{className:"workspace-heading",children:t})]}),u=n?o.jsx("div",{className:"workspace-actions",children:n}):null;return r?o.jsxs(o.Fragment,{children:[Ea.createPortal(c,r),n&&(a?Ea.createPortal(u,a):o.jsx("div",{className:"workspace-actions is-inline",children:n}))]}):o.jsxs("header",{className:`workspace-header${s?` ${s}`:""}`,children:[c,u]})}function Wne(){return o.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"m15 18-6-6 6-6"})})}function qne({projects:t,shelved:e,conversations:n,selectedProjectId:i,busy:s,chatParents:r,ledgerSnapshot:a=Qo,coordinatorChatKeys:c=new Set,allowNewTask:u=!0,onSelectProject:d,onOpenChat:p,onNewTask:m,onNewProject:v,onProjectSettings:x,onClose:y,onShowShelved:k,onRestoreProject:S}){const C=rg(),A=_.useRef(null),N=_.useRef(!0),[E,M]=_.useState(!1),[L,$]=_.useState(null);_.useEffect(()=>{if(N.current){N.current=!1;return}A.current?.focus({preventScroll:!0}),$(null)},[i]);const V=MC(n,r),X=[...t,...e],D=i===null?null:X.find(z=>z.id===i)??null;if(i!==null){const z=D?Fte(V,D.id,a,c??new Set):[],H=!!D&&e.some(W=>W.id===D.id);return o.jsxs("section",{className:"projects-page","aria-label":D?`${D.name} tasks`:"Project",children:[o.jsx(kh,{back:{label:"Projects",ariaLabel:"Back to projects",onClick:()=>d(null)},title:o.jsxs(o.Fragment,{children:[D&&o.jsx(Jc,{project:D,size:"small"}),o.jsx("h1",{ref:A,tabIndex:-1,children:D?.name??"Project unavailable"})]}),actions:D&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"projects-page-secondary",onClick:()=>x(D.id),children:"Project settings"}),H&&S&&o.jsx("button",{type:"button",className:"projects-page-primary",disabled:E,onClick:async()=>{M(!0),$(null);try{await S(D.id)}catch(W){$(W instanceof Error?W.message:String(W))}finally{M(!1)}},children:o.jsx("span",{children:E?"Restoring…":"Restore project"})}),u&&!H&&o.jsxs("button",{type:"button",className:"projects-page-primary",onClick:()=>m(D.id),children:[o.jsx(wM,{}),o.jsx("span",{children:"New task"})]})]})}),L&&o.jsx("p",{className:"projects-page-error",role:"alert",children:L}),o.jsxs("div",{className:"projects-page-body",children:[D&&(D.primary_path||H)&&o.jsxs("p",{className:"projects-page-meta",title:D.primary_path,children:[D.primary_path??"Shelved",D.primary_path&&H?" · Shelved":""]}),D?z.length===0?o.jsxs("div",{className:"projects-page-empty",role:"status",children:[o.jsxs("p",{children:["No tasks in ",D.name," yet."]}),u&&!H&&o.jsx("button",{type:"button",onClick:()=>m(D.id),children:"Start a task"})]}):o.jsxs(o.Fragment,{children:[o.jsx("h2",{className:"projects-page-count",children:z.length===1?"1 task":`${z.length} tasks`}),o.jsx("ul",{className:"projects-task-list","aria-label":`Tasks in ${D.name}`,children:z.map(W=>{const F=s.has(W.id),Y=Pc(W),J=C.forRow(W.id),te=[F&&"Working",Y&&"Done",W.pinned&&"Pinned"].filter(I=>!!I);return o.jsxs("li",{children:[o.jsxs("button",{type:"button",className:"projects-task",onClick:()=>p(W),"aria-label":[W.title,...J.length?[cy(J)]:[],...te].join(", "),children:[o.jsxs("span",{className:"projects-task-line",children:[o.jsx("span",{className:"projects-task-title",children:W.title}),o.jsx("time",{dateTime:new Date(W.updatedAt).toISOString(),children:DC(W.updatedAt)})]}),o.jsxs("span",{className:"projects-task-line",children:[o.jsx("span",{className:"projects-task-snippet",children:EC(W.latestResponse??(F?"Working…":"No response yet"))}),te.length>0&&o.jsx("span",{className:"projects-task-states","aria-hidden":"true",children:te.map(I=>o.jsx("span",{className:`is-${I.toLowerCase()}`,children:I},I))})]})]}),o.jsx(uy,{className:"projects-task-pending",actions:J,subject:W.title})]},W.id)})})]}):o.jsxs("div",{className:"projects-page-empty",role:"status",children:[o.jsx("p",{children:"This project was removed or is no longer in this profile."}),o.jsx("button",{type:"button",onClick:()=>d(null),children:"Show all projects"})]})]})]})}const Q=Hte(V,a,c??new Set),P=z=>{const H=Q.get(z.id)??0;return o.jsx("li",{children:o.jsxs("button",{type:"button",className:"projects-row",onClick:()=>d(z.id),"aria-label":`${z.name}, ${H===1?"1 task":`${H} tasks`}`,children:[o.jsx(Jc,{project:z,size:"medium"}),o.jsxs("span",{className:"projects-row-text",children:[o.jsx("span",{className:"projects-row-name",children:z.name}),z.primary_path&&o.jsx("span",{className:"projects-row-path",children:z.primary_path})]}),o.jsx("span",{className:"projects-row-count","aria-hidden":"true",children:H}),o.jsx(Une,{})]})},z.id)};return o.jsxs("section",{className:"projects-page","aria-label":"Projects",children:[o.jsx(kh,{root:!0,back:{label:"Chat",ariaLabel:"Back to chat",onClick:y},title:o.jsx("h1",{ref:A,tabIndex:-1,children:"Projects"}),actions:o.jsxs("button",{type:"button",className:"projects-page-primary",onClick:v,children:[o.jsx(wM,{}),o.jsx("span",{children:"New project"})]})}),o.jsx("div",{className:"projects-page-body",children:X.length===0?o.jsxs("div",{className:"projects-page-empty",role:"status",children:[o.jsx("p",{children:"No projects yet."}),o.jsx("button",{type:"button",onClick:v,children:"Add a project"})]}):o.jsxs(o.Fragment,{children:[t.length>0&&o.jsx("h2",{className:"projects-page-count",children:t.length===1?"1 project":`${t.length} projects`}),t.length>0&&o.jsx("ul",{className:"projects-list","aria-label":"Projects",children:t.map(P)}),e.length>0&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"projects-page-subhead",children:[o.jsx("h2",{className:"projects-page-count",children:"Shelved"}),k&&o.jsx("button",{type:"button",className:"projects-page-link",onClick:k,children:"Restore shelved projects"})]}),o.jsx("ul",{className:"projects-list","aria-label":"Shelved projects",children:e.map(P)})]})]})})]})}function Une(){return o.jsx("svg",{className:"projects-row-go",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"m9 18 6-6-6-6"})})}function wM(){return o.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:o.jsx("path",{d:"M12 5v14M5 12h14"})})}const BB=t=>t.replace(/\s+/g," ").trim();function Vne(t){const e=/^\d{4}-\d{2}-\d{2}T\S+\s+(?:ERROR|WARN|WARNING)\s+(.+)$/is.exec(t.trim());return e?BB(e[1]):null}function Kne(t){const e=BB(t);if(/collab spawn failed:.*agent thread limit reached/i.test(e))return{key:"agent-thread-limit",title:"A background agent could not start",detail:"The agent thread limit was reached. The current chat can keep going.",technical:t.trim()};if(/responses_websocket:.*failed to connect to websocket:.*504 Gateway Timeout/i.test(e))return{key:"codex-connection-timeout",title:"The Codex connection timed out",detail:"This was recorded in diagnostics. If the turn stops, send the message again.",technical:t.trim()};const n=Vne(t);if(n){const i=n.replace(/^[\w.-]+(?:::[\w.-]+)*:\s*/,"");return{key:`provider:${i.toLocaleLowerCase()}`,title:"The agent reported a background issue",detail:i,technical:t.trim()}}return{key:`message:${e.toLocaleLowerCase()}`,title:e}}function Gne(t){const e=new Map;for(const n of t){const i=Kne(n),s=e.get(i.key);s?e.set(i.key,{...s,detail:i.detail??s.detail,technical:i.technical??s.technical,count:s.count+1}):e.set(i.key,{...i,count:1})}return[...e.values()]}function Yne(){return o.jsxs("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.5","aria-hidden":"true",children:[o.jsx("circle",{cx:"10",cy:"10",r:"7.25"}),o.jsx("path",{d:"M10 8.6v4.2",strokeLinecap:"round"}),o.jsx("circle",{cx:"10",cy:"5.9",r:".65",fill:"currentColor",stroke:"none"})]})}function Xne(){return o.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5","aria-hidden":"true",children:o.jsx("path",{d:"m4.5 6 3.5 3.5L11.5 6",strokeLinecap:"round",strokeLinejoin:"round"})})}function Qne({notices:t,onClear:e}){const[n,i]=_.useState(!1),s=_.useMemo(()=>Gne(t),[t]);if(s.length===0)return null;const r=t.length,a=s.every(d=>!!d.technical),c=r===1?s[0].title:`${r} ${a?"background notices":"notices"}`,u=r===1&&s[0].detail?s[0].detail:`${s.length} ${s.length===1?"kind":"kinds"}, grouped quietly`;return o.jsxs("section",{className:`chat-notices ${n?"is-open":""}`,"aria-label":"Background notices",children:[o.jsxs("div",{className:"chat-notices-bar",children:[o.jsxs("button",{className:"chat-notices-toggle",type:"button","aria-expanded":n,onClick:()=>i(d=>!d),children:[o.jsx("span",{className:"chat-notices-icon",children:o.jsx(Yne,{})}),o.jsxs("span",{className:"chat-notices-copy",children:[o.jsx("span",{className:"chat-notices-title",children:c}),o.jsx("span",{className:"chat-notices-hint",children:u})]}),o.jsx("span",{className:"chat-notices-chevron",children:o.jsx(Xne,{})})]}),o.jsx("button",{className:"chat-notices-clear",type:"button","aria-label":"Clear all background notices",title:"Clear all",onClick:e,children:"×"})]}),n&&o.jsx("div",{className:"chat-notices-panel",children:s.map(d=>o.jsxs("article",{className:"chat-notice-item",children:[o.jsxs("div",{className:"chat-notice-head",children:[o.jsx("span",{children:d.title}),d.count>1&&o.jsxs("span",{className:"chat-notice-count",children:[d.count," times"]})]}),d.detail&&o.jsx("p",{children:d.detail}),d.technical&&o.jsxs("details",{className:"chat-notice-technical",children:[o.jsx("summary",{children:"Technical details"}),o.jsx("pre",{children:d.technical})]})]},d.key))})]})}function Wb(t){const[e,n]=_.useState(()=>typeof window>"u"?!1:window.matchMedia(t).matches);return _.useEffect(()=>{const i=window.matchMedia(t);n(i.matches);const s=r=>n(r.matches);return i.addEventListener("change",s),()=>i.removeEventListener("change",s)},[t]),e}const Zne="(min-width: 701px)",kM="(max-width: 859.98px)",Jne="(min-width: 1181px)",OB=18,eie=10,tie=24,SM=1.5,nie=350,iie=.4,CM=.5,sie=72;function rie(t,e){return!e.open&&t.x>OB?null:{phase:"watching",opening:!e.open,from:t,at:t,width:e.width}}function aie(t,e){if(t.phase==="dropped")return t;const n={...t,at:e};if(t.phase==="swiping")return n;const i=e.x-t.from.x,s=e.y-t.from.y;if(e.t-t.from.t>nie)return{...n,phase:"dropped"};const r=Math.abs(i),a=Math.abs(s);return a>eie&&r<a*SM?{...n,phase:"dropped"}:r<tie?n:(t.opening?i<0:i>0)?{...n,phase:"dropped"}:r<a*SM?{...n,phase:"dropped"}:{...n,phase:"swiping"}}function IB(t){const e=t.at.x-t.from.x,n=t.opening?e/t.width:1+e/t.width;return Math.min(1,Math.max(0,n))}function oie(t){if(t.phase!=="swiping")return null;const e=t.at.x-t.from.x,n=t.at.t-t.from.t,i=n>0?e/n:0;if(Math.abs(e)>=sie){if(i>CM)return"open";if(i<-CM)return"close"}return IB(t)>iie?"open":"close"}function lie({enabled:t,open:e,onChange:n}){const i=_.useRef(e);i.current=e;const s=_.useRef(n);return s.current=n,_.useCallback(r=>{if(!(!r||!t))return cie(r,()=>i.current,a=>s.current(a))},[t])}function cie(t,e,n){let i=null,s=0;const r=()=>{i?.phase==="swiping"&&(s=Date.now()+700),i=null,t.removeAttribute("data-drawer-swiping"),t.style.removeProperty("--swipe-p")},a=m=>{if(r(),m.touches.length!==1)return;s=0;const v=m.touches[0],x=e();if(x){const k=window.getSelection();if(k&&k.rangeCount>0&&!k.isCollapsed)return}const y=t.querySelector(".sidebar")?.offsetWidth||t.clientWidth;i=rie({x:v.clientX,y:v.clientY,t:m.timeStamp},{open:x,width:y}),i&&v.clientX<=OB&&m.cancelable&&m.preventDefault()},c=m=>{if(!i)return;if(m.touches.length!==1||!m.cancelable)return r();const v=m.touches[0];if(i=aie(i,{x:v.clientX,y:v.clientY,t:m.timeStamp}),i.phase==="dropped")return r();i.phase==="swiping"&&(m.preventDefault(),t.setAttribute("data-drawer-swiping",""),t.style.setProperty("--swipe-p",String(IB(i))))},u=m=>{const v=i&&oie(i);v&&m.cancelable&&m.preventDefault(),r(),v&&v==="open"!==e()&&n(v==="open")},d=m=>{i?.phase!=="swiping"&&Date.now()>=s||(m.preventDefault(),m.stopImmediatePropagation())},p=m=>{i?.phase!=="swiping"&&(m.key==="Enter"||m.key===" ")&&(s=0)};return t.addEventListener("touchstart",a,{passive:!1}),t.addEventListener("touchmove",c,{passive:!1}),t.addEventListener("touchend",u,{passive:!1}),t.addEventListener("touchcancel",r,{passive:!0}),t.addEventListener("click",d,!0),t.addEventListener("dblclick",d,!0),t.addEventListener("keydown",p,!0),()=>{t.removeEventListener("touchstart",a),t.removeEventListener("touchmove",c),t.removeEventListener("touchend",u),t.removeEventListener("touchcancel",r),t.removeEventListener("click",d,!0),t.removeEventListener("dblclick",d,!0),t.removeEventListener("keydown",p,!0),r()}}let Oc,S0=0;function ok(t,e){const n=++S0;Oc?.skipTransition(),Oc=void 0;const i=document.documentElement;delete i.dataset.zenTransition;let s=!1;const r=()=>{n!==S0||s||(s=!0,Ea.flushSync(e))},a=()=>{n===S0&&(Oc=void 0,delete i.dataset.zenTransition)},c=window.matchMedia("(prefers-reduced-motion: reduce)").matches;if(c||!document.startViewTransition){r(),c||document.querySelector(".app .main")?.animate?.([{opacity:.75},{opacity:1}],{duration:320,easing:"ease-out"});return}i.dataset.zenTransition=t;try{Oc=document.startViewTransition(r),Oc.ready.catch(()=>{}),Oc.finished.then(a,()=>{r(),a()})}catch{r(),a()}}function jM(){S0++,Oc?.skipTransition(),Oc=void 0,delete document.documentElement.dataset.zenTransition}const uie={opus:{color:"#b99cff",width:1.42,roundness:.42,bodyWidth:.96,beat:1.3},sonnet:{color:"#e07a59",width:1.46,roundness:.28,bodyWidth:.94,beat:1.05},haiku:{color:"#59c9c5",width:1.32,roundness:.24,bodyWidth:.76,beat:.8},fable:{color:"#e48db7",width:1.38,roundness:.16,bodyWidth:.9,beat:1.2},claude:{color:"#d97757",width:1.48,roundness:.38,bodyWidth:1.02,beat:1.15},astra:{color:"#d76bf0",width:1.4,roundness:.12,bodyWidth:.88,beat:.95},sol:{color:"#f1b84b",width:1.38,roundness:.45,bodyWidth:.98,beat:.9},terra:{color:"#78c892",width:1.56,roundness:.12,bodyWidth:1.12,beat:1.25},luna:{color:"#84a9ff",width:1.4,roundness:.4,bodyWidth:.8,beat:1.4},codex:{color:"#8eb3c3",width:1.44,roundness:.16,bodyWidth:.94,beat:1.1}};function hie(t){return t==="pi"?"codex":t.startsWith("pi-")?t.slice(3):t}const die={opus:{ears:"M 17 43 Q 5 30 11 16 Q 28 18 34 31 Z M 66 31 Q 72 18 89 16 Q 95 30 83 43 Z",inner:"M 19 34 L 16 23 Q 26 25 28 31 Z M 72 31 Q 74 25 84 23 L 81 34 Z",fringe:"M 15 48 Q 10 27 28 21 L 29 9 L 42 19 L 50 5 L 58 19 L 72 9 L 72 22 Q 91 30 85 49 L 74 41 L 72 46 Q 63 41 60 32 Q 53 43 43 46 L 45 35 Q 33 46 25 42 L 23 49 Z",shine:"M 25 29 Q 35 25 41 28 M 59 25 L 65 28",mark:"M 50 17 L 54 24 L 50 31 L 46 24 Z"},sonnet:{ears:"M 16 46 Q 5 31 9 8 Q 29 13 37 32 Z M 63 32 Q 71 13 91 8 Q 95 31 84 46 Z",inner:"M 19 34 L 15 17 Q 27 21 29 31 Z M 71 31 Q 73 21 85 17 L 81 34 Z",fringe:"M 15 49 Q 10 28 29 21 Q 40 18 45 11 L 45 19 Q 55 16 59 8 Q 65 14 63 21 Q 89 24 85 49 L 74 42 L 72 48 Q 60 42 57 33 Q 49 44 37 45 L 41 35 Q 31 43 24 42 L 22 50 Z",shine:"M 25 30 Q 33 26 39 27 M 64 27 L 70 29",mark:"M 48 27 Q 44 22 48 19 Q 48 23 51 23 Q 55 18 55 17 Q 60 26 54 29 Q 51 31 48 27 Z"},haiku:{ears:"M 33 29 Q 8 33 7 8 Q 31 6 36 27 Z M 64 27 Q 68 6 93 8 Q 92 32 67 29 Z",inner:"M 16 16 Q 27 16 30 26 Q 20 26 16 16 Z M 70 26 Q 74 16 84 16 Q 80 26 70 26 Z",fringe:"M 15 48 Q 10 23 36 21 Q 42 12 55 13 L 51 20 Q 83 15 87 40 L 84 50 L 74 41 Q 64 47 55 37 Q 50 46 43 46 L 44 36 Q 35 48 24 42 L 21 49 Z",shine:"M 24 31 Q 33 25 40 28 M 65 29 L 72 32",mark:"M 50 32 Q 38 29 41 20 Q 52 21 50 32 Q 49 19 61 20 Q 61 30 50 32 Z"},fable:{ears:"M 20 40 Q 5 24 16 4 Q 31 9 34 30 Z M 66 30 Q 70 8 84 4 Q 96 24 80 40 Z",inner:"M 21 27 Q 16 17 19 12 Q 26 17 27 28 Z M 73 28 Q 74 17 81 12 Q 84 17 79 27 Z",fringe:"M 15 49 Q 9 28 30 21 Q 36 17 42 21 Q 51 13 61 20 Q 90 22 86 50 L 77 44 L 74 51 Q 59 44 53 34 Q 46 45 34 45 L 36 36 Q 29 42 23 44 L 22 51 Z",shine:"M 24 31 Q 31 27 36 28 M 61 27 Q 68 26 73 31",mark:"M 50 31 C 34 22 44 15 50 22 C 56 15 67 22 50 31 Z"},claude:{ears:"M 23 43 C 3 45 2 27 13 24 C 6 13 22 7 30 20 L 37 32 Z M 63 32 L 70 20 C 78 7 94 13 87 24 C 98 27 97 45 77 43 Z",inner:"M 16 30 Q 13 19 24 23 L 28 32 Z M 72 32 L 76 23 Q 87 19 84 30 Z",fringe:"M 15 49 Q 8 35 18 26 Q 22 16 36 21 Q 44 10 53 20 Q 64 13 71 23 Q 91 23 86 49 L 76 42 L 74 49 Q 62 46 58 35 Q 50 45 41 46 L 42 36 Q 30 46 25 43 L 23 50 Z",shine:"M 24 31 Q 30 27 36 29 M 62 28 L 69 30",mark:"M 50 19 V 30 M 44 22 L 56 27 M 45 28 L 55 21"},astra:{ears:"M 15 44 L 7 11 L 24 18 L 31 13 L 37 32 Z M 63 32 L 69 13 L 76 18 L 93 11 L 85 44 Z",inner:"M 19 34 L 15 22 L 27 28 Z M 73 28 L 85 22 L 81 34 Z",fringe:"M 15 50 Q 11 27 32 21 L 39 12 L 47 18 L 57 9 L 60 19 Q 88 21 87 48 L 78 42 L 75 50 Q 62 44 61 31 Q 50 48 38 46 L 42 34 Q 31 45 25 41 L 22 51 Z",shine:"M 24 31 L 35 27 M 66 27 L 74 32",mark:"M 52 16 L 55 22 L 62 24 L 55 27 L 52 34 L 49 27 L 42 24 L 49 22 Z"},sol:{ears:"M 22 45 L 6 36 L 13 28 L 7 14 L 24 18 L 31 9 L 38 30 Z M 62 30 L 69 9 L 76 18 L 93 14 L 87 28 L 94 36 L 78 45 Z",inner:"M 19 32 L 17 24 L 28 27 L 27 35 Z M 73 35 L 72 27 L 83 24 L 81 32 Z",fringe:"M 14 49 L 10 38 L 18 33 Q 18 22 35 21 L 41 12 L 46 19 L 56 7 L 60 20 L 69 16 L 70 23 Q 86 26 86 40 L 89 50 L 76 43 L 75 50 Q 61 45 56 34 Q 52 43 43 46 L 44 36 Q 32 47 25 43 L 22 51 Z",shine:"M 25 31 L 36 27 M 65 29 L 71 31",mark:"M 54 25 A 5 5 0 1 0 44 25 A 5 5 0 1 0 54 25 Z M 49 16 V 17 M 49 33 V 34 M 40 25 H 41 M 57 25 H 58"},terra:{ears:"M 31 33 Q 7 30 6 11 Q 30 8 38 29 Z M 62 29 Q 70 8 94 11 Q 93 30 69 33 Z",inner:"M 15 17 Q 26 16 31 28 Q 20 26 15 17 Z M 69 28 Q 74 16 85 17 Q 80 26 69 28 Z",fringe:"M 13 49 Q 8 24 31 22 L 31 17 L 42 20 Q 46 12 58 13 L 56 20 Q 82 16 89 39 L 86 51 L 75 43 L 74 50 Q 59 47 55 34 Q 48 45 36 46 L 39 35 Q 29 44 23 43 L 21 52 Z",shine:"M 23 32 Q 29 27 35 29 M 65 27 L 73 32",mark:"M 47 32 Q 41 19 59 19 Q 61 32 47 32 Z M 47 32 L 55 24"},luna:{ears:"M 23 40 Q 5 22 20 5 Q 24 19 37 29 Z M 63 29 Q 76 19 80 5 Q 95 22 77 40 Z",inner:"M 24 29 Q 17 22 20 15 Q 24 24 29 27 Z M 71 27 Q 76 24 80 15 Q 83 22 76 29 Z",fringe:"M 15 49 Q 10 24 34 20 Q 45 13 61 20 Q 88 22 86 49 L 75 43 L 74 50 Q 57 45 57 32 Q 49 46 35 47 L 40 34 Q 31 44 24 42 L 22 50 Z",shine:"M 24 30 Q 31 26 37 28 M 65 28 L 72 31",mark:"M 54 17 A 8 8 0 1 0 59 30 A 9 9 0 0 1 54 17 Z"},codex:{ears:"M 17 44 L 8 32 L 8 16 L 24 16 L 35 31 Z M 65 31 L 76 16 L 92 16 L 92 32 L 83 44 Z",inner:"M 16 23 H 22 L 28 31 L 21 33 L 16 29 Z M 72 31 L 78 23 H 84 V 29 L 79 33 Z",fringe:"M 14 49 Q 12 26 31 22 L 36 15 L 47 20 L 57 13 L 63 22 Q 86 23 86 48 L 76 42 L 74 49 Q 61 44 57 33 Q 48 45 37 45 L 40 35 Q 30 44 24 42 L 22 50 Z",shine:"M 24 31 L 35 28 M 64 28 L 72 31",mark:"M 45 20 L 39 25 L 45 30 M 55 20 L 61 25 L 55 30 M 52 20 L 48 30"}},fie={idle:"M 43 75 Q 50 78 57 75 Q 56 84 50 84 Q 44 84 43 75 Z",still:"M 45 78 Q 50 81 55 78",think:"M 48 79 Q 53 76 58 78",work:"M 44 78 Q 49 81 56 76",asleep:"M 48 79 C 48 75 53 75 53 79 C 53 83 48 83 48 79 Z"};function BC({robot:t="sonnet",size:e=28,alert:n=!1,mood:i="idle",asleep:s=!1}){const r=hie(t),a=die[r],c=`mascot-iris-${_.useId()}`,u=s?"asleep":i,d=u==="think",p=u==="work",m=p?8:r==="haiku"||r==="luna"||r==="fable"?12:11;return o.jsxs("span",{className:`mascot${n?" is-alert":""}${s?" is-asleep":""}`,"data-robot":t,"data-mood":i,"data-expression":u,style:{width:e,height:e,"--mascot-size":`${e}px`,"--robot-accent":uie[r].color},"aria-hidden":"true",children:[o.jsxs("svg",{className:"mascot-avatar",viewBox:"0 0 100 100",width:e,height:e,fill:"none",focusable:"false",children:[o.jsx("defs",{children:o.jsxs("linearGradient",{id:c,x1:"0",y1:"0",x2:"0",y2:"1",children:[o.jsx("stop",{className:"mascot-iris-dark",offset:"0"}),o.jsx("stop",{className:"mascot-iris-color",offset:".65"}),o.jsx("stop",{className:"mascot-iris-light",offset:"1"})]})}),o.jsxs("g",{className:"mascot-avatar-character",children:[o.jsx("path",{className:"mascot-fur mascot-ears",d:a.ears}),o.jsx("path",{className:"mascot-ear-inner",d:a.inner}),o.jsx("path",{className:"mascot-collar",d:"M 33 81 Q 50 77 67 81 L 74 94 Q 51 101 26 94 Z"}),o.jsx("path",{className:"mascot-collar-fold",d:"M 32 84 L 48 92 L 41 97 L 28 92 Z M 68 84 L 52 92 L 59 97 L 72 92 Z"}),o.jsx("path",{className:"mascot-collar-gem",d:"M 50 87 L 54 92 L 50 97 L 46 92 Z"}),o.jsx("path",{className:"mascot-avatar-base",d:"M 16 49 C 14 28 29 20 50 20 C 71 20 86 28 84 49 L 89 63 L 82 65 L 85 73 L 77 73 C 72 85 61 91 50 91 C 39 91 28 85 23 73 L 15 73 L 18 65 L 11 63 Z"}),o.jsx("path",{className:"mascot-face-shadow",d:"M 14 61 L 20 64 L 18 70 L 26 70 Q 34 84 50 85 Q 68 85 78 71 L 83 72 L 77 73 C 72 85 61 91 50 91 C 39 91 28 85 23 73 L 15 73 L 18 65 L 11 63 Z"}),o.jsx("path",{className:"mascot-brow-shadow",d:"M 19 47 Q 25 34 50 34 Q 75 34 82 48 L 73 47 Q 62 49 55 42 Q 43 52 32 47 L 25 51 Z"}),o.jsx("path",{className:"mascot-fur mascot-fringe",d:a.fringe}),o.jsx("path",{className:"mascot-hair-shine",d:a.shine}),o.jsx("g",{className:`mascot-avatar-mark${r==="claude"||r==="codex"?" mascot-mark-lines":""}`,children:o.jsx("path",{d:a.mark})}),o.jsxs("g",{className:"mascot-avatar-face",strokeLinecap:"round",strokeLinejoin:"round",children:[o.jsxs("g",{className:"mascot-avatar-cheeks",children:[o.jsx("ellipse",{cx:"23",cy:"71",rx:"7",ry:"3.5"}),o.jsx("ellipse",{cx:"77",cy:"71",rx:"7",ry:"3.5"}),o.jsx("path",{className:"mascot-blush-lines",d:"M 20 70 L 19 72 M 24 70 L 23 72 M 76 70 L 75 72 M 80 70 L 79 72"})]}),o.jsx("g",{className:"mascot-avatar-eyes",children:s?o.jsxs("g",{className:"mascot-sleep-eyes",children:[o.jsx("path",{d:"M 25 59 Q 33 67 41 59 M 59 59 Q 67 67 75 59"}),o.jsx("path",{className:"mascot-lower-lash",d:"M 26 61 L 24 63 M 74 61 L 76 63"})]}):[33,67].map((v,x)=>{const y=d?57+x*2:59,k=v+(d?2:0);return o.jsxs("g",{children:[o.jsx("ellipse",{className:"mascot-eye-white",cx:v,cy:y,rx:"10",ry:m+1}),o.jsx("ellipse",{className:"mascot-avatar-eye",cx:k,cy:y+1,rx:"7.7",ry:m,fill:`url(#${c})`}),o.jsx("ellipse",{className:"mascot-pupil",cx:k,cy:y,rx:"3.4",ry:m*.66}),o.jsx("path",{className:"mascot-iris-glow",d:`M ${k-4.5} ${y+m-3} Q ${k} ${y+m} ${k+4.5} ${y+m-3}`}),o.jsx("ellipse",{className:"mascot-eye-glint",cx:k-2.7,cy:y-m*.43,rx:"3",ry:"3.4"}),o.jsx("circle",{className:"mascot-eye-glint mascot-eye-glint-small",cx:k+3.5,cy:y+4,r:"1.4"}),o.jsx("path",{className:"mascot-upper-lash",d:`M ${v-10} ${y-3} Q ${v-8} ${y-m-3} ${v+1} ${y-m-1} Q ${v+7} ${y-m} ${v+10} ${y-4}`}),o.jsx("path",{className:"mascot-lower-lash",d:`M ${v-6} ${y+m} Q ${v} ${y+m+2} ${v+5} ${y+m}`})]},v)})}),(d||p)&&o.jsxs("g",{className:"mascot-eyebrows",children:[o.jsx("path",{d:d?"M 26 43 Q 32 39 39 42":"M 26 45 L 39 48"}),o.jsx("path",{d:d?"M 61 45 Q 67 42 74 44":"M 61 48 L 74 45"})]}),o.jsx("path",{className:"mascot-nose",d:"M 48.5 71 Q 50 70 51.5 71 L 50 72 Z"}),o.jsx("path",{className:"mascot-avatar-mouth",d:fie[u]}),u==="idle"&&o.jsx("path",{className:"mascot-tongue",d:"M 47 81 Q 50 78 53 81 Q 50 84 47 81 Z"})]})]})]}),t.startsWith("pi")&&o.jsx("span",{className:"mascot-provider-badge","data-provider-mark":"pi",children:"P"}),s&&o.jsx("span",{className:"mascot-z",children:"z"}),n&&o.jsx("span",{className:"mascot-task-dot"})]})}function $B(t){if(/^[A-Za-z]:[\\/]/.test(t))return t.slice(0,3);const e=/^(?:\\\\|\/\/)[^\\/]+[\\/][^\\/]+/.exec(t);return e?e[0]:t.startsWith("/")?"/":null}function AM(t){return $B(t)!==null}function NM(t){const e=$B(t);if(!e)return null;const n=t.replace(e==="/"?/\/+$/:/[\\/]+$/,"");if(n.length<=e.length)return null;const i=e==="/"?n.lastIndexOf("/"):Math.max(n.lastIndexOf("/"),n.lastIndexOf("\\"));return i<e.length?e:n.slice(0,i)}function pie(t,e){return t.filter(n=>n.is_dir?!n.is_hidden&&!n.name.startsWith("."):e)}function OC({start:t,title:e,onPick:n,onClose:i,files:s=!1}){const[r,a]=_.useState(t),[c,u]=_.useState(t),[d,p]=_.useState([]),[m,v]=_.useState(null),[x,y]=_.useState(!0),k=_.useCallback(C=>{a(C),u(C)},[]);_.useEffect(()=>{let C=!0;return y(!0),ae.invoke("list_dir",{path:r}).then(A=>{if(!C)return;p(pie(A??[],s)),v(null);const N=(A??[])[0];if(N&&!AM(r)){const E=NM(N.path);E&&(a(E),u(E))}}).catch(A=>{C&&(p([]),v(A.message))}).finally(()=>C&&y(!1)),()=>{C=!1}},[r,s]),_.useEffect(()=>{const C=A=>A.key==="Escape"&&i();return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[i]);const S=NM(r);return o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"panel-scrim",onClick:i}),o.jsxs("div",{className:"fp-picker",role:"dialog","aria-label":e,children:[o.jsxs("header",{className:"fp-picker-head",children:[o.jsx("span",{className:"fp-picker-title",children:e}),o.jsx("button",{className:"panel-close",type:"button",onClick:i,"aria-label":"Close",children:"✕"})]}),o.jsxs("form",{className:"fp-picker-path",onSubmit:C=>{C.preventDefault(),k(c.trim())},children:[o.jsx("input",{className:"fp-picker-input",value:c,spellCheck:!1,autoCapitalize:"off",autoCorrect:"off",placeholder:"Folder path",onChange:C=>u(C.target.value)}),o.jsx("button",{className:"panel-btn",type:"submit",children:"Go"})]}),m&&o.jsx("div",{className:"panel-error",children:m}),o.jsxs("div",{className:"fp-picker-body",children:[S&&o.jsxs("button",{className:"fp-picker-row is-up",type:"button",onClick:()=>k(S),children:[o.jsx(EM,{}),o.jsx("span",{className:"fp-picker-name",children:".."})]}),x&&d.length===0&&!m&&o.jsx("div",{className:"dots","aria-label":"loading"}),!x&&d.length===0&&!m&&o.jsx("div",{className:"fp-picker-empty",children:s?"No files or visible folders in here.":"No visible folders in here."}),d.map(C=>o.jsxs("button",{className:`fp-picker-row ${C.is_dir?"":"is-file"}`,type:"button",onClick:()=>C.is_dir?k(C.path):n(C.path),children:[C.is_dir?o.jsx(EM,{}):o.jsx(mie,{}),o.jsx("span",{className:"fp-picker-name",children:C.name})]},C.path))]}),o.jsxs("footer",{className:"fp-picker-foot",children:[o.jsx("div",{className:"fp-picker-here",title:r,children:o.jsx("bdi",{children:r})}),!s&&o.jsx("button",{className:"panel-btn is-primary",type:"button",disabled:!AM(r),onClick:()=>n(r),children:"Use this folder"})]})]})]})}function EM(){return o.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"M3 7a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.7.9l.8 1.2a2 2 0 0 0 1.7.9H19a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"})})}function mie(){return o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z"}),o.jsx("path",{d:"M14 2v6h6"})]})}function gie({onReference:t,onUpload:e}){return o.jsxs(o.Fragment,{children:[o.jsxs("button",{type:"button",role:"menuitem",className:"picker-item",onClick:t,children:[o.jsx("span",{className:"picker-name",children:"Reference a file"}),o.jsx("span",{className:"picker-model",children:"on the machine running the agents"})]}),o.jsxs("button",{type:"button",role:"menuitem",className:"picker-item",onClick:e,children:[o.jsx("span",{className:"picker-name",children:"Upload a file"}),o.jsx("span",{className:"picker-model",children:"from this device — up to 12 MB per file"})]})]})}function Ol(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}const vie={isRepo:!1,current:"",branches:[],isWorktree:!1};function xie({projects:t,projectId:e,onProject:n,branch:i,branches:s=vie,onBranch:r,newWorktree:a,onNewWorktree:c,useSandbox:u=!1,onUseSandbox:d}){const p=t.filter(x=>Ol(x.name)!=="general"),m=i&&!s.branches.includes(i)?[i,...s.branches]:s.branches,v=s.loading?"Finding branches…":s.error?"Branches unavailable":s.isRepo?i||s.current||"No branch":"No Git repository";return o.jsxs("div",{className:"work-location","aria-label":"Work location",children:[o.jsxs("label",{className:"work-location-field",title:"Project",children:[o.jsx(yie,{}),o.jsx("span",{className:"sr-only",children:"Project"}),o.jsxs("select",{"aria-label":"Project",value:e??"",onChange:x=>n(x.target.value||null),children:[o.jsx("option",{value:"",children:"General"}),p.map(x=>o.jsx("option",{value:x.id,children:x.name},x.id))]})]}),o.jsx("span",{className:"work-location-divider","aria-hidden":"true"}),o.jsxs("label",{className:`work-location-field is-branch ${s.isRepo?"":"is-muted"}`,title:a?"Base branch":"Branch",children:[o.jsx(_ie,{}),o.jsx("span",{className:"sr-only",children:a?"Base branch":"Branch"}),o.jsxs("select",{"aria-label":a?"Base branch":"Branch",value:i,disabled:s.loading||!s.isRepo,onChange:x=>r(x.target.value),children:[!m.length&&o.jsx("option",{value:"",children:v}),m.map(x=>o.jsx("option",{value:x,children:x},x))]})]}),o.jsx("span",{className:"work-location-spacer"}),o.jsxs("label",{className:`worktree-choice ${s.isWorktree?"is-active":""}`,title:s.isWorktree?"This chat runs in a linked worktree":"Create a task branch in a new linked worktree",children:[o.jsx("input",{type:"checkbox",checked:a,disabled:!s.isRepo,onChange:x=>c(x.target.checked)}),o.jsx(bie,{}),o.jsx("span",{children:"New worktree"})]}),o.jsxs("label",{className:"worktree-choice sandbox-choice",title:"Prepare local test services and a separate database for this chat",children:[o.jsx("input",{type:"checkbox",checked:u,onChange:x=>d?.(x.target.checked)}),o.jsx("span",{children:"Use sandbox"})]}),s.error&&o.jsx("span",{className:"work-location-error",role:"status",children:s.error})]})}function yie(){return o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M3 7.5h7l2 2h9v9.5H3z"}),o.jsx("path",{d:"M3 7.5V5h7l2 2h9v2.5"})]})}function _ie(){return o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"6",cy:"5",r:"2"}),o.jsx("circle",{cx:"18",cy:"7",r:"2"}),o.jsx("circle",{cx:"6",cy:"19",r:"2"}),o.jsx("path",{d:"M6 7v10M8 10h4a6 6 0 0 0 6-1"})]})}function bie(){return o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"6",cy:"6",r:"2"}),o.jsx("circle",{cx:"18",cy:"6",r:"2"}),o.jsx("circle",{cx:"12",cy:"18",r:"2"}),o.jsx("path",{d:"M6 8v2a4 4 0 0 0 4 4h2M18 8v2a4 4 0 0 1-4 4h-2v2"})]})}function wie(t){return`pasted.${(t.split("/")[1]||"png").replace("jpeg","jpg")}`}function PB(t){const e=t;return e?.message||e?.name||String(t??"no reason given")}function kie(t){return t?.name==="NotAllowedError"?"Tap it again, then tap “Paste” when the browser asks. Or hold the box and choose Paste.":`The browser would not read the clipboard (${PB(t)}). Hold the box and choose Paste.`}async function Sie(t){const e=[];let n="";for(const i of t){const s=i.types.find(r=>r.startsWith("image/"));if(s){const r=await i.getType(s);e.push(new File([r],wie(s),{type:s}));continue}i.types.includes("text/plain")&&(n+=await(await i.getType("text/plain")).text())}return{files:e,text:n}}const qb="blank:new",Cie=()=>({text:"",attached:[]});class zB{held=new Map;keep(e,n){const i=e??qb;if(!n.text.trim()&&n.attached.length===0){this.held.delete(i);return}this.held.set(i,{text:n.text,attached:[...n.attached]})}take(e){const n=e??qb,i=this.held.get(n);return this.held.delete(n),i??Cie()}forget(e){this.held.delete(e??qb)}}function MM(t,e,n,i){const s=t.slice(n,i),r=(e==="codex"?/^([/$])(\S*)$/:/^(\/)(\S*)$/).exec(s);if(r)return{trigger:r[1],query:r[2],start:n,end:i}}function LM(t,e,n=t.length){const i=Math.max(0,Math.min(n,t.length));let s=i;for(;s>0&&!/\s/.test(t[s-1]);)s-=1;const r=t.slice(i).search(/\s/),a=r<0?t.length:i+r,c=MM(t,e,s,a);if(e==="claude")return s===0&&a===t.length?c:void 0;if(c)return c;let u=s;for(;u>0;){for(;u>0&&/\s/.test(t[u-1]);)u-=1;const d=u;for(;u>0&&!/\s/.test(t[u-1]);)u-=1;const p=MM(t,e,u,d);if(p)return p}}function TM(t,e){return e==="$"?t.replace(/^\//,"$"):t}function jie(t,e,n){const i=e.end<t.length&&/\s/.test(t[e.end])?n.trimEnd():n;return{text:t.slice(0,e.start)+i+t.slice(e.end),caret:e.start+i.length}}function Aie(t,e){const n=hi(t).models.filter(u=>u.flag),i=t==="claude"?n.filter(u=>["opus","sonnet","haiku","fable"].includes(u.flag)):[],s=e.models.flatMap(u=>{const d=ay(t,u.model,u.displayName,u.description??u.model);return d?[d]:[]}),r=[],a=new Set,c=e.source==="bundled"?n:[];for(const u of[...i,...s,...c]){const d=u.flag.toLowerCase();!d||a.has(d)||(a.add(d),r.push(u))}return r}const Ub=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches,Nie=8e3,Eie=typeof navigator<"u"&&!!navigator.clipboard&&!!(navigator.clipboard.read||navigator.clipboard.readText);function Mie(t,e){const[n,i]=_.useState({}),[s,r]=_.useState({}),a=_.useRef(new Set),c=_.useCallback((p,m=!1)=>{p==="pi"||!m&&a.current.has(p)||(a.current.add(p),r(v=>({...v,[p]:{...v[p],loading:!0,error:void 0}})),ae.invoke("agent_models",{agent:p}).then(v=>{i(x=>({...x,[p]:Aie(p,v)})),r(x=>({...x,[p]:{loading:!1,note:v.note??void 0}}))}).catch(v=>{r(x=>({...x,[p]:{loading:!1,error:String(v?.message??v)}}))}))},[]);_.useEffect(()=>{if(t)for(const p of["claude","codex"])e&&!e.includes(p)||c(p)},[t,e,c]);const u=_.useMemo(()=>Eh.flatMap(p=>n[p.id]??p.models),[n]),d=_.useCallback(p=>{a.current.delete(p),c(p,!0)},[c]);return{models:u,status:s,reload:d}}function FB({list:t,access:e,onPick:n}){const i=t.filter(a=>!a.bypass),s=t.find(a=>a.bypass),r=_.useRef(e===s?.id?i[i.length-1].id:e);return e!==s?.id&&(r.current=e),o.jsxs(o.Fragment,{children:[i.map(a=>o.jsxs("button",{type:"button",role:"menuitem",className:`picker-item ${a.id===e?"is-on":""}`,onClick:()=>n(a.id),children:[o.jsx("span",{className:"picker-name",children:a.label}),o.jsx("span",{className:"picker-model",children:a.hint}),a.id===e&&o.jsx("span",{className:"picker-tick","aria-hidden":"true",children:"✓"})]},a.id)),s&&o.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":e===s.id,className:`picker-item is-bypass ${e===s.id?"is-on":""}`,title:s.hint,onClick:()=>n(e===s.id?r.current:s.id),children:[o.jsx("span",{className:"picker-name",children:s.label}),o.jsx("span",{className:"picker-switch",children:e===s.id?"Enabled":"Enable"})]})]})}const RM=/\.(png|jpe?g|gif|webp)$/i,Lie=100;function HB(t){return`octiq.v2.history:${t||"new"}`}function DM(t){try{const e=JSON.parse(localStorage.getItem(HB(t))||"[]");return Array.isArray(e)?e.filter(n=>typeof n=="string"):[]}catch{return[]}}function Tie(t,e){try{localStorage.setItem(HB(t),JSON.stringify(e))}catch{}}function Rie(t,e,n,i,s){if(s==="older"){if(!t.length)return{index:e,text:n,draft:i};const a=Math.min(e+1,t.length-1);return{index:a,text:t[a],draft:e===-1?n:i}}if(e<0)return{index:e,text:n,draft:i};const r=e-1;return{index:r,text:r<0?i:t[r],draft:i}}function Die(t,e){return[t.trim(),...e.map(n=>n.trim())].filter(Boolean).join(`
81
81
 
82
82
  `)}function Bie({focusMode:t=!1,session:e,draftStore:n,focusOn:i,choice:s,onChoice:r,access:a,onAccess:c,onSend:u,onStop:d,putBack:p,onPutBack:m,busy:v,disabled:x,started:y,commands:k,onCommandOpen:S,onReloadSkills:C,skillsStatus:A,contextTokens:N,contextWindow:E,activity:M,turnStartedAt:L,turnTokens:$,turnApprox:V,thinking:X,thought:D,background:Q,effort:P,onEffort:z,lite:H,onLite:W,projects:F,projectId:Y,onProject:J,branch:te,branches:I,onBranch:U,newWorktree:Z,onNewWorktree:R,useSandbox:K,onUseSandbox:O,showWorkLocation:ie,cwd:re,onTerminal:ve,terminalOpen:le,onRestart:Re,installed:De,model:Ke,lastDurationMs:xe,lastCostUsd:Te,identity:vt,advanced:Bt}){const[Ot,At]=_.useState(""),[nn,ke]=_.useState(!1);_.useEffect(()=>{ke(!1)},[t]);const[Je,at]=_.useState(0),[it,We]=_.useState(!1),[pn,he]=_.useState(!1),[Me,ze]=_.useState(!1),[ut,de]=_.useState(0),st=hi(s.agent),Tn=st.access,qt=st.efforts,on=pB(s.agent),An=Tn.find(me=>me.id===a)??Tn[0],kt=qt.find(me=>me.id===P)??qt[Math.floor(qt.length/2)],bn=_.useRef(null),Nn=_.useRef(null),[Ss,ti]=_.useState(!1),[cs,Qn]=_.useState(!1),[xt,Ft]=_.useState([]),[On,_e]=_.useState(null),[Ye,St]=_.useState(null),[ot,In]=_.useState(()=>DM(e)),[ht,Et]=_.useState(-1);_.useEffect(()=>{In(DM(e)),Et(-1)},[e]);const En=me=>De!==void 0&&!De.includes(me),ye=De!==void 0&&De.length===0,jt=Mie(it||pn,De),Yt=_.useRef(""),[Zn,ni]=_.useState(!1),wn=_.useCallback((me,qe=!1)=>{const ft=Rie(ot,ht,Ot,Yt.current,me);if(Yt.current=ft.draft,Et(ft.index),At(ft.text),!qe)return;at(ft.text.length);const kn=bn.current;kn?.focus({preventScroll:!0}),requestAnimationFrame(()=>{kn&&kn.setSelectionRange(kn.value.length,kn.value.length)})},[ot,ht,Ot]),Ht=LM(Ot,s.agent,Je),Tt=Ht?.query,ii=Ht!==void 0;_.useEffect(()=>{ii&&S?.()},[ii,S]);const Rt=Tt===void 0?[]:(k??[]).filter(me=>me.id.toLowerCase().startsWith(Tt.toLowerCase())).sort((me,qe)=>+(qe.id.toLowerCase()===Tt.toLowerCase())-+(me.id.toLowerCase()===Tt.toLowerCase())).slice(0,40),gt=ii&&(Rt.length>0||!!C),Xi=Tt!==void 0&&Rt[ut]?.id.toLowerCase()===Tt.toLowerCase();_.useEffect(()=>{de(me=>me<Rt.length?me:0)},[Rt.length]);function be(me){const qe=Ht??LM(Ot,s.agent,bn.current?.selectionStart);if(!qe)return;const ft=jie(Ot,qe,TM(me.insert,qe.trigger));At(ft.text),at(ft.caret),requestAnimationFrame(()=>{bn.current?.focus(),bn.current?.setSelectionRange(ft.caret,ft.caret)})}_.useEffect(()=>{const me=bn.current;me&&(me.style.height="auto",me.style.height=`${Math.min(me.scrollHeight,420)}px`)},[Ot]);const Fe=_.useCallback(async me=>{for(const qe of me){if(qe.size>12*1024*1024){_e(`${qe.name}: file is larger than 12 MB`);continue}try{const ft=await qe.arrayBuffer();let kn="";const cn=new Uint8Array(ft);for(let Qe=0;Qe<cn.length;Qe+=8192)kn+=String.fromCharCode(...cn.subarray(Qe,Qe+8192));const bi=(qe.type.split("/")[1]||"bin").replace("jpeg","jpg"),Ys=qe.name||`pasted.${bi}`,Xs=RM.test(Ys),su=await ae.invoke("save_attachment",{dataBase64:btoa(kn),extension:bi,filename:Ys});_e(null),Ft(Qe=>[...Qe,{path:su,name:Ys,isImage:Xs,url:Xs?URL.createObjectURL(qe):void 0}])}catch(ft){_e(String(ft.message??ft))}}},[]),dt=_.useCallback(me=>{const qe=bn.current;if(!qe){At(ft=>ft+me);return}qe.focus({preventScroll:!0}),qe.setRangeText(me,qe.selectionStart,qe.selectionEnd,"end"),At(qe.value)},[]);_.useEffect(()=>mK(me=>dt(uK(me,re))),[dt,re]);const Pt=_.useCallback(async()=>{const me=navigator.clipboard?.read?navigator.clipboard.read():null;_e(null);const qe=ft=>{_e(kie(ft)),bn.current?.focus()};if(me){let ft;try{ft=await me}catch(kn){qe(kn);return}try{const{files:kn,text:cn}=await Sie(ft);kn.length&&await Fe(kn),cn&&dt(cn),!kn.length&&!cn&&_e("There is nothing to paste.")}catch(kn){_e(`Could not read what is on the clipboard (${PB(kn)}).`)}return}try{const ft=await navigator.clipboard.readText();ft?dt(ft):_e("There is nothing to paste.")}catch(ft){qe(ft)}},[Fe,dt]),mn=_.useCallback(me=>{_e(null),Ft(qe=>{const ft=new Set(qe.map(cn=>cn.path)),kn=me.filter(cn=>cn&&!ft.has(cn)).map(cn=>({path:cn,name:cn.split("/").filter(Boolean).pop()??cn,isImage:RM.test(cn)}));return[...qe,...kn]})},[]),ln=_.useCallback(me=>{for(const qe of me)qe.url&&URL.revokeObjectURL(qe.url)},[]),gn=_.useCallback(()=>{Ye&&ln(Ye.attached),St({text:Ot,attached:xt}),At(""),Ft([]),_e(null),Et(-1),Yt.current="",bn.current?.focus()},[xt,Ye,ln,Ot]),Vs=_.useCallback(()=>{Ye&&(At(Ye.text),Ft(Ye.attached),St(null),bn.current?.focus())},[Ye]);_.useEffect(()=>{if(!Ye)return;if(Ot||xt.length){ln(Ye.attached),St(null);return}const me=setTimeout(()=>{ln(Ye.attached),St(null)},Nie);return()=>clearTimeout(me)},[xt.length,Ye,ln,Ot]);const Ks=_.useRef({text:"",attached:[]});Ks.current={text:Ot,attached:xt};const Ni=_.useRef(n??new zB),Qi=_.useRef(e);_.useLayoutEffect(()=>{if(!n)return;Ni.current=n;const me=n.take(Qi.current);return(me.text||me.attached.length)&&(Ks.current=me,At(me.text),Ft(me.attached)),()=>n.keep(Qi.current,Ks.current)},[n]),_.useEffect(()=>{if(Qi.current===e)return;Ni.current.keep(Qi.current,Ks.current),Qi.current=e;const me=Ni.current.take(e);At(me.text),Ft(me.attached),_e(null),Yt.current="",St(qe=>(qe&&ln(qe.attached),null))},[e,ln]);const Gs=_.useRef(null);_.useEffect(()=>{!p?.length||Gs.current===p||(Gs.current=p,At(me=>Die(me,p.map(qe=>qe.text))),Ft(me=>{const qe=p.flatMap(ft=>ft.attachments);return[...me,...qe.filter(ft=>!me.some(kn=>kn.path===ft.path))]}),Et(-1),Yt.current="",m?.())},[p,m]);const Cs=_.useRef(i);_.useEffect(()=>{Cs.current!==i&&(Cs.current=i,!(Ub||x)&&bn.current?.focus())},[i,x]);function Bi(me){In(qe=>{const ft=qe[0]===me?qe:[me,...qe].slice(0,Lie);return Tie(e,ft),ft}),Et(-1),Yt.current=""}function Rr(){if(x)return;const me="👌 OK";u(me,[]),Bi(me)}function Ta(){const me=Ot.trim();!me&&xt.length===0||x||(u(me,xt),Bi(me),At(""),ln(xt),Ft([]),_e(null))}return o.jsxs("div",{className:`composer ${t?"composer-focus":""} ${t&&nn?"focus-options-open":""}`,"data-composer-style":s.composerStyle,"data-model-id":s.id,children:[t&&o.jsx("div",{className:"focus-activity",role:"status",children:M||(v?"Working…":" ")}),!!D?.trim()&&o.jsx("div",{className:"think-live","aria-live":"off",children:o.jsx("span",{className:"think-live-text",children:D})}),o.jsxs("div",{className:"composer-hint",children:[o.jsx("span",{className:"composer-hint-said",children:o.jsx($V,{tasks:Q??[],busy:v,children:v?o.jsx(Yie,{since:L,tokens:$,approx:V,activity:M,thinking:X,effort:kt.label.toLowerCase(),background:(Q??[]).length>0,robot:s.composerStyle,persona:vt}):o.jsxs(o.Fragment,{children:[vt?o.jsx(ws,{name:vt.name,avatar:vt.avatar,id:vt.id??vt.name,size:18,removed:vt.removed,className:"composer-hint-avatar"}):o.jsx(BC,{robot:s.composerStyle,mood:"idle"}),M??(Ub?"Enter for a new line":"Enter to send · Shift+Enter for a new line")]})})}),(Ke||xe!==void 0||Te!==void 0)&&o.jsxs("span",{className:"composer-last",title:[Ke&&`Model · ${Ke}`,xe!==void 0&&`Last turn · ${(xe/1e3).toFixed(1)}s`,Te!==void 0&&`Cost · $${Te.toFixed(3)}`].filter(Boolean).join(`
83
83
  `),children:[Ke&&o.jsx("span",{className:"composer-last-model",children:Ke}),xe!==void 0&&o.jsxs("span",{className:"composer-last-item",children:[o.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"12",cy:"12",r:"9"}),o.jsx("path",{d:"M12 7v5l3 2"})]}),o.jsx(Lt,{children:`${(xe/1e3).toFixed(1)}s`})]}),Te!==void 0&&o.jsx("span",{className:"composer-last-item",children:o.jsx(Lt,{children:`$${Te.toFixed(3)}`})})]}),o.jsxs("div",{className:"composer-history",role:"group","aria-label":"Sent message history",children:[o.jsx("button",{className:"history-step",type:"button","aria-label":"Show previous sent message",title:"Previous sent message",disabled:!ot.length||ht>=ot.length-1,onPointerDown:me=>me.preventDefault(),onClick:()=>wn("older",!0),children:o.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"m6 14 6-6 6 6"})})}),o.jsx("button",{className:"history-step",type:"button","aria-label":"Show next sent message",title:"Next sent message",disabled:ht<0,onPointerDown:me=>me.preventDefault(),onClick:()=>wn("newer",!0),children:o.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"m6 10 6 6 6-6"})})})]})]}),gt&&o.jsxs("div",{className:"slash",children:[o.jsx("div",{className:"slash-head",children:o.jsx(Lt,{children:Rt.length?`${Rt.length} command${Rt.length===1?"":"s"} · ${Xi?"Enter to send":"Tab to complete"}`:"No matching skills"})}),C&&o.jsxs("div",{className:"skill-reload",children:[o.jsx("button",{type:"button",disabled:A==="loading",onClick:C,children:A==="loading"?"Reloading…":"Reload skills"}),A&&A!=="loading"&&o.jsx("span",{role:"alert",children:A})]}),o.jsx("ul",{className:"slash-list",role:"listbox",children:Rt.map((me,qe)=>o.jsx("li",{children:o.jsx("button",{type:"button",role:"option","aria-selected":qe===ut,className:`slash-item ${qe===ut?"is-on":""}`,onMouseEnter:()=>de(qe),onClick:()=>be(me),children:TM(me.label,Ht?.trigger??"/")})},me.id))})]}),Zn&&o.jsx(OC,{start:re??"",title:"Reference a file",files:!0,onPick:me=>{mn([me]),ni(!1)},onClose:()=>ni(!1)}),o.jsxs("div",{className:"composer-box",children:[(xt.length>0||On||Ye)&&o.jsxs("div",{className:"attach",children:[xt.map(me=>o.jsxs("span",{className:`chip ${me.isImage?"is-image":""}`,title:me.path,children:[me.isImage?o.jsx(q6,{attachment:me}):o.jsx(Jie,{}),o.jsx("span",{className:"chip-name",children:me.name}),o.jsx("button",{className:"chip-x",type:"button","aria-label":`Remove ${me.name}`,onClick:()=>{ln([me]),Ft(qe=>qe.filter(ft=>ft.path!==me.path))},children:"✕"})]},me.path)),On&&o.jsx("span",{className:"attach-error",children:On}),Ye&&o.jsxs("span",{className:"attach-undo",children:["Cleared.",o.jsx("button",{className:"attach-undo-btn",type:"button",onClick:Vs,children:"Undo"})]})]}),o.jsx("div",{className:"composer-input-wrap",children:o.jsx("textarea",{ref:bn,className:"composer-input","aria-label":"Message",rows:2,value:Ot,placeholder:x?"Chat unavailable":mV(vt,s.name),disabled:x,onChange:me=>{ht>=0&&Et(-1),At(me.target.value),at(me.target.selectionStart)},onSelect:me=>at(me.currentTarget.selectionStart),onPaste:me=>{const qe=[...me.clipboardData?.files??[]];qe.length&&(me.preventDefault(),Fe(qe))},onKeyDown:me=>{if(gt&&Rt.length>0){if(me.key==="ArrowDown"){me.preventDefault(),de(Ys=>(Ys+1)%Rt.length);return}if(me.key==="ArrowUp"){me.preventDefault(),de(Ys=>(Ys-1+Rt.length)%Rt.length);return}const bi=me.key==="Enter"&&!me.shiftKey&&!me.metaKey&&!me.ctrlKey&&!me.altKey;if(me.key==="Tab"||bi&&!Xi){me.preventDefault(),be(Rt[ut]);return}if(me.key==="Escape"){me.preventDefault(),At("");return}}const qe=me.currentTarget,ft=qe.selectionStart===0&&qe.selectionEnd===0,kn=!Ot.slice(0,qe.selectionStart).includes(`
@@ -201,7 +201,7 @@ Reporter: ${t.source.modelId??"Unknown"}`].join(`
201
201
  --radius: 0.5rem;
202
202
  }
203
203
  `,hk="light",Wd="dark",dk="fun",kx=[{id:hk,name:"Light",scheme:"light",tokens:HM(Gse).light},{id:Wd,name:"Dark",scheme:"dark"},{id:dk,name:"Fun",scheme:"dark",tokens:HM(Yse).dark}],Xse={bg:"#101010",sunken:"#141414",card:"#1b1b1b",accent:"#f5f5f5",fg:"#fafafa"};function Qse(t){if(!t.tokens)return Xse;const e=IC(t.tokens);return{bg:e["--bg-0"],sunken:e["--bg-sunken"],card:e["--bg-1"],accent:e["--accent"],fg:e["--fg-0"]}}const XB="octiq.theme",fk="octiq-theme";function QB(){try{const t=localStorage.getItem(XB);return t===hk||t==="one-light"?hk:t===dk||t==="candyland"?dk:Wd}catch{return Wd}}function Zse(t){return kx.find(e=>e.id===t)??kx.find(e=>e.id===Wd)}function ZB(t){const e=Zse(t),n=document.documentElement;if(e.tokens){for(const[i,s]of Object.entries(IC(e.tokens)))n.style.setProperty(i,s);n.setAttribute("data-theme",e.id)}else{for(const i of Kse)n.style.removeProperty(i);n.removeAttribute("data-theme")}n.setAttribute("data-color-scheme",e.scheme);try{localStorage.setItem(XB,e.id)}catch{}window.dispatchEvent(new CustomEvent(fk,{detail:e.id}))}const UM={path:"",writable:!1};function Jse(){const[t,e]=_.useState(UM),[n,i]=_.useState(""),[s,r]=_.useState(!0),[a,c]=_.useState(!1),[u,d]=_.useState(!1),[p,m]=_.useState(!1),[v,x]=_.useState(""),[y,k]=_.useState(""),[S,C]=_.useState(""),[A,N]=_.useState(null),[E,M]=_.useState({query:"",path:""}),[L,$]=_.useState(null),V=_.useRef(0);_.useEffect(()=>{let P=!0;return ae.invoke("memory_vault_settings").then(z=>{P&&(e(z),i(z.path))}).catch(z=>{P&&x(String(z))}).finally(()=>{P&&r(!1)}),()=>{P=!1,V.current++}},[]);async function X(P){V.current++,c(!0),d(!1),x(""),N(null),$(null);try{const z=await ae.invoke("memory_vault_configure",{config:P});e(z),i(z.path)}catch(z){x(String(z))}finally{c(!1)}}async function D(P=0){const z=P?E:{query:y.trim(),path:S.trim()};if(!z.query)return;const H=++V.current;d(!0),x(""),P||(N(null),$(null),M(z));try{const W=await ae.invoke("memory_vault_call",{action:"search",args:{...z,offset:P,limit:30}});H===V.current&&N(F=>({...W,matches:P&&F?[...F.matches,...W.matches]:W.matches}))}catch(W){H===V.current&&x(String(W))}finally{H===V.current&&d(!1)}}async function Q(P,z=1){const H=++V.current;d(!0),x(""),$(null);try{const W=await ae.invoke("memory_vault_call",{action:"read",args:{path:P,startLine:z,lineCount:100}});H===V.current&&$(W)}catch(W){H===V.current&&x(String(W))}finally{H===V.current&&d(!1)}}return o.jsxs("section",{className:"settings-section memory-vault","aria-labelledby":"memory-vault-title",children:[o.jsx("header",{className:"settings-section-head",children:o.jsxs("div",{children:[o.jsx("h2",{id:"memory-vault-title",children:"Shared Memory Vault"}),o.jsx("p",{children:"One place for Claude, Codex, and your other agents to share knowledge."})]})}),s?o.jsx("p",{role:"status",children:"Loading vault settings…"}):o.jsxs(o.Fragment,{children:[o.jsxs("form",{className:"vault-connect",onSubmit:P=>{P.preventDefault(),X({path:n.trim(),writable:n.trim()===t.path&&t.writable})},children:[o.jsx("label",{htmlFor:"vault-path",children:"Vault folder on the server"}),o.jsxs("div",{className:"vault-input-row",children:[o.jsx("input",{id:"vault-path",value:n,placeholder:"Absolute folder path",disabled:a,onChange:P=>i(P.target.value),autoComplete:"off"}),o.jsx("button",{type:"button",className:"vault-button",disabled:a,onClick:()=>m(!0),children:"Browse"}),o.jsx("button",{type:"submit",className:"settings-primary",disabled:a||!n.trim()||n.trim()===t.path,children:a?"Saving…":"Connect"})]}),o.jsx("p",{className:"vault-help",children:"Use your existing Obsidian vault or any folder of Markdown notes. Files stay where they are."})]}),t.path?o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"vault-access",children:[o.jsxs("label",{className:"vault-write-toggle",children:[o.jsx("input",{type:"checkbox",checked:t.writable,disabled:a,onChange:P=>{X({...t,writable:P.target.checked})}}),o.jsx("span",{children:"Allow agents to update notes"})]}),o.jsx("p",{className:"vault-help",children:"Updates check the current revision and return a saved receipt. Archived notes remain recoverable. Private preference notes stay excluded."}),o.jsx("button",{type:"button",className:"vault-button",disabled:a,onClick:()=>{X(UM)},children:"Disconnect vault"})]}),o.jsxs("form",{className:"vault-search",onSubmit:P=>{P.preventDefault(),D()},children:[o.jsx("h3",{children:"Find a memory"}),o.jsx("label",{htmlFor:"vault-query",children:"Search notes"}),o.jsxs("div",{className:"vault-input-row",children:[o.jsx("input",{id:"vault-query",value:y,onChange:P=>k(P.target.value),placeholder:"A decision, project, or phrase"}),o.jsx("button",{type:"submit",className:"settings-primary",disabled:u||a||!y.trim(),children:"Search"})]}),o.jsxs("label",{htmlFor:"vault-search-folder",children:["Within folder ",o.jsx("span",{className:"vault-help",children:"(optional)"})]}),o.jsx("input",{id:"vault-search-folder",value:S,onChange:P=>C(P.target.value),placeholder:"For example, agent-zone/projects"})]}),u&&o.jsx("p",{role:"status",children:"Reading the vault…"}),A&&o.jsxs("div",{className:"vault-results","aria-label":"Vault search results",children:[o.jsxs("p",{className:"vault-help",children:[A.total," matching ",A.total===1?"note":"notes",A.truncated?" in this partial search. Narrow the folder to search further.":".",A.skipped>0?` ${A.skipped} unreadable or oversized entries skipped.`:""]}),A.matches.map(P=>o.jsxs("button",{className:"vault-result",type:"button",disabled:a||u,onClick:()=>{Q(P.path,Math.max(1,P.line-5))},children:[o.jsx("strong",{children:P.path}),o.jsxs("small",{children:["Line ",P.line]}),o.jsx("span",{children:P.snippet})]},P.path)),A.nextOffset!==null&&o.jsx("button",{type:"button",className:"vault-button",disabled:u||a,onClick:()=>{D(A.nextOffset)},children:"Show more"})]}),L&&o.jsxs("article",{className:"vault-note","aria-label":`Note: ${L.path}`,children:[o.jsx("h3",{children:L.path}),o.jsxs("p",{className:"vault-help",children:["From line ",L.startLine," · ",L.totalLines," lines"]}),o.jsx("pre",{children:L.content}),L.nextLine!==null&&o.jsx("button",{className:"vault-button",type:"button",disabled:u||a,onClick:()=>{Q(L.path,L.nextLine)},children:"Read next section"})]})]}):o.jsx("p",{className:"vault-help",children:"Connect a folder to make its notes available through OctiqFlow’s own vault tools."})]}),v&&o.jsx("p",{className:"set-warn",role:"alert",children:v}),p&&o.jsx(OC,{title:"Choose a memory vault",start:n||t.path,onClose:()=>m(!1),onPick:P=>{m(!1),X({path:P,writable:P===t.path&&t.writable})}})]})}const JB="octiq.agentsMode";function ere(){return ar(JB)==="on"}function tre(t){Ln(JB,t?"on":"off")}async function tf(t,e=!1){return await ae.invoke("team_list",{projectId:t,all:e})}async function nre(t){return await ae.invoke("team_save",{agent:t})}async function ire(t){await ae.invoke("team_delete",{id:t})}async function sre(t,e,n,i,s=!1){return await ae.invoke("team_brief",{chatKey:t,projectId:e,leadId:n,task:i,crossProject:s})}async function eO(){return await ae.invoke("team_leads",{})}async function Sx(){return await ae.invoke("team_head",{})}async function rre(t){return await ae.invoke("team_head_set",{id:t})}async function tO(){return await ae.invoke("team_home",{})}async function are(t){return await ae.invoke("team_home_set",{id:t})}async function ore(t,e,n,i,s){await ae.invoke("orchestration_plan_approve",{actorChatKey:t,runId:e,taskIds:n,revision:i,...s})}function VM(t,e,n=()=>!0){const i=new Set(t.map(s=>s.id));return t.filter(s=>!s.reportsTo||!i.has(s.reportsTo)).filter(s=>!s.projectId||n(s.projectId)).sort((s,r)=>+(r.id===e)-+(s.id===e)||s.name.localeCompare(r.name))}function lre(t){const{recipients:e,pickedId:n,headId:i,projectId:s}=t,r=c=>!c.projectId||c.projectId===s,a=e.find(c=>c.id===n);return a&&r(a)?a:e.find(c=>c.id===i)??e.find(c=>!c.projectId)??e.find(r)??null}function KM(t,e,n){return{...t?{id:t.id}:{},...t?.avatar?{avatar:t.avatar}:{},name:t?.name??e,role:t?.role??"",provider:n.agent,model:n.model,...t?{}:{removed:!0}}}function nO(t){const e=t.model.toLowerCase();return e.includes("fable")||e.includes("astra")}function pk(t){return ya.filter(e=>e.agent===t&&e.flag)}function cre(t){const e=ya.find(n=>n.agent===t.agent&&n.flag===t.model);return e?{choice:e,effort:Zw(t.agent,t.effort??"medium"),access:Ku(t.agent,t.access)}:null}function ure(t,e){switch(e.type){case"status":return t.kind!=="checking"&&t.kind!=="unavailable"?t:e.status.available?{kind:"idle"}:{kind:"unavailable",reason:e.status.reason,setup:e.status.setup};case"statusFailed":return t.kind==="checking"?{kind:"unavailable",reason:`Could not check avatar generation: ${e.error}`}:t;case"start":return t.kind==="idle"||t.kind==="candidate"||t.kind==="failed"?{kind:"starting"}:t;case"started":return t.kind==="starting"?{kind:"running",jobId:e.job.id,startedAt:e.job.startedAt}:t;case"startFailed":return t.kind==="starting"?{kind:"failed",error:e.error}:t;case"job":return t.kind!=="running"||t.jobId!==e.job.id||e.job.state==="running"?t:e.job.state==="done"?e.job.image?{kind:"candidate",image:e.job.image}:t:e.job.state==="cancelled"?{kind:"idle"}:{kind:"failed",error:e.job.error||"Generation failed."};case"cancel":return t.kind==="running"||t.kind==="starting"?{kind:"idle"}:t;case"accept":case"discard":return t.kind==="candidate"?{kind:"idle"}:t}}function hre(t,e){const n=Math.max(0,(e-t)/1e3);return n<45?"Drawing… usually about a minute":n<120?"Still drawing…":"Taking longer than usual…"}const iO=["image/png","image/jpeg","image/webp"],dre=8*1024*1024,GM=500*1024,Yv=256;function fre(t){return iO.includes(t.type)?t.size>dre?"That image is larger than 8 MB.":t.size===0?"That file is empty.":null:"Choose a PNG, JPEG or WebP image."}function pre(t,e){const n=Math.min(t,e);return{sx:Math.round((t-n)/2),sy:Math.round((e-n)/2),side:n}}function mre(t){return new Promise((e,n)=>{const i=new Image;i.onload=()=>e(i),i.onerror=()=>n(new Error("The image could not be read.")),i.src=t})}function gre(t){return new Promise((e,n)=>{const i=new FileReader;i.onload=()=>e(String(i.result)),i.onerror=()=>n(new Error("The file could not be read.")),i.readAsDataURL(t)})}async function YM(t){const e=typeof t=="string"?t:await gre(t),n=await mre(e),{sx:i,sy:s,side:r}=pre(n.naturalWidth,n.naturalHeight);if(!r)throw new Error("The image has no size.");const a=document.createElement("canvas");a.width=Yv,a.height=Yv;const c=a.getContext("2d");if(!c)throw new Error("This browser cannot resize images.");c.imageSmoothingQuality="high",c.drawImage(n,i,s,r,r,0,0,Yv,Yv);let u=a.toDataURL("image/webp",.9);if(u.startsWith("data:image/webp")||(u=a.toDataURL("image/png")),u.length>GM&&(u=a.toDataURL("image/jpeg",.85)),u.length>GM)throw new Error("The avatar is still too large after resizing.");return u}const vre=4e3;function xre({name:t,role:e,avatar:n,agentId:i,onChange:s}){const[r,a]=_.useReducer(ure,{kind:"checking"}),[c,u]=_.useState(""),[d,p]=_.useState(""),[m,v]=_.useState(()=>Date.now()),x=_.useRef(null),y=r.kind==="running"?r.jobId:null,k=_.useRef(null);k.current=y,_.useEffect(()=>{let E=!0;return ae.invoke("agent_avatar_status",{}).then(M=>{E&&a({type:"status",status:M})}).catch(M=>{E&&a({type:"statusFailed",error:String(M.message??M)})}),()=>{E=!1}},[]);const S=async E=>{if(E.state!=="done"){a({type:"job",job:E});return}try{const M=E.image?E:await ae.invoke("agent_avatar_job",{id:E.id});if(!M.image)throw new Error("The generated picture was not returned.");const L=await YM(M.image);k.current===E.id&&a({type:"job",job:{...M,image:L}})}catch(M){a({type:"job",job:{...E,state:"failed",error:String(M.message??M)}})}};_.useEffect(()=>{if(!y)return;const E=ae.on("agent-avatar-job",L=>{L?.id===y&&L.state!=="running"&&S(L)}),M=setInterval(()=>{v(Date.now()),ae.invoke("agent_avatar_job",{id:y}).then(L=>{L.state!=="running"&&S(L)}).catch(()=>{})},vre);return()=>{E(),clearInterval(M)}},[y]),_.useEffect(()=>()=>{k.current&&ae.invoke("agent_avatar_cancel",{id:k.current}).catch(()=>{})},[]);const C=async()=>{a({type:"start"});try{const E=await ae.invoke("agent_avatar_generate",{request:{name:t,role:e,description:c}});v(Date.now()),a({type:"started",job:E})}catch(E){a({type:"startFailed",error:String(E.message??E)})}},A=()=>{y&&ae.invoke("agent_avatar_cancel",{id:y}).catch(()=>{}),a({type:"cancel"})},N=async E=>{if(p(""),!E)return;const M=fre(E);if(M){p(M);return}try{s(await YM(E))}catch(L){p(String(L.message??L))}};return o.jsx(yre,{name:t,avatar:n,agentId:i,gen:r,now:m,description:c,uploadError:d,onDescription:u,onUpload:()=>x.current?.click(),onRemove:()=>s(""),onGenerate:()=>{C()},onCancel:A,onAccept:()=>{r.kind==="candidate"&&s(r.image),a({type:"accept"})},onDiscard:()=>a({type:"discard"}),fileInput:o.jsx("input",{ref:x,className:"avatar-editor-file",type:"file",accept:iO.join(","),"aria-label":"Upload an avatar image",onChange:E=>{N(E.target.files?.[0]),E.target.value=""}})})}function yre({name:t,avatar:e,agentId:n,gen:i,now:s,description:r,uploadError:a,onDescription:c,onUpload:u,onRemove:d,onGenerate:p,onCancel:m,onAccept:v,onDiscard:x,fileInput:y}){const k=t.trim()||"New agent",S=i.kind==="starting"||i.kind==="running",C=i.kind==="idle"||i.kind==="failed"||i.kind==="candidate";return o.jsxs("fieldset",{className:"avatar-editor team-form-wide",children:[o.jsx("legend",{children:"Avatar"}),o.jsxs("div",{className:"avatar-editor-row",children:[o.jsxs("div",{className:"avatar-editor-now",children:[o.jsx(ws,{name:k,avatar:e||void 0,id:n??k,size:56}),o.jsx("span",{className:"avatar-editor-caption",children:e?"Current":"Initials"})]}),i.kind==="candidate"&&o.jsxs("div",{className:"avatar-editor-now is-candidate","aria-live":"polite",children:[o.jsx(ws,{name:`${k}, generated`,avatar:i.image,id:n??k,size:56}),o.jsx("span",{className:"avatar-editor-caption",children:"Generated"})]}),o.jsxs("div",{className:"avatar-editor-actions",children:[o.jsx("div",{className:"avatar-editor-buttons",children:i.kind==="candidate"?o.jsxs(o.Fragment,{children:[o.jsx("button",{className:"settings-primary",type:"button",onClick:v,children:"Use this"}),o.jsx("button",{className:"vault-button",type:"button",onClick:p,children:"Regenerate"}),o.jsx("button",{className:"vault-button",type:"button",onClick:x,children:"Discard"})]}):S?o.jsx("button",{className:"vault-button",type:"button",onClick:m,children:"Cancel"}):o.jsxs(o.Fragment,{children:[o.jsx("button",{className:"vault-button",type:"button",onClick:u,children:"Upload image"}),o.jsx("button",{className:"vault-button",type:"button",onClick:p,disabled:!C||!t.trim(),title:t.trim()?"Uses your Codex sign-in with ChatGPT, and counts toward its usage":"Give the agent a name first",children:"Generate with ChatGPT"}),e&&o.jsx("button",{className:"vault-button",type:"button",onClick:d,children:"Remove"})]})}),y,(i.kind==="idle"||i.kind==="failed")&&o.jsx("input",{className:"avatar-editor-description",value:r,maxLength:500,placeholder:"Optional look, e.g. round glasses, calm, teal background","aria-label":"Describe the avatar (optional)",onChange:A=>c(A.target.value)}),o.jsxs("p",{className:"avatar-editor-status",role:"status","aria-live":"polite",children:[i.kind==="checking"&&"Checking whether ChatGPT can draw one here…",i.kind==="starting"&&"Starting…",i.kind==="running"&&hre(i.startedAt,s),i.kind==="candidate"&&"Use it, or regenerate. Nothing is saved until you press Save.",i.kind==="failed"&&o.jsx("span",{className:"avatar-editor-error",children:i.error}),i.kind==="unavailable"&&o.jsxs("span",{children:[i.reason,i.setup&&o.jsxs(o.Fragment,{children:[" ",i.setup]})," ","You can still upload an image."]}),a&&o.jsxs("span",{className:"avatar-editor-error",children:[" ",a]})]})]})]})]})}function sO({text:t,name:e,className:n}){const i=_.useRef(null),s=_.useId(),[r,a]=_.useState(!1),[c,u]=_.useState(!1);return _.useEffect(()=>a(!1),[t]),_.useLayoutEffect(()=>{const d=i.current;if(!d||r)return;const p=()=>u(d.scrollHeight>d.clientHeight+1);if(p(),typeof ResizeObserver>"u")return;const m=new ResizeObserver(p);return m.observe(d),()=>m.disconnect()},[t,r]),o.jsxs("div",{className:`agent-role${r?" is-open":""}${n?` ${n}`:""}`,children:[o.jsx("p",{className:"agent-role-text",id:s,ref:i,children:t}),o.jsx("button",{type:"button",className:"agent-role-toggle",hidden:!c&&!r,"aria-expanded":r,"aria-controls":s,"aria-label":r?`Show less of ${e}'s role`:`Full role for ${e}`,onClick:()=>a(!r),children:r?"Show less":"Full role"})]})}function _re({name:t,role:e,scope:n,how:i}){const s=_.useId(),[r,a]=_.useState(!1),c=[e.trim()?rO(e,64):"",n].filter(Boolean).join(" · ");return o.jsxs(o.Fragment,{children:[o.jsxs("p",{className:"hero-sub agent-welcome",children:[o.jsx("span",{className:"agent-welcome-summary",children:c}),o.jsxs("button",{type:"button",className:"agent-welcome-toggle","aria-expanded":r,"aria-controls":s,"aria-label":`Details about ${t}`,onClick:()=>a(!r),children:["Details",o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"m6 9 6 6 6-6"})})]})]}),o.jsxs("div",{className:"agent-welcome-details",id:s,role:"region","aria-label":`About ${t}`,tabIndex:r?0:-1,hidden:!r,children:[e.trim()&&o.jsx("p",{className:"agent-welcome-role",children:e.trim()}),o.jsx("p",{children:i})]})]})}function rO(t,e=56){const n=t.replace(/\s+/g," ").trim(),s=(n.match(/^.+?[.;:!?](?=\s|$)/)?.[0]??n).replace(/[.;:]$/,"");if(s.length<=e)return s;const r=s.slice(0,e+1),a=r.lastIndexOf(" ");return`${(a>e/2?r.slice(0,a):s.slice(0,e)).replace(/[\s,;:·-]+$/,"")}…`}const bre=["claude","codex"];function wre(t){return{name:"",role:"",agent:"claude",model:"sonnet",effort:"medium",access:"auto",projectId:t,reportsTo:null}}function kre({on:t,onToggle:e,projects:n}){const[i,s]=_.useState([]),[r,a]=_.useState(!0),[c,u]=_.useState(""),[d,p]=_.useState(null),[m,v]=_.useState(!1),[x,y]=_.useState(null),[k,S]=_.useState(null);_.useEffect(()=>{let D=!0;return Promise.all([tf(null,!0),Sx(),tO().catch(()=>null)]).then(([Q,P,z])=>{D&&(s(Q),y(P?.id??null),S(z))}).catch(Q=>{D&&u(String(Q.message??Q))}).finally(()=>{D&&a(!1)}),()=>{D=!1}},[]);const C=_.useMemo(()=>i.filter(D=>!D.projectId),[i]),A=async D=>{u("");try{const Q=await rre(D);y(Q?.id??null)}catch(Q){u(String(Q.message??Q))}},N=async D=>{u("");try{S(await are(D))}catch(Q){u(String(Q.message??Q))}},E=!!k&&n.some(D=>D.id===k),M=_.useMemo(()=>new Map(n.map(D=>[D.id,D.name])),[n]),L=_.useMemo(()=>_B(i),[i]),$=async()=>{if(d){v(!0),u("");try{const D=await nre({...d,projectId:d.projectId||null,reportsTo:d.reportsTo||null});D.memoryError&&u(`${D.name} was saved, but its memory note could not be created: ${D.memoryError}`),s(await tf(null,!0)),p(null)}catch(D){u(String(D.message??D))}finally{v(!1)}}},V=async D=>{u("");try{await ire(D.id),s(await tf(null,!0)),y((await Sx())?.id??null),d?.id===D.id&&p(null)}catch(Q){u(String(Q.message??Q))}},X=({agent:D,depth:Q})=>o.jsxs("li",{className:"team-row",style:{"--team-depth":Q},children:[o.jsxs("div",{className:"team-row-head",children:[Q>0&&o.jsx("span",{className:"team-row-branch","aria-hidden":"true",children:"└"}),o.jsx(ws,{name:D.name,avatar:D.avatar,id:D.id,size:28,decorative:!0}),o.jsxs("span",{className:"team-row-copy",children:[o.jsxs("span",{className:"team-row-name",children:[o.jsx("bdi",{children:D.name}),nO(D)&&o.jsx("span",{className:"team-tag",title:"Fable and Astra can lead a task but cannot take one",children:"lead only"})]}),o.jsxs("span",{className:"team-row-meta",children:[Xo[D.agent]," ",aO(D),D.effort?` · ${D.effort}`:""," · ",D.projectId?M.get(D.projectId)??"Removed project":"Every project"]})]}),o.jsxs("span",{className:"team-row-actions",children:[o.jsxs("button",{className:"vault-button team-row-action",type:"button","aria-label":`Edit ${D.name}`,title:"Edit",onClick:()=>p({...D,projectId:D.projectId??null,reportsTo:D.reportsTo??null}),children:[o.jsx(Cre,{}),o.jsx("span",{className:"team-row-action-text",children:"Edit"})]}),o.jsxs("button",{className:"vault-button team-row-action",type:"button","aria-label":`Remove ${D.name}`,title:"Remove",onClick:()=>{V(D)},children:[o.jsx(jre,{}),o.jsx("span",{className:"team-row-action-text",children:"Remove"})]})]})]}),D.role&&o.jsx(sO,{className:"team-row-role",text:D.role,name:D.name})]},D.id);return o.jsxs("section",{className:"settings-section team-settings","aria-labelledby":"settings-agents-title",children:[o.jsx("header",{className:"settings-section-head",children:o.jsxs("div",{children:[o.jsx("h2",{id:"settings-agents-title",children:"Agents"}),o.jsx("p",{children:"Register agents, then hand a task to one. It does the task, passes it on, or splits it across the others."})]})}),o.jsxs("div",{className:"settings-control-row",children:[o.jsxs("div",{className:"settings-control-copy",children:[o.jsx("h3",{children:"Agents mode"}),o.jsx("p",{children:"Work starts in one conversation with your CTO, who routes it to the right project and agent. Off, chats work as they always have."})]}),o.jsxs("button",{className:`set-switch${t?" is-on":""}`,type:"button",role:"switch","aria-checked":t,onClick:()=>e(!t),children:[o.jsx("span",{className:"set-switch-track","aria-hidden":"true"}),o.jsx("span",{className:"set-switch-text",children:t?"On":"Off"})]})]}),o.jsxs("div",{className:"settings-control-row",children:[o.jsxs("div",{className:"settings-control-copy",children:[o.jsx("h3",{children:"Talk to"}),o.jsx("p",{children:"The lead you talk to from any project. It picks the project, repository and teammate for each part of the work, and you approve the plan first."})]}),o.jsxs("select",{className:"team-head-select","aria-label":"Lead you talk to across projects",value:x??"",disabled:r||C.length===0,onChange:D=>{A(D.target.value||null)},children:[o.jsx("option",{value:"",children:C.length===0?"Add an agent for every project first":"No one"}),C.map(D=>o.jsxs("option",{value:D.id,children:[D.name,D.role?` · ${rO(D.role)}`:""]},D.id))]})]}),o.jsxs("div",{className:"settings-control-row",children:[o.jsxs("div",{className:"settings-control-copy",children:[o.jsx("h3",{children:"Home workspace"}),o.jsx("p",{children:"Where conversations with your lead live. It needs no code project or Git setup; the lead routes each task to a registered project."})]}),o.jsxs("select",{className:"team-head-select","aria-label":"Home workspace for your lead",value:E?k??"":"",disabled:r,onChange:D=>{N(D.target.value||null)},children:[o.jsx("option",{value:"",children:"General (default)"}),n.map(D=>o.jsx("option",{value:D.id,children:D.name},D.id))]})]}),o.jsxs("div",{className:"team-head",children:[o.jsx("h3",{children:"Registered agents"}),o.jsx("button",{className:"settings-primary",type:"button",onClick:()=>p(wre(null)),disabled:!!d&&!d.id,children:"Add agent"})]}),c&&o.jsx("p",{className:"set-warn",role:"alert",children:c}),d&&o.jsx(Are,{draft:d,team:i,projects:n,saving:m,onChange:p,onSave:()=>{$()},onCancel:()=>p(null)}),r?o.jsx("p",{role:"status",className:"settings-note",children:"Loading agents…"}):i.length===0?o.jsxs("div",{className:"settings-empty",children:[o.jsx("strong",{children:"No agents yet"}),o.jsx("span",{children:"Add one with a name, a role and the model it runs on."})]}):o.jsxs("div",{className:"team-group",children:[o.jsx("h4",{children:"Org chart · agents at the top report to you"}),o.jsx("ul",{className:"team-list",children:L.map(X)})]})]})}function Sre({agents:t,selectedId:e,projectName:n,onPick:i,onManage:s}){if(t.length===0)return o.jsx("div",{className:"lead-picker",children:o.jsxs("p",{className:"lead-picker-note",children:["No agent reports to you yet. ",o.jsx("button",{type:"button",onClick:s,children:"Add one in Settings"})," to start a conversation."]})});if(t.length===1&&t[0].id===e)return null;const r=t.some(c=>c.id===e)?e:t[0].id,a=c=>{const u={ArrowRight:1,ArrowDown:1,ArrowLeft:-1,ArrowUp:-1}[c.key],d=t.findIndex(m=>m.id===r),p=c.key==="Home"?0:c.key==="End"?t.length-1:u?(d+u+t.length)%t.length:-1;p<0||(c.preventDefault(),i(t[p]),c.currentTarget.querySelectorAll("[role=radio]")[p]?.focus())};return o.jsxs("div",{className:"lead-picker",children:[o.jsx("div",{className:"lead-picker-list",role:"radiogroup","aria-label":"Talk to",onKeyDown:a,children:t.map(c=>{const u=c.projectId?n(c.projectId)??"another project":null;return o.jsxs("button",{className:`lead-chip${c.id===e?" is-on":""}`,type:"button",role:"radio","aria-checked":c.id===e,tabIndex:c.id===r?0:-1,title:[c.role,u?`Works in ${u}`:"Works in any project",`${Xo[c.agent]} ${aO(c)}`].filter(Boolean).join(`
204
- `),onClick:()=>i(c),children:[o.jsx(ws,{name:c.name,avatar:c.avatar,id:c.id,size:20,decorative:!0}),o.jsx("span",{className:"lead-chip-name",children:c.name}),u&&o.jsx("span",{className:"lead-chip-meta",children:u})]},c.id)})}),o.jsx("p",{className:"lead-picker-note",children:o.jsx("button",{type:"button",onClick:s,children:"Manage agents"})})]})}function Cre(){return o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M4 20h4L19 9a2.8 2.8 0 0 0-4-4L4 16v4Z"}),o.jsx("path",{d:"m13.5 6.5 4 4"})]})}function jre(){return o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M4 7h16"}),o.jsx("path",{d:"M10 11v6M14 11v6"}),o.jsx("path",{d:"M6 7l1 13h10l1-13"}),o.jsx("path",{d:"M9 7V4h6v3"})]})}function aO(t){return pk(t.agent).find(e=>e.flag===t.model)?.model??t.model}function Are({draft:t,team:e,projects:n,saving:i,onChange:s,onSave:r,onCancel:a}){const c=pk(t.agent),u=Pb[t.agent],d=cM[t.agent],p=k=>s({...t,...k}),m=k=>{const S=pk(k)[0]?.flag??"",C=Pb[k].some(N=>N.id===t.effort)?t.effort:Pb[k][0]?.id,A=cM[k].some(N=>N.id===t.access)?t.access:"auto";s({...t,agent:k,model:S,effort:C,access:A})},v=nO(t),x=new Set;if(t.id){let k=!0;for(x.add(t.id);k;){k=!1;for(const S of e)S.reportsTo&&x.has(S.reportsTo)&&!x.has(S.id)&&(x.add(S.id),k=!0)}}const y=e.filter(k=>!x.has(k.id)&&(!k.projectId||k.projectId===(t.projectId||void 0)));return o.jsxs("form",{className:"team-form",onSubmit:k=>{k.preventDefault(),r()},children:[o.jsxs("label",{children:[o.jsx("span",{children:"Name"}),o.jsx("input",{value:t.name,maxLength:60,placeholder:"e.g. Reviewer",autoFocus:!0,onChange:k=>p({name:k.target.value})})]}),o.jsx(xre,{name:t.name,role:t.role,avatar:t.avatar,agentId:t.id,onChange:k=>p({avatar:k})},t.id??"new"),o.jsxs("label",{className:"team-form-wide",children:[o.jsx("span",{children:"Role"}),o.jsx("textarea",{value:t.role,maxLength:2e3,rows:3,placeholder:"What this agent is good at, and what it should take on",onChange:k=>p({role:k.target.value})})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Provider"}),o.jsx("select",{value:t.agent,onChange:k=>m(k.target.value),children:bre.map(k=>o.jsx("option",{value:k,children:Xo[k]},k))})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Model"}),o.jsx("select",{value:t.model,onChange:k=>p({model:k.target.value}),children:c.map(k=>o.jsx("option",{value:k.flag,children:k.model},k.id))})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Effort"}),o.jsx("select",{value:t.effort??"",onChange:k=>p({effort:k.target.value}),children:u.map(k=>o.jsx("option",{value:k.id,children:k.label},k.id))})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Access"}),o.jsx("select",{value:t.access,onChange:k=>p({access:k.target.value}),children:d.map(k=>o.jsx("option",{value:k.id,children:k.label},k.id))})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Reports to"}),o.jsxs("select",{value:t.reportsTo??"",onChange:k=>p({reportsTo:k.target.value||null}),children:[o.jsx("option",{value:"",children:"You"}),y.map(k=>o.jsx("option",{value:k.id,children:k.name},k.id))]})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Available in"}),o.jsxs("select",{value:t.projectId??"",onChange:k=>p({projectId:k.target.value||null}),children:[o.jsx("option",{value:"",children:"Every project"}),n.map(k=>o.jsx("option",{value:k.id,children:k.name},k.id))]})]}),v&&o.jsx("p",{className:"settings-note team-form-wide",children:"Fable and Astra can lead a task, but they cannot be given one."}),o.jsxs("div",{className:"team-form-actions team-form-wide",children:[o.jsx("button",{className:"vault-button",type:"button",onClick:a,children:"Cancel"}),o.jsx("button",{className:"settings-primary",type:"submit",disabled:i||!t.name.trim()||!t.model,children:i?"Saving…":t.id?"Save":"Add"})]})]})}function Nre(){const{snapshot:t,error:e,refresh:n}=lS(),[i,s]=_.useState(!1),[r,a]=_.useState(null),c=t?.defaultEnabled??!1;async function u(){s(!0),a(null);try{await ae.invoke("sandbox_configure",{enabled:!c}),await n()}catch(d){a(String(d.message??d))}finally{s(!1)}}return o.jsxs("section",{className:"settings-section","aria-labelledby":"settings-sandbox-title",children:[o.jsx("header",{className:"settings-section-head",children:o.jsxs("div",{children:[o.jsx("h2",{id:"settings-sandbox-title",children:"Sandbox"}),o.jsx("p",{children:"Run a separate test app and database for each chat on the OctiqFlow host."})]})}),o.jsxs("div",{className:"settings-control-row",children:[o.jsxs("div",{className:"settings-control-copy",children:[o.jsx("h3",{children:"Use sandbox for new chats"}),o.jsx("p",{children:"Set the default. You can change the checkbox before starting each new chat."})]}),o.jsxs("button",{className:`set-switch${c?" is-on":""}`,type:"button",role:"switch","aria-label":"Use sandbox for new chats","aria-checked":c,disabled:i||!t,onClick:()=>{u()},children:[o.jsx("span",{className:"set-switch-track","aria-hidden":"true"}),o.jsx("span",{className:"set-switch-text",children:i?"…":c?"On":"Off"})]})]}),o.jsx("p",{className:"settings-note",children:"Each chat keeps its database when resumed. Existing chats keep their original choice. Projects need a sandbox recipe and Docker running locally on the host."}),(r||e)&&o.jsx("p",{className:"set-warn",role:"alert",children:r||e})]})}const Ere=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});function Mre(t,e){return Ere.compare(t.name,e.name)||t.name.localeCompare(e.name)||t.id.localeCompare(e.id)}function Lre({current:t,onPick:e,notify:n,onNotify:i,projects:s,onProject:r,agentsMode:a=!1,onAgentsMode:c,onFeedback:u,initialSection:d="projects",onClose:p}){const m=X=>{ZB(X),e(X)},[v,x]=_.useState(F1),[y,k]=_.useState(""),[S,C]=_.useState(!1),[A,N]=_.useState(d),E=Px()||xf()||$R(),M=async()=>{if(!S){C(!0),k("");try{if(n){await Iz(),G_(!1),i(!1,!1);return}const X=await Oz();if(x(F1()),X==="on"){G_(!0),i(!0,!0);return}if(X==="denied"){k("denied");return}if(X==="needs-install"){k("needs-install");return}const D=await Mz();if(x(D),D!=="granted"){k("denied");return}G_(!0),i(!0,!1)}finally{C(!1)}}},L=n&&v==="granted",$=kx.find(X=>X.id===t)?.name??"Dark",V=[...s].sort(Mre);return o.jsxs("section",{className:"settings-page","aria-labelledby":"settings-title",children:[o.jsx(kh,{root:!0,back:{label:"Chat",ariaLabel:"Back to chat",onClick:p},title:o.jsx("h1",{id:"settings-title",children:"Settings"})}),o.jsxs("div",{className:"settings-layout",children:[o.jsxs("nav",{className:"settings-nav","aria-label":"Settings sections",children:[o.jsxs("div",{className:"settings-nav-list",children:[o.jsx(_d,{section:"projects",label:"Projects",detail:`${s.length} ${s.length===1?"project":"projects"}`,active:A==="projects",onPick:N}),c&&o.jsx(_d,{section:"agents",label:"Agents",detail:a?"Agents mode on":"Agents mode off",active:A==="agents",onPick:N}),E&&o.jsx(_d,{section:"notifications",label:"Notifications",detail:L?"On":"Off",active:A==="notifications",onPick:N}),o.jsx(_d,{section:"sandbox",label:"Sandbox",detail:"Local test environments",active:A==="sandbox",onPick:N}),o.jsx(_d,{section:"memory",label:"Memory Vault",detail:"Shared agent knowledge",active:A==="memory",onPick:N}),o.jsx(_d,{section:"appearance",label:"Appearance",detail:$,active:A==="appearance",onPick:N}),u&&o.jsxs("button",{className:"settings-nav-item",type:"button","aria-haspopup":"dialog",onClick:u,children:[o.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M4 4h16v13H9l-5 4V4Z"}),o.jsx("path",{d:"M8 8h8M8 12h5"})]}),o.jsxs("span",{className:"settings-nav-copy",children:[o.jsx("span",{children:"Feedback inbox"}),o.jsx("small",{children:"Reports from your agents"})]})]})]}),o.jsxs("p",{className:"settings-nav-foot",children:["Switches apply automatically.",o.jsxs("span",{className:"settings-version",children:["OctiqFlow v","0.2.12"]})]})]}),o.jsxs("div",{className:"settings-content",children:[A==="sandbox"&&o.jsx(Nre,{}),A==="memory"&&o.jsx(Jse,{}),A==="agents"&&c&&o.jsx(kre,{on:a,onToggle:c,projects:V}),A==="projects"&&o.jsxs("section",{className:"settings-section","aria-labelledby":"settings-projects-title",children:[o.jsxs("header",{className:"settings-section-head",children:[o.jsxs("div",{children:[o.jsx("h2",{id:"settings-projects-title",children:"Projects"}),o.jsx("p",{children:"Manage names, folders, environment, links, and visibility."})]}),o.jsxs("button",{className:"settings-primary",type:"button",onClick:()=>r("new"),children:[o.jsx(Rre,{}),o.jsx("span",{children:"New project"})]})]}),s.length?o.jsx("div",{className:"settings-projects",children:V.map(X=>o.jsxs("button",{className:"settings-project",type:"button",onClick:()=>r(X.id),"aria-label":`Configure ${X.name}`,children:[o.jsx(Jc,{project:X,size:"medium"}),o.jsxs("span",{className:"settings-project-copy",children:[o.jsx("span",{className:"settings-project-name",children:X.name}),X.primary_path&&o.jsx("span",{className:"settings-project-path",title:X.primary_path,children:o.jsx("bdi",{children:X.primary_path})})]}),X.shelved&&o.jsx("span",{className:"settings-project-state",children:"Shelved"}),o.jsx(Dre,{})]},X.id))}):o.jsxs("div",{className:"settings-empty",children:[o.jsx("strong",{children:"No projects yet"}),o.jsx("span",{children:"Create a project to give chats their own workspace."})]})]}),A==="notifications"&&E&&o.jsxs("section",{className:"settings-section","aria-labelledby":"settings-notifications-title",children:[o.jsx("header",{className:"settings-section-head",children:o.jsxs("div",{children:[o.jsx("h2",{id:"settings-notifications-title",children:"Notifications"}),o.jsx("p",{children:"Choose when OctiqFlow can bring a chat back to your attention."})]})}),o.jsxs("div",{className:"settings-control-row",children:[o.jsxs("div",{className:"settings-control-copy",children:[o.jsx("h3",{children:"Chat activity"}),o.jsx("p",{children:"Get a banner when a chat you are not watching finishes, needs permission, or asks you a question."})]}),o.jsxs("button",{className:`set-switch${L?" is-on":""}`,type:"button",role:"switch","aria-checked":L,disabled:S,onClick:M,children:[o.jsx("span",{className:"set-switch-track","aria-hidden":"true"}),o.jsx("span",{className:"set-switch-text",children:S?"…":L?"On":"Off"})]})]}),o.jsx("p",{className:"settings-note",children:"On a phone, alerts can arrive even while OctiqFlow is closed. Nothing appears for the chat currently on screen."}),y==="needs-install"&&o.jsxs("p",{className:"set-warn",children:["iPhone and iPad only allow notifications for an app on the home screen. Tap Share, then ",o.jsx("b",{children:"Add to Home Screen"}),", open OctiqFlow from there, and turn this on again."]}),(y==="denied"||v==="denied")&&o.jsx("p",{className:"set-warn",children:"This browser is blocking notifications for OctiqFlow. Allow them in the site settings and come back."}),y==="failed"&&o.jsx("p",{className:"set-warn",children:"Could not register for notifications. This needs an https address — a plain http one will not do, even on your own network."})]}),A==="appearance"&&o.jsxs("section",{className:"settings-section settings-appearance","aria-labelledby":"settings-appearance-title",children:[o.jsx("header",{className:"settings-section-head",children:o.jsxs("div",{children:[o.jsx("h2",{id:"settings-appearance-title",children:"Appearance"}),o.jsx("p",{children:"Keep it light, stay focused in dark, or add some colour with fun mode."})]})}),o.jsx("div",{className:"thm-grid",role:"radiogroup","aria-label":"Appearance",children:kx.map(X=>{const D=Qse(X),Q=X.id===t;return o.jsxs("button",{className:`thm${Q?" is-on":""}`,type:"button",role:"radio","aria-checked":Q,onClick:()=>m(X.id),children:[o.jsxs("span",{className:"thm-shot",style:{background:D.bg},"aria-hidden":"true",children:[o.jsx("span",{className:"thm-bar",style:{background:D.sunken}}),o.jsx("span",{className:"thm-card",style:{background:D.card}}),o.jsx("span",{className:"thm-line",style:{background:D.fg}}),o.jsx("span",{className:"thm-dot",style:{background:D.accent}})]}),o.jsx("span",{className:"thm-name",children:X.name})]},X.id)})})]})]})]})]})}function _d({section:t,label:e,detail:n,active:i,onPick:s}){return o.jsxs("button",{className:`settings-nav-item${i?" is-on":""}`,type:"button","aria-current":i?"page":void 0,onClick:()=>s(t),children:[o.jsx(Tre,{section:t}),o.jsxs("span",{className:"settings-nav-copy",children:[o.jsx("span",{children:e}),o.jsx("small",{children:n})]})]})}function Tre({section:t}){return t==="agents"?o.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"9",cy:"8",r:"3"}),o.jsx("path",{d:"M3 20c0-3.3 2.7-6 6-6s6 2.7 6 6"}),o.jsx("circle",{cx:"17",cy:"9",r:"2.4"}),o.jsx("path",{d:"M16 14.2c2.9.3 5 2.6 5 5.8"})]}):t==="memory"?o.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M12 5c-3-2-6-2-9-1v15c3-1 6-1 9 1 3-2 6-2 9-1V4c-3-1-6-1-9 1Z"}),o.jsx("path",{d:"M12 5v15"})]}):t==="projects"?o.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M3 7.5h7l2 2h9v9.5H3z"}),o.jsx("path",{d:"M3 7.5V5h7l2 2h6"})]}):t==="notifications"?o.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M18 8a6 6 0 0 0-12 0c0 7-3 7-3 9h18c0-2-3-2-3-9"}),o.jsx("path",{d:"M10 21h4"})]}):o.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"12",cy:"12",r:"9"}),o.jsx("path",{d:"M12 3a9 9 0 0 0 0 18c2.2-2.2 3.3-5.2 3.3-9S14.2 5.2 12 3Z"}),o.jsx("path",{d:"M3 12h18"})]})}function Rre(){return o.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:o.jsx("path",{d:"M12 5v14M5 12h14"})})}function Dre(){return o.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"m9 18 6-6-6-6"})})}const Bre=["small","medium","large"],Hm={small:"Small",medium:"Medium",large:"Large"},$C={small:25,medium:75,large:150};async function Ore(){return await ae.invoke("agent_levels",{})}async function XM(t,e=0){return await ae.invoke("agent_level_profile",{agentId:t,offset:e})}async function oO(t,e){return await ae.invoke("orchestration_task_accept",{taskId:t,attemptId:e})}async function Ire(t,e){await ae.invoke("orchestration_task_size",{taskId:t,size:e})}function lO(t){const e=t.nextLevelXp-t.levelXp;return e<=0?0:Math.min(1,Math.max(0,(t.xp-t.levelXp)/e))}function cO(t){return`${Math.max(0,t.nextLevelXp-t.xp).toLocaleString("en-US")} XP to level ${t.level+1}`}function $re(t){if(t<1e3)return String(t);const e=[[1e9,"B"],[1e6,"M"],[1e3,"K"]];for(const[n,i]of e)if(t>=n){const s=t/n;return`${s>=100?Math.round(s):Number(s.toFixed(1))}${i}`}return String(t)}function Pre(t){const e=!!t.activeAttemptId,n=!e&&(t.status==="pending"||t.status==="ready"),i=t.size??(e?void 0:"medium");return i?{size:i,editable:n,label:`${Hm[i]} · ${$C[i]} XP`}:{editable:!1,label:"Not recorded · earns no XP"}}function zre(t){if(t.xp>0)return{amount:`+${t.xp} XP`};switch(t.unpaid){case"already_paid":return{amount:"0 XP",why:"Accepted again · paid the first time"};case"unsized":return{amount:"0 XP",why:"No size recorded"};case"no_agent":return{amount:"0 XP",why:"No registered agent"};default:return{amount:"0 XP"}}}function uO(t){return t.kind==="person"?"you":t.agentName??"the lead"}function Fre(t){return t.status!=="completed"||!t.assignee||!t.activeAttemptId?!1:t.acceptance?.attemptId!==t.activeAttemptId}function wm(t){return new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}const Hre={xp:0,level:1,levelXp:0,nextLevelXp:100};function Wre({name:t,progress:e,onOpen:n}){const i=e??Hre,s=`Level ${i.level} · ${i.xp.toLocaleString("en-US")} XP · ${cO(i)}`;return o.jsxs("button",{type:"button",className:"level-chip",onClick:n,title:s,"aria-label":`${t}: level ${i.level}, ${i.xp} XP. Open profile`,children:[o.jsxs("span",{className:"level-chip-text",children:["Lv ",i.level]}),o.jsx("span",{className:"level-chip-bar","aria-hidden":"true",children:o.jsx("span",{style:{width:`${Math.round(lO(i)*100)}%`}})})]})}function qre({progress:t,name:e}){return o.jsx("div",{className:"level-bar",role:"progressbar","aria-label":`${e}'s progress to level ${t.level+1}`,"aria-valuemin":t.levelXp,"aria-valuemax":t.nextLevelXp,"aria-valuenow":t.xp,"aria-valuetext":`${t.xp} of ${t.nextLevelXp} XP`,children:o.jsx("span",{style:{width:`${Math.round(lO(t)*100)}%`}})})}function Ure(t){if(t.chats===0)return"None yet";const e=[t.leadChats?`${t.leadChats} leading`:"",t.workerChats?`${t.workerChats} as a worker`:""].filter(Boolean);return`${t.chats} of its own: ${e.join(", ")}`}function Vre({record:t,onOpen:e}){const n=zre(t);return o.jsxs("li",{className:"xp-row",children:[o.jsxs("button",{type:"button",className:"xp-row-open",disabled:!t.coordinatorChatKey,onClick:e,"aria-label":`${t.title}: ${n.amount}${n.why?`, ${n.why}`:""}. Open task`,children:[o.jsx("span",{className:"dash-item-title",children:t.title}),o.jsxs("span",{className:"dash-item-meta",children:[n.why??(t.size?Hm[t.size]:"No size recorded")," · accepted by ",uO(t.acceptedBy)," · ",wm(t.acceptedAt)]})]}),o.jsx("span",{className:t.xp>0?"xp-gain":"xp-gain is-zero",children:n.amount})]})}function Kre({agent:t,connected:e,onOpenRun:n,onChanged:i}){const[s,r]=_.useState(null),[a,c]=_.useState([]),[u,d]=_.useState(""),[p,m]=_.useState(null),[v,x]=_.useState(""),[y,k]=_.useState(0);_.useEffect(()=>{if(!e)return;let M=!0;return XM(t.id,0).then(L=>{M&&(r(L),c([]),d(""))}).catch(L=>{M&&d(String(L.message??L))}),()=>{M=!1}},[t.id,e,y]);const S=s?[...s.history,...a]:[],C=async()=>{if(s){m("more");try{const M=await XM(t.id,S.length);c(L=>[...L,...M.history])}catch(M){d(String(M.message??M))}finally{m(null)}}},A=async(M,L)=>{m(M),x("");try{const $=await oO(M,L);x($.awarded&&$.award?`Accepted. ${t.name} earned ${$.award.xp} XP.`:`Accepted. ${$.note??"No XP was paid."}`),k(V=>V+1),i()}catch($){d(String($.message??$))}finally{m(null)}},N=(M,L)=>{if(M)try{n(M,L)}catch($){d(String($.message??$))}},E=s?.usage;return o.jsxs("section",{className:"agent-profile","aria-label":`${t.name}'s profile`,children:[o.jsxs("header",{className:"agent-profile-head",children:[o.jsx(ws,{name:t.name,avatar:t.avatar,id:t.id,size:44,removed:t.removed,decorative:!0}),o.jsxs("div",{className:"agent-profile-title",children:[o.jsx("h2",{children:o.jsx("bdi",{children:t.name})}),t.detail&&o.jsx("span",{className:"team-row-meta",children:o.jsx("bdi",{children:t.detail})})]})]}),u&&o.jsx("p",{className:"set-warn",role:"alert",children:u}),v&&o.jsx("p",{className:"agent-profile-notice",role:"status",children:v}),!s&&!u&&o.jsx("p",{className:"projects-page-meta",children:"Loading profile…"}),s&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"level-block",children:[o.jsxs("div",{className:"level-head",children:[o.jsxs("strong",{className:"level-number",children:["Level ",s.level]}),o.jsxs("span",{className:"level-xp",children:[s.xp.toLocaleString("en-US")," XP"]})]}),o.jsx(qre,{progress:s,name:t.name}),o.jsx("p",{className:"level-next",children:cO(s)})]}),o.jsxs("dl",{className:"agent-profile-stats",children:[o.jsxs("div",{children:[o.jsx("dt",{children:"Accepted tasks"}),o.jsxs("dd",{title:"Every task accepted for this agent, counted once for good, including those that earned no XP",children:[s.acceptedTasks.toLocaleString("en-US"),o.jsx("span",{className:"agent-profile-stat-note",children:"lifetime"})]})]}),o.jsxs("div",{children:[o.jsx("dt",{children:"Tokens used"}),o.jsx("dd",{title:E&&E.chats>0?`${E.total.toLocaleString("en-US")} tokens`:void 0,children:E?E.chats===0?"None recorded":$re(E.total):"Unavailable"})]})]}),s.awaiting.length>0&&o.jsxs("section",{className:"agent-profile-section","aria-label":"Waiting for acceptance",children:[o.jsx("h3",{children:"Waiting for acceptance"}),o.jsx("ul",{className:"agent-profile-list",children:s.awaiting.map(M=>o.jsxs("li",{className:"xp-row",children:[o.jsxs("button",{type:"button",className:"xp-row-open",onClick:()=>N(M.coordinatorChatKey,M.runId),"aria-label":`Open task: ${M.title}`,children:[o.jsx("span",{className:"dash-item-title",children:M.title}),o.jsxs("span",{className:"dash-item-meta",children:[M.size?Hm[M.size]:"No size recorded",M.unscored?" · earns no XP":""," · finished ",wm(M.finishedAt)]})]}),o.jsx("button",{type:"button",className:"vault-button xp-accept",disabled:p!==null||!e,onClick:()=>{A(M.taskId,M.attemptId)},children:p===M.taskId?"Accepting…":"Accept"})]},M.taskId))})]}),o.jsxs("section",{className:"agent-profile-section","aria-label":"XP history",children:[o.jsx("h3",{children:"XP history"}),S.length===0?o.jsx("p",{className:"projects-page-meta",children:"No accepted tasks yet."}):o.jsx("ul",{className:"agent-profile-list",children:S.map(M=>o.jsx(Vre,{record:M,onOpen:()=>N(M.coordinatorChatKey,M.runId)},`${M.taskId}:${M.attemptId}`))}),S.length<s.historyTotal&&o.jsx("button",{type:"button",className:"dash-more",disabled:p!==null,onClick:()=>{C()},children:p==="more"?"Loading…":`Show more (${s.historyTotal-S.length})`})]}),E&&o.jsxs("details",{className:"agent-profile-details",children:[o.jsx("summary",{children:"Token usage"}),o.jsxs("dl",{className:"plan-card-facts",children:[o.jsx("dt",{children:"Input"}),o.jsxs("dd",{children:[E.usage.input.toLocaleString("en-US"),o.jsxs("span",{className:"plan-card-note",children:[E.usage.cachedInput.toLocaleString("en-US")," from cache",E.usage.cacheWrite>0?`, ${E.usage.cacheWrite.toLocaleString("en-US")} written to cache`:""]})]}),o.jsx("dt",{children:"Output"}),o.jsxs("dd",{children:[E.usage.output.toLocaleString("en-US"),E.reasoningReported&&o.jsxs("span",{className:"plan-card-note",children:[E.usage.reasoning.toLocaleString("en-US")," reasoning (Codex only)"]})]}),o.jsx("dt",{children:"Chats"}),o.jsx("dd",{children:Ure(E)})]}),o.jsxs("p",{className:"agent-profile-fine",children:["Counted since ",wm(E.since||s.scoringSince),", from what each provider reports, so this is a floor: earlier chats, and a turn stopped before the provider reported it, are not included. Claude’s figures include helper subagents it runs inside its own chat. Registered reports have their own chats and count for themselves. Cached and reasoning tokens are part of input and output, not extra."]})]}),s.usageError&&o.jsx("p",{className:"set-warn",role:"alert",children:s.usageError}),o.jsxs("details",{className:"agent-profile-details",children:[o.jsx("summary",{children:"How levels work"}),o.jsxs("ul",{className:"agent-profile-rules",children:[o.jsxs("li",{children:["XP is paid when you or the responsible lead accept a finished task:"," ",s.rules.sizes.map(([M,L])=>`${Hm[M].toLowerCase()} ${L}`).join(", "),"."]}),o.jsx("li",{children:"The size is chosen before the task starts and cannot change after. Each task pays once, however often it is reopened or retried."}),o.jsx("li",{children:"Accepted tasks counts every task you or a lead accepted, once and for good, including tasks that earned no XP. A task reopened and accepted again shows in the history again, but is counted once."}),o.jsxs("li",{children:["Level 1 starts at 0 XP. Going from level L to L+1 takes ",s.rules.levelStep," × L XP."]}),o.jsx("li",{children:"Only accepted tasks in runs count. Work in ordinary chats is not scored."}),o.jsxs("li",{children:["Scoring began ",wm(s.scoringSince),". Tasks finished before then are not scored."]}),o.jsx("li",{children:"Token usage is shown for information only. It does not affect XP."})]})]})]})]})}const QM=3;function Gre({snapshot:t,ledgerError:e,connected:n,projects:i,running:s,busy:r,waitingOn:a,chatTitle:c,chatExists:u,onOpenChat:d,onOpenRun:p,onManage:m,onClose:v}){const[x,y]=_.useState(null),[k,S]=_.useState([]),[C,A]=_.useState(""),[N,E]=_.useState(null),[M,L]=_.useState(new Set),[$,V]=_.useState(""),[X,D]=_.useState(new Map),[Q,P]=_.useState(0),[z,H]=_.useState(null),W=_.useMemo(()=>(t?.tasks??[]).filter(re=>re.acceptance).map(re=>`${re.id}:${re.acceptance.attemptId}`).sort().join(","),[t]);_.useEffect(()=>{if(!n)return;let re=!0;return Ore().then(ve=>{re&&D(new Map((ve??[]).map(le=>[le.agentId,le])))}).catch(()=>{re&&D(new Map)}),()=>{re=!1}},[n,W,Q]),_.useEffect(()=>{if(!n)return;let re=!0;return Promise.all([tf(null,!0),eO()]).then(([ve,le])=>{re&&(y(ve),S(le),A(""))}).catch(ve=>{re&&A(String(ve.message??ve))}),()=>{re=!1}},[n]);const F=_.useMemo(()=>[...s].sort().join(",")+"|"+[...r].sort().join(","),[s,r]);_.useEffect(()=>{if(!n)return;let re=!0;return ae.invoke("chat_activity").then(ve=>{re&&E(new Map((ve??[]).map(le=>[le.key,le.busy])))}).catch(()=>{re&&E(null)}),()=>{re=!1}},[n,F]);const Y=re=>{const ve=re.replace(/^chat:/,"");if(r.has(ve))return"busy";const le=N?.get(re);return le!==void 0?le?"busy":"idle":N?"ended":s.has(ve)?"unknown":"ended"},J=_.useMemo(()=>i.map(({id:re,name:ve})=>({id:re,name:ve})),[i]),te=Xte({team:x,leads:k,snapshot:t,projects:J,providerLabel:re=>`${Xo[re.agent]} ${re.model}`,chatTitle:c,chatExists:u,leadActivity:Y,waitingOn:a}),I=Qte(te),U=!n||!!e,Z=re=>i.find(ve=>ve.id===re),R=re=>{V("");try{if(re.chatKey)d(re.chatKey);else if(re.runId){const ve=t?.runs.find(le=>le.id===re.runId);ve&&p(ve.coordinatorChatKey,ve.id)}}catch(ve){V(String(ve.message??ve))}},K=re=>!!re.chatKey||!!re.runId&&!!t?.runs.some(ve=>ve.id===re.runId),O=z?te.find(re=>re.id===z):void 0;if(z&&O)return o.jsxs("section",{className:"projects-page agents-dashboard","aria-label":"Agents",children:[o.jsx(kh,{root:!0,back:{label:"All agents",ariaLabel:"Back to all agents",onClick:()=>H(null)},title:o.jsx("h1",{children:O.name}),actions:o.jsx("button",{type:"button",className:"projects-page-secondary",onClick:m,children:"Manage agents"})}),o.jsx("div",{className:"projects-page-body",children:o.jsx(Kre,{agent:O,connected:n,onOpenRun:p,onChanged:()=>P(re=>re+1)})})]});const ie=re=>L(ve=>{const le=new Set(ve);return le.has(re)?le.delete(re):le.add(re),le});return o.jsxs("section",{className:"projects-page agents-dashboard","aria-label":"Agents",children:[o.jsx(kh,{root:!0,back:{label:"Chat",ariaLabel:"Back to chat",onClick:v},title:o.jsx("h1",{children:"Agents"}),actions:o.jsx("button",{type:"button",className:"projects-page-secondary",onClick:m,children:"Manage agents"})}),o.jsxs("div",{className:"projects-page-body",children:[o.jsx("p",{className:"projects-page-meta dash-summary","aria-live":"polite",children:x===null&&!C?"Loading agents…":I.length===0?"Who is doing what":I.map(({state:re,count:ve})=>`${ve} ${sk[re].toLowerCase()}`).join(" · ")}),U&&x!==null&&o.jsx("p",{className:"dash-stale",role:"status",children:n?"Could not refresh work. Showing the last known state.":"Disconnected. Showing the last known state."}),C&&o.jsx("p",{className:"set-warn",role:"alert",children:C}),$&&o.jsx("p",{className:"set-warn",role:"alert",children:$}),x!==null&&te.length===0?o.jsxs("div",{className:"settings-empty",children:[o.jsx("strong",{children:"No agents yet"}),o.jsx("button",{className:"vault-button",type:"button",onClick:m,children:"Add agents in Settings"})]}):o.jsx("ul",{className:"team-list agents-dashboard-list",children:te.map(re=>o.jsx(Yre,{row:re,stale:U,expanded:M.has(re.id),onToggle:()=>ie(re.id),appearance:Z,canOpen:K,onOpen:R,level:X.get(re.id),onProfile:()=>H(re.id),onOpenRecent:ve=>{V("");try{d(ve)}catch(le){V(String(le.message??le))}}},re.id))})]})]})}function Yre({row:t,stale:e,expanded:n,onToggle:i,appearance:s,canOpen:r,onOpen:a,onOpenRecent:c,level:u,onProfile:d}){const p=t.state==="working"&&!e,m=n?t.activities:t.activities.slice(0,QM),v=Object.entries(t.counts).filter(([y])=>y!==t.state),x=sk[t.state];return o.jsxs("li",{className:"dash-agent","data-state":t.state,style:{"--team-depth":t.depth},children:[o.jsxs("div",{className:"dash-agent-head",children:[t.depth>0&&o.jsx("span",{className:"team-row-branch","aria-hidden":"true",children:"└"}),o.jsx(ws,{name:t.name,avatar:t.avatar,id:t.id,size:28,removed:t.removed,className:p?"dash-avatar is-working":"dash-avatar",label:`${t.name}, ${x.toLowerCase()}`}),o.jsxs("span",{className:"team-row-copy",children:[o.jsxs("span",{className:"team-row-name",children:[o.jsx("bdi",{children:t.name}),!t.removed&&o.jsx(Wre,{name:t.name,progress:u,onOpen:d})]}),o.jsxs("span",{className:"team-row-meta",children:[o.jsx("bdi",{children:t.detail}),o.jsx("span",{"aria-hidden":"true",children:" · "}),t.removed?"Removed":t.scope?o.jsx("bdi",{children:t.scope.name}):"All projects"]})]}),o.jsxs("span",{className:"dash-agent-status",children:[o.jsx("span",{className:`dash-state is-${t.state}${e?" is-stale":""}`,title:e?`Last known: ${t.stateLabel}`:t.stateLabel,children:e?`${x} (last known)`:x}),v.map(([y,k])=>o.jsxs("span",{className:`dash-count is-${y}`,children:[k," ",sk[y].toLowerCase()]},y))]})]}),t.role&&o.jsx(sO,{className:"dash-agent-role",text:t.role,name:t.name}),t.activities.length>0?o.jsxs("div",{className:"dash-agent-work",children:[m.map(y=>o.jsxs("button",{className:"dash-item",type:"button","data-state":y.state,disabled:!r(y),onClick:()=>a(y),"aria-label":`${y.label}: ${y.title}${y.project?`, in ${y.project.name}`:""}. Open ${y.kind==="lead"?"conversation":"task"}`,children:[o.jsx("span",{className:`dash-dot is-${y.state}`,"aria-hidden":"true"}),o.jsxs("span",{className:"dash-item-copy",children:[o.jsx("span",{className:"dash-item-title",children:y.title}),o.jsxs("span",{className:"dash-item-meta",children:[o.jsx("span",{className:"dash-item-state",children:y.label}),y.project?o.jsxs("span",{className:"dash-item-project",children:[s(y.project.id)&&o.jsx(Jc,{project:s(y.project.id),size:"tiny"}),o.jsx("bdi",{children:y.project.name})]}):y.crossProject?o.jsx("span",{className:"dash-item-project",children:"Across projects"}):null]})]}),o.jsx("span",{className:"dash-item-open","aria-hidden":"true",children:"Open"})]},y.key)),t.activities.length>QM&&o.jsx("button",{className:"dash-more",type:"button","aria-expanded":n,onClick:i,children:n?"Show fewer":`Show all ${t.activities.length}`})]}):t.recent?o.jsx("div",{className:"dash-agent-work",children:o.jsxs("button",{className:"dash-recent",type:"button",onClick:()=>c(t.recent.chatKey),"aria-label":`Open last: ${t.recent.title}`,children:["Last: ",o.jsx("span",{className:"dash-item-title",children:t.recent.title})]})}):null]})}function Xre(t){return!!t.headId&&t.recipientId===t.headId}function Qre(t){return(t??"").trim().toLowerCase()==="general"}function Zre(t){const{toHead:e,project:n,homeId:i,repo:s,sandboxDefault:r}=t,a=t.overrides??{},c=Object.values(a).some(S=>S!==void 0);if(e)return{target:"home",projectId:i??null,prepare:!1,branch:"",newWorktree:!1,useSandbox:!1,chosenBy:"auto",reason:"Coordinates from your home workspace. Each task it hands out runs where the host routes it.",crossProject:!0};const u=a.projectId!==void 0?a.projectId:n?.id??null;if(!u||u===i||u===n?.id&&Qre(n?.name))return{target:"home",projectId:u??i??null,prepare:!1,branch:"",newWorktree:!1,useSandbox:a.useSandbox??!1,chosenBy:c?"advanced":"auto",reason:"No code project: works from your home workspace.",crossProject:!1};const p=!!s&&!s.loading&&!s.error,m=a.branch??(p&&s.isRepo?s.current:""),v=a.newWorktree??!0,x=a.useSandbox??r,y=m||"the project's current branch",k=c?"Chosen under Advanced.":p&&!s.isRepo?"Not a Git repository: works in the project folder.":`New worktree from ${y}, so the primary checkout stays untouched.`;return{target:"project",projectId:u,prepare:!0,branch:m,newWorktree:v,useSandbox:x,chosenBy:c?"advanced":"auto",reason:k,crossProject:!1}}const Jre=6e4,eae=15e3,hO="octiq.v2.usage",tae=180,nae=60,iae=85;function sae(){try{const t=JSON.parse(localStorage.getItem(hO)||"null");if(!t||typeof t!="object")return{claude:null,codex:null};const e=n=>n?.available?n:null;return{claude:e(t.claude),codex:e(t.codex)}}catch{return{claude:null,codex:null}}}function dO(t){return t>=iae?"is-danger":t>=nae?"is-warn":""}function rae(t){if(!t)return"";const e=t-Date.now()/1e3;if(e<=0)return"resetting";const n=Math.floor(e/3600),i=Math.floor(e%3600/60);return n>=24?`resets in ${Math.floor(n/24)}d ${n%24}h`:n?`resets in ${n}h ${i}m`:`resets in ${i}m`}function aae(){const[t,e]=_.useState(sae),[n,i]=_.useState({claude:!0,codex:!0}),[s,r]=_.useState(null),a=_.useRef(null),c=_.useRef(0),u=_.useCallback(()=>{a.current&&clearTimeout(a.current),a.current=null},[]);_.useEffect(()=>u,[u]);const d=_.useCallback(async m=>{if(!(!m&&Date.now()-c.current<eae)){c.current=Date.now();try{const v=await ae.invoke("usage_summary"),x=(y,k)=>y?.available?y:k?.available?k:y??k??null;e(y=>{const k={claude:x(v?.claude,y.claude),codex:x(v?.codex,y.codex)};try{localStorage.setItem(hO,JSON.stringify({claude:k.claude?.available?k.claude:y.claude,codex:k.codex?.available?k.codex:y.codex}))}catch{}return k}),i({claude:!v?.claude?.available,codex:!v?.codex?.available})}catch{i({claude:!0,codex:!0})}}},[]);if(_.useEffect(()=>{d(!0);const m=setInterval(()=>{d(!0)},Jre),v=()=>document.visibilityState==="visible"&&void d(!1);return document.addEventListener("visibilitychange",v),window.addEventListener("focus",v),()=>{clearInterval(m),document.removeEventListener("visibilitychange",v),window.removeEventListener("focus",v)}},[d]),!t.claude&&!t.codex)return null;const p=lae(t);return o.jsxs("div",{className:"usage",onPointerEnter:m=>{m.pointerType==="mouse"&&(u(),r(v=>v??"hover"),d(!1))},onPointerLeave:m=>{m.pointerType==="mouse"&&(u(),a.current=setTimeout(()=>r(v=>v==="hover"?null:v),tae))},children:[o.jsxs("button",{className:`usage-btn${p&&n[p.provider]?" is-stale":""}`,type:"button","aria-label":cae(t),"aria-haspopup":"dialog","aria-expanded":s!==null,title:"Plan usage — hover or tap for every window",onClick:()=>{u(),r(m=>m==="pin"?null:"pin"),d(!0)},children:[o.jsx(uae,{}),o.jsx("span",{className:`usage-val ${p?dO(p.percent):""}`,children:p?o.jsx(Lt,{children:`${Math.round(p.percent)}%`}):"—"})]}),s&&o.jsxs(o.Fragment,{children:[s==="pin"&&o.jsx("div",{className:"usage-scrim",onClick:()=>r(null)}),o.jsxs("div",{className:"usage-pop",role:"dialog","aria-label":"Plan usage",children:[o.jsx(ZM,{name:"Claude",provider:t.claude,stale:n.claude}),o.jsx(ZM,{name:"Codex",provider:t.codex,stale:n.codex})]})]})]})}function fO(t){const e=[];t?.fiveHour&&e.push({label:"5h",window:t.fiveHour}),t?.weekly&&e.push({label:"7d",window:t.weekly});for(const n of t?.models??[])e.push({label:n.name,window:n});return e.length===0?null:e.reduce((n,i)=>i.window.percent>n.window.percent?i:n)}const oae={claude:"Claude",codex:"Codex"};function lae(t){let e=null;for(const n of["claude","codex"]){const i=fO(t[n]);if(!i)continue;const s=Math.min(100,Math.max(0,i.window.percent));(!e||s>e.percent)&&(e={provider:n,label:i.label,percent:s})}return e}function cae(t){const e=["claude","codex"].flatMap(n=>{const i=fO(t[n]);return i?[`${oae[n]} ${i.label} ${Math.round(Math.min(100,Math.max(0,i.window.percent)))}%`]:[]});return e.length?`Plan usage: ${e.join(", ")}`:"Plan usage: no reading yet"}function uae(){return o.jsxs("svg",{className:"usage-icon",width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M4.5 18a9 9 0 1 1 15 0"}),o.jsx("path",{d:"m12 13 3.5-4"}),o.jsx("circle",{cx:"12",cy:"13",r:"1"})]})}function ZM({name:t,provider:e,stale:n}){return o.jsxs("section",{className:"usage-block",children:[o.jsxs("header",{className:"usage-block-head",children:[o.jsx("span",{className:"usage-block-name",children:t}),e?.plan&&o.jsx("span",{className:"usage-plan",children:e.plan}),n&&o.jsx("span",{className:"usage-stale",children:"last known"})]}),e?o.jsxs(o.Fragment,{children:[o.jsx(Vb,{label:"5 hours",window:e.fiveHour}),o.jsx(Vb,{label:"Week",window:e.weekly}),(e.models??[]).map(i=>o.jsx(Vb,{label:`Week · ${i.name}`,window:i},i.name)),e.note&&o.jsx("div",{className:"usage-empty",children:e.note})]}):o.jsx("div",{className:"usage-empty",children:"No reading yet."})]})}function Vb({label:t,window:e}){if(!e)return null;const n=Math.min(100,Math.max(0,e.percent));return o.jsxs("div",{className:"usage-row",children:[o.jsx("span",{className:"usage-row-label",children:t}),o.jsx("span",{className:`usage-track ${dO(n)}`,children:o.jsx("span",{className:"usage-fill",style:{width:`${n}%`}})}),o.jsx("span",{className:"usage-val",children:o.jsx(Lt,{children:`${Number.isInteger(n)?n:n.toFixed(1)}%`})}),o.jsx("span",{className:"usage-reset",children:o.jsx(Lt,{children:rae(e.resetsAt)})})]})}const nf="octiq-git-changed";function hae(t){const e=new Set;for(const n of t)for(const i of[n.primary_path,...n.paths??[]])i?.trim()&&e.add(i);return[...e]}function dae(t){return[...new Set(t.flatMap(e=>e.primary_path?.trim()?[e.primary_path]:[]))]}function fae(t,e){const n=new Map(e.map(s=>[s.path,s])),i={};for(const s of t){if(!s.primary_path)continue;const r=n.get(s.primary_path);r?.is_repo&&r.branch&&(i[s.id]=r.branch)}return i}const pae={added:{letter:"A",cls:"is-add"},deleted:{letter:"D",cls:"is-del"},renamed:{letter:"R",cls:"is-ren"},untracked:{letter:"U",cls:"is-new"}},mae={letter:"M",cls:"is-mod"},pO=["rebase","merge","ff-only"],JM="octiq.v2.gitPullMode",gae="octiq.v2.gitWidth",vae={initial:380,min:280,max:680},xae=/^(diff --git |index |--- |\+\+\+ |new file mode|deleted file mode|old mode|new mode|similarity index|dissimilarity index|rename from|rename to|copy from|copy to|Binary files )/;function mO(t){return t?[t.primary_path??"",...t.paths??[]].filter(e=>e.trim()!=="").join(`
204
+ `),onClick:()=>i(c),children:[o.jsx(ws,{name:c.name,avatar:c.avatar,id:c.id,size:20,decorative:!0}),o.jsx("span",{className:"lead-chip-name",children:c.name}),u&&o.jsx("span",{className:"lead-chip-meta",children:u})]},c.id)})}),o.jsx("p",{className:"lead-picker-note",children:o.jsx("button",{type:"button",onClick:s,children:"Manage agents"})})]})}function Cre(){return o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M4 20h4L19 9a2.8 2.8 0 0 0-4-4L4 16v4Z"}),o.jsx("path",{d:"m13.5 6.5 4 4"})]})}function jre(){return o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M4 7h16"}),o.jsx("path",{d:"M10 11v6M14 11v6"}),o.jsx("path",{d:"M6 7l1 13h10l1-13"}),o.jsx("path",{d:"M9 7V4h6v3"})]})}function aO(t){return pk(t.agent).find(e=>e.flag===t.model)?.model??t.model}function Are({draft:t,team:e,projects:n,saving:i,onChange:s,onSave:r,onCancel:a}){const c=pk(t.agent),u=Pb[t.agent],d=cM[t.agent],p=k=>s({...t,...k}),m=k=>{const S=pk(k)[0]?.flag??"",C=Pb[k].some(N=>N.id===t.effort)?t.effort:Pb[k][0]?.id,A=cM[k].some(N=>N.id===t.access)?t.access:"auto";s({...t,agent:k,model:S,effort:C,access:A})},v=nO(t),x=new Set;if(t.id){let k=!0;for(x.add(t.id);k;){k=!1;for(const S of e)S.reportsTo&&x.has(S.reportsTo)&&!x.has(S.id)&&(x.add(S.id),k=!0)}}const y=e.filter(k=>!x.has(k.id)&&(!k.projectId||k.projectId===(t.projectId||void 0)));return o.jsxs("form",{className:"team-form",onSubmit:k=>{k.preventDefault(),r()},children:[o.jsxs("label",{children:[o.jsx("span",{children:"Name"}),o.jsx("input",{value:t.name,maxLength:60,placeholder:"e.g. Reviewer",autoFocus:!0,onChange:k=>p({name:k.target.value})})]}),o.jsx(xre,{name:t.name,role:t.role,avatar:t.avatar,agentId:t.id,onChange:k=>p({avatar:k})},t.id??"new"),o.jsxs("label",{className:"team-form-wide",children:[o.jsx("span",{children:"Role"}),o.jsx("textarea",{value:t.role,maxLength:2e3,rows:3,placeholder:"What this agent is good at, and what it should take on",onChange:k=>p({role:k.target.value})})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Provider"}),o.jsx("select",{value:t.agent,onChange:k=>m(k.target.value),children:bre.map(k=>o.jsx("option",{value:k,children:Xo[k]},k))})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Model"}),o.jsx("select",{value:t.model,onChange:k=>p({model:k.target.value}),children:c.map(k=>o.jsx("option",{value:k.flag,children:k.model},k.id))})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Effort"}),o.jsx("select",{value:t.effort??"",onChange:k=>p({effort:k.target.value}),children:u.map(k=>o.jsx("option",{value:k.id,children:k.label},k.id))})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Access"}),o.jsx("select",{value:t.access,onChange:k=>p({access:k.target.value}),children:d.map(k=>o.jsx("option",{value:k.id,children:k.label},k.id))})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Reports to"}),o.jsxs("select",{value:t.reportsTo??"",onChange:k=>p({reportsTo:k.target.value||null}),children:[o.jsx("option",{value:"",children:"You"}),y.map(k=>o.jsx("option",{value:k.id,children:k.name},k.id))]})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Available in"}),o.jsxs("select",{value:t.projectId??"",onChange:k=>p({projectId:k.target.value||null}),children:[o.jsx("option",{value:"",children:"Every project"}),n.map(k=>o.jsx("option",{value:k.id,children:k.name},k.id))]})]}),v&&o.jsx("p",{className:"settings-note team-form-wide",children:"Fable and Astra can lead a task, but they cannot be given one."}),o.jsxs("div",{className:"team-form-actions team-form-wide",children:[o.jsx("button",{className:"vault-button",type:"button",onClick:a,children:"Cancel"}),o.jsx("button",{className:"settings-primary",type:"submit",disabled:i||!t.name.trim()||!t.model,children:i?"Saving…":t.id?"Save":"Add"})]})]})}function Nre(){const{snapshot:t,error:e,refresh:n}=lS(),[i,s]=_.useState(!1),[r,a]=_.useState(null),c=t?.defaultEnabled??!1;async function u(){s(!0),a(null);try{await ae.invoke("sandbox_configure",{enabled:!c}),await n()}catch(d){a(String(d.message??d))}finally{s(!1)}}return o.jsxs("section",{className:"settings-section","aria-labelledby":"settings-sandbox-title",children:[o.jsx("header",{className:"settings-section-head",children:o.jsxs("div",{children:[o.jsx("h2",{id:"settings-sandbox-title",children:"Sandbox"}),o.jsx("p",{children:"Run a separate test app and database for each chat on the OctiqFlow host."})]})}),o.jsxs("div",{className:"settings-control-row",children:[o.jsxs("div",{className:"settings-control-copy",children:[o.jsx("h3",{children:"Use sandbox for new chats"}),o.jsx("p",{children:"Set the default. You can change the checkbox before starting each new chat."})]}),o.jsxs("button",{className:`set-switch${c?" is-on":""}`,type:"button",role:"switch","aria-label":"Use sandbox for new chats","aria-checked":c,disabled:i||!t,onClick:()=>{u()},children:[o.jsx("span",{className:"set-switch-track","aria-hidden":"true"}),o.jsx("span",{className:"set-switch-text",children:i?"…":c?"On":"Off"})]})]}),o.jsx("p",{className:"settings-note",children:"Each chat keeps its database when resumed. Existing chats keep their original choice. Projects need a sandbox recipe and Docker running locally on the host."}),(r||e)&&o.jsx("p",{className:"set-warn",role:"alert",children:r||e})]})}const Ere=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});function Mre(t,e){return Ere.compare(t.name,e.name)||t.name.localeCompare(e.name)||t.id.localeCompare(e.id)}function Lre({current:t,onPick:e,notify:n,onNotify:i,projects:s,onProject:r,agentsMode:a=!1,onAgentsMode:c,onFeedback:u,initialSection:d="projects",onClose:p}){const m=X=>{ZB(X),e(X)},[v,x]=_.useState(F1),[y,k]=_.useState(""),[S,C]=_.useState(!1),[A,N]=_.useState(d),E=Px()||xf()||$R(),M=async()=>{if(!S){C(!0),k("");try{if(n){await Iz(),G_(!1),i(!1,!1);return}const X=await Oz();if(x(F1()),X==="on"){G_(!0),i(!0,!0);return}if(X==="denied"){k("denied");return}if(X==="needs-install"){k("needs-install");return}const D=await Mz();if(x(D),D!=="granted"){k("denied");return}G_(!0),i(!0,!1)}finally{C(!1)}}},L=n&&v==="granted",$=kx.find(X=>X.id===t)?.name??"Dark",V=[...s].sort(Mre);return o.jsxs("section",{className:"settings-page","aria-labelledby":"settings-title",children:[o.jsx(kh,{root:!0,back:{label:"Chat",ariaLabel:"Back to chat",onClick:p},title:o.jsx("h1",{id:"settings-title",children:"Settings"})}),o.jsxs("div",{className:"settings-layout",children:[o.jsxs("nav",{className:"settings-nav","aria-label":"Settings sections",children:[o.jsxs("div",{className:"settings-nav-list",children:[o.jsx(_d,{section:"projects",label:"Projects",detail:`${s.length} ${s.length===1?"project":"projects"}`,active:A==="projects",onPick:N}),c&&o.jsx(_d,{section:"agents",label:"Agents",detail:a?"Agents mode on":"Agents mode off",active:A==="agents",onPick:N}),E&&o.jsx(_d,{section:"notifications",label:"Notifications",detail:L?"On":"Off",active:A==="notifications",onPick:N}),o.jsx(_d,{section:"sandbox",label:"Sandbox",detail:"Local test environments",active:A==="sandbox",onPick:N}),o.jsx(_d,{section:"memory",label:"Memory Vault",detail:"Shared agent knowledge",active:A==="memory",onPick:N}),o.jsx(_d,{section:"appearance",label:"Appearance",detail:$,active:A==="appearance",onPick:N}),u&&o.jsxs("button",{className:"settings-nav-item",type:"button","aria-haspopup":"dialog",onClick:u,children:[o.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M4 4h16v13H9l-5 4V4Z"}),o.jsx("path",{d:"M8 8h8M8 12h5"})]}),o.jsxs("span",{className:"settings-nav-copy",children:[o.jsx("span",{children:"Feedback inbox"}),o.jsx("small",{children:"Reports from your agents"})]})]})]}),o.jsxs("p",{className:"settings-nav-foot",children:["Switches apply automatically.",o.jsxs("span",{className:"settings-version",children:["OctiqFlow v","0.2.13"]})]})]}),o.jsxs("div",{className:"settings-content",children:[A==="sandbox"&&o.jsx(Nre,{}),A==="memory"&&o.jsx(Jse,{}),A==="agents"&&c&&o.jsx(kre,{on:a,onToggle:c,projects:V}),A==="projects"&&o.jsxs("section",{className:"settings-section","aria-labelledby":"settings-projects-title",children:[o.jsxs("header",{className:"settings-section-head",children:[o.jsxs("div",{children:[o.jsx("h2",{id:"settings-projects-title",children:"Projects"}),o.jsx("p",{children:"Manage names, folders, environment, links, and visibility."})]}),o.jsxs("button",{className:"settings-primary",type:"button",onClick:()=>r("new"),children:[o.jsx(Rre,{}),o.jsx("span",{children:"New project"})]})]}),s.length?o.jsx("div",{className:"settings-projects",children:V.map(X=>o.jsxs("button",{className:"settings-project",type:"button",onClick:()=>r(X.id),"aria-label":`Configure ${X.name}`,children:[o.jsx(Jc,{project:X,size:"medium"}),o.jsxs("span",{className:"settings-project-copy",children:[o.jsx("span",{className:"settings-project-name",children:X.name}),X.primary_path&&o.jsx("span",{className:"settings-project-path",title:X.primary_path,children:o.jsx("bdi",{children:X.primary_path})})]}),X.shelved&&o.jsx("span",{className:"settings-project-state",children:"Shelved"}),o.jsx(Dre,{})]},X.id))}):o.jsxs("div",{className:"settings-empty",children:[o.jsx("strong",{children:"No projects yet"}),o.jsx("span",{children:"Create a project to give chats their own workspace."})]})]}),A==="notifications"&&E&&o.jsxs("section",{className:"settings-section","aria-labelledby":"settings-notifications-title",children:[o.jsx("header",{className:"settings-section-head",children:o.jsxs("div",{children:[o.jsx("h2",{id:"settings-notifications-title",children:"Notifications"}),o.jsx("p",{children:"Choose when OctiqFlow can bring a chat back to your attention."})]})}),o.jsxs("div",{className:"settings-control-row",children:[o.jsxs("div",{className:"settings-control-copy",children:[o.jsx("h3",{children:"Chat activity"}),o.jsx("p",{children:"Get a banner when a chat you are not watching finishes, needs permission, or asks you a question."})]}),o.jsxs("button",{className:`set-switch${L?" is-on":""}`,type:"button",role:"switch","aria-checked":L,disabled:S,onClick:M,children:[o.jsx("span",{className:"set-switch-track","aria-hidden":"true"}),o.jsx("span",{className:"set-switch-text",children:S?"…":L?"On":"Off"})]})]}),o.jsx("p",{className:"settings-note",children:"On a phone, alerts can arrive even while OctiqFlow is closed. Nothing appears for the chat currently on screen."}),y==="needs-install"&&o.jsxs("p",{className:"set-warn",children:["iPhone and iPad only allow notifications for an app on the home screen. Tap Share, then ",o.jsx("b",{children:"Add to Home Screen"}),", open OctiqFlow from there, and turn this on again."]}),(y==="denied"||v==="denied")&&o.jsx("p",{className:"set-warn",children:"This browser is blocking notifications for OctiqFlow. Allow them in the site settings and come back."}),y==="failed"&&o.jsx("p",{className:"set-warn",children:"Could not register for notifications. This needs an https address — a plain http one will not do, even on your own network."})]}),A==="appearance"&&o.jsxs("section",{className:"settings-section settings-appearance","aria-labelledby":"settings-appearance-title",children:[o.jsx("header",{className:"settings-section-head",children:o.jsxs("div",{children:[o.jsx("h2",{id:"settings-appearance-title",children:"Appearance"}),o.jsx("p",{children:"Keep it light, stay focused in dark, or add some colour with fun mode."})]})}),o.jsx("div",{className:"thm-grid",role:"radiogroup","aria-label":"Appearance",children:kx.map(X=>{const D=Qse(X),Q=X.id===t;return o.jsxs("button",{className:`thm${Q?" is-on":""}`,type:"button",role:"radio","aria-checked":Q,onClick:()=>m(X.id),children:[o.jsxs("span",{className:"thm-shot",style:{background:D.bg},"aria-hidden":"true",children:[o.jsx("span",{className:"thm-bar",style:{background:D.sunken}}),o.jsx("span",{className:"thm-card",style:{background:D.card}}),o.jsx("span",{className:"thm-line",style:{background:D.fg}}),o.jsx("span",{className:"thm-dot",style:{background:D.accent}})]}),o.jsx("span",{className:"thm-name",children:X.name})]},X.id)})})]})]})]})]})}function _d({section:t,label:e,detail:n,active:i,onPick:s}){return o.jsxs("button",{className:`settings-nav-item${i?" is-on":""}`,type:"button","aria-current":i?"page":void 0,onClick:()=>s(t),children:[o.jsx(Tre,{section:t}),o.jsxs("span",{className:"settings-nav-copy",children:[o.jsx("span",{children:e}),o.jsx("small",{children:n})]})]})}function Tre({section:t}){return t==="agents"?o.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"9",cy:"8",r:"3"}),o.jsx("path",{d:"M3 20c0-3.3 2.7-6 6-6s6 2.7 6 6"}),o.jsx("circle",{cx:"17",cy:"9",r:"2.4"}),o.jsx("path",{d:"M16 14.2c2.9.3 5 2.6 5 5.8"})]}):t==="memory"?o.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M12 5c-3-2-6-2-9-1v15c3-1 6-1 9 1 3-2 6-2 9-1V4c-3-1-6-1-9 1Z"}),o.jsx("path",{d:"M12 5v15"})]}):t==="projects"?o.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M3 7.5h7l2 2h9v9.5H3z"}),o.jsx("path",{d:"M3 7.5V5h7l2 2h6"})]}):t==="notifications"?o.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M18 8a6 6 0 0 0-12 0c0 7-3 7-3 9h18c0-2-3-2-3-9"}),o.jsx("path",{d:"M10 21h4"})]}):o.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("circle",{cx:"12",cy:"12",r:"9"}),o.jsx("path",{d:"M12 3a9 9 0 0 0 0 18c2.2-2.2 3.3-5.2 3.3-9S14.2 5.2 12 3Z"}),o.jsx("path",{d:"M3 12h18"})]})}function Rre(){return o.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:o.jsx("path",{d:"M12 5v14M5 12h14"})})}function Dre(){return o.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"m9 18 6-6-6-6"})})}const Bre=["small","medium","large"],Hm={small:"Small",medium:"Medium",large:"Large"},$C={small:25,medium:75,large:150};async function Ore(){return await ae.invoke("agent_levels",{})}async function XM(t,e=0){return await ae.invoke("agent_level_profile",{agentId:t,offset:e})}async function oO(t,e){return await ae.invoke("orchestration_task_accept",{taskId:t,attemptId:e})}async function Ire(t,e){await ae.invoke("orchestration_task_size",{taskId:t,size:e})}function lO(t){const e=t.nextLevelXp-t.levelXp;return e<=0?0:Math.min(1,Math.max(0,(t.xp-t.levelXp)/e))}function cO(t){return`${Math.max(0,t.nextLevelXp-t.xp).toLocaleString("en-US")} XP to level ${t.level+1}`}function $re(t){if(t<1e3)return String(t);const e=[[1e9,"B"],[1e6,"M"],[1e3,"K"]];for(const[n,i]of e)if(t>=n){const s=t/n;return`${s>=100?Math.round(s):Number(s.toFixed(1))}${i}`}return String(t)}function Pre(t){const e=!!t.activeAttemptId,n=!e&&(t.status==="pending"||t.status==="ready"),i=t.size??(e?void 0:"medium");return i?{size:i,editable:n,label:`${Hm[i]} · ${$C[i]} XP`}:{editable:!1,label:"Not recorded · earns no XP"}}function zre(t){if(t.xp>0)return{amount:`+${t.xp} XP`};switch(t.unpaid){case"already_paid":return{amount:"0 XP",why:"Accepted again · paid the first time"};case"unsized":return{amount:"0 XP",why:"No size recorded"};case"no_agent":return{amount:"0 XP",why:"No registered agent"};default:return{amount:"0 XP"}}}function uO(t){return t.kind==="person"?"you":t.agentName??"the lead"}function Fre(t){return t.status!=="completed"||!t.assignee||!t.activeAttemptId?!1:t.acceptance?.attemptId!==t.activeAttemptId}function wm(t){return new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}const Hre={xp:0,level:1,levelXp:0,nextLevelXp:100};function Wre({name:t,progress:e,onOpen:n}){const i=e??Hre,s=`Level ${i.level} · ${i.xp.toLocaleString("en-US")} XP · ${cO(i)}`;return o.jsxs("button",{type:"button",className:"level-chip",onClick:n,title:s,"aria-label":`${t}: level ${i.level}, ${i.xp} XP. Open profile`,children:[o.jsxs("span",{className:"level-chip-text",children:["Lv ",i.level]}),o.jsx("span",{className:"level-chip-bar","aria-hidden":"true",children:o.jsx("span",{style:{width:`${Math.round(lO(i)*100)}%`}})})]})}function qre({progress:t,name:e}){return o.jsx("div",{className:"level-bar",role:"progressbar","aria-label":`${e}'s progress to level ${t.level+1}`,"aria-valuemin":t.levelXp,"aria-valuemax":t.nextLevelXp,"aria-valuenow":t.xp,"aria-valuetext":`${t.xp} of ${t.nextLevelXp} XP`,children:o.jsx("span",{style:{width:`${Math.round(lO(t)*100)}%`}})})}function Ure(t){if(t.chats===0)return"None yet";const e=[t.leadChats?`${t.leadChats} leading`:"",t.workerChats?`${t.workerChats} as a worker`:""].filter(Boolean);return`${t.chats} of its own: ${e.join(", ")}`}function Vre({record:t,onOpen:e}){const n=zre(t);return o.jsxs("li",{className:"xp-row",children:[o.jsxs("button",{type:"button",className:"xp-row-open",disabled:!t.coordinatorChatKey,onClick:e,"aria-label":`${t.title}: ${n.amount}${n.why?`, ${n.why}`:""}. Open task`,children:[o.jsx("span",{className:"dash-item-title",children:t.title}),o.jsxs("span",{className:"dash-item-meta",children:[n.why??(t.size?Hm[t.size]:"No size recorded")," · accepted by ",uO(t.acceptedBy)," · ",wm(t.acceptedAt)]})]}),o.jsx("span",{className:t.xp>0?"xp-gain":"xp-gain is-zero",children:n.amount})]})}function Kre({agent:t,connected:e,onOpenRun:n,onChanged:i}){const[s,r]=_.useState(null),[a,c]=_.useState([]),[u,d]=_.useState(""),[p,m]=_.useState(null),[v,x]=_.useState(""),[y,k]=_.useState(0);_.useEffect(()=>{if(!e)return;let M=!0;return XM(t.id,0).then(L=>{M&&(r(L),c([]),d(""))}).catch(L=>{M&&d(String(L.message??L))}),()=>{M=!1}},[t.id,e,y]);const S=s?[...s.history,...a]:[],C=async()=>{if(s){m("more");try{const M=await XM(t.id,S.length);c(L=>[...L,...M.history])}catch(M){d(String(M.message??M))}finally{m(null)}}},A=async(M,L)=>{m(M),x("");try{const $=await oO(M,L);x($.awarded&&$.award?`Accepted. ${t.name} earned ${$.award.xp} XP.`:`Accepted. ${$.note??"No XP was paid."}`),k(V=>V+1),i()}catch($){d(String($.message??$))}finally{m(null)}},N=(M,L)=>{if(M)try{n(M,L)}catch($){d(String($.message??$))}},E=s?.usage;return o.jsxs("section",{className:"agent-profile","aria-label":`${t.name}'s profile`,children:[o.jsxs("header",{className:"agent-profile-head",children:[o.jsx(ws,{name:t.name,avatar:t.avatar,id:t.id,size:44,removed:t.removed,decorative:!0}),o.jsxs("div",{className:"agent-profile-title",children:[o.jsx("h2",{children:o.jsx("bdi",{children:t.name})}),t.detail&&o.jsx("span",{className:"team-row-meta",children:o.jsx("bdi",{children:t.detail})})]})]}),u&&o.jsx("p",{className:"set-warn",role:"alert",children:u}),v&&o.jsx("p",{className:"agent-profile-notice",role:"status",children:v}),!s&&!u&&o.jsx("p",{className:"projects-page-meta",children:"Loading profile…"}),s&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"level-block",children:[o.jsxs("div",{className:"level-head",children:[o.jsxs("strong",{className:"level-number",children:["Level ",s.level]}),o.jsxs("span",{className:"level-xp",children:[s.xp.toLocaleString("en-US")," XP"]})]}),o.jsx(qre,{progress:s,name:t.name}),o.jsx("p",{className:"level-next",children:cO(s)})]}),o.jsxs("dl",{className:"agent-profile-stats",children:[o.jsxs("div",{children:[o.jsx("dt",{children:"Accepted tasks"}),o.jsxs("dd",{title:"Every task accepted for this agent, counted once for good, including those that earned no XP",children:[s.acceptedTasks.toLocaleString("en-US"),o.jsx("span",{className:"agent-profile-stat-note",children:"lifetime"})]})]}),o.jsxs("div",{children:[o.jsx("dt",{children:"Tokens used"}),o.jsx("dd",{title:E&&E.chats>0?`${E.total.toLocaleString("en-US")} tokens`:void 0,children:E?E.chats===0?"None recorded":$re(E.total):"Unavailable"})]})]}),s.awaiting.length>0&&o.jsxs("section",{className:"agent-profile-section","aria-label":"Waiting for acceptance",children:[o.jsx("h3",{children:"Waiting for acceptance"}),o.jsx("ul",{className:"agent-profile-list",children:s.awaiting.map(M=>o.jsxs("li",{className:"xp-row",children:[o.jsxs("button",{type:"button",className:"xp-row-open",onClick:()=>N(M.coordinatorChatKey,M.runId),"aria-label":`Open task: ${M.title}`,children:[o.jsx("span",{className:"dash-item-title",children:M.title}),o.jsxs("span",{className:"dash-item-meta",children:[M.size?Hm[M.size]:"No size recorded",M.unscored?" · earns no XP":""," · finished ",wm(M.finishedAt)]})]}),o.jsx("button",{type:"button",className:"vault-button xp-accept",disabled:p!==null||!e,onClick:()=>{A(M.taskId,M.attemptId)},children:p===M.taskId?"Accepting…":"Accept"})]},M.taskId))})]}),o.jsxs("section",{className:"agent-profile-section","aria-label":"XP history",children:[o.jsx("h3",{children:"XP history"}),S.length===0?o.jsx("p",{className:"projects-page-meta",children:"No accepted tasks yet."}):o.jsx("ul",{className:"agent-profile-list",children:S.map(M=>o.jsx(Vre,{record:M,onOpen:()=>N(M.coordinatorChatKey,M.runId)},`${M.taskId}:${M.attemptId}`))}),S.length<s.historyTotal&&o.jsx("button",{type:"button",className:"dash-more",disabled:p!==null,onClick:()=>{C()},children:p==="more"?"Loading…":`Show more (${s.historyTotal-S.length})`})]}),E&&o.jsxs("details",{className:"agent-profile-details",children:[o.jsx("summary",{children:"Token usage"}),o.jsxs("dl",{className:"plan-card-facts",children:[o.jsx("dt",{children:"Input"}),o.jsxs("dd",{children:[E.usage.input.toLocaleString("en-US"),o.jsxs("span",{className:"plan-card-note",children:[E.usage.cachedInput.toLocaleString("en-US")," from cache",E.usage.cacheWrite>0?`, ${E.usage.cacheWrite.toLocaleString("en-US")} written to cache`:""]})]}),o.jsx("dt",{children:"Output"}),o.jsxs("dd",{children:[E.usage.output.toLocaleString("en-US"),E.reasoningReported&&o.jsxs("span",{className:"plan-card-note",children:[E.usage.reasoning.toLocaleString("en-US")," reasoning (Codex only)"]})]}),o.jsx("dt",{children:"Chats"}),o.jsx("dd",{children:Ure(E)})]}),o.jsxs("p",{className:"agent-profile-fine",children:["Counted since ",wm(E.since||s.scoringSince),", from what each provider reports, so this is a floor: earlier chats, and a turn stopped before the provider reported it, are not included. Claude’s figures include helper subagents it runs inside its own chat. Registered reports have their own chats and count for themselves. Cached and reasoning tokens are part of input and output, not extra."]})]}),s.usageError&&o.jsx("p",{className:"set-warn",role:"alert",children:s.usageError}),o.jsxs("details",{className:"agent-profile-details",children:[o.jsx("summary",{children:"How levels work"}),o.jsxs("ul",{className:"agent-profile-rules",children:[o.jsxs("li",{children:["XP is paid when you or the responsible lead accept a finished task:"," ",s.rules.sizes.map(([M,L])=>`${Hm[M].toLowerCase()} ${L}`).join(", "),"."]}),o.jsx("li",{children:"The size is chosen before the task starts and cannot change after. Each task pays once, however often it is reopened or retried."}),o.jsx("li",{children:"Accepted tasks counts every task you or a lead accepted, once and for good, including tasks that earned no XP. A task reopened and accepted again shows in the history again, but is counted once."}),o.jsxs("li",{children:["Level 1 starts at 0 XP. Going from level L to L+1 takes ",s.rules.levelStep," × L XP."]}),o.jsx("li",{children:"Only accepted tasks in runs count. Work in ordinary chats is not scored."}),o.jsxs("li",{children:["Scoring began ",wm(s.scoringSince),". Tasks finished before then are not scored."]}),o.jsx("li",{children:"Token usage is shown for information only. It does not affect XP."})]})]})]})]})}const QM=3;function Gre({snapshot:t,ledgerError:e,connected:n,projects:i,running:s,busy:r,waitingOn:a,chatTitle:c,chatExists:u,onOpenChat:d,onOpenRun:p,onManage:m,onClose:v}){const[x,y]=_.useState(null),[k,S]=_.useState([]),[C,A]=_.useState(""),[N,E]=_.useState(null),[M,L]=_.useState(new Set),[$,V]=_.useState(""),[X,D]=_.useState(new Map),[Q,P]=_.useState(0),[z,H]=_.useState(null),W=_.useMemo(()=>(t?.tasks??[]).filter(re=>re.acceptance).map(re=>`${re.id}:${re.acceptance.attemptId}`).sort().join(","),[t]);_.useEffect(()=>{if(!n)return;let re=!0;return Ore().then(ve=>{re&&D(new Map((ve??[]).map(le=>[le.agentId,le])))}).catch(()=>{re&&D(new Map)}),()=>{re=!1}},[n,W,Q]),_.useEffect(()=>{if(!n)return;let re=!0;return Promise.all([tf(null,!0),eO()]).then(([ve,le])=>{re&&(y(ve),S(le),A(""))}).catch(ve=>{re&&A(String(ve.message??ve))}),()=>{re=!1}},[n]);const F=_.useMemo(()=>[...s].sort().join(",")+"|"+[...r].sort().join(","),[s,r]);_.useEffect(()=>{if(!n)return;let re=!0;return ae.invoke("chat_activity").then(ve=>{re&&E(new Map((ve??[]).map(le=>[le.key,le.busy])))}).catch(()=>{re&&E(null)}),()=>{re=!1}},[n,F]);const Y=re=>{const ve=re.replace(/^chat:/,"");if(r.has(ve))return"busy";const le=N?.get(re);return le!==void 0?le?"busy":"idle":N?"ended":s.has(ve)?"unknown":"ended"},J=_.useMemo(()=>i.map(({id:re,name:ve})=>({id:re,name:ve})),[i]),te=Xte({team:x,leads:k,snapshot:t,projects:J,providerLabel:re=>`${Xo[re.agent]} ${re.model}`,chatTitle:c,chatExists:u,leadActivity:Y,waitingOn:a}),I=Qte(te),U=!n||!!e,Z=re=>i.find(ve=>ve.id===re),R=re=>{V("");try{if(re.chatKey)d(re.chatKey);else if(re.runId){const ve=t?.runs.find(le=>le.id===re.runId);ve&&p(ve.coordinatorChatKey,ve.id)}}catch(ve){V(String(ve.message??ve))}},K=re=>!!re.chatKey||!!re.runId&&!!t?.runs.some(ve=>ve.id===re.runId),O=z?te.find(re=>re.id===z):void 0;if(z&&O)return o.jsxs("section",{className:"projects-page agents-dashboard","aria-label":"Agents",children:[o.jsx(kh,{root:!0,back:{label:"All agents",ariaLabel:"Back to all agents",onClick:()=>H(null)},title:o.jsx("h1",{children:O.name}),actions:o.jsx("button",{type:"button",className:"projects-page-secondary",onClick:m,children:"Manage agents"})}),o.jsx("div",{className:"projects-page-body",children:o.jsx(Kre,{agent:O,connected:n,onOpenRun:p,onChanged:()=>P(re=>re+1)})})]});const ie=re=>L(ve=>{const le=new Set(ve);return le.has(re)?le.delete(re):le.add(re),le});return o.jsxs("section",{className:"projects-page agents-dashboard","aria-label":"Agents",children:[o.jsx(kh,{root:!0,back:{label:"Chat",ariaLabel:"Back to chat",onClick:v},title:o.jsx("h1",{children:"Agents"}),actions:o.jsx("button",{type:"button",className:"projects-page-secondary",onClick:m,children:"Manage agents"})}),o.jsxs("div",{className:"projects-page-body",children:[o.jsx("p",{className:"projects-page-meta dash-summary","aria-live":"polite",children:x===null&&!C?"Loading agents…":I.length===0?"Who is doing what":I.map(({state:re,count:ve})=>`${ve} ${sk[re].toLowerCase()}`).join(" · ")}),U&&x!==null&&o.jsx("p",{className:"dash-stale",role:"status",children:n?"Could not refresh work. Showing the last known state.":"Disconnected. Showing the last known state."}),C&&o.jsx("p",{className:"set-warn",role:"alert",children:C}),$&&o.jsx("p",{className:"set-warn",role:"alert",children:$}),x!==null&&te.length===0?o.jsxs("div",{className:"settings-empty",children:[o.jsx("strong",{children:"No agents yet"}),o.jsx("button",{className:"vault-button",type:"button",onClick:m,children:"Add agents in Settings"})]}):o.jsx("ul",{className:"team-list agents-dashboard-list",children:te.map(re=>o.jsx(Yre,{row:re,stale:U,expanded:M.has(re.id),onToggle:()=>ie(re.id),appearance:Z,canOpen:K,onOpen:R,level:X.get(re.id),onProfile:()=>H(re.id),onOpenRecent:ve=>{V("");try{d(ve)}catch(le){V(String(le.message??le))}}},re.id))})]})]})}function Yre({row:t,stale:e,expanded:n,onToggle:i,appearance:s,canOpen:r,onOpen:a,onOpenRecent:c,level:u,onProfile:d}){const p=t.state==="working"&&!e,m=n?t.activities:t.activities.slice(0,QM),v=Object.entries(t.counts).filter(([y])=>y!==t.state),x=sk[t.state];return o.jsxs("li",{className:"dash-agent","data-state":t.state,style:{"--team-depth":t.depth},children:[o.jsxs("div",{className:"dash-agent-head",children:[t.depth>0&&o.jsx("span",{className:"team-row-branch","aria-hidden":"true",children:"└"}),o.jsx(ws,{name:t.name,avatar:t.avatar,id:t.id,size:28,removed:t.removed,className:p?"dash-avatar is-working":"dash-avatar",label:`${t.name}, ${x.toLowerCase()}`}),o.jsxs("span",{className:"team-row-copy",children:[o.jsxs("span",{className:"team-row-name",children:[o.jsx("bdi",{children:t.name}),!t.removed&&o.jsx(Wre,{name:t.name,progress:u,onOpen:d})]}),o.jsxs("span",{className:"team-row-meta",children:[o.jsx("bdi",{children:t.detail}),o.jsx("span",{"aria-hidden":"true",children:" · "}),t.removed?"Removed":t.scope?o.jsx("bdi",{children:t.scope.name}):"All projects"]})]}),o.jsxs("span",{className:"dash-agent-status",children:[o.jsx("span",{className:`dash-state is-${t.state}${e?" is-stale":""}`,title:e?`Last known: ${t.stateLabel}`:t.stateLabel,children:e?`${x} (last known)`:x}),v.map(([y,k])=>o.jsxs("span",{className:`dash-count is-${y}`,children:[k," ",sk[y].toLowerCase()]},y))]})]}),t.role&&o.jsx(sO,{className:"dash-agent-role",text:t.role,name:t.name}),t.activities.length>0?o.jsxs("div",{className:"dash-agent-work",children:[m.map(y=>o.jsxs("button",{className:"dash-item",type:"button","data-state":y.state,disabled:!r(y),onClick:()=>a(y),"aria-label":`${y.label}: ${y.title}${y.project?`, in ${y.project.name}`:""}. Open ${y.kind==="lead"?"conversation":"task"}`,children:[o.jsx("span",{className:`dash-dot is-${y.state}`,"aria-hidden":"true"}),o.jsxs("span",{className:"dash-item-copy",children:[o.jsx("span",{className:"dash-item-title",children:y.title}),o.jsxs("span",{className:"dash-item-meta",children:[o.jsx("span",{className:"dash-item-state",children:y.label}),y.project?o.jsxs("span",{className:"dash-item-project",children:[s(y.project.id)&&o.jsx(Jc,{project:s(y.project.id),size:"tiny"}),o.jsx("bdi",{children:y.project.name})]}):y.crossProject?o.jsx("span",{className:"dash-item-project",children:"Across projects"}):null]})]}),o.jsx("span",{className:"dash-item-open","aria-hidden":"true",children:"Open"})]},y.key)),t.activities.length>QM&&o.jsx("button",{className:"dash-more",type:"button","aria-expanded":n,onClick:i,children:n?"Show fewer":`Show all ${t.activities.length}`})]}):t.recent?o.jsx("div",{className:"dash-agent-work",children:o.jsxs("button",{className:"dash-recent",type:"button",onClick:()=>c(t.recent.chatKey),"aria-label":`Open last: ${t.recent.title}`,children:["Last: ",o.jsx("span",{className:"dash-item-title",children:t.recent.title})]})}):null]})}function Xre(t){return!!t.headId&&t.recipientId===t.headId}function Qre(t){return(t??"").trim().toLowerCase()==="general"}function Zre(t){const{toHead:e,project:n,homeId:i,repo:s,sandboxDefault:r}=t,a=t.overrides??{},c=Object.values(a).some(S=>S!==void 0);if(e)return{target:"home",projectId:i??null,prepare:!1,branch:"",newWorktree:!1,useSandbox:!1,chosenBy:"auto",reason:"Coordinates from your home workspace. Each task it hands out runs where the host routes it.",crossProject:!0};const u=a.projectId!==void 0?a.projectId:n?.id??null;if(!u||u===i||u===n?.id&&Qre(n?.name))return{target:"home",projectId:u??i??null,prepare:!1,branch:"",newWorktree:!1,useSandbox:a.useSandbox??!1,chosenBy:c?"advanced":"auto",reason:"No code project: works from your home workspace.",crossProject:!1};const p=!!s&&!s.loading&&!s.error,m=a.branch??(p&&s.isRepo?s.current:""),v=a.newWorktree??!0,x=a.useSandbox??r,y=m||"the project's current branch",k=c?"Chosen under Advanced.":p&&!s.isRepo?"Not a Git repository: works in the project folder.":`New worktree from ${y}, so the primary checkout stays untouched.`;return{target:"project",projectId:u,prepare:!0,branch:m,newWorktree:v,useSandbox:x,chosenBy:c?"advanced":"auto",reason:k,crossProject:!1}}const Jre=6e4,eae=15e3,hO="octiq.v2.usage",tae=180,nae=60,iae=85;function sae(){try{const t=JSON.parse(localStorage.getItem(hO)||"null");if(!t||typeof t!="object")return{claude:null,codex:null};const e=n=>n?.available?n:null;return{claude:e(t.claude),codex:e(t.codex)}}catch{return{claude:null,codex:null}}}function dO(t){return t>=iae?"is-danger":t>=nae?"is-warn":""}function rae(t){if(!t)return"";const e=t-Date.now()/1e3;if(e<=0)return"resetting";const n=Math.floor(e/3600),i=Math.floor(e%3600/60);return n>=24?`resets in ${Math.floor(n/24)}d ${n%24}h`:n?`resets in ${n}h ${i}m`:`resets in ${i}m`}function aae(){const[t,e]=_.useState(sae),[n,i]=_.useState({claude:!0,codex:!0}),[s,r]=_.useState(null),a=_.useRef(null),c=_.useRef(0),u=_.useCallback(()=>{a.current&&clearTimeout(a.current),a.current=null},[]);_.useEffect(()=>u,[u]);const d=_.useCallback(async m=>{if(!(!m&&Date.now()-c.current<eae)){c.current=Date.now();try{const v=await ae.invoke("usage_summary"),x=(y,k)=>y?.available?y:k?.available?k:y??k??null;e(y=>{const k={claude:x(v?.claude,y.claude),codex:x(v?.codex,y.codex)};try{localStorage.setItem(hO,JSON.stringify({claude:k.claude?.available?k.claude:y.claude,codex:k.codex?.available?k.codex:y.codex}))}catch{}return k}),i({claude:!v?.claude?.available,codex:!v?.codex?.available})}catch{i({claude:!0,codex:!0})}}},[]);if(_.useEffect(()=>{d(!0);const m=setInterval(()=>{d(!0)},Jre),v=()=>document.visibilityState==="visible"&&void d(!1);return document.addEventListener("visibilitychange",v),window.addEventListener("focus",v),()=>{clearInterval(m),document.removeEventListener("visibilitychange",v),window.removeEventListener("focus",v)}},[d]),!t.claude&&!t.codex)return null;const p=lae(t);return o.jsxs("div",{className:"usage",onPointerEnter:m=>{m.pointerType==="mouse"&&(u(),r(v=>v??"hover"),d(!1))},onPointerLeave:m=>{m.pointerType==="mouse"&&(u(),a.current=setTimeout(()=>r(v=>v==="hover"?null:v),tae))},children:[o.jsxs("button",{className:`usage-btn${p&&n[p.provider]?" is-stale":""}`,type:"button","aria-label":cae(t),"aria-haspopup":"dialog","aria-expanded":s!==null,title:"Plan usage — hover or tap for every window",onClick:()=>{u(),r(m=>m==="pin"?null:"pin"),d(!0)},children:[o.jsx(uae,{}),o.jsx("span",{className:`usage-val ${p?dO(p.percent):""}`,children:p?o.jsx(Lt,{children:`${Math.round(p.percent)}%`}):"—"})]}),s&&o.jsxs(o.Fragment,{children:[s==="pin"&&o.jsx("div",{className:"usage-scrim",onClick:()=>r(null)}),o.jsxs("div",{className:"usage-pop",role:"dialog","aria-label":"Plan usage",children:[o.jsx(ZM,{name:"Claude",provider:t.claude,stale:n.claude}),o.jsx(ZM,{name:"Codex",provider:t.codex,stale:n.codex})]})]})]})}function fO(t){const e=[];t?.fiveHour&&e.push({label:"5h",window:t.fiveHour}),t?.weekly&&e.push({label:"7d",window:t.weekly});for(const n of t?.models??[])e.push({label:n.name,window:n});return e.length===0?null:e.reduce((n,i)=>i.window.percent>n.window.percent?i:n)}const oae={claude:"Claude",codex:"Codex"};function lae(t){let e=null;for(const n of["claude","codex"]){const i=fO(t[n]);if(!i)continue;const s=Math.min(100,Math.max(0,i.window.percent));(!e||s>e.percent)&&(e={provider:n,label:i.label,percent:s})}return e}function cae(t){const e=["claude","codex"].flatMap(n=>{const i=fO(t[n]);return i?[`${oae[n]} ${i.label} ${Math.round(Math.min(100,Math.max(0,i.window.percent)))}%`]:[]});return e.length?`Plan usage: ${e.join(", ")}`:"Plan usage: no reading yet"}function uae(){return o.jsxs("svg",{className:"usage-icon",width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("path",{d:"M4.5 18a9 9 0 1 1 15 0"}),o.jsx("path",{d:"m12 13 3.5-4"}),o.jsx("circle",{cx:"12",cy:"13",r:"1"})]})}function ZM({name:t,provider:e,stale:n}){return o.jsxs("section",{className:"usage-block",children:[o.jsxs("header",{className:"usage-block-head",children:[o.jsx("span",{className:"usage-block-name",children:t}),e?.plan&&o.jsx("span",{className:"usage-plan",children:e.plan}),n&&o.jsx("span",{className:"usage-stale",children:"last known"})]}),e?o.jsxs(o.Fragment,{children:[o.jsx(Vb,{label:"5 hours",window:e.fiveHour}),o.jsx(Vb,{label:"Week",window:e.weekly}),(e.models??[]).map(i=>o.jsx(Vb,{label:`Week · ${i.name}`,window:i},i.name)),e.note&&o.jsx("div",{className:"usage-empty",children:e.note})]}):o.jsx("div",{className:"usage-empty",children:"No reading yet."})]})}function Vb({label:t,window:e}){if(!e)return null;const n=Math.min(100,Math.max(0,e.percent));return o.jsxs("div",{className:"usage-row",children:[o.jsx("span",{className:"usage-row-label",children:t}),o.jsx("span",{className:`usage-track ${dO(n)}`,children:o.jsx("span",{className:"usage-fill",style:{width:`${n}%`}})}),o.jsx("span",{className:"usage-val",children:o.jsx(Lt,{children:`${Number.isInteger(n)?n:n.toFixed(1)}%`})}),o.jsx("span",{className:"usage-reset",children:o.jsx(Lt,{children:rae(e.resetsAt)})})]})}const nf="octiq-git-changed";function hae(t){const e=new Set;for(const n of t)for(const i of[n.primary_path,...n.paths??[]])i?.trim()&&e.add(i);return[...e]}function dae(t){return[...new Set(t.flatMap(e=>e.primary_path?.trim()?[e.primary_path]:[]))]}function fae(t,e){const n=new Map(e.map(s=>[s.path,s])),i={};for(const s of t){if(!s.primary_path)continue;const r=n.get(s.primary_path);r?.is_repo&&r.branch&&(i[s.id]=r.branch)}return i}const pae={added:{letter:"A",cls:"is-add"},deleted:{letter:"D",cls:"is-del"},renamed:{letter:"R",cls:"is-ren"},untracked:{letter:"U",cls:"is-new"}},mae={letter:"M",cls:"is-mod"},pO=["rebase","merge","ff-only"],JM="octiq.v2.gitPullMode",gae="octiq.v2.gitWidth",vae={initial:380,min:280,max:680},xae=/^(diff --git |index |--- |\+\+\+ |new file mode|deleted file mode|old mode|new mode|similarity index|dissimilarity index|rename from|rename to|copy from|copy to|Binary files )/;function mO(t){return t?[t.primary_path??"",...t.paths??[]].filter(e=>e.trim()!=="").join(`
205
205
  `):""}function yae(t){const e=new Map;for(const n of t)!n.is_repo||!n.repo_root||e.has(n.repo_root)||e.set(n.repo_root,n);return[...e.values()]}function _ae(t){const e=t.lastIndexOf("/");return e<0?{dir:"",name:t}:{dir:t.slice(0,e),name:t.slice(e+1)}}function bae({project:t,open:e,onToggle:n}){const[i,s]=_.useState([]),[r,a]=_.useState(null),c=t?.primary_path??"",u=mO(t),d=_.useMemo(()=>u?u.split(`
206
206
  `):[],[u]);_.useEffect(()=>{if(d.length===0){s([]);return}let x=!0;const y=()=>{ae.invoke("git_status_summary",{paths:d}).then(S=>{if(!x)return;const C=S??[];s(yae(C)),a(C.find(A=>A.is_repo&&A.path===c)??null)}).catch(()=>{x&&s([])})};window.addEventListener("focus",y),window.addEventListener(nf,y);const k=ae.onState(S=>{S==="open"&&y()});return()=>{x=!1,window.removeEventListener("focus",y),window.removeEventListener(nf,y),k()}},[d,c]);const p=i.reduce((x,y)=>x+y.changed,0),m=i.reduce((x,y)=>x+y.ahead,0),v=_.useMemo(()=>{if(i.length===0)return[];const x=i.filter(y=>y.repo_root!==r?.repo_root);return r?[r,...x]:x},[i,r]);return o.jsxs("button",{className:`gitp-toggle ${e?"is-on":""}`,type:"button","aria-expanded":e,"aria-label":["Git",p>0?`${p} changed`:null,m>0?`${m} to push`:null].filter(Boolean).join(", "),title:t?[`Git — ${t.name}`,...v.map((x,y)=>{const k=x.repo_root.split("/").pop()??x.repo_root,S=[x.changed>0?`${x.changed} changed`:"clean",x.ahead>0?`↑${x.ahead} to push`:null].filter(Boolean).join(" · ");return`${k} · ${x.branch||"(detached)"} · ${S}${y===0&&r?" — this chat":""}`})].join(`
207
207
  `):"Git",onClick:n,children:[o.jsx(Aae,{}),o.jsx("span",{className:"topbar-action-label",children:"Git"}),p>0&&o.jsx("span",{className:"gitp-badge",children:o.jsx(cr,{value:p})}),m>0&&o.jsxs("span",{className:"gitp-badge is-ahead",children:["↑",o.jsx(cr,{value:m})]})]})}function wae({project:t,open:e,persistent:n=!1,onClose:i}){const[s,r]=_.useState(null),[a,c]=_.useState(null),[u,d]=_.useState(!1),[p,m]=_.useState({}),[v,x]=_.useState({}),[y,k]=_.useState(""),[S,C]=_.useState(null),[A,N]=_.useState(!1),{width:E,startDrag:M,entered:L}=of(gae,vae),[$,V]=_.useState(()=>{const Z=localStorage.getItem(JM);return pO.includes(Z)?Z:"rebase"}),X=mO(t),D=_.useMemo(()=>X?X.split(`
@@ -320,7 +320,7 @@ ${n.map(s=>`- ${s.path}`).join(`
320
320
 
321
321
  Files to look at:
322
322
  ${Ze.map($e=>`- ${$e}`).join(`
323
- `)}`.trim());const Oe=O??crypto.randomUUID(),Ve=j;if(G){try{j=await sre(pt(Oe),Se.id,G.id,j,fe)}catch($t){qt(`Could not hand the task to ${G.name}: ${String($t.message??$t)}`);return}const $e={chatKey:pt(Oe),leadId:G.id,leadName:G.name,projectId:Se.id,crossProject:fe||void 0,createdAt:Date.now()};dg($t=>[...$t.filter(Hi=>Hi.chatKey!==$e.chatKey),$e])}if(O||ie(Oe),j.trim()==="/clear"){const $e=pt(Oe);Ia.current.has(Oe)&&ae.invoke("chat_send",{key:$e,text:j,recordUser:!1}).catch(()=>{}),ae.invoke("chat_forget",{key:$e}).catch(()=>{}),As.current.delete(Oe),sa.current.forget(Oe),zh.current.delete(Oe),G5(Oe),Ii.current.own($e),It(Oe,$t=>({...Uc(),sessionId:$t.sessionId})),K($t=>{const Hi=$t.map(er=>er.id===Oe?{...er,messages:[],seq:0,updatedAt:Date.now()}:er);return Ms(Hi),Hi});return}const Ie=Oa.current.get(Oe);if(Ie)try{await Ie}catch{return}const Wt=Ba.current.has(Oe),Ut=Wt?FT(Mn.current[Oe]?.messages??[]):void 0;ci.current[Oe]={projectId:Se.id,modelId:_t.id,access:pi};const hn=j1(),Fi=_oe(sL(ii.current,pt(Oe)));It(Oe,$e=>q_($e,j,B.map($t=>({path:$t.path,name:$t.name,isImage:!!$t.isImage})),void 0,hn)),Ir.current.add(hn);const et=$e=>It(Oe,$t=>({...$t,busy:Ia.current.has(Oe)?$t.busy:!1,messages:$t.messages.map(Hi=>Hi.turnId===hn&&!Hi.echo&&!Hi.takenUp?{...Hi,delivery:"unknown",queueError:String($e.message??$e)}:Hi)}));try{const $e=$n.current.find(Sn=>Sn.id===Oe),$t=$e?.cwd??Mn.current[Oe]?.cwd;let Hi=$t??Se.primary_path??"",er;const da=!$t&&!!bt&&bt.id===Se.id&&(ee?ee.prepare&&ee.target==="project":Ol(bt.name)!=="general"),Ru=ee?ee.branch:At,cc=ee?ee.newWorktree:at,uc=ee?ee.useSandbox:pn??We.snapshot?.defaultEnabled??!1,by=$e?void 0:{projectId:Se.id,projectName:Se.name,path:Se.primary_path??"",baseBranch:da?Ru||(bt?.id===Se.id?ke.current:""):"",newWorktree:da&&cc,useSandbox:uc,prepare:da,chosenBy:ee?ee.chosenBy:"person",reason:ee?.reason??"",decidedAt:Date.now()};if(da&&bt)try{const Sn=await ae.invoke("git_prepare_chat_workspace",{path:bt.primary_path??"",branch:Ru,newWorktree:cc,prompt:Ve,chatId:Oe});Hi=Sn.cwd,nn(Sn.branch),Je(tr=>({isRepo:Sn.is_repo,current:Sn.branch,branches:Sn.branch&&!tr.branches.includes(Sn.branch)?[Sn.branch,...tr.branches]:tr.branches,isWorktree:Sn.is_worktree})),It(Oe,tr=>({...tr,cwd:Hi}))}catch(Sn){er=Sn}const si=Date.now(),ns=oA($e,{...$e??{},id:Oe,projectId:Se.id,title:$e?.title??d0(Ve),latestResponse:$e?.latestResponse,customTitle:$e?.customTitle,sessionId:Mn.current[Oe]?.sessionId??$e?.sessionId,cwd:er?$e?.cwd:Hi,messages:Mn.current[Oe]?.messages??$e?.messages??[],modelId:_t.id,permission:pi,createdAt:$e?.createdAt??si,updatedAt:si,pinned:$e?.pinned??!1,generation:$e?.generation,launch:$e?.launch??by});if(K(Sn=>{const tr=[ns,...Sn.filter(rd=>rd.id!==Oe)];return Ms(tr),tr}),Dp({id:ns.id,projectId:ns.projectId,title:ns.title,latestResponse:ns.latestResponse,customTitle:ns.customTitle,sessionId:ns.sessionId??null,cwd:ns.cwd??null,modelId:ns.modelId??null,access:ns.permission??null,createdAt:ns.createdAt,updatedAt:ns.updatedAt,pinned:ns.pinned??!1,generation:ns.generation,launch:ns.launch}),er){et(er);return}if(!Wt&&Ia.current.has(Oe))try{await ae.invoke("chat_send",{key:pt(Oe),text:j,images:Ee,turnId:hn,seenPlans:Fi});return}catch(Sn){if(!String(Sn.message??Sn).includes("no such chat")){et(Sn);return}}const sd=Wt?null:Mn.current[Oe]?.sessionId??$n.current.find(Sn=>Sn.id===Oe)?.sessionId??null;Ii.current.holds(pt(Oe))||(sd?await aa(Oe,$n.current.find(Sn=>Sn.id===Oe)?.seq).catch(()=>{}):Ii.current.own(pt(Oe))),L(Sn=>new Set(Sn).add(Oe));try{await ae.invoke("chat_start",{key:pt(Oe),cwd:Hi,useSandbox:$e?!1:ee?ee.useSandbox:pn??We.snapshot?.defaultEnabled??null,extraDirs:Se.paths??[],env:Se.env??{},agent:_t.agent,model:_t.flag||null,access:pi,effort:Ji,lite:lo,images:Ee,prompt:j,handoff:Ut??null,turnId:hn,seenPlans:Fi,resume:sd}),Wt&&Ba.current.delete(Oe)}catch(Sn){if(!Wt&&String(Sn.message??Sn).includes("already running"))try{await ae.invoke("chat_send",{key:pt(Oe),text:j,images:Ee,turnId:hn,seenPlans:Fi});return}catch(tr){et(tr)}else et(Sn);L(tr=>{const rd=new Set(tr);return rd.delete(Oe),rd})}}finally{Ir.current.delete(hn),la(Oe).catch(()=>{})}},[bt,Of,At,at,pn,We.snapshot?.defaultEnabled,_t,pi,Ji,lo,O,It,aa,la,un,mi,nc,rl,n,gt,Rn,ke]),_y=_.useCallback(async j=>{const B=n.find(Ve=>Ve.id===j.projectId);if(!B)throw new Error("The selected project is no longer available.");if(!j.cwd)throw new Error("The selected repository has no working directory.");const G=crypto.randomUUID(),ee=Date.now(),fe=j.access??pi,Se={...Uc(),cwd:j.cwd},Ee={id:G,projectId:B.id,title:j.title,customTitle:!0,cwd:j.cwd,messages:[],modelId:_t.id,permission:fe,createdAt:ee,updatedAt:ee};await ae.invoke("chat_index_save",{meta:{...Ee,messages:void 0,sessionId:null,access:fe,pinned:!1,generation:0}}),ci.current[G]={projectId:B.id,modelId:_t.id,access:fe},Ii.current.own(pt(G)),It(G,()=>Se);const Ze=[Ee,...$n.current.filter(Ve=>Ve.id!==G)];$n.current=Ze,K(Ze),Ms(Ze);let Oe=!1;return{chatId:G,start:async()=>{if(Oe)throw new Error("This PR agent chat has already been started.");Oe=!0;const Ve=j1(),Ie=Date.now(),Wt=q_(Mn.current[G]??Se,j.prompt,[],Ie,Ve);It(G,()=>Wt);const Ut=$n.current.map(hn=>hn.id===G?{...hn,messages:Wt.messages,updatedAt:Ie}:hn);$n.current=Ut,K(Ut),Ms(Ut),Ir.current.add(Ve),L(hn=>new Set(hn).add(G));try{await ae.invoke("chat_start",{key:pt(G),cwd:j.cwd,extraDirs:B.paths??[],env:B.env??{},agent:_t.agent,model:_t.flag||null,access:fe,effort:Ji,lite:lo,images:[],prompt:j.prompt,handoff:null,turnId:Ve,resume:null})}catch(hn){const Fi=String(hn?.message??hn);throw It(G,et=>({...et,busy:!1,messages:et.messages.map($e=>$e.turnId===Ve?{...$e,delivery:"unknown",queueError:Fi}:$e),notices:[...et.notices,`Could not start this PR agent: ${Fi}`].slice(-8)})),L(et=>{const $e=new Set(et);return $e.delete(G),$e}),hn}finally{Ir.current.delete(Ve)}}}},[n,_t,pi,Ji,lo,It]);_.useEffect(()=>{!Ks||Ks.id!==O||gt||(Ni(null),Wr(Ks.text))},[Ks,O,gt,Wr]);const Eg=_.useCallback(()=>{!O||!Ia.current.has(O)||(It(O,j=>({...j,stopping:!0})),ae.invoke("chat_interrupt",{key:pt(O)}).catch(()=>{}))},[O,It]),Jh=_.useCallback((j,B)=>{if(!O||t!=="open")return;const G=O;yu.current.run({chatId:G,turnId:j,action:B,read:()=>Mn.current[G]??im,patch:ee=>It(G,ee),invoke:ee=>ae.invoke(ee,{key:pt(G),turnId:j}),refresh:async()=>{await aa(G),await la(G)},reclaim:ee=>qh(G,j,ee)})},[O,t,It,aa,la,qh]),Mg=_.useCallback(j=>Jh(j,"cancel"),[Jh]),gl=_.useCallback(j=>Jh(j,"start"),[Jh]),Zf=_.useCallback(j=>{if(!O)return;const B=Mn.current[O];if(!B?.messages.some(ee=>ee.turnId===j&&(ee.queueLost||ee.delivery==="unknown")&&!ee.echo&&!ee.takenUp))return;const G=B.messages.find(ee=>ee.turnId===j);G&&Pf(ee=>({...ee,[O]:[...ee[O]??[],zT(G)]}))},[O]),ed=_.useCallback(j=>{if(!O)return;const B=O;Mn.current[B]?.messages.some(ee=>ee.turnId===j&&ee.queueLost&&!ee.echo&&!ee.takenUp)&&ae.invoke("chat_dismiss_unsent",{key:pt(B),turnId:j}).then(ee=>{ee!==!1&&It(B,fe=>({...fe,messages:fe.messages.filter(Se=>Se.turnId!==j)}))}).catch(ee=>It(B,fe=>({...fe,notices:[...fe.notices,String(ee.message??ee)]})))},[O,It]),Jf=_.useCallback(j=>{if(!O||!Ia.current.has(O))return!1;const B=j1();return It(O,G=>q_(G,j,[],void 0,B)),ae.invoke("chat_send",{key:pt(O),text:j,turnId:B}).catch(()=>{}),!0},[O,It]),vl=_.useCallback(j=>{const B=_t;if(j.id===B.id)return;const G=Ku(j.agent,pi);oo(j),Ln(c0,j.id),G!==pi&&(sl(G),Ln(u0,G));const ee=Zw(j.agent,Ji);if(ee!==Ji&&(Qs(ee),Ln(sm,ee)),O&&ci.current[O]&&(ci.current[O].modelId=j.id),!O||rt.messages.length===0)return;const fe=O,Se=Mn.current[fe]?.sessionId??$n.current.find(Ve=>Ve.id===fe)?.sessionId;Ba.current.add(fe);const Ee=(Ve,Ie)=>{K(Wt=>{const Ut=Wt.map(hn=>hn.id===fe?{...hn,modelId:Ve.id,sessionId:Ie}:hn);return Ms(Ut),Ut})},Ze=()=>{const Ve=Mc(ci.current[fe]?.modelId??null)??j;It(fe,Ie=>({...Ie,sessionId:void 0,model:Ve.flag||void 0,modelAsked:!1,commands:void 0,contextTokens:void 0,contextWindow:void 0}))};if(Ee(j),Ze(),Oa.current.has(fe))return;const Oe=(Ia.current.has(fe)?ae.invoke("chat_retarget",{key:pt(fe)}):Promise.resolve()).then(()=>{L(Ve=>{if(!Ve.has(fe))return Ve;const Ie=new Set(Ve);return Ie.delete(fe),Ie}),Ze()}).catch(Ve=>{throw Ba.current.delete(fe),oo(B),Ln(c0,B.id),sl(pi),Ln(u0,pi),Qs(Ji),Ln(sm,Ji),ci.current[fe]&&(ci.current[fe].modelId=B.id),Ee(B,Se),It(fe,Ie=>({...Ie,sessionId:Se,model:B.flag||Ie.model,notices:[...Ie.notices,`Could not switch models: ${String(Ve?.message??Ve)}`].slice(-8)})),Ve}).finally(()=>Oa.current.delete(fe));Oa.current.set(fe,Oe)},[rt.messages.length,Ji,pi,_t,O,It]),ep=_.useCallback(j=>{Qs(j),Ln(sm,j);const B=Cte(_t.agent,"effort",j);B&&Jf(B)||O&&Jn(O)},[O,Jn,_t.agent,Jf]),Au=_.useCallback((j,B)=>{const G=Mc(ci.current[j]?.modelId??null)?.agent??"claude";return uM(G,B)},[]),ac=_.useCallback((j,B)=>{Jn(j);const G=vg.current[j],ee=G?Au(j,G):"That access level";It(j,fe=>({...fe,notices:[...fe.notices,`${ee} needs a fresh agent: ${B}. The conversation is kept — say anything to carry on.`].slice(-8)}))},[Jn,It,Au]);xg.current=ac;const Lg=_.useCallback(()=>{const j=O;j&&(ae.invoke("chat_restart",{key:pt(j)}).catch(()=>Jn(j)),L(B=>{if(!B.has(j))return B;const G=new Set(B);return G.delete(j),G}),It(j,B=>({...B,notices:[...B.notices,"Agent stopped. The conversation is kept — say anything to start a fresh one, with whatever MCP servers and plugins it can see now."].slice(-8)})))},[O,Jn,It]),tp=Qpe({chats:N,running:M,known:$&&t==="open"}),br=!!O&&tp.has(O),Ua=_.useMemo(()=>gt||!O?[]:sL(Ht.snapshot,pt(O)),[Ht.snapshot,O,gt]),np=!gt&&rt.busy&&!br,ip=_.useCallback(j=>[...n,...u].find(B=>B.id===j)?.name,[n,u]),oc=_.useMemo(()=>Ua.some(j=>j.pending)?o.jsx(Doe,{plans:Ua,drafting:np,projectName:ip}):void 0,[Ua,np,ip]),Nu=_.useCallback(j=>{if(sl(j),Ln(u0,j),!O||(ci.current[O]&&(ci.current[O].access=j),!Ia.current.has(O)))return;vg.current[O]=j;const B=O;ae.invoke("chat_set_access",{key:pt(B),access:j}).catch(G=>{const ee=String(G.message??G);ee.includes("no such chat")||ac(B,ee)})},[O,ac]),td=async j=>{if(!bt)throw new Error("Choose a project before starting a run.");if(gt)throw new Error("Start runs from the main chat.");if(_t.agent==="pi")throw new Error("Choose Codex or Claude as the main agent.");const B=O??crypto.randomUUID(),G=Oa.current.get(B);if(G&&await G,Mn.current[B]?.busy)throw new Error("Wait for the main agent's turn to finish before starting a run.");const ee=$n.current.find(Ze=>Ze.id===B),fe=Date.now(),Se={...ee??{},id:B,projectId:bt.id,title:ee?.title??d0(j),cwd:ee?.cwd??Mn.current[B]?.cwd??bt.primary_path,sessionId:Ba.current.has(B)?void 0:Mn.current[B]?.sessionId??ee?.sessionId,messages:Mn.current[B]?.messages??ee?.messages??[],modelId:_t.id,permission:pi,createdAt:ee?.createdAt??fe,updatedAt:fe};await ae.invoke("chat_index_save",{meta:{...Se,messages:void 0,sessionId:Se.sessionId??null,access:pi,pinned:Se.pinned??!1,generation:Se.generation??0}}),ci.current[B]={projectId:bt.id,modelId:_t.id,access:pi};const Ee=[Se,...$n.current.filter(Ze=>Ze.id!==B)];return $n.current=Ee,K(Ee),Ms(Ee),ee||Ii.current.own(pt(B)),It(B,Ze=>({...Ze,cwd:Se.cwd})),be(Ze=>({...Ze,[B]:!0})),dt(Ze=>({...Ze,[B]:"run"})),ie(B),pt(B)},Eu=async j=>{const B=j.coordinatorChatKey.replace(/^chat:/,""),G=Oa.current.get(B);G&&await G;const ee=Ba.current.has(B),fe=ee?FT(Mn.current[B]?.messages??[])??"[]":void 0;await ae.invoke("orchestration_master_start",{actorChatKey:j.coordinatorChatKey,runId:j.id,agent:_t.agent,model:_t.flag||null,access:pi,effort:Ji,lite:lo,handoff:fe??null}),ee&&Ba.current.delete(B),L(Se=>new Set(Se).add(B))},So=(j,B)=>{const G=j.replace(/^chat:/,""),ee=$n.current.find(fe=>fe.id===G);if(!ee)throw new Error("This chat is not available yet. Wait for the chat list to sync and try again.");if(B){if(Hd(G,Rt))throw new Error("Send this decision in the main chat.");Ni({id:G,text:B})}dt(fe=>({...fe,[G]:"chat"})),vi(ee)},nd=_.useMemo(()=>vne({orchestration:Tt,parents:Rt,asks:Ra,safetyBlocks:Zi,questions:Da}),[Tt,Rt,Ra,Zi,Da]),[Va,id]=_.useState(null),[ha,Mu]=_.useState(null),lc=_.useCallback((j,B)=>{be(G=>({...G,[j]:!0})),dt(G=>({...G,[j]:"run"})),id({chatKey:pt(j),runId:B,nonce:Date.now()})},[]),Ka=_.useCallback(j=>{const B=$n.current.find(G=>G.id===j.openChatId);B&&(j.surface==="run"&&j.runId?lc(B.id,j.runId):dt(G=>({...G,[B.id]:"chat"})),vi(B),Mu({action:j,nonce:Date.now()}))},[vi,lc]);_.useEffect(()=>{if(!ha)return;const{action:j}=ha,B=Date.now();let G=!1,ee=requestAnimationFrame(function fe(){if(Cne(j.key)){Mu(null),id(null);return}if(!G&&j.kind==="plan"&&j.runId&&Date.now()-B>1200&&(G=!0,lc(j.openChatId,j.runId)),Date.now()-B>4e3){Mu(null),id(null);return}ee=requestAnimationFrame(fe)});return()=>cancelAnimationFrame(ee)},[ha,lc]);const Co=_.useMemo(()=>{const j=xne(nd),B=yne(nd);return{forRow:G=>j.get(G)??WT,forTask:G=>B.get(G)??WT,reveal:Ka}},[nd,Ka]),Lu=async()=>{const[j,B]=await Promise.all([Sx().catch(()=>al),tf(null,!0).catch(()=>es)]);if(js(j),lu(B),VM(B,j?.id).length===0){qf();return}Pr()},sp=_.useMemo(()=>R.filter(j=>!Hd(j.id,Rt)).map(({id:j,title:B,projectId:G,cwd:ee})=>({id:j,title:B,projectId:G,cwd:ee,busy:N[j]?.busy??M.has(j)})),[R,Rt,N,M]),rp=_.useCallback(j=>{const B=$n.current.find(G=>G.id===j);B&&vi(B)},[vi]);if(t==="unauthorized")return o.jsx(tse,{});const Ga=j=>{D(!1),P(j==="pulls"),H(j==="projects"?{projectId:null}:null),F(j==="search"),Zn(j==="settings"),ol(j==="agents")},Tu=Os?null:o.jsxs(o.Fragment,{children:[O&&o.jsx(yle,{count:qO(Pi.images).length,open:Pi.open,onClick:()=>Pi.setOpen(!Pi.open)}),qa&&o.jsx(bae,{project:qa,open:il&&!Ei,onToggle:()=>{Pi.setOpen(!1),_o(Ei||!il)}}),bt&&!de&&o.jsx(HT,{onClick:On})]}),Tg=o.jsxs(o.Fragment,{children:[!un&&o.jsxs("button",{className:"icon-btn new-chat",type:"button","aria-label":"Start new task",title:"Start new task",onClick:Pr,children:[o.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:o.jsx("path",{d:"M12 5v14M5 12h14"})}),o.jsx("span",{className:"topbar-action-label",children:"New task"})]}),!Os&&o.jsxs(o.Fragment,{children:[O&&o.jsx(KO,{action:!0,chatId:O,connected:t==="open",context:Wf,busy:rt.busy&&!br,waiting:(Da[O]?.length??0)+(Ra[O]?.length??0)+(Zi[O]?.length??0)>0}),o.jsx(Tte,{count:rt.agents.length,open:!ru&&!Ei,onToggle:()=>{Pi.setOpen(!1),wo(Ei||ru)}}),o.jsx(Ble,{count:$r.length,open:gr&&!Ei,onToggle:()=>{Pi.setOpen(!1),bo(Ei||!gr)}}),kt&&xt&&o.jsx(Fle,{expanded:ti,onToggle:Gf}),!un&&!gt&&o.jsx("button",{className:`orch-toggle${gn==="run"&&Bi?" is-on":""}`,type:"button",title:Cs.runs.length?"Open this chat's runs":"Start a supervised run","aria-label":Cs.runs.length?"Open this chat's runs":"Start a supervised run",onClick:()=>{be(j=>({...j,[Pt]:!0})),Vs("run")},children:o.jsx("span",{className:"topbar-action-label",children:"Run"})})]}),o.jsx(Hle,{}),!Os&&O&&o.jsx(Wle,{chatId:O}),!Os&&O&&!gt&&o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"topbar-actions-separator",role:"separator"}),o.jsx(ine,{deleting:pl.has(O),disabled:zi.has(O),deleteMs:A1,onDelete:()=>xi(O)})]})]}),ap=[O,...Ys].reduce((j,B)=>j+(B?(Ra[B]?.length??0)+(Zi[B]?.length??0)+(Da[B]?.length??0):0),0);return o.jsx(DB.Provider,{value:Ye,children:o.jsx(TC.Provider,{value:un?es:Sme,children:o.jsx(SB.Provider,{value:gu,children:o.jsx(LB.Provider,{value:Co,children:o.jsxs("div",{ref:En,className:`app ${Et?"projects-screen":""} ${cs?"nav-shut":""} ${ti?"chat-wide":""} ${Ft?"focus-mode":""}`,children:[Ft&&o.jsx(HT,{active:!0,onClick:_e}),o.jsx(Mne,{projects:n,shelved:u,deletedCount:v.length,onShowDeleted:()=>k(!0),conversations:Vh,chatParents:Rt,orchestration:Tt,ledgerSnapshot:Ht.snapshot,ledgerUnavailable:jg,coordinatorChatKeys:Hf,getPreviewMessages:j=>Ii.current.holds(pt(j))?N[j]?.messages:void 0,loadPreview:yg,currentConversation:O,running:M,busy:_u,deleting:pl,leaving:zi,deleteMs:A1,onPickConversation:j=>{vi(j)},onNewChat:un?()=>{Lu()}:Pr,newLabel:un?"New conversation":"New task",allowEmptyCreate:!un,onDelete:xi,onPin:Xf,onToggleDone:Cu,onRename:ju,onArchiveWorker:async(j,B)=>{const G=Tt.attempts.find(fe=>fe.id===j),ee=Tt.runs.find(fe=>fe.id===G?.runId);if(!ee)throw new Error("This worker's run is unavailable. Reconnect and try again.");await ae.invoke("orchestration_worker_archive",{actorChatKey:ee.coordinatorChatKey,attemptId:j,archived:B})},branches:s,onResize:xt?void 0:ot.startDrag,onCollapse:xt?void 0:()=>{yo(!1),requestAnimationFrame(()=>St.current?.focus())},onSearch:()=>Ga("search"),onSettings:()=>Ga("settings"),onAgents:un?()=>Ga("agents"):void 0,onProjects:()=>Ga("projects"),onPullRequests:()=>Ga("pulls"),activeView:W?"search":z?"projects":Rf&&un?"agents":Q?"pulls":Yt?"settings":null}),o.jsxs("div",{className:"shell-main",children:[o.jsxs("header",{className:"topbar",children:[o.jsxs("div",{className:"topbar-leading",children:[Et?o.jsxs("button",{className:"topbar-title topbar-brand",type:"button","aria-label":"Show Chats menu","aria-controls":"chats-navigation",title:"Show Chats menu",onClick:()=>{document.querySelector(".task-chat-scroll")?.scrollTo({top:0,behavior:"auto"}),requestAnimationFrame(()=>document.querySelector(".sidebar-new-chat")?.focus({preventScroll:!0}))},children:[o.jsx("img",{className:"topbar-logo",src:"./icon-192.png",alt:"","aria-hidden":"true"}),o.jsxs("span",{className:"topbar-identity",children:[o.jsx("span",{className:"topbar-name",children:"Chats"}),o.jsxs("span",{className:"topbar-version",children:["OctiqFlow v","0.2.12"]})]})]}):(xt||cs)&&o.jsxs("button",{ref:St,className:`topbar-nav${xt?"":" is-brand"}`,type:"button","aria-label":xt?"Show chats":"Show sidebar",title:xt?"Show chats":"Show sidebar · OctiqFlow v0.2.12","aria-expanded":!1,disabled:!xt&&ti,onClick:()=>{xt?(Ss(!1),D(!0)):(yo(!0),requestAnimationFrame(()=>document.querySelector(".sidebar-collapse")?.focus()))},children:[!xt&&o.jsx("img",{className:"topbar-nav-logo",src:"./icon-192.png",alt:"","aria-hidden":"true"}),o.jsxs("svg",{className:"topbar-nav-icon",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),o.jsx("path",{d:"M9 4v16M13 10l2 2-2 2"})]})]}),o.jsx("div",{className:"topbar-page",ref:J,hidden:!Os||Et}),!Et&&!Os&&o.jsxs("span",{className:"topbar-chat",title:bt?.primary_path,children:[bt&&o.jsx(Jc,{project:bt,size:"small",className:"topbar-project-avatar"}),o.jsx("span",{className:"topbar-name",children:bt?.name??(O?"Chat":un?al?.name??"CTO":"New chat")})]}),o.jsx("div",{className:"topbar-context",ref:Z,hidden:Os||Et}),o.jsx(nse,{state:t})]}),o.jsxs("div",{className:"topbar-actions",children:[!xt&&o.jsx("div",{className:"topbar-page-actions",ref:I,hidden:!Os}),Et?o.jsxs("button",{className:"projects-return",type:"button","aria-label":"Return to chat",title:"Return to chat",onClick:()=>D(!1),children:[o.jsx("span",{children:"Return to chat"}),o.jsx("svg",{className:"projects-return-icon",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"M5 12h14m-6-6 6 6-6 6"})})]}):o.jsx(Ule,{directActions:Tu,overflowActions:Tg}),!Et&&o.jsx(aae,{})]})]}),o.jsxs("div",{className:"body",id:"dock",children:[o.jsxs("main",{className:"main",hidden:Et,ref:ht,children:[Q&&o.jsx(pme,{projects:n,initialProjectId:a,chats:sp,agent:{provider:hi(_t.agent).name,model:_t.model,access:uM(_t.agent,pi)},connected:t==="open",onClose:()=>P(!1),onPrepareChat:_y,onOpenChat:rp}),z&&o.jsx(qne,{projects:n,shelved:u,conversations:R,selectedProjectId:z.projectId,busy:_u,chatParents:Rt,ledgerSnapshot:Ht.snapshot,coordinatorChatKeys:Hf,allowNewTask:!un,onSelectProject:j=>H({projectId:j}),onOpenChat:vi,onNewTask:j=>{Pr(),c(j)},onNewProject:()=>jt("new"),onProjectSettings:jt,onShowShelved:()=>m(!0),onRestoreProject:async j=>{await ae.invoke("set_workspace_shelved",{id:j,shelved:!1}),await Br()},onClose:()=>H(null)}),W&&o.jsx(Sse,{conversations:Vh,chatParents:Rt,projects:[...n,...u],ledgerSnapshot:Ht.snapshot,ledgerUnavailable:jg,coordinatorChatKeys:Hf,searchChats:Cg,onOpenChat:vi,onClose:()=>F(!1),deletedCount:v.length,onShowDeleted:()=>k(!0)}),Yt&&o.jsx(Lre,{current:Xs,onPick:su,notify:Hh,onNotify:(j,B)=>{Zl(j),bg(j&&B)},projects:[...n,...u],onProject:jt,agentsMode:un,onAgentsMode:Bh,onFeedback:()=>wn(!0),initialSection:Tf,onClose:()=>{Zn(!1),gg("projects")}}),Rf&&un&&o.jsx(Gre,{snapshot:Ht.snapshot,ledgerError:Ht.error,connected:t==="open",projects:[...n,...u],running:M,busy:_u,waitingOn:j=>{const B=j.replace(/^chat:/,"");return(Ra[B]?.length??0)+(Da[B]?.length??0)+(Zi[B]?.length??0)},chatTitle:j=>R.find(B=>pt(B.id)===j)?.title,chatExists:j=>R.some(B=>pt(B.id)===j),onOpenChat:j=>{So(j),ol(!1)},onOpenRun:(j,B)=>{So(j);const G=j.replace(/^chat:/,"");be(ee=>({...ee,[G]:!0})),dt(ee=>({...ee,[G]:"run"})),me(ee=>({...ee,[j]:B})),ol(!1)},onManage:qf,onClose:()=>ol(!1)}),o.jsx("div",{className:"chat-app-surface",hidden:Os,children:de?o.jsxs("div",{className:"hero",role:"status",children:[o.jsx("h1",{className:"hero-title",children:"Chat unavailable"}),o.jsx("p",{children:"This chat was deleted or is no longer in this profile. Choose another chat from the chat list."})]}):o.jsxs(o.Fragment,{children:[(!gt||Bi)&&o.jsx(ple,{snapshot:Cs,orchestrated:Bi,view:gn,focusMode:Ft,split:Rr,unified:Bi,selectedRun:cn,worker:gt,onBackToMain:gt&&(bi??Gs)&&!(Bi&&(Rr||gn==="run"))?()=>So(bi??Gs):void 0,onOpenBeside:gt&&O&&!Ft&&Yh(pt(O))?()=>Uf(pt(O)):void 0,besideTitle:oa?.title,readOnly:gt,planPending:!!Js,pendingApprovals:ap,onView:Vs}),o.jsxs("div",{className:`workflow-surfaces${Rr?" is-split":""}`,children:[Bi&&o.jsxs("div",{className:"workflow-run-surface",hidden:!Rr&&gn!=="run",style:{"--run-w":`${In.width}px`},children:[Rr&&o.jsx("div",{className:"workflow-run-resizer",role:"separator","aria-orientation":"vertical","aria-label":"Resize the run column",onPointerDown:In.startDrag}),o.jsx(Goe,{embedded:!0,sharedHeading:!0,project:bt,coordinatorKey:Gs,allowManualRun:!un,pendingApprovals:gt?0:ap,focusRun:Va&&Va.chatKey===Gs?Va:null,projectName:j=>[...n,...u].find(B=>B.id===j)?.name,onSelectedRunChange:ft,coordinatorBusy:!gt&&rt.busy&&!br,currentChatKey:O?pt(O):null,initialSnapshot:Tt,currentCwd:Or,onEnsureCoordinator:td,onStartMaster:Eu,onOpenChat:So,onClose:()=>Vs("chat"),onOpenBeside:Ft?void 0:Uf,besideChatKey:sn?pt(sn):null,setupContext:o.jsxs("div",{className:"workflow-setup-context",children:[o.jsxs("label",{children:["Project",o.jsxs("select",{"aria-label":"Run project",value:bt?.id??"",disabled:!!O,onChange:j=>xu(j.target.value||null),children:[o.jsx("option",{value:"",children:"Choose a project"}),n.map(j=>o.jsx("option",{value:j.id,children:j.name},j.id))]})]}),o.jsxs("label",{children:["Main agent",o.jsxs("select",{"aria-label":"Main agent",value:_t.id,onChange:j=>{const B=ya.find(G=>G.id===j.target.value);B&&vl(B)},children:[_t.agent==="pi"&&o.jsx("option",{value:_t.id,disabled:!0,children:"Choose Codex or Claude"}),ya.filter(j=>j.agent!=="pi"&&(!ra||ra.includes(j.agent))).map(j=>o.jsxs("option",{value:j.id,children:[j.name," · ",j.model]},j.id))]})]}),o.jsx("p",{children:"Keep talking in Chat. Worker providers are independent of the main agent."})]})})]}),o.jsxs("div",{className:"workflow-chat-surface",hidden:!Rr&&gn==="run",ref:Te,children:[sn&&Hn&&!pu&&o.jsx(ace,{showing:le,taskTitle:Hn.title,onShow:Re,onClose:Xh}),o.jsxs("div",{className:`beside-panes${Fa?" is-split":""}`,children:[o.jsxs("div",{className:"beside-pane is-main",hidden:!Kh,...sn?{role:"region","aria-label":"Main chat"}:{},children:[Fa&&o.jsx(rce,{persona:vo}),gt&&!Bi&&o.jsx("div",{className:"read-only-strip",children:o.jsx(qC,{})}),O&&Bf[O]&&rt.messages.length>0&&o.jsx("div",{className:"chat-sync-note",role:"status",children:"Updating conversation…"}),rt.messages.length===0&&O&&Bf[O]?o.jsxs("div",{className:"hero is-waiting",children:[o.jsx("div",{className:"dots","aria-label":"opening"}),o.jsxs("p",{className:"hero-sub",children:["opening “",Xl[O]?.title??R.find(j=>j.id===O)?.title??"the session","”…"]})]}):rt.messages.length===0&&gt?o.jsxs("div",{className:"hero",children:[o.jsx("h1",{className:"hero-title",children:"Agent conversation"}),o.jsx("p",{className:"hero-sub",children:"The agent's progress will appear here. Send instructions in the main chat."})]}):rt.messages.length===0&&mn.runs.length>0?o.jsxs("div",{className:"hero",children:[o.jsx("h2",{className:"hero-title",children:"Main chat"}),o.jsx("p",{className:"hero-sub",children:"Talk with the main agent here. Select a task to follow its conversation."})]}):rt.messages.length===0?o.jsxs("div",{className:`hero ${bt?"":"hero-start"}${Is?" is-agent-welcome":""}`,children:[o.jsx("h1",{className:"hero-title",children:Is&&mi?`Talk to ${mi.name}`:Is&&nc.length>0?"Choose who you talk to":Is?bt?`What's the task in ${bt.name}?`:"What's the task?":bt?`What do you want to do in ${bt.name}?`:"What should we work on?"}),Is&&mi&&o.jsx(_re,{name:mi.name,role:mi.role??"",scope:ul?"Works across every project":`Works ${mi.projectId?`only in ${bt?.name??"its project"}`:"in any project"}`,how:ul?"Picks the project, repository and teammate for each part, and you approve the plan before anyone starts.":"Does the work itself or hands parts to its team, and you approve any plan first."},mi.id),(!bt||Is)&&Tn&&o.jsx("p",{className:"hero-route-error",role:"alert",children:Tn}),Is&&o.jsx(Sre,{agents:nc,selectedId:mi?.id??null,projectName:j=>n.find(B=>B.id===j)?.name,onPick:xr,onManage:qf}),rt.sessionId&&(O&&Xl[O]?o.jsxs("p",{className:"hero-sub",children:["continuing “",Xl[O].title,"” ·"," ",hi(Xl[O].agent).name,Xl[O].problem&&o.jsxs("span",{className:"hero-warn",children:[" ","· could not read it back (",Xl[O].problem,"). Typing still carries on the session."]})]}):o.jsx("p",{className:"hero-sub",children:"continuing an earlier session"})),bt&&!gt&&o.jsx(fse,{projectPath:Or,onResume:yr})]}):o.jsx("div",{className:"chat-body",children:o.jsx(J6,{value:Or,children:o.jsx(U4,{value:Vf,children:o.jsxs("div",{className:"chat-main",children:[o.jsx(hB,{messages:rt.messages,tail:oc,hasEarlier:!!O&&sa.current.hasEarlier(O),loadingEarlier:!!O&&!!hu[O]?.loading,earlierError:O?hu[O]?.error:void 0,onLoadEarlier:du,busy:rt.busy&&!br,stoppedAt:rt.stoppedAt,compactingSince:rt.compactingSince,conversationId:O??void 0,hostName:lN(vo,hi(_t.agent).name),hostPersona:vo,onCancelQueued:!gt&&t==="open"?Mg:void 0,onStartQueued:!gt&&t==="open"?gl:void 0,onRestoreUnsent:gt?void 0:Zf,onDismissUnsent:gt?void 0:ed,onSetting:gt?void 0:Wr,agentByTool:Ag,onOpenAgent:An}),ca&&o.jsx(bte,{run:ca,messages:rt.messages,onBack:()=>An(null)})]})})})}),(gi||$i)&&O&&o.jsxs("div",{className:`failure ${gi?.outOfCredit||$i?"is-quota":""}`,role:"alert",children:[gi&&!$i&&o.jsx("button",{className:"failure-close",type:"button","aria-label":"Dismiss",onClick:()=>{vz(O,gi),It(O,j=>({...j,failure:void 0}))},children:"×"}),o.jsx("div",{className:"failure-title",children:gi?.title??"Auto-resume scheduled"}),gi?.detail&&o.jsx("div",{className:"failure-detail",children:gi.detail}),$i&&o.jsxs("div",{className:"auto-resume-row",children:[o.jsxs("span",{children:["OctiqFlow will resume this ",$i.agent==="claude"?"Claude":$i.agent==="codex"?"Codex":"Pi"," session around"," ",new Date($i.runAt*1e3).toLocaleString([],{dateStyle:"medium",timeStyle:"short"}),"."]}),!gt&&o.jsx("button",{className:"auto-resume-cancel",type:"button",onClick:()=>{ae.invoke("chat_cancel_auto_resume",{key:pt(O)}).catch(j=>{It(O,B=>({...B,notices:[...B.notices,`Could not cancel auto-resume: ${String(j.message??j)}`]}))})},children:"Cancel auto-resume"})]}),gi?.link&&o.jsx("a",{className:"failure-link",href:gi.link,target:"_blank",rel:"noreferrer noopener",children:gi.link})]}),O&&fl.length>0&&o.jsx(Qne,{notices:fl,onClear:()=>It(O,j=>({...j,notices:[]}))}),O&&!gt&&o.jsx($T,{asks:Ra[O]??[],safetyBlocks:Zi[O]??[],questions:Da[O]??[],onPermissionAnswered:j=>au(B=>({...B,[O]:(B[O]??[]).filter(G=>G.id!==j)})),onSafetyAnswered:j=>Rh(B=>({...B,[O]:(B[O]??[]).filter(G=>G.id!==j)})),onQuestionsAnswered:j=>Yl(B=>({...B,[O]:(B[O]??[]).filter(G=>!j.includes(G.id))})),onContinue:Wr}),O&&We.snapshot?.environments[pt(O)]?.enabled&&o.jsx(z$,{environment:We.snapshot.environments[pt(O)],running:rt.busy,onRefresh:We.refresh},O),Qe&&qa&&o.jsx(bpe,{project:qa,onCommandsChanged:Br,onHide:()=>{Oi(!1),Ln(E1,"0")}},qa.id),Ys.map(j=>(Ra[j]?.length??0)+(Zi[j]?.length??0)>0&&o.jsxs("section",{"aria-label":"Agent safety approvals",children:[o.jsxs("p",{className:"worker-approval-context",children:["Approval for ",R.find(B=>B.id===j)?.title??"agent",". Follow-up instructions go through this main chat."]}),o.jsx($T,{asks:Ra[j]??[],safetyBlocks:Zi[j]??[],questions:[],onPermissionAnswered:B=>au(G=>({...G,[j]:(G[j]??[]).filter(ee=>ee.id!==B)})),onSafetyAnswered:B=>Rh(G=>({...G,[j]:(G[j]??[]).filter(ee=>ee.id!==B)})),onQuestionsAnswered:()=>{},onContinue:B=>Wr(`For your worker chat ${j}:
323
+ `)}`.trim());const Oe=O??crypto.randomUUID(),Ve=j;if(G){try{j=await sre(pt(Oe),Se.id,G.id,j,fe)}catch($t){qt(`Could not hand the task to ${G.name}: ${String($t.message??$t)}`);return}const $e={chatKey:pt(Oe),leadId:G.id,leadName:G.name,projectId:Se.id,crossProject:fe||void 0,createdAt:Date.now()};dg($t=>[...$t.filter(Hi=>Hi.chatKey!==$e.chatKey),$e])}if(O||ie(Oe),j.trim()==="/clear"){const $e=pt(Oe);Ia.current.has(Oe)&&ae.invoke("chat_send",{key:$e,text:j,recordUser:!1}).catch(()=>{}),ae.invoke("chat_forget",{key:$e}).catch(()=>{}),As.current.delete(Oe),sa.current.forget(Oe),zh.current.delete(Oe),G5(Oe),Ii.current.own($e),It(Oe,$t=>({...Uc(),sessionId:$t.sessionId})),K($t=>{const Hi=$t.map(er=>er.id===Oe?{...er,messages:[],seq:0,updatedAt:Date.now()}:er);return Ms(Hi),Hi});return}const Ie=Oa.current.get(Oe);if(Ie)try{await Ie}catch{return}const Wt=Ba.current.has(Oe),Ut=Wt?FT(Mn.current[Oe]?.messages??[]):void 0;ci.current[Oe]={projectId:Se.id,modelId:_t.id,access:pi};const hn=j1(),Fi=_oe(sL(ii.current,pt(Oe)));It(Oe,$e=>q_($e,j,B.map($t=>({path:$t.path,name:$t.name,isImage:!!$t.isImage})),void 0,hn)),Ir.current.add(hn);const et=$e=>It(Oe,$t=>({...$t,busy:Ia.current.has(Oe)?$t.busy:!1,messages:$t.messages.map(Hi=>Hi.turnId===hn&&!Hi.echo&&!Hi.takenUp?{...Hi,delivery:"unknown",queueError:String($e.message??$e)}:Hi)}));try{const $e=$n.current.find(Sn=>Sn.id===Oe),$t=$e?.cwd??Mn.current[Oe]?.cwd;let Hi=$t??Se.primary_path??"",er;const da=!$t&&!!bt&&bt.id===Se.id&&(ee?ee.prepare&&ee.target==="project":Ol(bt.name)!=="general"),Ru=ee?ee.branch:At,cc=ee?ee.newWorktree:at,uc=ee?ee.useSandbox:pn??We.snapshot?.defaultEnabled??!1,by=$e?void 0:{projectId:Se.id,projectName:Se.name,path:Se.primary_path??"",baseBranch:da?Ru||(bt?.id===Se.id?ke.current:""):"",newWorktree:da&&cc,useSandbox:uc,prepare:da,chosenBy:ee?ee.chosenBy:"person",reason:ee?.reason??"",decidedAt:Date.now()};if(da&&bt)try{const Sn=await ae.invoke("git_prepare_chat_workspace",{path:bt.primary_path??"",branch:Ru,newWorktree:cc,prompt:Ve,chatId:Oe});Hi=Sn.cwd,nn(Sn.branch),Je(tr=>({isRepo:Sn.is_repo,current:Sn.branch,branches:Sn.branch&&!tr.branches.includes(Sn.branch)?[Sn.branch,...tr.branches]:tr.branches,isWorktree:Sn.is_worktree})),It(Oe,tr=>({...tr,cwd:Hi}))}catch(Sn){er=Sn}const si=Date.now(),ns=oA($e,{...$e??{},id:Oe,projectId:Se.id,title:$e?.title??d0(Ve),latestResponse:$e?.latestResponse,customTitle:$e?.customTitle,sessionId:Mn.current[Oe]?.sessionId??$e?.sessionId,cwd:er?$e?.cwd:Hi,messages:Mn.current[Oe]?.messages??$e?.messages??[],modelId:_t.id,permission:pi,createdAt:$e?.createdAt??si,updatedAt:si,pinned:$e?.pinned??!1,generation:$e?.generation,launch:$e?.launch??by});if(K(Sn=>{const tr=[ns,...Sn.filter(rd=>rd.id!==Oe)];return Ms(tr),tr}),Dp({id:ns.id,projectId:ns.projectId,title:ns.title,latestResponse:ns.latestResponse,customTitle:ns.customTitle,sessionId:ns.sessionId??null,cwd:ns.cwd??null,modelId:ns.modelId??null,access:ns.permission??null,createdAt:ns.createdAt,updatedAt:ns.updatedAt,pinned:ns.pinned??!1,generation:ns.generation,launch:ns.launch}),er){et(er);return}if(!Wt&&Ia.current.has(Oe))try{await ae.invoke("chat_send",{key:pt(Oe),text:j,images:Ee,turnId:hn,seenPlans:Fi});return}catch(Sn){if(!String(Sn.message??Sn).includes("no such chat")){et(Sn);return}}const sd=Wt?null:Mn.current[Oe]?.sessionId??$n.current.find(Sn=>Sn.id===Oe)?.sessionId??null;Ii.current.holds(pt(Oe))||(sd?await aa(Oe,$n.current.find(Sn=>Sn.id===Oe)?.seq).catch(()=>{}):Ii.current.own(pt(Oe))),L(Sn=>new Set(Sn).add(Oe));try{await ae.invoke("chat_start",{key:pt(Oe),cwd:Hi,useSandbox:$e?!1:ee?ee.useSandbox:pn??We.snapshot?.defaultEnabled??null,extraDirs:Se.paths??[],env:Se.env??{},agent:_t.agent,model:_t.flag||null,access:pi,effort:Ji,lite:lo,images:Ee,prompt:j,handoff:Ut??null,turnId:hn,seenPlans:Fi,resume:sd}),Wt&&Ba.current.delete(Oe)}catch(Sn){if(!Wt&&String(Sn.message??Sn).includes("already running"))try{await ae.invoke("chat_send",{key:pt(Oe),text:j,images:Ee,turnId:hn,seenPlans:Fi});return}catch(tr){et(tr)}else et(Sn);L(tr=>{const rd=new Set(tr);return rd.delete(Oe),rd})}}finally{Ir.current.delete(hn),la(Oe).catch(()=>{})}},[bt,Of,At,at,pn,We.snapshot?.defaultEnabled,_t,pi,Ji,lo,O,It,aa,la,un,mi,nc,rl,n,gt,Rn,ke]),_y=_.useCallback(async j=>{const B=n.find(Ve=>Ve.id===j.projectId);if(!B)throw new Error("The selected project is no longer available.");if(!j.cwd)throw new Error("The selected repository has no working directory.");const G=crypto.randomUUID(),ee=Date.now(),fe=j.access??pi,Se={...Uc(),cwd:j.cwd},Ee={id:G,projectId:B.id,title:j.title,customTitle:!0,cwd:j.cwd,messages:[],modelId:_t.id,permission:fe,createdAt:ee,updatedAt:ee};await ae.invoke("chat_index_save",{meta:{...Ee,messages:void 0,sessionId:null,access:fe,pinned:!1,generation:0}}),ci.current[G]={projectId:B.id,modelId:_t.id,access:fe},Ii.current.own(pt(G)),It(G,()=>Se);const Ze=[Ee,...$n.current.filter(Ve=>Ve.id!==G)];$n.current=Ze,K(Ze),Ms(Ze);let Oe=!1;return{chatId:G,start:async()=>{if(Oe)throw new Error("This PR agent chat has already been started.");Oe=!0;const Ve=j1(),Ie=Date.now(),Wt=q_(Mn.current[G]??Se,j.prompt,[],Ie,Ve);It(G,()=>Wt);const Ut=$n.current.map(hn=>hn.id===G?{...hn,messages:Wt.messages,updatedAt:Ie}:hn);$n.current=Ut,K(Ut),Ms(Ut),Ir.current.add(Ve),L(hn=>new Set(hn).add(G));try{await ae.invoke("chat_start",{key:pt(G),cwd:j.cwd,extraDirs:B.paths??[],env:B.env??{},agent:_t.agent,model:_t.flag||null,access:fe,effort:Ji,lite:lo,images:[],prompt:j.prompt,handoff:null,turnId:Ve,resume:null})}catch(hn){const Fi=String(hn?.message??hn);throw It(G,et=>({...et,busy:!1,messages:et.messages.map($e=>$e.turnId===Ve?{...$e,delivery:"unknown",queueError:Fi}:$e),notices:[...et.notices,`Could not start this PR agent: ${Fi}`].slice(-8)})),L(et=>{const $e=new Set(et);return $e.delete(G),$e}),hn}finally{Ir.current.delete(Ve)}}}},[n,_t,pi,Ji,lo,It]);_.useEffect(()=>{!Ks||Ks.id!==O||gt||(Ni(null),Wr(Ks.text))},[Ks,O,gt,Wr]);const Eg=_.useCallback(()=>{!O||!Ia.current.has(O)||(It(O,j=>({...j,stopping:!0})),ae.invoke("chat_interrupt",{key:pt(O)}).catch(()=>{}))},[O,It]),Jh=_.useCallback((j,B)=>{if(!O||t!=="open")return;const G=O;yu.current.run({chatId:G,turnId:j,action:B,read:()=>Mn.current[G]??im,patch:ee=>It(G,ee),invoke:ee=>ae.invoke(ee,{key:pt(G),turnId:j}),refresh:async()=>{await aa(G),await la(G)},reclaim:ee=>qh(G,j,ee)})},[O,t,It,aa,la,qh]),Mg=_.useCallback(j=>Jh(j,"cancel"),[Jh]),gl=_.useCallback(j=>Jh(j,"start"),[Jh]),Zf=_.useCallback(j=>{if(!O)return;const B=Mn.current[O];if(!B?.messages.some(ee=>ee.turnId===j&&(ee.queueLost||ee.delivery==="unknown")&&!ee.echo&&!ee.takenUp))return;const G=B.messages.find(ee=>ee.turnId===j);G&&Pf(ee=>({...ee,[O]:[...ee[O]??[],zT(G)]}))},[O]),ed=_.useCallback(j=>{if(!O)return;const B=O;Mn.current[B]?.messages.some(ee=>ee.turnId===j&&ee.queueLost&&!ee.echo&&!ee.takenUp)&&ae.invoke("chat_dismiss_unsent",{key:pt(B),turnId:j}).then(ee=>{ee!==!1&&It(B,fe=>({...fe,messages:fe.messages.filter(Se=>Se.turnId!==j)}))}).catch(ee=>It(B,fe=>({...fe,notices:[...fe.notices,String(ee.message??ee)]})))},[O,It]),Jf=_.useCallback(j=>{if(!O||!Ia.current.has(O))return!1;const B=j1();return It(O,G=>q_(G,j,[],void 0,B)),ae.invoke("chat_send",{key:pt(O),text:j,turnId:B}).catch(()=>{}),!0},[O,It]),vl=_.useCallback(j=>{const B=_t;if(j.id===B.id)return;const G=Ku(j.agent,pi);oo(j),Ln(c0,j.id),G!==pi&&(sl(G),Ln(u0,G));const ee=Zw(j.agent,Ji);if(ee!==Ji&&(Qs(ee),Ln(sm,ee)),O&&ci.current[O]&&(ci.current[O].modelId=j.id),!O||rt.messages.length===0)return;const fe=O,Se=Mn.current[fe]?.sessionId??$n.current.find(Ve=>Ve.id===fe)?.sessionId;Ba.current.add(fe);const Ee=(Ve,Ie)=>{K(Wt=>{const Ut=Wt.map(hn=>hn.id===fe?{...hn,modelId:Ve.id,sessionId:Ie}:hn);return Ms(Ut),Ut})},Ze=()=>{const Ve=Mc(ci.current[fe]?.modelId??null)??j;It(fe,Ie=>({...Ie,sessionId:void 0,model:Ve.flag||void 0,modelAsked:!1,commands:void 0,contextTokens:void 0,contextWindow:void 0}))};if(Ee(j),Ze(),Oa.current.has(fe))return;const Oe=(Ia.current.has(fe)?ae.invoke("chat_retarget",{key:pt(fe)}):Promise.resolve()).then(()=>{L(Ve=>{if(!Ve.has(fe))return Ve;const Ie=new Set(Ve);return Ie.delete(fe),Ie}),Ze()}).catch(Ve=>{throw Ba.current.delete(fe),oo(B),Ln(c0,B.id),sl(pi),Ln(u0,pi),Qs(Ji),Ln(sm,Ji),ci.current[fe]&&(ci.current[fe].modelId=B.id),Ee(B,Se),It(fe,Ie=>({...Ie,sessionId:Se,model:B.flag||Ie.model,notices:[...Ie.notices,`Could not switch models: ${String(Ve?.message??Ve)}`].slice(-8)})),Ve}).finally(()=>Oa.current.delete(fe));Oa.current.set(fe,Oe)},[rt.messages.length,Ji,pi,_t,O,It]),ep=_.useCallback(j=>{Qs(j),Ln(sm,j);const B=Cte(_t.agent,"effort",j);B&&Jf(B)||O&&Jn(O)},[O,Jn,_t.agent,Jf]),Au=_.useCallback((j,B)=>{const G=Mc(ci.current[j]?.modelId??null)?.agent??"claude";return uM(G,B)},[]),ac=_.useCallback((j,B)=>{Jn(j);const G=vg.current[j],ee=G?Au(j,G):"That access level";It(j,fe=>({...fe,notices:[...fe.notices,`${ee} needs a fresh agent: ${B}. The conversation is kept — say anything to carry on.`].slice(-8)}))},[Jn,It,Au]);xg.current=ac;const Lg=_.useCallback(()=>{const j=O;j&&(ae.invoke("chat_restart",{key:pt(j)}).catch(()=>Jn(j)),L(B=>{if(!B.has(j))return B;const G=new Set(B);return G.delete(j),G}),It(j,B=>({...B,notices:[...B.notices,"Agent stopped. The conversation is kept — say anything to start a fresh one, with whatever MCP servers and plugins it can see now."].slice(-8)})))},[O,Jn,It]),tp=Qpe({chats:N,running:M,known:$&&t==="open"}),br=!!O&&tp.has(O),Ua=_.useMemo(()=>gt||!O?[]:sL(Ht.snapshot,pt(O)),[Ht.snapshot,O,gt]),np=!gt&&rt.busy&&!br,ip=_.useCallback(j=>[...n,...u].find(B=>B.id===j)?.name,[n,u]),oc=_.useMemo(()=>Ua.some(j=>j.pending)?o.jsx(Doe,{plans:Ua,drafting:np,projectName:ip}):void 0,[Ua,np,ip]),Nu=_.useCallback(j=>{if(sl(j),Ln(u0,j),!O||(ci.current[O]&&(ci.current[O].access=j),!Ia.current.has(O)))return;vg.current[O]=j;const B=O;ae.invoke("chat_set_access",{key:pt(B),access:j}).catch(G=>{const ee=String(G.message??G);ee.includes("no such chat")||ac(B,ee)})},[O,ac]),td=async j=>{if(!bt)throw new Error("Choose a project before starting a run.");if(gt)throw new Error("Start runs from the main chat.");if(_t.agent==="pi")throw new Error("Choose Codex or Claude as the main agent.");const B=O??crypto.randomUUID(),G=Oa.current.get(B);if(G&&await G,Mn.current[B]?.busy)throw new Error("Wait for the main agent's turn to finish before starting a run.");const ee=$n.current.find(Ze=>Ze.id===B),fe=Date.now(),Se={...ee??{},id:B,projectId:bt.id,title:ee?.title??d0(j),cwd:ee?.cwd??Mn.current[B]?.cwd??bt.primary_path,sessionId:Ba.current.has(B)?void 0:Mn.current[B]?.sessionId??ee?.sessionId,messages:Mn.current[B]?.messages??ee?.messages??[],modelId:_t.id,permission:pi,createdAt:ee?.createdAt??fe,updatedAt:fe};await ae.invoke("chat_index_save",{meta:{...Se,messages:void 0,sessionId:Se.sessionId??null,access:pi,pinned:Se.pinned??!1,generation:Se.generation??0}}),ci.current[B]={projectId:bt.id,modelId:_t.id,access:pi};const Ee=[Se,...$n.current.filter(Ze=>Ze.id!==B)];return $n.current=Ee,K(Ee),Ms(Ee),ee||Ii.current.own(pt(B)),It(B,Ze=>({...Ze,cwd:Se.cwd})),be(Ze=>({...Ze,[B]:!0})),dt(Ze=>({...Ze,[B]:"run"})),ie(B),pt(B)},Eu=async j=>{const B=j.coordinatorChatKey.replace(/^chat:/,""),G=Oa.current.get(B);G&&await G;const ee=Ba.current.has(B),fe=ee?FT(Mn.current[B]?.messages??[])??"[]":void 0;await ae.invoke("orchestration_master_start",{actorChatKey:j.coordinatorChatKey,runId:j.id,agent:_t.agent,model:_t.flag||null,access:pi,effort:Ji,lite:lo,handoff:fe??null}),ee&&Ba.current.delete(B),L(Se=>new Set(Se).add(B))},So=(j,B)=>{const G=j.replace(/^chat:/,""),ee=$n.current.find(fe=>fe.id===G);if(!ee)throw new Error("This chat is not available yet. Wait for the chat list to sync and try again.");if(B){if(Hd(G,Rt))throw new Error("Send this decision in the main chat.");Ni({id:G,text:B})}dt(fe=>({...fe,[G]:"chat"})),vi(ee)},nd=_.useMemo(()=>vne({orchestration:Tt,parents:Rt,asks:Ra,safetyBlocks:Zi,questions:Da}),[Tt,Rt,Ra,Zi,Da]),[Va,id]=_.useState(null),[ha,Mu]=_.useState(null),lc=_.useCallback((j,B)=>{be(G=>({...G,[j]:!0})),dt(G=>({...G,[j]:"run"})),id({chatKey:pt(j),runId:B,nonce:Date.now()})},[]),Ka=_.useCallback(j=>{const B=$n.current.find(G=>G.id===j.openChatId);B&&(j.surface==="run"&&j.runId?lc(B.id,j.runId):dt(G=>({...G,[B.id]:"chat"})),vi(B),Mu({action:j,nonce:Date.now()}))},[vi,lc]);_.useEffect(()=>{if(!ha)return;const{action:j}=ha,B=Date.now();let G=!1,ee=requestAnimationFrame(function fe(){if(Cne(j.key)){Mu(null),id(null);return}if(!G&&j.kind==="plan"&&j.runId&&Date.now()-B>1200&&(G=!0,lc(j.openChatId,j.runId)),Date.now()-B>4e3){Mu(null),id(null);return}ee=requestAnimationFrame(fe)});return()=>cancelAnimationFrame(ee)},[ha,lc]);const Co=_.useMemo(()=>{const j=xne(nd),B=yne(nd);return{forRow:G=>j.get(G)??WT,forTask:G=>B.get(G)??WT,reveal:Ka}},[nd,Ka]),Lu=async()=>{const[j,B]=await Promise.all([Sx().catch(()=>al),tf(null,!0).catch(()=>es)]);if(js(j),lu(B),VM(B,j?.id).length===0){qf();return}Pr()},sp=_.useMemo(()=>R.filter(j=>!Hd(j.id,Rt)).map(({id:j,title:B,projectId:G,cwd:ee})=>({id:j,title:B,projectId:G,cwd:ee,busy:N[j]?.busy??M.has(j)})),[R,Rt,N,M]),rp=_.useCallback(j=>{const B=$n.current.find(G=>G.id===j);B&&vi(B)},[vi]);if(t==="unauthorized")return o.jsx(tse,{});const Ga=j=>{D(!1),P(j==="pulls"),H(j==="projects"?{projectId:null}:null),F(j==="search"),Zn(j==="settings"),ol(j==="agents")},Tu=Os?null:o.jsxs(o.Fragment,{children:[O&&o.jsx(yle,{count:qO(Pi.images).length,open:Pi.open,onClick:()=>Pi.setOpen(!Pi.open)}),qa&&o.jsx(bae,{project:qa,open:il&&!Ei,onToggle:()=>{Pi.setOpen(!1),_o(Ei||!il)}}),bt&&!de&&o.jsx(HT,{onClick:On})]}),Tg=o.jsxs(o.Fragment,{children:[!un&&o.jsxs("button",{className:"icon-btn new-chat",type:"button","aria-label":"Start new task",title:"Start new task",onClick:Pr,children:[o.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:o.jsx("path",{d:"M12 5v14M5 12h14"})}),o.jsx("span",{className:"topbar-action-label",children:"New task"})]}),!Os&&o.jsxs(o.Fragment,{children:[O&&o.jsx(KO,{action:!0,chatId:O,connected:t==="open",context:Wf,busy:rt.busy&&!br,waiting:(Da[O]?.length??0)+(Ra[O]?.length??0)+(Zi[O]?.length??0)>0}),o.jsx(Tte,{count:rt.agents.length,open:!ru&&!Ei,onToggle:()=>{Pi.setOpen(!1),wo(Ei||ru)}}),o.jsx(Ble,{count:$r.length,open:gr&&!Ei,onToggle:()=>{Pi.setOpen(!1),bo(Ei||!gr)}}),kt&&xt&&o.jsx(Fle,{expanded:ti,onToggle:Gf}),!un&&!gt&&o.jsx("button",{className:`orch-toggle${gn==="run"&&Bi?" is-on":""}`,type:"button",title:Cs.runs.length?"Open this chat's runs":"Start a supervised run","aria-label":Cs.runs.length?"Open this chat's runs":"Start a supervised run",onClick:()=>{be(j=>({...j,[Pt]:!0})),Vs("run")},children:o.jsx("span",{className:"topbar-action-label",children:"Run"})})]}),o.jsx(Hle,{}),!Os&&O&&o.jsx(Wle,{chatId:O}),!Os&&O&&!gt&&o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"topbar-actions-separator",role:"separator"}),o.jsx(ine,{deleting:pl.has(O),disabled:zi.has(O),deleteMs:A1,onDelete:()=>xi(O)})]})]}),ap=[O,...Ys].reduce((j,B)=>j+(B?(Ra[B]?.length??0)+(Zi[B]?.length??0)+(Da[B]?.length??0):0),0);return o.jsx(DB.Provider,{value:Ye,children:o.jsx(TC.Provider,{value:un?es:Sme,children:o.jsx(SB.Provider,{value:gu,children:o.jsx(LB.Provider,{value:Co,children:o.jsxs("div",{ref:En,className:`app ${Et?"projects-screen":""} ${cs?"nav-shut":""} ${ti?"chat-wide":""} ${Ft?"focus-mode":""}`,children:[Ft&&o.jsx(HT,{active:!0,onClick:_e}),o.jsx(Mne,{projects:n,shelved:u,deletedCount:v.length,onShowDeleted:()=>k(!0),conversations:Vh,chatParents:Rt,orchestration:Tt,ledgerSnapshot:Ht.snapshot,ledgerUnavailable:jg,coordinatorChatKeys:Hf,getPreviewMessages:j=>Ii.current.holds(pt(j))?N[j]?.messages:void 0,loadPreview:yg,currentConversation:O,running:M,busy:_u,deleting:pl,leaving:zi,deleteMs:A1,onPickConversation:j=>{vi(j)},onNewChat:un?()=>{Lu()}:Pr,newLabel:un?"New conversation":"New task",allowEmptyCreate:!un,onDelete:xi,onPin:Xf,onToggleDone:Cu,onRename:ju,onArchiveWorker:async(j,B)=>{const G=Tt.attempts.find(fe=>fe.id===j),ee=Tt.runs.find(fe=>fe.id===G?.runId);if(!ee)throw new Error("This worker's run is unavailable. Reconnect and try again.");await ae.invoke("orchestration_worker_archive",{actorChatKey:ee.coordinatorChatKey,attemptId:j,archived:B})},branches:s,onResize:xt?void 0:ot.startDrag,onCollapse:xt?void 0:()=>{yo(!1),requestAnimationFrame(()=>St.current?.focus())},onSearch:()=>Ga("search"),onSettings:()=>Ga("settings"),onAgents:un?()=>Ga("agents"):void 0,onProjects:()=>Ga("projects"),onPullRequests:()=>Ga("pulls"),activeView:W?"search":z?"projects":Rf&&un?"agents":Q?"pulls":Yt?"settings":null}),o.jsxs("div",{className:"shell-main",children:[o.jsxs("header",{className:"topbar",children:[o.jsxs("div",{className:"topbar-leading",children:[Et?o.jsxs("button",{className:"topbar-title topbar-brand",type:"button","aria-label":"Show Chats menu","aria-controls":"chats-navigation",title:"Show Chats menu",onClick:()=>{document.querySelector(".task-chat-scroll")?.scrollTo({top:0,behavior:"auto"}),requestAnimationFrame(()=>document.querySelector(".sidebar-new-chat")?.focus({preventScroll:!0}))},children:[o.jsx("img",{className:"topbar-logo",src:"./icon-192.png",alt:"","aria-hidden":"true"}),o.jsxs("span",{className:"topbar-identity",children:[o.jsx("span",{className:"topbar-name",children:"Chats"}),o.jsxs("span",{className:"topbar-version",children:["OctiqFlow v","0.2.13"]})]})]}):(xt||cs)&&o.jsxs("button",{ref:St,className:`topbar-nav${xt?"":" is-brand"}`,type:"button","aria-label":xt?"Show chats":"Show sidebar",title:xt?"Show chats":"Show sidebar · OctiqFlow v0.2.13","aria-expanded":!1,disabled:!xt&&ti,onClick:()=>{xt?(Ss(!1),D(!0)):(yo(!0),requestAnimationFrame(()=>document.querySelector(".sidebar-collapse")?.focus()))},children:[!xt&&o.jsx("img",{className:"topbar-nav-logo",src:"./icon-192.png",alt:"","aria-hidden":"true"}),o.jsxs("svg",{className:"topbar-nav-icon",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[o.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),o.jsx("path",{d:"M9 4v16M13 10l2 2-2 2"})]})]}),o.jsx("div",{className:"topbar-page",ref:J,hidden:!Os||Et}),!Et&&!Os&&o.jsxs("span",{className:"topbar-chat",title:bt?.primary_path,children:[bt&&o.jsx(Jc,{project:bt,size:"small",className:"topbar-project-avatar"}),o.jsx("span",{className:"topbar-name",children:bt?.name??(O?"Chat":un?al?.name??"CTO":"New chat")})]}),o.jsx("div",{className:"topbar-context",ref:Z,hidden:Os||Et}),o.jsx(nse,{state:t})]}),o.jsxs("div",{className:"topbar-actions",children:[!xt&&o.jsx("div",{className:"topbar-page-actions",ref:I,hidden:!Os}),Et?o.jsxs("button",{className:"projects-return",type:"button","aria-label":"Return to chat",title:"Return to chat",onClick:()=>D(!1),children:[o.jsx("span",{children:"Return to chat"}),o.jsx("svg",{className:"projects-return-icon",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"M5 12h14m-6-6 6 6-6 6"})})]}):o.jsx(Ule,{directActions:Tu,overflowActions:Tg}),!Et&&o.jsx(aae,{})]})]}),o.jsxs("div",{className:"body",id:"dock",children:[o.jsxs("main",{className:"main",hidden:Et,ref:ht,children:[Q&&o.jsx(pme,{projects:n,initialProjectId:a,chats:sp,agent:{provider:hi(_t.agent).name,model:_t.model,access:uM(_t.agent,pi)},connected:t==="open",onClose:()=>P(!1),onPrepareChat:_y,onOpenChat:rp}),z&&o.jsx(qne,{projects:n,shelved:u,conversations:R,selectedProjectId:z.projectId,busy:_u,chatParents:Rt,ledgerSnapshot:Ht.snapshot,coordinatorChatKeys:Hf,allowNewTask:!un,onSelectProject:j=>H({projectId:j}),onOpenChat:vi,onNewTask:j=>{Pr(),c(j)},onNewProject:()=>jt("new"),onProjectSettings:jt,onShowShelved:()=>m(!0),onRestoreProject:async j=>{await ae.invoke("set_workspace_shelved",{id:j,shelved:!1}),await Br()},onClose:()=>H(null)}),W&&o.jsx(Sse,{conversations:Vh,chatParents:Rt,projects:[...n,...u],ledgerSnapshot:Ht.snapshot,ledgerUnavailable:jg,coordinatorChatKeys:Hf,searchChats:Cg,onOpenChat:vi,onClose:()=>F(!1),deletedCount:v.length,onShowDeleted:()=>k(!0)}),Yt&&o.jsx(Lre,{current:Xs,onPick:su,notify:Hh,onNotify:(j,B)=>{Zl(j),bg(j&&B)},projects:[...n,...u],onProject:jt,agentsMode:un,onAgentsMode:Bh,onFeedback:()=>wn(!0),initialSection:Tf,onClose:()=>{Zn(!1),gg("projects")}}),Rf&&un&&o.jsx(Gre,{snapshot:Ht.snapshot,ledgerError:Ht.error,connected:t==="open",projects:[...n,...u],running:M,busy:_u,waitingOn:j=>{const B=j.replace(/^chat:/,"");return(Ra[B]?.length??0)+(Da[B]?.length??0)+(Zi[B]?.length??0)},chatTitle:j=>R.find(B=>pt(B.id)===j)?.title,chatExists:j=>R.some(B=>pt(B.id)===j),onOpenChat:j=>{So(j),ol(!1)},onOpenRun:(j,B)=>{So(j);const G=j.replace(/^chat:/,"");be(ee=>({...ee,[G]:!0})),dt(ee=>({...ee,[G]:"run"})),me(ee=>({...ee,[j]:B})),ol(!1)},onManage:qf,onClose:()=>ol(!1)}),o.jsx("div",{className:"chat-app-surface",hidden:Os,children:de?o.jsxs("div",{className:"hero",role:"status",children:[o.jsx("h1",{className:"hero-title",children:"Chat unavailable"}),o.jsx("p",{children:"This chat was deleted or is no longer in this profile. Choose another chat from the chat list."})]}):o.jsxs(o.Fragment,{children:[(!gt||Bi)&&o.jsx(ple,{snapshot:Cs,orchestrated:Bi,view:gn,focusMode:Ft,split:Rr,unified:Bi,selectedRun:cn,worker:gt,onBackToMain:gt&&(bi??Gs)&&!(Bi&&(Rr||gn==="run"))?()=>So(bi??Gs):void 0,onOpenBeside:gt&&O&&!Ft&&Yh(pt(O))?()=>Uf(pt(O)):void 0,besideTitle:oa?.title,readOnly:gt,planPending:!!Js,pendingApprovals:ap,onView:Vs}),o.jsxs("div",{className:`workflow-surfaces${Rr?" is-split":""}`,children:[Bi&&o.jsxs("div",{className:"workflow-run-surface",hidden:!Rr&&gn!=="run",style:{"--run-w":`${In.width}px`},children:[Rr&&o.jsx("div",{className:"workflow-run-resizer",role:"separator","aria-orientation":"vertical","aria-label":"Resize the run column",onPointerDown:In.startDrag}),o.jsx(Goe,{embedded:!0,sharedHeading:!0,project:bt,coordinatorKey:Gs,allowManualRun:!un,pendingApprovals:gt?0:ap,focusRun:Va&&Va.chatKey===Gs?Va:null,projectName:j=>[...n,...u].find(B=>B.id===j)?.name,onSelectedRunChange:ft,coordinatorBusy:!gt&&rt.busy&&!br,currentChatKey:O?pt(O):null,initialSnapshot:Tt,currentCwd:Or,onEnsureCoordinator:td,onStartMaster:Eu,onOpenChat:So,onClose:()=>Vs("chat"),onOpenBeside:Ft?void 0:Uf,besideChatKey:sn?pt(sn):null,setupContext:o.jsxs("div",{className:"workflow-setup-context",children:[o.jsxs("label",{children:["Project",o.jsxs("select",{"aria-label":"Run project",value:bt?.id??"",disabled:!!O,onChange:j=>xu(j.target.value||null),children:[o.jsx("option",{value:"",children:"Choose a project"}),n.map(j=>o.jsx("option",{value:j.id,children:j.name},j.id))]})]}),o.jsxs("label",{children:["Main agent",o.jsxs("select",{"aria-label":"Main agent",value:_t.id,onChange:j=>{const B=ya.find(G=>G.id===j.target.value);B&&vl(B)},children:[_t.agent==="pi"&&o.jsx("option",{value:_t.id,disabled:!0,children:"Choose Codex or Claude"}),ya.filter(j=>j.agent!=="pi"&&(!ra||ra.includes(j.agent))).map(j=>o.jsxs("option",{value:j.id,children:[j.name," · ",j.model]},j.id))]})]}),o.jsx("p",{children:"Keep talking in Chat. Worker providers are independent of the main agent."})]})})]}),o.jsxs("div",{className:"workflow-chat-surface",hidden:!Rr&&gn==="run",ref:Te,children:[sn&&Hn&&!pu&&o.jsx(ace,{showing:le,taskTitle:Hn.title,onShow:Re,onClose:Xh}),o.jsxs("div",{className:`beside-panes${Fa?" is-split":""}`,children:[o.jsxs("div",{className:"beside-pane is-main",hidden:!Kh,...sn?{role:"region","aria-label":"Main chat"}:{},children:[Fa&&o.jsx(rce,{persona:vo}),gt&&!Bi&&o.jsx("div",{className:"read-only-strip",children:o.jsx(qC,{})}),O&&Bf[O]&&rt.messages.length>0&&o.jsx("div",{className:"chat-sync-note",role:"status",children:"Updating conversation…"}),rt.messages.length===0&&O&&Bf[O]?o.jsxs("div",{className:"hero is-waiting",children:[o.jsx("div",{className:"dots","aria-label":"opening"}),o.jsxs("p",{className:"hero-sub",children:["opening “",Xl[O]?.title??R.find(j=>j.id===O)?.title??"the session","”…"]})]}):rt.messages.length===0&&gt?o.jsxs("div",{className:"hero",children:[o.jsx("h1",{className:"hero-title",children:"Agent conversation"}),o.jsx("p",{className:"hero-sub",children:"The agent's progress will appear here. Send instructions in the main chat."})]}):rt.messages.length===0&&mn.runs.length>0?o.jsxs("div",{className:"hero",children:[o.jsx("h2",{className:"hero-title",children:"Main chat"}),o.jsx("p",{className:"hero-sub",children:"Talk with the main agent here. Select a task to follow its conversation."})]}):rt.messages.length===0?o.jsxs("div",{className:`hero ${bt?"":"hero-start"}${Is?" is-agent-welcome":""}`,children:[o.jsx("h1",{className:"hero-title",children:Is&&mi?`Talk to ${mi.name}`:Is&&nc.length>0?"Choose who you talk to":Is?bt?`What's the task in ${bt.name}?`:"What's the task?":bt?`What do you want to do in ${bt.name}?`:"What should we work on?"}),Is&&mi&&o.jsx(_re,{name:mi.name,role:mi.role??"",scope:ul?"Works across every project":`Works ${mi.projectId?`only in ${bt?.name??"its project"}`:"in any project"}`,how:ul?"Picks the project, repository and teammate for each part, and you approve the plan before anyone starts.":"Does the work itself or hands parts to its team, and you approve any plan first."},mi.id),(!bt||Is)&&Tn&&o.jsx("p",{className:"hero-route-error",role:"alert",children:Tn}),Is&&o.jsx(Sre,{agents:nc,selectedId:mi?.id??null,projectName:j=>n.find(B=>B.id===j)?.name,onPick:xr,onManage:qf}),rt.sessionId&&(O&&Xl[O]?o.jsxs("p",{className:"hero-sub",children:["continuing “",Xl[O].title,"” ·"," ",hi(Xl[O].agent).name,Xl[O].problem&&o.jsxs("span",{className:"hero-warn",children:[" ","· could not read it back (",Xl[O].problem,"). Typing still carries on the session."]})]}):o.jsx("p",{className:"hero-sub",children:"continuing an earlier session"})),bt&&!gt&&o.jsx(fse,{projectPath:Or,onResume:yr})]}):o.jsx("div",{className:"chat-body",children:o.jsx(J6,{value:Or,children:o.jsx(U4,{value:Vf,children:o.jsxs("div",{className:"chat-main",children:[o.jsx(hB,{messages:rt.messages,tail:oc,hasEarlier:!!O&&sa.current.hasEarlier(O),loadingEarlier:!!O&&!!hu[O]?.loading,earlierError:O?hu[O]?.error:void 0,onLoadEarlier:du,busy:rt.busy&&!br,stoppedAt:rt.stoppedAt,compactingSince:rt.compactingSince,conversationId:O??void 0,hostName:lN(vo,hi(_t.agent).name),hostPersona:vo,onCancelQueued:!gt&&t==="open"?Mg:void 0,onStartQueued:!gt&&t==="open"?gl:void 0,onRestoreUnsent:gt?void 0:Zf,onDismissUnsent:gt?void 0:ed,onSetting:gt?void 0:Wr,agentByTool:Ag,onOpenAgent:An}),ca&&o.jsx(bte,{run:ca,messages:rt.messages,onBack:()=>An(null)})]})})})}),(gi||$i)&&O&&o.jsxs("div",{className:`failure ${gi?.outOfCredit||$i?"is-quota":""}`,role:"alert",children:[gi&&!$i&&o.jsx("button",{className:"failure-close",type:"button","aria-label":"Dismiss",onClick:()=>{vz(O,gi),It(O,j=>({...j,failure:void 0}))},children:"×"}),o.jsx("div",{className:"failure-title",children:gi?.title??"Auto-resume scheduled"}),gi?.detail&&o.jsx("div",{className:"failure-detail",children:gi.detail}),$i&&o.jsxs("div",{className:"auto-resume-row",children:[o.jsxs("span",{children:["OctiqFlow will resume this ",$i.agent==="claude"?"Claude":$i.agent==="codex"?"Codex":"Pi"," session around"," ",new Date($i.runAt*1e3).toLocaleString([],{dateStyle:"medium",timeStyle:"short"}),"."]}),!gt&&o.jsx("button",{className:"auto-resume-cancel",type:"button",onClick:()=>{ae.invoke("chat_cancel_auto_resume",{key:pt(O)}).catch(j=>{It(O,B=>({...B,notices:[...B.notices,`Could not cancel auto-resume: ${String(j.message??j)}`]}))})},children:"Cancel auto-resume"})]}),gi?.link&&o.jsx("a",{className:"failure-link",href:gi.link,target:"_blank",rel:"noreferrer noopener",children:gi.link})]}),O&&fl.length>0&&o.jsx(Qne,{notices:fl,onClear:()=>It(O,j=>({...j,notices:[]}))}),O&&!gt&&o.jsx($T,{asks:Ra[O]??[],safetyBlocks:Zi[O]??[],questions:Da[O]??[],onPermissionAnswered:j=>au(B=>({...B,[O]:(B[O]??[]).filter(G=>G.id!==j)})),onSafetyAnswered:j=>Rh(B=>({...B,[O]:(B[O]??[]).filter(G=>G.id!==j)})),onQuestionsAnswered:j=>Yl(B=>({...B,[O]:(B[O]??[]).filter(G=>!j.includes(G.id))})),onContinue:Wr}),O&&We.snapshot?.environments[pt(O)]?.enabled&&o.jsx(z$,{environment:We.snapshot.environments[pt(O)],running:rt.busy,onRefresh:We.refresh},O),Qe&&qa&&o.jsx(bpe,{project:qa,onCommandsChanged:Br,onHide:()=>{Oi(!1),Ln(E1,"0")}},qa.id),Ys.map(j=>(Ra[j]?.length??0)+(Zi[j]?.length??0)>0&&o.jsxs("section",{"aria-label":"Agent safety approvals",children:[o.jsxs("p",{className:"worker-approval-context",children:["Approval for ",R.find(B=>B.id===j)?.title??"agent",". Follow-up instructions go through this main chat."]}),o.jsx($T,{asks:Ra[j]??[],safetyBlocks:Zi[j]??[],questions:[],onPermissionAnswered:B=>au(G=>({...G,[j]:(G[j]??[]).filter(ee=>ee.id!==B)})),onSafetyAnswered:B=>Rh(G=>({...G,[j]:(G[j]??[]).filter(ee=>ee.id!==B)})),onQuestionsAnswered:()=>{},onContinue:B=>Wr(`For your worker chat ${j}:
324
324
 
325
325
  ${B}
326
326