octiqflow-linux-x64 0.3.12 → 0.3.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.
Files changed (68) hide show
  1. package/bin/octiq-server +0 -0
  2. package/bin/v2/assets/{index-B9RQz1OR.js → index-9ROAFG8N.js} +1 -1
  3. package/bin/v2/assets/index-9ROAFG8N.js.br +0 -0
  4. package/bin/v2/assets/index-9ROAFG8N.js.gz +0 -0
  5. package/bin/v2/assets/index-BXVOMy73.css +1 -0
  6. package/bin/v2/assets/index-BXVOMy73.css.br +0 -0
  7. package/bin/v2/assets/index-BXVOMy73.css.gz +0 -0
  8. package/bin/v2/assets/{index-BD_cQrI6.js → index-BhWK4R0o.js} +1 -1
  9. package/bin/v2/assets/index-BhWK4R0o.js.br +0 -0
  10. package/bin/v2/assets/index-BhWK4R0o.js.gz +0 -0
  11. package/bin/v2/assets/{index-DcQlJMgK.js → index-BtOXjqUr.js} +6 -6
  12. package/bin/v2/assets/index-BtOXjqUr.js.br +0 -0
  13. package/bin/v2/assets/index-BtOXjqUr.js.gz +0 -0
  14. package/bin/v2/assets/{index-BgOsXXRm.js → index-C0op0LaU.js} +1 -1
  15. package/bin/v2/assets/index-C0op0LaU.js.br +0 -0
  16. package/bin/v2/assets/index-C0op0LaU.js.gz +0 -0
  17. package/bin/v2/assets/{index-DKPe1qy4.js → index-CKZbCF5Y.js} +1 -1
  18. package/bin/v2/assets/index-CKZbCF5Y.js.br +0 -0
  19. package/bin/v2/assets/{index-DKPe1qy4.js.gz → index-CKZbCF5Y.js.gz} +0 -0
  20. package/bin/v2/assets/{index-CTzvT_1x.js → index-CkkiNkM6.js} +1 -1
  21. package/bin/v2/assets/index-CkkiNkM6.js.br +0 -0
  22. package/bin/v2/assets/index-CkkiNkM6.js.gz +0 -0
  23. package/bin/v2/assets/{index-DE8onpZH.js → index-DNdWJa_x.js} +1 -1
  24. package/bin/v2/assets/index-DNdWJa_x.js.br +0 -0
  25. package/bin/v2/assets/index-DNdWJa_x.js.gz +0 -0
  26. package/bin/v2/assets/{index-DrUz882s.js → index-DV3dNMS1.js} +1 -1
  27. package/bin/v2/assets/index-DV3dNMS1.js.br +0 -0
  28. package/bin/v2/assets/index-DV3dNMS1.js.gz +0 -0
  29. package/bin/v2/assets/{index-d1wSMeTJ.js → index-DgVqfi3n.js} +1 -1
  30. package/bin/v2/assets/index-DgVqfi3n.js.br +0 -0
  31. package/bin/v2/assets/index-DgVqfi3n.js.gz +0 -0
  32. package/bin/v2/assets/{index-hprnX92o.js → index-EbE9Equf.js} +1 -1
  33. package/bin/v2/assets/index-EbE9Equf.js.br +0 -0
  34. package/bin/v2/assets/index-EbE9Equf.js.gz +0 -0
  35. package/bin/v2/assets/{index-BOO1PLTc.js → index-RUqxFSoX.js} +1 -1
  36. package/bin/v2/assets/index-RUqxFSoX.js.br +0 -0
  37. package/bin/v2/assets/index-RUqxFSoX.js.gz +0 -0
  38. package/bin/v2/assets/{index-Di5fgmBQ.js → index-_HwsVN5C.js} +1 -1
  39. package/bin/v2/assets/index-_HwsVN5C.js.br +0 -0
  40. package/bin/v2/assets/index-_HwsVN5C.js.gz +0 -0
  41. package/bin/v2/index.html +2 -2
  42. package/package.json +1 -1
  43. package/bin/v2/assets/index-B9RQz1OR.js.br +0 -0
  44. package/bin/v2/assets/index-B9RQz1OR.js.gz +0 -0
  45. package/bin/v2/assets/index-BD_cQrI6.js.br +0 -0
  46. package/bin/v2/assets/index-BD_cQrI6.js.gz +0 -0
  47. package/bin/v2/assets/index-BOO1PLTc.js.br +0 -0
  48. package/bin/v2/assets/index-BOO1PLTc.js.gz +0 -0
  49. package/bin/v2/assets/index-BgOsXXRm.js.br +0 -0
  50. package/bin/v2/assets/index-BgOsXXRm.js.gz +0 -0
  51. package/bin/v2/assets/index-CTzvT_1x.js.br +0 -0
  52. package/bin/v2/assets/index-CTzvT_1x.js.gz +0 -0
  53. package/bin/v2/assets/index-D-KvT_lB.css +0 -1
  54. package/bin/v2/assets/index-D-KvT_lB.css.br +0 -0
  55. package/bin/v2/assets/index-D-KvT_lB.css.gz +0 -0
  56. package/bin/v2/assets/index-DE8onpZH.js.br +0 -0
  57. package/bin/v2/assets/index-DE8onpZH.js.gz +0 -0
  58. package/bin/v2/assets/index-DKPe1qy4.js.br +0 -0
  59. package/bin/v2/assets/index-DcQlJMgK.js.br +0 -0
  60. package/bin/v2/assets/index-DcQlJMgK.js.gz +0 -0
  61. package/bin/v2/assets/index-Di5fgmBQ.js.br +0 -0
  62. package/bin/v2/assets/index-Di5fgmBQ.js.gz +0 -0
  63. package/bin/v2/assets/index-DrUz882s.js.br +0 -0
  64. package/bin/v2/assets/index-DrUz882s.js.gz +0 -0
  65. package/bin/v2/assets/index-d1wSMeTJ.js.br +0 -0
  66. package/bin/v2/assets/index-d1wSMeTJ.js.gz +0 -0
  67. package/bin/v2/assets/index-hprnX92o.js.br +0 -0
  68. package/bin/v2/assets/index-hprnX92o.js.gz +0 -0
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./index-DE8onpZH.js","./index-Di5fgmBQ.js","./index-DrUz882s.js","./index-B9RQz1OR.js","./index-CTzvT_1x.js","./index-hprnX92o.js","./index-BD_cQrI6.js","./index-d1wSMeTJ.js","./index-BOO1PLTc.js","./index-DKPe1qy4.js","./index-BgOsXXRm.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./index-DNdWJa_x.js","./index-_HwsVN5C.js","./index-DV3dNMS1.js","./index-9ROAFG8N.js","./index-CkkiNkM6.js","./index-EbE9Equf.js","./index-BhWK4R0o.js","./index-DgVqfi3n.js","./index-RUqxFSoX.js","./index-CKZbCF5Y.js","./index-C0op0LaU.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 i of document.querySelectorAll('link[rel="modulepreload"]'))s(i);new MutationObserver(i=>{for(const r of i)if(r.type==="childList")for(const o of r.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&s(o)}).observe(document,{childList:!0,subtree:!0});function n(i){const r={};return i.integrity&&(r.integrity=i.integrity),i.referrerPolicy&&(r.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?r.credentials="include":i.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function s(i){if(i.ep)return;i.ep=!0;const r=n(i);fetch(i.href,r)}})();function fI(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Mk={exports:{}},jv={};var PM;function GW(){if(PM)return jv;PM=1;var t=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function n(s,i,r){var o=null;if(r!==void 0&&(o=""+r),i.key!==void 0&&(o=""+i.key),"key"in i){r={};for(var l in i)l!=="key"&&(r[l]=i[l])}else r=i;return i=r.ref,{$$typeof:t,type:s,key:o,ref:i!==void 0?i:null,props:r}}return jv.Fragment=e,jv.jsx=n,jv.jsxs=n,jv}var zM;function YW(){return zM||(zM=1,Mk.exports=GW()),Mk.exports}var a=YW(),Lk={exports:{}},Ht={};var FM;function XW(){if(FM)return Ht;FM=1;var t=Symbol.for("react.transitional.element"),e=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),r=Symbol.for("react.consumer"),o=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),h=Symbol.for("react.memo"),f=Symbol.for("react.lazy"),m=Symbol.for("react.activity"),g=Symbol.iterator;function x(Y){return Y===null||typeof Y!="object"?null:(Y=g&&Y[g]||Y["@@iterator"],typeof Y=="function"?Y:null)}var b={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},_=Object.assign,k={};function N(Y,J,P){this.props=Y,this.context=J,this.refs=k,this.updater=P||b}N.prototype.isReactComponent={},N.prototype.setState=function(Y,J){if(typeof Y!="object"&&typeof Y!="function"&&Y!=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,Y,J,"setState")},N.prototype.forceUpdate=function(Y){this.updater.enqueueForceUpdate(this,Y,"forceUpdate")};function j(){}j.prototype=N.prototype;function M(Y,J,P){this.props=Y,this.context=J,this.refs=k,this.updater=P||b}var A=M.prototype=new j;A.constructor=M,_(A,N.prototype),A.isPureReactComponent=!0;var E=Array.isArray;function L(){}var O={H:null,A:null,T:null,S:null},X=Object.prototype.hasOwnProperty;function q(Y,J,P){var ne=P.ref;return{$$typeof:t,type:Y,key:J,ref:ne!==void 0?ne:null,props:P}}function $(Y,J){return q(Y.type,J,Y.props)}function G(Y){return typeof Y=="object"&&Y!==null&&Y.$$typeof===t}function B(Y){var J={"=":"=0",":":"=2"};return"$"+Y.replace(/[=:]/g,function(P){return J[P]})}var F=/\/+/g;function z(Y,J){return typeof Y=="object"&&Y!==null&&Y.key!=null?B(""+Y.key):J.toString(36)}function W(Y){switch(Y.status){case"fulfilled":return Y.value;case"rejected":throw Y.reason;default:switch(typeof Y.status=="string"?Y.then(L,L):(Y.status="pending",Y.then(function(J){Y.status==="pending"&&(Y.status="fulfilled",Y.value=J)},function(J){Y.status==="pending"&&(Y.status="rejected",Y.reason=J)})),Y.status){case"fulfilled":return Y.value;case"rejected":throw Y.reason}}throw Y}function H(Y,J,P,ne,he){var le=typeof Y;(le==="undefined"||le==="boolean")&&(Y=null);var oe=!1;if(Y===null)oe=!0;else switch(le){case"bigint":case"string":case"number":oe=!0;break;case"object":switch(Y.$$typeof){case t:case e:oe=!0;break;case f:return oe=Y._init,H(oe(Y._payload),J,P,ne,he)}}if(oe)return he=he(Y),oe=ne===""?"."+z(Y,0):ne,E(he)?(P="",oe!=null&&(P=oe.replace(F,"$&/")+"/"),H(he,J,P,"",function(Oe){return Oe})):he!=null&&(G(he)&&(he=$(he,P+(he.key==null||Y&&Y.key===he.key?"":(""+he.key).replace(F,"$&/")+"/")+oe)),J.push(he)),1;oe=0;var ye=ne===""?".":ne+":";if(E(Y))for(var D=0;D<Y.length;D++)ne=Y[D],le=ye+z(ne,D),oe+=H(ne,J,P,le,he);else if(D=x(Y),typeof D=="function")for(Y=D.call(Y),D=0;!(ne=Y.next()).done;)ne=ne.value,le=ye+z(ne,D++),oe+=H(ne,J,P,le,he);else if(le==="object"){if(typeof Y.then=="function")return H(W(Y),J,P,ne,he);throw J=String(Y),Error("Objects are not valid as a React child (found: "+(J==="[object Object]"?"object with keys {"+Object.keys(Y).join(", ")+"}":J)+"). If you meant to render a collection of children, use an array instead.")}return oe}function U(Y,J,P){if(Y==null)return Y;var ne=[],he=0;return H(Y,ne,"","",function(le){return J.call(P,le,he++)}),ne}function ee(Y){if(Y._status===-1){var J=Y._result;J=J(),J.then(function(P){(Y._status===0||Y._status===-1)&&(Y._status=1,Y._result=P)},function(P){(Y._status===0||Y._status===-1)&&(Y._status=2,Y._result=P)}),Y._status===-1&&(Y._status=0,Y._result=J)}if(Y._status===1)return Y._result.default;throw Y._result}var Q=typeof reportError=="function"?reportError:function(Y){if(typeof window=="object"&&typeof window.ErrorEvent=="function"){var J=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:typeof Y=="object"&&Y!==null&&typeof Y.message=="string"?String(Y.message):String(Y),error:Y});if(!window.dispatchEvent(J))return}else if(typeof process=="object"&&typeof process.emit=="function"){process.emit("uncaughtException",Y);return}console.error(Y)},I={map:U,forEach:function(Y,J,P){U(Y,function(){J.apply(this,arguments)},P)},count:function(Y){var J=0;return U(Y,function(){J++}),J},toArray:function(Y){return U(Y,function(J){return J})||[]},only:function(Y){if(!G(Y))throw Error("React.Children.only expected to receive a single React element child.");return Y}};return Ht.Activity=m,Ht.Children=I,Ht.Component=N,Ht.Fragment=n,Ht.Profiler=i,Ht.PureComponent=M,Ht.StrictMode=s,Ht.Suspense=u,Ht.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=O,Ht.__COMPILER_RUNTIME={__proto__:null,c:function(Y){return O.H.useMemoCache(Y)}},Ht.cache=function(Y){return function(){return Y.apply(null,arguments)}},Ht.cacheSignal=function(){return null},Ht.cloneElement=function(Y,J,P){if(Y==null)throw Error("The argument must be a React element, but you passed "+Y+".");var ne=_({},Y.props),he=Y.key;if(J!=null)for(le in J.key!==void 0&&(he=""+J.key),J)!X.call(J,le)||le==="key"||le==="__self"||le==="__source"||le==="ref"&&J.ref===void 0||(ne[le]=J[le]);var le=arguments.length-2;if(le===1)ne.children=P;else if(1<le){for(var oe=Array(le),ye=0;ye<le;ye++)oe[ye]=arguments[ye+2];ne.children=oe}return q(Y.type,he,ne)},Ht.createContext=function(Y){return Y={$$typeof:o,_currentValue:Y,_currentValue2:Y,_threadCount:0,Provider:null,Consumer:null},Y.Provider=Y,Y.Consumer={$$typeof:r,_context:Y},Y},Ht.createElement=function(Y,J,P){var ne,he={},le=null;if(J!=null)for(ne in J.key!==void 0&&(le=""+J.key),J)X.call(J,ne)&&ne!=="key"&&ne!=="__self"&&ne!=="__source"&&(he[ne]=J[ne]);var oe=arguments.length-2;if(oe===1)he.children=P;else if(1<oe){for(var ye=Array(oe),D=0;D<oe;D++)ye[D]=arguments[D+2];he.children=ye}if(Y&&Y.defaultProps)for(ne in oe=Y.defaultProps,oe)he[ne]===void 0&&(he[ne]=oe[ne]);return q(Y,le,he)},Ht.createRef=function(){return{current:null}},Ht.forwardRef=function(Y){return{$$typeof:l,render:Y}},Ht.isValidElement=G,Ht.lazy=function(Y){return{$$typeof:f,_payload:{_status:-1,_result:Y},_init:ee}},Ht.memo=function(Y,J){return{$$typeof:h,type:Y,compare:J===void 0?null:J}},Ht.startTransition=function(Y){var J=O.T,P={};O.T=P;try{var ne=Y(),he=O.S;he!==null&&he(P,ne),typeof ne=="object"&&ne!==null&&typeof ne.then=="function"&&ne.then(L,Q)}catch(le){Q(le)}finally{J!==null&&P.types!==null&&(J.types=P.types),O.T=J}},Ht.unstable_useCacheRefresh=function(){return O.H.useCacheRefresh()},Ht.use=function(Y){return O.H.use(Y)},Ht.useActionState=function(Y,J,P){return O.H.useActionState(Y,J,P)},Ht.useCallback=function(Y,J){return O.H.useCallback(Y,J)},Ht.useContext=function(Y){return O.H.useContext(Y)},Ht.useDebugValue=function(){},Ht.useDeferredValue=function(Y,J){return O.H.useDeferredValue(Y,J)},Ht.useEffect=function(Y,J){return O.H.useEffect(Y,J)},Ht.useEffectEvent=function(Y){return O.H.useEffectEvent(Y)},Ht.useId=function(){return O.H.useId()},Ht.useImperativeHandle=function(Y,J,P){return O.H.useImperativeHandle(Y,J,P)},Ht.useInsertionEffect=function(Y,J){return O.H.useInsertionEffect(Y,J)},Ht.useLayoutEffect=function(Y,J){return O.H.useLayoutEffect(Y,J)},Ht.useMemo=function(Y,J){return O.H.useMemo(Y,J)},Ht.useOptimistic=function(Y,J){return O.H.useOptimistic(Y,J)},Ht.useReducer=function(Y,J,P){return O.H.useReducer(Y,J,P)},Ht.useRef=function(Y){return O.H.useRef(Y)},Ht.useState=function(Y){return O.H.useState(Y)},Ht.useSyncExternalStore=function(Y,J,P){return O.H.useSyncExternalStore(Y,J,P)},Ht.useTransition=function(){return O.H.useTransition()},Ht.version="19.2.8",Ht}var HM;function RN(){return HM||(HM=1,Lk.exports=XW()),Lk.exports}var y=RN(),Tk={exports:{}},Nv={},Rk={exports:{}},Dk={};var WM;function QW(){return WM||(WM=1,(function(t){function e(H,U){var ee=H.length;H.push(U);e:for(;0<ee;){var Q=ee-1>>>1,I=H[Q];if(0<i(I,U))H[Q]=U,H[ee]=I,ee=Q;else break e}}function n(H){return H.length===0?null:H[0]}function s(H){if(H.length===0)return null;var U=H[0],ee=H.pop();if(ee!==U){H[0]=ee;e:for(var Q=0,I=H.length,Y=I>>>1;Q<Y;){var J=2*(Q+1)-1,P=H[J],ne=J+1,he=H[ne];if(0>i(P,ee))ne<I&&0>i(he,P)?(H[Q]=he,H[ne]=ee,Q=ne):(H[Q]=P,H[J]=ee,Q=J);else if(ne<I&&0>i(he,ee))H[Q]=he,H[ne]=ee,Q=ne;else break e}}return U}function i(H,U){var ee=H.sortIndex-U.sortIndex;return ee!==0?ee:H.id-U.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 o=Date,l=o.now();t.unstable_now=function(){return o.now()-l}}var u=[],h=[],f=1,m=null,g=3,x=!1,b=!1,_=!1,k=!1,N=typeof setTimeout=="function"?setTimeout:null,j=typeof clearTimeout=="function"?clearTimeout:null,M=typeof setImmediate<"u"?setImmediate:null;function A(H){for(var U=n(h);U!==null;){if(U.callback===null)s(h);else if(U.startTime<=H)s(h),U.sortIndex=U.expirationTime,e(u,U);else break;U=n(h)}}function E(H){if(_=!1,A(H),!b)if(n(u)!==null)b=!0,L||(L=!0,B());else{var U=n(h);U!==null&&W(E,U.startTime-H)}}var L=!1,O=-1,X=5,q=-1;function $(){return k?!0:!(t.unstable_now()-q<X)}function G(){if(k=!1,L){var H=t.unstable_now();q=H;var U=!0;try{e:{b=!1,_&&(_=!1,j(O),O=-1),x=!0;var ee=g;try{t:{for(A(H),m=n(u);m!==null&&!(m.expirationTime>H&&$());){var Q=m.callback;if(typeof Q=="function"){m.callback=null,g=m.priorityLevel;var I=Q(m.expirationTime<=H);if(H=t.unstable_now(),typeof I=="function"){m.callback=I,A(H),U=!0;break t}m===n(u)&&s(u),A(H)}else s(u);m=n(u)}if(m!==null)U=!0;else{var Y=n(h);Y!==null&&W(E,Y.startTime-H),U=!1}}break e}finally{m=null,g=ee,x=!1}U=void 0}}finally{U?B():L=!1}}}var B;if(typeof M=="function")B=function(){M(G)};else if(typeof MessageChannel<"u"){var F=new MessageChannel,z=F.port2;F.port1.onmessage=G,B=function(){z.postMessage(null)}}else B=function(){N(G,0)};function W(H,U){O=N(function(){H(t.unstable_now())},U)}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(H){H.callback=null},t.unstable_forceFrameRate=function(H){0>H||125<H?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):X=0<H?Math.floor(1e3/H):5},t.unstable_getCurrentPriorityLevel=function(){return g},t.unstable_next=function(H){switch(g){case 1:case 2:case 3:var U=3;break;default:U=g}var ee=g;g=U;try{return H()}finally{g=ee}},t.unstable_requestPaint=function(){k=!0},t.unstable_runWithPriority=function(H,U){switch(H){case 1:case 2:case 3:case 4:case 5:break;default:H=3}var ee=g;g=H;try{return U()}finally{g=ee}},t.unstable_scheduleCallback=function(H,U,ee){var Q=t.unstable_now();switch(typeof ee=="object"&&ee!==null?(ee=ee.delay,ee=typeof ee=="number"&&0<ee?Q+ee:Q):ee=Q,H){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=ee+I,H={id:f++,callback:U,priorityLevel:H,startTime:ee,expirationTime:I,sortIndex:-1},ee>Q?(H.sortIndex=ee,e(h,H),n(u)===null&&H===n(h)&&(_?(j(O),O=-1):_=!0,W(E,ee-Q))):(H.sortIndex=I,e(u,H),b||x||(b=!0,L||(L=!0,B()))),H},t.unstable_shouldYield=$,t.unstable_wrapCallback=function(H){var U=g;return function(){var ee=g;g=U;try{return H.apply(this,arguments)}finally{g=ee}}}})(Dk)),Dk}var qM;function ZW(){return qM||(qM=1,Rk.exports=QW()),Rk.exports}var Ok={exports:{}},hr={};var UM;function JW(){if(UM)return hr;UM=1;var t=RN();function e(u){var h="https://react.dev/errors/"+u;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 #"+u+"; visit "+h+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function n(){}var s={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},i=Symbol.for("react.portal");function r(u,h,f){var m=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:i,key:m==null?null:""+m,children:u,containerInfo:h,implementation:f}}var o=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function l(u,h){if(u==="font")return"";if(typeof h=="string")return h==="use-credentials"?h:""}return hr.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=s,hr.createPortal=function(u,h){var f=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!h||h.nodeType!==1&&h.nodeType!==9&&h.nodeType!==11)throw Error(e(299));return r(u,h,null,f)},hr.flushSync=function(u){var h=o.T,f=s.p;try{if(o.T=null,s.p=2,u)return u()}finally{o.T=h,s.p=f,s.d.f()}},hr.preconnect=function(u,h){typeof u=="string"&&(h?(h=h.crossOrigin,h=typeof h=="string"?h==="use-credentials"?h:"":void 0):h=null,s.d.C(u,h))},hr.prefetchDNS=function(u){typeof u=="string"&&s.d.D(u)},hr.preinit=function(u,h){if(typeof u=="string"&&h&&typeof h.as=="string"){var f=h.as,m=l(f,h.crossOrigin),g=typeof h.integrity=="string"?h.integrity:void 0,x=typeof h.fetchPriority=="string"?h.fetchPriority:void 0;f==="style"?s.d.S(u,typeof h.precedence=="string"?h.precedence:void 0,{crossOrigin:m,integrity:g,fetchPriority:x}):f==="script"&&s.d.X(u,{crossOrigin:m,integrity:g,fetchPriority:x,nonce:typeof h.nonce=="string"?h.nonce:void 0})}},hr.preinitModule=function(u,h){if(typeof u=="string")if(typeof h=="object"&&h!==null){if(h.as==null||h.as==="script"){var f=l(h.as,h.crossOrigin);s.d.M(u,{crossOrigin:f,integrity:typeof h.integrity=="string"?h.integrity:void 0,nonce:typeof h.nonce=="string"?h.nonce:void 0})}}else h==null&&s.d.M(u)},hr.preload=function(u,h){if(typeof u=="string"&&typeof h=="object"&&h!==null&&typeof h.as=="string"){var f=h.as,m=l(f,h.crossOrigin);s.d.L(u,f,{crossOrigin:m,integrity:typeof h.integrity=="string"?h.integrity:void 0,nonce:typeof h.nonce=="string"?h.nonce:void 0,type:typeof h.type=="string"?h.type:void 0,fetchPriority:typeof h.fetchPriority=="string"?h.fetchPriority:void 0,referrerPolicy:typeof h.referrerPolicy=="string"?h.referrerPolicy:void 0,imageSrcSet:typeof h.imageSrcSet=="string"?h.imageSrcSet:void 0,imageSizes:typeof h.imageSizes=="string"?h.imageSizes:void 0,media:typeof h.media=="string"?h.media:void 0})}},hr.preloadModule=function(u,h){if(typeof u=="string")if(h){var f=l(h.as,h.crossOrigin);s.d.m(u,{as:typeof h.as=="string"&&h.as!=="script"?h.as:void 0,crossOrigin:f,integrity:typeof h.integrity=="string"?h.integrity:void 0})}else s.d.m(u)},hr.requestFormReset=function(u){s.d.r(u)},hr.unstable_batchedUpdates=function(u,h){return u(h)},hr.useFormState=function(u,h,f){return o.H.useFormState(u,h,f)},hr.useFormStatus=function(){return o.H.useHostTransitionStatus()},hr.version="19.2.8",hr}var VM;function pI(){if(VM)return Ok.exports;VM=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(),Ok.exports=JW(),Ok.exports}var KM;function eq(){if(KM)return Nv;KM=1;var t=ZW(),e=RN(),n=pI();function s(c){var d="https://react.dev/errors/"+c;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 #"+c+"; visit "+d+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function i(c){return!(!c||c.nodeType!==1&&c.nodeType!==9&&c.nodeType!==11)}function r(c){var d=c,p=c;if(c.alternate)for(;d.return;)d=d.return;else{c=d;do d=c,(d.flags&4098)!==0&&(p=d.return),c=d.return;while(c)}return d.tag===3?p:null}function o(c){if(c.tag===13){var d=c.memoizedState;if(d===null&&(c=c.alternate,c!==null&&(d=c.memoizedState)),d!==null)return d.dehydrated}return null}function l(c){if(c.tag===31){var d=c.memoizedState;if(d===null&&(c=c.alternate,c!==null&&(d=c.memoizedState)),d!==null)return d.dehydrated}return null}function u(c){if(r(c)!==c)throw Error(s(188))}function h(c){var d=c.alternate;if(!d){if(d=r(c),d===null)throw Error(s(188));return d!==c?null:c}for(var p=c,v=d;;){var w=p.return;if(w===null)break;var S=w.alternate;if(S===null){if(v=w.return,v!==null){p=v;continue}break}if(w.child===S.child){for(S=w.child;S;){if(S===p)return u(w),c;if(S===v)return u(w),d;S=S.sibling}throw Error(s(188))}if(p.return!==v.return)p=w,v=S;else{for(var R=!1,K=w.child;K;){if(K===p){R=!0,p=w,v=S;break}if(K===v){R=!0,v=w,p=S;break}K=K.sibling}if(!R){for(K=S.child;K;){if(K===p){R=!0,p=S,v=w;break}if(K===v){R=!0,v=S,p=w;break}K=K.sibling}if(!R)throw Error(s(189))}}if(p.alternate!==v)throw Error(s(190))}if(p.tag!==3)throw Error(s(188));return p.stateNode.current===p?c:d}function f(c){var d=c.tag;if(d===5||d===26||d===27||d===6)return c;for(c=c.child;c!==null;){if(d=f(c),d!==null)return d;c=c.sibling}return null}var m=Object.assign,g=Symbol.for("react.element"),x=Symbol.for("react.transitional.element"),b=Symbol.for("react.portal"),_=Symbol.for("react.fragment"),k=Symbol.for("react.strict_mode"),N=Symbol.for("react.profiler"),j=Symbol.for("react.consumer"),M=Symbol.for("react.context"),A=Symbol.for("react.forward_ref"),E=Symbol.for("react.suspense"),L=Symbol.for("react.suspense_list"),O=Symbol.for("react.memo"),X=Symbol.for("react.lazy"),q=Symbol.for("react.activity"),$=Symbol.for("react.memo_cache_sentinel"),G=Symbol.iterator;function B(c){return c===null||typeof c!="object"?null:(c=G&&c[G]||c["@@iterator"],typeof c=="function"?c:null)}var F=Symbol.for("react.client.reference");function z(c){if(c==null)return null;if(typeof c=="function")return c.$$typeof===F?null:c.displayName||c.name||null;if(typeof c=="string")return c;switch(c){case _:return"Fragment";case N:return"Profiler";case k:return"StrictMode";case E:return"Suspense";case L:return"SuspenseList";case q:return"Activity"}if(typeof c=="object")switch(c.$$typeof){case b:return"Portal";case M:return c.displayName||"Context";case j:return(c._context.displayName||"Context")+".Consumer";case A:var d=c.render;return c=c.displayName,c||(c=d.displayName||d.name||"",c=c!==""?"ForwardRef("+c+")":"ForwardRef"),c;case O:return d=c.displayName||null,d!==null?d:z(c.type)||"Memo";case X:d=c._payload,c=c._init;try{return z(c(d))}catch{}}return null}var W=Array.isArray,H=e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,U=n.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ee={pending:!1,data:null,method:null,action:null},Q=[],I=-1;function Y(c){return{current:c}}function J(c){0>I||(c.current=Q[I],Q[I]=null,I--)}function P(c,d){I++,Q[I]=c.current,c.current=d}var ne=Y(null),he=Y(null),le=Y(null),oe=Y(null);function ye(c,d){switch(P(le,d),P(he,c),P(ne,null),d.nodeType){case 9:case 11:c=(c=d.documentElement)&&(c=c.namespaceURI)?lM(c):0;break;default:if(c=d.tagName,d=d.namespaceURI)d=lM(d),c=cM(d,c);else switch(c){case"svg":c=1;break;case"math":c=2;break;default:c=0}}J(ne),P(ne,c)}function D(){J(ne),J(he),J(le)}function Oe(c){c.memoizedState!==null&&P(oe,c);var d=ne.current,p=cM(d,c.type);d!==p&&(P(he,c),P(ne,p))}function ze(c){he.current===c&&(J(ne),J(he)),oe.current===c&&(J(oe),_v._currentValue=ee)}var Ce,ve;function Ie(c){if(Ce===void 0)try{throw Error()}catch(p){var d=p.stack.trim().match(/\n( *(at )?)/);Ce=d&&d[1]||"",ve=-1<p.stack.indexOf(`
3
3
  at`)?" (<anonymous>)":-1<p.stack.indexOf("@")?"@unknown:0:0":""}return`
4
4
  `+Ce+c+ve}var ae=!1;function $e(c,d){if(!c||ae)return"";ae=!0;var p=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var v={DetermineComponentFrameRoot:function(){try{if(d){var Me=function(){throw Error()};if(Object.defineProperty(Me.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Me,[])}catch(we){var xe=we}Reflect.construct(c,[],Me)}else{try{Me.call()}catch(we){xe=we}c.call(Me.prototype)}}else{try{throw Error()}catch(we){xe=we}(Me=c())&&typeof Me.catch=="function"&&Me.catch(function(){})}}catch(we){if(we&&xe&&typeof we.stack=="string")return[we.stack,xe.stack]}return[null,null]}};v.DetermineComponentFrameRoot.displayName="DetermineComponentFrameRoot";var w=Object.getOwnPropertyDescriptor(v.DetermineComponentFrameRoot,"name");w&&w.configurable&&Object.defineProperty(v.DetermineComponentFrameRoot,"name",{value:"DetermineComponentFrameRoot"});var S=v.DetermineComponentFrameRoot(),R=S[0],K=S[1];if(R&&K){var se=R.split(`
@@ -81,7 +81,7 @@ ${i}
81
81
  --Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\uFEFF-]`,Vj),dle={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 yS=null;function fle(){var t;if(yS==null&&typeof document<"u"&&document.body){let e=document.body.style;yS=((t=e.tabSize)!==null&&t!==void 0?t:e.MozTabSize)!=null}return yS||!1}const nw=ct.define({combine(t){let e=Mf(t,{render:null,specialChars:hle,addSpecialChars:null});return(e.replaceTabs=!fle())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,Vj)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,Vj)),e}});function ple(t={}){return[nw.of(t),mle()]}let IR=null;function mle(){return IR||(IR=Pr.fromClass(class{constructor(t){this.view=t,this.decorations=sn.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(t.state.facet(nw)),this.decorations=this.decorator.createDeco(t)}makeDecorator(t){return new ule({regexp:t.specialChars,decoration:(e,n,s)=>{let{doc:i}=n.state,r=JA(e[0],0);if(r==9){let o=i.lineAt(s),l=n.state.tabSize,u=dg(o.text,l,s-o.from);return sn.replace({widget:new yle((l-u%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=sn.replace({widget:new xle(t,r)}))},boundary:t.replaceTabs?void 0:/[^]/})}update(t){let e=t.state.facet(nw);t.startState.facet(nw)!=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 gle="•";function vle(t){return t>=32?gle:t==10?"␤":String.fromCharCode(9216+t)}class xle extends fg{constructor(e,n){super(),this.options=e,this.code=n}eq(e){return e.code==this.code}toDOM(e){let n=vle(this.code),s=e.state.phrase("Control character")+" "+(dle[this.code]||"0x"+this.code.toString(16)),i=this.options.render&&this.options.render(this.code,s,n);if(i)return i;let r=document.createElement("span");return r.textContent=n,r.title=s,r.setAttribute("aria-label",s),r.className="cm-specialChar",r}ignoreEvent(){return!1}}class yle extends fg{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 ble(){return _le}const wle=sn.line({class:"cm-activeLine"}),_le=Pr.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 s of t.state.selection.ranges){let i=t.lineBlockAt(s.head);i.from>e&&(n.push(wle.range(i.from)),e=i.from)}return sn.set(n)}},{decorations:t=>t.decorations}),Kj=2e3;function kle(t,e,n){let s=Math.min(e.line,n.line),i=Math.max(e.line,n.line),r=[];if(e.off>Kj||n.off>Kj||e.col<0||n.col<0){let o=Math.min(e.off,n.off),l=Math.max(e.off,n.off);for(let u=s;u<=i;u++){let h=t.doc.line(u);h.length<=l&&r.push(De.range(h.from+o,h.to+l))}}else{let o=Math.min(e.col,n.col),l=Math.max(e.col,n.col);for(let u=s;u<=i;u++){let h=t.doc.line(u),f=jj(h.text,o,t.tabSize,!0);if(f<0)r.push(De.cursor(h.to));else{let m=jj(h.text,l,t.tabSize);r.push(De.range(h.from+f,h.from+m))}}}return r}function Sle(t,e){let n=t.coordsAtPos(t.viewport.from);return n?Math.round(Math.abs((n.left-e)/t.defaultCharacterWidth)):-1}function BR(t,e){let n=t.posAtCoords({x:e.clientX,y:e.clientY},!1),s=t.state.doc.lineAt(n),i=n-s.from,r=i>Kj?-1:i==s.length?Sle(t,e.clientX):dg(s.text,t.state.tabSize,n-s.from);return{line:s.number,col:r,off:i}}function Cle(t,e){let n=BR(t,e),s=t.state.selection;return n?{update(i){if(i.docChanged){let r=i.changes.mapPos(i.startState.doc.line(n.line).from),o=i.state.doc.lineAt(r);n={line:o.number,col:n.col,off:Math.min(n.off,o.length)},s=s.map(i.changes)}},get(i,r,o){let l=BR(t,i);if(!l)return s;let u=kle(t.state,n,l);return u.length?o?De.create(u.concat(s.ranges)):De.create(u):s}}:null}function jle(t){let e=(n=>n.altKey&&n.button==0);return pt.mouseSelectionStyle.of((n,s)=>e(s)?Cle(n,s):null)}const $R=ct.define({combine(t){let e,n;for(let s of t)e=e||s.topContainer,n=n||s.bottomContainer;return{topContainer:e,bottomContainer:n}}});function lP(t,e){let n=t.plugin(cP),s=n?n.specs.indexOf(e):-1;return s>-1?n.panels[s]:null}const cP=Pr.fromClass(class{constructor(t){this.input=t.state.facet(o_),this.specs=this.input.filter(n=>n),this.panels=this.specs.map(n=>n(t));let e=t.state.facet($R);this.top=new cb(t,!0,e.topContainer),this.bottom=new cb(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($R);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new cb(t.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new cb(t.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let n=t.state.facet(o_);if(n!=this.input){let s=n.filter(u=>u),i=[],r=[],o=[],l=[];for(let u of s){let h=this.specs.indexOf(u),f;h<0?(f=u(t.view),l.push(f)):(f=this.panels[h],f.update&&f.update(t)),i.push(f),(f.top?r:o).push(f)}this.specs=s,this.panels=i,this.top.sync(r),this.bottom.sync(o);for(let u of l)u.dom.classList.add("cm-panel"),u.mount&&u.mount()}else for(let s of this.panels)s.update&&s.update(t)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:t=>pt.scrollMargins.of(e=>{let n=e.plugin(t);return n&&{top:n.top.scrollMargin(),bottom:n.bottom.scrollMargin()}})});class cb{constructor(e,n,s){this.view=e,this.top=n,this.container=s,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=PR(e);e=e.nextSibling}else this.dom.insertBefore(n.dom,e);for(;e;)e=PR(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 PR(t){let e=t.nextSibling;return t.remove(),e}const o_=ct.define({enables:cP});function Nle(t,e){let n,s=new Promise(o=>n=o),i=o=>Ale(o,e,n);t.state.field(bS,!1)?t.dispatch({effects:uP.of(i)}):t.dispatch({effects:ss.appendConfig.of(bS.init(()=>[i]))});let r=hP.of(i);return{close:r,result:s.then(o=>((t.win.queueMicrotask||(u=>t.win.setTimeout(u,10)))(()=>{t.state.field(bS).indexOf(i)>-1&&t.dispatch({effects:r})}),o))}}const bS=Kl.define({create(){return[]},update(t,e){for(let n of e.effects)n.is(uP)?t=[n.value].concat(t):n.is(hP)&&(t=t.filter(s=>s!=n.value));return t},provide:t=>o_.computeN([t],e=>e.field(t))}),uP=ss.define(),hP=ss.define();function Ale(t,e,n){let s=e.content?e.content(t,()=>o(null)):null;if(!s){if(s=Mi("form"),e.input){let l=Mi("input",e.input);/^(text|password|number|email|tel|url)$/.test(l.type)&&l.classList.add("cm-textfield"),l.name||(l.name="input"),s.appendChild(Mi("label",(e.label||"")+": ",l))}else s.appendChild(document.createTextNode(e.label||""));s.appendChild(document.createTextNode(" ")),s.appendChild(Mi("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let i=s.nodeName=="FORM"?[s]:s.querySelectorAll("form");for(let l=0;l<i.length;l++){let u=i[l];u.addEventListener("keydown",h=>{h.keyCode==27?(h.preventDefault(),o(null)):h.keyCode==13&&(h.preventDefault(),o(u))}),u.addEventListener("submit",h=>{h.preventDefault(),o(u)})}let r=Mi("div",s,Mi("button",{onclick:()=>o(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 o(l){r.contains(r.ownerDocument.activeElement)&&t.focus(),n(l)}return{dom:r,top:e.top,mount:()=>{if(e.focus){let l;typeof e.focus=="string"?l=s.querySelector(e.focus):l=s.querySelector("input")||s.querySelector("button"),l&&"select"in l?l.select():l&&"focus"in l&&l.focus()}}}}class Ah extends vf{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}Ah.prototype.elementClass="";Ah.prototype.toDOM=void 0;Ah.prototype.mapMode=Wa.TrackBefore;Ah.prototype.startSide=Ah.prototype.endSide=-1;Ah.prototype.point=!0;const sw=ct.define(),Ele=ct.define(),iw=ct.define(),zR=ct.define({combine:t=>t.some(e=>e)});function Mle(t){return[Lle]}const Lle=Pr.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(iw).map(e=>new HR(t,e)),this.fixed=!t.state.facet(zR);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,s=Math.min(e.to,n.to)-Math.max(e.from,n.from);this.syncGutters(s<(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(zR)!=!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=kn.iter(this.view.state.facet(sw),this.view.viewport.from),s=[],i=this.gutters.map(r=>new Tle(r,this.view.viewport,-this.view.documentPadding.top));for(let r of this.view.viewportLineBlocks)if(s.length&&(s=[]),Array.isArray(r.type)){let o=!0;for(let l of r.type)if(l.type==er.Text&&o){Gj(n,s,l.from);for(let u of i)u.line(this.view,l,s);o=!1}else if(l.widget)for(let u of i)u.widget(this.view,l)}else if(r.type==er.Text){Gj(n,s,r.from);for(let o of i)o.line(this.view,r,s)}else if(r.widget)for(let o of i)o.widget(this.view,r);for(let r of i)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(iw),n=t.state.facet(iw),s=t.docChanged||t.heightChanged||t.viewportChanged||!kn.eq(t.startState.facet(sw),t.state.facet(sw),t.view.viewport.from,t.view.viewport.to);if(e==n)for(let i of this.gutters)i.update(t)&&(s=!0);else{s=!0;let i=[];for(let r of n){let o=e.indexOf(r);o<0?i.push(new HR(this.view,r)):(this.gutters[o].update(t),i.push(this.gutters[o]))}for(let r of this.gutters)r.dom.remove(),i.indexOf(r)<0&&r.destroy();for(let r of i)r.config.side=="after"?this.getDOMAfter().appendChild(r.dom):this.dom.appendChild(r.dom);this.gutters=i}return s}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:t=>pt.scrollMargins.of(e=>{let n=e.plugin(t);if(!n||n.gutters.length==0||!n.fixed)return null;let s=n.dom.offsetWidth*e.scaleX,i=n.domAfter?n.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==Ss.LTR?{left:s,right:i}:{right:s,left:i}})});function FR(t){return Array.isArray(t)?t:[t]}function Gj(t,e,n){for(;t.value&&t.from<=n;)t.from==n&&e.push(t.value),t.next()}class Tle{constructor(e,n,s){this.gutter=e,this.height=s,this.i=0,this.cursor=kn.iter(e.markers,n.from)}addElement(e,n,s){let{gutter:i}=this,r=(n.top-this.height)/e.scaleY,o=n.height/e.scaleY;if(this.i==i.elements.length){let l=new dP(e,o,r,s);i.elements.push(l),i.dom.appendChild(l.dom)}else i.elements[this.i].update(e,o,r,s);this.height=n.bottom,this.i++}line(e,n,s){let i=[];Gj(this.cursor,i,n.from),s.length&&(i=i.concat(s));let r=this.gutter.config.lineMarker(e,n,i);r&&i.unshift(r);let o=this.gutter;i.length==0&&!o.config.renderEmptyElements||this.addElement(e,n,i)}widget(e,n){let s=this.gutter.config.widgetMarker(e,n.widget,n),i=s?[s]:null;for(let r of e.state.facet(Ele)){let o=r(e,n.widget,n);o&&(i||(i=[])).push(o)}i&&this.addElement(e,n,i)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let n=e.elements.pop();e.dom.removeChild(n.dom),n.destroy()}}}class HR{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 s in n.domEventHandlers)this.dom.addEventListener(s,i=>{let r=i.target,o;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let u=r.getBoundingClientRect();o=(u.top+u.bottom)/2}else o=i.clientY;let l=e.lineBlockAtHeight(o-e.documentTop);n.domEventHandlers[s](e,l,i)&&i.preventDefault()});this.markers=FR(n.markers(e)),n.initialSpacer&&(this.spacer=new dP(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=FR(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let i=this.config.updateSpacer(this.spacer.markers[0],e);i!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[i])}let s=e.view.viewport;return!kn.eq(this.markers,n,s.from,s.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}}class dP{constructor(e,n,s,i){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,n,s,i)}update(e,n,s,i){this.height!=n&&(this.height=n,this.dom.style.height=n+"px"),this.above!=s&&(this.dom.style.marginTop=(this.above=s)?s+"px":""),Rle(this.markers,i)||this.setMarkers(e,i)}setMarkers(e,n){let s="cm-gutterElement",i=this.dom.firstChild;for(let r=0,o=0;;){let l=o,u=r<n.length?n[r++]:null,h=!1;if(u){let f=u.elementClass;f&&(s+=" "+f);for(let m=o;m<this.markers.length;m++)if(this.markers[m].compare(u)){l=m,h=!0;break}}else l=this.markers.length;for(;o<l;){let f=this.markers[o++];if(f.toDOM){f.destroy(i);let m=i.nextSibling;i.remove(),i=m}}if(!u)break;u.toDOM&&(h?i=i.nextSibling:this.dom.insertBefore(u.toDOM(e),i)),h&&o++}this.dom.className=s,this.markers=n}destroy(){this.setMarkers(null,[])}}function Rle(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 Dle=ct.define(),Ole=ct.define(),gm=ct.define({combine(t){return Mf(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,n){let s=Object.assign({},e);for(let i in n){let r=s[i],o=n[i];s[i]=r?(l,u,h)=>r(l,u,h)||o(l,u,h):o}return s}})}});class wS extends Ah{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function _S(t,e){return t.state.facet(gm).formatNumber(e,t.state)}const Ile=iw.compute([gm],t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(Dle)},lineMarker(e,n,s){return s.some(i=>i.toDOM)?null:new wS(_S(e,e.state.doc.lineAt(n.from).number))},widgetMarker:(e,n,s)=>{for(let i of e.state.facet(Ole)){let r=i(e,n,s);if(r)return r}return null},lineMarkerChange:e=>e.startState.facet(gm)!=e.state.facet(gm),initialSpacer(e){return new wS(_S(e,WR(e.state.doc.lines)))},updateSpacer(e,n){let s=_S(n.view,WR(n.view.state.doc.lines));return s==e.number?e:new wS(s)},domEventHandlers:t.facet(gm).domEventHandlers,side:"before"}));function Ble(t={}){return[gm.of(t),Mle(),Ile]}function WR(t){let e=9;for(;e<t;)e=e*10+9;return e}const $le=new class extends Ah{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},Ple=sw.compute(["selection"],t=>{let e=[],n=-1;for(let s of t.selection.ranges){let i=t.doc.lineAt(s.head).from;i>n&&(n=i,e.push($le.range(i)))}return kn.of(e)});function zle(){return Ple}const Fle=1024;let Hle=0;class jo{constructor(e,n){this.from=e,this.to=n}}class an{constructor(e={}){this.id=Hle++,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 s=e(n);return s===void 0?null:[this,s]}}}an.closedBy=new an({deserialize:t=>t.split(" ")});an.openedBy=new an({deserialize:t=>t.split(" ")});an.group=new an({deserialize:t=>t.split(" ")});an.isolate=new an({deserialize:t=>{if(t&&t!="rtl"&&t!="ltr"&&t!="auto")throw new RangeError("Invalid value for isolate: "+t);return t||"auto"}});an.contextHash=new an({perNode:!0});an.lookAhead=new an({perNode:!0});an.mounted=new an({perNode:!0});class Nm{constructor(e,n,s,i=!1){this.tree=e,this.overlay=n,this.parser=s,this.bracketed=i}static get(e){return e&&e.props&&e.props[an.mounted.id]}}const Wle=Object.create(null);class Fr{constructor(e,n,s,i=0){this.name=e,this.props=n,this.id=s,this.flags=i}static define(e){let n=e.props&&e.props.length?Object.create(null):Wle,s=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),i=new Fr(e.name||"",n,e.id,s);if(e.props){for(let r of e.props)if(Array.isArray(r)||(r=r(i)),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 i}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(an.group);return n?n.indexOf(e)>-1:!1}return this.id==e}static match(e){let n=Object.create(null);for(let s in e)for(let i of s.split(" "))n[i]=e[s];return s=>{for(let i=s.prop(an.group),r=-1;r<(i?i.length:0);r++){let o=n[r<0?s.name:i[r]];if(o)return o}}}}Fr.none=new Fr("",Object.create(null),0,8);class pE{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 s of this.types){let i=null;for(let r of e){let o=r(s);if(o){i||(i=Object.assign({},s.props));let l=o[1],u=o[0];u.combine&&u.id in i&&(l=u.combine(i[u.id],l)),i[u.id]=l}}n.push(i?new Fr(s.name,i,s.id,s.flags):s)}return new pE(n)}}const ub=new WeakMap,qR=new WeakMap;var ns;(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"})(ns||(ns={}));class is{constructor(e,n,s,i,r){if(this.type=e,this.children=n,this.positions=s,this.length=i,this.props=null,r&&r.length){this.props=Object.create(null);for(let[o,l]of r)this.props[typeof o=="number"?o:o.id]=l}}toString(){let e=Nm.get(this);if(e&&!e.overlay)return e.tree.toString();let n="";for(let s of this.children){let i=s.toString();i&&(n&&(n+=","),n+=i)}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 l_(this.topNode,e)}cursorAt(e,n=0,s=0){let i=ub.get(this)||this.topNode,r=new l_(i);return r.moveTo(e,n),ub.set(this,r._tree),r}get topNode(){return new xr(this,0,0,null)}resolve(e,n=0){let s=Zx(ub.get(this)||this.topNode,e,n,!1);return ub.set(this,s),s}resolveInner(e,n=0){let s=Zx(qR.get(this)||this.topNode,e,n,!0);return qR.set(this,s),s}resolveStack(e,n=0){return Vle(this,e,n)}iterate(e){let{enter:n,leave:s,from:i=0,to:r=this.length}=e,o=e.mode||0,l=(o&ns.IncludeAnonymous)>0;for(let u=this.cursor(o|ns.IncludeAnonymous);;){let h=!1;if(u.from<=r&&u.to>=i&&(!l&&u.type.isAnonymous||n(u)!==!1)){if(u.firstChild())continue;h=!0}for(;h&&s&&(l||!u.type.isAnonymous)&&s(u),!u.nextSibling();){if(!u.parent())return;h=!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:vE(Fr.none,this.children,this.positions,0,this.children.length,0,this.length,(n,s,i)=>new is(this.type,n,s,i,this.propValues),e.makeTree||((n,s,i)=>new is(Fr.none,n,s,i)))}static build(e){return Kle(e)}}is.empty=new is(Fr.none,[],[],0);class mE{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 mE(this.buffer,this.index)}}class Eh{constructor(e,n,s){this.buffer=e,this.length=n,this.set=s}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],s=this.buffer[e+3],i=this.set.types[n],r=i.name;if(/\W/.test(r)&&!i.isError&&(r=JSON.stringify(r)),e+=4,s==e)return r;let o=[];for(;e<s;)o.push(this.childString(e)),e=this.buffer[e+3];return r+"("+o.join(",")+")"}findChild(e,n,s,i,r){let{buffer:o}=this,l=-1;for(let u=e;u!=n&&!(fP(r,i,o[u+1],o[u+2])&&(l=u,s>0));u=o[u+3]);return l}slice(e,n,s){let i=this.buffer,r=new Uint16Array(n-e),o=0;for(let l=e,u=0;l<n;){r[u++]=i[l++],r[u++]=i[l++]-s;let h=r[u++]=i[l++]-s;r[u++]=i[l++]-e,o=Math.max(o,h)}return new Eh(r,o,this.set)}}function fP(t,e,n,s){switch(t){case-2:return n<e;case-1:return s>=e&&n<e;case 0:return n<e&&s>e;case 1:return n<=e&&s>e;case 2:return s>e;case 4:return!0}}function Zx(t,e,n,s){for(var i;t.from==t.to||(n<1?t.from>=e:t.from>e)||(n>-1?t.to<=e:t.to<e);){let o=!s&&t instanceof xr&&t.index<0?null:t.parent;if(!o)return t;t=o}let r=s?0:ns.IgnoreOverlays;if(s)for(let o=t,l=o.parent;l;o=l,l=o.parent)o instanceof xr&&o.index<0&&((i=l.enter(e,n,r))===null||i===void 0?void 0:i.from)!=o.from&&(t=l);for(;;){let o=t.enter(e,n,r);if(!o)return t;t=o}}class pP{cursor(e=0){return new l_(this,e)}getChild(e,n=null,s=null){let i=UR(this,e,n,s);return i.length?i[0]:null}getChildren(e,n=null,s=null){return UR(this,e,n,s)}resolve(e,n=0){return Zx(this,e,n,!1)}resolveInner(e,n=0){return Zx(this,e,n,!0)}matchContext(e){return Yj(this.parent,e)}enterUnfinishedNodesBefore(e){let n=this.childBefore(e),s=this;for(;n;){let i=n.lastChild;if(!i||i.to!=n.to)break;i.type.isError&&i.from==i.to?(s=n,n=i.prevSibling):n=i}return s}get node(){return this}get next(){return this.parent}}class xr extends pP{constructor(e,n,s,i){super(),this._tree=e,this.from=n,this.index=s,this._parent=i}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,n,s,i,r=0){for(let o=this;;){for(let{children:l,positions:u}=o._tree,h=n>0?l.length:-1;e!=h;e+=n){let f=l[e],m=u[e]+o.from,g;if(!(!(r&ns.EnterBracketed&&f instanceof is&&(g=Nm.get(f))&&!g.overlay&&g.bracketed&&s>=m&&s<=m+f.length)&&!fP(i,s,m,m+f.length))){if(f instanceof Eh){if(r&ns.ExcludeBuffers)continue;let x=f.findChild(0,f.buffer.length,n,s-m,i);if(x>-1)return new Dl(new qle(o,f,e,m),null,x)}else if(r&ns.IncludeAnonymous||!f.type.isAnonymous||gE(f)){let x;if(!(r&ns.IgnoreMounts)&&(x=Nm.get(f))&&!x.overlay)return new xr(x.tree,m,e,o);let b=new xr(f,m,e,o);return r&ns.IncludeAnonymous||!b.type.isAnonymous?b:b.nextChild(n<0?f.children.length-1:0,n,s,i,r)}}}if(r&ns.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+n:e=n<0?-1:o._parent._tree.children.length,o=o._parent,!o))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,s=0){let i;if(!(s&ns.IgnoreOverlays)&&(i=Nm.get(this._tree))&&i.overlay){let r=e-this.from,o=s&ns.EnterBracketed&&i.bracketed;for(let{from:l,to:u}of i.overlay)if((n>0||o?l<=r:l<r)&&(n<0||o?u>=r:u>r))return new xr(i.tree,i.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,n,s)}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 UR(t,e,n,s){let i=t.cursor(),r=[];if(!i.firstChild())return r;if(n!=null){for(let o=!1;!o;)if(o=i.type.is(n),!i.nextSibling())return r}for(;;){if(s!=null&&i.type.is(s))return r;if(i.type.is(e)&&r.push(i.node),!i.nextSibling())return s==null?r:[]}}function Yj(t,e,n=e.length-1){for(let s=t;n>=0;s=s.parent){if(!s)return!1;if(!s.type.isAnonymous){if(e[n]&&e[n]!=s.name)return!1;n--}}return!0}class qle{constructor(e,n,s,i){this.parent=e,this.buffer=n,this.index=s,this.start=i}}class Dl extends pP{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,s){super(),this.context=e,this._parent=n,this.index=s,this.type=e.buffer.set.types[e.buffer.buffer[s]]}child(e,n,s){let{buffer:i}=this.context,r=i.findChild(this.index+4,i.buffer[this.index+3],e,n-this.context.start,s);return r<0?null:new Dl(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,s=0){if(s&ns.ExcludeBuffers)return null;let{buffer:i}=this.context,r=i.findChild(this.index+4,i.buffer[this.index+3],n>0?1:-1,e-this.context.start,n);return r<0?null:new Dl(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 Dl(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 Dl(this.context,this._parent,e.findChild(n,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],n=[],{buffer:s}=this.context,i=this.index+4,r=s.buffer[this.index+3];if(r>i){let o=s.buffer[this.index+1];e.push(s.slice(i,r,o)),n.push(0)}return new is(this.type,e,n,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function mP(t){if(!t.length)return null;let e=0,n=t[0];for(let r=1;r<t.length;r++){let o=t[r];(o.from>n.from||o.to<n.to)&&(n=o,e=r)}let s=n instanceof xr&&n.index<0?null:n.parent,i=t.slice();return s?i[e]=s:i.splice(e,1),new Ule(i,n)}class Ule{constructor(e,n){this.heads=e,this.node=n}get next(){return mP(this.heads)}}function Vle(t,e,n){let s=t.resolveInner(e,n),i=null;for(let r=s instanceof xr?s:s.context.parent;r;r=r.parent)if(r.index<0){let o=r.parent;(i||(i=[s])).push(o.resolve(e,n)),r=o}else{let o=Nm.get(r.tree);if(o&&o.overlay&&o.overlay[0].from<=e&&o.overlay[o.overlay.length-1].to>=e){let l=new xr(o.tree,o.overlay[0].from+r.from,-1,r);(i||(i=[s])).push(Zx(l,e,n,!1))}}return i?mP(i):s}class l_{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&~ns.EnterBracketed,e instanceof xr)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let s=e._parent;s;s=s._parent)this.stack.unshift(s.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:s,buffer:i}=this.buffer;return this.type=n||i.set.types[i.buffer[e]],this.from=s+i.buffer[e+1],this.to=s+i.buffer[e+2],!0}yield(e){return e?e instanceof xr?(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,s){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,n,s,this.mode));let{buffer:i}=this.buffer,r=i.findChild(this.index+4,i.buffer[this.index+3],e,n-this.buffer.start,s);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,s=this.mode){return this.buffer?s&ns.ExcludeBuffers?!1:this.enterChild(1,e,n):this.yield(this._tree.enter(e,n,s))}parent(){if(!this.buffer)return this.yieldNode(this.mode&ns.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&ns.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,s=this.stack.length-1;if(e<0){let i=s<0?0:this.stack[s]+4;if(this.index!=i)return this.yieldBuf(n.findChild(i,this.index,-1,0,4))}else{let i=n.buffer[this.index+3];if(i<(s<0?n.buffer.length:n.buffer[this.stack[s]+3]))return this.yieldBuf(i)}return s<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,s,{buffer:i}=this;if(i){if(e>0){if(this.index<i.buffer.buffer.length)return!1}else for(let r=0;r<this.index;r++)if(i.buffer.buffer[r+3]<this.index)return!1;({index:n,parent:s}=i)}else({index:n,_parent:s}=this._tree);for(;s;{index:n,_parent:s}=s)if(n>-1)for(let r=n+e,o=e<0?-1:s._tree.children.length;r!=o;r+=e){let l=s._tree.children[r];if(this.mode&ns.IncludeAnonymous||l instanceof Eh||!l.type.isAnonymous||gE(l))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,s=0;if(e&&e.context==this.buffer)e:for(let i=this.index,r=this.stack.length;r>=0;){for(let o=e;o;o=o._parent)if(o.index==i){if(i==this.index)return o;n=o,s=r+1;break e}i=this.stack[--r]}for(let i=s;i<this.stack.length;i++)n=new Dl(this.buffer,n,this.stack[i]);return this.bufferNode=new Dl(this.buffer,n,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,n){for(let s=0;;){let i=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){s++;continue}this.type.isAnonymous||(i=!0)}for(;;){if(i&&n&&n(this),i=this.type.isAnonymous,!s)return;if(this.nextSibling())break;this.parent(),s--,i=!0}}}matchContext(e){if(!this.buffer)return Yj(this.node.parent,e);let{buffer:n}=this.buffer,{types:s}=n.set;for(let i=e.length-1,r=this.stack.length-1;i>=0;r--){if(r<0)return Yj(this._tree,e,i);let o=s[n.buffer[this.stack[r]]];if(!o.isAnonymous){if(e[i]&&e[i]!=o.name)return!1;i--}}return!0}}function gE(t){return t.children.some(e=>e instanceof Eh||!e.type.isAnonymous||gE(e))}function Kle(t){var e;let{buffer:n,nodeSet:s,maxBufferLength:i=Fle,reused:r=[],minRepeatType:o=s.types.length}=t,l=Array.isArray(n)?new mE(n,n.length):n,u=s.types,h=0,f=0;function m(E,L,O,X,q,$){let{id:G,start:B,end:F,size:z}=l,W=f,H=h;if(z<0)if(l.next(),z==-1){let Y=r[G];O.push(Y),X.push(B-E);return}else if(z==-3){h=G;return}else if(z==-4){f=G;return}else throw new RangeError(`Unrecognized record size: ${z}`);let U=u[G],ee,Q,I=B-E;if(F-B<=i&&(Q=k(l.pos-L,q))){let Y=new Uint16Array(Q.size-Q.skip),J=l.pos-Q.size,P=Y.length;for(;l.pos>J;)P=N(Q.start,Y,P);ee=new Eh(Y,F-Q.start,s),I=Q.start-E}else{let Y=l.pos-z;l.next();let J=[],P=[],ne=G>=o?G:-1,he=0,le=F;for(;l.pos>Y;)ne>=0&&l.id==ne&&l.size>=0?(l.end<=le-i&&(b(J,P,B,he,l.end,le,ne,W,H),he=J.length,le=l.end),l.next()):$>2500?g(B,Y,J,P):m(B,Y,J,P,ne,$+1);if(ne>=0&&he>0&&he<J.length&&b(J,P,B,he,B,le,ne,W,H),J.reverse(),P.reverse(),ne>-1&&he>0){let oe=x(U,H);ee=vE(U,J,P,0,J.length,0,F-B,oe,oe)}else ee=_(U,J,P,F-B,W-F,H)}O.push(ee),X.push(I)}function g(E,L,O,X){let q=[],$=0,G=-1;for(;l.pos>L;){let{id:B,start:F,end:z,size:W}=l;if(W>4)l.next();else{if(G>-1&&F<G)break;G<0&&(G=z-i),q.push(B,F,z),$++,l.next()}}if($){let B=new Uint16Array($*4),F=q[q.length-2];for(let z=q.length-3,W=0;z>=0;z-=3)B[W++]=q[z],B[W++]=q[z+1]-F,B[W++]=q[z+2]-F,B[W++]=W;O.push(new Eh(B,q[2]-F,s)),X.push(F-E)}}function x(E,L){return(O,X,q)=>{let $=0,G=O.length-1,B,F;if(G>=0&&(B=O[G])instanceof is){if(!G&&B.type==E&&B.length==q)return B;(F=B.prop(an.lookAhead))&&($=X[G]+B.length+F)}return _(E,O,X,q,$,L)}}function b(E,L,O,X,q,$,G,B,F){let z=[],W=[];for(;E.length>X;)z.push(E.pop()),W.push(L.pop()+O-q);E.push(_(s.types[G],z,W,$-q,B-$,F)),L.push(q-O)}function _(E,L,O,X,q,$,G){if($){let B=[an.contextHash,$];G=G?[B].concat(G):[B]}if(q>25){let B=[an.lookAhead,q];G=G?[B].concat(G):[B]}return new is(E,L,O,X,G)}function k(E,L){let O=l.fork(),X=0,q=0,$=0,G=O.end-i,B={size:0,start:0,skip:0};e:for(let F=O.pos-E;O.pos>F;){let z=O.size;if(O.id==L&&z>=0){B.size=X,B.start=q,B.skip=$,$+=4,X+=4,O.next();continue}let W=O.pos-z;if(z<0||W<F||O.start<G)break;let H=O.id>=o?4:0,U=O.start;for(O.next();O.pos>W;){if(O.size<0)if(O.size==-3||O.size==-4)H+=4;else break e;else O.id>=o&&(H+=4);O.next()}q=U,X+=z,$+=H}return(L<0||X==E)&&(B.size=X,B.start=q,B.skip=$),B.size>4?B:void 0}function N(E,L,O){let{id:X,start:q,end:$,size:G}=l;if(l.next(),G>=0&&X<o){let B=O;if(G>4){let F=l.pos-(G-4);for(;l.pos>F;)O=N(E,L,O)}L[--O]=B,L[--O]=$-E,L[--O]=q-E,L[--O]=X}else G==-3?h=X:G==-4&&(f=X);return O}let j=[],M=[];for(;l.pos>0;)m(t.start||0,t.bufferStart||0,j,M,-1,0);let A=(e=t.length)!==null&&e!==void 0?e:j.length?M[0]+j[0].length:0;return new is(u[t.topID],j.reverse(),M.reverse(),A)}const VR=new WeakMap;function rw(t,e){if(!t.isAnonymous||e instanceof Eh||e.type!=t)return 1;let n=VR.get(e);if(n==null){n=1;for(let s of e.children){if(s.type!=t||!(s instanceof is)){n=1;break}n+=rw(t,s)}VR.set(e,n)}return n}function vE(t,e,n,s,i,r,o,l,u){let h=0;for(let b=s;b<i;b++)h+=rw(t,e[b]);let f=Math.ceil(h*1.5/8),m=[],g=[];function x(b,_,k,N,j){for(let M=k;M<N;){let A=M,E=_[M],L=rw(t,b[M]);for(M++;M<N;M++){let O=rw(t,b[M]);if(L+O>=f)break;L+=O}if(M==A+1){if(L>f){let O=b[A];x(O.children,O.positions,0,O.children.length,_[A]+j);continue}m.push(b[A])}else{let O=_[M-1]+b[M-1].length-E;m.push(vE(t,b,_,A,M,E,O,null,u))}g.push(E+j-r)}}return x(e,n,s,i,0),(l||u)(m,g,o)}class g5e{constructor(){this.map=new WeakMap}setBuffer(e,n,s){let i=this.map.get(e);i||this.map.set(e,i=new Map),i.set(n,s)}getBuffer(e,n){let s=this.map.get(e);return s&&s.get(n)}set(e,n){e instanceof Dl?this.setBuffer(e.context.buffer,e.index,n):e instanceof xr&&this.map.set(e.tree,n)}get(e){return e instanceof Dl?this.getBuffer(e.context.buffer,e.index):e instanceof xr?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 Qc{constructor(e,n,s,i,r=!1,o=!1){this.from=e,this.to=n,this.tree=s,this.offset=i,this.open=(r?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,n=[],s=!1){let i=[new Qc(0,e.length,e,0,!1,s)];for(let r of n)r.to>e.length&&i.push(r);return i}static applyChanges(e,n,s=128){if(!n.length)return e;let i=[],r=1,o=e.length?e[0]:null;for(let l=0,u=0,h=0;;l++){let f=l<n.length?n[l]:null,m=f?f.fromA:1e9;if(m-u>=s)for(;o&&o.from<m;){let g=o;if(u>=g.from||m<=g.to||h){let x=Math.max(g.from,u)-h,b=Math.min(g.to,m)-h;g=x>=b?null:new Qc(x,b,g.tree,g.offset+h,l>0,!!f)}if(g&&i.push(g),o.to>m)break;o=r<e.length?e[r++]:null}if(!f)break;u=f.toA,h=f.toA-f.toB}return i}}class gP{startParse(e,n,s){return typeof e=="string"&&(e=new Gle(e)),s=s?s.length?s.map(i=>new jo(i.from,i.to)):[new jo(0,0)]:[new jo(0,e.length)],this.createParse(e,n||[],s)}parse(e,n,s){let i=this.startParse(e,n,s);for(;;){let r=i.advance();if(r)return r}}}class Gle{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 v5e(t){return(e,n,s,i)=>new Xle(e,t,n,s,i)}class KR{constructor(e,n,s,i,r,o){this.parser=e,this.parse=n,this.overlay=s,this.bracketed=i,this.target=r,this.from=o}}function GR(t){if(!t.length||t.some(e=>e.from>=e.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(t))}class Yle{constructor(e,n,s,i,r,o,l,u){this.parser=e,this.predicate=n,this.mounts=s,this.index=i,this.start=r,this.bracketed=o,this.target=l,this.prev=u,this.depth=0,this.ranges=[]}}const Xj=new an({perNode:!0});class Xle{constructor(e,n,s,i,r){this.nest=n,this.input=s,this.fragments=i,this.ranges=r,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}advance(){if(this.baseParse){let s=this.baseParse.advance();if(!s)return null;if(this.baseParse=null,this.baseTree=s,this.startInner(),this.stoppedAt!=null)for(let i of this.inner)i.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let s=this.baseTree;return this.stoppedAt!=null&&(s=new is(s.type,s.children,s.positions,s.length,s.propValues.concat([[Xj,this.stoppedAt]]))),s}let e=this.inner[this.innerDone],n=e.parse.advance();if(n){this.innerDone++;let s=Object.assign(Object.create(null),e.target.props);s[an.mounted.id]=new Nm(n,e.overlay,e.parser,e.bracketed),e.target.props=s}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 Jle(this.fragments),n=null,s=null,i=new l_(new xr(this.baseTree,this.ranges[0].from,0,null),ns.IncludeAnonymous|ns.IgnoreMounts);e:for(let r,o;;){let l=!0,u;if(this.stoppedAt!=null&&i.from>=this.stoppedAt)l=!1;else if(e.hasNode(i)){if(n){let h=n.mounts.find(f=>f.frag.from<=i.from&&f.frag.to>=i.to&&f.mount.overlay);if(h)for(let f of h.mount.overlay){let m=f.from+h.pos,g=f.to+h.pos;m>=i.from&&g<=i.to&&!n.ranges.some(x=>x.from<g&&x.to>m)&&n.ranges.push({from:m,to:g})}}l=!1}else if(s&&(o=Qle(s.ranges,i.from,i.to)))l=o!=2;else if(!i.type.isAnonymous&&(r=this.nest(i,this.input))&&(i.from<i.to||!r.overlay)){i.tree||(Zle(i),n&&n.depth++,s&&s.depth++);let h=e.findMounts(i.from,r.parser);if(typeof r.overlay=="function")n=new Yle(r.parser,r.overlay,h,this.inner.length,i.from,!!r.bracketed,i.tree,n);else{let f=QR(this.ranges,r.overlay||(i.from<i.to?[new jo(i.from,i.to)]:[]));f.length&&GR(f),(f.length||!r.overlay)&&this.inner.push(new KR(r.parser,f.length?r.parser.startParse(this.input,ZR(h,f),f):r.parser.startParse(""),r.overlay?r.overlay.map(m=>new jo(m.from-i.from,m.to-i.from)):null,!!r.bracketed,i.tree,f.length?f[0].from:i.from)),r.overlay?f.length&&(s={ranges:f,depth:0,prev:s}):l=!1}}else if(n&&(u=n.predicate(i))&&(u===!0&&(u=new jo(i.from,i.to)),u.from<u.to)){let h=n.ranges.length-1;h>=0&&n.ranges[h].to==u.from?n.ranges[h]={from:n.ranges[h].from,to:u.to}:n.ranges.push(u)}if(l&&i.firstChild())n&&n.depth++,s&&s.depth++;else for(;!i.nextSibling();){if(!i.parent())break e;if(n&&!--n.depth){let h=QR(this.ranges,n.ranges);h.length&&(GR(h),this.inner.splice(n.index,0,new KR(n.parser,n.parser.startParse(this.input,ZR(n.mounts,h),h),n.ranges.map(f=>new jo(f.from-n.start,f.to-n.start)),n.bracketed,n.target,h[0].from))),n=n.prev}s&&!--s.depth&&(s=s.prev)}}}}function Qle(t,e,n){for(let s of t){if(s.from>=n)break;if(s.to>e)return s.from<=e&&s.to>=n?2:1}return 0}function YR(t,e,n,s,i,r){if(e<n){let o=t.buffer[e+1];s.push(t.slice(e,n,o)),i.push(o-r)}}function Zle(t){let{node:e}=t,n=[],s=e.context.buffer;do n.push(t.index),t.parent();while(!t.tree);let i=t.tree,r=i.children.indexOf(s),o=i.children[r],l=o.buffer,u=[r];function h(f,m,g,x,b,_){let k=n[_],N=[],j=[];YR(o,f,k,N,j,x);let M=l[k+1],A=l[k+2];u.push(N.length);let E=_?h(k+4,l[k+3],o.set.types[l[k]],M,A-M,_-1):e.toTree();return N.push(E),j.push(M-x),YR(o,l[k+3],m,N,j,x),new is(g,N,j,b)}i.children[r]=h(0,l.length,Fr.none,0,o.length,n.length-1);for(let f of u){let m=t.tree.children[f],g=t.tree.positions[f];t.yield(new xr(m,g+t.from,f,t._tree))}}class XR{constructor(e,n){this.offset=n,this.done=!1,this.cursor=e.cursor(ns.IncludeAnonymous|ns.IgnoreMounts)}moveTo(e){let{cursor:n}=this,s=e-this.offset;for(;!this.done&&n.from<s;)if(!(n.to>=e&&n.enter(s,1,ns.IgnoreOverlays|ns.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 is)n=n.children[0];else break}return!1}}class Jle{constructor(e){var n;if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let s=this.curFrag=e[0];this.curTo=(n=s.tree.prop(Xj))!==null&&n!==void 0?n:s.to,this.inner=new XR(s.tree,-s.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(Xj))!==null&&e!==void 0?e:n.to,this.inner=new XR(n.tree,-n.offset)}}findMounts(e,n){var s;let i=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let r=this.inner.cursor.node;r;r=r.parent){let o=(s=r.tree)===null||s===void 0?void 0:s.prop(an.mounted);if(o&&o.parser==n)for(let l=this.fragI;l<this.fragments.length;l++){let u=this.fragments[l];if(u.from>=r.to)break;u.tree==this.curFrag.tree&&i.push({frag:u,pos:r.from-u.offset,mount:o})}}}return i}}function QR(t,e){let n=null,s=e;for(let i=1,r=0;i<t.length;i++){let o=t[i-1].to,l=t[i].from;for(;r<s.length;r++){let u=s[r];if(u.from>=l)break;u.to<=o||(n||(s=n=e.slice()),u.from<o?(n[r]=new jo(u.from,o),u.to>l&&n.splice(r+1,0,new jo(l,u.to))):u.to>l?n[r--]=new jo(l,u.to):n.splice(r--,1))}}return s}function ece(t,e,n,s){let i=0,r=0,o=!1,l=!1,u=-1e9,h=[];for(;;){let f=i==t.length?1e9:o?t[i].to:t[i].from,m=r==e.length?1e9:l?e[r].to:e[r].from;if(o!=l){let g=Math.max(u,n),x=Math.min(f,m,s);g<x&&h.push(new jo(g,x))}if(u=Math.min(f,m),u==1e9)break;f==u&&(o?(o=!1,i++):o=!0),m==u&&(l?(l=!1,r++):l=!0)}return h}function ZR(t,e){let n=[];for(let{pos:s,mount:i,frag:r}of t){let o=s+(i.overlay?i.overlay[0].from:0),l=o+i.tree.length,u=Math.max(r.from,o),h=Math.min(r.to,l);if(i.overlay){let f=i.overlay.map(g=>new jo(g.from+s,g.to+s)),m=ece(e,f,u,h);for(let g=0,x=u;;g++){let b=g==m.length,_=b?h:m[g].from;if(_>x&&n.push(new Qc(x,_,i.tree,-o,r.from>=x||r.openStart,r.to<=_||r.openEnd)),b)break;x=m[g].to}}else n.push(new Qc(u,h,i.tree,-o,r.from>=o||r.openStart,r.to<=l||r.openEnd))}return n}let tce=0;class _o{constructor(e,n,s,i){this.name=e,this.set=n,this.base=s,this.modified=i,this.id=tce++}toString(){let{name:e}=this;for(let n of this.modified)n.name&&(e=`${n.name}(${e})`);return e}static define(e,n){let s=typeof e=="string"?e:"?";if(e instanceof _o&&(n=e),n?.base)throw new Error("Can not derive from a modified tag");let i=new _o(s,[],null,[]);if(i.set.push(i),n)for(let r of n.set)i.set.push(r);return i}static defineModifier(e){let n=new c_(e);return s=>s.modified.indexOf(n)>-1?s:c_.get(s.base||s,s.modified.concat(n).sort((i,r)=>i.id-r.id))}}let nce=0;class c_{constructor(e){this.name=e,this.instances=[],this.id=nce++}static get(e,n){if(!n.length)return e;let s=n[0].instances.find(l=>l.base==e&&sce(n,l.modified));if(s)return s;let i=[],r=new _o(e.name,i,e,n);for(let l of n)l.instances.push(r);let o=ice(n);for(let l of e.set)if(!l.modified.length)for(let u of o)i.push(c_.get(l,u));return r}}function sce(t,e){return t.length==e.length&&t.every((n,s)=>n==e[s])}function ice(t){let e=[[]];for(let n=0;n<t.length;n++)for(let s=0,i=e.length;s<i;s++)e.push(e[s].concat(t[n]));return e.sort((n,s)=>s.length-n.length)}function rce(t){let e=Object.create(null);for(let n in t){let s=t[n];Array.isArray(s)||(s=[s]);for(let i of n.split(" "))if(i){let r=[],o=2,l=i;for(let m=0;;){if(l=="..."&&m>0&&m+3==i.length){o=1;break}let g=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!g)throw new RangeError("Invalid path: "+i);if(r.push(g[0]=="*"?"":g[0][0]=='"'?JSON.parse(g[0]):g[0]),m+=g[0].length,m==i.length)break;let x=i[m++];if(m==i.length&&x=="!"){o=0;break}if(x!="/")throw new RangeError("Invalid path: "+i);l=i.slice(m)}let u=r.length-1,h=r[u];if(!h)throw new RangeError("Invalid path: "+i);let f=new Jx(s,o,u>0?r.slice(0,u):null);e[h]=f.sort(e[h])}}return vP.add(e)}const vP=new an({combine(t,e){let n,s,i;for(;t||e;){if(!t||e&&t.depth>=e.depth?(i=e,e=e.next):(i=t,t=t.next),n&&n.mode==i.mode&&!i.context&&!n.context)continue;let r=new Jx(i.tags,i.mode,i.context);n?n.next=r:s=r,n=r}return s}});class Jx{constructor(e,n,s,i){this.tags=e,this.mode=n,this.context=s,this.next=i}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}}Jx.empty=new Jx([],2,null);function xP(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 o of r.tag)n[o.id]=r.class;let{scope:s,all:i=null}=e||{};return{style:r=>{let o=i;for(let l of r)for(let u of l.set){let h=n[u.id];if(h){o=o?o+" "+h:h;break}}return o},scope:s}}function ace(t,e){let n=null;for(let s of t){let i=s.style(e);i&&(n=n?n+" "+i:i)}return n}function oce(t,e,n,s=0,i=t.length){let r=new lce(s,Array.isArray(e)?e:[e],n);r.highlightRange(t.cursor(),s,i,"",r.highlighters),r.flush(i)}class lce{constructor(e,n,s){this.at=e,this.highlighters=n,this.span=s,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,s,i,r){let{type:o,from:l,to:u}=e;if(l>=s||u<=n)return;o.isTop&&(r=this.highlighters.filter(x=>!x.scope||x.scope(o)));let h=i,f=cce(e)||Jx.empty,m=ace(r,f.tags);if(m&&(h&&(h+=" "),h+=m,f.mode==1&&(i+=(i?" ":"")+m)),this.startSpan(Math.max(n,l),h),f.opaque)return;let g=e.tree&&e.tree.prop(an.mounted);if(g&&g.overlay){let x=e.node.enter(g.overlay[0].from+l,1),b=this.highlighters.filter(k=>!k.scope||k.scope(g.tree.type)),_=e.firstChild();for(let k=0,N=l;;k++){let j=k<g.overlay.length?g.overlay[k]:null,M=j?j.from+l:u,A=Math.max(n,N),E=Math.min(s,M);if(A<E&&_)for(;e.from<E&&(this.highlightRange(e,A,E,i,r),this.startSpan(Math.min(E,e.to),h),!(e.to>=M||!e.nextSibling())););if(!j||M>s)break;N=j.to+l,N>n&&(this.highlightRange(x.cursor(),Math.max(n,j.from+l),Math.min(s,N),"",b),this.startSpan(Math.min(s,N),h))}_&&e.parent()}else if(e.firstChild()){g&&(i="");do if(!(e.to<=n)){if(e.from>=s)break;this.highlightRange(e,n,s,i,r),this.startSpan(Math.min(s,e.to),h)}while(e.nextSibling());e.parent()}}}function cce(t){let e=t.type.prop(vP);for(;e&&e.context&&!t.matchContext(e.context);)e=e.next;return e||null}const Ye=_o.define,hb=Ye(),rh=Ye(),JR=Ye(rh),e4=Ye(rh),ah=Ye(),db=Ye(ah),kS=Ye(ah),jl=Ye(),Dd=Ye(jl),wl=Ye(),_l=Ye(),Qj=Ye(),Pv=Ye(Qj),fb=Ye(),Ke={comment:hb,lineComment:Ye(hb),blockComment:Ye(hb),docComment:Ye(hb),name:rh,variableName:Ye(rh),typeName:JR,tagName:Ye(JR),propertyName:e4,attributeName:Ye(e4),className:Ye(rh),labelName:Ye(rh),namespace:Ye(rh),macroName:Ye(rh),literal:ah,string:db,docString:Ye(db),character:Ye(db),attributeValue:Ye(db),number:kS,integer:Ye(kS),float:Ye(kS),bool:Ye(ah),regexp:Ye(ah),escape:Ye(ah),color:Ye(ah),url:Ye(ah),keyword:wl,self:Ye(wl),null:Ye(wl),atom:Ye(wl),unit:Ye(wl),modifier:Ye(wl),operatorKeyword:Ye(wl),controlKeyword:Ye(wl),definitionKeyword:Ye(wl),moduleKeyword:Ye(wl),operator:_l,derefOperator:Ye(_l),arithmeticOperator:Ye(_l),logicOperator:Ye(_l),bitwiseOperator:Ye(_l),compareOperator:Ye(_l),updateOperator:Ye(_l),definitionOperator:Ye(_l),typeOperator:Ye(_l),controlOperator:Ye(_l),punctuation:Qj,separator:Ye(Qj),bracket:Pv,angleBracket:Ye(Pv),squareBracket:Ye(Pv),paren:Ye(Pv),brace:Ye(Pv),content:jl,heading:Dd,heading1:Ye(Dd),heading2:Ye(Dd),heading3:Ye(Dd),heading4:Ye(Dd),heading5:Ye(Dd),heading6:Ye(Dd),contentSeparator:Ye(jl),list:Ye(jl),quote:Ye(jl),emphasis:Ye(jl),strong:Ye(jl),link:Ye(jl),monospace:Ye(jl),strikethrough:Ye(jl),inserted:Ye(),deleted:Ye(),changed:Ye(),invalid:Ye(),meta:fb,documentMeta:Ye(fb),annotation:Ye(fb),processingInstruction:Ye(fb),definition:_o.defineModifier("definition"),constant:_o.defineModifier("constant"),function:_o.defineModifier("function"),standard:_o.defineModifier("standard"),local:_o.defineModifier("local"),special:_o.defineModifier("special")};for(let t in Ke){let e=Ke[t];e instanceof _o&&(e.name=t)}xP([{tag:Ke.link,class:"tok-link"},{tag:Ke.heading,class:"tok-heading"},{tag:Ke.emphasis,class:"tok-emphasis"},{tag:Ke.strong,class:"tok-strong"},{tag:Ke.keyword,class:"tok-keyword"},{tag:Ke.atom,class:"tok-atom"},{tag:Ke.bool,class:"tok-bool"},{tag:Ke.url,class:"tok-url"},{tag:Ke.labelName,class:"tok-labelName"},{tag:Ke.inserted,class:"tok-inserted"},{tag:Ke.deleted,class:"tok-deleted"},{tag:Ke.literal,class:"tok-literal"},{tag:Ke.string,class:"tok-string"},{tag:Ke.number,class:"tok-number"},{tag:[Ke.regexp,Ke.escape,Ke.special(Ke.string)],class:"tok-string2"},{tag:Ke.variableName,class:"tok-variableName"},{tag:Ke.local(Ke.variableName),class:"tok-variableName tok-local"},{tag:Ke.definition(Ke.variableName),class:"tok-variableName tok-definition"},{tag:Ke.special(Ke.variableName),class:"tok-variableName2"},{tag:Ke.definition(Ke.propertyName),class:"tok-propertyName tok-definition"},{tag:Ke.typeName,class:"tok-typeName"},{tag:Ke.namespace,class:"tok-namespace"},{tag:Ke.className,class:"tok-className"},{tag:Ke.macroName,class:"tok-macroName"},{tag:Ke.propertyName,class:"tok-propertyName"},{tag:Ke.operator,class:"tok-operator"},{tag:Ke.comment,class:"tok-comment"},{tag:Ke.meta,class:"tok-meta"},{tag:Ke.invalid,class:"tok-invalid"},{tag:Ke.punctuation,class:"tok-punctuation"}]);var SS;const Jd=new an;function yP(t){return ct.define({combine:t?e=>e.concat(t):void 0})}const uce=new an;class No{constructor(e,n,s=[],i=""){this.data=e,this.name=i,Nn.prototype.hasOwnProperty("tree")||Object.defineProperty(Nn.prototype,"tree",{get(){return Wl(this)}}),this.parser=n,this.extension=[Zm.of(this),Nn.languageData.of((r,o,l)=>{let u=t4(r,o,l),h=u.type.prop(Jd);if(!h)return[];let f=r.facet(h),m=u.type.prop(uce);if(m){let g=u.resolve(o-u.from,l);for(let x of m)if(x.test(g,r)){let b=r.facet(x.facet);return x.type=="replace"?b:b.concat(f)}}return f})].concat(s)}isActiveAt(e,n,s=-1){return t4(e,n,s).type.prop(Jd)==this.data}findRegions(e){let n=e.facet(Zm);if(n?.data==this.data)return[{from:0,to:e.doc.length}];if(!n||!n.allowsNesting)return[];let s=[],i=(r,o)=>{if(r.prop(Jd)==this.data){s.push({from:o,to:o+r.length});return}let l=r.prop(an.mounted);if(l){if(l.tree.prop(Jd)==this.data){if(l.overlay)for(let u of l.overlay)s.push({from:u.from+o,to:u.to+o});else s.push({from:o,to:o+r.length});return}else if(l.overlay){let u=s.length;if(i(l.tree,l.overlay[0].from+o),s.length>u)return}}for(let u=0;u<r.children.length;u++){let h=r.children[u];h instanceof is&&i(h,r.positions[u]+o)}};return i(Wl(e),0),s}get allowsNesting(){return!0}}No.setState=ss.define();function t4(t,e,n){let s=t.facet(Zm),i=Wl(t).topNode;if(!s||s.allowsNesting)for(let r=i;r;r=r.enter(e,n,ns.ExcludeBuffers|ns.EnterBracketed))r.type.isTop&&(i=r);return i}class Zj extends No{constructor(e,n,s){super(e,n,[],s),this.parser=n}static define(e){let n=yP(e.languageData);return new Zj(n,e.parser.configure({props:[Jd.add(s=>s.isTop?n:void 0)]}),e.name)}configure(e,n){return new Zj(this.data,this.parser.configure(e),n||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function Wl(t){let e=t.field(No.state,!1);return e?e.tree:is.empty}class hce{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 s=this.cursorPos-this.string.length;return e<s||n>=this.cursorPos?this.doc.sliceString(e,n):this.string.slice(e-s,n-s)}}let zv=null;class Xm{constructor(e,n,s=[],i,r,o,l,u){this.parser=e,this.state=n,this.fragments=s,this.tree=i,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=u,this.parse=null,this.tempSkipped=[]}static create(e,n,s){return new Xm(e,n,[],is.empty,0,s,[],null)}startParse(){return this.parser.startParse(new hce(this.state.doc),this.fragments)}work(e,n){return n!=null&&n>=this.state.doc.length&&(n=void 0),this.tree!=is.empty&&this.isDone(n??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var s;if(typeof e=="number"){let i=Date.now()+e;e=()=>Date.now()>i}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 i=this.parse.advance();if(i)if(this.fragments=this.withoutTempSkipped(Qc.addTree(i,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(s=this.parse.stoppedAt)!==null&&s!==void 0?s:this.state.doc.length,this.tree=i,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(Qc.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let n=zv;zv=this;try{return e()}finally{zv=n}}withoutTempSkipped(e){for(let n;n=this.tempSkipped.pop();)e=n4(e,n.from,n.to);return e}changes(e,n){let{fragments:s,tree:i,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let u=[];if(e.iterChangedRanges((h,f,m,g)=>u.push({fromA:h,toA:f,fromB:m,toB:g})),s=Qc.applyChanges(s,u),i=is.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let h of this.skipped){let f=e.mapPos(h.from,1),m=e.mapPos(h.to,-1);f<m&&l.push({from:f,to:m})}}}return new Xm(this.parser,n,s,i,r,o,l,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 s=0;s<this.skipped.length;s++){let{from:i,to:r}=this.skipped[s];i<e.to&&r>e.from&&(this.fragments=n4(this.fragments,i,r),this.skipped.splice(s--,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 gP{createParse(n,s,i){let r=i[0].from,o=i[i.length-1].to;return{parsedPos:r,advance(){let u=zv;if(u){for(let h of i)u.tempSkipped.push(h);e&&(u.scheduleOn=u.scheduleOn?Promise.all([u.scheduleOn,e]):e)}return this.parsedPos=o,new is(Fr.none,[],[],o-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 zv}}function n4(t,e,n){return Qc.applyChanges(t,[{fromA:e,toA:n,fromB:e,toB:n}])}class Qm{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),s=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),n.viewport.to);return n.work(20,s)||n.takeTree(),new Qm(n)}static init(e){let n=Math.min(3e3,e.doc.length),s=Xm.create(e.facet(Zm).parser,e,{from:0,to:n});return s.work(20,n)||s.takeTree(),new Qm(s)}}No.state=Kl.define({create:Qm.init,update(t,e){for(let n of e.effects)if(n.is(No.setState))return n.value;return e.startState.facet(Zm)!=e.state.facet(Zm)?Qm.init(e.state):t.apply(e)}});let bP=t=>{let e=setTimeout(()=>t(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(bP=t=>{let e=-1,n=setTimeout(()=>{e=requestIdleCallback(t,{timeout:400})},100);return()=>e<0?clearTimeout(n):cancelIdleCallback(e)});const CS=typeof navigator<"u"&&(!((SS=navigator.scheduling)===null||SS===void 0)&&SS.isInputPending)?()=>navigator.scheduling.isInputPending():null,dce=Pr.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(No.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(No.state);(n.tree!=n.context.tree||!n.context.isDone(e.doc.length))&&(this.working=bP(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:s,viewport:{to:i}}=this.view,r=s.field(No.state);if(r.tree==r.context.tree&&r.context.isDone(i+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!CS?Math.max(25,e.timeRemaining()-5):1e9),l=r.context.treeLen<i&&s.doc.length>i+1e3,u=r.context.work(()=>CS&&CS()||Date.now()>o,i+(l?0:1e5));this.chunkBudget-=Date.now()-n,(u||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:No.setState.of(new Qm(r.context))})),this.chunkBudget>0&&!(u&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(n=>Rl(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()}}}),Zm=ct.define({combine(t){return t.length?t[0]:null},enables:t=>[No.state,dce,pt.contentAttributes.compute([t],e=>{let n=e.facet(t);return n&&n.name?{"data-language":n.name}:{}})]});class y5e{constructor(e,n=[]){this.language=e,this.support=n,this.extension=[e,n]}}class wP{constructor(e,n,s,i,r,o=void 0){this.name=e,this.alias=n,this.extensions=s,this.filename=i,this.loadFunc=r,this.support=o,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:s}=e;if(!n){if(!s)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");n=()=>Promise.resolve(s)}return new wP(e.name,(e.alias||[]).concat(e.name).map(i=>i.toLowerCase()),e.extensions||[],e.filename,n,s)}static matchFilename(e,n){for(let i of e)if(i.filename&&i.filename.test(n))return i;let s=/\.([^.]+)$/.exec(n);if(s){for(let i of e)if(i.extensions.indexOf(s[1])>-1)return i}return null}static matchLanguageName(e,n,s=!0){n=n.toLowerCase();for(let i of e)if(i.alias.some(r=>r==n))return i;if(s)for(let i of e)for(let r of i.alias){let o=n.indexOf(r);if(o>-1&&(r.length>2||!/\w/.test(n[o-1])&&!/\w/.test(n[o+r.length])))return i}return null}}const fce=ct.define(),c1=ct.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 _f(t){let e=t.facet(c1);return e.charCodeAt(0)==9?t.tabSize*e.length:e.length}function e0(t,e){let n="",s=t.tabSize,i=t.facet(c1)[0];if(i==" "){for(;e>=s;)n+=" ",e-=s;i=" "}for(let r=0;r<e;r++)n+=i;return n}function xE(t,e){t instanceof Nn&&(t=new u1(t));for(let s of t.state.facet(fce)){let i=s(t,e);if(i!==void 0)return i}let n=Wl(t.state);return n.length>=e?pce(t,n,e):null}class u1{constructor(e,n={}){this.state=e,this.options=n,this.unit=_f(e)}lineAt(e,n=1){let s=this.state.doc.lineAt(e),{simulateBreak:i,simulateDoubleBreak:r}=this.options;return i!=null&&i>=s.from&&i<=s.to?r&&i==e?{text:"",from:e}:(n<0?i<e:i<=e)?{text:s.text.slice(i-s.from),from:i}:{text:s.text.slice(0,i-s.from),from:s.from}:s}textAfterPos(e,n=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:s,from:i}=this.lineAt(e,n);return s.slice(e-i,Math.min(s.length,e+100-i))}column(e,n=1){let{text:s,from:i}=this.lineAt(e,n),r=this.countColumn(s,e-i),o=this.options.overrideIndentation?this.options.overrideIndentation(i):-1;return o>-1&&(r+=o-this.countColumn(s,s.search(/\S|$/))),r}countColumn(e,n=e.length){return dg(e,this.state.tabSize,n)}lineIndent(e,n=1){let{text:s,from:i}=this.lineAt(e,n),r=this.options.overrideIndentation;if(r){let o=r(i);if(o>-1)return o}return this.countColumn(s,s.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const _P=new an;function pce(t,e,n){let s=e.resolveStack(n),i=e.resolveInner(n,-1).resolve(n,0).enterUnfinishedNodesBefore(n);if(i!=s.node){let r=[];for(let o=i;o&&!(o.from<s.node.from||o.to>s.node.to||o.from==s.node.from&&o.type==s.node.type);o=o.parent)r.push(o);for(let o=r.length-1;o>=0;o--)s={node:r[o],next:s}}return kP(s,t,n)}function kP(t,e,n){for(let s=t;s;s=s.next){let i=gce(s.node);if(i)return i(yE.create(e,n,s))}return 0}function mce(t){return t.pos==t.options.simulateBreak&&t.options.simulateDoubleBreak}function gce(t){let e=t.type.prop(_P);if(e)return e;let n=t.firstChild,s;if(n&&(s=n.type.prop(an.closedBy))){let i=t.lastChild,r=i&&s.indexOf(i.name)>-1;return o=>SP(o,!0,1,void 0,r&&!mce(o)?i.from:void 0)}return t.parent==null?vce:null}function vce(){return 0}class yE extends u1{constructor(e,n,s){super(e.state,e.options),this.base=e,this.pos=n,this.context=s}get node(){return this.context.node}static create(e,n,s){return new yE(e,n,s)}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 s=e.resolve(n.from);for(;s.parent&&s.parent.from==s.from;)s=s.parent;if(xce(s,e))break;n=this.state.doc.lineAt(s.from)}return this.lineIndent(n.from)}continue(){return kP(this.context.next,this.base,this.pos)}}function xce(t,e){for(let n=e;n;n=n.parent)if(t==n)return!0;return!1}function yce(t){let e=t.node,n=e.childAfter(e.from),s=e.lastChild;if(!n)return null;let i=t.options.simulateBreak,r=t.state.doc.lineAt(n.from),o=i==null||i<=r.from?r.to:Math.min(r.to,i);for(let l=n.to;;){let u=e.childAfter(l);if(!u||u==s)return null;if(!u.type.isSkipped){if(u.from>=o)return null;let h=/^ */.exec(r.text.slice(n.to-r.from))[0].length;return{from:n.from,to:n.to+h}}l=u.to}}function b5e({closing:t,align:e=!0,units:n=1}){return s=>SP(s,e,n,t)}function SP(t,e,n,s,i){let r=t.textAfter,o=r.match(/^\s*/)[0].length,l=s&&r.slice(o,o+s.length)==s||i==t.pos+o,u=e?yce(t):null;return u?l?t.column(u.from):t.column(u.to):t.baseIndent+(l?0:t.unit*n)}const w5e=t=>t.baseIndent;function _5e({except:t,units:e=1}={}){return n=>{let s=t&&t.test(n.textAfter);return n.baseIndent+(s?0:e*n.unit)}}const bce=200;function wce(){return Nn.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:s}=t.newSelection.main,i=n.lineAt(s);if(s>i.from+bce)return t;let r=n.sliceString(i.from,s);if(!e.some(h=>h.test(r)))return t;let{state:o}=t,l=-1,u=[];for(let{head:h}of o.selection.ranges){let f=o.doc.lineAt(h);if(f.from==l)continue;l=f.from;let m=xE(o,f.from);if(m==null)continue;let g=/^\s*/.exec(f.text)[0],x=e0(o,m);g!=x&&u.push({from:f.from,to:f.from+g.length,insert:x})}return u.length?[t,{changes:u,sequential:!0}]:t})}const k5e=ct.define(),S5e=new an;function C5e(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 h1{constructor(e,n){this.specs=e;let s;function i(l){let u=Ch.newName();return(s||(s=Object.create(null)))["."+u]=l,u}const r=typeof n.all=="string"?n.all:n.all?i(n.all):void 0,o=n.scope;this.scope=o instanceof No?l=>l.prop(Jd)==o.data:o?l=>l==o:void 0,this.style=xP(e.map(l=>({tag:l.tag,class:l.class||i(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=s?new Ch(s):null,this.themeType=n.themeType}static define(e,n){return new h1(e,n||{})}}const Jj=ct.define(),_ce=ct.define({combine(t){return t.length?[t[0]]:null}});function jS(t){let e=t.facet(Jj);return e.length?e:t.facet(_ce)}function kce(t,e){let n=[Cce],s;return t instanceof h1&&(t.module&&n.push(pt.styleModule.of(t.module)),s=t.themeType),s?n.push(Jj.computeN([pt.darkTheme],i=>i.facet(pt.darkTheme)==(s=="dark")?[t]:[])):n.push(Jj.of(t)),n}class Sce{constructor(e){this.markCache=Object.create(null),this.tree=Wl(e.state),this.decorations=this.buildDeco(e,jS(e.state)),this.decoratedTo=e.viewport.to}update(e){let n=Wl(e.state),s=jS(e.state),i=s!=jS(e.startState),{viewport:r}=e.view,o=e.changes.mapPos(this.decoratedTo,1);n.length<r.to&&!i&&n.type==this.tree.type&&o>=r.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(n!=this.tree||e.viewportChanged||i)&&(this.tree=n,this.decorations=this.buildDeco(e.view,s),this.decoratedTo=r.to)}buildDeco(e,n){if(!n||!this.tree.length)return sn.none;let s=new xf;for(let{from:i,to:r}of e.visibleRanges)oce(this.tree,n,(o,l,u)=>{s.add(o,l,this.markCache[u]||(this.markCache[u]=sn.mark({class:u})))},i,r);return s.finish()}}const Cce=S0.high(Pr.fromClass(Sce,{decorations:t=>t.decorations})),jce=pt.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),CP=1e4,jP="()[]{}",NP=ct.define({combine(t){return Mf(t,{afterCursor:!0,brackets:jP,maxScanDistance:CP,renderMatch:Ece})}}),Nce=sn.mark({class:"cm-matchingBracket"}),Ace=sn.mark({class:"cm-nonmatchingBracket"});function Ece(t){let e=[],n=t.matched?Nce:Ace;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 s4(t){let e=[],n=t.facet(NP);for(let s of t.selection.ranges){if(!s.empty)continue;let i=Ol(t,s.head,-1,n)||s.head>0&&Ol(t,s.head-1,1,n)||n.afterCursor&&(Ol(t,s.head,1,n)||s.head<t.doc.length&&Ol(t,s.head+1,-1,n));i&&(e=e.concat(n.renderMatch(i,t)))}return sn.set(e,!0)}const Mce=Pr.fromClass(class{constructor(t){this.paused=!1,this.decorations=s4(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=s4(t.state),this.paused=!1))}},{decorations:t=>t.decorations}),Lce=[Mce,jce];function Tce(t={}){return[NP.of(t),Lce]}const Rce=new an;function e2(t,e,n){let s=t.prop(e<0?an.openedBy:an.closedBy);if(s)return s;if(t.name.length==1){let i=n.indexOf(t.name);if(i>-1&&i%2==(e<0?1:0))return[n[i+e]]}return null}function t2(t){let e=t.type.prop(Rce);return e?e(t.node):t}function Ol(t,e,n,s={}){let i=s.maxScanDistance||CP,r=s.brackets||jP,o=Wl(t),l=o.resolveInner(e,n);for(let u=l;u;u=u.parent){let h=e2(u.type,n,r);if(h&&u.from<u.to){let f=t2(u);if(f&&(n>0?e>=f.from&&e<f.to:e>f.from&&e<=f.to))return Dce(t,e,n,u,f,h,r)}}return Oce(t,e,n,o,l.type,i,r)}function Dce(t,e,n,s,i,r,o){let l=s.parent,u={from:i.from,to:i.to},h=0,f=l?.cursor();if(f&&(n<0?f.childBefore(s.from):f.childAfter(s.to)))do if(n<0?f.to<=s.from:f.from>=s.to){if(h==0&&r.indexOf(f.type.name)>-1&&f.from<f.to){let m=t2(f);return{start:u,end:m?{from:m.from,to:m.to}:void 0,matched:!0}}else if(e2(f.type,n,o))h++;else if(e2(f.type,-n,o)){if(h==0){let m=t2(f);return{start:u,end:m&&m.from<m.to?{from:m.from,to:m.to}:void 0,matched:!1}}h--}}while(n<0?f.prevSibling():f.nextSibling());return{start:u,matched:!1}}function Oce(t,e,n,s,i,r,o){if(n<0?!e:e==t.doc.length)return null;let l=n<0?t.sliceDoc(e-1,e):t.sliceDoc(e,e+1),u=o.indexOf(l);if(u<0||u%2==0!=n>0)return null;let h={from:n<0?e-1:e,to:n>0?e+1:e},f=t.doc.iterRange(e,n>0?t.doc.length:0),m=0;for(let g=0;!f.next().done&&g<=r;){let x=f.value;n<0&&(g+=x.length);let b=e+g*n;for(let _=n>0?0:x.length-1,k=n>0?x.length:-1;_!=k;_+=n){let N=o.indexOf(x[_]);if(!(N<0||s.resolveInner(b+_,1).type!=i))if(N%2==0==n>0)m++;else{if(m==1)return{start:h,end:{from:b+_,to:b+_+1},matched:N>>1==u>>1};m--}}n>0&&(g+=x.length)}return f.done?{start:h,matched:!1}:null}function i4(t,e,n,s=0,i=0){e==null&&(e=t.search(/[^\s\u00a0]/),e==-1&&(e=t.length));let r=i;for(let o=s;o<e;o++)t.charCodeAt(o)==9?r+=n-r%n:r++;return r}class AP{constructor(e,n,s,i){this.string=e,this.tabSize=n,this.indentUnit=s,this.overrideIndent=i,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),s;if(typeof e=="string"?s=n==e:s=n&&(e instanceof RegExp?e.test(n):e(n)),s)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=i4(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:i4(this.string,null,this.tabSize)}match(e,n,s){if(typeof e=="string"){let i=o=>s?o.toLowerCase():o,r=this.string.substr(this.pos,e.length);return i(r)==i(e)?(n!==!1&&(this.pos+=e.length),!0):null}else{let i=this.string.slice(this.pos).match(e);return i&&i.index>0?null:(i&&n!==!1&&(this.pos+=i[0].length),i)}}current(){return this.string.slice(this.start,this.pos)}}function Ice(t){return{name:t.name||"",token:t.token,blankLine:t.blankLine||(()=>{}),startState:t.startState||(()=>!0),copyState:t.copyState||Bce,indent:t.indent||(()=>null),languageData:t.languageData||{},tokenTable:t.tokenTable||_E,mergeTokens:t.mergeTokens!==!1}}function Bce(t){if(typeof t!="object")return t;let e={};for(let n in t){let s=t[n];e[n]=s instanceof Array?s.slice():s}return e}const r4=new WeakMap;class bE extends No{constructor(e){let n=yP(e.languageData),s=Ice(e),i,r=new class extends gP{createParse(o,l,u){return new Pce(i,o,l,u)}};super(n,r,[],e.name),this.topNode=Hce(n,this),i=this,this.streamParser=s,this.stateAfter=new an({perNode:!0}),this.tokenTable=e.tokenTable?new TP(s.tokenTable):Fce}static define(e){return new bE(e)}getIndent(e){let n,{overrideIndentation:s}=e.options;s&&(n=r4.get(e.state),n!=null&&n<e.pos-1e4&&(n=void 0));let i=wE(this,e.node.tree,e.node.from,e.node.from,n??e.pos),r,o;if(i?(o=i.state,r=i.pos+1):(o=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),h=Math.min(e.pos,u.to);if(u.length){let f=s?s(u.from):-1,m=new AP(u.text,e.state.tabSize,e.unit,f<0?void 0:f);for(;m.pos<h-u.from;)MP(this.streamParser.token,m,o)}else this.streamParser.blankLine(o,e.unit);if(h==e.pos)break;r=u.to+1}let l=e.lineAt(e.pos);return s&&n==null&&r4.set(e.state,l.from),this.streamParser.indent(o,/^\s*(.*)/.exec(l.text)[1],e)}get allowsNesting(){return!1}}function wE(t,e,n,s,i){let r=n>=s&&n+e.length<=i&&e.prop(t.stateAfter);if(r)return{state:t.streamParser.copyState(r),pos:n+e.length};for(let o=e.children.length-1;o>=0;o--){let l=e.children[o],u=n+e.positions[o],h=l instanceof is&&u<i&&wE(t,l,u,s,i);if(h)return h}return null}function EP(t,e,n,s,i){if(i&&n<=0&&s>=e.length)return e;!i&&n==0&&e.type==t.topNode&&(i=!0);for(let r=e.children.length-1;r>=0;r--){let o=e.positions[r],l=e.children[r],u;if(o<s&&l instanceof is){if(!(u=EP(t,l,n-o,s-o,i)))break;return i?new is(e.type,e.children.slice(0,r).concat(u),e.positions.slice(0,r+1),o+u.length):u}}return null}function $ce(t,e,n,s,i){for(let r of e){let o=r.from+(r.openStart?25:0),l=r.to-(r.openEnd?25:0),u=o<=n&&l>n&&wE(t,r.tree,0-r.offset,n,l),h;if(u&&u.pos<=s&&(h=EP(t,r.tree,n+r.offset,u.pos+r.offset,!1)))return{state:u.state,tree:h}}return{state:t.streamParser.startState(i?_f(i):4),tree:is.empty}}class Pce{constructor(e,n,s,i){this.lang=e,this.input=n,this.fragments=s,this.ranges=i,this.stoppedAt=null,this.chunks=[],this.chunkPos=[],this.chunk=[],this.chunkReused=void 0,this.rangeIndex=0,this.to=i[i.length-1].to;let r=Xm.get(),o=i[0].from,{state:l,tree:u}=$ce(e,s,o,this.to,r?.state);this.state=l,this.parsedPos=this.chunkStart=o+u.length;for(let h=0;h<u.children.length;h++)this.chunks.push(u.children[h]),this.chunkPos.push(u.positions[h]);r&&this.parsedPos<r.viewport.from-1e5&&i.some(h=>h.from<=r.viewport.from&&h.to>=r.viewport.from)&&(this.state=this.lang.streamParser.startState(_f(r.state)),r.skipUntilInView(this.parsedPos,r.viewport.from),this.parsedPos=r.viewport.from),this.moveRangeIndex()}advance(){let e=Xm.get(),n=this.stoppedAt==null?this.to:Math.min(this.to,this.stoppedAt),s=Math.min(n,this.chunkStart+512);for(e&&(s=Math.min(s,e.viewport.to));this.parsedPos<s;)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==`
82
82
  `&&(n="");else{let s=n.indexOf(`
83
83
  `);s>-1&&(n=n.slice(0,s))}return e+n.length<=this.to?n:n.slice(0,this.to-e)}nextLine(){let e=this.parsedPos,n=this.lineAfter(e),s=e+n.length;for(let i=this.rangeIndex;;){let r=this.ranges[i].to;if(r>=s||(n=n.slice(0,r-(s-n.length)),i++,i==this.ranges.length))break;let o=this.ranges[i].from,l=this.lineAfter(o);n+=l,s=o+l.length}return{line:n,end:s}}skipGapsTo(e,n,s){for(;;){let i=this.ranges[this.rangeIndex].to,r=e+n;if(s>0?i>r:i>=r)break;let o=this.ranges[++this.rangeIndex].from;n+=o-i}return n}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(e,n,s,i){let r=4;if(this.ranges.length>1){i=this.skipGapsTo(n,i,1),n+=i;let l=this.chunk.length;i=this.skipGapsTo(s,i,-1),s+=i,r+=this.chunk.length-l}let o=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&r==4&&o>=0&&this.chunk[o]==e&&this.chunk[o+2]==n?this.chunk[o+2]=s:this.chunk.push(e,n,s,r),i}parseLine(e){let{line:n,end:s}=this.nextLine(),i=0,{streamParser:r}=this.lang,o=new AP(n,e?e.state.tabSize:4,e?_f(e.state):2);if(o.eol())r.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=MP(r.token,o,this.state);if(l&&(i=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,i)),o.start>1e4)break}this.parsedPos=s,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let e=is.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:zce,topID:0,maxBufferLength:512,reused:this.chunkReused});e=new is(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 is(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function MP(t,e,n){e.start=e.pos;for(let s=0;s<10;s++){let i=t(e,n);if(e.pos>e.start)return i}throw new Error("Stream parser failed to advance stream.")}const _E=Object.create(null),t0=[Fr.none],zce=new pE(t0),a4=[],o4=Object.create(null),LP=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"]])LP[t]=RP(_E,e);class TP{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),LP)}resolve(e){return e?this.table[e]||(this.table[e]=RP(this.extra,e)):0}}const Fce=new TP(_E);function NS(t,e){a4.indexOf(t)>-1||(a4.push(t),console.warn(e))}function RP(t,e){let n=[];for(let l of e.split(" ")){let u=[];for(let h of l.split(".")){let f=t[h]||Ke[h];f?typeof f=="function"?u.length?u=u.map(f):NS(h,`Modifier ${h} used at start of tag`):u.length?NS(h,`Tag ${h} used as modifier`):u=Array.isArray(f)?f:[f]:NS(h,`Unknown highlighting tag ${h}`)}for(let h of u)n.push(h)}if(!n.length)return 0;let s=e.replace(/ /g,"_"),i=s+" "+n.map(l=>l.id),r=o4[i];if(r)return r.id;let o=o4[i]=Fr.define({id:t0.length,name:s,props:[rce({[s]:n})]});return t0.push(o),o.id}function Hce(t,e){let n=Fr.define({id:t0.length,name:"Document",props:[Jd.add(()=>t),_P.add(()=>s=>e.getIndent(s))],top:!0});return t0.push(n),n}Ss.RTL,Ss.LTR;const Wce=t=>{let{state:e}=t,n=e.doc.lineAt(e.selection.main.from),s=SE(t.state,n.from);return s.line?qce(t):s.block?Vce(t):!1};function kE(t,e){return({state:n,dispatch:s})=>{if(n.readOnly)return!1;let i=t(e,n);return i?(s(n.update(i)),!0):!1}}const qce=kE(Yce,0),Uce=kE(DP,0),Vce=kE((t,e)=>DP(t,e,Gce(e)),0);function SE(t,e){let n=t.languageDataAt("commentTokens",e,1);return n.length?n[0]:{}}const Fv=50;function Kce(t,{open:e,close:n},s,i){let r=t.sliceDoc(s-Fv,s),o=t.sliceDoc(i,i+Fv),l=/\s*$/.exec(r)[0].length,u=/^\s*/.exec(o)[0].length,h=r.length-l;if(r.slice(h-e.length,h)==e&&o.slice(u,u+n.length)==n)return{open:{pos:s-l,margin:l&&1},close:{pos:i+u,margin:u&&1}};let f,m;i-s<=2*Fv?f=m=t.sliceDoc(s,i):(f=t.sliceDoc(s,s+Fv),m=t.sliceDoc(i-Fv,i));let g=/^\s*/.exec(f)[0].length,x=/\s*$/.exec(m)[0].length,b=m.length-x-n.length;return f.slice(g,g+e.length)==e&&m.slice(b,b+n.length)==n?{open:{pos:s+g+e.length,margin:/\s/.test(f.charAt(g+e.length))?1:0},close:{pos:i-x-n.length,margin:/\s/.test(m.charAt(b-1))?1:0}}:null}function Gce(t){let e=[];for(let n of t.selection.ranges){let s=t.doc.lineAt(n.from),i=n.to<=s.to?s:t.doc.lineAt(n.to);i.from>s.from&&i.from==n.to&&(i=n.to==s.to+1?s:t.doc.lineAt(n.to-1));let r=e.length-1;r>=0&&e[r].to>s.from?e[r].to=i.to:e.push({from:s.from+/^\s*/.exec(s.text)[0].length,to:i.to})}return e}function DP(t,e,n=e.selection.ranges){let s=n.map(r=>SE(e,r.from).block);if(!s.every(r=>r))return null;let i=n.map((r,o)=>Kce(e,s[o],r.from,r.to));if(t!=2&&!i.every(r=>r))return{changes:e.changes(n.map((r,o)=>i[o]?[]:[{from:r.from,insert:s[o].open+" "},{from:r.to,insert:" "+s[o].close}]))};if(t!=1&&i.some(r=>r)){let r=[];for(let o=0,l;o<i.length;o++)if(l=i[o]){let u=s[o],{open:h,close:f}=l;r.push({from:h.pos-u.open.length,to:h.pos+h.margin},{from:f.pos-f.margin,to:f.pos+u.close.length})}return{changes:r}}return null}function Yce(t,e,n=e.selection.ranges){let s=[],i=-1;e:for(let{from:r,to:o}of n){let l=s.length,u=1e9,h;for(let f=r;f<=o;){let m=e.doc.lineAt(f);if(h==null&&(h=SE(e,m.from).line,!h))continue e;if(m.from>i&&(r==o||o>m.from)){i=m.from;let g=/^\s*/.exec(m.text)[0].length,x=g==m.length,b=m.text.slice(g,g+h.length)==h?g:-1;g<m.text.length&&g<u&&(u=g),s.push({line:m,comment:b,token:h,indent:g,empty:x,single:!1})}f=m.to+1}if(u<1e9)for(let f=l;f<s.length;f++)s[f].indent<s[f].line.text.length&&(s[f].indent=u);s.length==l+1&&(s[l].single=!0)}if(t!=2&&s.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:u,indent:h,empty:f,single:m}of s)(m||!f)&&r.push({from:l.from+h,insert:u+" "});let o=e.changes(r);return{changes:o,selection:e.selection.map(o,1)}}else if(t!=1&&s.some(r=>r.comment>=0)){let r=[];for(let{line:o,comment:l,token:u}of s)if(l>=0){let h=o.from+l,f=h+u.length;o.text[f-o.from]==" "&&f++,r.push({from:h,to:f})}return{changes:r}}return null}const n2=Oh.define(),Xce=Oh.define(),Qce=ct.define(),OP=ct.define({combine(t){return Mf(t,{minDepth:100,newGroupDelay:500,joinToEvent:(e,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,n)=>(s,i)=>e(s,i)||n(s,i)})}}),IP=Kl.define({create(){return Il.empty},update(t,e){let n=e.state.facet(OP),s=e.annotation(n2);if(s){let u=la.fromTransaction(e,s.selection),h=s.side,f=h==0?t.undone:t.done;return u?f=u_(f,f.length,n.minDepth,u):f=PP(f,e.startState.selection),new Il(h==0?s.rest:f,h==0?f:s.rest)}let i=e.annotation(Xce);if((i=="full"||i=="before")&&(t=t.isolate()),e.annotation(wi.addToHistory)===!1)return e.changes.empty?t:t.addMapping(e.changes.desc);let r=la.fromTransaction(e),o=e.annotation(wi.time),l=e.annotation(wi.userEvent);return r?t=t.addChanges(r,o,l,n,e):e.selection&&(t=t.addSelection(e.startState.selection,o,l,n.newGroupDelay)),(i=="full"||i=="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 Il(t.done.map(la.fromJSON),t.undone.map(la.fromJSON))}});function Zce(t={}){return[IP,OP.of(t),pt.domEventHandlers({beforeinput(e,n){let s=e.inputType=="historyUndo"?BP:e.inputType=="historyRedo"?s2:null;return s?(e.preventDefault(),s(n)):!1}})]}function d1(t,e){return function({state:n,dispatch:s}){if(!e&&n.readOnly)return!1;let i=n.field(IP,!1);if(!i)return!1;let r=i.pop(t,n,e);return r?(s(r),!0):!1}}const BP=d1(0,!1),s2=d1(1,!1),Jce=d1(0,!0),eue=d1(1,!0);class la{constructor(e,n,s,i,r){this.changes=e,this.effects=n,this.mapped=s,this.startSelection=i,this.selectionsAfter=r}setSelAfter(e){return new la(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,n,s;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:(s=this.startSelection)===null||s===void 0?void 0:s.toJSON(),selectionsAfter:this.selectionsAfter.map(i=>i.toJSON())}}static fromJSON(e){return new la(e.changes&&bi.fromJSON(e.changes),[],e.mapped&&Pl.fromJSON(e.mapped),e.startSelection&&De.fromJSON(e.startSelection),e.selectionsAfter.map(De.fromJSON))}static fromTransaction(e,n){let s=Ao;for(let i of e.startState.facet(Qce)){let r=i(e);r.length&&(s=s.concat(r))}return!s.length&&e.changes.empty?null:new la(e.changes.invert(e.startState.doc),s,void 0,n||e.startState.selection,Ao)}static selection(e){return new la(void 0,Ao,void 0,void 0,e)}}function u_(t,e,n,s){let i=e+1>n+20?e-n-1:0,r=t.slice(i,e);return r.push(s),r}function tue(t,e){let n=[],s=!1;return t.iterChangedRanges((i,r)=>n.push(i,r)),e.iterChangedRanges((i,r,o,l)=>{for(let u=0;u<n.length;){let h=n[u++],f=n[u++];l>=h&&o<=f&&(s=!0)}}),s}function nue(t,e){return t.ranges.length==e.ranges.length&&t.ranges.filter((n,s)=>n.empty!=e.ranges[s].empty).length===0}function $P(t,e){return t.length?e.length?t.concat(e):t:e}const Ao=[],sue=200;function PP(t,e){if(t.length){let n=t[t.length-1],s=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-sue));return s.length&&s[s.length-1].eq(e)?t:(s.push(e),u_(t,t.length-1,1e9,n.setSelAfter(s)))}else return[la.selection([e])]}function iue(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 AS(t,e){if(!t.length)return t;let n=t.length,s=Ao;for(;n;){let i=rue(t[n-1],e,s);if(i.changes&&!i.changes.empty||i.effects.length){let r=t.slice(0,n);return r[n-1]=i,r}else e=i.mapped,n--,s=i.selectionsAfter}return s.length?[la.selection(s)]:Ao}function rue(t,e,n){let s=$P(t.selectionsAfter.length?t.selectionsAfter.map(l=>l.map(e)):Ao,n);if(!t.changes)return la.selection(s);let i=t.changes.map(e),r=e.mapDesc(t.changes,!0),o=t.mapped?t.mapped.composeDesc(r):r;return new la(i,ss.mapEffects(t.effects,e),o,t.startSelection.map(r),s)}const aue=/^(input\.type|delete)($|\.)/;class Il{constructor(e,n,s=0,i=void 0){this.done=e,this.undone=n,this.prevTime=s,this.prevUserEvent=i}isolate(){return this.prevTime?new Il(this.done,this.undone):this}addChanges(e,n,s,i,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!s||aue.test(s))&&(!l.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(r,tue(l.changes,e.changes))||s=="input.type.compose")?o=u_(o,o.length-1,i.minDepth,new la(e.changes.compose(l.changes),$P(ss.mapEffects(e.effects,l.changes),l.effects),l.mapped,l.startSelection,Ao)):o=u_(o,o.length,i.minDepth,e),new Il(o,Ao,n,s)}addSelection(e,n,s,i){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:Ao;return r.length>0&&n-this.prevTime<i&&s==this.prevUserEvent&&s&&/^select($|\.)/.test(s)&&nue(r[r.length-1],e)?this:new Il(PP(this.done,e),this.undone,n,s)}addMapping(e){return new Il(AS(this.done,e),AS(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,n,s){let i=e==0?this.done:this.undone;if(i.length==0)return null;let r=i[i.length-1],o=r.selectionsAfter[0]||(r.startSelection?r.startSelection.map(r.changes.invertedDesc,1):n.selection);if(s&&r.selectionsAfter.length)return n.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:n2.of({side:e,rest:iue(i),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let l=i.length==1?Ao:i.slice(0,i.length-1);return r.mapped&&(l=AS(l,r.mapped)),n.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:n2.of({side:e,rest:l,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}Il.empty=new Il(Ao,Ao);const oue=[{key:"Mod-z",run:BP,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:s2,preventDefault:!0},{linux:"Ctrl-Shift-z",run:s2,preventDefault:!0},{key:"Mod-u",run:Jce,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:eue,preventDefault:!0}];function pg(t,e){return De.create(t.ranges.map(e),t.mainIndex)}function Yo(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function Xo({state:t,dispatch:e},n){let s=pg(t.selection,n);return s.eq(t.selection,!0)?!1:(e(Yo(t,s)),!0)}function f1(t,e){return De.cursor(e?t.to:t.from)}function zP(t,e){return Xo(t,n=>n.empty?t.moveByChar(n,e):f1(n,e))}function _r(t){return t.textDirectionAt(t.state.selection.main.head)==Ss.LTR}const FP=t=>zP(t,!_r(t)),HP=t=>zP(t,_r(t));function WP(t,e){return Xo(t,n=>n.empty?t.moveByGroup(n,e):f1(n,e))}const lue=t=>WP(t,!_r(t)),cue=t=>WP(t,_r(t));function uue(t,e,n){if(e.type.prop(n))return!0;let s=e.to-e.from;return s&&(s>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function p1(t,e,n){let s=Wl(t).resolveInner(e.head),i=n?an.closedBy:an.openedBy;for(let u=e.head;;){let h=n?s.childAfter(u):s.childBefore(u);if(!h)break;uue(t,h,i)?s=h:u=n?h.to:h.from}let r=s.type.prop(i),o,l;return r&&(o=n?Ol(t,s.from,1):Ol(t,s.to,-1))&&o.matched?l=n?o.end.to:o.end.from:l=n?s.to:s.from,De.cursor(l,n?-1:1)}const hue=t=>Xo(t,e=>p1(t.state,e,!_r(t))),due=t=>Xo(t,e=>p1(t.state,e,_r(t)));function qP(t,e){return Xo(t,n=>{if(!n.empty)return f1(n,e);let s=t.moveVertically(n,e);return s.head!=n.head?s:t.moveToLineBoundary(n,e)})}const UP=t=>qP(t,!1),VP=t=>qP(t,!0);function KP(t){let e=t.scrollDOM.clientHeight<t.scrollDOM.scrollHeight-2,n=0,s=0,i;if(e){for(let r of t.state.facet(pt.scrollMargins)){let o=r(t);o?.top&&(n=Math.max(o?.top,n)),o?.bottom&&(s=Math.max(o?.bottom,s))}i=t.scrollDOM.clientHeight-n-s}else i=(t.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:s,selfScroll:e,height:Math.max(t.defaultLineHeight,i-5)}}function GP(t,e){let n=KP(t),{state:s}=t,i=pg(s.selection,o=>o.empty?t.moveVertically(o,e,n.height):f1(o,e));if(i.eq(s.selection))return!1;let r;if(n.selfScroll){let o=t.coordsAtPos(s.selection.main.head),l=t.scrollDOM.getBoundingClientRect(),u=l.top+n.marginTop,h=l.bottom-n.marginBottom;o&&o.top>u&&o.bottom<h&&(r=pt.scrollIntoView(i.main.head,{y:"start",yMargin:o.top-u}))}return t.dispatch(Yo(s,i),{effects:r}),!0}const l4=t=>GP(t,!1),i2=t=>GP(t,!0);function Ih(t,e,n){let s=t.lineBlockAt(e.head),i=t.moveToLineBoundary(e,n);if(i.head==e.head&&i.head!=(n?s.to:s.from)&&(i=t.moveToLineBoundary(e,n,!1)),!n&&i.head==s.from&&s.length){let r=/^\s*/.exec(t.state.sliceDoc(s.from,Math.min(s.from+100,s.to)))[0].length;r&&e.head!=s.from+r&&(i=De.cursor(s.from+r))}return i}const fue=t=>Xo(t,e=>Ih(t,e,!0)),pue=t=>Xo(t,e=>Ih(t,e,!1)),mue=t=>Xo(t,e=>Ih(t,e,!_r(t))),gue=t=>Xo(t,e=>Ih(t,e,_r(t))),vue=t=>Xo(t,e=>De.cursor(t.lineBlockAt(e.head).from,1)),xue=t=>Xo(t,e=>De.cursor(t.lineBlockAt(e.head).to,-1));function yue(t,e,n){let s=!1,i=pg(t.selection,r=>{let o=Ol(t,r.head,-1)||Ol(t,r.head,1)||r.head>0&&Ol(t,r.head-1,1)||r.head<t.doc.length&&Ol(t,r.head+1,-1);if(!o||!o.end)return r;s=!0;let l=o.start.from==r.head?o.end.to:o.end.from;return De.cursor(l)});return s?(e(Yo(t,i)),!0):!1}const bue=({state:t,dispatch:e})=>yue(t,e);function Lo(t,e,n){let s=pg(t.state.selection,i=>{i.undirectional&&i.head>=i.anchor!=e&&(i=De.range(i.head,i.anchor));let r=n(i);return De.range(i.anchor,r.head,r.goalColumn,r.bidiLevel||void 0,r.assoc)});return s.eq(t.state.selection)?!1:(t.dispatch(Yo(t.state,s)),!0)}function YP(t,e){return Lo(t,e,n=>t.moveByChar(n,e))}const XP=t=>YP(t,!_r(t)),QP=t=>YP(t,_r(t));function ZP(t,e){return Lo(t,e,n=>t.moveByGroup(n,e))}const wue=t=>ZP(t,!_r(t)),_ue=t=>ZP(t,_r(t)),kue=t=>{let e=!_r(t);return Lo(t,e,n=>p1(t.state,n,e))},Sue=t=>{let e=_r(t);return Lo(t,e,n=>p1(t.state,n,e))};function JP(t,e){return Lo(t,e,n=>t.moveVertically(n,e))}const e7=t=>JP(t,!1),t7=t=>JP(t,!0);function n7(t,e){return Lo(t,e,n=>t.moveVertically(n,e,KP(t).height))}const c4=t=>n7(t,!1),u4=t=>n7(t,!0),Cue=t=>Lo(t,!0,e=>Ih(t,e,!0)),jue=t=>Lo(t,!1,e=>Ih(t,e,!1)),Nue=t=>{let e=!_r(t);return Lo(t,e,n=>Ih(t,n,e))},Aue=t=>{let e=_r(t);return Lo(t,e,n=>Ih(t,n,e))},Eue=t=>Lo(t,!1,e=>De.cursor(t.lineBlockAt(e.head).from)),Mue=t=>Lo(t,!0,e=>De.cursor(t.lineBlockAt(e.head).to)),h4=({state:t,dispatch:e})=>(e(Yo(t,{anchor:0})),!0),d4=({state:t,dispatch:e})=>(e(Yo(t,{anchor:t.doc.length})),!0),f4=({state:t,dispatch:e})=>(e(Yo(t,{anchor:t.selection.main.anchor,head:0})),!0),p4=({state:t,dispatch:e})=>(e(Yo(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0),Lue=({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0),Tue=({state:t,dispatch:e})=>{let n=m1(t).map(({from:s,to:i})=>De.undirectionalRange(s,Math.min(i+1,t.doc.length)));return e(t.update({selection:De.create(n),userEvent:"select"})),!0},Rue=({state:t,dispatch:e})=>{let n=pg(t.selection,s=>{let i=Wl(t),r=i.resolveStack(s.from,1);if(s.empty){let o=i.resolveStack(s.from,-1);o.node.from>=r.node.from&&o.node.to<=r.node.to&&(r=o)}for(let o=r;o;o=o.next){let{node:l}=o;if((l.from<s.from&&l.to>=s.to||l.to>s.to&&l.from<=s.from)&&o.next)return De.undirectionalRange(l.from,l.to)}return s});return n.eq(t.selection)?!1:(e(Yo(t,n)),!0)};function s7(t,e){let{state:n}=t,s=n.selection,i=n.selection.ranges.slice();for(let r of n.selection.ranges){let o=n.doc.lineAt(r.head);if(e?o.to<t.state.doc.length:o.from>0)for(let l=r;;){let u=t.moveVertically(l,e);if(u.head<o.from||u.head>o.to){i.some(h=>h.head==u.head)||i.push(u);break}else{if(u.head==l.head)break;l=u}}}return i.length==s.ranges.length?!1:(t.dispatch(Yo(n,De.create(i,i.length-1))),!0)}const Due=t=>s7(t,!1),Oue=t=>s7(t,!0),Iue=({state:t,dispatch:e})=>{let n=t.selection,s=null;return n.ranges.length>1?s=De.create([n.main]):n.main.empty||(s=De.create([De.cursor(n.main.head)])),s?(e(Yo(t,s)),!0):!1};function E0(t,e){if(t.state.readOnly)return!1;let n="delete.selection",{state:s}=t,i=s.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let u=e(r);u<o?(n="delete.backward",u=pb(t,u,!1)):u>o&&(n="delete.forward",u=pb(t,u,!0)),o=Math.min(o,u),l=Math.max(l,u)}else o=pb(t,o,!1),l=pb(t,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:De.cursor(o,o<r.head?-1:1)}});return i.changes.empty?!1:(t.dispatch(s.update(i,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?pt.announce.of(s.phrase("Selection deleted")):void 0})),!0)}function pb(t,e,n){if(t instanceof pt)for(let s of t.state.facet(pt.atomicRanges).map(i=>i(t)))s.between(e,e,(i,r)=>{i<e&&r>e&&(e=n?r:i)});return e}const i7=(t,e,n)=>E0(t,s=>{let i=s.from,{state:r}=t,o=r.doc.lineAt(i),l,u;if(n&&!e&&i>o.from&&i<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,i-o.from))){if(l[l.length-1]==" ")return i-1;let h=dg(l,r.tabSize),f=h%_f(r)||_f(r);for(let m=0;m<f&&l[l.length-1-m]==" ";m++)i--;u=i}else u=$i(o.text,i-o.from,e,e)+o.from,u==i&&o.number!=(e?r.doc.lines:1)?u+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(u-o.from,i-o.from))&&(u=$i(o.text,u-o.from,!1,!1)+o.from);return u}),r2=t=>i7(t,!1,!0),r7=t=>i7(t,!0,!1),a7=(t,e)=>E0(t,n=>{let s=n.head,{state:i}=t,r=i.doc.lineAt(s),o=i.charCategorizer(s);for(let l=null;;){if(s==(e?r.to:r.from)){s==n.head&&r.number!=(e?i.doc.lines:1)&&(s+=e?1:-1);break}let u=$i(r.text,s-r.from,e)+r.from,h=r.text.slice(Math.min(s,u)-r.from,Math.max(s,u)-r.from),f=o(h);if(l!=null&&f!=l)break;(h!=" "||s!=n.head)&&(l=f),s=u}return s}),o7=t=>a7(t,!1),Bue=t=>a7(t,!0),$ue=t=>E0(t,e=>{let n=t.lineBlockAt(e.head).to;return e.head<n?n:Math.min(t.state.doc.length,e.head+1)}),Pue=t=>E0(t,e=>{let n=t.moveToLineBoundary(e,!1).head;return e.head>n?n:Math.max(0,e.head-1)}),zue=t=>E0(t,e=>{let n=t.moveToLineBoundary(e,!0).head;return e.head<n?n:Math.min(t.state.doc.length,e.head+1)}),Fue=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=t.changeByRange(s=>({changes:{from:s.from,to:s.to,insert:On.of(["",""])},range:De.cursor(s.from)}));return e(t.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},Hue=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=t.changeByRange(s=>{if(!s.empty||s.from==0||s.from==t.doc.length)return{range:s};let i=s.from,r=t.doc.lineAt(i),o=i==r.from?i-1:$i(r.text,i-r.from,!1)+r.from,l=i==r.to?i+1:$i(r.text,i-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:t.doc.slice(i,l).append(t.doc.slice(o,i))},range:De.cursor(l)}});return n.changes.empty?!1:(e(t.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function m1(t){let e=[],n=-1;for(let s of t.selection.ranges){let i=t.doc.lineAt(s.from),r=t.doc.lineAt(s.to);if(!s.empty&&s.to==r.from&&(r=t.doc.lineAt(s.to-1)),n>=i.number){let o=e[e.length-1];o.to=r.to,o.ranges.push(s)}else e.push({from:i.from,to:r.to,ranges:[s]});n=r.number+1}return e}function l7(t,e,n){if(t.readOnly)return!1;let s=[],i=[];for(let r of m1(t)){if(n?r.to==t.doc.length:r.from==0)continue;let o=t.doc.lineAt(n?r.to+1:r.from-1),l=o.length+1;if(n){s.push({from:r.to,to:o.to},{from:r.from,insert:o.text+t.lineBreak});for(let u of r.ranges)i.push(De.range(Math.min(t.doc.length,u.anchor+l),Math.min(t.doc.length,u.head+l)))}else{s.push({from:o.from,to:r.from},{from:r.to,insert:t.lineBreak+o.text});for(let u of r.ranges)i.push(De.range(u.anchor-l,u.head-l))}}return s.length?(e(t.update({changes:s,scrollIntoView:!0,selection:De.create(i,t.selection.mainIndex),userEvent:"move.line"})),!0):!1}const Wue=({state:t,dispatch:e})=>l7(t,e,!1),que=({state:t,dispatch:e})=>l7(t,e,!0);function c7(t,e,n){if(t.readOnly)return!1;let s=[];for(let r of m1(t))n?s.push({from:r.from,insert:t.doc.slice(r.from,r.to)+t.lineBreak}):s.push({from:r.to,insert:t.lineBreak+t.doc.slice(r.from,r.to)});let i=t.changes(s);return e(t.update({changes:i,selection:t.selection.map(i,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Uue=({state:t,dispatch:e})=>c7(t,e,!1),Vue=({state:t,dispatch:e})=>c7(t,e,!0),Kue=t=>{if(t.state.readOnly)return!1;let{state:e}=t,n=e.changes(m1(e).map(({from:i,to:r})=>(i>0?i--:r<e.doc.length&&r++,{from:i,to:r}))),s=pg(e.selection,i=>{let r;if(t.lineWrapping){let o=t.lineBlockAt(i.head),l=t.coordsAtPos(i.head,i.assoc||1);l&&(r=o.bottom+t.documentTop-l.bottom+t.defaultLineHeight/2)}return t.moveVertically(i,!0,r)}).map(n);return t.dispatch({changes:n,selection:s,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Gue(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let n=Wl(t).resolveInner(e),s=n.childBefore(e),i=n.childAfter(e),r;return s&&i&&s.to<=e&&i.from>=e&&(r=s.type.prop(an.closedBy))&&r.indexOf(i.name)>-1&&t.doc.lineAt(s.to).from==t.doc.lineAt(i.from).from&&!/\S/.test(t.sliceDoc(s.to,i.from))?{from:s.to,to:i.from}:null}const m4=u7(!1),Yue=u7(!0);function u7(t){return({state:e,dispatch:n})=>{if(e.readOnly)return!1;let s=e.changeByRange(i=>{let{from:r,to:o}=i,l=e.doc.lineAt(r),u=!t&&r==o&&Gue(e,r);t&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let h=new u1(e,{simulateBreak:r,simulateDoubleBreak:!!u}),f=xE(h,r);for(f==null&&(f=dg(/^\s*/.exec(e.doc.lineAt(r).text)[0],e.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;u?{from:r,to:o}=u:r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let m=["",e0(e,f)];return u&&m.push(e0(e,h.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:On.of(m)},range:De.cursor(r+1+m[1].length)}});return n(e.update(s,{scrollIntoView:!0,userEvent:"input"})),!0}}function CE(t,e){let n=-1;return t.changeByRange(s=>{let i=[];for(let o=s.from;o<=s.to;){let l=t.doc.lineAt(o);l.number>n&&(s.empty||s.to>l.from)&&(e(l,i,s),n=l.number),o=l.to+1}let r=t.changes(i);return{changes:i,range:De.range(r.mapPos(s.anchor,1),r.mapPos(s.head,1))}})}const Xue=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=Object.create(null),s=new u1(t,{overrideIndentation:r=>{let o=n[r];return o??-1}}),i=CE(t,(r,o,l)=>{let u=xE(s,r.from);if(u==null)return;/\S/.test(r.text)||(u=0);let h=/^\s*/.exec(r.text)[0],f=e0(t,u);(h!=f||l.from<r.from+h.length)&&(n[r.from]=u,o.push({from:r.from,to:r.from+h.length,insert:f}))});return i.changes.empty||e(t.update(i,{userEvent:"indent"})),!0},h7=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(CE(t,(n,s)=>{s.push({from:n.from,insert:t.facet(c1)})}),{userEvent:"input.indent"})),!0),d7=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(CE(t,(n,s)=>{let i=/^\s*/.exec(n.text)[0];if(!i)return;let r=dg(i,t.tabSize),o=0,l=e0(t,Math.max(0,r-_f(t)));for(;o<i.length&&o<l.length&&i.charCodeAt(o)==l.charCodeAt(o);)o++;s.push({from:n.from+o,to:n.from+i.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),Que=t=>(t.setTabFocusMode(),!0),Zue=[{key:"Ctrl-b",run:FP,shift:XP,preventDefault:!0},{key:"Ctrl-f",run:HP,shift:QP},{key:"Ctrl-p",run:UP,shift:e7},{key:"Ctrl-n",run:VP,shift:t7},{key:"Ctrl-a",run:vue,shift:Eue},{key:"Ctrl-e",run:xue,shift:Mue},{key:"Ctrl-d",run:r7},{key:"Ctrl-h",run:r2},{key:"Ctrl-k",run:$ue},{key:"Ctrl-Alt-h",run:o7},{key:"Ctrl-o",run:Fue},{key:"Ctrl-t",run:Hue},{key:"Ctrl-v",run:i2}],Jue=[{key:"ArrowLeft",run:FP,shift:XP,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:lue,shift:wue,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:mue,shift:Nue,preventDefault:!0},{key:"ArrowRight",run:HP,shift:QP,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:cue,shift:_ue,preventDefault:!0},{mac:"Cmd-ArrowRight",run:gue,shift:Aue,preventDefault:!0},{key:"ArrowUp",run:UP,shift:e7,preventDefault:!0},{mac:"Cmd-ArrowUp",run:h4,shift:f4},{mac:"Ctrl-ArrowUp",run:l4,shift:c4},{key:"ArrowDown",run:VP,shift:t7,preventDefault:!0},{mac:"Cmd-ArrowDown",run:d4,shift:p4},{mac:"Ctrl-ArrowDown",run:i2,shift:u4},{key:"PageUp",run:l4,shift:c4},{key:"PageDown",run:i2,shift:u4},{key:"Home",run:pue,shift:jue,preventDefault:!0},{key:"Mod-Home",run:h4,shift:f4},{key:"End",run:fue,shift:Cue,preventDefault:!0},{key:"Mod-End",run:d4,shift:p4},{key:"Enter",run:m4,shift:m4},{key:"Mod-a",run:Lue},{key:"Backspace",run:r2,shift:r2,preventDefault:!0},{key:"Delete",run:r7,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:o7,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:Bue,preventDefault:!0},{mac:"Mod-Backspace",run:Pue,preventDefault:!0},{mac:"Mod-Delete",run:zue,preventDefault:!0}].concat(Zue.map(t=>({mac:t.key,run:t.run,shift:t.shift}))),ehe=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:hue,shift:kue},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:due,shift:Sue},{key:"Alt-ArrowUp",run:Wue},{key:"Shift-Alt-ArrowUp",run:Uue},{key:"Alt-ArrowDown",run:que},{key:"Shift-Alt-ArrowDown",run:Vue},{key:"Mod-Alt-ArrowUp",run:Due},{key:"Mod-Alt-ArrowDown",run:Oue},{key:"Escape",run:Iue},{key:"Mod-Enter",run:Yue},{key:"Alt-l",mac:"Ctrl-l",run:Tue},{key:"Mod-i",run:Rue,preventDefault:!0},{key:"Mod-[",run:d7},{key:"Mod-]",run:h7},{key:"Mod-Alt-\\",run:Xue},{key:"Shift-Mod-k",run:Kue},{key:"Shift-Mod-\\",run:bue},{key:"Mod-/",run:Wce},{key:"Alt-A",mac:"Ctrl-A",run:Uce},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Que}].concat(Jue),the={key:"Tab",run:h7,shift:d7},g4=typeof String.prototype.normalize=="function"?t=>t.normalize("NFKD"):t=>t;class Jm{constructor(e,n,s=0,i=e.length,r,o){this.test=o,this.value={from:0,to:0,precise:!1},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(s,i),this.bufferStart=s,this.normalize=r?l=>r(g4(l)):g4,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 JA(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=Zre(e),s=this.bufferStart+this.bufferPos;this.bufferPos+=K$(e);let i=this.normalize(n);if(i.length)for(let r=0,o=s,l=!0;;r++){let u=i.charCodeAt(r),h=this.match(u,o,l,this.bufferPos+this.bufferStart,r==i.length-1);if(h)return this.value=h,this;if(r==i.length-1)break;l&&r<n.length&&n.charCodeAt(r)==u?o++:l=!1}}}match(e,n,s,i,r){let o=null;for(let l=0;l<this.matches.length;){let u=this.matches[l],h=!1;this.query.charCodeAt(u.index)==e&&(u.index==this.query.length-1?o={from:u.from,to:i,precise:r&&u.precise}:(u.index++,h=!0)),h?l++:this.matches.splice(l,1)}return this.query.charCodeAt(0)==e&&(this.query.length==1?o={from:n,to:i,precise:s&&r}:this.matches.push({from:n,index:1,precise:s})),o&&this.test&&!this.test(o.from,o.to,this.buffer,this.bufferStart)&&(o=null),o}}typeof Symbol<"u"&&(Jm.prototype[Symbol.iterator]=function(){return this});const f7={from:-1,to:-1,match:/.*/.exec(""),precise:!0},jE="gm"+(/x/.unicode==null?"":"u");class p7{constructor(e,n,s,i=0,r=e.length){if(this.text=e,this.to=r,this.curLine="",this.done=!1,this.value=f7,/\\[sWDnr]|\n|\r|\[\^/.test(n))return new m7(e,n,s,i,r);this.re=new RegExp(n,jE+(s?.ignoreCase?"i":"")),this.test=s?.test,this.iter=e.iter();let o=e.lineAt(i);this.curLineStart=o.from,this.matchPos=h_(e,i),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 s=this.curLineStart+n.index,i=s+n[0].length;if(this.matchPos=h_(this.text,i+(s==i?1:0)),s==this.curLineStart+this.curLine.length&&this.nextLine(),(s<i||s>this.value.to)&&(!this.test||this.test(s,i,n)))return this.value={from:s,to:i,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 ES=new WeakMap;class Am{constructor(e,n){this.from=e,this.text=n}get to(){return this.from+this.text.length}static get(e,n,s){let i=ES.get(e);if(!i||i.from>=s||i.to<=n){let l=new Am(n,e.sliceString(n,s));return ES.set(e,l),l}if(i.from==n&&i.to==s)return i;let{text:r,from:o}=i;return o>n&&(r=e.sliceString(n,o)+r,o=n),i.to<s&&(r+=e.sliceString(i.to,s)),ES.set(e,new Am(o,r)),new Am(n,r.slice(n-o,s-o))}}class m7{constructor(e,n,s,i,r){this.text=e,this.to=r,this.done=!1,this.value=f7,this.matchPos=h_(e,i),this.re=new RegExp(n,jE+(s?.ignoreCase?"i":"")),this.test=s?.test,this.flat=Am.get(e,i,this.chunkEnd(i+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 s=this.flat.from+n.index,i=s+n[0].length;if((this.flat.to>=this.to||n.index+n[0].length<=this.flat.text.length-10)&&(!this.test||this.test(s,i,n)))return this.value={from:s,to:i,precise:!0,match:n},this.matchPos=h_(this.text,i+(s==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Am.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(p7.prototype[Symbol.iterator]=m7.prototype[Symbol.iterator]=function(){return this});function nhe(t){try{return new RegExp(t,jE),!0}catch{return!1}}function h_(t,e){if(e>=t.length)return e;let n=t.lineAt(e),s;for(;e<n.to&&(s=n.text.charCodeAt(e-n.from))>=56320&&s<57344;)e++;return e}const she=t=>{let{state:e}=t,n=String(e.doc.lineAt(t.state.selection.main.head).number),{close:s,result:i}=Nle(t,{label:e.phrase("Go to line"),input:{type:"text",name:"line",value:n},focus:!0,submitLabel:e.phrase("go")});return i.then(r=>{let o=r&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(r.elements.line.value);if(!o){t.dispatch({effects:s});return}let l=e.doc.lineAt(e.selection.main.head),[,u,h,f,m]=o,g=f?+f.slice(1):0,x=h?+h:l.number;if(h&&m){let k=x/100;u&&(k=k*(u=="-"?-1:1)+l.number/e.doc.lines),x=Math.round(e.doc.lines*k)}else h&&u&&(x=x*(u=="-"?-1:1)+l.number);let b=e.doc.line(Math.max(1,Math.min(e.doc.lines,x))),_=De.cursor(b.from+Math.max(0,Math.min(g,b.length)));t.dispatch({effects:[s,pt.scrollIntoView(_.from,{y:"center"})],selection:_})}),!0},ihe={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},rhe=ct.define({combine(t){return Mf(t,ihe,{highlightWordAroundCursor:(e,n)=>e||n,minSelectionLength:Math.min,maxMatches:Math.min})}});function ahe(t){return[hhe,uhe]}const ohe=sn.mark({class:"cm-selectionMatch"}),lhe=sn.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function v4(t,e,n,s){return(n==0||t(e.sliceDoc(n-1,n))!=Xs.Word)&&(s==e.doc.length||t(e.sliceDoc(s,s+1))!=Xs.Word)}function che(t,e,n,s){return t(e.sliceDoc(n,n+1))==Xs.Word&&t(e.sliceDoc(s-1,s))==Xs.Word}const uhe=Pr.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(rhe),{state:n}=t,s=n.selection;if(s.ranges.length>1)return sn.none;let i=s.main,r,o=null;if(i.empty){if(!e.highlightWordAroundCursor)return sn.none;let u=n.wordAt(i.head);if(!u)return sn.none;o=n.charCategorizer(i.head),r=n.sliceDoc(u.from,u.to)}else{let u=i.to-i.from;if(u<e.minSelectionLength||u>200)return sn.none;if(e.wholeWords){if(r=n.sliceDoc(i.from,i.to),o=n.charCategorizer(i.head),!(v4(o,n,i.from,i.to)&&che(o,n,i.from,i.to)))return sn.none}else if(r=n.sliceDoc(i.from,i.to),!r)return sn.none}let l=[];for(let u of t.visibleRanges){let h=new Jm(n.doc,r,u.from,u.to);for(;!h.next().done;){let{from:f,to:m}=h.value;if((!o||v4(o,n,f,m))&&(i.empty&&f<=i.from&&m>=i.to?l.push(lhe.range(f,m)):(f>=i.to||m<=i.from)&&l.push(ohe.range(f,m)),l.length>e.maxMatches))return sn.none}}return sn.set(l)}},{decorations:t=>t.decorations}),hhe=pt.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),dhe=({state:t,dispatch:e})=>{let{selection:n}=t,s=De.create(n.ranges.map(i=>t.wordAt(i.head)||De.cursor(i.head)),n.mainIndex);return s.eq(n)?!1:(e(t.update({selection:s})),!0)};function fhe(t,e){let{main:n,ranges:s}=t.selection,i=t.wordAt(n.head),r=i&&i.from==n.from&&i.to==n.to;for(let o=!1,l=new Jm(t.doc,e,s[s.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new Jm(t.doc,e,0,Math.max(0,s[s.length-1].from-1)),o=!0}else{if(o&&s.some(u=>u.from==l.value.from))continue;if(r){let u=t.wordAt(l.value.from);if(!u||u.from!=l.value.from||u.to!=l.value.to)continue}return l.value}}const phe=({state:t,dispatch:e})=>{let{ranges:n}=t.selection;if(n.some(r=>r.from===r.to))return dhe({state:t,dispatch:e});let s=t.sliceDoc(n[0].from,n[0].to);if(t.selection.ranges.some(r=>t.sliceDoc(r.from,r.to)!=s))return!1;let i=fhe(t,s);return i?(e(t.update({selection:t.selection.addRange(De.range(i.from,i.to),!1),effects:pt.scrollIntoView(i.to)})),!0):!1},Lf=ct.define({combine(t){return Mf(t,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new Ehe(e),scrollToMatch:e=>pt.scrollIntoView(e)})}});function mhe(t){return t?[Lf.of(t),o2]:o2}class g7{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||nhe(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,s)=>s=="n"?`
84
- `:s=="r"?"\r":s=="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 whe(this):new xhe(this)}getCursor(e,n=0,s){let i=e.doc?e:Nn.create({doc:e});return s==null&&(s=i.doc.length),this.regexp?om(this,i,n,s):am(this,i,n,s)}}class v7{constructor(e){this.spec=e}}function ghe(t,e,n){return(s,i,r,o)=>{if(n&&!n(s,i,r,o))return!1;let l=s>=o&&i<=o+r.length?r.slice(s-o,i-o):e.doc.sliceString(s,i);return t(l,e,s,i)}}function am(t,e,n,s){let i;return t.wholeWord&&(i=vhe(e.doc,e.charCategorizer(e.selection.main.head))),t.test&&(i=ghe(t.test,e,i)),new Jm(e.doc,t.unquoted,n,s,t.caseSensitive?void 0:r=>r.toLowerCase(),i)}function vhe(t,e){return(n,s,i,r)=>((r>n||r+i.length<s)&&(r=Math.max(0,n-2),i=t.sliceString(r,Math.min(t.length,s+2))),(e(d_(i,n-r))!=Xs.Word||e(f_(i,n-r))!=Xs.Word)&&(e(f_(i,s-r))!=Xs.Word||e(d_(i,s-r))!=Xs.Word))}class xhe extends v7{constructor(e){super(e)}nextMatch(e,n,s){let i=am(this.spec,e,s,e.doc.length).nextOverlapping();if(i.done){let r=Math.min(e.doc.length,n+this.spec.unquoted.length);i=am(this.spec,e,0,r).nextOverlapping()}return i.done||i.value.from==n&&i.value.to==s?null:i.value}prevMatchInRange(e,n,s){for(let i=s;;){let r=Math.max(n,i-1e4-this.spec.unquoted.length),o=am(this.spec,e,r,i),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(r==n)return null;i-=1e4}}prevMatch(e,n,s){let i=this.prevMatchInRange(e,0,n);return i||(i=this.prevMatchInRange(e,Math.max(0,s-this.spec.unquoted.length),e.doc.length)),i&&(i.from!=n||i.to!=s)?i:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,n){let s=am(this.spec,e,0,e.doc.length),i=[];for(;!s.next().done;){if(i.length>=n)return null;i.push(s.value)}return i}highlight(e,n,s,i){let r=am(this.spec,e,Math.max(0,n-this.spec.unquoted.length),Math.min(s+this.spec.unquoted.length,e.doc.length));for(;!r.next().done;)i(r.value.from,r.value.to)}}function yhe(t,e,n){return(s,i,r)=>(!n||n(s,i,r))&&t(r[0],e,s,i)}function om(t,e,n,s){let i;return t.wholeWord&&(i=bhe(e.charCategorizer(e.selection.main.head))),t.test&&(i=yhe(t.test,e,i)),new p7(e.doc,t.search,{ignoreCase:!t.caseSensitive,test:i},n,s)}function d_(t,e){return t.slice($i(t,e,!1),e)}function f_(t,e){return t.slice(e,$i(t,e))}function bhe(t){return(e,n,s)=>!s[0].length||(t(d_(s.input,s.index))!=Xs.Word||t(f_(s.input,s.index))!=Xs.Word)&&(t(f_(s.input,s.index+s[0].length))!=Xs.Word||t(d_(s.input,s.index+s[0].length))!=Xs.Word)}class whe extends v7{nextMatch(e,n,s){let i=om(this.spec,e,s,e.doc.length).next();return i.done&&(i=om(this.spec,e,0,n).next()),i.done?null:i.value}prevMatchInRange(e,n,s){for(let i=1;;i++){let r=Math.max(n,s-i*1e4),o=om(this.spec,e,r,s),l=null;for(;!o.next().done;)l=o.value;if(l&&(r==n||l.from>r+10))return l;if(r==n)return null}}prevMatch(e,n,s){return this.prevMatchInRange(e,0,n)||this.prevMatchInRange(e,s,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(n,s)=>{if(s=="&")return e.match[0];if(s=="$")return"$";for(let i=s.length;i>0;i--){let r=+s.slice(0,i);if(r>0&&r<e.match.length)return e.match[r]+s.slice(i)}return n})}matchAll(e,n){let s=om(this.spec,e,0,e.doc.length),i=[];for(;!s.next().done;){if(i.length>=n)return null;i.push(s.value)}return i}highlight(e,n,s,i){let r=om(this.spec,e,Math.max(0,n-250),Math.min(s+250,e.doc.length));for(;!r.next().done;)i(r.value.from,r.value.to)}}const n0=ss.define(),NE=ss.define(),_h=Kl.define({create(t){return new MS(a2(t).create(),null)},update(t,e){for(let n of e.effects)n.is(n0)?t=new MS(n.value.create(),t.panel):n.is(NE)&&(t=new MS(t.query,n.value?AE:null));return t},provide:t=>o_.from(t,e=>e.panel)});class MS{constructor(e,n){this.query=e,this.panel=n}}const _he=sn.mark({class:"cm-searchMatch"}),khe=sn.mark({class:"cm-searchMatch cm-searchMatch-selected"}),She=Pr.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(_h))}update(t){let e=t.state.field(_h);(e!=t.startState.field(_h)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return sn.none;let{view:n}=this,s=new xf;for(let i=0,r=n.visibleRanges,o=r.length;i<o;i++){let{from:l,to:u}=r[i];for(;i<o-1&&u>r[i+1].from-500;)u=r[++i].to;t.highlight(n.state,l,u,(h,f)=>{let m=n.state.selection.ranges.some(g=>g.from==h&&g.to==f);s.add(h,f,m?khe:_he)})}return s.finish()}},{decorations:t=>t.decorations});function M0(t){return e=>{let n=e.state.field(_h,!1);return n&&n.query.spec.valid?t(e,n):b7(e)}}const p_=M0((t,{query:e})=>{let{to:n}=t.state.selection.main,s=e.nextMatch(t.state,n,n);if(!s)return!1;let i=De.single(s.from,s.to),r=t.state.facet(Lf);return t.dispatch({selection:i,effects:[EE(t,s),r.scrollToMatch(i.main,t)],userEvent:"select.search"}),y7(t),!0}),m_=M0((t,{query:e})=>{let{state:n}=t,{from:s}=n.selection.main,i=e.prevMatch(n,s,s);if(!i)return!1;let r=De.single(i.from,i.to),o=t.state.facet(Lf);return t.dispatch({selection:r,effects:[EE(t,i),o.scrollToMatch(r.main,t)],userEvent:"select.search"}),y7(t),!0}),Che=M0((t,{query:e})=>{let n=e.matchAll(t.state,1e3);return!n||!n.length?!1:(t.dispatch({selection:De.create(n.map(s=>De.range(s.from,s.to))),userEvent:"select.search.matches"}),!0)}),jhe=({state:t,dispatch:e})=>{let n=t.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:s,to:i}=n.main,r=[],o=0;for(let l=new Jm(t.doc,t.sliceDoc(s,i));!l.next().done;){if(r.length>1e3)return!1;l.value.from==s&&(o=r.length),r.push(De.range(l.value.from,l.value.to))}return e(t.update({selection:De.create(r,o),userEvent:"select.search.matches"})),!0},x4=M0((t,{query:e})=>{let{state:n}=t,{from:s,to:i}=n.selection.main;if(n.readOnly)return!1;let r=e.nextMatch(n,s,s);if(!r)return!1;let o=r,l=[],u,h,f=[];o.precise?o.from==s&&o.to==i&&(h=n.toText(e.getReplacement(o)),l.push({from:o.from,to:o.to,insert:h}),o=e.nextMatch(n,o.from,o.to),f.push(pt.announce.of(n.phrase("replaced match on line $",n.doc.lineAt(s).number)+"."))):o=e.nextMatch(n,o.from,o.to);let m=t.state.changes(l);return o&&(u=De.single(o.from,o.to).map(m),f.push(EE(t,o)),f.push(n.facet(Lf).scrollToMatch(u.main,t))),t.dispatch({changes:m,selection:u,effects:f,userEvent:"input.replace"}),!0}),Nhe=M0((t,{query:e})=>{if(t.state.readOnly)return!1;let n=[];for(let i of e.matchAll(t.state,1e9)){let{from:r,to:o,precise:l}=i;l&&n.push({from:r,to:o,insert:e.getReplacement(i)})}if(!n.length)return!1;let s=t.state.phrase("replaced $ matches",n.length)+".";return t.dispatch({changes:n,effects:pt.announce.of(s),userEvent:"input.replace.all"}),!0});function AE(t){return t.state.facet(Lf).createPanel(t)}function a2(t,e){var n,s,i,r,o;let l=t.selection.main,u=l.empty||l.to>l.from+100?"":t.sliceDoc(l.from,l.to);if(e&&!u)return e;let h=t.facet(Lf);return new g7({search:((n=e?.literal)!==null&&n!==void 0?n:h.literal)?u:u.replace(/\n/g,"\\n"),caseSensitive:(s=e?.caseSensitive)!==null&&s!==void 0?s:h.caseSensitive,literal:(i=e?.literal)!==null&&i!==void 0?i:h.literal,regexp:(r=e?.regexp)!==null&&r!==void 0?r:h.regexp,wholeWord:(o=e?.wholeWord)!==null&&o!==void 0?o:h.wholeWord})}function x7(t){let e=lP(t,AE);return e&&e.dom.querySelector("[main-field]")}function y7(t){let e=x7(t);e&&e==t.root.activeElement&&e.select()}const b7=t=>{let e=t.state.field(_h,!1);if(e&&e.panel){let n=x7(t);if(n&&n!=t.root.activeElement){let s=a2(t.state,e.query.spec);s.valid&&t.dispatch({effects:n0.of(s)}),n.focus(),n.select()}}else t.dispatch({effects:[NE.of(!0),e?n0.of(a2(t.state,e.query.spec)):ss.appendConfig.of(o2)]});return!0},w7=t=>{let e=t.state.field(_h,!1);if(!e||!e.panel)return!1;let n=lP(t,AE);return n&&n.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:NE.of(!1)}),!0},Ahe=[{key:"Mod-f",run:b7,scope:"editor search-panel"},{key:"F3",run:p_,shift:m_,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:p_,shift:m_,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:w7,scope:"editor search-panel"},{key:"Mod-Shift-l",run:jhe},{key:"Mod-Alt-g",run:she},{key:"Mod-d",run:phe,preventDefault:!0}];class Ehe{constructor(e){this.view=e;let n=this.query=e.state.field(_h).query.spec;this.commit=this.commit.bind(this),this.searchField=Mi("input",{value:n.search,placeholder:Ta(e,"Find"),"aria-label":Ta(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=Mi("input",{value:n.replace,placeholder:Ta(e,"Replace"),"aria-label":Ta(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=Mi("input",{type:"checkbox",name:"case",form:"",checked:n.caseSensitive,onchange:this.commit}),this.reField=Mi("input",{type:"checkbox",name:"re",form:"",checked:n.regexp,onchange:this.commit}),this.wordField=Mi("input",{type:"checkbox",name:"word",form:"",checked:n.wholeWord,onchange:this.commit});function s(i,r,o){return Mi("button",{class:"cm-button",name:i,onclick:r,type:"button"},o)}this.dom=Mi("div",{onkeydown:i=>this.keydown(i),class:"cm-search"},[this.searchField,s("next",()=>p_(e),[Ta(e,"next")]),s("prev",()=>m_(e),[Ta(e,"previous")]),s("select",()=>Che(e),[Ta(e,"all")]),Mi("label",null,[this.caseField,Ta(e,"match case")]),Mi("label",null,[this.reField,Ta(e,"regexp")]),Mi("label",null,[this.wordField,Ta(e,"by word")]),...e.state.readOnly?[]:[Mi("br"),this.replaceField,s("replace",()=>x4(e),[Ta(e,"replace")]),s("replaceAll",()=>Nhe(e),[Ta(e,"replace all")])],Mi("button",{name:"close",onclick:()=>w7(e),"aria-label":Ta(e,"close"),type:"button"},["×"])])}commit(){let e=new g7({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:n0.of(e)}))}keydown(e){Zoe(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?m_:p_)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),x4(this.view))}update(e){for(let n of e.transactions)for(let s of n.effects)s.is(n0)&&!s.value.eq(this.query)&&this.setQuery(s.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(Lf).top}}function Ta(t,e){return t.state.phrase(e)}const mb=30,gb=/[\s\.,:;?!]/;function EE(t,{from:e,to:n}){let s=t.state.doc.lineAt(e),i=t.state.doc.lineAt(n).to,r=Math.max(s.from,e-mb),o=Math.min(i,n+mb),l=t.state.sliceDoc(r,o);if(r!=s.from){for(let u=0;u<mb;u++)if(!gb.test(l[u+1])&&gb.test(l[u])){l=l.slice(u);break}}if(o!=i){for(let u=l.length-1;u>l.length-mb;u--)if(!gb.test(l[u-1])&&gb.test(l[u])){l=l.slice(0,u);break}}return pt.announce.of(`${t.state.phrase("current match")}. ${l} ${t.state.phrase("on line")} ${s.number}.`)}const Mhe=pt.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"}}),o2=[_h,S0.low(She),Mhe],Mn=t=>bE.define(t),Lhe={js:()=>vt(()=>import("./index-DE8onpZH.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript()),mjs:()=>vt(()=>import("./index-DE8onpZH.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript()),cjs:()=>vt(()=>import("./index-DE8onpZH.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript()),jsx:()=>vt(()=>import("./index-DE8onpZH.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({jsx:!0})),ts:()=>vt(()=>import("./index-DE8onpZH.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({typescript:!0})),mts:()=>vt(()=>import("./index-DE8onpZH.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({typescript:!0})),cts:()=>vt(()=>import("./index-DE8onpZH.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({typescript:!0})),tsx:()=>vt(()=>import("./index-DE8onpZH.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({jsx:!0,typescript:!0})),json:()=>vt(()=>import("./index-B9RQz1OR.js"),__vite__mapDeps([3,1]),import.meta.url).then(t=>t.json()),jsonc:()=>vt(()=>import("./index-B9RQz1OR.js"),__vite__mapDeps([3,1]),import.meta.url).then(t=>t.json()),md:()=>vt(()=>import("./index-CTzvT_1x.js"),__vite__mapDeps([4,2,5,1,6,0]),import.meta.url).then(t=>t.markdown()),markdown:()=>vt(()=>import("./index-CTzvT_1x.js"),__vite__mapDeps([4,2,5,1,6,0]),import.meta.url).then(t=>t.markdown()),mdx:()=>vt(()=>import("./index-CTzvT_1x.js"),__vite__mapDeps([4,2,5,1,6,0]),import.meta.url).then(t=>t.markdown()),html:()=>vt(()=>import("./index-hprnX92o.js"),__vite__mapDeps([5,1,6,0,2]),import.meta.url).then(t=>t.html()),htm:()=>vt(()=>import("./index-hprnX92o.js"),__vite__mapDeps([5,1,6,0,2]),import.meta.url).then(t=>t.html()),cshtml:()=>vt(()=>import("./index-hprnX92o.js"),__vite__mapDeps([5,1,6,0,2]),import.meta.url).then(t=>t.html()),vue:()=>vt(()=>import("./index-hprnX92o.js"),__vite__mapDeps([5,1,6,0,2]),import.meta.url).then(t=>t.html()),css:()=>vt(()=>import("./index-BD_cQrI6.js"),__vite__mapDeps([6,1]),import.meta.url).then(t=>t.css()),scss:()=>vt(()=>import("./index-BD_cQrI6.js"),__vite__mapDeps([6,1]),import.meta.url).then(t=>t.css()),less:()=>vt(()=>import("./index-BD_cQrI6.js"),__vite__mapDeps([6,1]),import.meta.url).then(t=>t.css()),rs:()=>vt(()=>import("./index-d1wSMeTJ.js"),__vite__mapDeps([7,1]),import.meta.url).then(t=>t.rust()),py:()=>vt(()=>import("./index-BOO1PLTc.js"),__vite__mapDeps([8,1,2]),import.meta.url).then(t=>t.python()),pyi:()=>vt(()=>import("./index-BOO1PLTc.js"),__vite__mapDeps([8,1,2]),import.meta.url).then(t=>t.python()),sql:()=>vt(()=>import("./index-DKPe1qy4.js"),__vite__mapDeps([9,1,2]),import.meta.url).then(t=>t.sql()),yaml:()=>vt(()=>import("./index-BgOsXXRm.js"),__vite__mapDeps([10,1]),import.meta.url).then(t=>t.yaml()),yml:()=>vt(()=>import("./index-BgOsXXRm.js"),__vite__mapDeps([10,1]),import.meta.url).then(t=>t.yaml()),sh:()=>vt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>Mn(t.shell)),bash:()=>vt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>Mn(t.shell)),zsh:()=>vt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>Mn(t.shell)),fish:()=>vt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>Mn(t.shell)),cs:()=>vt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>Mn(t.csharp)),c:()=>vt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>Mn(t.c)),h:()=>vt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>Mn(t.c)),cpp:()=>vt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>Mn(t.cpp)),hpp:()=>vt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>Mn(t.cpp)),java:()=>vt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>Mn(t.java)),kt:()=>vt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>Mn(t.kotlin)),swift:()=>vt(()=>import("./swift-BzpIVaGY.js"),[],import.meta.url).then(t=>Mn(t.swift)),go:()=>vt(()=>import("./go-CTD25R5P.js"),[],import.meta.url).then(t=>Mn(t.go)),rb:()=>vt(()=>import("./ruby-B2Rjki9n.js"),[],import.meta.url).then(t=>Mn(t.ruby)),lua:()=>vt(()=>import("./lua-VAEuO923.js"),[],import.meta.url).then(t=>Mn(t.lua)),toml:()=>vt(()=>import("./toml-Bm5Em-hy.js"),[],import.meta.url).then(t=>Mn(t.toml)),xml:()=>vt(()=>import("./xml-BQQZnNBQ.js"),[],import.meta.url).then(t=>Mn(t.xml)),svg:()=>vt(()=>import("./xml-BQQZnNBQ.js"),[],import.meta.url).then(t=>Mn(t.xml)),xaml:()=>vt(()=>import("./xml-BQQZnNBQ.js"),[],import.meta.url).then(t=>Mn(t.xml)),csproj:()=>vt(()=>import("./xml-BQQZnNBQ.js"),[],import.meta.url).then(t=>Mn(t.xml)),diff:()=>vt(()=>import("./diff-DbItnlRl.js"),[],import.meta.url).then(t=>Mn(t.diff)),patch:()=>vt(()=>import("./diff-DbItnlRl.js"),[],import.meta.url).then(t=>Mn(t.diff)),ps1:()=>vt(()=>import("./powershell-CFHJl5sT.js"),[],import.meta.url).then(t=>Mn(t.powerShell)),properties:()=>vt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>Mn(t.properties)),ini:()=>vt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>Mn(t.properties)),env:()=>vt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>Mn(t.properties))},y4={dockerfile:()=>vt(()=>import("./dockerfile-ZL4hHokT.js"),[],import.meta.url).then(t=>Mn(t.dockerFile)),makefile:()=>vt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>Mn(t.shell)),".env":()=>vt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>Mn(t.properties)),".gitignore":()=>vt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>Mn(t.properties)),".dockerignore":()=>vt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>Mn(t.properties)),".editorconfig":()=>vt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>Mn(t.properties))};async function The(t){const e=(t.split("/").pop()??t).toLowerCase(),n=y4[e]??y4[e.slice(0,e.indexOf(".",1))];if(n)return n();const s=e.lastIndexOf(".");if(s<=0)return null;const i=Lhe[e.slice(s+1)];return i?i():null}const Rhe=h1.define([{tag:[Ke.comment,Ke.lineComment,Ke.blockComment,Ke.docComment],color:"var(--syntax-comment)",fontStyle:"italic"},{tag:[Ke.keyword,Ke.modifier,Ke.controlKeyword,Ke.moduleKeyword],color:"var(--syntax-keyword)"},{tag:[Ke.string,Ke.special(Ke.string),Ke.regexp],color:"var(--syntax-string)"},{tag:[Ke.number,Ke.bool,Ke.null,Ke.atom],color:"var(--syntax-number)"},{tag:[Ke.function(Ke.variableName),Ke.function(Ke.propertyName),Ke.labelName],color:"var(--syntax-function)"},{tag:[Ke.typeName,Ke.className,Ke.namespace,Ke.self],color:"var(--syntax-type)"},{tag:[Ke.propertyName,Ke.attributeName],color:"var(--syntax-property)"},{tag:[Ke.variableName,Ke.definition(Ke.variableName)],color:"var(--fg-1)"},{tag:[Ke.operator,Ke.punctuation,Ke.separator,Ke.bracket],color:"var(--fg-2)"},{tag:[Ke.tagName],color:"var(--syntax-property)"},{tag:[Ke.heading],color:"var(--syntax-function)",fontWeight:"600"},{tag:[Ke.link,Ke.url],color:"var(--link)",textDecoration:"underline"},{tag:[Ke.emphasis],fontStyle:"italic"},{tag:[Ke.strong],fontWeight:"600"},{tag:[Ke.invalid],color:"var(--syntax-property)"}]),Dhe=pt.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 Ohe({path:t,initialDoc:e,readOnly:n=!1,onChange:s,onSave:i,onSelect:r}){const o=y.useRef(null),l=y.useRef(null),u=y.useRef(s),h=y.useRef(i),f=y.useRef(r);return u.current=s,h.current=i,f.current=r,y.useEffect(()=>{const m=o.current;if(!m)return;const g=new C0,x=Nn.create({doc:e,extensions:[Ble(),zle(),ble(),ple(),Zce(),ile(),jle(),wce(),Tce(),ahe(),mhe({top:!0}),pt.lineWrapping,c1.of(" "),kce(Rhe),Dhe,g.of([]),Nn.readOnly.of(n),pt.editable.of(!n),pt.contentAttributes.of({autocapitalize:"off",autocorrect:"off",spellcheck:"false"}),nP.of([{key:"Mod-s",preventDefault:!0,run:()=>(h.current(),!0)},{key:"Escape",run:j=>(j.contentDOM.blur(),!0)},...Ahe,...oue,...ehe,the]),pt.updateListener.of(j=>{if(j.docChanged&&u.current(j.state.doc.toString()),j.selectionSet||j.docChanged){const{from:M,to:A}=j.state.selection.main;f.current?.({from:M,to:A,text:M===A?"":j.state.doc.sliceString(M,A)})}})]}),b=new pt({state:x,parent:m});l.current=b;const _=P$(Yw("code",t));_&&b.dispatch({effects:_});const k=()=>$$(Yw("code",t),b.scrollSnapshot());b.scrollDOM.addEventListener("scroll",k,{passive:!0});let N=!0;return The(t).then(j=>{!N||!j||b.dispatch({effects:g.reconfigure(j)})}).catch(()=>{}),()=>{N=!1,b.scrollDOM.removeEventListener("scroll",k),b.destroy(),l.current=null}},[t,n]),y.useEffect(()=>{const m=o.current;if(!m||typeof IntersectionObserver>"u")return;const g=new IntersectionObserver(x=>{x.some(b=>b.isIntersecting)&&l.current?.requestMeasure()});return g.observe(m),()=>g.disconnect()},[]),a.jsx("div",{className:"ws-cm",ref:o})}function _7({children:t}){return a.jsx("div",{className:"prose-table",children:a.jsx("table",{children:t})})}const Ihe={a:PA,table:_7};function Bhe(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} kB`:`${(t/(1024*1024)).toFixed(1)} MB`}function $he({path:t,preview:e,draft:n,onDraft:s,onSave:i,raw:r,generation:o,onProseRef:l,onSelect:u}){if(!e)return a.jsx("div",{className:"dots","aria-label":"loading"});const h=ZA(t,e),f=r&&(h==="prose"||h==="page")?"code":h;return f==="image"?a.jsx(zhe,{path:t}):f==="video"?a.jsx(Fhe,{path:t,size:e.size},`${t}:${o??0}`):f==="none"?a.jsx(S7,{path:t,preview:e}):f==="page"?a.jsx(Phe,{path:t,html:n}):f==="prose"?a.jsx("div",{className:"prose panel-prose",ref:l,children:a.jsx(MA,{remarkPlugins:[DA],components:Ihe,children:n})}):a.jsx(Ohe,{path:t,initialDoc:e.content,readOnly:e.truncated,onChange:s,onSave:()=>i?.(),onSelect:u},`${t}:${o??0}`)}function k7({path:t}){const[e,n]=y.useState(!1),[s,i]=y.useState(null),[r,o]=y.useState(!1);async function l(){n(!0),i(null),o(!1);try{await te.invoke("open_file_native",{path:t}),o(!0)}catch(u){i(u instanceof Error?u.message:String(u))}finally{n(!1)}}return a.jsxs("div",{className:"native-open",children:[a.jsx("button",{className:"native-open-btn",type:"button",disabled:e,onClick:()=>{l()},children:e?"Opening…":"Open in default app"}),a.jsx("p",{className:"native-open-note",children:"On the computer running OctiqFlow"}),r&&a.jsx("p",{className:"native-open-status",role:"status",children:"Opened."}),s&&a.jsx("p",{className:"native-open-error",role:"alert",children:s})]})}function S7({path:t,preview:e,reason:n="Preview unavailable"}){const s=e.kind==="pdf"?"PDF document":"File";return a.jsxs("div",{className:"panel-unsupported",children:[a.jsxs("div",{className:"panel-unsupported-copy",children:[a.jsx("strong",{children:n}),a.jsxs("span",{children:[s," · ",a.jsx(Kt,{children:Bhe(e.size)})]})]}),a.jsx(k7,{path:t},t)]})}function Phe({path:t,html:e}){return a.jsx("iframe",{className:"panel-page",title:`${ks(t)} — preview`,srcDoc:e,sandbox:"allow-scripts allow-popups",referrerPolicy:"no-referrer"})}function zhe({path:t}){const[e,n]=y.useState(null),[s,i]=y.useState(null),r=y.useRef(null);return y.useEffect(()=>{let o=!0;return te.fetchFile(t).then(l=>{o&&(r.current=URL.createObjectURL(l),n(r.current))}).catch(l=>o&&i(l.message)),()=>{o=!1,r.current&&URL.revokeObjectURL(r.current)}},[t]),s?a.jsx("div",{className:"panel-error",children:s}):e?a.jsx("div",{className:"ws-image",children:a.jsx("img",{src:e,alt:ks(t)})}):a.jsx("div",{className:"dots","aria-label":"loading"})}function Fhe({path:t,size:e}){const[n,s]=y.useState(!1);return n?a.jsx(S7,{path:t,preview:{kind:"video",content:"",truncated:!1,size:e},reason:"This video can’t play in this browser"}):a.jsx("div",{className:"ws-video",children:a.jsx("video",{src:te.fileUrl(t),controls:!0,playsInline:!0,preload:"metadata","aria-label":ks(t),onError:()=>s(!0)})})}function Hhe(t,e){const[n,s]=y.useState("closed"),[i,r]=y.useState(null),o=y.useRef(null),l=y.useRef(!1),u=y.useRef(null);y.useLayoutEffect(()=>s("closed"),[e]),y.useLayoutEffect(()=>{const x=document.getElementById("dock"),b=x?.querySelector(".main:not([hidden])"),_=x?.closest(".app"),k=window.matchMedia("(max-width: 700px)");if(!x||!b||!t){r(null);return}const N=b.inert,j=window.visualViewport,M=()=>{k.matches&&j&&_?.style.setProperty("--reader-viewport-height",`${j.height}px`)},A=()=>{r(k.matches?b:null),k.matches?(x.dataset.readerChat=n,_?.classList.add("is-file-reading"),b.inert=n==="closed",M()):(delete x.dataset.readerChat,_?.classList.remove("is-file-reading"),b.inert=N)};return A(),k.addEventListener("change",A),j?.addEventListener("resize",M),()=>{k.removeEventListener("change",A),j?.removeEventListener("resize",M),b.inert=N,delete x.dataset.readerChat,_?.classList.remove("is-file-reading"),_?.style.removeProperty("--reader-viewport-height")}},[t,n]);function h(){i&&Eo.flushSync(()=>s("half"))}function f(){document.activeElement instanceof HTMLElement&&i?.contains(document.activeElement)&&document.activeElement.blur(),Eo.flushSync(()=>s("closed")),u.current?.focus({preventScroll:!0})}const m=i&&n!=="closed"?Eo.createPortal(a.jsxs("header",{className:"reader-chat-head",children:[a.jsxs("button",{className:"reader-chat-resize",type:"button","aria-label":n==="large"?"Make chat smaller":"Expand chat","aria-expanded":n==="large",onClick:()=>{if(l.current){l.current=!1;return}s(n==="large"?"half":"large")},onPointerDown:x=>{l.current=!1,o.current=x.clientY,x.currentTarget.setPointerCapture(x.pointerId)},onPointerUp:x=>{const b=x.clientY-(o.current??x.clientY);o.current=null,!(Math.abs(b)<30)&&(l.current=!0,x.preventDefault(),b>0?f():s("large"))},onPointerCancel:()=>{o.current=null},children:[a.jsx("span",{className:"reader-chat-grip"}),"Chat"]}),a.jsxs("button",{type:"button",onClick:f,children:["Continue reading ",a.jsx("span",{"aria-hidden":"true",children:"⌄"})]})]}),i):null;return{show:h,collapse:f,size:n,controls:m,launcher:i&&n==="closed"?a.jsxs("button",{ref:u,className:"reader-chat-launch",type:"button",onClick:h,children:[a.jsx("span",{children:"Ask agent / discuss this file"}),a.jsx("span",{"aria-hidden":"true",children:"⌃"})]}):null}}function LS(t,e){const n=t.getBoundingClientRect().top,s=Array.from(e.children),i=Math.max(0,s.findIndex(o=>o.getBoundingClientRect().bottom>n)),r=[i,i+1,i-1];return{scrollTop:t.scrollTop,blocks:r.flatMap(o=>{const l=s[o];return l?[{text:l.textContent??"",index:o,offset:l.getBoundingClientRect().top-n}]:[]})}}function Whe(t,e,n){const s=Array.from(e.children);for(const i of n.blocks){if(!i.text)continue;const r=s.map((o,l)=>({el:o,index:l})).filter(({el:o})=>o.textContent===i.text).sort((o,l)=>Math.abs(o.index-i.index)-Math.abs(l.index-i.index))[0];if(r){t.scrollTop+=r.el.getBoundingClientRect().top-t.getBoundingClientRect().top-i.offset;return}}t.scrollTop=n.scrollTop}const qhe="octiq.v2.fileWidth",Uhe={initial:480,min:320,max:760},Vhe="dock";function b4(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} kB`:`${(t/(1024*1024)).toFixed(1)} MB`}function Khe({path:t,open:e,onClose:n}){const[s,i]=y.useState(null),[r,o]=y.useState(null),[l,u]=y.useState(""),[h,f]=y.useState(!1),[m,g]=y.useState(!1),[x,b]=y.useState(!1),[_,k]=y.useState(!1),[N,j]=y.useState(null),[M,A]=y.useState(0),E=Hhe(e,t),L=y.useRef(null),O=y.useRef(null),X=y.useRef(0),q=k0(),{width:$,startDrag:G,entered:B}=qm(qhe,Uhe),F=y.useRef(null),z=y.useRef(null),W=y.useRef(null),H=y.useRef(null),U=!!s&&l!==s.content,ee=y.useRef(l),Q=y.useRef(s?.content??"");ee.current=l,Q.current=s?.content??"";const I=!!s&&s.kind==="text"&&!s.truncated&&U,Y=!!s&&!h&&ZA(t,s)==="prose",J=y.useCallback(async D=>{const Oe=++X.current,ze=ee.current;try{const Ce=await te.invoke("read_file_preview",{path:t});if(Oe!==X.current)return;if(D&&ee.current!==ze){k(!0);return}D&&W.current&&z.current&&(L.current=LS(W.current,z.current)),i(Ce),u(Ce.content??""),A(ve=>ve+1),j(null),k(!1),o(null),D||f(!1)}catch(Ce){if(Oe!==X.current)return;o(String(Ce.message??Ce))}},[t]);y.useEffect(()=>(i(null),o(null),f(!1),j(null),L.current=null,O.current=null,J(!1),()=>{X.current++}),[t,J]),y.useLayoutEffect(()=>{const D=W.current;if(!D||!Y)return;const Oe=P$(Yw("prose",t));Oe&&(D.scrollTop=Oe)},[t,Y]),y.useLayoutEffect(()=>{Y&&W.current&&z.current&&L.current&&Whe(W.current,z.current,L.current)},[M,Y,E.size]),y.useEffect(()=>{if(E.size!=="closed"||!O.current||!z.current)return;const D=Array.from(z.current.children).find(ze=>ze.textContent?.includes(O.current));if(!D)return;D.classList.add("reader-return-highlight");const Oe=setTimeout(()=>D.classList.remove("reader-return-highlight"),1800);return()=>{clearTimeout(Oe),D.classList.remove("reader-return-highlight")}},[E.size]),y.useEffect(()=>{te.invoke("file_watch_paths",{paths:[t]}).catch(()=>{});const D=te.on("file-changed",Oe=>{if(!(!Array.isArray(Oe)||!Oe.includes(t))){if(ee.current!==Q.current){k(!0);return}J(!0)}});return()=>{D(),te.invoke("file_watch_paths",{paths:[]}).catch(()=>{})}},[t,J]);const P=y.useCallback(()=>{const D=window.getSelection();if(!D||D.isCollapsed||D.rangeCount===0)return j(null);const Oe=D.getRangeAt(0),ze=z.current;if(!ze||!ze.contains(Oe.commonAncestorContainer))return j(null);const Ce=D.toString();if(!Ce.trim())return j(null);const ve=ee.current.indexOf(Ce),ae=ve>=0&&ee.current.lastIndexOf(Ce)===ve?qT(ee.current,ve,ve+Ce.length):{from:0,to:0},$e=Oe.getBoundingClientRect();j({quote:{path:t,text:Ce,...ae},x:$e.left+$e.width/2,y:$e.top})},[t]);y.useEffect(()=>{const D=()=>{requestAnimationFrame(P)};return document.addEventListener("selectionchange",D),()=>document.removeEventListener("selectionchange",D)},[P]);const ne=y.useCallback(D=>{if(!D.text.trim())return j(null);const Oe=ee.current,ze=H.current??Ghe(F.current);j({quote:{path:t,text:D.text,...qT(Oe,D.from,D.to)},...ze})},[t]),he=y.useCallback(()=>{N&&(O.current=N.quote.text,W.current&&z.current&&(L.current=LS(W.current,z.current)),E.show(),Hre(N.quote),j(null))},[N,E]);y.useEffect(()=>{const D=()=>{const ze=document.activeElement;return!ze||ze===document.body||!!F.current?.contains(ze)},Oe=ze=>{if(D()){if(ze.key==="Escape"){if(N)return j(null);if(E.size!=="closed")return E.collapse();U||n()}ze.key==="s"&&(ze.metaKey||ze.ctrlKey)&&(ze.preventDefault(),le())}};return window.addEventListener("keydown",Oe),()=>window.removeEventListener("keydown",Oe)});async function le(){if(!(!I||m)){g(!0),o(null);try{await te.invoke("write_file",{path:t,content:l}),i(D=>D&&{...D,content:l}),b(!0),setTimeout(()=>b(!1),1600)}catch(D){o(String(D.message??D))}finally{g(!1)}}}async function oe(){U&&!await q({title:"Close without saving?",body:`Your changes to ${ks(t)} will be lost.`,confirmLabel:"Discard changes",danger:!0})||n()}const ye=typeof document>"u"?null:document.getElementById(Vhe);return ye?a.jsxs(a.Fragment,{children:[Eo.createPortal(a.jsxs(a.Fragment,{children:[a.jsx("div",{className:`fpanel-scrim ${B&&e?"is-open":""}`,onClick:()=>{oe()},"aria-hidden":"true"}),a.jsxs("aside",{ref:F,className:`fpanel ${B&&e?"is-open":""}`,"aria-label":ks(t),style:{"--gitp-w":`${$}px`},onPointerUp:D=>{H.current={x:D.clientX,y:D.clientY},P()},children:[a.jsx("div",{className:"gitp-resizer",role:"separator","aria-orientation":"vertical","aria-label":"Resize the file panel",onPointerDown:G}),a.jsxs("header",{className:"panel-head",children:[a.jsxs("div",{className:"panel-id",children:[a.jsxs("div",{className:"panel-name",children:[ks(t),U&&a.jsx("span",{className:"panel-dirty",title:"Unsaved changes"})]}),a.jsx("div",{className:"panel-path",children:a.jsx("bdi",{children:t})})]}),a.jsxs("span",{className:"panel-acts",children:[a.jsx(Ux,{className:"panel-act",icon:a.jsx(_0,{}),idle:"Copy the path",done:"Path copied",read:()=>({text:t})}),s?.kind==="text"&&a.jsx(Ux,{className:"panel-act",icon:a.jsx(t$,{}),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:l,partial:s.truncated})})]}),Ore(t,s)&&a.jsx("button",{className:"panel-btn",type:"button",onClick:()=>f(D=>!D),children:h?"Preview":"Edit"}),s?.kind==="text"&&!s.truncated&&a.jsx("button",{className:"panel-btn is-primary",type:"button",onClick:le,disabled:!I||m,children:m?"Saving…":x?"Saved":"Save"}),a.jsx("button",{className:"panel-close",type:"button",onClick:()=>{oe()},"aria-label":"Close",children:"✕"})]}),r&&a.jsxs("div",{className:"panel-error",children:[r,a.jsx(k7,{path:t},t)]}),_&&a.jsxs("div",{className:"panel-warn is-stale",children:["This file changed on disk while you were editing it.",a.jsx("button",{className:"panel-inline-btn",type:"button",onClick:()=>{J(!0)},children:"Reload and lose my changes"})]}),s?.truncated&&a.jsxs("div",{className:"panel-warn",children:["Showing the first ",a.jsx(Kt,{children:b4(s.content.length)})," of"," ",a.jsx(Kt,{children:b4(s.size)}),". Saving is off for this file — writing back what is on screen would cut the rest away."]}),a.jsxs("div",{className:"panel-body",ref:W,onScroll:D=>{Y&&($$(Yw("prose",t),D.currentTarget.scrollTop),z.current&&(L.current=LS(D.currentTarget,z.current)))},children:[!s&&!r&&a.jsx("div",{className:"dots","aria-label":"loading"}),s&&a.jsx($he,{path:t,preview:s,draft:l,raw:h,generation:M,onDraft:u,onSave:()=>{le()},onSelect:ne,onProseRef:D=>{z.current=D}})]}),E.launcher]})]}),ye),E.controls,N&&Wre()&&Eo.createPortal(a.jsxs("button",{className:"quote-btn reader-quote",type:"button",style:{left:`${N.x}px`,top:`${N.y}px`},onMouseDown:D=>D.preventDefault(),onPointerDown:D=>D.preventDefault(),onClick:he,children:[a.jsx("span",{className:"quote-btn-plus","aria-hidden":"true",children:"+"}),"Add to chat",N.quote.from>0&&a.jsx("span",{className:"quote-btn-at",children:N.quote.to>N.quote.from?`${N.quote.from}–${N.quote.to}`:N.quote.from})]}),document.body)]}):null}function Ghe(t){if(!t)return{x:24,y:80};const e=t.getBoundingClientRect();return{x:e.left+e.width/2,y:e.top+40}}const Fc=1,C7=8,w4=[1,1.5,2,3,4,6,8],Yhe=400;function ME(t){return Number.isFinite(t)?Math.min(C7,Math.max(Fc,t)):Fc}function vb(t,e){const n=ME(t);return(e>0?w4.find(i=>i>n+1e-6):[...w4].reverse().find(i=>i<n-1e-6))??n}function Xhe(t,e){return ME(t*Math.exp(-e/Yhe))}function Qhe(t,e,n,s){const i=s/n;return{x:e.x-(e.x-t.x)*i,y:e.y-(e.y-t.y)*i}}function Zhe(t,e,n,s){const i=(l,u)=>Math.max(0,(u*s-l)/2),r=i(e.w,n.w),o=i(e.h,n.h);return{x:Math.min(r,Math.max(-r,t.x)),y:Math.min(o,Math.max(-o,t.y))}}const aw={x:0,y:0},_4=4,xb={scale:Fc,pan:aw};function j7({path:t,onClose:e}){const[n,s]=y.useState(null),[i,r]=y.useState(null),[o,l]=y.useState(xb),u=y.useRef(null),h=y.useRef(null),f=QA(t);y.useEffect(()=>{let O=!0,X=null;return l(xb),te.fetchFile(t).then(q=>{O&&(X=URL.createObjectURL(q),s(X))}).catch(q=>O&&r(q.message)),()=>{O=!1,X&&URL.revokeObjectURL(X)}},[t]);const m=y.useCallback((O,X,q)=>{const $=ME(X),G=u.current,B=h.current,F={w:G?.clientWidth??0,h:G?.clientHeight??0},z={w:B?.offsetWidth??0,h:B?.offsetHeight??0};return{scale:$,pan:Zhe(Qhe(O.pan,q,O.scale,$),F,z,$)}},[]),g=y.useCallback((O,X=aw)=>l(q=>m(q,O(q.scale),X)),[m]),x=y.useCallback((O,X)=>{const q=u.current?.getBoundingClientRect();return q?{x:O-(q.left+q.width/2),y:X-(q.top+q.height/2)}:aw},[]);y.useEffect(()=>{const O=u.current;if(!O||f)return;const X=q=>{q.preventDefault();const $=q.ctrlKey?q.deltaY*3:q.deltaY;g(G=>Xhe(G,$),x(q.clientX,q.clientY))};return O.addEventListener("wheel",X,{passive:!1}),()=>O.removeEventListener("wheel",X)},[x,f,n,g]),y.useEffect(()=>{const O=X=>{if(X.key==="Escape")return e();if(f||X.metaKey||X.ctrlKey||X.altKey)return;const q=X.target;q&&(q.tagName==="INPUT"||q.tagName==="TEXTAREA"||q.isContentEditable)||(X.key==="+"||X.key==="="?g($=>vb($,1)):X.key==="-"||X.key==="_"?g($=>vb($,-1)):X.key==="0"&&l(xb))};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[e,f,g]);const b=y.useRef(new Map),_=y.useRef(null),k=y.useRef(null),N=y.useRef(!1),j=()=>{const[O,X]=[...b.current.values()];return Math.hypot(O.x-X.x,O.y-X.y)},M=()=>{const[O,X]=[...b.current.values()];return x((O.x+X.x)/2,(O.y+X.y)/2)};function A(O){if(!f){if(b.current.size===0&&(N.current=!1),b.current.set(O.pointerId,{x:O.clientX,y:O.clientY}),b.current.size===2){_.current=null,k.current=j(),N.current=!0;return}b.current.size>2||o.scale<=Fc||(O.target.setPointerCapture?.(O.pointerId),_.current={id:O.pointerId,from:{x:O.clientX,y:O.clientY},pan:o.pan})}}function E(O){if(!b.current.has(O.pointerId))return;if(b.current.set(O.pointerId,{x:O.clientX,y:O.clientY}),k.current!==null&&b.current.size===2){const G=j(),B=k.current>0?G/k.current:1;k.current=G,g(F=>F*B,M());return}const X=_.current;if(!X||X.id!==O.pointerId)return;const q=O.clientX-X.from.x,$=O.clientY-X.from.y;(Math.abs(q)>_4||Math.abs($)>_4)&&(N.current=!0),l(G=>m({...G,pan:{x:X.pan.x+q,y:X.pan.y+$}},G.scale,aw))}function L(O){b.current.delete(O.pointerId),b.current.size<2&&(k.current=null),_.current?.id===O.pointerId&&(_.current=null)}return Eo.createPortal(a.jsxs("div",{className:"viewer",onClick:()=>N.current?N.current=!1:e(),children:[a.jsxs("div",{className:"viewer-bar",onClick:O=>O.stopPropagation(),children:[a.jsx("span",{className:"viewer-name",children:ks(t)}),!f&&n&&a.jsxs("div",{className:"viewer-zoom",children:[a.jsx("button",{className:"viewer-btn",type:"button",onClick:()=>g(O=>vb(O,-1)),disabled:o.scale<=Fc,"aria-label":"Zoom out",title:"Zoom out (−)",children:"−"}),a.jsx("button",{className:"viewer-level",type:"button",onClick:()=>l(xb),disabled:o.scale<=Fc,title:"Fit to screen (0)",children:a.jsx(Kt,{children:`${Math.round(o.scale*10)/10}×`})}),a.jsx("button",{className:"viewer-btn",type:"button",onClick:()=>g(O=>vb(O,1)),disabled:o.scale>=C7,"aria-label":"Zoom in",title:"Zoom in (+)",children:"+"})]}),a.jsx("button",{className:"viewer-close",type:"button",onClick:e,"aria-label":"Close",children:"✕"})]}),i?a.jsx("div",{className:"viewer-error",children:i}):n?f?a.jsx("iframe",{className:"viewer-pdf",src:n,title:ks(t)}):a.jsx("div",{className:`viewer-stage ${o.scale>Fc?"is-zoomed":""}`,ref:u,onPointerDown:A,onPointerMove:E,onPointerUp:L,onPointerCancel:L,onDoubleClick:O=>g(X=>X>Fc?Fc:2,x(O.clientX,O.clientY)),children:a.jsx("img",{className:"viewer-img",ref:h,src:n,alt:ks(t),draggable:!1,style:{transform:`translate(${o.pan.x}px, ${o.pan.y}px) scale(${o.scale})`},onClick:O=>O.stopPropagation()})}):a.jsx("div",{className:"dots","aria-label":"loading"})]}),document.body)}const Jhe=220;function ede({children:t}){const[e,n]=y.useState(null),[s,i]=y.useState(null),[r,o]=y.useState(null),l=y.useCallback(()=>{n(null),i(null)},[]),u=y.useCallback(h=>{if(I$(h)){i(null),n(null),te.openFileInBrowser(h);return}XA(h)||QA(h)?(i(null),n(h)):(n(null),i(h),o(h))},[]);return y.useEffect(()=>{if(s)return;const h=setTimeout(()=>o(null),Jhe);return()=>clearTimeout(h)},[s]),a.jsx(JB.Provider,{value:u,children:a.jsxs(e$.Provider,{value:l,children:[t,e&&a.jsx(j7,{path:e,onClose:()=>n(null)}),r&&a.jsx(Khe,{path:r,open:!!s,onClose:()=>i(null)})]})})}function N7({attachment:t}){const[e,n]=y.useState(t.url??null);return y.useEffect(()=>{if(t.url){n(t.url);return}let s=!0,i=null;return te.fetchFile(t.path).then(r=>{s&&(i=URL.createObjectURL(r),n(i))}).catch(()=>s&&n(null)),()=>{s=!1,i&&URL.revokeObjectURL(i)}},[t.path,t.url]),e?a.jsx("img",{className:"chip-thumb",src:e,alt:""}):a.jsx(nde,{})}function tde({files:t}){const e=w0();return t.length===0?null:a.jsx("div",{className:"sent-files",children:t.map(n=>a.jsxs("button",{className:`chip ${n.isImage?"is-image":""}`,type:"button",title:`${n.path} — click to open`,onClick:()=>e(n.path),children:[n.isImage?a.jsx(N7,{attachment:n}):a.jsx(sde,{}),a.jsx("span",{className:"chip-name",children:n.name})]},n.path))})}function nde(){return a.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:[a.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2.5"}),a.jsx("circle",{cx:"8.5",cy:"9.5",r:"1.6"}),a.jsx("path",{d:"m4 17 4.5-4.5a2 2 0 0 1 2.8 0L16 17"}),a.jsx("path",{d:"m14 14 1.8-1.8a2 2 0 0 1 2.8 0L21 14.5"})]})}function sde(){return a.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:[a.jsx("path",{d:"M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8Z"}),a.jsx("path",{d:"M14 3v5h5"})]})}function TS(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 ide=42,rde=2.5,ade=320,k4=1500;function ode(){return window.matchMedia?.("(prefers-reduced-motion: reduce)").matches??!1}function lde(t,e){const[n,s]=y.useState(()=>e?0:t.length),i=y.useRef(n),r=y.useRef(0),o=y.useRef(0),l=y.useRef(0),u=y.useRef(e);return i.current=n,e&&(u.current=!0),y.useEffect(()=>{if(ode()||!u.current){i.current!==t.length&&s(t.length);return}if(i.current>t.length){s(t.length);return}const h=f=>{const m=t.length-i.current;if(m<=0){o.current=0,r.current=0;return}const g=o.current?Math.min(f-o.current,100):16;if(o.current=f,m>k4){i.current=t.length-k4,s(i.current),l.current=requestAnimationFrame(h);return}const x=Math.min(ade,Math.max(ide,m/rde));r.current+=x*g/1e3;const b=Math.floor(r.current);b>=1&&(r.current-=b,i.current=Math.min(t.length,i.current+b),s(i.current)),l.current=requestAnimationFrame(h)};return l.current=requestAnimationFrame(h),()=>cancelAnimationFrame(l.current)},[t,e]),t.slice(0,n)}const cde=/^\s{0,3}(`{3,}|~{3,})(.*)$/;function A7(t){return cde.exec(t.endsWith("\r")?t.slice(0,-1):t)}function ude(t){if(!t)return[];const e=t.split(`
84
+ `:s=="r"?"\r":s=="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 whe(this):new xhe(this)}getCursor(e,n=0,s){let i=e.doc?e:Nn.create({doc:e});return s==null&&(s=i.doc.length),this.regexp?om(this,i,n,s):am(this,i,n,s)}}class v7{constructor(e){this.spec=e}}function ghe(t,e,n){return(s,i,r,o)=>{if(n&&!n(s,i,r,o))return!1;let l=s>=o&&i<=o+r.length?r.slice(s-o,i-o):e.doc.sliceString(s,i);return t(l,e,s,i)}}function am(t,e,n,s){let i;return t.wholeWord&&(i=vhe(e.doc,e.charCategorizer(e.selection.main.head))),t.test&&(i=ghe(t.test,e,i)),new Jm(e.doc,t.unquoted,n,s,t.caseSensitive?void 0:r=>r.toLowerCase(),i)}function vhe(t,e){return(n,s,i,r)=>((r>n||r+i.length<s)&&(r=Math.max(0,n-2),i=t.sliceString(r,Math.min(t.length,s+2))),(e(d_(i,n-r))!=Xs.Word||e(f_(i,n-r))!=Xs.Word)&&(e(f_(i,s-r))!=Xs.Word||e(d_(i,s-r))!=Xs.Word))}class xhe extends v7{constructor(e){super(e)}nextMatch(e,n,s){let i=am(this.spec,e,s,e.doc.length).nextOverlapping();if(i.done){let r=Math.min(e.doc.length,n+this.spec.unquoted.length);i=am(this.spec,e,0,r).nextOverlapping()}return i.done||i.value.from==n&&i.value.to==s?null:i.value}prevMatchInRange(e,n,s){for(let i=s;;){let r=Math.max(n,i-1e4-this.spec.unquoted.length),o=am(this.spec,e,r,i),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(r==n)return null;i-=1e4}}prevMatch(e,n,s){let i=this.prevMatchInRange(e,0,n);return i||(i=this.prevMatchInRange(e,Math.max(0,s-this.spec.unquoted.length),e.doc.length)),i&&(i.from!=n||i.to!=s)?i:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,n){let s=am(this.spec,e,0,e.doc.length),i=[];for(;!s.next().done;){if(i.length>=n)return null;i.push(s.value)}return i}highlight(e,n,s,i){let r=am(this.spec,e,Math.max(0,n-this.spec.unquoted.length),Math.min(s+this.spec.unquoted.length,e.doc.length));for(;!r.next().done;)i(r.value.from,r.value.to)}}function yhe(t,e,n){return(s,i,r)=>(!n||n(s,i,r))&&t(r[0],e,s,i)}function om(t,e,n,s){let i;return t.wholeWord&&(i=bhe(e.charCategorizer(e.selection.main.head))),t.test&&(i=yhe(t.test,e,i)),new p7(e.doc,t.search,{ignoreCase:!t.caseSensitive,test:i},n,s)}function d_(t,e){return t.slice($i(t,e,!1),e)}function f_(t,e){return t.slice(e,$i(t,e))}function bhe(t){return(e,n,s)=>!s[0].length||(t(d_(s.input,s.index))!=Xs.Word||t(f_(s.input,s.index))!=Xs.Word)&&(t(f_(s.input,s.index+s[0].length))!=Xs.Word||t(d_(s.input,s.index+s[0].length))!=Xs.Word)}class whe extends v7{nextMatch(e,n,s){let i=om(this.spec,e,s,e.doc.length).next();return i.done&&(i=om(this.spec,e,0,n).next()),i.done?null:i.value}prevMatchInRange(e,n,s){for(let i=1;;i++){let r=Math.max(n,s-i*1e4),o=om(this.spec,e,r,s),l=null;for(;!o.next().done;)l=o.value;if(l&&(r==n||l.from>r+10))return l;if(r==n)return null}}prevMatch(e,n,s){return this.prevMatchInRange(e,0,n)||this.prevMatchInRange(e,s,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(n,s)=>{if(s=="&")return e.match[0];if(s=="$")return"$";for(let i=s.length;i>0;i--){let r=+s.slice(0,i);if(r>0&&r<e.match.length)return e.match[r]+s.slice(i)}return n})}matchAll(e,n){let s=om(this.spec,e,0,e.doc.length),i=[];for(;!s.next().done;){if(i.length>=n)return null;i.push(s.value)}return i}highlight(e,n,s,i){let r=om(this.spec,e,Math.max(0,n-250),Math.min(s+250,e.doc.length));for(;!r.next().done;)i(r.value.from,r.value.to)}}const n0=ss.define(),NE=ss.define(),_h=Kl.define({create(t){return new MS(a2(t).create(),null)},update(t,e){for(let n of e.effects)n.is(n0)?t=new MS(n.value.create(),t.panel):n.is(NE)&&(t=new MS(t.query,n.value?AE:null));return t},provide:t=>o_.from(t,e=>e.panel)});class MS{constructor(e,n){this.query=e,this.panel=n}}const _he=sn.mark({class:"cm-searchMatch"}),khe=sn.mark({class:"cm-searchMatch cm-searchMatch-selected"}),She=Pr.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(_h))}update(t){let e=t.state.field(_h);(e!=t.startState.field(_h)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return sn.none;let{view:n}=this,s=new xf;for(let i=0,r=n.visibleRanges,o=r.length;i<o;i++){let{from:l,to:u}=r[i];for(;i<o-1&&u>r[i+1].from-500;)u=r[++i].to;t.highlight(n.state,l,u,(h,f)=>{let m=n.state.selection.ranges.some(g=>g.from==h&&g.to==f);s.add(h,f,m?khe:_he)})}return s.finish()}},{decorations:t=>t.decorations});function M0(t){return e=>{let n=e.state.field(_h,!1);return n&&n.query.spec.valid?t(e,n):b7(e)}}const p_=M0((t,{query:e})=>{let{to:n}=t.state.selection.main,s=e.nextMatch(t.state,n,n);if(!s)return!1;let i=De.single(s.from,s.to),r=t.state.facet(Lf);return t.dispatch({selection:i,effects:[EE(t,s),r.scrollToMatch(i.main,t)],userEvent:"select.search"}),y7(t),!0}),m_=M0((t,{query:e})=>{let{state:n}=t,{from:s}=n.selection.main,i=e.prevMatch(n,s,s);if(!i)return!1;let r=De.single(i.from,i.to),o=t.state.facet(Lf);return t.dispatch({selection:r,effects:[EE(t,i),o.scrollToMatch(r.main,t)],userEvent:"select.search"}),y7(t),!0}),Che=M0((t,{query:e})=>{let n=e.matchAll(t.state,1e3);return!n||!n.length?!1:(t.dispatch({selection:De.create(n.map(s=>De.range(s.from,s.to))),userEvent:"select.search.matches"}),!0)}),jhe=({state:t,dispatch:e})=>{let n=t.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:s,to:i}=n.main,r=[],o=0;for(let l=new Jm(t.doc,t.sliceDoc(s,i));!l.next().done;){if(r.length>1e3)return!1;l.value.from==s&&(o=r.length),r.push(De.range(l.value.from,l.value.to))}return e(t.update({selection:De.create(r,o),userEvent:"select.search.matches"})),!0},x4=M0((t,{query:e})=>{let{state:n}=t,{from:s,to:i}=n.selection.main;if(n.readOnly)return!1;let r=e.nextMatch(n,s,s);if(!r)return!1;let o=r,l=[],u,h,f=[];o.precise?o.from==s&&o.to==i&&(h=n.toText(e.getReplacement(o)),l.push({from:o.from,to:o.to,insert:h}),o=e.nextMatch(n,o.from,o.to),f.push(pt.announce.of(n.phrase("replaced match on line $",n.doc.lineAt(s).number)+"."))):o=e.nextMatch(n,o.from,o.to);let m=t.state.changes(l);return o&&(u=De.single(o.from,o.to).map(m),f.push(EE(t,o)),f.push(n.facet(Lf).scrollToMatch(u.main,t))),t.dispatch({changes:m,selection:u,effects:f,userEvent:"input.replace"}),!0}),Nhe=M0((t,{query:e})=>{if(t.state.readOnly)return!1;let n=[];for(let i of e.matchAll(t.state,1e9)){let{from:r,to:o,precise:l}=i;l&&n.push({from:r,to:o,insert:e.getReplacement(i)})}if(!n.length)return!1;let s=t.state.phrase("replaced $ matches",n.length)+".";return t.dispatch({changes:n,effects:pt.announce.of(s),userEvent:"input.replace.all"}),!0});function AE(t){return t.state.facet(Lf).createPanel(t)}function a2(t,e){var n,s,i,r,o;let l=t.selection.main,u=l.empty||l.to>l.from+100?"":t.sliceDoc(l.from,l.to);if(e&&!u)return e;let h=t.facet(Lf);return new g7({search:((n=e?.literal)!==null&&n!==void 0?n:h.literal)?u:u.replace(/\n/g,"\\n"),caseSensitive:(s=e?.caseSensitive)!==null&&s!==void 0?s:h.caseSensitive,literal:(i=e?.literal)!==null&&i!==void 0?i:h.literal,regexp:(r=e?.regexp)!==null&&r!==void 0?r:h.regexp,wholeWord:(o=e?.wholeWord)!==null&&o!==void 0?o:h.wholeWord})}function x7(t){let e=lP(t,AE);return e&&e.dom.querySelector("[main-field]")}function y7(t){let e=x7(t);e&&e==t.root.activeElement&&e.select()}const b7=t=>{let e=t.state.field(_h,!1);if(e&&e.panel){let n=x7(t);if(n&&n!=t.root.activeElement){let s=a2(t.state,e.query.spec);s.valid&&t.dispatch({effects:n0.of(s)}),n.focus(),n.select()}}else t.dispatch({effects:[NE.of(!0),e?n0.of(a2(t.state,e.query.spec)):ss.appendConfig.of(o2)]});return!0},w7=t=>{let e=t.state.field(_h,!1);if(!e||!e.panel)return!1;let n=lP(t,AE);return n&&n.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:NE.of(!1)}),!0},Ahe=[{key:"Mod-f",run:b7,scope:"editor search-panel"},{key:"F3",run:p_,shift:m_,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:p_,shift:m_,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:w7,scope:"editor search-panel"},{key:"Mod-Shift-l",run:jhe},{key:"Mod-Alt-g",run:she},{key:"Mod-d",run:phe,preventDefault:!0}];class Ehe{constructor(e){this.view=e;let n=this.query=e.state.field(_h).query.spec;this.commit=this.commit.bind(this),this.searchField=Mi("input",{value:n.search,placeholder:Ta(e,"Find"),"aria-label":Ta(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=Mi("input",{value:n.replace,placeholder:Ta(e,"Replace"),"aria-label":Ta(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=Mi("input",{type:"checkbox",name:"case",form:"",checked:n.caseSensitive,onchange:this.commit}),this.reField=Mi("input",{type:"checkbox",name:"re",form:"",checked:n.regexp,onchange:this.commit}),this.wordField=Mi("input",{type:"checkbox",name:"word",form:"",checked:n.wholeWord,onchange:this.commit});function s(i,r,o){return Mi("button",{class:"cm-button",name:i,onclick:r,type:"button"},o)}this.dom=Mi("div",{onkeydown:i=>this.keydown(i),class:"cm-search"},[this.searchField,s("next",()=>p_(e),[Ta(e,"next")]),s("prev",()=>m_(e),[Ta(e,"previous")]),s("select",()=>Che(e),[Ta(e,"all")]),Mi("label",null,[this.caseField,Ta(e,"match case")]),Mi("label",null,[this.reField,Ta(e,"regexp")]),Mi("label",null,[this.wordField,Ta(e,"by word")]),...e.state.readOnly?[]:[Mi("br"),this.replaceField,s("replace",()=>x4(e),[Ta(e,"replace")]),s("replaceAll",()=>Nhe(e),[Ta(e,"replace all")])],Mi("button",{name:"close",onclick:()=>w7(e),"aria-label":Ta(e,"close"),type:"button"},["×"])])}commit(){let e=new g7({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:n0.of(e)}))}keydown(e){Zoe(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?m_:p_)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),x4(this.view))}update(e){for(let n of e.transactions)for(let s of n.effects)s.is(n0)&&!s.value.eq(this.query)&&this.setQuery(s.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(Lf).top}}function Ta(t,e){return t.state.phrase(e)}const mb=30,gb=/[\s\.,:;?!]/;function EE(t,{from:e,to:n}){let s=t.state.doc.lineAt(e),i=t.state.doc.lineAt(n).to,r=Math.max(s.from,e-mb),o=Math.min(i,n+mb),l=t.state.sliceDoc(r,o);if(r!=s.from){for(let u=0;u<mb;u++)if(!gb.test(l[u+1])&&gb.test(l[u])){l=l.slice(u);break}}if(o!=i){for(let u=l.length-1;u>l.length-mb;u--)if(!gb.test(l[u-1])&&gb.test(l[u])){l=l.slice(0,u);break}}return pt.announce.of(`${t.state.phrase("current match")}. ${l} ${t.state.phrase("on line")} ${s.number}.`)}const Mhe=pt.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"}}),o2=[_h,S0.low(She),Mhe],Mn=t=>bE.define(t),Lhe={js:()=>vt(()=>import("./index-DNdWJa_x.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript()),mjs:()=>vt(()=>import("./index-DNdWJa_x.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript()),cjs:()=>vt(()=>import("./index-DNdWJa_x.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript()),jsx:()=>vt(()=>import("./index-DNdWJa_x.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({jsx:!0})),ts:()=>vt(()=>import("./index-DNdWJa_x.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({typescript:!0})),mts:()=>vt(()=>import("./index-DNdWJa_x.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({typescript:!0})),cts:()=>vt(()=>import("./index-DNdWJa_x.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({typescript:!0})),tsx:()=>vt(()=>import("./index-DNdWJa_x.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(t=>t.javascript({jsx:!0,typescript:!0})),json:()=>vt(()=>import("./index-9ROAFG8N.js"),__vite__mapDeps([3,1]),import.meta.url).then(t=>t.json()),jsonc:()=>vt(()=>import("./index-9ROAFG8N.js"),__vite__mapDeps([3,1]),import.meta.url).then(t=>t.json()),md:()=>vt(()=>import("./index-CkkiNkM6.js"),__vite__mapDeps([4,2,5,1,6,0]),import.meta.url).then(t=>t.markdown()),markdown:()=>vt(()=>import("./index-CkkiNkM6.js"),__vite__mapDeps([4,2,5,1,6,0]),import.meta.url).then(t=>t.markdown()),mdx:()=>vt(()=>import("./index-CkkiNkM6.js"),__vite__mapDeps([4,2,5,1,6,0]),import.meta.url).then(t=>t.markdown()),html:()=>vt(()=>import("./index-EbE9Equf.js"),__vite__mapDeps([5,1,6,0,2]),import.meta.url).then(t=>t.html()),htm:()=>vt(()=>import("./index-EbE9Equf.js"),__vite__mapDeps([5,1,6,0,2]),import.meta.url).then(t=>t.html()),cshtml:()=>vt(()=>import("./index-EbE9Equf.js"),__vite__mapDeps([5,1,6,0,2]),import.meta.url).then(t=>t.html()),vue:()=>vt(()=>import("./index-EbE9Equf.js"),__vite__mapDeps([5,1,6,0,2]),import.meta.url).then(t=>t.html()),css:()=>vt(()=>import("./index-BhWK4R0o.js"),__vite__mapDeps([6,1]),import.meta.url).then(t=>t.css()),scss:()=>vt(()=>import("./index-BhWK4R0o.js"),__vite__mapDeps([6,1]),import.meta.url).then(t=>t.css()),less:()=>vt(()=>import("./index-BhWK4R0o.js"),__vite__mapDeps([6,1]),import.meta.url).then(t=>t.css()),rs:()=>vt(()=>import("./index-DgVqfi3n.js"),__vite__mapDeps([7,1]),import.meta.url).then(t=>t.rust()),py:()=>vt(()=>import("./index-RUqxFSoX.js"),__vite__mapDeps([8,1,2]),import.meta.url).then(t=>t.python()),pyi:()=>vt(()=>import("./index-RUqxFSoX.js"),__vite__mapDeps([8,1,2]),import.meta.url).then(t=>t.python()),sql:()=>vt(()=>import("./index-CKZbCF5Y.js"),__vite__mapDeps([9,1,2]),import.meta.url).then(t=>t.sql()),yaml:()=>vt(()=>import("./index-C0op0LaU.js"),__vite__mapDeps([10,1]),import.meta.url).then(t=>t.yaml()),yml:()=>vt(()=>import("./index-C0op0LaU.js"),__vite__mapDeps([10,1]),import.meta.url).then(t=>t.yaml()),sh:()=>vt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>Mn(t.shell)),bash:()=>vt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>Mn(t.shell)),zsh:()=>vt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>Mn(t.shell)),fish:()=>vt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>Mn(t.shell)),cs:()=>vt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>Mn(t.csharp)),c:()=>vt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>Mn(t.c)),h:()=>vt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>Mn(t.c)),cpp:()=>vt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>Mn(t.cpp)),hpp:()=>vt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>Mn(t.cpp)),java:()=>vt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>Mn(t.java)),kt:()=>vt(()=>import("./clike-B9uivgTg.js"),[],import.meta.url).then(t=>Mn(t.kotlin)),swift:()=>vt(()=>import("./swift-BzpIVaGY.js"),[],import.meta.url).then(t=>Mn(t.swift)),go:()=>vt(()=>import("./go-CTD25R5P.js"),[],import.meta.url).then(t=>Mn(t.go)),rb:()=>vt(()=>import("./ruby-B2Rjki9n.js"),[],import.meta.url).then(t=>Mn(t.ruby)),lua:()=>vt(()=>import("./lua-VAEuO923.js"),[],import.meta.url).then(t=>Mn(t.lua)),toml:()=>vt(()=>import("./toml-Bm5Em-hy.js"),[],import.meta.url).then(t=>Mn(t.toml)),xml:()=>vt(()=>import("./xml-BQQZnNBQ.js"),[],import.meta.url).then(t=>Mn(t.xml)),svg:()=>vt(()=>import("./xml-BQQZnNBQ.js"),[],import.meta.url).then(t=>Mn(t.xml)),xaml:()=>vt(()=>import("./xml-BQQZnNBQ.js"),[],import.meta.url).then(t=>Mn(t.xml)),csproj:()=>vt(()=>import("./xml-BQQZnNBQ.js"),[],import.meta.url).then(t=>Mn(t.xml)),diff:()=>vt(()=>import("./diff-DbItnlRl.js"),[],import.meta.url).then(t=>Mn(t.diff)),patch:()=>vt(()=>import("./diff-DbItnlRl.js"),[],import.meta.url).then(t=>Mn(t.diff)),ps1:()=>vt(()=>import("./powershell-CFHJl5sT.js"),[],import.meta.url).then(t=>Mn(t.powerShell)),properties:()=>vt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>Mn(t.properties)),ini:()=>vt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>Mn(t.properties)),env:()=>vt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>Mn(t.properties))},y4={dockerfile:()=>vt(()=>import("./dockerfile-ZL4hHokT.js"),[],import.meta.url).then(t=>Mn(t.dockerFile)),makefile:()=>vt(()=>import("./shell-CjFT_Tl9.js"),[],import.meta.url).then(t=>Mn(t.shell)),".env":()=>vt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>Mn(t.properties)),".gitignore":()=>vt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>Mn(t.properties)),".dockerignore":()=>vt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>Mn(t.properties)),".editorconfig":()=>vt(()=>import("./properties-C78fOPTZ.js"),[],import.meta.url).then(t=>Mn(t.properties))};async function The(t){const e=(t.split("/").pop()??t).toLowerCase(),n=y4[e]??y4[e.slice(0,e.indexOf(".",1))];if(n)return n();const s=e.lastIndexOf(".");if(s<=0)return null;const i=Lhe[e.slice(s+1)];return i?i():null}const Rhe=h1.define([{tag:[Ke.comment,Ke.lineComment,Ke.blockComment,Ke.docComment],color:"var(--syntax-comment)",fontStyle:"italic"},{tag:[Ke.keyword,Ke.modifier,Ke.controlKeyword,Ke.moduleKeyword],color:"var(--syntax-keyword)"},{tag:[Ke.string,Ke.special(Ke.string),Ke.regexp],color:"var(--syntax-string)"},{tag:[Ke.number,Ke.bool,Ke.null,Ke.atom],color:"var(--syntax-number)"},{tag:[Ke.function(Ke.variableName),Ke.function(Ke.propertyName),Ke.labelName],color:"var(--syntax-function)"},{tag:[Ke.typeName,Ke.className,Ke.namespace,Ke.self],color:"var(--syntax-type)"},{tag:[Ke.propertyName,Ke.attributeName],color:"var(--syntax-property)"},{tag:[Ke.variableName,Ke.definition(Ke.variableName)],color:"var(--fg-1)"},{tag:[Ke.operator,Ke.punctuation,Ke.separator,Ke.bracket],color:"var(--fg-2)"},{tag:[Ke.tagName],color:"var(--syntax-property)"},{tag:[Ke.heading],color:"var(--syntax-function)",fontWeight:"600"},{tag:[Ke.link,Ke.url],color:"var(--link)",textDecoration:"underline"},{tag:[Ke.emphasis],fontStyle:"italic"},{tag:[Ke.strong],fontWeight:"600"},{tag:[Ke.invalid],color:"var(--syntax-property)"}]),Dhe=pt.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 Ohe({path:t,initialDoc:e,readOnly:n=!1,onChange:s,onSave:i,onSelect:r}){const o=y.useRef(null),l=y.useRef(null),u=y.useRef(s),h=y.useRef(i),f=y.useRef(r);return u.current=s,h.current=i,f.current=r,y.useEffect(()=>{const m=o.current;if(!m)return;const g=new C0,x=Nn.create({doc:e,extensions:[Ble(),zle(),ble(),ple(),Zce(),ile(),jle(),wce(),Tce(),ahe(),mhe({top:!0}),pt.lineWrapping,c1.of(" "),kce(Rhe),Dhe,g.of([]),Nn.readOnly.of(n),pt.editable.of(!n),pt.contentAttributes.of({autocapitalize:"off",autocorrect:"off",spellcheck:"false"}),nP.of([{key:"Mod-s",preventDefault:!0,run:()=>(h.current(),!0)},{key:"Escape",run:j=>(j.contentDOM.blur(),!0)},...Ahe,...oue,...ehe,the]),pt.updateListener.of(j=>{if(j.docChanged&&u.current(j.state.doc.toString()),j.selectionSet||j.docChanged){const{from:M,to:A}=j.state.selection.main;f.current?.({from:M,to:A,text:M===A?"":j.state.doc.sliceString(M,A)})}})]}),b=new pt({state:x,parent:m});l.current=b;const _=P$(Yw("code",t));_&&b.dispatch({effects:_});const k=()=>$$(Yw("code",t),b.scrollSnapshot());b.scrollDOM.addEventListener("scroll",k,{passive:!0});let N=!0;return The(t).then(j=>{!N||!j||b.dispatch({effects:g.reconfigure(j)})}).catch(()=>{}),()=>{N=!1,b.scrollDOM.removeEventListener("scroll",k),b.destroy(),l.current=null}},[t,n]),y.useEffect(()=>{const m=o.current;if(!m||typeof IntersectionObserver>"u")return;const g=new IntersectionObserver(x=>{x.some(b=>b.isIntersecting)&&l.current?.requestMeasure()});return g.observe(m),()=>g.disconnect()},[]),a.jsx("div",{className:"ws-cm",ref:o})}function _7({children:t}){return a.jsx("div",{className:"prose-table",children:a.jsx("table",{children:t})})}const Ihe={a:PA,table:_7};function Bhe(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} kB`:`${(t/(1024*1024)).toFixed(1)} MB`}function $he({path:t,preview:e,draft:n,onDraft:s,onSave:i,raw:r,generation:o,onProseRef:l,onSelect:u}){if(!e)return a.jsx("div",{className:"dots","aria-label":"loading"});const h=ZA(t,e),f=r&&(h==="prose"||h==="page")?"code":h;return f==="image"?a.jsx(zhe,{path:t}):f==="video"?a.jsx(Fhe,{path:t,size:e.size},`${t}:${o??0}`):f==="none"?a.jsx(S7,{path:t,preview:e}):f==="page"?a.jsx(Phe,{path:t,html:n}):f==="prose"?a.jsx("div",{className:"prose panel-prose",ref:l,children:a.jsx(MA,{remarkPlugins:[DA],components:Ihe,children:n})}):a.jsx(Ohe,{path:t,initialDoc:e.content,readOnly:e.truncated,onChange:s,onSave:()=>i?.(),onSelect:u},`${t}:${o??0}`)}function k7({path:t}){const[e,n]=y.useState(!1),[s,i]=y.useState(null),[r,o]=y.useState(!1);async function l(){n(!0),i(null),o(!1);try{await te.invoke("open_file_native",{path:t}),o(!0)}catch(u){i(u instanceof Error?u.message:String(u))}finally{n(!1)}}return a.jsxs("div",{className:"native-open",children:[a.jsx("button",{className:"native-open-btn",type:"button",disabled:e,onClick:()=>{l()},children:e?"Opening…":"Open in default app"}),a.jsx("p",{className:"native-open-note",children:"On the computer running OctiqFlow"}),r&&a.jsx("p",{className:"native-open-status",role:"status",children:"Opened."}),s&&a.jsx("p",{className:"native-open-error",role:"alert",children:s})]})}function S7({path:t,preview:e,reason:n="Preview unavailable"}){const s=e.kind==="pdf"?"PDF document":"File";return a.jsxs("div",{className:"panel-unsupported",children:[a.jsxs("div",{className:"panel-unsupported-copy",children:[a.jsx("strong",{children:n}),a.jsxs("span",{children:[s," · ",a.jsx(Kt,{children:Bhe(e.size)})]})]}),a.jsx(k7,{path:t},t)]})}function Phe({path:t,html:e}){return a.jsx("iframe",{className:"panel-page",title:`${ks(t)} — preview`,srcDoc:e,sandbox:"allow-scripts allow-popups",referrerPolicy:"no-referrer"})}function zhe({path:t}){const[e,n]=y.useState(null),[s,i]=y.useState(null),r=y.useRef(null);return y.useEffect(()=>{let o=!0;return te.fetchFile(t).then(l=>{o&&(r.current=URL.createObjectURL(l),n(r.current))}).catch(l=>o&&i(l.message)),()=>{o=!1,r.current&&URL.revokeObjectURL(r.current)}},[t]),s?a.jsx("div",{className:"panel-error",children:s}):e?a.jsx("div",{className:"ws-image",children:a.jsx("img",{src:e,alt:ks(t)})}):a.jsx("div",{className:"dots","aria-label":"loading"})}function Fhe({path:t,size:e}){const[n,s]=y.useState(!1);return n?a.jsx(S7,{path:t,preview:{kind:"video",content:"",truncated:!1,size:e},reason:"This video can’t play in this browser"}):a.jsx("div",{className:"ws-video",children:a.jsx("video",{src:te.fileUrl(t),controls:!0,playsInline:!0,preload:"metadata","aria-label":ks(t),onError:()=>s(!0)})})}function Hhe(t,e){const[n,s]=y.useState("closed"),[i,r]=y.useState(null),o=y.useRef(null),l=y.useRef(!1),u=y.useRef(null);y.useLayoutEffect(()=>s("closed"),[e]),y.useLayoutEffect(()=>{const x=document.getElementById("dock"),b=x?.querySelector(".main:not([hidden])"),_=x?.closest(".app"),k=window.matchMedia("(max-width: 700px)");if(!x||!b||!t){r(null);return}const N=b.inert,j=window.visualViewport,M=()=>{k.matches&&j&&_?.style.setProperty("--reader-viewport-height",`${j.height}px`)},A=()=>{r(k.matches?b:null),k.matches?(x.dataset.readerChat=n,_?.classList.add("is-file-reading"),b.inert=n==="closed",M()):(delete x.dataset.readerChat,_?.classList.remove("is-file-reading"),b.inert=N)};return A(),k.addEventListener("change",A),j?.addEventListener("resize",M),()=>{k.removeEventListener("change",A),j?.removeEventListener("resize",M),b.inert=N,delete x.dataset.readerChat,_?.classList.remove("is-file-reading"),_?.style.removeProperty("--reader-viewport-height")}},[t,n]);function h(){i&&Eo.flushSync(()=>s("half"))}function f(){document.activeElement instanceof HTMLElement&&i?.contains(document.activeElement)&&document.activeElement.blur(),Eo.flushSync(()=>s("closed")),u.current?.focus({preventScroll:!0})}const m=i&&n!=="closed"?Eo.createPortal(a.jsxs("header",{className:"reader-chat-head",children:[a.jsxs("button",{className:"reader-chat-resize",type:"button","aria-label":n==="large"?"Make chat smaller":"Expand chat","aria-expanded":n==="large",onClick:()=>{if(l.current){l.current=!1;return}s(n==="large"?"half":"large")},onPointerDown:x=>{l.current=!1,o.current=x.clientY,x.currentTarget.setPointerCapture(x.pointerId)},onPointerUp:x=>{const b=x.clientY-(o.current??x.clientY);o.current=null,!(Math.abs(b)<30)&&(l.current=!0,x.preventDefault(),b>0?f():s("large"))},onPointerCancel:()=>{o.current=null},children:[a.jsx("span",{className:"reader-chat-grip"}),"Chat"]}),a.jsxs("button",{type:"button",onClick:f,children:["Continue reading ",a.jsx("span",{"aria-hidden":"true",children:"⌄"})]})]}),i):null;return{show:h,collapse:f,size:n,controls:m,launcher:i&&n==="closed"?a.jsxs("button",{ref:u,className:"reader-chat-launch",type:"button",onClick:h,children:[a.jsx("span",{children:"Ask agent / discuss this file"}),a.jsx("span",{"aria-hidden":"true",children:"⌃"})]}):null}}function LS(t,e){const n=t.getBoundingClientRect().top,s=Array.from(e.children),i=Math.max(0,s.findIndex(o=>o.getBoundingClientRect().bottom>n)),r=[i,i+1,i-1];return{scrollTop:t.scrollTop,blocks:r.flatMap(o=>{const l=s[o];return l?[{text:l.textContent??"",index:o,offset:l.getBoundingClientRect().top-n}]:[]})}}function Whe(t,e,n){const s=Array.from(e.children);for(const i of n.blocks){if(!i.text)continue;const r=s.map((o,l)=>({el:o,index:l})).filter(({el:o})=>o.textContent===i.text).sort((o,l)=>Math.abs(o.index-i.index)-Math.abs(l.index-i.index))[0];if(r){t.scrollTop+=r.el.getBoundingClientRect().top-t.getBoundingClientRect().top-i.offset;return}}t.scrollTop=n.scrollTop}const qhe="octiq.v2.fileWidth",Uhe={initial:480,min:320,max:760},Vhe="dock";function b4(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} kB`:`${(t/(1024*1024)).toFixed(1)} MB`}function Khe({path:t,open:e,onClose:n}){const[s,i]=y.useState(null),[r,o]=y.useState(null),[l,u]=y.useState(""),[h,f]=y.useState(!1),[m,g]=y.useState(!1),[x,b]=y.useState(!1),[_,k]=y.useState(!1),[N,j]=y.useState(null),[M,A]=y.useState(0),E=Hhe(e,t),L=y.useRef(null),O=y.useRef(null),X=y.useRef(0),q=k0(),{width:$,startDrag:G,entered:B}=qm(qhe,Uhe),F=y.useRef(null),z=y.useRef(null),W=y.useRef(null),H=y.useRef(null),U=!!s&&l!==s.content,ee=y.useRef(l),Q=y.useRef(s?.content??"");ee.current=l,Q.current=s?.content??"";const I=!!s&&s.kind==="text"&&!s.truncated&&U,Y=!!s&&!h&&ZA(t,s)==="prose",J=y.useCallback(async D=>{const Oe=++X.current,ze=ee.current;try{const Ce=await te.invoke("read_file_preview",{path:t});if(Oe!==X.current)return;if(D&&ee.current!==ze){k(!0);return}D&&W.current&&z.current&&(L.current=LS(W.current,z.current)),i(Ce),u(Ce.content??""),A(ve=>ve+1),j(null),k(!1),o(null),D||f(!1)}catch(Ce){if(Oe!==X.current)return;o(String(Ce.message??Ce))}},[t]);y.useEffect(()=>(i(null),o(null),f(!1),j(null),L.current=null,O.current=null,J(!1),()=>{X.current++}),[t,J]),y.useLayoutEffect(()=>{const D=W.current;if(!D||!Y)return;const Oe=P$(Yw("prose",t));Oe&&(D.scrollTop=Oe)},[t,Y]),y.useLayoutEffect(()=>{Y&&W.current&&z.current&&L.current&&Whe(W.current,z.current,L.current)},[M,Y,E.size]),y.useEffect(()=>{if(E.size!=="closed"||!O.current||!z.current)return;const D=Array.from(z.current.children).find(ze=>ze.textContent?.includes(O.current));if(!D)return;D.classList.add("reader-return-highlight");const Oe=setTimeout(()=>D.classList.remove("reader-return-highlight"),1800);return()=>{clearTimeout(Oe),D.classList.remove("reader-return-highlight")}},[E.size]),y.useEffect(()=>{te.invoke("file_watch_paths",{paths:[t]}).catch(()=>{});const D=te.on("file-changed",Oe=>{if(!(!Array.isArray(Oe)||!Oe.includes(t))){if(ee.current!==Q.current){k(!0);return}J(!0)}});return()=>{D(),te.invoke("file_watch_paths",{paths:[]}).catch(()=>{})}},[t,J]);const P=y.useCallback(()=>{const D=window.getSelection();if(!D||D.isCollapsed||D.rangeCount===0)return j(null);const Oe=D.getRangeAt(0),ze=z.current;if(!ze||!ze.contains(Oe.commonAncestorContainer))return j(null);const Ce=D.toString();if(!Ce.trim())return j(null);const ve=ee.current.indexOf(Ce),ae=ve>=0&&ee.current.lastIndexOf(Ce)===ve?qT(ee.current,ve,ve+Ce.length):{from:0,to:0},$e=Oe.getBoundingClientRect();j({quote:{path:t,text:Ce,...ae},x:$e.left+$e.width/2,y:$e.top})},[t]);y.useEffect(()=>{const D=()=>{requestAnimationFrame(P)};return document.addEventListener("selectionchange",D),()=>document.removeEventListener("selectionchange",D)},[P]);const ne=y.useCallback(D=>{if(!D.text.trim())return j(null);const Oe=ee.current,ze=H.current??Ghe(F.current);j({quote:{path:t,text:D.text,...qT(Oe,D.from,D.to)},...ze})},[t]),he=y.useCallback(()=>{N&&(O.current=N.quote.text,W.current&&z.current&&(L.current=LS(W.current,z.current)),E.show(),Hre(N.quote),j(null))},[N,E]);y.useEffect(()=>{const D=()=>{const ze=document.activeElement;return!ze||ze===document.body||!!F.current?.contains(ze)},Oe=ze=>{if(D()){if(ze.key==="Escape"){if(N)return j(null);if(E.size!=="closed")return E.collapse();U||n()}ze.key==="s"&&(ze.metaKey||ze.ctrlKey)&&(ze.preventDefault(),le())}};return window.addEventListener("keydown",Oe),()=>window.removeEventListener("keydown",Oe)});async function le(){if(!(!I||m)){g(!0),o(null);try{await te.invoke("write_file",{path:t,content:l}),i(D=>D&&{...D,content:l}),b(!0),setTimeout(()=>b(!1),1600)}catch(D){o(String(D.message??D))}finally{g(!1)}}}async function oe(){U&&!await q({title:"Close without saving?",body:`Your changes to ${ks(t)} will be lost.`,confirmLabel:"Discard changes",danger:!0})||n()}const ye=typeof document>"u"?null:document.getElementById(Vhe);return ye?a.jsxs(a.Fragment,{children:[Eo.createPortal(a.jsxs(a.Fragment,{children:[a.jsx("div",{className:`fpanel-scrim ${B&&e?"is-open":""}`,onClick:()=>{oe()},"aria-hidden":"true"}),a.jsxs("aside",{ref:F,className:`fpanel ${B&&e?"is-open":""}`,"aria-label":ks(t),style:{"--gitp-w":`${$}px`},onPointerUp:D=>{H.current={x:D.clientX,y:D.clientY},P()},children:[a.jsx("div",{className:"gitp-resizer",role:"separator","aria-orientation":"vertical","aria-label":"Resize the file panel",onPointerDown:G}),a.jsxs("header",{className:"panel-head",children:[a.jsxs("div",{className:"panel-id",children:[a.jsxs("div",{className:"panel-name",children:[ks(t),U&&a.jsx("span",{className:"panel-dirty",title:"Unsaved changes"})]}),a.jsx("div",{className:"panel-path",children:a.jsx("bdi",{children:t})})]}),a.jsxs("span",{className:"panel-acts",children:[a.jsx(Ux,{className:"panel-act",icon:a.jsx(_0,{}),idle:"Copy the path",done:"Path copied",read:()=>({text:t})}),s?.kind==="text"&&a.jsx(Ux,{className:"panel-act",icon:a.jsx(t$,{}),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:l,partial:s.truncated})})]}),Ore(t,s)&&a.jsx("button",{className:"panel-btn",type:"button",onClick:()=>f(D=>!D),children:h?"Preview":"Edit"}),s?.kind==="text"&&!s.truncated&&a.jsx("button",{className:"panel-btn is-primary",type:"button",onClick:le,disabled:!I||m,children:m?"Saving…":x?"Saved":"Save"}),a.jsx("button",{className:"panel-close",type:"button",onClick:()=>{oe()},"aria-label":"Close",children:"✕"})]}),r&&a.jsxs("div",{className:"panel-error",children:[r,a.jsx(k7,{path:t},t)]}),_&&a.jsxs("div",{className:"panel-warn is-stale",children:["This file changed on disk while you were editing it.",a.jsx("button",{className:"panel-inline-btn",type:"button",onClick:()=>{J(!0)},children:"Reload and lose my changes"})]}),s?.truncated&&a.jsxs("div",{className:"panel-warn",children:["Showing the first ",a.jsx(Kt,{children:b4(s.content.length)})," of"," ",a.jsx(Kt,{children:b4(s.size)}),". Saving is off for this file — writing back what is on screen would cut the rest away."]}),a.jsxs("div",{className:"panel-body",ref:W,onScroll:D=>{Y&&($$(Yw("prose",t),D.currentTarget.scrollTop),z.current&&(L.current=LS(D.currentTarget,z.current)))},children:[!s&&!r&&a.jsx("div",{className:"dots","aria-label":"loading"}),s&&a.jsx($he,{path:t,preview:s,draft:l,raw:h,generation:M,onDraft:u,onSave:()=>{le()},onSelect:ne,onProseRef:D=>{z.current=D}})]}),E.launcher]})]}),ye),E.controls,N&&Wre()&&Eo.createPortal(a.jsxs("button",{className:"quote-btn reader-quote",type:"button",style:{left:`${N.x}px`,top:`${N.y}px`},onMouseDown:D=>D.preventDefault(),onPointerDown:D=>D.preventDefault(),onClick:he,children:[a.jsx("span",{className:"quote-btn-plus","aria-hidden":"true",children:"+"}),"Add to chat",N.quote.from>0&&a.jsx("span",{className:"quote-btn-at",children:N.quote.to>N.quote.from?`${N.quote.from}–${N.quote.to}`:N.quote.from})]}),document.body)]}):null}function Ghe(t){if(!t)return{x:24,y:80};const e=t.getBoundingClientRect();return{x:e.left+e.width/2,y:e.top+40}}const Fc=1,C7=8,w4=[1,1.5,2,3,4,6,8],Yhe=400;function ME(t){return Number.isFinite(t)?Math.min(C7,Math.max(Fc,t)):Fc}function vb(t,e){const n=ME(t);return(e>0?w4.find(i=>i>n+1e-6):[...w4].reverse().find(i=>i<n-1e-6))??n}function Xhe(t,e){return ME(t*Math.exp(-e/Yhe))}function Qhe(t,e,n,s){const i=s/n;return{x:e.x-(e.x-t.x)*i,y:e.y-(e.y-t.y)*i}}function Zhe(t,e,n,s){const i=(l,u)=>Math.max(0,(u*s-l)/2),r=i(e.w,n.w),o=i(e.h,n.h);return{x:Math.min(r,Math.max(-r,t.x)),y:Math.min(o,Math.max(-o,t.y))}}const aw={x:0,y:0},_4=4,xb={scale:Fc,pan:aw};function j7({path:t,onClose:e}){const[n,s]=y.useState(null),[i,r]=y.useState(null),[o,l]=y.useState(xb),u=y.useRef(null),h=y.useRef(null),f=QA(t);y.useEffect(()=>{let O=!0,X=null;return l(xb),te.fetchFile(t).then(q=>{O&&(X=URL.createObjectURL(q),s(X))}).catch(q=>O&&r(q.message)),()=>{O=!1,X&&URL.revokeObjectURL(X)}},[t]);const m=y.useCallback((O,X,q)=>{const $=ME(X),G=u.current,B=h.current,F={w:G?.clientWidth??0,h:G?.clientHeight??0},z={w:B?.offsetWidth??0,h:B?.offsetHeight??0};return{scale:$,pan:Zhe(Qhe(O.pan,q,O.scale,$),F,z,$)}},[]),g=y.useCallback((O,X=aw)=>l(q=>m(q,O(q.scale),X)),[m]),x=y.useCallback((O,X)=>{const q=u.current?.getBoundingClientRect();return q?{x:O-(q.left+q.width/2),y:X-(q.top+q.height/2)}:aw},[]);y.useEffect(()=>{const O=u.current;if(!O||f)return;const X=q=>{q.preventDefault();const $=q.ctrlKey?q.deltaY*3:q.deltaY;g(G=>Xhe(G,$),x(q.clientX,q.clientY))};return O.addEventListener("wheel",X,{passive:!1}),()=>O.removeEventListener("wheel",X)},[x,f,n,g]),y.useEffect(()=>{const O=X=>{if(X.key==="Escape")return e();if(f||X.metaKey||X.ctrlKey||X.altKey)return;const q=X.target;q&&(q.tagName==="INPUT"||q.tagName==="TEXTAREA"||q.isContentEditable)||(X.key==="+"||X.key==="="?g($=>vb($,1)):X.key==="-"||X.key==="_"?g($=>vb($,-1)):X.key==="0"&&l(xb))};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[e,f,g]);const b=y.useRef(new Map),_=y.useRef(null),k=y.useRef(null),N=y.useRef(!1),j=()=>{const[O,X]=[...b.current.values()];return Math.hypot(O.x-X.x,O.y-X.y)},M=()=>{const[O,X]=[...b.current.values()];return x((O.x+X.x)/2,(O.y+X.y)/2)};function A(O){if(!f){if(b.current.size===0&&(N.current=!1),b.current.set(O.pointerId,{x:O.clientX,y:O.clientY}),b.current.size===2){_.current=null,k.current=j(),N.current=!0;return}b.current.size>2||o.scale<=Fc||(O.target.setPointerCapture?.(O.pointerId),_.current={id:O.pointerId,from:{x:O.clientX,y:O.clientY},pan:o.pan})}}function E(O){if(!b.current.has(O.pointerId))return;if(b.current.set(O.pointerId,{x:O.clientX,y:O.clientY}),k.current!==null&&b.current.size===2){const G=j(),B=k.current>0?G/k.current:1;k.current=G,g(F=>F*B,M());return}const X=_.current;if(!X||X.id!==O.pointerId)return;const q=O.clientX-X.from.x,$=O.clientY-X.from.y;(Math.abs(q)>_4||Math.abs($)>_4)&&(N.current=!0),l(G=>m({...G,pan:{x:X.pan.x+q,y:X.pan.y+$}},G.scale,aw))}function L(O){b.current.delete(O.pointerId),b.current.size<2&&(k.current=null),_.current?.id===O.pointerId&&(_.current=null)}return Eo.createPortal(a.jsxs("div",{className:"viewer",onClick:()=>N.current?N.current=!1:e(),children:[a.jsxs("div",{className:"viewer-bar",onClick:O=>O.stopPropagation(),children:[a.jsx("span",{className:"viewer-name",children:ks(t)}),!f&&n&&a.jsxs("div",{className:"viewer-zoom",children:[a.jsx("button",{className:"viewer-btn",type:"button",onClick:()=>g(O=>vb(O,-1)),disabled:o.scale<=Fc,"aria-label":"Zoom out",title:"Zoom out (−)",children:"−"}),a.jsx("button",{className:"viewer-level",type:"button",onClick:()=>l(xb),disabled:o.scale<=Fc,title:"Fit to screen (0)",children:a.jsx(Kt,{children:`${Math.round(o.scale*10)/10}×`})}),a.jsx("button",{className:"viewer-btn",type:"button",onClick:()=>g(O=>vb(O,1)),disabled:o.scale>=C7,"aria-label":"Zoom in",title:"Zoom in (+)",children:"+"})]}),a.jsx("button",{className:"viewer-close",type:"button",onClick:e,"aria-label":"Close",children:"✕"})]}),i?a.jsx("div",{className:"viewer-error",children:i}):n?f?a.jsx("iframe",{className:"viewer-pdf",src:n,title:ks(t)}):a.jsx("div",{className:`viewer-stage ${o.scale>Fc?"is-zoomed":""}`,ref:u,onPointerDown:A,onPointerMove:E,onPointerUp:L,onPointerCancel:L,onDoubleClick:O=>g(X=>X>Fc?Fc:2,x(O.clientX,O.clientY)),children:a.jsx("img",{className:"viewer-img",ref:h,src:n,alt:ks(t),draggable:!1,style:{transform:`translate(${o.pan.x}px, ${o.pan.y}px) scale(${o.scale})`},onClick:O=>O.stopPropagation()})}):a.jsx("div",{className:"dots","aria-label":"loading"})]}),document.body)}const Jhe=220;function ede({children:t}){const[e,n]=y.useState(null),[s,i]=y.useState(null),[r,o]=y.useState(null),l=y.useCallback(()=>{n(null),i(null)},[]),u=y.useCallback(h=>{if(I$(h)){i(null),n(null),te.openFileInBrowser(h);return}XA(h)||QA(h)?(i(null),n(h)):(n(null),i(h),o(h))},[]);return y.useEffect(()=>{if(s)return;const h=setTimeout(()=>o(null),Jhe);return()=>clearTimeout(h)},[s]),a.jsx(JB.Provider,{value:u,children:a.jsxs(e$.Provider,{value:l,children:[t,e&&a.jsx(j7,{path:e,onClose:()=>n(null)}),r&&a.jsx(Khe,{path:r,open:!!s,onClose:()=>i(null)})]})})}function N7({attachment:t}){const[e,n]=y.useState(t.url??null);return y.useEffect(()=>{if(t.url){n(t.url);return}let s=!0,i=null;return te.fetchFile(t.path).then(r=>{s&&(i=URL.createObjectURL(r),n(i))}).catch(()=>s&&n(null)),()=>{s=!1,i&&URL.revokeObjectURL(i)}},[t.path,t.url]),e?a.jsx("img",{className:"chip-thumb",src:e,alt:""}):a.jsx(nde,{})}function tde({files:t}){const e=w0();return t.length===0?null:a.jsx("div",{className:"sent-files",children:t.map(n=>a.jsxs("button",{className:`chip ${n.isImage?"is-image":""}`,type:"button",title:`${n.path} — click to open`,onClick:()=>e(n.path),children:[n.isImage?a.jsx(N7,{attachment:n}):a.jsx(sde,{}),a.jsx("span",{className:"chip-name",children:n.name})]},n.path))})}function nde(){return a.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:[a.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2.5"}),a.jsx("circle",{cx:"8.5",cy:"9.5",r:"1.6"}),a.jsx("path",{d:"m4 17 4.5-4.5a2 2 0 0 1 2.8 0L16 17"}),a.jsx("path",{d:"m14 14 1.8-1.8a2 2 0 0 1 2.8 0L21 14.5"})]})}function sde(){return a.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:[a.jsx("path",{d:"M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8Z"}),a.jsx("path",{d:"M14 3v5h5"})]})}function TS(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 ide=42,rde=2.5,ade=320,k4=1500;function ode(){return window.matchMedia?.("(prefers-reduced-motion: reduce)").matches??!1}function lde(t,e){const[n,s]=y.useState(()=>e?0:t.length),i=y.useRef(n),r=y.useRef(0),o=y.useRef(0),l=y.useRef(0),u=y.useRef(e);return i.current=n,e&&(u.current=!0),y.useEffect(()=>{if(ode()||!u.current){i.current!==t.length&&s(t.length);return}if(i.current>t.length){s(t.length);return}const h=f=>{const m=t.length-i.current;if(m<=0){o.current=0,r.current=0;return}const g=o.current?Math.min(f-o.current,100):16;if(o.current=f,m>k4){i.current=t.length-k4,s(i.current),l.current=requestAnimationFrame(h);return}const x=Math.min(ade,Math.max(ide,m/rde));r.current+=x*g/1e3;const b=Math.floor(r.current);b>=1&&(r.current-=b,i.current=Math.min(t.length,i.current+b),s(i.current)),l.current=requestAnimationFrame(h)};return l.current=requestAnimationFrame(h),()=>cancelAnimationFrame(l.current)},[t,e]),t.slice(0,n)}const cde=/^\s{0,3}(`{3,}|~{3,})(.*)$/;function A7(t){return cde.exec(t.endsWith("\r")?t.slice(0,-1):t)}function ude(t){if(!t)return[];const e=t.split(`
85
85
  `),n=[];let s=[],i=null;const r=()=>{s.length&&(n.push(s.join(`
86
86
  `)),s=[])};for(const o of e){const l=A7(o);if(i){s.push(o),l&&l[1][0]===i.marker&&l[1].length>=i.length&&!l[2].trim()&&(i=null,r());continue}if(l){r(),i={marker:l[1][0],length:l[1].length},s.push(o);continue}if(!o.trim()){r();continue}s.push(o)}return r(),n}function hde(t){const e=t.split(`
87
87
  `);let n=null;for(const s of e){const i=A7(s);i&&(n?i[1][0]===n.marker&&i[1].length>=n.length&&!i[2].trim()&&(n=null):n={marker:i[1][0],length:i[1].length})}return n?`${t}
@@ -89,12 +89,12 @@ ${n.marker.repeat(n.length)}`:t}function dde(t){const e=t.match(/\S+\s*|\s+/g);r
89
89
  `)){const r=i.trim();if(!r.startsWith("|")){r&&(s=null);continue}if(mde.test(r))continue;const o=pde(r),l=o[0]?.toLowerCase();if(l==="category"){s="categories";continue}if(l==="tool"){s="tools";continue}s==="categories"&&o.length>=2?e.categories.push({label:o[0],tokens:yb(o[1]),percent:Number(o[2]?.replace("%",""))||0}):s==="tools"&&o.length>=3&&e.tools.push({name:o[0],server:o[1],tokens:yb(o[2])})}return e.categories.length?e:null}function xde(t){const e=new Map;for(const n of t.tools){const s=e.get(n.server)??{tokens:0,count:0};s.tokens+=n.tokens,s.count+=1,e.set(n.server,s)}return[...e.entries()].map(([n,s])=>({server:n,...s})).sort((n,s)=>s.tokens-n.tokens)}const bb=["#0a84ff","#5e5ce6","#bf5af2","#ff375f","#ff9f0a","#ffd426","#30d158","#64d2ff","#8e8e93"];function Hv(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(t>=1e4?0:1)}k`:String(t)}function yde({report:t}){const[e,n]=y.useState(!1),s=t.categories.filter(o=>!/^free/i.test(o.label)),i=s.reduce((o,l)=>o+l.tokens,0)||1,r=xde(t);return a.jsxs("div",{className:"ctxr",children:[a.jsxs("div",{className:"ctxr-head",children:[a.jsx("span",{className:"ctxr-total",children:a.jsx(Kt,{children:t.usedTokens!==void 0&&t.totalTokens!==void 0?`${Hv(t.usedTokens)} of ${Hv(t.totalTokens)}`:"Context"})}),t.usedPercent!==void 0&&a.jsx("span",{className:"ctxr-pct",children:a.jsx(Kt,{children:`${t.usedPercent}% full`})}),t.model&&a.jsx("span",{className:"ctxr-model",children:t.model})]}),a.jsx("div",{className:"ctxr-bar",role:"img","aria-label":"What is using the context",children:s.map((o,l)=>a.jsx("span",{className:"ctxr-seg",style:{width:`${o.tokens/i*100}%`,background:bb[l%bb.length]},title:`${o.label}: ${Hv(o.tokens)}`},o.label))}),a.jsx("ul",{className:"ctxr-legend",children:s.map((o,l)=>a.jsxs("li",{children:[a.jsx("span",{className:"ctxr-dot",style:{background:bb[l%bb.length]}}),a.jsx("span",{className:"ctxr-label",children:o.label}),a.jsx("span",{className:"ctxr-tokens",children:a.jsx(Kt,{children:Hv(o.tokens)})}),a.jsx("span",{className:"ctxr-share",children:a.jsx(Kt,{children:`${Math.round(o.tokens/i*100)}%`})})]},o.label))}),r.length>0&&a.jsxs("div",{className:"ctxr-servers",children:[a.jsx("button",{className:"ctxr-more",type:"button",onClick:()=>n(o=>!o),children:a.jsx(Kt,{children:`${e?"Hide":"Show"} MCP servers · ${t.tools.length} tools`})}),e&&a.jsx("ul",{className:"ctxr-legend",children:r.map(o=>a.jsxs("li",{children:[a.jsx("span",{className:"ctxr-label",children:o.server}),a.jsx("span",{className:"ctxr-tokens",children:a.jsx(Kt,{children:Hv(o.tokens)})}),a.jsx("span",{className:"ctxr-share",children:a.jsx(Kt,{children:`${o.count} tools`})})]},o.server))})]})]})}const M7=88,RS=12,bde=3,S4=t=>Math.max(1,Math.ceil(t.length/M7));function wde(t,e){const n=t.slice(0,e),s=n.lastIndexOf(" ");return(s>e*.6?n.slice(0,s):n).trimEnd()}function _de(t){const e=t.split(`
90
90
  `);if(e.reduce((r,o)=>r+S4(o),0)<=RS+bde)return{head:t,clipped:!1};const s=[];let i=0;for(const r of e){const o=S4(r);if(i+o>RS){s.length||s.push(wde(r,RS*M7));break}s.push(r),i+=o}return{head:s.join(`
91
91
  `).trimEnd(),clipped:!0}}const kde=/^usage:\s*\/config\s+key=value/i,Sde=/^\s*([A-Za-z][A-Za-z0-9]*)=(.+)$/;function L7(t){const e=t.trim().split(`
92
- `);if(!e.length||!kde.test(e[0].trim()))return null;const n=[],s=new Set;for(const i of e.slice(1)){const r=Sde.exec(i);if(!r){if(i.trim())break;continue}const[,o,l]=r;if(s.has(o))continue;s.add(o);const u=l.trim()==="<value>"?[]:l.trim().split("|").filter(Boolean);n.push({key:o,options:u})}return n.length?n:null}const Cde=/^set\s+(.+?)\s+to\s+(.+?)\.?$/i;function jde(t,e){const n=Cde.exec(t.trim());if(!n)return null;const s=n[1].replace(/\s+/g,"").toLowerCase(),i=n[2].trim();let r=null;for(const o of e)s.startsWith(o.toLowerCase())&&(!r||o.length>r.length)&&(r=o);return r?{key:r,value:i}:null}const C4=new Set(["ide","pr","api","url","id","mcp","cli","ui","ai"]);function Nde(t){const e=t.replace(/([a-z0-9])([A-Z])/g,"$1 $2").toLowerCase().split(" ").map(s=>C4.has(s)?s.toUpperCase():s),n=e[0]??"";return e[0]=C4.has(n.toLowerCase())?n:n.charAt(0).toUpperCase()+n.slice(1),e.join(" ")}const Ade=[{title:"The model",keys:["model","switchModelsOnFlag","thinking","outputStyle"]},{title:"What it may do",keys:["permissionMode","useAutoModeDuringPlan","checkpoints","gitignore","worktreeBaseRef"]},{title:"Workflows",keys:["workflows","workflowKeywordTriggerEnabled","workflowSizeGuideline"]},{title:"The window",keys:["theme","language","reduceMotion","progressBar","tips","turnDuration","verbose","recap"]},{title:"Editing",keys:["editor","externalEditorContext","autoConnectIde","chrome"]},{title:"Notifications",keys:["notifChannel","prStatus"]},{title:"The conversation",keys:["autoCompact","artifacts","copyFullResponse","defaultToAgentsView","leftArrowOpensAgents"]}];function Ede(t){const e=new Map(t.map(r=>[r.key,r])),n=[],s=new Set;for(const r of Ade){const o=r.keys.map(l=>e.get(l)).filter(l=>!!l);for(const l of o)s.add(l.key);o.length&&n.push({title:r.title,rows:o})}const i=t.filter(r=>!s.has(r.key));return i.length&&n.push({title:"Everything else",rows:i}),n}const T7=y.createContext({say:()=>{},said:[]});function Mde({say:t,said:e,readOnly:n=!1,children:s}){const i=y.useMemo(()=>({say:t,said:e,readOnly:n}),[t,e,n]);return a.jsx(T7.Provider,{value:i,children:s})}function Lde(t){return L7(t)!==null}function Tde({text:t}){const e=y.useMemo(()=>L7(t),[t]),n=y.useMemo(()=>e?Ede(e):[],[e]),{say:s,said:i,readOnly:r}=y.useContext(T7),o=y.useMemo(()=>{const l=new Map,u=e?.map(h=>h.key)??[];if(!u.length)return l;for(const h of i){const f=jde(h,u);f&&l.set(f.key,f.value)}return l},[i,e]);return e?a.jsxs("div",{className:"cfg",children:[a.jsxs("div",{className:"cfg-head",children:[a.jsx("span",{className:"cfg-title",children:"Settings"}),a.jsx("span",{className:"cfg-note",children:a.jsx(Kt,{children:r?"Read-only · change settings through the main chat":`${e.length} this agent takes · picking a value sends it`})})]}),n.map(l=>a.jsxs("section",{className:"cfg-group",children:[a.jsx("h4",{className:"cfg-group-head",children:l.title}),l.rows.map(u=>a.jsx(Rde,{row:u,value:o.get(u.key),onPick:s,readOnly:r},u.key))]},l.title))]}):null}function Rde({row:t,value:e,onPick:n,readOnly:s}){return a.jsxs("div",{className:"cfg-row",children:[a.jsxs("span",{className:"cfg-key",children:[Nde(t.key),a.jsx("code",{className:"cfg-code",children:t.key})]}),t.options.length?a.jsx("span",{className:"cfg-opts",children:t.options.map(i=>a.jsx("button",{type:"button",disabled:s,className:`cfg-opt ${e===i?"is-on":""}`,"aria-pressed":e===i,title:`/config ${t.key}=${i}`,onClick:()=>n(`/config ${t.key}=${i}`),children:i},i))}):a.jsx("span",{className:"cfg-free",children:a.jsxs("code",{className:"cfg-code",children:["/config ",t.key,"=…"]})})]})}const Dde=40,Ode=4e3,Em=new Map,g_=new Set,v_=new Map,l2=new Set;let c2=null;const s0=(t,e)=>`${e}\0${t}`;function Ide(t,e){return Em.get(s0(t,e))}function Bde(t,e){const n=new Map;for(const s of t){const i=Em.get(s0(s,e));i!==void 0&&n.set(s,i)}return n}function R7(t,e){let n=!1;for(const s of t){const i=s0(s,e);if(Em.has(i)||g_.has(i))continue;g_.add(i);let r=v_.get(e);r||v_.set(e,r=new Set),r.add(s),n=!0}n&&c2===null&&(c2=setTimeout($de,Dde))}function D7(t){return l2.add(t),()=>{l2.delete(t)}}function $de(){c2=null;const t=[...v_.entries()];v_.clear();for(const[e,n]of t){const s=[...n];te.invoke("resolve_paths",{paths:s,cwd:e}).then(i=>{s.forEach((r,o)=>{const l=s0(r,e);g_.delete(l),Em.set(l,i?.[o]??null)}),Em.size>Ode&&Em.clear();for(const r of l2)r()}).catch(()=>{for(const i of s)g_.delete(s0(i,e))})}}const O7="allow-scripts allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-downloads",Pde="600px";function I7(){const t=y.useRef(null),[e,n]=y.useState(!1);return y.useEffect(()=>{const s=t.current;if(!s)return;if(typeof IntersectionObserver>"u"){n(!0);return}const i=new IntersectionObserver(r=>{r.some(o=>o.isIntersecting)&&(n(!0),i.disconnect())},{rootMargin:Pde});return i.observe(s),()=>i.disconnect()},[]),[t,e]}function j4({path:t,kind:e}){const[n,s]=I7(),[i,r]=y.useState(!1);if(i)return null;const o=ks(t);return a.jsx("span",{className:`prose-media is-${e}`,ref:n,children:s?e==="video"?a.jsx("video",{src:te.fileUrl(t),controls:!0,playsInline:!0,preload:"metadata","aria-label":o,onError:()=>r(!0)}):a.jsx("audio",{src:te.fileUrl(t),controls:!0,preload:"metadata","aria-label":o,onError:()=>r(!0)}):a.jsx("span",{className:"prose-media-wait","aria-hidden":"true"})})}function zde({path:t}){const[e,n]=I7(),[s,i]=y.useState(null),[r,o]=y.useState(!1);return y.useEffect(()=>{if(!n)return;let l=!0,u=null;return te.fetchFile(t).then(h=>{l&&(u=URL.createObjectURL(h),i(u))}).catch(()=>l&&o(!0)),()=>{l=!1,u&&URL.revokeObjectURL(u)}},[n,t]),r?null:a.jsx("span",{className:"prose-media is-pdf",ref:e,children:s?a.jsx("iframe",{src:s,title:ks(t)}):a.jsx("span",{className:"prose-media-wait","aria-hidden":"true"})})}function Fde({path:t}){const e=w0(),[n,s]=y.useState(!1),[i,r]=y.useState(null),[o,l]=y.useState(!1);y.useEffect(()=>{if(!n||i!==null)return;let h=!0;return te.fetchFile(t).then(f=>f.text()).then(f=>h&&r(f)).catch(()=>h&&l(!0)),()=>{h=!1}},[n,i,t]);const u=ks(t);return a.jsxs("span",{className:"prose-media is-page",children:[a.jsxs("span",{className:"prose-page-card",children:[a.jsx("span",{className:"prose-page-icon","aria-hidden":"true",children:"</>"}),a.jsx("span",{className:"prose-page-name",title:t,children:u}),a.jsx("button",{type:"button","aria-expanded":n,onClick:()=>s(h=>!h),children:n?"Hide":"Show here"}),a.jsx("button",{type:"button",title:"Open in a new tab",onClick:()=>e(t),children:"Open"})]}),n&&a.jsx("span",{className:"prose-page-stage",children:i!==null?a.jsx("iframe",{title:u,sandbox:O7,srcDoc:i}):o?a.jsx("span",{role:"status",children:"Page unavailable"}):a.jsx("span",{className:"prose-media-wait","aria-hidden":"true"})})]})}const Hde="600px";function B7({path:t}){const e=w0(),n=y.useRef(null),[s,i]=y.useState(!1),[r,o]=y.useState(null),[l,u]=y.useState(!1);return y.useEffect(()=>{const h=n.current;if(!h)return;if(typeof IntersectionObserver>"u"){i(!0);return}const f=new IntersectionObserver(m=>{m.some(g=>g.isIntersecting)&&(i(!0),f.disconnect())},{rootMargin:Hde});return f.observe(h),()=>f.disconnect()},[]),y.useEffect(()=>{if(!s)return;let h=!0,f=null;return te.fetchFile(t).then(m=>{h&&(f=URL.createObjectURL(m),o(f))}).catch(()=>h&&u(!0)),()=>{h=!1,f&&URL.revokeObjectURL(f)}},[s,t]),l?null:a.jsx("span",{className:"prose-shot",ref:n,children:r?a.jsx("button",{className:"prose-shot-btn",type:"button",title:`${ks(t)} — click to see it full size`,onClick:()=>e(t),children:a.jsx("img",{src:r,alt:ks(t)})}):a.jsx("span",{className:"prose-shot-wait","aria-hidden":"true"})})}const Wde=Object.freeze(Object.defineProperty({__proto__:null,ProseShot:B7},Symbol.toStringTag,{value:"Module"})),$7=y.createContext(""),P7=$7.Provider;function qde({path:t,code:e,children:n}){const s=y.useContext($7),i=()=>t?Ide(t,s):void 0,r=y.useSyncExternalStore(D7,i,i);if(y.useEffect(()=>{t&&R7([t],s)},[t,s]),!t||!r)return e?a.jsx("code",{children:n}):a.jsx(a.Fragment,{children:n});const o=XA(r),l=o?a.jsx(B7,{path:r}):jre(r)?a.jsx(j4,{path:r,kind:"video"}):Nre(r)?a.jsx(j4,{path:r,kind:"audio"}):QA(r)?a.jsx(zde,{path:r}):I$(r)?a.jsx(Fde,{path:r}):null,u=a.jsx(n$,{path:r,code:!!e,children:o?ks(r):n});return l?a.jsxs(a.Fragment,{children:[u,l]}):u}const z7="octiq-path",Ude=String.raw`\/?(?:~|\.{1,2}|[\w.@+-]+)(?:\/[\w.@+-]+)+`,F7=String.raw`[\w][\w@+-]*\.[A-Za-z]\w{0,7}`,g1=String.raw`(?::\d+(?::\d+)?)?`,N4=new RegExp(`(?:${Ude}|${F7})${g1}`,"g"),Vde=new RegExp(`${g1}$`),Kde=new RegExp(`^${F7}${g1}$`),Gde=new RegExp(String.raw`[^/]\.[A-Za-z]\w{0,7}${g1}$`),Yde=/[.,;:!?]+$/;function LE(t){const e=[],n=(r,o)=>{if(!r)return;const l=e[e.length-1];!o&&l&&!l.path?l.text+=r:e.push(o?{text:r,path:o}:{text:r})};let s=0;N4.lastIndex=0;let i;for(;i=N4.exec(t);){const r=i[0].replace(Yde,""),o=r.includes("/")?Gde.test(r):Kde.test(r);!r||i.index<s||!o||(n(t.slice(s,i.index)),n(r,r.replace(Vde,"")),s=i.index+r.length)}return n(t.slice(s)),e.length?e:[{text:t}]}function H7(t,e,n){return{type:"element",tagName:z7,properties:n?{path:e,code:"1"}:{path:e},children:[{type:"text",value:t}]}}function Xde(t){const e=LE(t);return e.length===1&&!e[0].path?[{type:"text",value:t}]:e.map(n=>n.path?H7(n.text,n.path):{type:"text",value:n.text})}function Qde(t){const e=t.children?.length===1?t.children[0]:null;if(!e||e.type!=="text"||!e.value)return t;const n=e.value.trim(),s=LE(n);return s.length!==1||!s[0].path?t:H7(n,s[0].path,!0)}function W7(t){if(!t.children?.length||t.tagName==="pre"||t.tagName==="a")return;const e=[];for(const n of t.children){if(n.type==="text"&&n.value){e.push(...Xde(n.value));continue}if(n.tagName==="code"){e.push(Qde(n));continue}W7(n),e.push(n)}t.children=e}function A4(){return t=>W7(t)}const Zde=8;function q7(t){return t.name||t.id}function Jde(t){const e=new Map;for(const n of t){if(!n.speaker)continue;const s=q7(n.speaker);e.has(s)||e.set(s,e.size%Zde)}return e}function efe(t){return t.trigger==="approved"?`PR #${t.number} completed on current-head approval`:`PR #${t.number} completed on merge`}function tfe(t){return t?.reference?`Against ${t.reference}`:t?.command?`From ${t.command}`:""}const u2={unverified:"Unverified","nothing-yet":"No changes yet","to-commit":"To commit","to-merge":"To merge","to-push":"To push","to-release":"To release",released:"Released"};function nfe(t){return t?t.uncommitted>0?"to-commit":t.onTarget?t.commits>0&&!t.pushed?"to-push":DS(t):t.commits===0?t.merged?DS(t):"nothing-yet":t.merged?t.mergedRemote?DS(t):"to-push":"to-merge":"unverified"}function DS(t){return t.released===null||t.released===void 0?"unverified":t.released?"released":"to-release"}function E4(t){return t==="released"?"ok":"quiet"}function U7(t,e={}){const n=nfe(t?.delivery);return e.waiting==="unknown"||e.waiting==="unchecked"?{label:u2[n],tone:E4(n),stage:n}:e.waiting?{label:"Needs you",tone:"decide",stage:n}:e.busy?{label:"Working",tone:"accent",stage:n}:{label:u2[n],tone:E4(n),stage:n}}function V7(t){const e=t?.steps??[];return e.length===0?"":`${e.filter(n=>n.state==="done").length}/${e.length}`}function TE(t){return t?t.exists?t.isRepo?t.isWorktree?"Task worktree":"Primary checkout":"Not a Git repository":t.isWorktree?"Task worktree (removed)":"Directory removed":"Unknown"}function sfe(t){return t.replace(/[\\/]+$/,"").split(/[\\/]/).pop()||t}function ife(t,e=""){if(!t||t.exists||!t.cwd)return;if(t.isWorktree)return{label:"Worktree removed",next:"next message rebuilds it from its branch",path:t.cwd,detail:["Your next message rebuilds it from its branch with committed work only.","Uncommitted and untracked files are not restored.","If it cannot be rebuilt, this chat moves to the project's own folder."]};const n=i=>i.replace(/[\\/]+$/,""),s=[t.primaryRoot,e].find(i=>i&&n(i)!==n(t.cwd));return{label:"Folder removed",next:s?`next message moves this chat to ${sfe(s)}`:"no folder to continue in, start a new chat",path:t.cwd,detail:s?[`Your next message moves this chat to ${s}.`,"Nothing from the removed folder is restored."]:["There is no other folder to continue in. Start a new chat."]}}function rfe(t){if(!t||!t.isRepo)return"Unknown";if(!t.exists)return"Directory removed";const e=[];return e.push(t.changed===0?"Clean":`${t.changed} changed`),t.ahead>0&&e.push(`${t.ahead} to push`),t.behind>0&&e.push(`${t.behind} behind`),t.hasUpstream||e.push("no upstream"),e.join(" · ")}function afe(t){return t?t.onTarget?`Working directly on ${t.target}`:t.mergedRemote?`In origin/${t.target}`:t.merged?`In ${t.target} locally — not pushed`:t.commits===0?`Nothing committed to merge into ${t.target} yet`:`Not in ${t.target}`:"Unverified"}function ofe(t){if(!t)return"Unverified";const e=[];return t.commits>0&&e.push(`${t.commits} commit${t.commits===1?"":"s"}`),t.uncommitted>0&&e.push(`${t.uncommitted} uncommitted`),e.length===0?"Nothing committed for this task":(t.pushed&&t.commits>0&&e.push("pushed"),e.join(" · "))}function lfe(t){return t?t.released===!0?"Released":t.released===!1?"Not in the released build":"Unverified":"Unverified"}function Ha(t,e){if(!t)return"never";const n=Math.max(0,Math.round((e-t)/1e3));if(n<60)return"just now";const s=Math.round(n/60);if(s<60)return`${s}m ago`;const i=Math.round(s/60);if(i<24)return`${i}h ago`;const r=Math.round(i/24);return r===1?"yesterday":`${r}d ago`}const cfe="Not reported by the agent",ufe=64,K7=new Map;function hfe(t,e=K7){t?.chatId&&(e.delete(t.chatId),e.set(t.chatId,t),e.size>ufe&&e.delete(e.keys().next().value))}function dfe(t,e=K7){return e.get(t)}const ffe="octiq-complete-";function v1(t){return typeof t=="string"&&t.startsWith(ffe)}function M4(t){return t.worker?"worker":t.frontDesk?"front-desk":/^chat:[^#/:]+$/.test(t.key)?"main":"seat"}const pfe={worker:"A worker's chat ends with its task. Complete the main chat that coordinates it.","front-desk":"A front desk only routes. There is nothing in it to complete.",seat:"Only a chat's own agent can be completed."};function mfe(t){return t.kind!=="main"?{shown:!1,disabled:!0,label:pfe[t.kind]}:t.completing?{shown:!0,disabled:!0,label:"This chat is completing"}:t.connected?{shown:!0,disabled:!1,label:"Complete this chat"}:{shown:!0,disabled:!0,label:"Complete this chat (not connected)"}}const G7=(t,e,n=`${e}s`)=>`${t} ${t===1?e:n}`;function gfe(t){return t?t.onTarget?`On ${t.target}`:t.mergedRemote||t.merged?`Yes, in ${t.target}`:`No, not in ${t.target}`:"Unverified"}function vfe(t){const e=[];return t.live?e.push("Running"):t.mission&&e.push("Open"),t.workersRunning>0&&e.push(G7(t.workersRunning,"worker")+" running"),{label:t.mission?"Mission":"Run",value:e.join(" · ")||t.status}}function xfe(t,e={busy:!1}){const n=t?.workspace,s=t?.delivery,i=!!n?.isRepo,r=[];i&&n?.branch&&r.push({label:"Branch",value:n.branch}),n&&(i||!n.exists)&&r.push({label:"Folder",value:TE(n)});const o=s?.uncommitted??n?.changed??0;o>0&&r.push({label:"Uncommitted",value:G7(o,"file")}),i&&r.push({label:"Merged",value:gfe(s)});for(const u of t?.runs??[])r.push(vfe(u));const l=[{label:"Work",line:"Commits uncommitted work, or says why it stays."},{label:"Clean up",line:"Removes temporary files. A worktree and its branch go only if merged."}];return t?.registeredAgent&&l.push({label:"Memory",line:"Saves what is worth keeping."}),t?.runs.some(u=>u.live)&&l.push({label:"Run",line:"Stops the run it coordinates. The mission stays yours to close."}),l.push({label:"Report",line:"Done, not done, remaining risks."}),{title:"Complete this chat?",lead:"The agent wraps up, then the chat is marked done and its process stops. A new message reopens it.",...e.busy?{waits:"A reply is running. The wrap-up waits behind it."}:{},facts:r,steps:l,...t?.refusal?{refusal:t.refusal}:{}}}function yfe(t){return(t?.runs??[]).filter(e=>e.mission&&e.closeEligible)}function bfe(t){return(t?.runs??[]).filter(e=>e.mission).map(e=>e.runId)}const wfe={completing:{},ended:{},rev:{},settled:{}};function dx(t,e,n){if(n)return t.settled[e]?.find(s=>s.turnId===n)?.end}const lm=(t,e)=>{if(!(e in t))return t;const n={...t};return delete n[e],n},ow=(t,e)=>({...t,[e]:(t[e]??0)+1}),wb=(t,e,n)=>({...t,completing:lm(t.completing,e),ended:{...t.ended,[e]:n},rev:ow(t.rev,e)});function _fe(t,e){switch(e.type){case"asked":return t.completing[e.chatId]?t:{...t,completing:{...t.completing,[e.chatId]:{state:"asked"}},ended:lm(t.ended,e.chatId),rev:ow(t.rev,e.chatId)};case"refused":return t.completing[e.chatId]?.state!=="asked"?t:wb(t,e.chatId,{ok:!1,reason:e.error});case"completing":return dx(t,e.chatId,e.turnId)?t:{...t,completing:{...t.completing,[e.chatId]:{turnId:e.turnId,state:e.state}},ended:lm(t.ended,e.chatId),rev:ow(t.rev,e.chatId)};case"receipt":{if(t.completing[e.chatId]?.state!=="asked")return t;const s=dx(t,e.chatId,e.turnId);return s?wb(t,e.chatId,s):{...t,completing:{...t.completing,[e.chatId]:{turnId:e.turnId,state:e.state}},rev:ow(t.rev,e.chatId)}}case"completed":{const n={ok:e.ok,...e.reason?{reason:e.reason}:{},...e.doneAt!=null?{doneAt:e.doneAt}:{}};if(!e.turnId)return wb(t,e.chatId,n);if(dx(t,e.chatId,e.turnId))return t;const s={...t,settled:{...t.settled,[e.chatId]:[...t.settled[e.chatId]??[],{turnId:e.turnId,end:n}].slice(-8)}},i=t.completing[e.chatId];return i?.turnId&&i.turnId!==e.turnId||i?.state==="asked"?s:wb(s,e.chatId,n)}case"activity":{const n=r=>(t.rev[r]??0)===(e.rev[r]??0),s=new Set(e.completing);let i=t.completing;for(const r of Object.keys(t.completing))s.has(r)||!n(r)||t.completing[r].state==="asked"||(i=lm(i,r));for(const r of s)i[r]||!n(r)||(i={...i,[r]:{state:"started"}});return i===t.completing?t:{...t,completing:i}}case"queue":{if((t.rev[e.chatId]??0)!==e.rev)return t;const n=t.completing[e.chatId];return e.completingTurnId?n?.turnId===e.completingTurnId||dx(t,e.chatId,e.completingTurnId)?t:{...t,completing:{...t.completing,[e.chatId]:{turnId:e.completingTurnId,state:n?.state==="queued"?"queued":"started"}}}:!n||n.state==="asked"?t:{...t,completing:lm(t.completing,e.chatId)}}case"dismiss":return e.chatId in t.ended?{...t,ended:lm(t.ended,e.chatId)}:t}}function kfe(t,e,n){return dx(t,e,n)?"ended":"completing"}function Sfe(t){return new Set(Object.keys(t.completing))}const L4={cancelled:"Completion cancelled.",stopped:"Stopped before the wrap-up finished.",failed:"The wrap-up did not finish cleanly.",superseded:"A newer message took over from the wrap-up.",ended:"The agent's process ended before the wrap-up finished."};function Cfe(t){return t?Object.hasOwn(L4,t)?L4[t]:t:"The chat was not completed."}function jfe(t,e){const n=[...e].reverse().find(s=>s.role==="user"&&(t.turnId?s.turnId===t.turnId:v1(s.turnId)));return n?!n.echo&&!n.takenUp&&(n.delivery==="queued"||n.delivery==="starting"):t.state==="queued"}function Nfe(t){const{completing:e,ended:n}=t;return e?{kind:"completing",label:"Completing",detail:e.state==="asked"?"Asking the agent to wrap up":jfe(e,t.messages)?"Waiting for the current reply":"Wrapping up"}:n?n.ok?t.done?{kind:"done",label:"Completed",detail:"Marked done. A new message reopens it."}:null:{kind:"not-done",label:"Not completed",detail:Cfe(n.reason)}:null}const Y7="Wrap-up";function Afe(t){if(!v1(t.turnId))return null;const e=!t.echo&&!t.takenUp&&t.delivery==="queued";return{label:Y7,detail:e?"Completing this chat after the current reply":"Completing this chat"}}const Efe="octiq-plan-start-";function x1(t){return typeof t=="string"&&t.startsWith(Efe)}const h2="Plan started";function X7(t){return t.echo||t.takenUp?null:t.queueLost?"lost":t.delivery==="failed"?"failed":null}const Mfe={failed:"Not sent · this turn did not reach the agent",lost:"Lost from the queue · this turn did not reach the agent"};function Lfe(t){if(!x1(t.turnId))return null;const e=X7(t);if(e)return{label:h2,detail:Mfe[e]};const n=!t.echo&&!t.takenUp&&t.delivery==="queued";return{label:h2,detail:n?"Telling the agent after the current reply":"The agent was told to begin"}}function Tfe(t,e){if(!x1(e))return!1;const n=e.replace(/-try\d+$/,""),i=t.filter(r=>r.role==="user"&&typeof r.turnId=="string"&&(r.turnId===n||r.turnId.startsWith(`${n}-try`)&&/^\d+$/.test(r.turnId.slice(n.length+4)))).at(-1);return!!i&&X7(i)!==null}function T4(t){const e=t.flatMap(n=>n.blocks).filter(n=>n.kind==="text").map(n=>n.text).join(" ").replace(/\s+/g," ").trim();return e?e.length>260?`${e.slice(0,257).trimEnd()}…`:e:""}function Rfe(t){return t.flatMap((e,n)=>{if(e[0]?.role!=="user")return[];if(hg(e[0].turnId))return[];const s=t.slice(n+1).find(i=>i[0]?.role==="assistant");return[{id:e[0].id,prompt:v1(e[0].turnId)?Y7:x1(e[0].turnId)?h2:H_(e[0].turnId)?fK:T4(e)||"Message",reply:s?T4(s):""}]})}function Dfe(t,e){return t.reduce((n,s)=>!n||Math.abs(s.offset-e)<Math.abs(n.offset-e)?s:n,void 0)}function Ofe(t,e){return e<=1?0:t/e}const R4=3;function Ife(t){if(t===null)return 12;const s=Math.abs(t);return s>=R4?12:Math.round(12+20*.5*(1+Math.cos(Math.PI*s/R4)))}function Bfe({turns:t,scrollerRef:e,innerRef:n,onJump:s}){const[i,r]=y.useState([]),[o,l]=y.useState(0),[u,h]=y.useState(null),f=y.useRef(0);y.useEffect(()=>{const N=e.current,j=n.current;if(!N||!j)return;const M=()=>{const L=N.getBoundingClientRect(),O=new Map([...N.querySelectorAll("[data-map-turn]")].map(q=>[q.dataset.mapTurn,q])),X=t.flatMap(q=>{const $=O.get(q.id);if(!$)return[];const G=N.scrollTop+$.getBoundingClientRect().top-L.top;return[{...q,offset:G}]});r(X.map((q,$)=>({...q,rank:Ofe($,X.length)}))),l(N.scrollTop+N.clientHeight/2)},A=()=>{cancelAnimationFrame(f.current),f.current=requestAnimationFrame(M)};M();const E=typeof ResizeObserver>"u"?void 0:new ResizeObserver(A);return E?.observe(N),E?.observe(j),window.addEventListener("resize",A),()=>{cancelAnimationFrame(f.current),E?.disconnect(),window.removeEventListener("resize",A)}},[n,e,t]),y.useEffect(()=>{const N=e.current;if(!N)return;const j=()=>{cancelAnimationFrame(f.current),f.current=requestAnimationFrame(()=>l(N.scrollTop+N.clientHeight/2))};return N.addEventListener("scroll",j,{passive:!0}),()=>{cancelAnimationFrame(f.current),N.removeEventListener("scroll",j)}},[e]);const m=y.useMemo(()=>i.find(N=>N.id===u),[u,i]),g=y.useMemo(()=>u===null?-1:i.findIndex(N=>N.id===u),[u,i]),x=y.useMemo(()=>Dfe(i,o),[o,i]),b=Math.min(360,Math.max(5,i.length*5)),_=b/Math.max(i.length,1);if(t.length===0)return null;const k=N=>{const j=e.current;if(!j)return;s?.();const M=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;j.scrollTo({top:Math.max(0,N.offset-j.clientHeight*.2),behavior:M?"auto":"smooth"})};return a.jsx("aside",{className:"conversation-map","aria-label":"Conversation map",children:a.jsxs("div",{className:"conversation-map-body",style:{height:`${b}px`},children:[a.jsx("div",{className:"conversation-map-points",children:i.map((N,j)=>a.jsx("button",{className:`conversation-map-point ${x?.id===N.id?"is-current":""}`,type:"button",style:{top:`${N.rank*b}px`,height:`${_}px`,width:`${Ife(g<0?null:j-g)}px`},"aria-label":`Jump to message: ${N.prompt}`,"aria-current":x?.id===N.id?"location":void 0,onPointerEnter:()=>h(N.id),onPointerLeave:()=>h(null),onFocus:()=>h(N.id),onBlur:()=>h(null),onClick:()=>k(N)},N.id))}),m&&a.jsxs("div",{className:"conversation-map-preview","aria-hidden":"true",style:{top:`${m.rank*b+_/2-54}px`},children:[a.jsx("div",{className:"conversation-map-preview-title",children:m.prompt}),m.reply&&a.jsx("div",{className:"conversation-map-preview-body",children:m.reply})]})]})})}function $fe({user:t,message:e,wrapUp:n=!1,planStart:s=!1,jobTurn:i=!1,onStart:r,onCancel:o,onRestore:l,onDismiss:u,footer:h,children:f}){const m=a.jsx("div",{className:"msg-body",children:f});if(!t)return m;const g=!!(e.echo||e.takenUp),x=g?"dispatched":e.queueLost?"failed":e.delivery,b=!!e.queueAction,_=e.queueAction==="cancel"?n||s||i?"Cancelling…":"Returning to composer…":e.queueAction==="start"||x==="starting"?"Sending next…":g?"Sent":x==="queued"?"Queued":x==="sending"?"Sending…":x==="dispatched"?"Awaiting agent confirmation":x==="failed"?"Not sent":e.turnId?"Delivery unconfirmed":void 0,k=x==="queued"?"Runs after the current reply. Send now stops that reply.":x==="dispatched"&&!g?"The message was handed off, but the agent has not confirmed receipt yet.":x==="failed"?"This message is no longer waiting. Restore it to edit or send again.":x==="unknown"?"Delivery could not be confirmed. Check the conversation before sending again.":void 0,N=x==="queued"&&!g&&!b;return a.jsxs("div",{className:"message-bubble","data-noswipe":r||o||l||u?"":void 0,children:[m,(_||h)&&a.jsx("div",{className:"message-delivery","data-delivery":x,"aria-busy":b,children:a.jsxs("div",{className:"message-delivery-line",children:[a.jsxs("span",{className:"message-delivery-status",role:"status",title:k,children:[N&&a.jsx(Pfe,{}),_]}),N&&a.jsxs("span",{className:"message-delivery-note",children:["Runs after the current reply.",r&&" Send now stops it."]}),a.jsxs("div",{className:"message-delivery-actions",role:"group","aria-label":"Message actions",children:[r&&a.jsx("button",{type:"button",disabled:b,title:n?"Stop the current reply and wrap up now":s?"Stop the current reply and tell the agent now":i?"Stop the current reply and tell the agent the job ended":"Stop the current reply and send this message next","aria-label":"Send this queued message now",onClick:r,children:"Send now"}),o&&(n?a.jsx("button",{type:"button",disabled:b,title:"Take the wrap-up back. The chat is not completed.","aria-label":"Cancel completing this chat",onClick:o,children:"Cancel"}):i?a.jsx("button",{type:"button",disabled:b,title:"Take this turn back. The agent is not told that the job ended.","aria-label":"Cancel telling the agent the job ended",onClick:o,children:"Cancel"}):s?a.jsx("button",{type:"button",disabled:b,title:"Take this turn back. The plan stays started.","aria-label":"Cancel telling the agent its plan was started",onClick:o,children:"Cancel"}):a.jsx("button",{type:"button",disabled:b,title:"Return this message and its attachments to the composer","aria-label":"Take this queued message back to edit",onClick:o,children:"Edit"})),l&&a.jsx("button",{type:"button",onClick:l,children:"Restore to composer"}),u&&a.jsx("button",{type:"button",onClick:u,children:"Dismiss"}),h]})]})}),k&&!g&&x!=="dispatched"&&x!=="queued"&&a.jsx("p",{className:"message-delivery-detail",children:k}),e.queueError&&a.jsx("p",{className:"message-delivery-error",role:"alert",children:e.queueError})]})}function Pfe(){return a.jsxs("svg",{className:"message-delivery-icon",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[a.jsx("circle",{cx:"12",cy:"12",r:"9"}),a.jsx("path",{d:"M12 7v5l3 2"})]})}function zfe({children:t}){return a.jsx("div",{className:"chat-status",children:t})}function RE(){return a.jsx("span",{className:"status-row-chevron","aria-hidden":"true",children:a.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:a.jsx("path",{d:"m4.5 6 3.5 3.5L11.5 6"})})})}function DE({label:t,onClick:e}){return a.jsx("button",{type:"button",className:"status-row-dismiss","aria-label":t,title:t,onClick:e,children:a.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round","aria-hidden":"true",children:a.jsx("path",{d:"M6 6l12 12M18 6 6 18"})})})}function Ffe({action:t,onClick:e}){return t.shown?a.jsxs("button",{className:"icon-btn complete-chat",type:"button","aria-label":t.label,title:t.label,disabled:t.disabled,onClick:e,children:[a.jsx(OE,{}),a.jsx("span",{className:"topbar-action-label",children:"Complete"})]}):null}function OE({size:t=17}){return a.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[a.jsx("path",{d:"M5 21V4"}),a.jsx("path",{d:"M5 5h11l-2 3.5 2 3.5H5"})]})}function Hfe({size:t=17}){return a.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[a.jsx("circle",{cx:"12",cy:"12",r:"8.5"}),a.jsx("path",{d:"M10 8.5v7l5.5-3.5z"})]})}function Wfe({size:t=17}){return a.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[a.jsx("circle",{cx:"12",cy:"13",r:"7.5"}),a.jsx("path",{d:"M12 9.5V13l2.5 1.5"}),a.jsx("path",{d:"M10 3h4"})]})}function qfe({chatKey:t,busy:e,onCancel:n,onConfirm:s}){const[i,r]=y.useState(),[o,l]=y.useState(!0);return y.useEffect(()=>{let u=!0;return l(!0),te.invoke("chat_complete_preview",{chatKey:t}).then(h=>{u&&r(h)}).catch(()=>{}).finally(()=>{u&&l(!1)}),()=>{u=!1}},[t]),a.jsx(Ufe,{content:xfe(i,{busy:e}),loading:o,onCancel:n,onConfirm:()=>s(i)})}function Ufe({content:t,loading:e=!1,startOpen:n=!1,onCancel:s,onConfirm:i}){const r=Ef("complete-chat",{startOpen:n}),o=e1(i),l=y.useRef(s);return l.current=s,y.useEffect(()=>{const u=h=>{h.key==="Escape"&&(h.preventDefault(),l.current())};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[]),a.jsx("div",{className:"ask-scrim",onClick:s,children:a.jsxs("div",{className:"ask complete-ask",role:"alertdialog","aria-modal":"true","aria-label":t.title,onKeyDownCapture:o.keys,onClick:u=>u.stopPropagation(),children:[a.jsxs("h2",{className:"ask-title complete-ask-title",children:[a.jsx("span",{className:"complete-ask-mark","aria-hidden":"true",children:a.jsx(OE,{size:15})}),t.title]}),a.jsx("p",{className:"complete-ask-lead",children:t.lead}),t.waits&&a.jsx("p",{className:"complete-ask-waits",children:t.waits}),t.facts.length>0?a.jsx("dl",{className:"complete-ask-facts",children:t.facts.map((u,h)=>a.jsxs("div",{children:[a.jsx("dt",{children:u.label}),a.jsx("dd",{title:u.value,children:u.value})]},`${h}-${u.label}`))}):e&&a.jsx("p",{className:"complete-ask-loading",role:"status",children:"Checking the workspace…"}),a.jsxs("div",{className:"complete-ask-steps",children:[a.jsx(ug,{fold:r,what:"the steps",labels:[`What the agent is asked · ${vr(t.steps.length,"step")}`]}),a.jsx($l,{fold:r,children:a.jsx("ol",{children:t.steps.map(u=>a.jsxs("li",{children:[a.jsx("strong",{children:u.label}),a.jsx("span",{children:u.line})]},u.label))})})]}),t.refusal&&a.jsx("p",{className:"complete-ask-refusal",role:"status",children:t.refusal}),a.jsxs("div",{className:"ask-buttons",children:[a.jsx("button",{className:"ask-btn",type:"button",autoFocus:!0,onClick:s,children:t.refusal?"Close":"Cancel"}),!t.refusal&&a.jsx("button",{className:"ask-btn is-primary",type:"button",disabled:e,onClick:o.confirm,children:"Complete"})]})]})})}function Vfe({line:t,offers:e=[],onCloseMission:n,onDismiss:s}){if(!t)return null;const i=e.find(r=>r.error)?.error;return a.jsxs("div",{className:"chat-completion status-row","data-kind":t.kind,role:"status",children:[a.jsx("span",{className:"status-row-icon chat-completion-mark","aria-hidden":"true",children:t.kind==="done"?a.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",children:a.jsx("path",{d:"m5 12.5 4.5 4.5L19 7.5"})}):t.kind==="completing"?a.jsx("span",{className:"chat-completion-dot"}):a.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:a.jsx("path",{d:"M6 12h12"})})}),a.jsxs("span",{className:"chat-completion-copy",children:[a.jsx("span",{className:"chat-completion-label",children:t.label}),t.detail&&a.jsx("span",{className:"chat-completion-detail",children:t.detail}),i&&a.jsx("span",{className:"chat-completion-detail",children:i})]}),t.kind==="done"&&n&&e.map(r=>a.jsx("button",{type:"button",className:"chat-completion-action",disabled:r.closing,title:"Git confirms the merge. Remove the mission's worktree and its local branch.",onClick:()=>n(r.run.runId),children:r.closing?"Closing…":"Close mission"},r.run.runId)),t.kind!=="completing"&&s&&a.jsx(DE,{label:"Dismiss",onClick:s})]})}function Kfe({label:t,detail:e,text:n,mark:s="complete"}){const i=n.split(`
92
+ `);if(!e.length||!kde.test(e[0].trim()))return null;const n=[],s=new Set;for(const i of e.slice(1)){const r=Sde.exec(i);if(!r){if(i.trim())break;continue}const[,o,l]=r;if(s.has(o))continue;s.add(o);const u=l.trim()==="<value>"?[]:l.trim().split("|").filter(Boolean);n.push({key:o,options:u})}return n.length?n:null}const Cde=/^set\s+(.+?)\s+to\s+(.+?)\.?$/i;function jde(t,e){const n=Cde.exec(t.trim());if(!n)return null;const s=n[1].replace(/\s+/g,"").toLowerCase(),i=n[2].trim();let r=null;for(const o of e)s.startsWith(o.toLowerCase())&&(!r||o.length>r.length)&&(r=o);return r?{key:r,value:i}:null}const C4=new Set(["ide","pr","api","url","id","mcp","cli","ui","ai"]);function Nde(t){const e=t.replace(/([a-z0-9])([A-Z])/g,"$1 $2").toLowerCase().split(" ").map(s=>C4.has(s)?s.toUpperCase():s),n=e[0]??"";return e[0]=C4.has(n.toLowerCase())?n:n.charAt(0).toUpperCase()+n.slice(1),e.join(" ")}const Ade=[{title:"The model",keys:["model","switchModelsOnFlag","thinking","outputStyle"]},{title:"What it may do",keys:["permissionMode","useAutoModeDuringPlan","checkpoints","gitignore","worktreeBaseRef"]},{title:"Workflows",keys:["workflows","workflowKeywordTriggerEnabled","workflowSizeGuideline"]},{title:"The window",keys:["theme","language","reduceMotion","progressBar","tips","turnDuration","verbose","recap"]},{title:"Editing",keys:["editor","externalEditorContext","autoConnectIde","chrome"]},{title:"Notifications",keys:["notifChannel","prStatus"]},{title:"The conversation",keys:["autoCompact","artifacts","copyFullResponse","defaultToAgentsView","leftArrowOpensAgents"]}];function Ede(t){const e=new Map(t.map(r=>[r.key,r])),n=[],s=new Set;for(const r of Ade){const o=r.keys.map(l=>e.get(l)).filter(l=>!!l);for(const l of o)s.add(l.key);o.length&&n.push({title:r.title,rows:o})}const i=t.filter(r=>!s.has(r.key));return i.length&&n.push({title:"Everything else",rows:i}),n}const T7=y.createContext({say:()=>{},said:[]});function Mde({say:t,said:e,readOnly:n=!1,children:s}){const i=y.useMemo(()=>({say:t,said:e,readOnly:n}),[t,e,n]);return a.jsx(T7.Provider,{value:i,children:s})}function Lde(t){return L7(t)!==null}function Tde({text:t}){const e=y.useMemo(()=>L7(t),[t]),n=y.useMemo(()=>e?Ede(e):[],[e]),{say:s,said:i,readOnly:r}=y.useContext(T7),o=y.useMemo(()=>{const l=new Map,u=e?.map(h=>h.key)??[];if(!u.length)return l;for(const h of i){const f=jde(h,u);f&&l.set(f.key,f.value)}return l},[i,e]);return e?a.jsxs("div",{className:"cfg",children:[a.jsxs("div",{className:"cfg-head",children:[a.jsx("span",{className:"cfg-title",children:"Settings"}),a.jsx("span",{className:"cfg-note",children:a.jsx(Kt,{children:r?"Read-only · change settings through the main chat":`${e.length} this agent takes · picking a value sends it`})})]}),n.map(l=>a.jsxs("section",{className:"cfg-group",children:[a.jsx("h4",{className:"cfg-group-head",children:l.title}),l.rows.map(u=>a.jsx(Rde,{row:u,value:o.get(u.key),onPick:s,readOnly:r},u.key))]},l.title))]}):null}function Rde({row:t,value:e,onPick:n,readOnly:s}){return a.jsxs("div",{className:"cfg-row",children:[a.jsxs("span",{className:"cfg-key",children:[Nde(t.key),a.jsx("code",{className:"cfg-code",children:t.key})]}),t.options.length?a.jsx("span",{className:"cfg-opts",children:t.options.map(i=>a.jsx("button",{type:"button",disabled:s,className:`cfg-opt ${e===i?"is-on":""}`,"aria-pressed":e===i,title:`/config ${t.key}=${i}`,onClick:()=>n(`/config ${t.key}=${i}`),children:i},i))}):a.jsx("span",{className:"cfg-free",children:a.jsxs("code",{className:"cfg-code",children:["/config ",t.key,"=…"]})})]})}const Dde=40,Ode=4e3,Em=new Map,g_=new Set,v_=new Map,l2=new Set;let c2=null;const s0=(t,e)=>`${e}\0${t}`;function Ide(t,e){return Em.get(s0(t,e))}function Bde(t,e){const n=new Map;for(const s of t){const i=Em.get(s0(s,e));i!==void 0&&n.set(s,i)}return n}function R7(t,e){let n=!1;for(const s of t){const i=s0(s,e);if(Em.has(i)||g_.has(i))continue;g_.add(i);let r=v_.get(e);r||v_.set(e,r=new Set),r.add(s),n=!0}n&&c2===null&&(c2=setTimeout($de,Dde))}function D7(t){return l2.add(t),()=>{l2.delete(t)}}function $de(){c2=null;const t=[...v_.entries()];v_.clear();for(const[e,n]of t){const s=[...n];te.invoke("resolve_paths",{paths:s,cwd:e}).then(i=>{s.forEach((r,o)=>{const l=s0(r,e);g_.delete(l),Em.set(l,i?.[o]??null)}),Em.size>Ode&&Em.clear();for(const r of l2)r()}).catch(()=>{for(const i of s)g_.delete(s0(i,e))})}}const O7="allow-scripts allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-downloads",Pde="600px";function I7(){const t=y.useRef(null),[e,n]=y.useState(!1);return y.useEffect(()=>{const s=t.current;if(!s)return;if(typeof IntersectionObserver>"u"){n(!0);return}const i=new IntersectionObserver(r=>{r.some(o=>o.isIntersecting)&&(n(!0),i.disconnect())},{rootMargin:Pde});return i.observe(s),()=>i.disconnect()},[]),[t,e]}function j4({path:t,kind:e}){const[n,s]=I7(),[i,r]=y.useState(!1);if(i)return null;const o=ks(t);return a.jsx("span",{className:`prose-media is-${e}`,ref:n,children:s?e==="video"?a.jsx("video",{src:te.fileUrl(t),controls:!0,playsInline:!0,preload:"metadata","aria-label":o,onError:()=>r(!0)}):a.jsx("audio",{src:te.fileUrl(t),controls:!0,preload:"metadata","aria-label":o,onError:()=>r(!0)}):a.jsx("span",{className:"prose-media-wait","aria-hidden":"true"})})}function zde({path:t}){const[e,n]=I7(),[s,i]=y.useState(null),[r,o]=y.useState(!1);return y.useEffect(()=>{if(!n)return;let l=!0,u=null;return te.fetchFile(t).then(h=>{l&&(u=URL.createObjectURL(h),i(u))}).catch(()=>l&&o(!0)),()=>{l=!1,u&&URL.revokeObjectURL(u)}},[n,t]),r?null:a.jsx("span",{className:"prose-media is-pdf",ref:e,children:s?a.jsx("iframe",{src:s,title:ks(t)}):a.jsx("span",{className:"prose-media-wait","aria-hidden":"true"})})}function Fde({path:t}){const e=w0(),[n,s]=y.useState(!1),[i,r]=y.useState(null),[o,l]=y.useState(!1);y.useEffect(()=>{if(!n||i!==null)return;let h=!0;return te.fetchFile(t).then(f=>f.text()).then(f=>h&&r(f)).catch(()=>h&&l(!0)),()=>{h=!1}},[n,i,t]);const u=ks(t);return a.jsxs("span",{className:"prose-media is-page",children:[a.jsxs("span",{className:"prose-page-card",children:[a.jsx("span",{className:"prose-page-icon","aria-hidden":"true",children:"</>"}),a.jsx("span",{className:"prose-page-name",title:t,children:u}),a.jsx("button",{type:"button","aria-expanded":n,onClick:()=>s(h=>!h),children:n?"Hide":"Show here"}),a.jsx("button",{type:"button",title:"Open in a new tab",onClick:()=>e(t),children:"Open"})]}),n&&a.jsx("span",{className:"prose-page-stage",children:i!==null?a.jsx("iframe",{title:u,sandbox:O7,srcDoc:i}):o?a.jsx("span",{role:"status",children:"Page unavailable"}):a.jsx("span",{className:"prose-media-wait","aria-hidden":"true"})})]})}const Hde="600px";function B7({path:t}){const e=w0(),n=y.useRef(null),[s,i]=y.useState(!1),[r,o]=y.useState(null),[l,u]=y.useState(!1);return y.useEffect(()=>{const h=n.current;if(!h)return;if(typeof IntersectionObserver>"u"){i(!0);return}const f=new IntersectionObserver(m=>{m.some(g=>g.isIntersecting)&&(i(!0),f.disconnect())},{rootMargin:Hde});return f.observe(h),()=>f.disconnect()},[]),y.useEffect(()=>{if(!s)return;let h=!0,f=null;return te.fetchFile(t).then(m=>{h&&(f=URL.createObjectURL(m),o(f))}).catch(()=>h&&u(!0)),()=>{h=!1,f&&URL.revokeObjectURL(f)}},[s,t]),l?null:a.jsx("span",{className:"prose-shot",ref:n,children:r?a.jsx("button",{className:"prose-shot-btn",type:"button",title:`${ks(t)} — click to see it full size`,onClick:()=>e(t),children:a.jsx("img",{src:r,alt:ks(t)})}):a.jsx("span",{className:"prose-shot-wait","aria-hidden":"true"})})}const Wde=Object.freeze(Object.defineProperty({__proto__:null,ProseShot:B7},Symbol.toStringTag,{value:"Module"})),$7=y.createContext(""),P7=$7.Provider;function qde({path:t,code:e,children:n}){const s=y.useContext($7),i=()=>t?Ide(t,s):void 0,r=y.useSyncExternalStore(D7,i,i);if(y.useEffect(()=>{t&&R7([t],s)},[t,s]),!t||!r)return e?a.jsx("code",{children:n}):a.jsx(a.Fragment,{children:n});const o=XA(r),l=o?a.jsx(B7,{path:r}):jre(r)?a.jsx(j4,{path:r,kind:"video"}):Nre(r)?a.jsx(j4,{path:r,kind:"audio"}):QA(r)?a.jsx(zde,{path:r}):I$(r)?a.jsx(Fde,{path:r}):null,u=a.jsx(n$,{path:r,code:!!e,children:o?ks(r):n});return l?a.jsxs(a.Fragment,{children:[u,l]}):u}const z7="octiq-path",Ude=String.raw`\/?(?:~|\.{1,2}|[\w.@+-]+)(?:\/[\w.@+-]+)+`,F7=String.raw`[\w][\w@+-]*\.[A-Za-z]\w{0,7}`,g1=String.raw`(?::\d+(?::\d+)?)?`,N4=new RegExp(`(?:${Ude}|${F7})${g1}`,"g"),Vde=new RegExp(`${g1}$`),Kde=new RegExp(`^${F7}${g1}$`),Gde=new RegExp(String.raw`[^/]\.[A-Za-z]\w{0,7}${g1}$`),Yde=/[.,;:!?]+$/;function LE(t){const e=[],n=(r,o)=>{if(!r)return;const l=e[e.length-1];!o&&l&&!l.path?l.text+=r:e.push(o?{text:r,path:o}:{text:r})};let s=0;N4.lastIndex=0;let i;for(;i=N4.exec(t);){const r=i[0].replace(Yde,""),o=r.includes("/")?Gde.test(r):Kde.test(r);!r||i.index<s||!o||(n(t.slice(s,i.index)),n(r,r.replace(Vde,"")),s=i.index+r.length)}return n(t.slice(s)),e.length?e:[{text:t}]}function H7(t,e,n){return{type:"element",tagName:z7,properties:n?{path:e,code:"1"}:{path:e},children:[{type:"text",value:t}]}}function Xde(t){const e=LE(t);return e.length===1&&!e[0].path?[{type:"text",value:t}]:e.map(n=>n.path?H7(n.text,n.path):{type:"text",value:n.text})}function Qde(t){const e=t.children?.length===1?t.children[0]:null;if(!e||e.type!=="text"||!e.value)return t;const n=e.value.trim(),s=LE(n);return s.length!==1||!s[0].path?t:H7(n,s[0].path,!0)}function W7(t){if(!t.children?.length||t.tagName==="pre"||t.tagName==="a")return;const e=[];for(const n of t.children){if(n.type==="text"&&n.value){e.push(...Xde(n.value));continue}if(n.tagName==="code"){e.push(Qde(n));continue}W7(n),e.push(n)}t.children=e}function A4(){return t=>W7(t)}const Zde=8;function q7(t){return t.name||t.id}function Jde(t){const e=new Map;for(const n of t){if(!n.speaker)continue;const s=q7(n.speaker);e.has(s)||e.set(s,e.size%Zde)}return e}function efe(t){return t.trigger==="approved"?`PR #${t.number} completed on current-head approval`:`PR #${t.number} completed on merge`}function tfe(t){return t?.reference?`Against ${t.reference}`:t?.command?`From ${t.command}`:""}const u2={unverified:"Unverified","nothing-yet":"No changes yet","to-commit":"To commit","to-merge":"To merge","to-push":"To push","to-release":"To release",released:"Released"};function nfe(t){return t?t.uncommitted>0?"to-commit":t.onTarget?t.commits>0&&!t.pushed?"to-push":DS(t):t.commits===0?t.merged?DS(t):"nothing-yet":t.merged?t.mergedRemote?DS(t):"to-push":"to-merge":"unverified"}function DS(t){return t.released===null||t.released===void 0?"unverified":t.released?"released":"to-release"}function E4(t){return t==="released"?"ok":"quiet"}function U7(t,e={}){const n=nfe(t?.delivery);return e.waiting==="unknown"||e.waiting==="unchecked"?{label:u2[n],tone:E4(n),stage:n}:e.waiting?{label:"Needs you",tone:"decide",stage:n}:e.busy?{label:"Working",tone:"accent",stage:n}:{label:u2[n],tone:E4(n),stage:n}}function V7(t){const e=t?.steps??[];return e.length===0?"":`${e.filter(n=>n.state==="done").length}/${e.length}`}function TE(t){return t?t.exists?t.isRepo?t.isWorktree?"Task worktree":"Primary checkout":"Not a Git repository":t.isWorktree?"Task worktree (removed)":"Directory removed":"Unknown"}function sfe(t){return t.replace(/[\\/]+$/,"").split(/[\\/]/).pop()||t}function ife(t,e=""){if(!t||t.exists||!t.cwd)return;if(t.isWorktree)return{label:"Worktree removed",next:"next message rebuilds it from its branch",path:t.cwd,detail:["Your next message rebuilds it from its branch with committed work only.","Uncommitted and untracked files are not restored.","If it cannot be rebuilt, this chat moves to the project's own folder."]};const n=i=>i.replace(/[\\/]+$/,""),s=[t.primaryRoot,e].find(i=>i&&n(i)!==n(t.cwd));return{label:"Folder removed",next:s?`next message moves this chat to ${sfe(s)}`:"no folder to continue in, start a new chat",path:t.cwd,detail:s?[`Your next message moves this chat to ${s}.`,"Nothing from the removed folder is restored."]:["There is no other folder to continue in. Start a new chat."]}}function rfe(t){if(!t||!t.isRepo)return"Unknown";if(!t.exists)return"Directory removed";const e=[];return e.push(t.changed===0?"Clean":`${t.changed} changed`),t.ahead>0&&e.push(`${t.ahead} to push`),t.behind>0&&e.push(`${t.behind} behind`),t.hasUpstream||e.push("no upstream"),e.join(" · ")}function afe(t){return t?t.onTarget?`Working directly on ${t.target}`:t.mergedRemote?`In origin/${t.target}`:t.merged?`In ${t.target} locally — not pushed`:t.commits===0?`Nothing committed to merge into ${t.target} yet`:`Not in ${t.target}`:"Unverified"}function ofe(t){if(!t)return"Unverified";const e=[];return t.commits>0&&e.push(`${t.commits} commit${t.commits===1?"":"s"}`),t.uncommitted>0&&e.push(`${t.uncommitted} uncommitted`),e.length===0?"Nothing committed for this task":(t.pushed&&t.commits>0&&e.push("pushed"),e.join(" · "))}function lfe(t){return t?t.released===!0?"Released":t.released===!1?"Not in the released build":"Unverified":"Unverified"}function Ha(t,e){if(!t)return"never";const n=Math.max(0,Math.round((e-t)/1e3));if(n<60)return"just now";const s=Math.round(n/60);if(s<60)return`${s}m ago`;const i=Math.round(s/60);if(i<24)return`${i}h ago`;const r=Math.round(i/24);return r===1?"yesterday":`${r}d ago`}const cfe="Not reported by the agent",ufe=64,K7=new Map;function hfe(t,e=K7){t?.chatId&&(e.delete(t.chatId),e.set(t.chatId,t),e.size>ufe&&e.delete(e.keys().next().value))}function dfe(t,e=K7){return e.get(t)}const ffe="octiq-complete-";function v1(t){return typeof t=="string"&&t.startsWith(ffe)}function M4(t){return t.worker?"worker":t.frontDesk?"front-desk":/^chat:[^#/:]+$/.test(t.key)?"main":"seat"}const pfe={worker:"A worker's chat ends with its task. Complete the main chat that coordinates it.","front-desk":"A front desk only routes. There is nothing in it to complete.",seat:"Only a chat's own agent can be completed."};function mfe(t){return t.kind!=="main"?{shown:!1,disabled:!0,label:pfe[t.kind]}:t.completing?{shown:!0,disabled:!0,label:"This chat is completing"}:t.connected?{shown:!0,disabled:!1,label:"Complete this chat"}:{shown:!0,disabled:!0,label:"Complete this chat (not connected)"}}const G7=(t,e,n=`${e}s`)=>`${t} ${t===1?e:n}`;function gfe(t){return t?t.onTarget?`On ${t.target}`:t.mergedRemote||t.merged?`Yes, in ${t.target}`:`No, not in ${t.target}`:"Unverified"}function vfe(t){const e=[];return t.live?e.push("Running"):t.mission&&e.push("Open"),t.workersRunning>0&&e.push(G7(t.workersRunning,"worker")+" running"),{label:t.mission?"Mission":"Run",value:e.join(" · ")||t.status}}function xfe(t,e={busy:!1}){const n=t?.workspace,s=t?.delivery,i=!!n?.isRepo,r=[];i&&n?.branch&&r.push({label:"Branch",value:n.branch}),n&&(i||!n.exists)&&r.push({label:"Folder",value:TE(n)});const o=s?.uncommitted??n?.changed??0;o>0&&r.push({label:"Uncommitted",value:G7(o,"file")}),i&&r.push({label:"Merged",value:gfe(s)});for(const u of t?.runs??[])r.push(vfe(u));const l=[{label:"Work",line:"Commits uncommitted work, or says why it stays."},{label:"Clean up",line:"Removes temporary files. A worktree and its branch go only if merged."}];return t?.registeredAgent&&l.push({label:"Memory",line:"Saves what is worth keeping."}),t?.runs.some(u=>u.live)&&l.push({label:"Run",line:"Stops the run it coordinates. The mission stays yours to close."}),l.push({label:"Report",line:"Done, not done, remaining risks."}),{title:"Complete this chat?",lead:"The agent wraps up, then the chat is marked done and its process stops. A new message reopens it.",...e.busy?{waits:"A reply is running. The wrap-up waits behind it."}:{},facts:r,steps:l,...t?.refusal?{refusal:t.refusal}:{}}}function yfe(t){return(t?.runs??[]).filter(e=>e.mission&&e.closeEligible)}function bfe(t){return(t?.runs??[]).filter(e=>e.mission).map(e=>e.runId)}const wfe={completing:{},ended:{},rev:{},settled:{}};function dx(t,e,n){if(n)return t.settled[e]?.find(s=>s.turnId===n)?.end}const lm=(t,e)=>{if(!(e in t))return t;const n={...t};return delete n[e],n},ow=(t,e)=>({...t,[e]:(t[e]??0)+1}),wb=(t,e,n)=>({...t,completing:lm(t.completing,e),ended:{...t.ended,[e]:n},rev:ow(t.rev,e)});function _fe(t,e){switch(e.type){case"asked":return t.completing[e.chatId]?t:{...t,completing:{...t.completing,[e.chatId]:{state:"asked"}},ended:lm(t.ended,e.chatId),rev:ow(t.rev,e.chatId)};case"refused":return t.completing[e.chatId]?.state!=="asked"?t:wb(t,e.chatId,{ok:!1,reason:e.error});case"completing":return dx(t,e.chatId,e.turnId)?t:{...t,completing:{...t.completing,[e.chatId]:{turnId:e.turnId,state:e.state}},ended:lm(t.ended,e.chatId),rev:ow(t.rev,e.chatId)};case"receipt":{if(t.completing[e.chatId]?.state!=="asked")return t;const s=dx(t,e.chatId,e.turnId);return s?wb(t,e.chatId,s):{...t,completing:{...t.completing,[e.chatId]:{turnId:e.turnId,state:e.state}},rev:ow(t.rev,e.chatId)}}case"completed":{const n={ok:e.ok,...e.reason?{reason:e.reason}:{},...e.doneAt!=null?{doneAt:e.doneAt}:{}};if(!e.turnId)return wb(t,e.chatId,n);if(dx(t,e.chatId,e.turnId))return t;const s={...t,settled:{...t.settled,[e.chatId]:[...t.settled[e.chatId]??[],{turnId:e.turnId,end:n}].slice(-8)}},i=t.completing[e.chatId];return i?.turnId&&i.turnId!==e.turnId||i?.state==="asked"?s:wb(s,e.chatId,n)}case"activity":{const n=r=>(t.rev[r]??0)===(e.rev[r]??0),s=new Set(e.completing);let i=t.completing;for(const r of Object.keys(t.completing))s.has(r)||!n(r)||t.completing[r].state==="asked"||(i=lm(i,r));for(const r of s)i[r]||!n(r)||(i={...i,[r]:{state:"started"}});return i===t.completing?t:{...t,completing:i}}case"queue":{if((t.rev[e.chatId]??0)!==e.rev)return t;const n=t.completing[e.chatId];return e.completingTurnId?n?.turnId===e.completingTurnId||dx(t,e.chatId,e.completingTurnId)?t:{...t,completing:{...t.completing,[e.chatId]:{turnId:e.completingTurnId,state:n?.state==="queued"?"queued":"started"}}}:!n||n.state==="asked"?t:{...t,completing:lm(t.completing,e.chatId)}}case"dismiss":return e.chatId in t.ended?{...t,ended:lm(t.ended,e.chatId)}:t}}function kfe(t,e,n){return dx(t,e,n)?"ended":"completing"}function Sfe(t){return new Set(Object.keys(t.completing))}const L4={cancelled:"Completion cancelled.",stopped:"Stopped before the wrap-up finished.",failed:"The wrap-up did not finish cleanly.",superseded:"A newer message took over from the wrap-up.",ended:"The agent's process ended before the wrap-up finished."};function Cfe(t){return t?Object.hasOwn(L4,t)?L4[t]:t:"The chat was not completed."}function jfe(t,e){const n=[...e].reverse().find(s=>s.role==="user"&&(t.turnId?s.turnId===t.turnId:v1(s.turnId)));return n?!n.echo&&!n.takenUp&&(n.delivery==="queued"||n.delivery==="starting"):t.state==="queued"}function Nfe(t){const{completing:e,ended:n}=t;return e?{kind:"completing",label:"Completing",detail:e.state==="asked"?"Asking the agent to wrap up":jfe(e,t.messages)?"Waiting for the current reply":"Wrapping up"}:n?n.ok?t.done?{kind:"done",label:"Completed",detail:"Marked done. A new message reopens it."}:null:{kind:"not-done",label:"Not completed",detail:Cfe(n.reason)}:null}const Y7="Wrap-up";function Afe(t){if(!v1(t.turnId))return null;const e=!t.echo&&!t.takenUp&&t.delivery==="queued";return{label:Y7,detail:e?"Completing this chat after the current reply":"Completing this chat"}}const Efe="octiq-plan-start-";function x1(t){return typeof t=="string"&&t.startsWith(Efe)}const h2="Plan started";function X7(t){return t.echo||t.takenUp?null:t.queueLost?"lost":t.delivery==="failed"?"failed":null}const Mfe={failed:"Not sent · this turn did not reach the agent",lost:"Lost from the queue · this turn did not reach the agent"};function Lfe(t){if(!x1(t.turnId))return null;const e=X7(t);if(e)return{label:h2,detail:Mfe[e]};const n=!t.echo&&!t.takenUp&&t.delivery==="queued";return{label:h2,detail:n?"Telling the agent after the current reply":"The agent was told to begin"}}function Tfe(t,e){if(!x1(e))return!1;const n=e.replace(/-try\d+$/,""),i=t.filter(r=>r.role==="user"&&typeof r.turnId=="string"&&(r.turnId===n||r.turnId.startsWith(`${n}-try`)&&/^\d+$/.test(r.turnId.slice(n.length+4)))).at(-1);return!!i&&X7(i)!==null}function T4(t){const e=t.flatMap(n=>n.blocks).filter(n=>n.kind==="text").map(n=>n.text).join(" ").replace(/\s+/g," ").trim();return e?e.length>260?`${e.slice(0,257).trimEnd()}…`:e:""}function Rfe(t){return t.flatMap((e,n)=>{if(e[0]?.role!=="user")return[];if(hg(e[0].turnId))return[];const s=t.slice(n+1).find(i=>i[0]?.role==="assistant");return[{id:e[0].id,prompt:v1(e[0].turnId)?Y7:x1(e[0].turnId)?h2:H_(e[0].turnId)?fK:T4(e)||"Message",reply:s?T4(s):""}]})}function Dfe(t,e){return t.reduce((n,s)=>!n||Math.abs(s.offset-e)<Math.abs(n.offset-e)?s:n,void 0)}function Ofe(t,e){return e<=1?0:t/e}const R4=3;function Ife(t){if(t===null)return 12;const s=Math.abs(t);return s>=R4?12:Math.round(12+20*.5*(1+Math.cos(Math.PI*s/R4)))}function Bfe({turns:t,scrollerRef:e,innerRef:n,onJump:s}){const[i,r]=y.useState([]),[o,l]=y.useState(0),[u,h]=y.useState(null),f=y.useRef(0);y.useEffect(()=>{const N=e.current,j=n.current;if(!N||!j)return;const M=()=>{const L=N.getBoundingClientRect(),O=new Map([...N.querySelectorAll("[data-map-turn]")].map(q=>[q.dataset.mapTurn,q])),X=t.flatMap(q=>{const $=O.get(q.id);if(!$)return[];const G=N.scrollTop+$.getBoundingClientRect().top-L.top;return[{...q,offset:G}]});r(X.map((q,$)=>({...q,rank:Ofe($,X.length)}))),l(N.scrollTop+N.clientHeight/2)},A=()=>{cancelAnimationFrame(f.current),f.current=requestAnimationFrame(M)};M();const E=typeof ResizeObserver>"u"?void 0:new ResizeObserver(A);return E?.observe(N),E?.observe(j),window.addEventListener("resize",A),()=>{cancelAnimationFrame(f.current),E?.disconnect(),window.removeEventListener("resize",A)}},[n,e,t]),y.useEffect(()=>{const N=e.current;if(!N)return;const j=()=>{cancelAnimationFrame(f.current),f.current=requestAnimationFrame(()=>l(N.scrollTop+N.clientHeight/2))};return N.addEventListener("scroll",j,{passive:!0}),()=>{cancelAnimationFrame(f.current),N.removeEventListener("scroll",j)}},[e]);const m=y.useMemo(()=>i.find(N=>N.id===u),[u,i]),g=y.useMemo(()=>u===null?-1:i.findIndex(N=>N.id===u),[u,i]),x=y.useMemo(()=>Dfe(i,o),[o,i]),b=Math.min(360,Math.max(5,i.length*5)),_=b/Math.max(i.length,1);if(t.length===0)return null;const k=N=>{const j=e.current;if(!j)return;s?.();const M=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;j.scrollTo({top:Math.max(0,N.offset-j.clientHeight*.2),behavior:M?"auto":"smooth"})};return a.jsx("aside",{className:"conversation-map","aria-label":"Conversation map",children:a.jsxs("div",{className:"conversation-map-body",style:{height:`${b}px`},children:[a.jsx("div",{className:"conversation-map-points",children:i.map((N,j)=>a.jsx("button",{className:`conversation-map-point ${x?.id===N.id?"is-current":""}`,type:"button",style:{top:`${N.rank*b}px`,height:`${_}px`,width:`${Ife(g<0?null:j-g)}px`},"aria-label":`Jump to message: ${N.prompt}`,"aria-current":x?.id===N.id?"location":void 0,onPointerEnter:()=>h(N.id),onPointerLeave:()=>h(null),onFocus:()=>h(N.id),onBlur:()=>h(null),onClick:()=>k(N)},N.id))}),m&&a.jsxs("div",{className:"conversation-map-preview","aria-hidden":"true",style:{top:`${m.rank*b+_/2-54}px`},children:[a.jsx("div",{className:"conversation-map-preview-title",children:m.prompt}),m.reply&&a.jsx("div",{className:"conversation-map-preview-body",children:m.reply})]})]})})}function $fe({user:t,message:e,wrapUp:n=!1,planStart:s=!1,jobTurn:i=!1,onStart:r,onCancel:o,onRestore:l,onDismiss:u,footer:h,children:f}){const m=a.jsx("div",{className:"msg-body",children:f});if(!t)return m;const g=!!(e.echo||e.takenUp),x=g?"dispatched":e.queueLost?"failed":e.delivery,b=!!e.queueAction,_=e.queueAction==="cancel"?n||s||i?"Cancelling…":"Returning to composer…":e.queueAction==="start"||x==="starting"?"Sending next…":g?"Sent":x==="queued"?"Queued":x==="sending"?"Sending…":x==="dispatched"?"Awaiting agent confirmation":x==="failed"?"Not sent":e.turnId?"Delivery unconfirmed":void 0,k=x==="queued"?"Runs after the current reply. Send now stops that reply.":x==="dispatched"&&!g?"The message was handed off, but the agent has not confirmed receipt yet.":x==="failed"?"This message is no longer waiting. Restore it to edit or send again.":x==="unknown"?"Delivery could not be confirmed. Check the conversation before sending again.":void 0,N=x==="queued"&&!g&&!b;return a.jsxs("div",{className:"message-bubble","data-noswipe":r||o||l||u?"":void 0,children:[m,(_||h)&&a.jsx("div",{className:"message-delivery","data-delivery":x,"aria-busy":b,children:a.jsxs("div",{className:"message-delivery-line",children:[a.jsxs("span",{className:"message-delivery-status",role:"status",title:k,children:[N&&a.jsx(Pfe,{}),_]}),a.jsxs("div",{className:"message-delivery-actions",role:"group","aria-label":"Message actions",children:[r&&a.jsx("button",{type:"button",disabled:b,title:n?"Stop the current reply and wrap up now":s?"Stop the current reply and tell the agent now":i?"Stop the current reply and tell the agent the job ended":"Stop the current reply and send this message next","aria-label":"Send this queued message now",onClick:r,children:"Send now"}),o&&(n?a.jsx("button",{type:"button",disabled:b,title:"Take the wrap-up back. The chat is not completed.","aria-label":"Cancel completing this chat",onClick:o,children:"Cancel"}):i?a.jsx("button",{type:"button",disabled:b,title:"Take this turn back. The agent is not told that the job ended.","aria-label":"Cancel telling the agent the job ended",onClick:o,children:"Cancel"}):s?a.jsx("button",{type:"button",disabled:b,title:"Take this turn back. The plan stays started.","aria-label":"Cancel telling the agent its plan was started",onClick:o,children:"Cancel"}):a.jsx("button",{type:"button",disabled:b,title:"Return this message and its attachments to the composer","aria-label":"Take this queued message back to edit",onClick:o,children:"Edit"})),l&&a.jsx("button",{type:"button",onClick:l,children:"Restore to composer"}),u&&a.jsx("button",{type:"button",onClick:u,children:"Dismiss"}),h]})]})}),k&&!g&&x!=="dispatched"&&x!=="queued"&&a.jsx("p",{className:"message-delivery-detail",children:k}),e.queueError&&a.jsx("p",{className:"message-delivery-error",role:"alert",children:e.queueError})]})}function Pfe(){return a.jsxs("svg",{className:"message-delivery-icon",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[a.jsx("circle",{cx:"12",cy:"12",r:"9"}),a.jsx("path",{d:"M12 7v5l3 2"})]})}function zfe({children:t}){return a.jsx("div",{className:"chat-status",children:t})}function RE(){return a.jsx("span",{className:"status-row-chevron","aria-hidden":"true",children:a.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:a.jsx("path",{d:"m4.5 6 3.5 3.5L11.5 6"})})})}function DE({label:t,onClick:e}){return a.jsx("button",{type:"button",className:"status-row-dismiss","aria-label":t,title:t,onClick:e,children:a.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round","aria-hidden":"true",children:a.jsx("path",{d:"M6 6l12 12M18 6 6 18"})})})}function Ffe({action:t,onClick:e}){return t.shown?a.jsxs("button",{className:"icon-btn complete-chat",type:"button","aria-label":t.label,title:t.label,disabled:t.disabled,onClick:e,children:[a.jsx(OE,{}),a.jsx("span",{className:"topbar-action-label",children:"Complete"})]}):null}function OE({size:t=17}){return a.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[a.jsx("path",{d:"M5 21V4"}),a.jsx("path",{d:"M5 5h11l-2 3.5 2 3.5H5"})]})}function Hfe({size:t=17}){return a.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[a.jsx("circle",{cx:"12",cy:"12",r:"8.5"}),a.jsx("path",{d:"M10 8.5v7l5.5-3.5z"})]})}function Wfe({size:t=17}){return a.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[a.jsx("circle",{cx:"12",cy:"13",r:"7.5"}),a.jsx("path",{d:"M12 9.5V13l2.5 1.5"}),a.jsx("path",{d:"M10 3h4"})]})}function qfe({chatKey:t,busy:e,onCancel:n,onConfirm:s}){const[i,r]=y.useState(),[o,l]=y.useState(!0);return y.useEffect(()=>{let u=!0;return l(!0),te.invoke("chat_complete_preview",{chatKey:t}).then(h=>{u&&r(h)}).catch(()=>{}).finally(()=>{u&&l(!1)}),()=>{u=!1}},[t]),a.jsx(Ufe,{content:xfe(i,{busy:e}),loading:o,onCancel:n,onConfirm:()=>s(i)})}function Ufe({content:t,loading:e=!1,startOpen:n=!1,onCancel:s,onConfirm:i}){const r=Ef("complete-chat",{startOpen:n}),o=e1(i),l=y.useRef(s);return l.current=s,y.useEffect(()=>{const u=h=>{h.key==="Escape"&&(h.preventDefault(),l.current())};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[]),a.jsx("div",{className:"ask-scrim",onClick:s,children:a.jsxs("div",{className:"ask complete-ask",role:"alertdialog","aria-modal":"true","aria-label":t.title,onKeyDownCapture:o.keys,onClick:u=>u.stopPropagation(),children:[a.jsxs("h2",{className:"ask-title complete-ask-title",children:[a.jsx("span",{className:"complete-ask-mark","aria-hidden":"true",children:a.jsx(OE,{size:15})}),t.title]}),a.jsx("p",{className:"complete-ask-lead",children:t.lead}),t.waits&&a.jsx("p",{className:"complete-ask-waits",children:t.waits}),t.facts.length>0?a.jsx("dl",{className:"complete-ask-facts",children:t.facts.map((u,h)=>a.jsxs("div",{children:[a.jsx("dt",{children:u.label}),a.jsx("dd",{title:u.value,children:u.value})]},`${h}-${u.label}`))}):e&&a.jsx("p",{className:"complete-ask-loading",role:"status",children:"Checking the workspace…"}),a.jsxs("div",{className:"complete-ask-steps",children:[a.jsx(ug,{fold:r,what:"the steps",labels:[`What the agent is asked · ${vr(t.steps.length,"step")}`]}),a.jsx($l,{fold:r,children:a.jsx("ol",{children:t.steps.map(u=>a.jsxs("li",{children:[a.jsx("strong",{children:u.label}),a.jsx("span",{children:u.line})]},u.label))})})]}),t.refusal&&a.jsx("p",{className:"complete-ask-refusal",role:"status",children:t.refusal}),a.jsxs("div",{className:"ask-buttons",children:[a.jsx("button",{className:"ask-btn",type:"button",autoFocus:!0,onClick:s,children:t.refusal?"Close":"Cancel"}),!t.refusal&&a.jsx("button",{className:"ask-btn is-primary",type:"button",disabled:e,onClick:o.confirm,children:"Complete"})]})]})})}function Vfe({line:t,offers:e=[],onCloseMission:n,onDismiss:s}){if(!t)return null;const i=e.find(r=>r.error)?.error;return a.jsxs("div",{className:"chat-completion status-row","data-kind":t.kind,role:"status",children:[a.jsx("span",{className:"status-row-icon chat-completion-mark","aria-hidden":"true",children:t.kind==="done"?a.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",children:a.jsx("path",{d:"m5 12.5 4.5 4.5L19 7.5"})}):t.kind==="completing"?a.jsx("span",{className:"chat-completion-dot"}):a.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:a.jsx("path",{d:"M6 12h12"})})}),a.jsxs("span",{className:"chat-completion-copy",children:[a.jsx("span",{className:"chat-completion-label",children:t.label}),t.detail&&a.jsx("span",{className:"chat-completion-detail",children:t.detail}),i&&a.jsx("span",{className:"chat-completion-detail",children:i})]}),t.kind==="done"&&n&&e.map(r=>a.jsx("button",{type:"button",className:"chat-completion-action",disabled:r.closing,title:"Git confirms the merge. Remove the mission's worktree and its local branch.",onClick:()=>n(r.run.runId),children:r.closing?"Closing…":"Close mission"},r.run.runId)),t.kind!=="completing"&&s&&a.jsx(DE,{label:"Dismiss",onClick:s})]})}function Kfe({label:t,detail:e,text:n,mark:s="complete"}){const i=n.split(`
93
93
  `).filter(r=>r.trim()).length;return a.jsxs("div",{className:"wrap-up-note","data-mark":s,children:[a.jsxs("span",{className:"wrap-up-note-head",children:[a.jsx("span",{className:"wrap-up-note-mark","aria-hidden":"true",children:s==="start"?a.jsx(Hfe,{size:13}):s==="job"?a.jsx(Wfe,{size:13}):a.jsx(OE,{size:13})}),a.jsx("span",{className:"wrap-up-note-label",children:t}),e&&a.jsx("span",{className:"wrap-up-note-detail",children:e})]}),i>0&&a.jsxs("details",{className:"wrap-up-note-text",children:[a.jsxs("summary",{children:[s==="job"?"What the agent was told":"What the agent is asked"," · ",i," ",i===1?"line":"lines"]}),a.jsx("p",{children:n})]})]})}const Q7=12;function Gfe(t,e){const n=e?t.findIndex(i=>i.some(r=>r.id===e)):-1,s=n>=0?Math.max(0,n-1):Math.max(0,t.length-Q7);return t[s]?.[0].id??null}function Yfe(t,e){return e===null?0:Math.max(0,t.findIndex(n=>n[0].id===e))}const D4="visualize",O4="";function Xfe(t){const e=t.trim();if(!e.startsWith(D4)||!e.endsWith(O4))return null;try{const n=JSON.parse(e.slice(D4.length,-O4.length));return typeof n.path!="string"||!n.path.startsWith("/")||n.mode!==void 0&&n.mode!=="wide"||n.title!==void 0&&typeof n.title!="string"?null:{path:n.path,...n.mode==="wide"?{mode:"wide"}:{},...typeof n.title=="string"?{title:n.title}:{}}}catch{return null}}function Qfe({reference:t}){const e=t.title||ks(t.path);return a.jsxs("button",{className:"visualization-link",type:"button",title:t.path,onClick:()=>te.openFileInBrowser(t.path),children:[a.jsx("span",{"aria-hidden":"true",children:"↗"}),a.jsx("span",{children:e})]})}const Z7=y.createContext(!0);function Zfe({children:t}){const[e,n]=y.useState(!1),s=y.useRef(null),i=t,r=/language-([\w-]+)/.exec(i?.props?.className??"")?.[1]??"";if(y.useContext(Z7)&&r===ure&&typeof i?.props?.children=="string"){const l=O$(i.props.children);if(l)return a.jsx(YA,{diagram:l})}return a.jsxs("div",{className:"code",children:[a.jsxs("div",{className:"code-head",children:[a.jsx("span",{className:"code-lang",children:r||"text"}),a.jsx("button",{className:"code-copy",type:"button",onClick:async()=>{await Rh(s.current?.innerText??"")&&(n(!0),setTimeout(()=>n(!1),1400))},children:e?"copied":"copy"})]}),a.jsx("pre",{ref:s,children:t})]})}function kf({text:t,animate:e}){const n=lde(t,e),s=y.useMemo(()=>e?null:vde(t),[t,e]);if(s)return a.jsx(yde,{report:s});const i=e&&n.length<t.length,r=y.useMemo(()=>ude(n),[n]);return a.jsx("div",{className:`prose ${i?"is-typing":""}`,children:r.map((o,l)=>a.jsx(tpe,{text:o,animate:e&&l===r.length-1,writing:(e||n.length<t.length)&&l===r.length-1},l))})}function Jfe({updates:t,candidate:e,streaming:n}){const s=[...t,...e?[e]:[]];if(!s.length)return null;const i=s[s.length-1],r=s.slice(0,-1),o=`${r.length} earlier progress ${r.length===1?"update":"updates"}`;return a.jsxs("div",{className:`agent-progress ${n?"is-live":"is-settled"}`,children:[r.length>0&&a.jsxs("details",{className:"agent-progress-log",children:[a.jsxs("summary",{children:[a.jsx("span",{children:o}),a.jsx("span",{className:"agent-progress-order",children:"Oldest first"})]}),a.jsx("div",{className:"agent-progress-items",role:"region","aria-label":"Progress history, oldest first",tabIndex:0,children:a.jsx("ol",{className:"agent-progress-list",children:r.map((l,u)=>a.jsx("li",{className:"agent-progress-item",children:a.jsx(kf,{text:l,animate:!1})},`${u}:${l.slice(0,24)}`))})})]}),a.jsxs("div",{className:"agent-progress-live",...n?{role:"status","aria-live":"polite"}:{},children:[a.jsx("span",{className:"agent-progress-pulse","aria-hidden":"true"}),a.jsxs("div",{className:"agent-progress-live-copy",children:[a.jsx("span",{className:"agent-progress-live-label",children:"Latest update"}),a.jsx(kf,{text:i,animate:!1})]})]})]})}const epe={pre:Zfe,table:_7,a:PA,[z7]:qde},tpe=y.memo(function({text:e,animate:n,writing:s}){const i=Xfe(e);if(i)return a.jsx(Qfe,{reference:i});const r=xre(e,s);if(r?.kind==="diagram")return a.jsx(YA,{diagram:r.diagram});if(r)return a.jsx(bre,{rows:r.rows});const o=hde(e);return a.jsx(Z7.Provider,{value:o===e,children:a.jsx(MA,{remarkPlugins:[DA],rehypePlugins:n?[A4,fde]:[A4],components:epe,children:o})})});function npe({block:t,animate:e,kids:n,agentByTool:s,onOpenAgent:i,note:r,folder:o}){const l=y.useContext(s1);if(t.kind==="text"&&Lde(t.text))return a.jsx(Tde,{text:t.text});if(t.kind==="text")return a.jsx(kf,{text:t.text,animate:!!e});if(t.kind==="compacted")return a.jsx(upe,{block:t});if(t.kind==="notice")return a.jsx(rpe,{text:t.text});if(t.kind==="peer")return a.jsx(cpe,{block:t});if(t.kind==="memory")return a.jsx(Lse,{activity:t.activity});if(t.kind==="reopened")return a.jsx(Wse,{reopened:t.reopened});if(t.kind==="answered")return a.jsx(rre,{answered:t.answered});if(t.kind==="thinking")return null;if(l&&t.state!=="error"&&Tne(t.name)){const f=J_(t.name,t.args,t.result);return a.jsx(are,{toolId:t.id,asked:f,late:f?Iie(l.late,f):null})}const u=s?.get(t.id),h=n.get(t.id);return a.jsx(s$,{tool:t,note:r,folder:o,agent:h?.length?{steps:h.length,body:a.jsx(ez,{messages:h,kids:n,agentByTool:s,onOpenAgent:i})}:void 0,onOpenAgent:u&&i?()=>i(u):void 0})}function J7({blocks:t,streaming:e,kids:n,agentByTool:s,onOpenAgent:i}){const r=ese(),o=y.useMemo(()=>VK(t,h=>n.has(h.id)||r.has(h.id)),[t,n,r]),l=y.useMemo(()=>Kne(o),[o]),u=t.length-1;return a.jsx(a.Fragment,{children:o.map((h,f)=>{const m=l[f],g=!!m&&m!==l[f-1],x=h.kind==="group"?h.tools[0]?.id??h.newest.id:h.index;return a.jsxs(y.Fragment,{children:[g&&a.jsx(spe,{dir:m}),h.kind==="group"?a.jsx(yse,{tools:h.tools,newest:h.newest,folder:m,note:h.note}):a.jsx(npe,{block:h.block,animate:e&&h.index===u,kids:n,agentByTool:s,onOpenAgent:i,note:h.note,folder:m})]},x)})})}function spe({dir:t}){return a.jsxs("div",{className:"folder-head",title:t,children:[a.jsx(ipe,{}),a.jsx("span",{className:"folder-head-name",children:Gne(t)})]})}function ipe(){return a.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:a.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 ez({messages:t,kids:e,agentByTool:n,onOpenAgent:s}){const i=t.flatMap(o=>o.blocks),r=t.some(o=>o.streaming);return a.jsxs("div",{className:"subagent",children:[a.jsx(J7,{blocks:i,streaming:r,kids:e,agentByTool:n,onOpenAgent:s}),r&&i.length===0&&a.jsx("div",{className:"dots","aria-label":"working"})]})}function rpe({text:t}){const e=cg();return a.jsx("div",{className:`cli-note${e?` ${e}`:""}`,children:t})}const ape=400;function ope(t){return(t.split(`
94
94
  `).find(n=>n.trim())??"").replace(/^\s*(?:#+|[-*+]|\d+[.)])\s+/,"").replace(/[*_`]/g,"").trim()}function lpe(t){return t.length>8?t.slice(0,8):t}function cpe({block:t}){const[e,n]=y.useState(t.text.length<=ape),s=t.source==="handback"?`subagent ${lpe(t.from)} reported back`:`${t.from||"another session"} sent a message`,i=ope(t.text),r=cg();return a.jsxs("div",{className:`peer-note ${e?"is-open":""}${r?` ${r}`:""}`,"data-peer":t.source,children:[a.jsxs("button",{type:"button",className:"peer-note-head","aria-expanded":e,onClick:()=>n(!e),children:[a.jsx(nz,{open:e}),a.jsx("span",{className:"peer-note-who",children:s}),!e&&i&&a.jsx("span",{className:"peer-note-opening",children:i})]}),e&&a.jsx("div",{className:"peer-note-body",children:a.jsx(kf,{text:t.text,animate:!1})})]})}function upe({block:t}){const[e,n]=y.useState(!1),s=!!t.text.trim(),i=[t.trigger==="manual"?"you asked":t.trigger?"context filled up":"",t.preTokens&&t.postTokens?`${TS(t.preTokens)} → ${TS(t.postTokens)} tokens`:t.preTokens?`${TS(t.preTokens)} tokens summarised`:"",t.durationMs?`${Math.max(1,Math.round(t.durationMs/1e3))}s`:""].filter(Boolean);return a.jsxs("div",{className:`compacted ${e?"is-open":""}`,children:[a.jsx(tz,{children:s?a.jsxs("button",{type:"button",className:"compacted-label is-button","aria-expanded":e,onClick:()=>n(!e),children:[a.jsx(nz,{open:e}),"history summarised to make room",i.length>0&&a.jsx("span",{className:"compacted-facts",children:a.jsx(Kt,{children:i.join(" · ")})})]}):a.jsxs("span",{className:"compacted-label",children:["history summarised to make room",i.length>0&&a.jsx("span",{className:"compacted-facts",children:a.jsx(Kt,{children:i.join(" · ")})})]})}),e&&s&&a.jsx("div",{className:"compacted-body",children:a.jsx(kf,{text:t.text,animate:!1})})]})}function tz({children:t,running:e}){const n=`compacted-line ${e?"is-running":""}`;return a.jsxs("div",{className:"compacted-bar",children:[a.jsx("span",{className:n,"aria-hidden":"true",children:e&&a.jsx(hpe,{})}),t,a.jsx("span",{className:n,"aria-hidden":"true"})]})}function hpe(){return a.jsx("span",{className:"compacting-truck","aria-hidden":"true",children:a.jsxs("svg",{className:"compacting-truck-art",viewBox:"0 0 32 16",width:"28",height:"14",children:[a.jsxs("g",{className:"compacting-truck-load",fill:"currentColor",children:[a.jsx("rect",{x:"1.8",y:"4.6",width:"7.2",height:"5.8",rx:"0.7",opacity:"0.62"}),a.jsx("rect",{x:"9.6",y:"6.6",width:"6",height:"3.8",rx:"0.6",opacity:"0.85"})]}),a.jsx("rect",{x:"0.8",y:"10.4",width:"15.8",height:"1.5",rx:"0.5",fill:"currentColor"}),a.jsx("path",{d:"M16.2 11.9V6.2h5l4.4 4v1.7z",fill:"currentColor"}),a.jsx("path",{d:"M20.2 7.4h.9l2.9 2.6h-3.8z",fill:"var(--bg-1)"}),a.jsx("circle",{cx:"6.4",cy:"13.2",r:"1.8",fill:"currentColor"}),a.jsx("circle",{cx:"21.4",cy:"13.2",r:"1.8",fill:"currentColor"}),a.jsx("circle",{cx:"6.4",cy:"13.2",r:"0.65",fill:"var(--bg-1)"}),a.jsx("circle",{cx:"21.4",cy:"13.2",r:"0.65",fill:"var(--bg-1)"})]})})}function dpe({since:t}){const[,e]=y.useState(0);y.useEffect(()=>{const s=setInterval(()=>e(i=>i+1),1e3);return()=>clearInterval(s)},[]);const n=Math.max(0,Math.round((Date.now()-t)/1e3));return a.jsx("div",{className:"compacted is-running",role:"status",children:a.jsx(tz,{running:!0,children:a.jsxs("span",{className:"compacted-label",children:["summarising history to make room",a.jsx("span",{className:"compacted-facts",children:a.jsx(Kt,{children:`${n}s`})})]})})})}function nz({open:t}){return a.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:a.jsx("path",{d:"m9 6 6 6-6 6"})})}function fpe({text:t}){const[e,n]=y.useState(!1),{head:s,clipped:i}=y.useMemo(()=>_de(t),[t]);return i?a.jsxs("div",{className:`clip ${e?"is-open":"is-cut"}`,children:[a.jsx(kf,{text:e?t:s,animate:!1}),a.jsx("button",{className:"clip-more",type:"button","aria-expanded":e,onClick:()=>n(!e),children:e?"show less":"show more"})]}):a.jsx(kf,{text:t,animate:!1})}function ppe(){return a.jsxs("div",{className:"stopmark",role:"separator",children:[a.jsx("span",{className:"stopmark-rule","aria-hidden":"true"}),a.jsxs("span",{className:"stopmark-label",children:[a.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:a.jsx("rect",{x:"5",y:"5",width:"14",height:"14",rx:"3"})}),"You stopped this"]}),a.jsx("span",{className:"stopmark-rule","aria-hidden":"true"})]})}function mpe({messages:t,kids:e,agentByTool:n,onOpenAgent:s,last:i,busy:r,tints:o,fresh:l,mapTurnId:u,hostName:h,hostPersona:f,onCancelQueued:m,onStartQueued:g,onRestoreUnsent:x,onDismissUnsent:b}){const _=t[0].role,k=t[0].speaker,N=t[0].to,j=t[0].relay,M=t[0].ranSkill,A=t.find(D=>D.replyTo)?.replyTo,E=t.some(D=>D.streaming),L=t.flatMap(D=>D.blocks),O=t.flatMap(D=>D.progress??[]),X=[...t].reverse().find(D=>D.codexCandidate)?.codexCandidate,q=D=>_==="user"?FC(D)?.task??D:D,$=_==="user"?L.map(D=>D.kind==="text"?FC(D.text)?.lead:void 0).find(Boolean):void 0,G=L.filter(D=>D.kind==="text").map(D=>q(D.text)).join(`
95
95
 
96
96
  `).trim(),B=t[0],F=_==="user"&&t.some(D=>D.queueLost&&!D.echo&&!D.takenUp),z=_==="user"&&!F&&!B.echo&&!B.takenUp&&B.delivery==="queued",W=z?B.turnId:void 0,H=m&&W?()=>m(W):void 0,U=g&&W?()=>g(W):void 0,ee=_==="user"?Afe(B):null,Q=_==="user"&&!ee?Lfe(B):null,I=_==="user"&&H_(B.turnId)?B.turnId:null,Y=XB(I?u6(I):null),J=I?vK(B,Y?.job,G):null,P=ee??Q??J,ne=L.length>0&&L.every(D=>D.kind==="compacted"||D.kind==="notice"||D.kind==="peer"||D.kind==="memory"||D.kind==="reopened"||D.kind==="answered"),he=y.useMemo(()=>{const D=new Map;for(const Oe of t)for(const ze of Oe.attachments??[])D.set(ze.path,ze);return[...D.values()]},[t]),le=_==="user"?_$(B):null,oe=le?of(le):[];if(oe.length){const D=!B.echo&&!B.takenUp;return a.jsx("article",{className:`msg msg-answer ${l?"is-new":""}`,children:a.jsx(bh,{lines:oe,status:D&&B.queueLost?"Not delivered":D&&B.delivery==="queued"?"Sent when the current reply ends":void 0})})}if(j&&!P)return a.jsxs("article",{className:"msg msg-relay",children:[a.jsx("span",{"aria-hidden":"true",children:"↳"})," ",j]});const ye=k?o?.get(q7(k)):void 0;return a.jsxs("article",{className:`msg msg-${_} ${k?"msg-seat":""} ${z?"is-queued":""} ${l?"is-new":""}`,"data-tint":ye,"data-map-turn":u,children:[_==="user"&&N&&a.jsxs("div",{className:"msg-to",children:["to ",N.name]}),$&&a.jsxs("div",{className:"msg-to",children:["task for ",$]}),_==="user"&&M&&a.jsx("div",{className:"msg-ran",title:"The skill this command resolved to",children:M}),_==="assistant"&&!ne&&a.jsx("div",{className:"msg-role",children:k?a.jsxs(a.Fragment,{children:[a.jsx(Hm,{agent:k.agent==="claude"?"claude":"codex",size:13}),k.name]}):f?a.jsxs(a.Fragment,{children:[a.jsx(Qs,{name:f.name,avatar:f.avatar,id:f.id??f.name,size:16,removed:f.removed,decorative:!0}),f.name]}):h??"Claude"}),_==="assistant"&&A&&a.jsxs("div",{className:"msg-reply",title:`Replying to: ${A.preview}`,children:[a.jsx("span",{className:"msg-reply-label",children:"Replying to"}),a.jsx("span",{className:"msg-reply-preview",children:A.preview})]}),a.jsxs($fe,{user:_==="user",message:B,wrapUp:!!ee,planStart:!!Q,jobTurn:!!J,onStart:U,onCancel:H,onRestore:!P&&(F||B.delivery==="unknown")&&!B.echo&&!B.takenUp&&x&&B.turnId?()=>x(B.turnId):void 0,onDismiss:F&&b&&B.turnId?()=>b(B.turnId):void 0,footer:_==="user"&&G&&!P?a.jsx(I4,{text:G,what:"message"}):void 0,children:[a.jsx(tde,{files:he}),_==="assistant"&&a.jsx(Jfe,{updates:O,candidate:X,streaming:E}),P?a.jsx(Kfe,{label:P.label,detail:P.detail,text:G,mark:Q?"start":J?"job":"complete"}):_==="user"&&L.every(D=>D.kind==="text")?L.map((D,Oe)=>a.jsx(fpe,{text:q(D.text)},Oe)):a.jsx(J7,{blocks:L,streaming:E,kids:e,agentByTool:n,onOpenAgent:s}),E&&L.length===0&&a.jsx("div",{className:"dots","aria-label":f?`${f.name} is working`:"working"}),_==="assistant"&&!E&&!(r&&i)&&G&&a.jsx("div",{className:"msg-foot",children:a.jsx(I4,{text:G,what:"reply"})})]})]})}function I4({text:t,what:e}){const[n,s]=y.useState("idle");return a.jsx("div",{className:"msg-actions",children:a.jsxs("button",{className:`msg-copy ${n==="done"?"is-done":""}`,type:"button",title:`Copy this ${e}`,onClick:async()=>{const i=await Rh(t);s(i?"done":"failed"),setTimeout(()=>s("idle"),1600)},children:[n==="done"?a.jsx(vpe,{}):a.jsx(gpe,{}),n==="done"?"Copied":n==="failed"?"Could not copy":"Copy"]})})}function gpe(){return a.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:[a.jsx("rect",{x:"9",y:"9",width:"12",height:"12",rx:"2"}),a.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}function vpe(){return a.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:a.jsx("path",{d:"m20 6-11 11-5-5"})})}function xpe(t){const e=[];for(const n of t){const s=e[e.length-1],i=n.role==="user"&&s?.[0].role==="user",r=n.replyTo?.id!==s?.[0].replyTo?.id&&(!!n.replyTo||!!s?.[0].replyTo);!(!!n.relay||!!s?.[0].relay||i||r)&&s&&s[0].role===n.role&&s[0].speaker?.id===n.speaker?.id?s.push(n):e.push([n])}return e}function ype(t){const e=y.useRef(null),n=y.useRef(new Set),s=y.useRef(0),i=t.map(l=>l[0].id),r=e.current;e.current=i;const o=bpe(r,i);return o&&(n.current.add(o),s.current++),{fresh:n.current,nth:s.current}}function bpe(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 wpe=280,_pe=t=>1-Math.pow(1-t,5);function kpe(t,e,n){const s=n<0?0:n>1?1:n;return t+(e-t)*_pe(s)}const Spe=8;function B4(){return typeof window>"u"?!1:!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches}const Wv=80;function Cpe(t){return!!t?.closest?.(".jump")}const jpe=400,$4=6e3;function qv(t){const e=t.getBoundingClientRect(),n=[];for(const s of t.querySelectorAll("[data-map-turn]")){const i=s.dataset.mapTurn;i&&n.push({id:i,offset:t.scrollTop+s.getBoundingClientRect().top-e.top})}return n}const Npe=function({messages:e,busy:n,stoppedAt:s,compactingSince:i,conversationId:r,onSetting:o,agentByTool:l,onOpenAgent:u,hostName:h,hostPersona:f,onCancelQueued:m,onStartQueued:g,onRestoreUnsent:x,onDismissUnsent:b,hasEarlier:_=!1,loadingEarlier:k=!1,earlierError:N,onLoadEarlier:j,tail:M,head:A,marks:E}){const L=y.useRef(null),O=y.useRef(null),X=y.useRef(null),q=y.useRef(()=>{}),$=y.useRef(!1),G=y.useRef(null),B=y.useRef(!0),F=y.useRef(!1),[z,W]=y.useState(!1),H=y.useRef(0),U=y.useRef(r),ee=y.useRef(null),Q=y.useRef(0),I=y.useRef(null),Y=()=>{H.current&&cancelAnimationFrame(H.current),H.current=0},J=()=>{window.clearTimeout(Q.current),Q.current=0;const pe=ee.current;ee.current=null,pe&&(pe.at?CY(pe.id,pe.at):D6(pe.id))},P=()=>{const pe=O.current,Qe=U.current;if(!pe||!Qe||H.current||I.current)return;const Ze=pe.scrollHeight-pe.scrollTop-pe.clientHeight<Wv;!Ze&&B.current||(ee.current={id:Qe,at:Ze?null:ML(pe.scrollTop,qv(pe))},window.clearTimeout(Q.current),Q.current=window.setTimeout(J,jpe))},ne=()=>{const pe=O.current;if(!pe)return;Y();const Qe=pe.scrollHeight-pe.clientHeight,Ze=Math.max(pe.clientHeight*1.5,400),_t=Math.max(pe.scrollTop,Qe-Ze);if(Qe-_t<Spe||B4()){pe.scrollTop=pe.scrollHeight;return}_t!==pe.scrollTop&&(pe.scrollTop=_t);const bt=performance.now(),Xt=pe.closest(".focus-mode")?440:wpe,St=Wn=>{const _n=(Wn-bt)/Xt;if(pe.scrollTop=kpe(_t,pe.scrollHeight-pe.clientHeight,_n),_n<1){H.current=requestAnimationFrame(St);return}H.current=0,B.current&&(pe.scrollTop=pe.scrollHeight)};H.current=requestAnimationFrame(St)},he=()=>{B.current=!0,W(!1),I.current=null,U.current&&(ee.current={id:U.current,at:null}),J(),ne()};y.useEffect(()=>{const pe=O.current;if(!pe)return;let Qe=0;const Ze=Xt=>{Cpe(Xt?.target??null)||(F.current=!0,Y(),I.current=null,window.clearTimeout(Qe),Qe=window.setTimeout(()=>F.current=!1,400))},_t=()=>{if(!F.current){P();return}Ze();const Xt=pe.scrollHeight-pe.scrollTop-pe.clientHeight<Wv;B.current=Xt,W(!Xt),P(),pe.scrollTop<160&&q.current()},bt=()=>J();return pe.addEventListener("scroll",_t,{passive:!0}),window.addEventListener("pagehide",bt),pe.addEventListener("wheel",Ze,{passive:!0}),pe.addEventListener("touchstart",Ze,{passive:!0}),pe.addEventListener("touchmove",Ze,{passive:!0}),pe.addEventListener("pointerdown",Ze,{passive:!0}),pe.addEventListener("keydown",Ze),()=>{window.clearTimeout(Qe),Y(),J(),window.removeEventListener("pagehide",bt),pe.removeEventListener("scroll",_t),pe.removeEventListener("wheel",Ze),pe.removeEventListener("touchstart",Ze),pe.removeEventListener("touchmove",Ze),pe.removeEventListener("pointerdown",Ze),pe.removeEventListener("keydown",Ze)}},[]),y.useLayoutEffect(()=>{const pe=O.current;if(J(),U.current=r,!pe)return;F.current=!1,Y();const Qe=r?EL(r):void 0;if(!Qe){B.current=!0,W(!1),I.current=null,pe.scrollTop=pe.scrollHeight;return}B.current=!1,I.current={at:Qe,until:performance.now()+$4},pe.scrollTop=Fk(Qe,qv(pe),pe.scrollHeight-pe.clientHeight),W(pe.scrollHeight-pe.scrollTop-pe.clientHeight>=Wv)},[r]),y.useEffect(()=>{const pe=O.current,Qe=X.current;if(!pe||!Qe||typeof ResizeObserver>"u")return;const Ze=new ResizeObserver(()=>{if(B.current&&!H.current){pe.scrollTop=pe.scrollHeight;return}const _t=I.current;_t&&(performance.now()>_t.until?I.current=null:pe.scrollTop=Fk(_t.at,qv(pe),pe.scrollHeight-pe.clientHeight)),H.current||W(pe.scrollHeight-pe.scrollTop-pe.clientHeight>=Wv)});return Ze.observe(Qe),Ze.observe(pe),()=>Ze.disconnect()},[]);const{turns:le,kids:oe}=y.useMemo(()=>{const pe=new Map,Qe=[];for(const Ze of e){if(!Ze.parent){Qe.push(Ze);continue}const _t=pe.get(Ze.parent);_t?_t.push(Ze):pe.set(Ze.parent,[Ze])}return{turns:xpe(Qe),kids:pe}},[e]),ye=()=>({id:r,ready:le.length>0,first:Gfe(le,r?EL(r)?.turn:void 0)});let[D,Oe]=y.useState(ye);(D.id!==r||!D.ready&&le.length>0)&&(D=ye(),Oe(D),G.current=null);const ze=Yfe(le,D.first),Ce=y.useMemo(()=>le.slice(ze),[le,ze]),ve=y.useMemo(()=>E?.size&&ze>0?le.slice(0,ze).flatMap(pe=>pe.map(Qe=>E.get(Qe.id)).filter(Boolean)):[],[E,le,ze]),Ie=ze>0||_,ae=async()=>{if(!Ie||k||$.current)return;const pe=O.current;if(!pe)return;const Qe=r,Ze=qv(pe);let _t=ML(pe.scrollTop,Ze);if(!_t.turn&&Ze[0]&&(_t={top:pe.scrollTop,turn:Ze[0].id,delta:pe.scrollTop-Ze[0].offset}),G.current={id:Qe,first:Ce[0]?.[0].id,at:_t},Y(),B.current=!1,ze>0){Oe({id:Qe,ready:!0,first:le[Math.max(0,ze-Q7)][0].id});return}$.current=!0;try{await j?.(),U.current===Qe&&Oe({id:Qe,ready:!0,first:null})}finally{$.current=!1}};q.current=()=>{N||ae()},y.useLayoutEffect(()=>{const pe=G.current,Qe=O.current;!pe||pe.id!==r||!Qe||pe.first===Ce[0]?.[0].id||(G.current=null,Qe.scrollTop=Fk(pe.at,qv(Qe),Qe.scrollHeight-Qe.clientHeight),I.current={at:pe.at,until:performance.now()+$4},W(Qe.scrollHeight-Qe.scrollTop-Qe.clientHeight>=Wv))},[Ce,r]);const $e=y.useMemo(()=>Jde(e),[e]),{fresh:He,nth:Wt}=ype(le),yt=y.useMemo(()=>Ce.map(pe=>pe[0].id),[Ce]),Bt=Mse(r??"",yt),Gt=y.useMemo(()=>({current:Bt}),[Bt]),qt=y.useMemo(()=>Rfe(Ce),[Ce]),Nt=y.useContext(A$),ht=y.useMemo(()=>Wie(Ce.flat()),[Ce]),Be=y.useMemo(()=>{if(!Nt)return null;const pe=Ce.flat(),Qe=ht.ids.size?Nt.questions.filter(Ze=>!ht.ids.has(Ze.id)):Nt.questions;return{placement:Lie(pe,Qe),late:Oie(pe),onDone:Nt.onDone}},[Nt,Ce,ht]),ue=()=>{Y(),I.current=null,B.current=!1,W(!0)},Te=y.useRef(ue);Te.current=ue,y.useEffect(()=>{if(Nt)return Yie(pe=>{Te.current(),pe.scrollIntoView({block:"center",behavior:B4()?"auto":"smooth"})})},[!!Nt]),y.useLayoutEffect(()=>{Wt&&B.current&&ne()},[Wt]);const Pe=y.useMemo(()=>{const pe=[];for(const Qe of e.slice(-40))if(Qe.role==="assistant")for(const Ze of Qe.blocks){if(Ze.kind!=="text")continue;const _t=Ze.text.trim();_t&&_t.length<=120&&pe.push(_t)}return pe},[e]),dt=y.useMemo(()=>({say:o??(()=>{}),said:Pe}),[o,Pe]);return a.jsxs("div",{className:"msgs",ref:O,children:[a.jsx(Bfe,{turns:qt,scrollerRef:O,innerRef:X,onJump:ue}),a.jsxs(Mde,{say:dt.say,said:dt.said,readOnly:!o,children:[a.jsx(a$.Provider,{value:Gt,children:a.jsx(h$.Provider,{value:r?`chat:${r}`:null,children:a.jsx(s1.Provider,{value:Be,children:a.jsx(GA.Provider,{value:ht,children:a.jsxs("div",{className:"msgs-inner",ref:X,children:[Ie&&a.jsxs("div",{className:"history-more",children:[a.jsx("button",{type:"button",disabled:k,onClick:()=>{ae()},children:k?"Loading earlier messages…":"Load earlier messages"}),N&&a.jsx("span",{role:"alert",children:"Could not load earlier messages. Try again."})]}),A,ve,Ce.map((pe,Qe)=>a.jsxs(y.Fragment,{children:[a.jsx(mpe,{messages:pe,kids:oe,agentByTool:l,onOpenAgent:u,last:Qe===Ce.length-1,busy:n,tints:$e,fresh:He.has(pe[0].id),mapTurnId:pe[0].role==="user"&&!hg(pe[0].turnId)?pe[0].id:void 0,hostName:h,hostPersona:f,onCancelQueued:m,onStartQueued:g,onRestoreUnsent:x,onDismissUnsent:b}),!!s&&pe.some(Ze=>Ze.id===s)&&a.jsx(ppe,{}),!!E?.size&&pe.map(Ze=>E.get(Ze.id)).filter(Boolean)]},pe[0].id)),i!==void 0&&a.jsx(dpe,{since:i}),a.jsx(ore,{}),M,a.jsx("div",{ref:L})]})})})})}),a.jsx("div",{className:"jump-slot","aria-hidden":!z,children:a.jsx("button",{type:"button",className:`jump ${z?"is-on":""}`,onClick:he,tabIndex:z?0:-1,title:"Jump to the end","aria-label":"Jump to the end",children:a.jsx(Ape,{})})})]})]})},sz=y.memo(Npe);function Ape(){return a.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:a.jsx("path",{d:"m6 9 6 6 6-6"})})}function Epe({messages:t,parent:e}){const n=new Map;for(const i of t){if(!i.parent)continue;const r=n.get(i.parent);r?r.push(i):n.set(i.parent,[i])}const s=n.get(e);return s?.length?a.jsx(ez,{messages:s,kids:n}):null}function Mpe(t){const[e,n]=y.useState({loading:!1});return y.useEffect(()=>{if(!t){n({loading:!1});return}let s=!0;return n({loading:!0}),te.invoke("read_file_preview",{path:t}).then(i=>{if(s){if(i.kind!=="text"){n({loading:!1,error:`the run's output is ${i.kind}, not text`});return}n({loading:!1,text:i.content,truncated:i.truncated})}}).catch(i=>{s&&n({loading:!1,error:i instanceof Error?i.message:String(i)})}),()=>{s=!1}},[t]),e}function Lpe({label:t,value:e,rolling:n=!1}){return a.jsxs("div",{className:"focus-stat",children:[a.jsx("span",{className:"focus-stat-label",children:t}),a.jsx("span",{className:"focus-stat-value",children:n?a.jsx(Kt,{children:e}):e})]})}function Tpe({run:t}){const e=Mpe(t.outputFile),n=t.workers??[];return a.jsxs(a.Fragment,{children:[a.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&&a.jsx("ul",{className:"focus-workers",children:n.map(s=>a.jsxs("li",{className:`focus-worker ${s.state==="done"?"is-done":"is-running"}`,children:[a.jsxs("div",{className:"focus-worker-head",children:[a.jsx("span",{className:"focus-worker-label",children:s.label||`agent ${s.index}`}),s.tokens!==void 0&&a.jsx("span",{className:"focus-worker-cost",children:a.jsx(Kt,{children:`${s.tokens.toLocaleString()} tok`})})]}),s.resultPreview&&a.jsx("div",{className:"focus-worker-result",children:s.resultPreview})]},s.id))}),a.jsx("h4",{className:"focus-heading",children:"Result"}),e.loading&&a.jsx("div",{className:"focus-muted",children:"reading the run's output…"}),e.error&&a.jsxs("div",{className:"focus-muted",children:["could not read the output file — ",e.error]}),e.text!==void 0&&a.jsxs(a.Fragment,{children:[a.jsx("pre",{className:"focus-output",children:e.text}),e.truncated&&a.jsx("div",{className:"focus-muted",children:"…output truncated"})]}),!t.outputFile&&!e.loading&&a.jsx("div",{className:"focus-muted",children:t.summary??"this run wrote no output file"})]})}function Rpe({run:t,messages:e}){const n=t.toolUseId?a.jsx(Epe,{messages:e,parent:t.toolUseId}):null;return n||a.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&&a.jsx("pre",{className:"focus-output",children:t.summary})]})}function Dpe({run:t,messages:e,onBack:n}){const s=[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(i=>!!i);return a.jsxs("div",{className:"focus",children:[a.jsxs("div",{className:"focus-bar",children:[a.jsx("button",{className:"focus-back",onClick:n,type:"button",children:"← conversation"}),a.jsx("span",{className:`focus-status is-${t.status}`,children:t.status})]}),a.jsxs("div",{className:"focus-scroll",children:[a.jsx("h3",{className:"focus-title",children:t.label}),s.length>0&&a.jsx("div",{className:"focus-stats",children:s.map(i=>a.jsx(Lpe,{label:i.label,value:i.value,rolling:i.rolling},i.label))}),t.kind==="local_workflow"?a.jsx(Tpe,{run:t}):a.jsx(Rpe,{run:t,messages:e})]})]})}function d2(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 Ope(t){return t<1e3?`${t}`:`${(t/1e3).toFixed(t<1e4?1:0)}k`}function Ipe(t){return I_(t)??/opus|sonnet|haiku|fable|gpt|codex/i.exec(t)?.[0].toLowerCase()??t}function Bpe(t){const[e,n]=y.useState(()=>Date.now());return y.useEffect(()=>{if(!t)return;n(Date.now());const s=setInterval(()=>n(Date.now()),1e3);return()=>clearInterval(s)},[t]),e}function iz(t,e,n,s,i){return t?n?d2(Math.max(0,e-n)):"running…":[s!==void 0?Ope(s):void 0,i!==void 0?d2(i):void 0].filter(Boolean).join(" · ")}function P4({worker:t,now:e}){const n=t.state!=="done",s=t.queuedAt&&t.startedAt&&t.startedAt-t.queuedAt>=1e3?t.startedAt-t.queuedAt:void 0;return a.jsxs("li",{className:`rail-row is-worker ${n?"is-running":"is-completed"}`,children:[a.jsx("span",{className:"rail-dot","aria-hidden":"true"}),a.jsxs("span",{className:"rail-body",children:[a.jsx("span",{className:"rail-label",children:t.label||`agent ${t.index}`}),a.jsxs("span",{className:"rail-meta",children:[t.model&&a.jsx("span",{className:"rail-kind rail-model",children:Ipe(t.model)}),t.attempt!==void 0&&t.attempt>1&&a.jsx("span",{className:"rail-retry",children:a.jsx(Kt,{children:`retry ${t.attempt}`})}),s&&a.jsx("span",{className:"rail-kind",children:a.jsx(Kt,{children:`queued ${d2(s)}`})}),a.jsx("span",{className:n?"rail-live":"rail-stats",children:a.jsx(Kt,{children:iz(n,e,t.startedAt,t.tokens,t.durationMs)})})]})]})]})}function $pe({run:t,now:e}){const n=t.workers??[],s=t.phases??[],i=n.filter(r=>!s.some(o=>o.index===r.phaseIndex));return a.jsxs(a.Fragment,{children:[s.map(r=>{const o=n.filter(u=>u.phaseIndex===r.index);if(o.length===0)return null;const l=o.filter(u=>u.state!=="done").length;return a.jsxs("li",{className:"rail-phase",children:[a.jsxs("div",{className:"rail-phase-head",children:[a.jsx("span",{className:"rail-phase-title",children:r.title}),a.jsx("span",{className:"rail-phase-count",children:a.jsx(Kt,{children:l>0?`${l}/${o.length}`:`${o.length}`})})]}),a.jsx("ul",{className:"rail-sub",children:o.map(u=>a.jsx(P4,{worker:u,now:e},u.id))})]},r.index)}),i.length>0&&a.jsxs("li",{className:"rail-phase",children:[a.jsx("div",{className:"rail-phase-head",children:a.jsx("span",{className:"rail-phase-title",children:"other"})}),a.jsx("ul",{className:"rail-sub",children:i.map(r=>a.jsx(P4,{worker:r,now:e},r.id))})]})]})}function Ppe({run:t,now:e,onOpen:n}){const s=t.status==="running";return a.jsxs("li",{className:`rail-run is-${t.status}`,children:[a.jsxs("button",{className:"rail-row",type:"button",onClick:()=>n?.(t.id),children:[a.jsx("span",{className:"rail-dot","aria-hidden":"true"}),a.jsxs("span",{className:"rail-body",children:[a.jsx("span",{className:"rail-label",children:t.label}),a.jsxs("span",{className:"rail-meta",children:[t.detail&&a.jsx("span",{className:"rail-kind",children:t.detail}),a.jsx("span",{className:s?"rail-live":"rail-stats",children:a.jsx(Kt,{children:iz(s,e,t.startedAt,t.tokens,t.durationMs)})})]})]})]}),(t.workers?.length??0)>0&&a.jsx("ul",{className:"rail-tree",children:a.jsx($pe,{run:t,now:e})})]})}function zpe({count:t,open:e,onToggle:n}){return t===0?null:a.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:[a.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:[a.jsx("path",{d:"M11 3l1.7 4.3L17 9l-4.3 1.7L11 15l-1.7-4.3L5 9l4.3-1.7z"}),a.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"})]}),a.jsx("span",{className:"topbar-action-label",children:"Agents"}),a.jsx("span",{className:"rail-count",children:a.jsx(Br,{value:t})})]})}function Fpe({agents:t,onOpen:e,onClose:n}){const s=t.filter(r=>r.status==="running").length,i=Bpe(s>0);return t.length===0?null:a.jsxs("aside",{className:"rail","aria-label":"agents",children:[a.jsxs("header",{className:"rail-head",children:[a.jsx("span",{className:"rail-title",children:"Agents"}),n&&a.jsx("button",{className:"rail-close",type:"button","aria-label":"Hide agents",onClick:n,children:"✕"})]}),a.jsx("ul",{className:"rail-list",children:t.map(r=>a.jsx(Ppe,{run:r,now:i,onOpen:e},r.id))}),a.jsx("div",{className:"rail-foot",children:a.jsx(Kt,{children:s>0?`${s} running`:`${t.length} finished`})})]})}function rz(t){if(t.parent||t.relay)return;const e=t.blocks.flatMap(n=>n.kind==="text"?[n.text]:[]).join(`
97
- `).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 Hpe(t){const e=[];for(let n=t.length-1;n>=0&&e.length<3;n--){const s=t[n],i=rz(s);i&&e.unshift(i)}return e}function f2(t){for(let e=t.length-1;e>=0;e--){if(t[e].role==="user")continue;const n=rz(t[e]);if(n)return n}}function IE(t){const e=[],n=i=>`${e.push(i)-1}`;return t.replace(/\\([\\`*_{}[\]()#+\-.!~|<>])/g,(i,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,(i,r)=>r.split("|").map(o=>o.trim()).filter(Boolean).join(" · ")).replace(/(`+)([^`]*?)\1/g,(i,r,o)=>n(o.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,(i,r)=>e[Number(r)])}async function Wpe(t,e,n){const s=await t();if(n())return[];if(!s.events.length)return e;let i=await rf(xh(),s.context,0,n);return i=await rf(i,s.events,0,n),i.messages}function qpe(t,e){return new Set(t.filter(n=>n.crossProject||!!e&&n.leadId===e).map(n=>n.chatKey))}function BE(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(i=>e(i.projectId,i.projectName)),s=t.unknownTaskCount?`, ${t.unknownTaskCount} ${t.unknownTaskCount===1?"task has":"tasks have"} no confirmed project`:"";return`${n.join(", ")}${s}, ${t.taskCount} ${t.taskCount===1?"task":"tasks"}`}function az(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 y1(t,e,n,s=!1){const i=`chat:${t.id}`;if(!e)return n&&!n.has(i)?{status:"home",destinations:[],taskCount:0,unknownTaskCount:0,homeProjectId:t.projectId}:{status:s?"unknown":"loading",destinations:[],taskCount:0,unknownTaskCount:0};const r=e.runs.filter(m=>m.coordinatorChatKey===i);if(r.length===0&&n===null)return{status:s?"unknown":"loading",destinations:[],taskCount:0,unknownTaskCount:0};if(!(r.length>0||!!n?.has(i)))return{status:"home",destinations:[],taskCount:0,unknownTaskCount:0,homeProjectId:t.projectId};const l=new Set(r.map(m=>m.id)),u=e.tasks.filter(m=>l.has(m.runId)).sort((m,g)=>g.updatedAt-m.updatedAt||m.id.localeCompare(g.id));if(u.length===0)return{status:"discussion",destinations:[],taskCount:0,unknownTaskCount:0};const h=new Map;let f=0;for(const m of u){if(!m.destination){f+=1;continue}h.has(m.destination.projectId)||h.set(m.destination.projectId,m.destination)}return h.size===0?{status:"unknown",destinations:[],taskCount:u.length,unknownTaskCount:f}:{status:"projects",destinations:[...h.values()],taskCount:u.length,unknownTaskCount:f}}function Upe(t,e,n,s){return t.filter(i=>{const r=y1(i,n,s);return r.status==="home"?r.homeProjectId===e:r.destinations.some(o=>o.projectId===e)}).sort((i,r)=>r.updatedAt-i.updatedAt)}function Vpe(t,e,n){const s=new Map;for(const i of t){const r=y1(i,e,n),o=r.status==="home"?r.homeProjectId?[r.homeProjectId]:[]:r.destinations.map(l=>l.projectId);for(const l of new Set(o))s.set(l,(s.get(l)??0)+1)}return s}const oz=new Set;function Kpe(t,e,n=qo,s=oz){return Upe(t,e,n,s)}function Gpe(t,e=qo,n=oz){return Vpe(t,e,n)}const z4=["#f87171","#fb923c","#fbbf24","#a3e635","#34d399","#22d3ee","#60a5fa","#a78bfa","#f472b6","#94a3b8"];function F4(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 b1(t){const e=t.color?.trim();if(e&&/^#[0-9a-f]{6}$/i.test(e))return e;const n=t.name||t.id;let s=0;for(let i=0;i<n.length;i+=1)s=s*31+n.charCodeAt(i)>>>0;return z4[s%z4.length]}function Ype(t){const e=[...(t.initial??"").trim()].slice(0,2).join("");return e?e.toLocaleUpperCase():[...t.name.trim()][0]?.toLocaleUpperCase()??"?"}function Mh({project:t,size:e="small",className:n=""}){const s=t.icon?.trim(),i={"--project-color":b1(t)};return a.jsx("span",{className:["project-avatar",`is-${e}`,s?"has-icon":"",n].filter(Boolean).join(" "),style:i,"aria-hidden":"true",children:s?a.jsx("img",{className:"project-avatar-image",src:s,alt:""}):a.jsx("span",{className:"project-avatar-text",children:Ype(t)})})}function H4(t,e){const n=new Map(t.map((l,u)=>[l.id,{chat:l,children:[],descendants:[],rank:u}])),s=new Map;for(const l of t){const u=e.get(l.id);if(!u||u===l.id||!n.has(u))continue;let h=u;for(;h&&h!==l.id;)h=s.get(h);h||s.set(l.id,u)}const i=[];for(const l of n.values()){const u=s.get(l.chat.id);u?n.get(u).children.push(l):i.push(l)}const r=l=>n.get(l.chat.id).rank,o=l=>{l.children.forEach(o),l.children.sort((u,h)=>r(u)-r(h)),l.descendants=l.children.flatMap(u=>[u.chat,...u.descendants]);for(const u of l.children)n.get(l.chat.id).rank=Math.min(r(l),r(u))};return i.forEach(o),i.sort((l,u)=>r(l)-r(u))}function p2(t,e){const n=t.tasks.find(i=>i.id===e.taskId);if(!n||!br(n)||t.attempts.some(i=>i.taskId===n.id&&["preparing","running"].includes(i.status)))return"Complete the task and settle its workers before archiving.";if(z_(t,n.runId).some(i=>!i.taskId||i.taskId===n.id))return"Resolve the open decision before archiving.";const s=n.workspace;return s?.abandoned?"Only workers for merged tasks can be archived.":!s||!["retained","cleaned"].includes(s.state)||!s.delivery?.merged||s.delivery.dirty?"Refresh delivery status to verify a clean, merged task before archiving.":null}function m2(t,e,n=!1){const s=new Set(e.attempts.filter(i=>i.archivedAt!=null).map(i=>i.workerChatKey.replace(/^chat:/,"")));return t.filter(i=>s.has(i.id)===n)}const Xpe=["needs","running","finished","planned"],Qpe={needs:"Needs you",running:"Running",finished:"Finished",planned:"Planned"},Zpe={needs:!1,running:!1,finished:!0,planned:!1},lz={needs:1/0,running:1/0,finished:3,planned:3},$E={running:"Running",needs:"Needs you",done:"Done",failed:"Failed"},x_=new Set(["planning","running","waiting"]);function w1(t){const e=Math.floor(Math.max(0,t)/6e4);return e<1?"<1m":e<60?`${e}m`:`${Math.floor(e/60)}h ${String(e%60).padStart(2,"0")}m`}function cz(t){const e=Math.max(0,Math.round(t));return e>=1e7?`${Math.round(e/1e6)}M`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:String(e)}function Jpe(t){if(!t||!Number.isFinite(t.input)||!Number.isFinite(t.output))return null;const e=t.input+t.output;return e>0?e:null}function uz(t){let e=0,n=!1;for(const s of t){const i=Jpe(s.usage);i!==null&&(e+=i,n=!0)}return n?e:null}function eme(t){return!t||!(t.window>0)||!(t.tokens>0)?null:Math.min(100,Math.round(t.tokens/t.window*100))}function tme(t){const e=[t.context?`ctx ${t.context}%`:null,t.tokens?cz(t.tokens):null,t.elapsedMs!==null&&t.elapsedMs>0?w1(t.elapsedMs):null].filter(Boolean);return e.length?e.join(" · "):null}function nme(t){return`${t.done}/${t.total} ${t.total===1?"step":"steps"}`}const sme=10*6e4;function ime(t,e,n){return!t||!e?.current||!e.step||e.at===null?null:{at:e.at,total:e.total,title:e.step,reportedAt:e.reportedAt,stale:n-e.reportedAt>sme}}function rme(t){return`${t.at}/${t.total}`}function ame(t){return t.replace(/\s+/g," ").trim()}function ome(t){return`${t.done} / ${t.total}`}const lme={plan:"Plan to approve",gate:"Asks a decision",failure:"Failed",question:"Asks a question",delivery:"Answer not delivered",permission:"Awaiting approval",safety:"Awaiting review",native:"Awaiting review",outage:"Safety check was down",handover:"Asks a handover"},y_="Waiting on the coordinator",hz="Retrying",W4=t=>`${t} automatic ${t===1?"retry":"retries"}`;function cme(t,e,n,s=null){const i=qN(t);if(!i)return null;const{move:r,kind:o}=i,l=i.because??null,u=t.retryLimit??0,h={move:r,kind:o,because:l};if(r==="coordinator"){const j=t.retriesUsed??0;return{...h,askCoordinator:!1,note:`Its coordinator is fixing it: ${j} of ${W4(u)} used. Nothing is asked of you.`}}if(r==="history")return{...h,askCoordinator:!1,note:l==="replaced"?"Another task replaced it. Nothing is owed for it.":"Its run was stopped, closed or archived. Nothing is owed for it."};const f=l==="coordinator_gone",m=l==="retries_used"?`Its ${W4(u)} are used.`:l==="escalated"?n?`Its coordinator asks you: ${n}`:"Its coordinator asks you to decide.":f?"The chat that coordinated this run is gone, so nobody retries it.":l==="time_limit"?"This peer request used up its working time.":"This failure waits on you.",g="stop or archive the run",x=l==="escalated"?"Answer it under Needs you above":null,b=e&&!e.blocked?`open this row for ${e.label}`:null,_=!e&&s?`open this row for ${s.label} to put it back to work with what you write`:null,k=[x,b,_].filter(Boolean),N=j=>j.charAt(0).toUpperCase()+j.slice(1);return k.length?{...h,askCoordinator:!1,note:`${m} ${N(k.join(", "))}, or ${g}.`}:e?.blocked?{...h,askCoordinator:!1,note:`${m} ${e.blocked}`}:f?{...h,askCoordinator:!1,note:`${m} ${N(g)} to put it away.`}:{...h,askCoordinator:!0,note:`${m} It cannot be started from here: ask the coordinator in its chat, or ${g}.`}}function b_(t,e,n,s,i){const r=s.person.find(h=>!h.failure);if(r)return{state:"needs",why:lme[r.kind],tone:"decide"};const o=qN(e);if(o?.move==="person")return{state:"failed",why:RC[o.kind],tone:"danger"};if(o?.move==="coordinator")return{state:"running",why:y_,tone:null};if(o?.move==="history"&&!e.supersededBy)return{state:"closed",why:RC[o.kind],tone:null};if(!o&&Sh(e))return{state:"failed",why:Om,tone:"danger"};if(sg(e))return{state:"done",why:null,tone:null};if(e.status==="cancelled")return{state:"closed",why:"Cancelled",tone:null};if(e.supersededBy)return{state:"closed",why:"Replaced",tone:null};if(t.status==="stopped")return{state:"closed",why:"Stopped",tone:null};if(s.coordinator.length)return{state:"running",why:y_,tone:"warn"};if(i?.kind==="stopped")return{state:"planned",why:i.label,tone:i.tone};const l=!!n&&e.activeAttemptId===n.id;if(zI(e))return l&&Bm(n)?{state:"running",why:$x[n.execution.state],tone:"warn"}:{state:"running",why:hz,tone:null};if(e.status==="failed")return{state:"failed",why:"Failed",tone:"danger"};const u=s.unsaid[0];if(u?.kind==="gate")return{state:"running",why:"Asks a decision",tone:null};if(e.status==="blocked")return u?{state:"running",why:"Decision recorded",tone:null}:{state:"failed",why:"Blocked",tone:"danger"};if(e.status==="running"){if(l&&n.execution){const h=n.execution.pendingTools?.["octiq:environment"];if(h)return{state:"running",why:h.startsWith("Waiting for environment capacity")?"Waiting for an environment slot":"Preparing environment",tone:null};if(Bm(n)||n.execution.state==="retrying")return{state:"running",why:$x[n.execution.state],tone:"warn"}}return l&&YN(n)==="proposed"?{state:"running",why:"Report proposed",tone:null}:n?.status==="preparing"&&!n.execution?{state:"running",why:"Preparing workspace",tone:null}:{state:"running",why:null,tone:null}}return{state:"planned",why:i?.label??null,tone:i?.tone??null}}const ume={needs:"needs",failed:"running",running:"running",done:"finished",closed:"finished",planned:"planned"};function hme(t,e){return e==="failed"&&ig(t)==="person"?"needs":ume[e]}function dme(t){return WN(t.task)?ig(t.task)==="person":t.state==="failed"}function fme(t,e,n){return n.state!=="running"||n.tone==="warn"||t.status!=="running"?!1:!!e&&t.activeAttemptId===e.id&&XN(e)}function dz(t,e,n,s,i,r=Yc(t,e,i)){const o=KN(t,n),l=r.tasks.get(n.id)??P_,u=f0(n,e,t.tasks,s),h=b_(e,n,o,l,u),f=hme(n,h.state),m=qN(n),g=m?.move==="person"?s6(n,e,t.tasks,t.attempts,r.gated.has(n.id)):null,x=m?.gateId?z_(t,e.id).find(L=>L.id===m.gateId)?.question??null:null,b=m?.move==="person"?i6(n,e):null,_=cme(n,g,x,b),k=QI(n,o,o?t.reports?.[o.workerChatKey]:void 0),N=k?{done:k.done,total:k.total}:null,j=t.attempts.filter(L=>L.taskId===n.id),M=new Map(t.tasks.map(L=>[L.id,L])),A=h.state==="running"||h.state==="needs",E=fme(n,o,h);return{task:n,attempt:o,...h,group:f,flight:E,step:ime(E,k,s),decisions:f==="needs"?l.person.length:0,failure:_&&(_.move==="person"||h.why===(_.move==="coordinator"?y_:RC[_.kind]))?_:null,hint:l.unsaid.length&&(h.state==="running"||h.state==="failed"||h.state==="planned")?qI:null,hold:h.state==="planned"?u:null,steps:N,percent:N?Math.round(N.done/N.total*100):h.state==="done"?100:null,model:o?.model||n.worker?.model||null,effort:o?.effort||n.worker?.effort||null,after:h.state!=="planned"?[]:n.dependsOn.flatMap(L=>{const O=M.get(L);return O&&!sg(O)?[O.title]:[]}),verdict:br(n)?n.verdict??null:null,elapsedMs:SV(t,n,s),tokens:uz(j),context:A&&o&&n.activeAttemptId===o.id?eme(o.context):null}}function fz(t,e){return t.planApproval?.status!=="pending"?!1:e.every(n=>n.state==="done"||n.state==="closed"||n.state==="planned"&&n.hold?.kind==="plan")}function pme(t,e){const n=new Map(e.map((r,o)=>[r,o])),s=(r,o)=>n.get(r)-n.get(o);if(t==="needs")return e;if(t==="finished"){const r=o=>o.attempt?.finishedAt??o.task.updatedAt;return[...e].sort((o,l)=>+(o.state==="closed")-+(l.state==="closed")||r(l)-r(o)||s(o,l))}if(t==="planned"){const r=o=>o.hold?.kind==="stopped"?0:o.hold?.tone==="warn"?1:o.hold?2:3;return[...e].sort((o,l)=>r(o)-r(l)||+(l.task.status==="ready")-+(o.task.status==="ready")||s(o,l))}const i=r=>r.state==="failed"?0:r.tone==="warn"?1:2;return[...e].sort((r,o)=>i(r)-i(o)||s(r,o))}function mme(t,e){const n=lz[t.key];return e||t.rows.length<=n+1?{rows:t.rows,more:0}:{rows:t.rows.slice(0,n),more:t.rows.length-n}}const Zc=(t,e,n)=>`${t} ${t===1?e:n}`;function gme(t){const e=t.rows.length;if(t.key!=="needs")return{label:`${t.label} · ${e}`,spoken:`${t.label}, ${Zc(e,"task","tasks")}`};const n=Zc(t.rows.reduce((s,i)=>s+i.decisions,0),"decision","decisions");return{label:`${t.label} · ${n}`,spoken:`${t.label}, ${n} in ${Zc(e,"task","tasks")}`}}function pz(t,e){const n=t.working?{text:`${t.working} working`,strong:!1}:null,s=t.failed?{text:`${t.failed} failed`,strong:!1}:null,i=t.runs>1?{text:`${t.runs} runs`,strong:!1}:null,r=t.stopped?{text:`${t.stopped} stopped`,strong:!1}:null;return(t.state==="needs"?[{text:t.planOnly?"Plan to approve":Zc(t.needs,"decision","decisions"),strong:!0},i??s??n??r]:t.state==="failed"?[{text:`${t.failed} failed`,strong:!0},i??n??r]:t.state==="done"?[e!==null&&e>0?{text:w1(e),strong:!1}:null,i]:[n,i??r]).filter(l=>!!l).slice(0,2)}function vme(t){const[e,...n]=t.side;return t.state==="failed"&&e?.strong?{word:e.text,side:n}:{word:t.word,side:t.side}}function xme(t,e){return br(e)?!0:e.status!=="cancelled"&&!e.supersededBy&&t.status!=="stopped"}function mz(t,e){const n=e.filter(r=>xme(t,r.task)),s=e.filter(dme).length,i=!e.some(r=>WN(r.task));return{done:n.filter(r=>sg(r.task)).length,total:n.length,failed:s+(i&&t.status==="failed"&&!s&&!e.some(r=>r.hold?.kind==="stopped")?1:0)}}function gz(t,e,n,s=Yc(t,e,n)){return mz(e,t.tasks.filter(i=>i.runId===e.id).map(i=>{const r=f0(i,e,t.tasks,0),{state:o}=b_(e,i,KN(t,i),s.tasks.get(i.id)??P_,r);return{task:i,state:o,hold:o==="planned"?r:null}}))}function yme(t){const e=i=>t.filter(r=>r.hold?.kind===i).length,[n,s]=[e("stopped"),e("reopen")];return[n?`${Zc(n,"task","tasks")} stopped by you: only your Start starts ${n===1?"it":"them"} again.`:null,s?`${Zc(s,"reopened task","reopened tasks")} held: the notice of ${s===1?"it":"them"} is not confirmed as saved yet.`:null].filter(i=>!!i)}function PE(t,e,n,s,i=Yc(t,e,s)){const r=t.tasks.filter(j=>j.runId===e.id),o=t.attempts.filter(j=>j.runId===e.id),l=r.map(j=>dz(t,e,j,n,s,i)),u=Xpe.flatMap(j=>{const M=l.filter(A=>A.group===j);return M.length?[{key:j,label:Qpe[j],rows:pme(j,M)}]:[]}),{done:h,total:f,failed:m}=mz(e,l),g=XI(t,e.id,n),x={tasks:{done:h,total:f},tokens:uz(o),elapsedMs:g},b=x_.has(e.status),_=i.person.length,k=l.filter(j=>j.flight).length;let N=null;if(_>0||f>0&&e.archivedAt==null&&e.status!=="closed"&&e.status!=="stopped"){const j=i.person.filter(X=>X.failure).length,M=_?j===_?"failed":"needs":m?"failed":h===f?"done":"running",A=l.filter(X=>X.failure?.move==="coordinator").length,E=[i.coordinator.length?`${i.coordinator.length} waiting on the coordinator.`:null,A?`${Zc(A,"failure","failures")} with the coordinator, which is fixing ${A===1?"it":"them"}: nothing is asked of you.`:null,i.unsaid.length?`${Zc(i.unsaid.length,"open decision","open decisions")}: the host does not say who ${i.unsaid.length===1?"it waits":"they wait"} on.`:null,...yme(l)].filter(X=>!!X),L=l.filter(X=>X.hold?.kind==="stopped").length,O={state:M,needs:_,failures:j,planOnly:_===1&&i.person[0].kind==="plan",failed:m,stopped:L,working:k,runs:1};N={...O,word:$E[M],done:h,total:f,percent:f?Math.round(h/f*100):0,label:f?`${h}/${f}`:r.length===0?"No tasks yet":e.status==="stopped"?"Run stopped":"No tasks left",side:pz(O,g),live:M==="running"&&b&&k>0,notes:E,signature:[e.id,M,`${h}/${f}`,_,m].join(":")}}return{rows:l,groups:u,tiles:x,strip:N}}function bme(t){return t.find(e=>x_.has(e.status)&&e.archivedAt==null)??t.find(e=>e.archivedAt==null&&e.status!=="closed"&&e.status!=="stopped")??null}function wme(t,e,n){const s=rg(t,n),i=b=>{const _=PE(t,b,e,n,s.runs.get(b.id)).strip;return _?[{run:b,strip:_}]:[]},r=t.runs.filter(b=>x_.has(b.status)&&b.archivedAt==null||!!s.runs.get(b.id)?.person.length).flatMap(i);if(r.length<2){if(r.length===1)return r[0];const b=bme(t.runs);return b?i(b)[0]??null:null}const o=r.find(b=>b.strip.state==="needs")??r.find(b=>b.strip.needs>0)??r.find(b=>b.strip.state==="failed")??r.find(b=>b.strip.live)??r[0],l=r.reduce((b,_)=>b+_.strip.needs,0),u=r.reduce((b,_)=>b+_.strip.failures,0),h=r.filter(b=>b.strip.needs>0),f=l?u===l?"failed":"needs":o.strip.state,m={state:f,needs:l,failures:u,planOnly:l===1&&h[0].strip.planOnly,failed:u?r.reduce((b,_)=>b+(_.strip.failures?_.strip.failed:0),0):o.strip.failed,stopped:o.strip.stopped,working:o.strip.working,runs:r.length},g=r.length-1,x=r.every(b=>x_.has(b.run.status)&&b.run.archivedAt==null);return{run:o.run,strip:{...o.strip,...m,word:$E[f],side:pz(m,null),notes:[`The bar is one of ${r.length} ${x?"live runs":"runs"} of this chat${o.strip.needs?", the one that waits on you":""}.`,...l>o.strip.needs?[`${Zc(l-o.strip.needs,"decision","decisions")} in ${g===1?"the other run":"the other runs"}.`]:[],...r.flatMap(b=>b.strip.notes)],signature:[o.run.id,f,`${o.strip.done}/${o.strip.total}`,l,m.failed,r.length].join(":")}}}const vz=40;function _me(t,e){const n=e.slice(0,e.indexOf(":"));return[...t.filter(s=>!s.startsWith(`${n}:`)),e].slice(-vz)}function kme(t,e){return!!e&&t.includes(e.signature)}function Sme(t){if(!t)return[];try{const e=JSON.parse(t);return Array.isArray(e)?e.filter(n=>typeof n=="string").slice(-vz):[]}catch{return[]}}const Lh=t=>["planning","running","waiting"].includes(t.status);function i0(t,e){if(!e)return qo;const n=t.runs.filter(i=>i.coordinatorChatKey===e).sort((i,r)=>Number(Lh(r))-Number(Lh(i))||r.createdAt-i.createdAt),s=new Set(n.map(i=>i.id));return{runs:n,reports:t.reports,tasks:t.tasks.filter(i=>s.has(i.runId)),...t.nativeDecisions?{nativeDecisions:t.nativeDecisions.filter(i=>s.has(i.runId))}:{},attempts:t.attempts.filter(i=>s.has(i.runId)),gates:t.gates.filter(i=>s.has(i.runId)),messages:t.messages.filter(i=>s.has(i.runId)),notifications:t.notifications?.filter(i=>s.has(i.runId))}}function Cme(t,e){const n=rg(t,e);return t.runs.find(s=>n.runs.get(s.id)?.person.length)??t.runs.find(s=>s.archivedAt==null)??t.runs[0]}function jme(t,e,n){const s=Yc(t,e,n),{done:i,total:r,failed:o}=gz(t,e,n,s),l=(...m)=>m.filter(Boolean).join(" · "),u=r?`${i}/${r} done`:null,h=o?`${o} failed`:null;if(s.person.length)return s.person.every(m=>m.failure)?{text:l(h,u),tone:"danger"}:{text:l($E.needs,h,u),tone:"decide"};if(o)return{text:l(h,u),tone:"danger"};const f=Im(e,t.tasks);return{text:l(f.charAt(0).toUpperCase()+f.slice(1),u),tone:null}}function Nme(t,e,n){const s=jme(t,e,n),i=t.tasks.length,r=t.tasks.filter(o=>o.runId===e.id).length;return t.runs.length<2||i===r?s:{...s,text:`${s.text} · ${i} ${i===1?"task":"tasks"} in ${t.runs.length} runs`}}function Ame(t,e){return e.archivedAt!=null?{text:`${t.title} · archived`,tone:null}:Sh(t)&&t.activeAttemptId===e.id?{text:`${t.title} · ${Om.toLowerCase()}`,tone:Vo(t)==="red"?"danger":null}:{text:`${t.title} · ${e.status}`,tone:null}}function Eme(t,e,n){const s=new Set(t.map(o=>o.id)),i=new Map(e.runs.map(o=>[o.id,o])),r=new Set;for(const o of e.tasks){const l=e.attempts.filter(f=>f.taskId===o.id).sort((f,m)=>m.number-f.number),u=l.find(f=>f.id===o.activeAttemptId)??l[0],h=i.get(o.runId)?.coordinatorChatKey.replace(/^chat:/,"");if(!(!u||!h||!s.has(h)||!s.has(u.workerChatKey.replace(/^chat:/,""))))for(const f of l)f.id!==u.id&&r.add(f.workerChatKey.replace(/^chat:/,""))}return m2(t,e).filter(o=>o.id===n||!r.has(o.id))}function xz(t,e){const n=t.teamId?e.find(s=>s.id===t.teamId):void 0;return n?{id:n.id,name:n.name}:null}function yz(t){const e=new Set(t.map(l=>l.id)),n=(l,u)=>l.name.localeCompare(u.name),s=l=>t.filter(u=>u.reportsTo===l).sort(n),i=[],r=new Set,o=(l,u)=>{if(!r.has(l.id)){r.add(l.id),i.push({agent:l,depth:u});for(const h of s(l.id))o(h,u+1)}};for(const l of t.filter(u=>!u.reportsTo||!e.has(u.reportsTo)).sort(n))o(l,0);return i}const r0={working:"Working",needs_you:"Needs you",failed:"Failed",blocked:"Blocked",stalled:"Stalled",queued:"Queued",idle:"Idle",unknown:"Unknown"},g2=["working","needs_you","failed","blocked","stalled","queued","unknown","idle"],q4=["needs_you","failed","blocked","stalled","working","queued","unknown","idle"],Mme=["planning","running","waiting"];function bz(t,e){const n=t.attempts.filter(s=>s.taskId===e.id);return n.find(s=>s.id===e.activeAttemptId)??[...n].sort((s,i)=>i.number-s.number)[0]}function wz(t,e,n,s,i){if(!e)return null;const r=s.person.find(h=>!h.failure);if(r)return{state:"needs_you",label:r.kind==="gate"?"Waiting on a decision":"Needs your approval"};if(s.person.length)return{state:"failed",label:b_(e,t,n,s,i).why??r0.failed,tone:"danger"};if(e.archivedAt||!(Mme.includes(e.status)||Vo(t)==="quiet"))return null;const o=b_(e,t,n,s,i);if(o.state==="failed")return{state:"failed",label:o.why??r0.failed,tone:"danger"};if(o.state==="done"||o.state==="closed")return null;const l=Vo(t)==="quiet";if(l||zI(t)){const h=!l&&!!n&&(n.execution?.state==="executing"||n.execution?.state==="waiting_tool");if(o.tone!=="warn")return{state:h?"working":"queued",label:o.why??hz}}if(s.coordinator.length)return{state:"blocked",label:"Waiting on the coordinator"};if([...s.nobody,...s.unsaid].some(h=>h.kind==="gate"))return{state:"blocked",label:"Decision open"};if(i)return{state:"queued",label:i.label,detail:i.detail,...i.tone?{tone:i.tone}:{}};if(t.status==="blocked")return{state:"blocked",label:"Blocked"};if(t.status==="pending"||t.status==="ready")return{state:"queued",label:t.status==="ready"?"Ready to start":"Queued"};if(!n)return{state:"queued",label:"Starting"};const u=n.execution?.state;if(u)switch(u){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 Lme(t,e){const n=new Map(t.runs.map(i=>[i.id,i])),s=rg(t,e);return t.tasks.filter(i=>{const r=bz(t,i),o=n.get(i.runId);return wz(i,o,r,_z(s,i),f0(i,o,t.tasks,0))?.state==="working"}).length}const _z=(t,e)=>t.runs.get(e.runId)?.tasks.get(e.id)??P_;function Tme(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 _b=(t,e)=>t.indexOf(e);function Rme(t){const{team:e,leads:n,snapshot:s,projects:i}=t;if(!e)return[];const r=new Map(i.map(j=>[j.id,j])),o=new Map((s?.runs??[]).map(j=>[j.id,j])),l=s?rg(s,t.held):null,u=new Map,h=new Map,f=(j,M)=>{u.set(j,[...u.get(j)??[],M])},m=(j,M,A,E)=>{const L=h.get(j);(!L||L.at<E)&&h.set(j,{chatKey:M,title:A,at:E})};for(const j of s?.tasks??[]){const M=j.assignee?.id;if(!M||!s)continue;const A=o.get(j.runId),E=bz(s,j);E&&t.chatExists(E.workerChatKey)&&m(M,E.workerChatKey,j.title,E.updatedAt);const L=wz(j,A,E,l?_z(l,j):P_,f0(j,A,s.tasks,t.now??0));if(!L)continue;const O=j.destination;f(M,{key:`task:${j.id}`,kind:"task",...L,title:j.title,project:O?{id:O.projectId,name:r.get(O.projectId)?.name??O.projectName}:null,chatKey:E?.workerChatKey??null,runId:j.runId,taskId:j.id,at:E?.updatedAt??j.updatedAt})}for(const j of n){if(!t.chatExists(j.chatKey))continue;const M=s?.runs.filter(X=>X.coordinatorChatKey===j.chatKey&&!X.archivedAt).sort((X,q)=>q.updatedAt-X.updatedAt)[0],A=t.chatTitle(j.chatKey)??M?.objective??"Conversation";m(j.leadId,j.chatKey,A,Math.max(j.createdAt,M?.updatedAt??0));const E=(s?.runs??[]).filter(X=>X.coordinatorChatKey===j.chatKey).flatMap(X=>l?.runs.get(X.id)?.person.filter(q=>!q.taskId)??[]),L=E.find(X=>X.kind==="plan"),O=Tme(t.leadActivity(j.chatKey),!!L,t.waitingOn(j.chatKey)+E.filter(X=>X.kind!=="plan").length);O&&f(j.leadId,{key:`lead:${j.chatKey}`,kind:"lead",...O,title:A,project:j.crossProject?null:r.get(j.projectId)??null,crossProject:!!j.crossProject,chatKey:j.chatKey,runId:L?.runId??M?.id,at:M?.updatedAt??j.createdAt})}const g=j=>{const M=[...u.get(j.id)??[]].sort((X,q)=>_b(q4,X.state)-_b(q4,q.state)||q.at-X.at),A={};for(const X of M)A[X.state]=(A[X.state]??0)+1;const E=[...M].sort((X,q)=>_b(g2,X.state)-_b(g2,q.state))[0],L=E?.state??(s?"idle":"unknown"),O=E?.label??(s?"Nothing in progress":"Work not loaded");return{...j,state:L,stateLabel:O,activities:M,counts:A,recent:h.get(j.id)??null}},x=new Map(e.map(j=>[j.id,j])),b=j=>{const M=j.reportsTo?x.get(j.reportsTo):void 0;return M?{id:M.id,name:M.name}:null},_=yz(e).map(({agent:j,depth:M})=>g({id:j.id,name:j.name,avatar:j.avatar,detail:t.providerLabel(j),effort:j.effort??null,reportsTo:b(j),role:j.role,scope:j.projectId?r.get(j.projectId)??{id:j.projectId,name:"Unknown project"}:null,team:xz(j,t.teams??[]),depth:M,removed:!1})),k=new Set(e.map(j=>j.id)),N=new Map;for(const j of s?.tasks??[])j.assignee&&!k.has(j.assignee.id)&&N.set(j.assignee.id,j.assignee.name);for(const j of n)k.has(j.leadId)||N.set(j.leadId,j.leadName);for(const[j,M]of N)u.get(j)?.length&&_.push(g({id:j,name:M,detail:"No longer registered",effort:null,reportsTo:null,role:"",scope:null,team:null,depth:0,removed:!0}));return _}function Dme(t){const e=new Map;for(const n of t)e.set(n.state,(e.get(n.state)??0)+1);return g2.filter(n=>e.has(n)).map(n=>({state:n,count:e.get(n)}))}function Ome(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));if(!n)return null;const s=t.tasks.filter(i=>i.runId===n.id);return{run:n,tasks:s,approvable:KI(n,s)!==null}}const _1=y.createContext([]),zE=y.createContext(()=>null);function L0(t){const e=y.useContext(_1);return t?e.find(n=>n.id===t):void 0}function Ime({deleting:t,disabled:e=!1,deleteMs:n,onDelete:s}){const i=t?"Cancel delete":"Delete this chat";return a.jsxs("button",{className:`icon-btn topbar-delete ${t?"is-going":""}`,type:"button","aria-label":i,title:i,disabled:e,onClick:s,children:[t?a.jsx(kz,{ms:n}):a.jsx(Bme,{}),a.jsx("span",{className:"topbar-action-label",children:t?"Undo":"Delete"})]})}function kz({ms:t}){return a.jsxs("svg",{className:"chat-drain",width:"17",height:"17",viewBox:"0 0 16 16","aria-hidden":"true",children:[a.jsx("circle",{className:"chat-drain-track",cx:"8",cy:"8",r:"6.6"}),a.jsx("circle",{className:"chat-drain-arc",cx:"8",cy:"8",r:"6.6",style:{animationDuration:`${t}ms`}}),a.jsx("path",{className:"chat-drain-x",d:"M9.9 6.1 6.1 9.9M6.1 6.1l3.8 3.8"})]})}function Bme(){return a.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:[a.jsx("path",{d:"M4 7h16"}),a.jsx("path",{d:"M9 7V4h6v3"}),a.jsx("path",{d:"m6 7 1 13h10l1-13"}),a.jsx("path",{d:"M10 11v5M14 11v5"})]})}function $me({chat:t,enabled:e,busy:n,getPreviewMessages:s,loadPreview:i,...r}){const o=y.useRef(null),l=y.useRef(void 0),[u,h]=y.useState(!1),f=y.useId(),m=()=>{clearTimeout(l.current),l.current=void 0},g=()=>{m(),h(!1)},x=()=>{m(),e&&(l.current=setTimeout(()=>h(!0),1500))},b=()=>{m(),l.current=setTimeout(()=>h(!1),160)};return y.useEffect(()=>(e||(clearTimeout(l.current),h(!1)),()=>clearTimeout(l.current)),[e]),y.useEffect(()=>{const _=k=>{k.key==="Escape"&&g()};return u&&document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[u]),a.jsxs(a.Fragment,{children:[a.jsx("button",{...r,ref:o,"aria-describedby":u&&e?f:void 0,onPointerEnter:_=>{_.pointerType==="mouse"&&x()},onPointerLeave:b,onFocus:_=>{_.currentTarget.matches(":focus-visible")&&x()},onBlur:g,onClick:_=>{g(),r.onClick?.(_)}}),u&&e&&a.jsx(Pme,{id:f,chat:t,anchor:o.current,messages:s?.(t.id),loadPreview:i,busy:n,onEnter:m,onLeave:b,onClose:g},t.id)]})}function Pme({id:t,chat:e,anchor:n,messages:s,loadPreview:i,busy:r,onEnter:o,onLeave:l,onClose:u}){const h=y.useRef(null),[f,m]=y.useState(e.messages),[g,x]=y.useState(s===void 0&&i?"loading":"ready"),[b,_]=y.useState({left:0,top:0}),k=s!==void 0;y.useEffect(()=>{if(k||!i){x("ready");return}let j=!1;x("loading");const M=setTimeout(()=>{j=!0,x("error")},8e3);return i(e,()=>j).then(A=>{j||(m(A),x("ready"))}).catch(()=>{j||x("error")}).finally(()=>clearTimeout(M)),()=>{j=!0,clearTimeout(M)}},[e.id,k,i]),y.useLayoutEffect(()=>{const j=()=>{const E=(n.closest(".chat")??n).getBoundingClientRect(),L=h.current.getBoundingClientRect(),O=E.right+12,X=O+L.width<=window.innerWidth-12?O:E.left-L.width-12;_({left:Math.max(12,Math.min(X,window.innerWidth-L.width-12)),top:Math.max(12,Math.min(E.top,window.innerHeight-L.height-12))})};j();const M=new ResizeObserver(j);M.observe(h.current),window.addEventListener("resize",u);const A=E=>{h.current?.contains(E.target)||u()};return document.addEventListener("scroll",A,!0),()=>{M.disconnect(),window.removeEventListener("resize",u),document.removeEventListener("scroll",A,!0)}},[n,u]);const N=Hpe(s??f);return Eo.createPortal(a.jsxs("div",{ref:h,id:t,role:"tooltip",className:"chat-preview",style:b,onPointerEnter:o,onPointerLeave:l,children:[a.jsxs("div",{className:"chat-preview-head",children:[a.jsx("strong",{children:e.title}),r&&a.jsx("span",{children:"Working…"})]}),a.jsx("div",{className:"chat-preview-label",children:"Latest conversation"}),N.map(j=>a.jsxs("div",{className:"chat-preview-message",children:[a.jsx("span",{children:j.speaker}),a.jsx("p",{children:j.text})]},j.id)),g==="loading"&&a.jsx("p",{className:"chat-preview-note",children:"Loading latest messages…"}),g==="error"&&a.jsx("p",{className:"chat-preview-note",children:"Preview unavailable. Open the chat to try again."}),g==="ready"&&!N.length&&a.jsx("p",{className:"chat-preview-note",children:"No messages yet."}),a.jsx("div",{className:"chat-preview-foot",children:"Click chat to open · Use ••• for actions"})]}),document.body)}function Sz({info:t,projects:e,limit:n=2,taskCount:s=!0}){const i=new Map(e.map(m=>[m.id,m]));if(t.status==="loading")return a.jsx("span",{className:"conversation-projects is-quiet","aria-label":"Work projects loading",children:"Projects loading…"});if(t.status==="discussion")return a.jsx("span",{className:"conversation-projects is-quiet",children:"Discussion"});if(t.status==="unknown")return a.jsx("span",{className:"conversation-projects is-quiet",children:"Project unknown"});if(t.status!=="projects")return null;const r=t.destinations.map(m=>{const g=i.get(m.projectId);return{id:m.projectId,name:g?.name??m.projectName??"Unknown project",style:g?{"--conversation-project-color":b1(g)}:void 0}}),o=r.slice(0,Math.max(1,n)),l=r.length-o.length,u=t.unknownTaskCount,h=BE(t,(m,g)=>i.get(m)?.name??g??"Unknown project"),f=`${t.taskCount} ${t.taskCount===1?"task":"tasks"}`;return a.jsxs("span",{className:"conversation-projects",title:h,"aria-label":`Work projects: ${h}`,children:[a.jsxs("span",{className:"conversation-project-chips","aria-hidden":"true",children:[o.map(m=>a.jsx("span",{className:`conversation-project-chip${m.style?" is-registered":""}`,style:m.style,children:m.name},m.id)),l>0&&a.jsxs("span",{className:"conversation-project-overflow",children:["+",l]}),u>0&&a.jsx("span",{className:"conversation-project-unknown",children:"+?"})]}),s&&a.jsx("span",{className:"conversation-project-task-count","aria-hidden":"true",children:f})]})}function Cz({info:t,projects:e}){const n=new Map(e.map(l=>[l.id,l])),s=az(t,l=>n.has(l)),i=s?n.get(s):void 0;if(i)return a.jsx(Mh,{project:i,size:"medium"});const r=t.status==="projects"&&t.destinations.length>1,o=t.status==="discussion";return a.jsx("span",{className:`project-avatar is-medium is-neutral${r?" is-several":""}${o?" is-discussion":""}`,"aria-hidden":"true",children:r?a.jsx(Hme,{}):o?a.jsx(zme,{}):t.status==="loading"?null:"?"})}function zme(){return a.jsx("svg",{viewBox:"0 0 16 16",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round","aria-hidden":"true",children:a.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 Fme(t,e){const n=az(t,i=>e.some(r=>r.id===i)),s=e.find(i=>i.id===n);return s?{"--chat-project-color":b1(s)}:void 0}function Hme(){return a.jsxs("svg",{viewBox:"0 0 16 16",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round","aria-hidden":"true",children:[a.jsx("rect",{x:"2.5",y:"5.5",width:"8",height:"8",rx:"2"}),a.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 U4({label:t,items:e,open:n,onOpenChange:s,className:i="",disabled:r=!1,icon:o}){const l=y.useRef(null),u=y.useId();return a.jsxs(a.Fragment,{children:[a.jsx("button",{ref:l,className:`sidebar-menu-trigger ${i}`,type:"button","aria-label":t,title:t,"aria-haspopup":"menu","aria-expanded":n,"aria-controls":n?u:void 0,disabled:r,onClick:h=>{h.currentTarget.focus(),s(!n)},onKeyDown:h=>{(h.key==="ArrowDown"||h.key==="ArrowUp")&&(h.preventDefault(),s(!0))},children:o??a.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[a.jsx("circle",{cx:"5",cy:"12",r:"1.7"}),a.jsx("circle",{cx:"12",cy:"12",r:"1.7"}),a.jsx("circle",{cx:"19",cy:"12",r:"1.7"})]})}),n&&!r&&a.jsx(Wme,{id:u,label:t,anchor:l,items:e,onClose:()=>s(!1)})]})}function Wme({id:t,label:e,anchor:n,items:s,onClose:i}){const r=y.useRef(null),o=y.useRef(!1),l=y.useRef(i);l.current=i,y.useLayoutEffect(()=>{const h=r.current,f=n.current;f.focus({preventScroll:!0}),h.showModal(),(h.querySelector('button[aria-checked="true"]:not(:disabled)')??h.querySelector("button:not(:disabled)"))?.focus({preventScroll:!0});const m=()=>{const _=f.getBoundingClientRect(),k=window.visualViewport,N=k?.offsetLeft??0,j=k?.offsetTop??0,M=k?.width??window.innerWidth,A=k?.height??window.innerHeight,E=h.getBoundingClientRect();h.style.left=`${Math.max(N+8,Math.min(_.right-E.width,N+M-E.width-8))}px`;const L=_.bottom+4,O=L+E.height<=j+A-8?L:_.top-E.height-4;h.style.top=`${Math.max(j+8,Math.min(O,j+A-E.height-8))}px`};m();const g=new ResizeObserver(m);g.observe(h);const x=()=>l.current(),b=_=>{(!(_.target instanceof Node)||!h.contains(_.target))&&x()};return window.addEventListener("resize",x),window.addEventListener("scroll",b,!0),window.visualViewport?.addEventListener("resize",x),()=>{g.disconnect(),h.close(),window.removeEventListener("resize",x),window.removeEventListener("scroll",b,!0),window.visualViewport?.removeEventListener("resize",x)}},[n]);const u=()=>{r.current?.close(),i()};return Eo.createPortal(a.jsx("dialog",{ref:r,id:t,className:"sidebar-dropdown",role:"menu","aria-label":e,onCancel:h=>{h.preventDefault(),u()},onPointerDown:h=>{o.current=h.target===h.currentTarget},onClick:h=>{o.current&&h.target===h.currentTarget&&u(),o.current=!1},onKeyDown:h=>{if(h.key==="Tab"){u();return}if(!["ArrowDown","ArrowUp","Home","End"].includes(h.key))return;h.preventDefault();const f=[...h.currentTarget.querySelectorAll("button:not(:disabled)")],m=f.indexOf(document.activeElement),g=h.key==="Home"?0:h.key==="End"?f.length-1:(m+(h.key==="ArrowDown"?1:-1)+f.length)%f.length;f[g]?.focus()},children:s.map(h=>a.jsxs("button",{type:"button",tabIndex:-1,role:h.checked===void 0?"menuitem":"menuitemradio","aria-checked":h.checked,className:[h.danger?"is-danger":"",h.checked?"is-checked":"",h.separator?"has-separator":""].filter(Boolean).join(" ")||void 0,disabled:h.disabled,title:h.title,onClick:()=>{h.keepOpen||u(),h.onSelect()},children:[h.icon,a.jsx("span",{children:h.label})]},h.id))}),document.body)}const V4=[],qme={forRow:()=>V4,forTask:()=>V4,held:new Map,reveal:()=>{}},jz=y.createContext(qme);function Tf(){return y.useContext(jz)}function k1({actions:t,subject:e,className:n=""}){const{reveal:s}=Tf();if(t.length===0)return null;const i=t1(t),r=xie(t),o=t.length>1;return a.jsxs("button",{type:"button",className:`pending-action-badge${n?` ${n}`:""}`,"data-kind":o?"several":t[0].kind,"data-tone":vie(t),"aria-label":`${i} for ${e}: ${r}. Show ${o?"the first one":"it"}`,title:`${r}. Click to show ${o?"the first one":"it"}.`,onClick:l=>{l.stopPropagation(),s(t[0])},children:[a.jsx(Vme,{}),a.jsx("span",{className:"pending-action-text",children:i})]})}function Ume(t,e=document){const n=[...e.querySelectorAll(yie(t))].map(i=>i.classList.contains("pending-target")?i.firstElementChild:i).find(i=>!!i&&i.getClientRects().length>0);if(!n)return!1;const s=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;return n.scrollIntoView?.({block:"center",behavior:s?"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 Vme(){return a.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:[a.jsx("circle",{cx:"12",cy:"12",r:"9"}),a.jsx("path",{d:"M12 7.5v5.5"}),a.jsx("path",{d:"M12 16.5h.01"})]})}const Kme=1,Gme=180,Yme="cubic-bezier(0.33, 1, 0.68, 1)";function Xme(t,e){const n=new Map;for(const[s,i]of e){const r=t.get(s);if(r===void 0)continue;const o=r-i;Math.abs(o)>=Kme&&n.set(s,o)}return n}function K4(t,e){const n=t.getBoundingClientRect().top,s=new Map;for(const i of t.querySelectorAll(e)){const r=i.dataset.row;r&&s.set(r,i.getBoundingClientRect().top-n)}return s}function Qme(t,e,n="[data-row]"){const s=y.useRef(null);s.current&&s.current.order!==e&&t.current&&(s.current={order:s.current.order,tops:K4(t.current,n)}),y.useLayoutEffect(()=>{const i=t.current;if(!i)return;const r=s.current,o=K4(i,n);if(s.current={order:e,tops:o},!r||r.order===e||typeof window>"u"||window.matchMedia?.("(prefers-reduced-motion: reduce)").matches)return;const l=Xme(r.tops,o);if(l.size)for(const u of i.querySelectorAll(n)){const h=u.dataset.row?l.get(u.dataset.row):void 0;h===void 0||typeof u.animate!="function"||u.animate([{transform:`translateY(${h}px)`},{transform:"translateY(0)"}],{duration:Gme,easing:Yme})}},[e,t,n])}const kb=new Set,Zme=new Map,Jme=new Map,Nz="octiq.chat.collapsed-agents",Az="octiq.chat.filter";function ege(){const t=ls(Az);return yY(t)?t:"active"}function tge(){try{const t=JSON.parse(ls(Nz)??"[]");return new Set(Array.isArray(t)?t.filter(e=>typeof e=="string"):[])}catch{return new Set}}function nge({orchestration:t=qo,ledgerSnapshot:e,ledgerUnavailable:n=!1,coordinatorChatKeys:s=kb,projects:i,shelved:r,deletedCount:o=0,onShowDeleted:l,conversations:u,currentConversation:h,running:f,busy:m,waiting:g=Zme,completing:x=kb,deleting:b=kb,leaving:_=kb,deleteMs:k=2e3,onPickConversation:N,getPreviewMessages:j,loadPreview:M,onNewChat:A,newLabel:E="New task",allowEmptyCreate:L=!0,onDelete:O,onPin:X,onToggleDone:q,onRename:$,onArchiveWorker:G,branches:B={},chatParents:F=Jme,onResize:z,onCollapse:W,onSearch:H,onSettings:U,onAgents:ee,onProjects:Q,onPullRequests:I,activeView:Y=null,projectsReady:J=!0,chatsReady:P=!0}){const ne=y.useMemo(()=>UN(u,F),[u,F]),[he,le]=y.useState(tge),[oe,ye]=y.useState(ege),[D,Oe]=y.useState(()=>new Set),[ze,Ce]=y.useState(!1),[ve,Ie]=y.useState(null),[ae,$e]=y.useState(null),[He,Wt]=y.useState(!1),[yt,Bt]=y.useState(!1),[Gt,qt]=y.useState(null),Nt=y.useContext(zE),ht=Tf(),Be=y.useRef(void 0),ue=y.useRef({x:0,y:0}),Te=y.useRef(!1),Pe=y.useRef(null),dt=y.useRef(new Set(ne.map(be=>be.id))),pe=gf(J),Qe=gf(P||u.length>0),Ze=[...i,...r],_t=e===void 0?t:e,bt=new Map(Ze.map(be=>[be.id,be])),Xt=new Map(ne.map(be=>[be.id,be])),St=m2(ne,t,!0),Wn=m2(ne,t);y.useEffect(()=>{Oe(be=>{const Et=new Set(be);for(const fn of be){const vs=Xt.get(fn);(!vs||(oe==="active"?!Hc(vs):oe!=="done"||Hc(vs)))&&Et.delete(fn)}return Et.size===be.size?be:Et})},[ne,oe]);const _n=He?St:HC(Wn,oe,h,D),_e=y.useMemo(()=>Eme(ne,t,h),[ne,t,h]),Ut=y.useMemo(()=>H4(HC(_e,oe,h,D),F),[_e,F,h,oe,D]),Lt=y.useMemo(()=>H4(_e,F),[_e,F]),$t=be=>!!be.chat.pinned||be.descendants.some(Et=>Et.pinned),gn=He?[]:Lt.filter($t),Xn=He?St.map(be=>({chat:be,children:[],descendants:[]})):Ut.filter(be=>!$t(be)),qn=y.useRef(null);Qme(qn,`${gn.map(be=>be.chat.id).join(",")}|${Xn.map(be=>be.chat.id).join(",")}`,".task-chat-list > li.chat-row[data-row]");const In=new Set;let ke=h?F.get(h):void 0;for(;ke&&!In.has(ke);)In.add(ke),ke=F.get(ke);const at=JSON.stringify([...In]);y.useEffect(()=>{const be=JSON.parse(at);le(Et=>be.some(fn=>Et.has(fn))?new Set([...Et].filter(fn=>!be.includes(fn))):Et)},[h,at]),y.useEffect(()=>{nn(Nz,JSON.stringify([...he]))},[he]),y.useEffect(()=>{nn(Az,oe)},[oe]),y.useEffect(()=>{dt.current=new Set(ne.map(be=>be.id))},[ne]),y.useEffect(()=>()=>clearTimeout(Be.current),[]);const Je=()=>clearTimeout(Be.current),vn=async(be,Et)=>{if(!(!G||yt)){Bt(!0),qt(null);try{await G(be,Et)}catch(fn){qt(fn instanceof Error?fn.message:String(fn))}finally{Bt(!1)}}},Ve=be=>{Oe(new Set),ye(be)},xt=be=>{const Et=Hc(be),fn=oe==="active"&&!Et||oe==="done"&&Et;Oe(vs=>{const zi=new Set(vs);return fn?zi.add(be.id):zi.delete(be.id),zi}),q(be.id)},Pt=be=>m.has(be)&&!g.has(be),Qn=({chat:be,children:Et,descendants:fn})=>{const vs=!he.has(be.id),zi=fn.filter(tt=>Pt(tt.id)).length,qs=fn.filter(tt=>$w(tt,h)).length,Bn=`chat-agents-${be.id}`,Ne=Xt.get(F.get(be.id)??""),We=b.has(be.id),ut=_.has(be.id),Rt=$w(be,h),zt=Hc(be),Js=bt.get(be.projectId),Dt=y1(be,_t,s,n),Cn=BE(Dt,(tt,on)=>bt.get(tt)?.name??on??"Unknown project"),Ln=Fme(Dt,Ze),sr=Js?.name??"Unknown project",Qt=t.attempts.find(tt=>tt.workerChatKey===`chat:${be.id}`),it=Qt&&t.tasks.find(tt=>tt.id===Qt.taskId),ui=Qt?.archivedAt!=null,Yl=Qt&&!ui?p2(t,Qt):null,ei=i0(t,`chat:${be.id}`),Ua=Cme(ei,ht.held),qr=!He&&ei.runs.length>0,Us=new Set(ei.attempts.map(tt=>tt.workerChatKey)),xs=qr?Et.filter(tt=>!Us.has(`chat:${tt.chat.id}`)):Et,Ur=xs.length>0,Vr=qr&&Us.has(`chat:${h}`),ua=Lme(ei,ht.held),ki=it&&Qt?Ame(it,Qt):Ua?Nme(ei,Ua,ht.held):null,Fi=ki?.text??null,ir=Dt.status==="home"?Qt?.branch||(Ne?"":B[be.projectId]):"",ti=ir?`${sr} | ${ir}`:sr,ys=eh(be.modelId??null),de=Nt(`chat:${be.id}`),Ge=f2(j?.(be.id)??be.messages),mt=He?[]:ht.forRow(be.id),$n=We?"Deleting…":Ge?.text??be.latestResponse??(Pt(be.id)?"Working…":"No response yet");return a.jsxs(rge,{id:be.id,entering:Qe==="settled"&&!dt.current.has(be.id),leaving:ut,children:[a.jsxs("div",{className:["chat",be.id===h?"is-on":"",f.has(be.id)?"is-live":"",Pt(be.id)?"is-busy":"",ua>0?"is-tasks-running":"",We?"is-going":"",ut?"is-leaving":"",be.pinned?"is-pinned":"",ve===be.id?"is-renaming":"",Rt?"is-unread":"",zt?"is-done":"",Vr?"is-worker-on":"",mt.length?"has-pending":"",x.has(be.id)?"is-completing":""].filter(Boolean).join(" "),style:Ln,children:[ve===be.id?a.jsx("form",{className:"chat-rename",onSubmit:tt=>{tt.preventDefault();const on=tt.currentTarget.elements.namedItem("chat-title");on instanceof HTMLInputElement&&on.value.trim()&&$(be.id,on.value),Ie(null)},children:a.jsx("input",{name:"chat-title",className:"chat-rename-input",defaultValue:be.title,"aria-label":"Chat title",maxLength:48,autoFocus:!0,onFocus:tt=>tt.currentTarget.select(),onBlur:tt=>{tt.currentTarget.value.trim()&&$(be.id,tt.currentTarget.value),Ie(null)},onKeyDown:tt=>{tt.key==="Escape"&&(tt.preventDefault(),Ie(null))}})}):a.jsx($me,{chat:be,enabled:!We&&!ut&&!ae,busy:m.has(be.id),getPreviewMessages:j,loadPreview:M,className:"chat-btn",type:"button","aria-label":`${Rt?"Unread, ":""}${be.title}, ${Cn}${ir?`, branch ${ir}`:""}${de?`, with ${de.name}`:ys?`, ${ys.name} ${ys.model}`:""}${Pt(be.id)?", working":f.has(be.id)?", session running":""}${x.has(be.id)?", completing":""}${ua>0?`, ${ua} ${ua===1?"task":"tasks"} running`:""}${mt.length?`, ${t1(mt)}`:""}${zt?", done":""}${be.pinned?", pinned":""}`,disabled:ut,"aria-current":be.id===h?"page":void 0,"aria-description":`${Ne?`Agent chat under ${Ne.title}. `:""}Hover to preview. Hold for chat actions.`,onPointerDown:tt=>{Je(),Te.current=!1,!(tt.pointerType==="mouse"||We||ut||!window.matchMedia("(max-width: 859.98px), (pointer: coarse)").matches)&&(ue.current={x:tt.clientX,y:tt.clientY},Be.current=setTimeout(()=>{Te.current=!0,$e(be.id)},500))},onPointerMove:tt=>{Math.hypot(tt.clientX-ue.current.x,tt.clientY-ue.current.y)>10&&Je()},onPointerUp:Je,onPointerCancel:Je,onContextMenu:tt=>{window.matchMedia("(max-width: 859.98px), (pointer: coarse)").matches&&(tt.preventDefault(),Je(),!We&&!ut&&$e(be.id))},onClick:()=>{if(Te.current){Te.current=!1;return}N(be)},children:a.jsxs("span",{className:"chat-summary",children:[a.jsxs("span",{className:"chat-heading",children:[Rt&&a.jsx("span",{className:"chat-unread-dot","aria-hidden":"true"}),a.jsx("span",{className:"chat-title",children:be.title}),a.jsx("time",{className:"chat-time",dateTime:new Date(be.updatedAt).toISOString(),title:new Date(be.updatedAt).toLocaleString(),children:FE(be.updatedAt)})]}),a.jsx("span",{className:"chat-snippet",children:IE($n)}),a.jsx(So,{inline:!0,when:!!Fi,children:a.jsx("span",{className:"chat-workflow-status","data-tone":ki?.tone??void 0,title:Fi??void 0,children:Fi})}),a.jsxs("span",{className:"chat-meta",children:[Dt.status==="home"?a.jsx("span",{className:"chat-project",children:a.jsx("span",{className:"chat-project-name",title:ti,children:ti})}):a.jsx(Sz,{info:Dt,projects:Ze,taskCount:!Ua}),de?a.jsxs("span",{className:"chat-model chat-persona",title:`${de.name}${ys?` · ${ys.name} ${ys.model}`:""}`,children:[a.jsx(Qs,{name:de.name,avatar:de.avatar,id:de.id??de.name,size:14,removed:de.removed,decorative:!0}),a.jsx("span",{children:de.name})]}):ys&&a.jsxs("span",{className:"chat-model",title:`Active model: ${ys.name} · ${ys.model}`,children:[a.jsx(Hm,{agent:ys.agent,size:10}),a.jsx("span",{children:ys.model})]})]})]})}),a.jsx(So,{when:ve!==be.id&&mt.length>0,className:"chat-pending-slot",children:a.jsx(k1,{className:"chat-pending",actions:mt,subject:be.title})}),a.jsxs("button",{className:"chat-badge",type:"button","aria-pressed":zt,title:zt?"Double-click or double-tap to mark not done":"Double-click or double-tap to mark done","aria-label":`${zt?"Mark not done":"Mark done"}: ${be.title}`,"aria-description":"Double-click or double-tap. With a keyboard, press Enter or Space.",disabled:We||ut,onBlur:()=>{Pe.current=null},onClick:tt=>{tt.stopPropagation();const on=Pe.current;Pe.current=null,tt.detail===0||on?.chatId===be.id&&tt.timeStamp-on.at<=500?xt(be):Pe.current={chatId:be.id,at:tt.timeStamp}},children:[a.jsx(Cz,{info:Dt,projects:Ze}),a.jsxs("svg",{className:"chat-badge-ring",viewBox:"0 0 32 32","aria-hidden":"true",children:[a.jsx("rect",{className:"chat-badge-track",x:"1",y:"1",width:"30",height:"30",rx:"8"}),a.jsx("rect",{className:"chat-badge-snake",x:"1",y:"1",width:"30",height:"30",rx:"8"}),a.jsx("rect",{className:"chat-badge-pellet",x:"1",y:"1",width:"30",height:"30",rx:"8"})]}),a.jsx("span",{className:"chat-badge-tick","aria-hidden":"true",children:a.jsx(sge,{done:zt})}),zt&&a.jsx("span",{className:"chat-badge-check","aria-hidden":"true",children:a.jsx(ige,{})}),be.pinned&&a.jsx("span",{className:"chat-badge-pin","aria-hidden":"true",children:a.jsx(X4,{})})]}),ve!==be.id&&a.jsx(U4,{className:"chat-actions-trigger",label:`Actions for ${be.title}`,open:ae===be.id,onOpenChange:tt=>$e(tt?be.id:null),disabled:ut,icon:We?a.jsx(kz,{ms:k}):void 0,items:[{id:"rename",label:"Rename chat",icon:a.jsx(pge,{}),disabled:We,onSelect:()=>Ie(be.id)},{id:"pin",label:be.pinned?"Unpin chat":"Pin chat",icon:a.jsx(X4,{}),disabled:We,onSelect:()=>X(be.id)},...Qt&&G?[{id:"archive",label:ui?"Restore worker":"Archive worker",icon:a.jsx(G4,{}),disabled:yt||!!Yl||!ui&&m.has(be.id),title:Yl??(ui?"Return this worker to the chat list.":"Hide this worker; its chat and task history are kept."),onSelect:()=>{vn(Qt.id,!ui)}}]:[],...Xd(be.id,F)?[]:[{id:"delete",label:We?"Cancel delete":"Delete chat",icon:a.jsx(Y4,{}),danger:!0,keepOpen:!We,onSelect:()=>O(be.id)}]]}),Ur&&a.jsxs("button",{className:"chat-children-toggle",type:"button","aria-label":`${vs?"Collapse":"Expand"} agent chats for ${be.title}`,"aria-expanded":vs,"aria-controls":Bn,disabled:ut,onClick:()=>le(tt=>{const on=new Set(tt);return on.has(be.id)?on.delete(be.id):on.add(be.id),on}),children:[a.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:a.jsx("path",{d:"m9 5 7 7-7 7"})}),a.jsx("span",{children:`${xs.length} ${xs.length===1?"agent":"agents"}`}),zi>0&&a.jsxs("span",{className:"chat-children-working",children:[zi," working"]}),qs>0&&a.jsxs("span",{className:"chat-children-unread",children:[qs," unread"]})]})]}),Ur&&a.jsx("div",{id:Bn,hidden:!vs,children:vs&&xs.length>0&&a.jsx("ul",{className:"chat-children","aria-label":`Agent chats for ${be.title}`,children:xs.map(Qn)})})]},be.id)},dn=()=>{Wt(!1),Oe(new Set)},gs=[...wY(Wn,oe).map(be=>({id:be.filter,label:be.label,checked:!He&&be.checked,onSelect:()=>{dn(),Ve(be.filter)}})),...St.length||He?[{id:"archived",label:`Archived workers (${St.length})`,icon:a.jsx(G4,{}),checked:He,separator:!0,onSelect:()=>{Wt(!0),Oe(new Set)}}]:[],...o&&l?[{id:"trash",label:`Deleted chats (${o})`,icon:a.jsx(Y4,{}),separator:!(St.length||He),onSelect:l}]:[]],nr=He?"Archived":WC[oe];return a.jsxs("nav",{className:`sidebar task-sidebar${pe==="settled"?"":` ${mh(pe)}`}`,"aria-label":"Chats",children:[a.jsxs("div",{className:"task-chat-scroll",children:[a.jsxs("div",{id:"chats-navigation",className:"sidebar-toolbar",children:[a.jsxs("div",{className:"sidebar-head",children:[a.jsx("img",{className:"sidebar-logo",src:"./icon-192.png",alt:"","aria-hidden":"true"}),a.jsxs("span",{className:"sidebar-title",children:["OctiqFlow ",a.jsxs("span",{className:"sidebar-version",children:["v","0.3.12"]})]}),W&&a.jsx("button",{className:"sidebar-collapse",type:"button",onClick:W,"aria-label":"Hide sidebar",title:"Hide sidebar",children:a.jsx(oge,{})})]}),a.jsxs("ul",{className:"sidebar-places","aria-label":"App",children:[a.jsx("li",{children:a.jsxs("button",{className:"sidebar-place sidebar-new-chat",type:"button",onClick:A,children:[a.jsx(lge,{}),a.jsx("span",{children:E})]})}),H&&a.jsx("li",{children:a.jsxs("button",{className:"sidebar-place",type:"button",onClick:H,"aria-current":Y==="search"?"page":void 0,children:[a.jsx(age,{}),a.jsx("span",{children:"Search chats"})]})}),Q&&a.jsx("li",{children:a.jsxs("button",{className:"sidebar-place",type:"button",onClick:Q,"aria-current":Y==="projects"?"page":void 0,children:[a.jsx(fge,{}),a.jsx("span",{children:"Projects"})]})}),ee&&a.jsx("li",{children:a.jsxs("button",{className:"sidebar-place",type:"button",onClick:ee,"aria-current":Y==="agents"?"page":void 0,children:[a.jsx(hge,{}),a.jsx("span",{children:"Agents"})]})}),I&&a.jsx("li",{children:a.jsxs("button",{className:"sidebar-place",type:"button",onClick:I,"aria-current":Y==="pulls"?"page":void 0,children:[a.jsx(dge,{}),a.jsx("span",{children:"Pull requests"})]})}),U&&a.jsx("li",{children:a.jsxs("button",{className:"sidebar-place",type:"button",onClick:U,"aria-current":Y==="settings"?"page":void 0,children:[a.jsx(uge,{}),a.jsx("span",{children:"Settings"})]})})]})]}),Gt&&a.jsxs("div",{className:"sidebar-archive-error",role:"alert",children:[Gt,a.jsx("button",{type:"button",onClick:()=>qt(null),children:"Dismiss"})]}),Qe==="held"?null:ne.length>0||He?a.jsxs("div",{ref:qn,className:`task-chat-content${Qe==="entering"?" enter-fade":""}`,children:[gn.length>0&&a.jsxs("section",{className:"sidebar-chat-section","aria-labelledby":"sidebar-pinned-heading",children:[a.jsx("h2",{id:"sidebar-pinned-heading",className:"sidebar-section-heading",children:"Pinned"}),a.jsx("ul",{className:"chat-list task-chat-list",children:gn.map(Qn)})]}),a.jsxs("section",{className:"sidebar-chat-section","aria-labelledby":"sidebar-recent-heading",children:[a.jsxs("div",{className:"sidebar-section-head",children:[a.jsx("h2",{id:"sidebar-recent-heading",className:"sidebar-section-heading",children:He?"Archived workers":"Recent"}),a.jsx(U4,{className:"sidebar-filter-trigger",label:`Show chats: ${nr}`,open:ze,onOpenChange:Ce,icon:a.jsxs(a.Fragment,{children:[a.jsx("span",{children:nr}),a.jsx(cge,{})]}),items:gs})]}),Xn.length>0?a.jsx("ul",{className:"chat-list task-chat-list",children:Xn.map(Qn)}):Zs()]})]}):a.jsxs("div",{className:"sidebar-empty",children:[a.jsx("span",{children:"No chats yet"}),L&&a.jsx("button",{type:"button",onClick:A,children:"Start your first chat"})]})]}),z&&a.jsx("span",{className:"nav-resizer",onPointerDown:z,role:"separator","aria-orientation":"vertical","aria-label":"Resize the chat column"})]});function Zs(){return He?a.jsxs("div",{className:"sidebar-empty",role:"status",children:[a.jsx("span",{children:"No archived workers."}),a.jsx("button",{type:"button",onClick:dn,children:"Show active chats"})]}):oe!=="active"?a.jsxs("div",{className:"sidebar-empty",role:"status",children:[a.jsx("span",{children:oe==="done"?"No chats are ticked off.":"Every chat is pinned."}),a.jsx("button",{type:"button",onClick:()=>Ve("active"),children:"Show active chats"})]}):Wn.some(Et=>Hc(Et)&&!Et.pinned)&&!_n.some(Et=>!Et.pinned)?a.jsxs("div",{className:"sidebar-empty",role:"status",children:[a.jsx("span",{children:"Every chat is ticked off."}),a.jsx("button",{type:"button",onClick:()=>Ve("done"),children:"Show done chats"})]}):a.jsx("div",{className:"sidebar-empty",role:"status",children:a.jsx("span",{children:gn.length>0?"Every active chat is pinned.":"No active chats."})})}}function sge({done:t}){return a.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:[a.jsx("circle",{cx:"12",cy:"12",r:"9"}),t&&a.jsx("path",{d:"m8 12 2.8 2.8L16 9.6"})]})}function ige(){return a.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:a.jsx("path",{d:"m5 12.5 4.5 4.5L19 7"})})}function FE(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 rge({id:t,entering:e,leaving:n,children:s}){const[i,r]=y.useState(()=>e&&!(typeof window<"u"&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches));return y.useEffect(()=>{if(!i)return;const o=requestAnimationFrame(()=>r(!1));return()=>cancelAnimationFrame(o)},[i]),a.jsx("li",{"data-row":t,className:["chat-row",i?"is-entering":"",n?"is-leaving":""].filter(Boolean).join(" "),children:a.jsx("div",{className:"chat-row-content",children:s})})}function age(){return a.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[a.jsx("circle",{cx:"11",cy:"11",r:"7"}),a.jsx("path",{d:"m20 20-4-4"})]})}function oge(){return a.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:[a.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),a.jsx("path",{d:"M9 4v16M15 10l-2 2 2 2"})]})}function lge(){return a.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:[a.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"}),a.jsx("path",{d:"m12 12 7.5-7.5a2.12 2.12 0 0 1 3 3L15 15l-4 1 1-4Z"})]})}function G4(){return a.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:[a.jsx("path",{d:"M4 7h16"}),a.jsx("path",{d:"M6 7v12h12V7"}),a.jsx("path",{d:"M3 4h18v3H3z"}),a.jsx("path",{d:"M10 11h4"})]})}function Y4(){return a.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:[a.jsx("path",{d:"M3 6h18"}),a.jsx("path",{d:"M8 6V4h8v2"}),a.jsx("path",{d:"m6 6 1 14h10l1-14"}),a.jsx("path",{d:"M10 10v6M14 10v6"})]})}function X4(){return a.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:[a.jsx("path",{d:"M12 17v5"}),a.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 cge(){return a.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:a.jsx("path",{d:"m6 9 6 6 6-6"})})}function uge(){return a.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:[a.jsx("circle",{cx:"12",cy:"12",r:"3"}),a.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 hge(){return a.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:[a.jsx("rect",{x:"9",y:"3",width:"6",height:"5",rx:"1"}),a.jsx("rect",{x:"3",y:"16",width:"6",height:"5",rx:"1"}),a.jsx("rect",{x:"15",y:"16",width:"6",height:"5",rx:"1"}),a.jsx("path",{d:"M12 8v4M6 16v-2h12v2"})]})}function dge(){return a.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:[a.jsx("circle",{cx:"6",cy:"5",r:"2"}),a.jsx("circle",{cx:"18",cy:"7",r:"2"}),a.jsx("circle",{cx:"6",cy:"19",r:"2"}),a.jsx("path",{d:"M6 7v10M8 5h4a6 6 0 0 1 6 6v-2"})]})}function fge(){return a.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:a.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 pge(){return a.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:[a.jsx("path",{d:"M12 20h9"}),a.jsx("path",{d:"M16.5 3.5a2.1 2.1 0 0 1 3 3L8 18l-4 1 1-4Z"})]})}const Ez=y.createContext(null);function a0(t){return y.useContext(Ez)?.[t]??null}function Sf({title:t,back:e,actions:n,root:s=!1,className:i}){const r=a0("heading"),o=a0("actions"),l=a.jsxs(a.Fragment,{children:[e&&a.jsxs("button",{type:"button",className:`workspace-back${s?" is-root":""}`,onClick:e.onClick,"aria-label":e.ariaLabel??`Back to ${e.label}`,title:e.ariaLabel??`Back to ${e.label}`,children:[a.jsx(mge,{}),a.jsx("span",{children:e.label})]}),a.jsx("div",{className:"workspace-heading",children:t})]}),u=n?a.jsx("div",{className:"workspace-actions",children:n}):null;return r?a.jsxs(a.Fragment,{children:[Eo.createPortal(l,r),n&&(o?Eo.createPortal(u,o):a.jsx("div",{className:"workspace-actions is-inline",children:n}))]}):a.jsxs("header",{className:`workspace-header${i?` ${i}`:""}`,children:[l,u]})}function mge(){return a.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:a.jsx("path",{d:"m15 18-6-6 6-6"})})}function gge({projects:t,shelved:e,conversations:n,selectedProjectId:s,busy:i,chatParents:r,ledgerSnapshot:o=qo,coordinatorChatKeys:l=new Set,allowNewTask:u=!0,onSelectProject:h,onOpenChat:f,onNewTask:m,onNewProject:g,onProjectSettings:x,onClose:b,onShowShelved:_,onRestoreProject:k}){const N=Tf(),j=y.useRef(null),M=y.useRef(!0),[A,E]=y.useState(!1),[L,O]=y.useState(null);y.useEffect(()=>{if(M.current){M.current=!1;return}j.current?.focus({preventScroll:!0}),O(null)},[s]);const X=UN(n,r),q=[...t,...e],$=s===null?null:q.find(F=>F.id===s)??null;if(s!==null){const F=$?Kpe(X,$.id,o,l??new Set):[],z=!!$&&e.some(W=>W.id===$.id);return a.jsxs("section",{className:"projects-page","aria-label":$?`${$.name} tasks`:"Project",children:[a.jsx(Sf,{back:{label:"Projects",ariaLabel:"Back to projects",onClick:()=>h(null)},title:a.jsxs(a.Fragment,{children:[$&&a.jsx(Mh,{project:$,size:"small"}),a.jsx("h1",{ref:j,tabIndex:-1,children:$?.name??"Project unavailable"})]}),actions:$&&a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",className:"projects-page-secondary",onClick:()=>x($.id),children:"Project settings"}),z&&k&&a.jsx("button",{type:"button",className:"projects-page-primary",disabled:A,onClick:async()=>{E(!0),O(null);try{await k($.id)}catch(W){O(W instanceof Error?W.message:String(W))}finally{E(!1)}},children:a.jsx("span",{children:A?"Restoring…":"Restore project"})}),u&&!z&&a.jsxs("button",{type:"button",className:"projects-page-primary",onClick:()=>m($.id),children:[a.jsx(Q4,{}),a.jsx("span",{children:"New task"})]})]})}),L&&a.jsx("p",{className:"projects-page-error",role:"alert",children:L}),a.jsxs("div",{className:"projects-page-body",children:[$&&($.primary_path||z)&&a.jsxs("p",{className:"projects-page-meta",title:$.primary_path,children:[$.primary_path??"Shelved",$.primary_path&&z?" · Shelved":""]}),$?F.length===0?a.jsxs("div",{className:"projects-page-empty",role:"status",children:[a.jsxs("p",{children:["No tasks in ",$.name," yet."]}),u&&!z&&a.jsx("button",{type:"button",onClick:()=>m($.id),children:"Start a task"})]}):a.jsxs(a.Fragment,{children:[a.jsx("h2",{className:"projects-page-count",children:F.length===1?"1 task":`${F.length} tasks`}),a.jsx("ul",{className:"projects-task-list","aria-label":`Tasks in ${$.name}`,children:F.map(W=>{const H=i.has(W.id),U=Hc(W),ee=N.forRow(W.id),Q=[H&&"Working",U&&"Done",W.pinned&&"Pinned"].filter(I=>!!I);return a.jsxs("li",{children:[a.jsxs("button",{type:"button",className:"projects-task",onClick:()=>f(W),"aria-label":[W.title,...ee.length?[t1(ee)]:[],...Q].join(", "),children:[a.jsxs("span",{className:"projects-task-line",children:[a.jsx("span",{className:"projects-task-title",children:W.title}),a.jsx("time",{dateTime:new Date(W.updatedAt).toISOString(),children:FE(W.updatedAt)})]}),a.jsxs("span",{className:"projects-task-line",children:[a.jsx("span",{className:"projects-task-snippet",children:IE(W.latestResponse??(H?"Working…":"No response yet"))}),Q.length>0&&a.jsx("span",{className:"projects-task-states","aria-hidden":"true",children:Q.map(I=>a.jsx("span",{className:`is-${I.toLowerCase()}`,children:I},I))})]})]}),a.jsx(k1,{className:"projects-task-pending",actions:ee,subject:W.title})]},W.id)})})]}):a.jsxs("div",{className:"projects-page-empty",role:"status",children:[a.jsx("p",{children:"This project was removed or is no longer in this profile."}),a.jsx("button",{type:"button",onClick:()=>h(null),children:"Show all projects"})]})]})]})}const G=Gpe(X,o,l??new Set),B=F=>{const z=G.get(F.id)??0;return a.jsx("li",{children:a.jsxs("button",{type:"button",className:"projects-row",onClick:()=>h(F.id),"aria-label":`${F.name}, ${z===1?"1 task":`${z} tasks`}`,children:[a.jsx(Mh,{project:F,size:"medium"}),a.jsxs("span",{className:"projects-row-text",children:[a.jsx("span",{className:"projects-row-name",children:F.name}),F.primary_path&&a.jsx("span",{className:"projects-row-path",children:F.primary_path})]}),a.jsx("span",{className:"projects-row-count","aria-hidden":"true",children:z}),a.jsx(vge,{})]})},F.id)};return a.jsxs("section",{className:"projects-page","aria-label":"Projects",children:[a.jsx(Sf,{root:!0,back:{label:"Chat",ariaLabel:"Back to chat",onClick:b},title:a.jsx("h1",{ref:j,tabIndex:-1,children:"Projects"}),actions:a.jsxs("button",{type:"button",className:"projects-page-primary",onClick:g,children:[a.jsx(Q4,{}),a.jsx("span",{children:"New project"})]})}),a.jsx("div",{className:"projects-page-body",children:q.length===0?a.jsxs("div",{className:"projects-page-empty",role:"status",children:[a.jsx("p",{children:"No projects yet."}),a.jsx("button",{type:"button",onClick:g,children:"Add a project"})]}):a.jsxs(a.Fragment,{children:[t.length>0&&a.jsx("h2",{className:"projects-page-count",children:t.length===1?"1 project":`${t.length} projects`}),t.length>0&&a.jsx("ul",{className:"projects-list","aria-label":"Projects",children:t.map(B)}),e.length>0&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"projects-page-subhead",children:[a.jsx("h2",{className:"projects-page-count",children:"Shelved"}),_&&a.jsx("button",{type:"button",className:"projects-page-link",onClick:_,children:"Restore shelved projects"})]}),a.jsx("ul",{className:"projects-list","aria-label":"Shelved projects",children:e.map(B)})]})]})})]})}function vge(){return a.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:a.jsx("path",{d:"m9 18 6-6-6-6"})})}function Q4(){return a.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:a.jsx("path",{d:"M12 5v14M5 12h14"})})}const Mz=t=>t.replace(/\s+/g," ").trim(),Z4=60,J4=t=>[...t].length;function xge(t){const e=/^\d{4}-\d{2}-\d{2}T\S+\s+(?:ERROR|WARN|WARNING)\s+(.+)$/is.exec(t.trim());return e?Mz(e[1]):null}function yge(t){const e=Mz(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=xge(t);if(n){const l=n.replace(/^[\w.-]+(?:::[\w.-]+)*:\s*/,"");return{key:`provider:${l.toLocaleLowerCase()}`,title:"The agent reported a background issue",detail:l,technical:t.trim()}}const s=/^(\d+) background task\(s\) interrupted when the provider process ended: (.+?)\. Retained output/i.exec(e);if(s){const l=Number(s[1]);return{key:`background-interrupted:${s[2].toLocaleLowerCase()}`,title:`${l} background ${l===1?"task":"tasks"} interrupted`,detail:e}}const i=pK(e);if(i)return{key:`jobs-interrupted:${i.labels.toLocaleLowerCase()}`,title:`${i.count} ${i.count===1?"job":"jobs"} interrupted`,detail:e};const r=`message:${e.toLocaleLowerCase()}`;if(J4(e)<=Z4)return{key:r,title:e};const o=/^([^:]+): /.exec(e)?.[1]??"";return{key:r,title:o&&J4(o)<=Z4?o:"Notice",detail:e}}function bge(t,e){return e<=0||t.length===0?"":e===1?t[0].title:`${e} notices`}function wge(t){const e=new Map;for(const n of t){const s=yge(n),i=e.get(s.key);i?e.set(s.key,{...i,detail:s.detail??i.detail,technical:s.technical??i.technical,count:i.count+1}):e.set(s.key,{...s,count:1})}return[...e.values()]}function _ge(){return a.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.5","aria-hidden":"true",children:[a.jsx("circle",{cx:"10",cy:"10",r:"7.25"}),a.jsx("path",{d:"M10 8.6v4.2",strokeLinecap:"round"}),a.jsx("circle",{cx:"10",cy:"5.9",r:".65",fill:"currentColor",stroke:"none"})]})}function kge({notices:t,onClear:e}){const[n,s]=y.useState(!1),i=y.useId(),r=y.useMemo(()=>wge(t),[t]);return r.length===0?null:a.jsxs("section",{className:`chat-notices ${n?"is-open":""}`,"aria-label":"Background notices",children:[a.jsxs("div",{className:"status-row",children:[a.jsxs("button",{className:"status-row-main chat-notices-toggle",type:"button","aria-expanded":n,"aria-controls":i,onClick:()=>s(o=>!o),children:[a.jsx("span",{className:"status-row-icon",children:a.jsx(_ge,{})}),a.jsx("span",{className:"status-row-text chat-notices-title",children:bge(r,t.length)}),a.jsx(RE,{})]}),a.jsx(DE,{label:"Clear all background notices",onClick:e})]}),n&&a.jsx("div",{className:"status-row-panel chat-notices-panel",id:i,children:r.map(o=>a.jsxs("article",{className:"chat-notice-item",children:[(r.length>1||o.count>1||!o.detail)&&a.jsxs("div",{className:"chat-notice-head",children:[a.jsx("span",{children:o.title}),o.count>1&&a.jsxs("span",{className:"chat-notice-count",children:[o.count," times"]})]}),o.detail&&a.jsx("p",{children:o.detail}),o.technical&&a.jsxs("details",{className:"chat-notice-technical",children:[a.jsx("summary",{children:"Technical details"}),a.jsx("pre",{children:o.technical})]})]},o.key))})]})}function Sge({chatId:t,connected:e,projectPath:n}){const[s,i]=y.useState(),r=y.useCallback(o=>{!t||!e||te.invoke("chat_task",{chatId:t,refresh:o}).then(i).catch(()=>{})},[t,e]);return y.useEffect(()=>r(!1),[r]),y.useEffect(()=>{if(!t||!e)return;const o=te.on("chat-task",u=>{u?.chatId===t&&i(u)}),l=te.on("chat-event",u=>{u?.key===`chat:${t}`&&u.event?.type==="octiq_chat_recovered"&&r(!0)});return()=>{o(),l()}},[t,e,r]),a.jsx(Cge,{workspace:s?.chatId===t?s.workspace:void 0,projectPath:n})}function Cge({workspace:t,projectPath:e,open:n=!1}){const[s,i]=y.useState(n),r=y.useId(),o=ife(t,e);return o?a.jsxs("div",{className:"chat-folder-gone",role:"status",children:[a.jsx("div",{className:"status-row",children:a.jsxs("button",{type:"button",className:"status-row-main","aria-expanded":s,"aria-controls":r,onClick:()=>i(l=>!l),children:[a.jsx("span",{className:"status-row-icon","data-tone":"warn","aria-hidden":"true",children:a.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[a.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"}),a.jsx("path",{d:"M9.5 11.5l5 5M14.5 11.5l-5 5"})]})}),a.jsx("span",{className:"status-row-label",children:o.label}),a.jsx("span",{className:"status-row-text",children:o.next}),a.jsx(RE,{})]})}),s&&a.jsxs("div",{className:"status-row-panel",id:r,children:[a.jsx("p",{className:"chat-folder-gone-path",children:o.path}),o.detail.map(l=>a.jsx("p",{children:l},l))]})]}):null}let eg=r6,eD=!1;const v2=new Set;let x2=new Set;function Lz(t){if(t!==eg){eg=t;for(const e of v2)e()}}function jge(t){return String(t?.message??t).includes("not available on this backend")}function Tz(t){const e=eg.rev;te.invoke("chat_jobs",t?{chatKey:t}:{}).then(n=>Lz(iK(eg,{jobs:n?.jobs,asked:e,chatKey:t},Date.now())),n=>{jge(n)||console.warn("chat_jobs failed",n)})}function y2(){eD||(eD=!0,te.on("chat-job",t=>Lz(sK(eg,t,Date.now()))),te.onState(t=>{t==="open"&&(x2=new Set,Tz())}))}function Nge(t){y2(),!x2.has(t)&&(x2.add(t),Tz(t))}const lw={snapshot(){return y2(),eg},subscribe(t){return y2(),v2.add(t),()=>v2.delete(t)}};function OS(t){const[e,n]=y.useState(()=>typeof window>"u"?!1:window.matchMedia(t).matches);return y.useEffect(()=>{const s=window.matchMedia(t);n(s.matches);const i=r=>n(r.matches);return s.addEventListener("change",i),()=>s.removeEventListener("change",i)},[t]),e}const Age="(min-width: 701px)",tD="(max-width: 859.98px)",Ege="(min-width: 1181px)",Rz=18,Mge=10,Lge=24,nD=1.5,Tge=350,Rge=.4,sD=.5,Dge=72;function Oge(t,e){return!e.open&&t.x>Rz?null:{phase:"watching",opening:!e.open,from:t,at:t,width:e.width}}function Ige(t,e){if(t.phase==="dropped")return t;const n={...t,at:e};if(t.phase==="swiping")return n;const s=e.x-t.from.x,i=e.y-t.from.y;if(e.t-t.from.t>Tge)return{...n,phase:"dropped"};const r=Math.abs(s),o=Math.abs(i);return o>Mge&&r<o*nD?{...n,phase:"dropped"}:r<Lge?n:(t.opening?s<0:s>0)?{...n,phase:"dropped"}:r<o*nD?{...n,phase:"dropped"}:{...n,phase:"swiping"}}function Dz(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 Bge(t){if(t.phase!=="swiping")return null;const e=t.at.x-t.from.x,n=t.at.t-t.from.t,s=n>0?e/n:0;if(Math.abs(e)>=Dge){if(s>sD)return"open";if(s<-sD)return"close"}return Dz(t)>Rge?"open":"close"}function $ge({enabled:t,open:e,onChange:n}){const s=y.useRef(e);s.current=e;const i=y.useRef(n);return i.current=n,y.useCallback(r=>{if(!(!r||!t))return Pge(r,()=>s.current,o=>i.current(o))},[t])}function Pge(t,e,n){let s=null,i=0;const r=()=>{s?.phase==="swiping"&&(i=Date.now()+700),s=null,t.removeAttribute("data-drawer-swiping"),t.style.removeProperty("--swipe-p")},o=m=>{if(r(),m.touches.length!==1)return;i=0;const g=m.touches[0],x=e();if(x){const _=window.getSelection();if(_&&_.rangeCount>0&&!_.isCollapsed)return}const b=t.querySelector(".sidebar")?.offsetWidth||t.clientWidth;s=Oge({x:g.clientX,y:g.clientY,t:m.timeStamp},{open:x,width:b}),s&&g.clientX<=Rz&&m.cancelable&&m.preventDefault()},l=m=>{if(!s)return;if(m.touches.length!==1||!m.cancelable)return r();const g=m.touches[0];if(s=Ige(s,{x:g.clientX,y:g.clientY,t:m.timeStamp}),s.phase==="dropped")return r();s.phase==="swiping"&&(m.preventDefault(),t.setAttribute("data-drawer-swiping",""),t.style.setProperty("--swipe-p",String(Dz(s))))},u=m=>{const g=s&&Bge(s);g&&m.cancelable&&m.preventDefault(),r(),g&&g==="open"!==e()&&n(g==="open")},h=m=>{s?.phase!=="swiping"&&Date.now()>=i||(m.preventDefault(),m.stopImmediatePropagation())},f=m=>{s?.phase!=="swiping"&&(m.key==="Enter"||m.key===" ")&&(i=0)};return t.addEventListener("touchstart",o,{passive:!1}),t.addEventListener("touchmove",l,{passive:!1}),t.addEventListener("touchend",u,{passive:!1}),t.addEventListener("touchcancel",r,{passive:!0}),t.addEventListener("click",h,!0),t.addEventListener("dblclick",h,!0),t.addEventListener("keydown",f,!0),()=>{t.removeEventListener("touchstart",o),t.removeEventListener("touchmove",l),t.removeEventListener("touchend",u),t.removeEventListener("touchcancel",r),t.removeEventListener("click",h,!0),t.removeEventListener("dblclick",h,!0),t.removeEventListener("keydown",f,!0),r()}}let oh,cw=0;function b2(t,e){const n=++cw;oh?.skipTransition(),oh=void 0;const s=document.documentElement;delete s.dataset.zenTransition;let i=!1;const r=()=>{n!==cw||i||(i=!0,Eo.flushSync(e))},o=()=>{n===cw&&(oh=void 0,delete s.dataset.zenTransition)},l=window.matchMedia("(prefers-reduced-motion: reduce)").matches;if(l||!document.startViewTransition){r(),l||document.querySelector(".app .main")?.animate?.([{opacity:.75},{opacity:1}],{duration:320,easing:"ease-out"});return}s.dataset.zenTransition=t;try{oh=document.startViewTransition(r),oh.ready.catch(()=>{}),oh.finished.then(o,()=>{r(),o()})}catch{r(),o()}}function iD(){cw++,oh?.skipTransition(),oh=void 0,delete document.documentElement.dataset.zenTransition}const zge={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 Fge(t){return t==="pi"?"codex":t==="antigravity"?"luna":t.startsWith("pi-")?t.slice(3):t}const Hge={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"}},Wge={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 HE({robot:t="sonnet",size:e=28,alert:n=!1,mood:s="idle",asleep:i=!1}){const r=Fge(t),o=Hge[r],l=`mascot-iris-${y.useId()}`,u=i?"asleep":s,h=u==="think",f=u==="work",m=f?8:r==="haiku"||r==="luna"||r==="fable"?12:11;return a.jsxs("span",{className:`mascot${n?" is-alert":""}${i?" is-asleep":""}`,"data-robot":t,"data-mood":s,"data-expression":u,style:{width:e,height:e,"--mascot-size":`${e}px`,"--robot-accent":zge[r].color},"aria-hidden":"true",children:[a.jsxs("svg",{className:"mascot-avatar",viewBox:"0 0 100 100",width:e,height:e,fill:"none",focusable:"false",children:[a.jsx("defs",{children:a.jsxs("linearGradient",{id:l,x1:"0",y1:"0",x2:"0",y2:"1",children:[a.jsx("stop",{className:"mascot-iris-dark",offset:"0"}),a.jsx("stop",{className:"mascot-iris-color",offset:".65"}),a.jsx("stop",{className:"mascot-iris-light",offset:"1"})]})}),a.jsxs("g",{className:"mascot-avatar-character",children:[a.jsx("path",{className:"mascot-fur mascot-ears",d:o.ears}),a.jsx("path",{className:"mascot-ear-inner",d:o.inner}),a.jsx("path",{className:"mascot-collar",d:"M 33 81 Q 50 77 67 81 L 74 94 Q 51 101 26 94 Z"}),a.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"}),a.jsx("path",{className:"mascot-collar-gem",d:"M 50 87 L 54 92 L 50 97 L 46 92 Z"}),a.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"}),a.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"}),a.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"}),a.jsx("path",{className:"mascot-fur mascot-fringe",d:o.fringe}),a.jsx("path",{className:"mascot-hair-shine",d:o.shine}),a.jsx("g",{className:`mascot-avatar-mark${r==="claude"||r==="codex"?" mascot-mark-lines":""}`,children:a.jsx("path",{d:o.mark})}),a.jsxs("g",{className:"mascot-avatar-face",strokeLinecap:"round",strokeLinejoin:"round",children:[a.jsxs("g",{className:"mascot-avatar-cheeks",children:[a.jsx("ellipse",{cx:"23",cy:"71",rx:"7",ry:"3.5"}),a.jsx("ellipse",{cx:"77",cy:"71",rx:"7",ry:"3.5"}),a.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"})]}),a.jsx("g",{className:"mascot-avatar-eyes",children:i?a.jsxs("g",{className:"mascot-sleep-eyes",children:[a.jsx("path",{d:"M 25 59 Q 33 67 41 59 M 59 59 Q 67 67 75 59"}),a.jsx("path",{className:"mascot-lower-lash",d:"M 26 61 L 24 63 M 74 61 L 76 63"})]}):[33,67].map((g,x)=>{const b=h?57+x*2:59,_=g+(h?2:0);return a.jsxs("g",{children:[a.jsx("ellipse",{className:"mascot-eye-white",cx:g,cy:b,rx:"10",ry:m+1}),a.jsx("ellipse",{className:"mascot-avatar-eye",cx:_,cy:b+1,rx:"7.7",ry:m,fill:`url(#${l})`}),a.jsx("ellipse",{className:"mascot-pupil",cx:_,cy:b,rx:"3.4",ry:m*.66}),a.jsx("path",{className:"mascot-iris-glow",d:`M ${_-4.5} ${b+m-3} Q ${_} ${b+m} ${_+4.5} ${b+m-3}`}),a.jsx("ellipse",{className:"mascot-eye-glint",cx:_-2.7,cy:b-m*.43,rx:"3",ry:"3.4"}),a.jsx("circle",{className:"mascot-eye-glint mascot-eye-glint-small",cx:_+3.5,cy:b+4,r:"1.4"}),a.jsx("path",{className:"mascot-upper-lash",d:`M ${g-10} ${b-3} Q ${g-8} ${b-m-3} ${g+1} ${b-m-1} Q ${g+7} ${b-m} ${g+10} ${b-4}`}),a.jsx("path",{className:"mascot-lower-lash",d:`M ${g-6} ${b+m} Q ${g} ${b+m+2} ${g+5} ${b+m}`})]},g)})}),(h||f)&&a.jsxs("g",{className:"mascot-eyebrows",children:[a.jsx("path",{d:h?"M 26 43 Q 32 39 39 42":"M 26 45 L 39 48"}),a.jsx("path",{d:h?"M 61 45 Q 67 42 74 44":"M 61 48 L 74 45"})]}),a.jsx("path",{className:"mascot-nose",d:"M 48.5 71 Q 50 70 51.5 71 L 50 72 Z"}),a.jsx("path",{className:"mascot-avatar-mouth",d:Wge[u]}),u==="idle"&&a.jsx("path",{className:"mascot-tongue",d:"M 47 81 Q 50 78 53 81 Q 50 84 47 81 Z"})]})]})]}),t.startsWith("pi")&&a.jsx("span",{className:"mascot-provider-badge","data-provider-mark":"pi",children:"P"}),t==="antigravity"&&a.jsx("span",{className:"mascot-provider-badge","data-provider-mark":"antigravity",children:"A"}),i&&a.jsx("span",{className:"mascot-z",children:"z"}),n&&a.jsx("span",{className:"mascot-task-dot"})]})}function Oz(t){if(/^[A-Za-z]:[\\/]/.test(t))return t.slice(0,3);const e=/^(?:\\\\|\/\/)[^\\/]+[\\/][^\\/]+/.exec(t);return e?e[0]:t.startsWith("/")?"/":null}function rD(t){return Oz(t)!==null}function aD(t){const e=Oz(t);if(!e)return null;const n=t.replace(e==="/"?/\/+$/:/[\\/]+$/,"");if(n.length<=e.length)return null;const s=e==="/"?n.lastIndexOf("/"):Math.max(n.lastIndexOf("/"),n.lastIndexOf("\\"));return s<e.length?e:n.slice(0,s)}function qge(t,e){return t.filter(n=>n.is_dir?!n.is_hidden&&!n.name.startsWith("."):e)}function WE({start:t,title:e,onPick:n,onClose:s,files:i=!1}){const[r,o]=y.useState(t),[l,u]=y.useState(t),[h,f]=y.useState([]),[m,g]=y.useState(null),[x,b]=y.useState(!0),_=y.useCallback(N=>{o(N),u(N)},[]);y.useEffect(()=>{let N=!0;return b(!0),te.invoke("list_dir",{path:r}).then(j=>{if(!N)return;f(qge(j??[],i)),g(null);const M=(j??[])[0];if(M&&!rD(r)){const A=aD(M.path);A&&(o(A),u(A))}}).catch(j=>{N&&(f([]),g(j.message))}).finally(()=>N&&b(!1)),()=>{N=!1}},[r,i]),y.useEffect(()=>{const N=j=>j.key==="Escape"&&s();return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[s]);const k=aD(r);return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"panel-scrim",onClick:s}),a.jsxs("div",{className:"fp-picker",role:"dialog","aria-label":e,children:[a.jsxs("header",{className:"fp-picker-head",children:[a.jsx("span",{className:"fp-picker-title",children:e}),a.jsx("button",{className:"panel-close",type:"button",onClick:s,"aria-label":"Close",children:"✕"})]}),a.jsxs("form",{className:"fp-picker-path",onSubmit:N=>{N.preventDefault(),_(l.trim())},children:[a.jsx("input",{className:"fp-picker-input",value:l,spellCheck:!1,autoCapitalize:"off",autoCorrect:"off",placeholder:"Folder path",onChange:N=>u(N.target.value)}),a.jsx("button",{className:"panel-btn",type:"submit",children:"Go"})]}),m&&a.jsx("div",{className:"panel-error",children:m}),a.jsxs("div",{className:"fp-picker-body",children:[k&&a.jsxs("button",{className:"fp-picker-row is-up",type:"button",onClick:()=>_(k),children:[a.jsx(oD,{}),a.jsx("span",{className:"fp-picker-name",children:".."})]}),x&&h.length===0&&!m&&a.jsx("div",{className:"dots","aria-label":"loading"}),!x&&h.length===0&&!m&&a.jsx("div",{className:"fp-picker-empty",children:i?"No files or visible folders in here.":"No visible folders in here."}),h.map(N=>a.jsxs("button",{className:`fp-picker-row ${N.is_dir?"":"is-file"}`,type:"button",onClick:()=>N.is_dir?_(N.path):n(N.path),children:[N.is_dir?a.jsx(oD,{}):a.jsx(Uge,{}),a.jsx("span",{className:"fp-picker-name",children:N.name})]},N.path))]}),a.jsxs("footer",{className:"fp-picker-foot",children:[a.jsx("div",{className:"fp-picker-here",title:r,children:a.jsx("bdi",{children:r})}),!i&&a.jsx("button",{className:"panel-btn is-primary",type:"button",disabled:!rD(r),onClick:()=>n(r),children:"Use this folder"})]})]})]})}function oD(){return a.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:a.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 Uge(){return a.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:[a.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z"}),a.jsx("path",{d:"M14 2v6h6"})]})}function Vge({onReference:t,onUpload:e}){return a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",role:"menuitem",className:"picker-item",onClick:t,children:[a.jsx("span",{className:"picker-name",children:"Reference a file"}),a.jsx("span",{className:"picker-model",children:"on the machine running the agents"})]}),a.jsxs("button",{type:"button",role:"menuitem",className:"picker-item",onClick:e,children:[a.jsx("span",{className:"picker-name",children:"Upload a file"}),a.jsx("span",{className:"picker-model",children:"from this device — up to 12 MB per file"})]})]})}function Pc(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}const Kge={isRepo:!1,current:"",branches:[],isWorktree:!1};function Gge({projects:t,projectId:e,onProject:n,branch:s,branches:i=Kge,onBranch:r,newWorktree:o,onNewWorktree:l,useSandbox:u=!1,onUseSandbox:h}){const f=t.filter(x=>Pc(x.name)!=="general"),m=s&&!i.branches.includes(s)?[s,...i.branches]:i.branches,g=i.loading?"Finding branches…":i.error?"Branches unavailable":i.isRepo?s||i.current||"No branch":"No Git repository";return a.jsxs("div",{className:"work-location enter-gated","aria-label":"Work location",children:[a.jsxs("label",{className:"work-location-field",title:"Project",children:[a.jsx(Yge,{}),a.jsx("span",{className:"sr-only",children:"Project"}),a.jsxs("select",{"aria-label":"Project",value:e??"",onChange:x=>n(x.target.value||null),children:[a.jsx("option",{value:"",children:"General"}),f.map(x=>a.jsx("option",{value:x.id,children:x.name},x.id))]})]}),a.jsx("span",{className:"work-location-divider","aria-hidden":"true"}),a.jsxs("label",{className:`work-location-field is-branch ${i.isRepo?"":"is-muted"}`,title:o?"Base branch":"Branch",children:[a.jsx(Xge,{}),a.jsx("span",{className:"sr-only",children:o?"Base branch":"Branch"}),a.jsxs("select",{"aria-label":o?"Base branch":"Branch",value:s,disabled:i.loading||!i.isRepo,onChange:x=>r(x.target.value),children:[!m.length&&a.jsx("option",{value:"",children:g}),m.map(x=>a.jsx("option",{value:x,children:x},x))]})]}),a.jsx("span",{className:"work-location-spacer"}),a.jsxs("label",{className:`worktree-choice ${i.isWorktree?"is-active":""}`,title:i.isWorktree?"This chat runs in a linked worktree":"Create a task branch in a new linked worktree",children:[a.jsx("input",{type:"checkbox",checked:o,disabled:!i.isRepo,onChange:x=>l(x.target.checked)}),a.jsx(Qge,{}),a.jsx("span",{children:"New worktree"})]}),a.jsxs("label",{className:"worktree-choice sandbox-choice",title:"Prepare local test services and a separate database for this chat",children:[a.jsx("input",{type:"checkbox",checked:u,onChange:x=>h?.(x.target.checked)}),a.jsx("span",{children:"Use sandbox"})]}),i.error&&a.jsx("span",{className:"work-location-error",role:"status",children:i.error})]})}function Yge(){return a.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:[a.jsx("path",{d:"M3 7.5h7l2 2h9v9.5H3z"}),a.jsx("path",{d:"M3 7.5V5h7l2 2h9v2.5"})]})}function Xge(){return a.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:[a.jsx("circle",{cx:"6",cy:"5",r:"2"}),a.jsx("circle",{cx:"18",cy:"7",r:"2"}),a.jsx("circle",{cx:"6",cy:"19",r:"2"}),a.jsx("path",{d:"M6 7v10M8 10h4a6 6 0 0 0 6-1"})]})}function Qge(){return a.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:[a.jsx("circle",{cx:"6",cy:"6",r:"2"}),a.jsx("circle",{cx:"18",cy:"6",r:"2"}),a.jsx("circle",{cx:"12",cy:"18",r:"2"}),a.jsx("path",{d:"M6 8v2a4 4 0 0 0 4 4h2M18 8v2a4 4 0 0 1-4 4h-2v2"})]})}function Zge(t){return`pasted.${(t.split("/")[1]||"png").replace("jpeg","jpg")}`}function Iz(t){const e=t;return e?.message||e?.name||String(t??"no reason given")}function Jge(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 (${Iz(t)}). Hold the box and choose Paste.`}async function eve(t){const e=[];let n="";for(const s of t){const i=s.types.find(r=>r.startsWith("image/"));if(i){const r=await s.getType(i);e.push(new File([r],Zge(i),{type:i}));continue}s.types.includes("text/plain")&&(n+=await(await s.getType("text/plain")).text())}return{files:e,text:n}}const IS="blank:new",tve=()=>({text:"",attached:[]});class Bz{held=new Map;keep(e,n){const s=e??IS;if(!n.text.trim()&&n.attached.length===0){this.held.delete(s);return}this.held.set(s,{text:n.text,attached:[...n.attached]})}take(e){const n=e??IS,s=this.held.get(n);return this.held.delete(n),s??tve()}forget(e){this.held.delete(e??IS)}}function nve(t){const{record:e,choice:n}=t,s=Hn(n.agent),i=e===null,r=o=>i||typeof o=="string"&&o!=="";return{model:(i||e?.modelId||t.reported)&&n.model?n.model:void 0,effort:r(e?.effort)?s.efforts.find(o=>o.id===t.effort)?.label:void 0,access:r(e?.permission)?s.access.find(o=>o.id===t.access)?.label:void 0}}function sve(t){return[t.model?.toLowerCase(),t.effort?.toLowerCase(),t.access].filter(e=>!!e).join(" · ")}function ive(t){const e=[t.model?.toLowerCase(),t.effort?.toLowerCase()].filter(n=>!!n).join(" · ");return{rest:e,access:t.access?`${e?" · ":""}${t.access}`:""}}function rve(t){return[{label:"Model",value:t.model},{label:"Effort",value:t.effort},{label:"Access",value:t.access}].filter(n=>!!n.value)}function ave(t,e){return[t!==void 0?`Last turn · ${(t/1e3).toFixed(1)}s`:"",e!==void 0?`Cost · $${e.toFixed(3)}`:""].filter(Boolean)}const $z={tight:!1,at:0};function ove(t,e,n=!1){return t.tight?n||e.clientWidth>t.at?$z:t:e.scrollWidth>e.clientWidth?{tight:!0,at:e.clientWidth}:t}const Pz={answer:"Waiting for your answer",approval:"Waiting for your approval",unknown:"Checking what waits on you",unchecked:"Could not check what waits on you"},lve="Check again",lD=t=>t==="answer"||t==="approval",cve=t=>t==="unknown"||t==="unchecked";function uve(t,e){return t.kind==="plan"?{chat:t.openChatId,wait:"approval"}:!t.chatId||t.cardMissing?null:t.kind==="permission"?{chat:t.chatId,wait:"approval"}:t.kind==="question"?{chat:t.chatId,wait:"answer"}:t.kind==="safety"&&!e.has(t.key)?{chat:t.chatId,wait:"answer"}:null}function hve(t,e=pve,n=dve){const s=new Map;for(const i of t){const r=uve(i,e);r&&!s.has(r.chat)&&s.set(r.chat,r.wait)}if(n.whole!=="read"){const i=n.whole==="unread"?"unknown":"unchecked";for(const r of n.restored)s.has(r)||s.set(r,i)}return s}const dve={whole:"read",restored:[]};function fve(t,e){const n=t.get(e);return cve(n)?"unknown":n!==void 0}const pve=new Set;function mve(t,e,n){const s=[];for(const[i,r]of Object.entries(t))if(r?.length)for(const o of n(r,e(i)).folded)s.push(`safety:${o.id}`);return s.sort()}function gve(t,e){const n=new Set;for(const s of t)e.has(s)||n.add(s);return n}function cD(t,e,n,s){const i=t.slice(n,s),r=(e==="codex"?/^([/$])(\S*)$/:/^(\/)(\S*)$/).exec(i);if(r)return{trigger:r[1],query:r[2],start:n,end:s}}function uD(t,e,n=t.length){const s=Math.max(0,Math.min(n,t.length));let i=s;for(;i>0&&!/\s/.test(t[i-1]);)i-=1;const r=t.slice(s).search(/\s/),o=r<0?t.length:s+r,l=cD(t,e,i,o);if(e==="claude")return i===0&&o===t.length?l:void 0;if(l)return l;let u=i;for(;u>0;){for(;u>0&&/\s/.test(t[u-1]);)u-=1;const h=u;for(;u>0&&!/\s/.test(t[u-1]);)u-=1;const f=cD(t,e,u,h);if(f)return f}}function hD(t,e){return e==="$"?t.replace(/^\//,"$"):t}function vve(t,e,n){const s=e.end<t.length&&/\s/.test(t[e.end])?n.trimEnd():n;return{text:t.slice(0,e.start)+s+t.slice(e.end),caret:e.start+s.length}}function xve(t,e){const n=Hn(t).models.filter(u=>u.flag),s=t==="claude"?n.filter(u=>["opus","sonnet","haiku","fable"].includes(u.flag)):[],i=e.models.flatMap(u=>{const h=B_(t,u.model,u.displayName,u.description??u.model);return h?[h]:[]}),r=[],o=new Set,l=e.source==="bundled"?n:[];for(const u of[...s,...i,...l]){const h=u.flag.toLowerCase();!h||o.has(h)||(o.add(h),r.push(u))}return r}const BS=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches;function yve(t){return t?null:"Enter to send · Shift+Enter for a new line"}function bve(t,e){return t?e?"avatar":null:"mascot"}const wve=8e3,_ve=typeof navigator<"u"&&!!navigator.clipboard&&!!(navigator.clipboard.read||navigator.clipboard.readText);function kve(t,e){const[n,s]=y.useState({}),[i,r]=y.useState({}),o=y.useRef(new Set),l=y.useCallback((f,m=!1)=>{f==="pi"||!m&&o.current.has(f)||(o.current.add(f),r(g=>({...g,[f]:{...g[f],loading:!0,error:void 0}})),te.invoke("agent_models",{agent:f}).then(g=>{s(x=>({...x,[f]:xve(f,g)})),r(x=>({...x,[f]:{loading:!1,note:g.note??void 0}}))}).catch(g=>{r(x=>({...x,[f]:{loading:!1,error:String(g?.message??g)}}))}))},[]);y.useEffect(()=>{if(t)for(const f of["claude","codex","antigravity"])e&&!e.includes(f)||l(f)},[t,e,l]);const u=y.useMemo(()=>Nf.flatMap(f=>n[f.id]??f.models),[n]),h=y.useCallback(f=>{o.current.delete(f),l(f,!0)},[l]);return{models:u,status:i,reload:h}}function zz({list:t,access:e,onPick:n,note:s}){const i=t.filter(l=>!l.bypass),r=t.find(l=>l.bypass),o=y.useRef(e===r?.id?i[i.length-1].id:e);return e!==r?.id&&(o.current=e),a.jsxs(a.Fragment,{children:[s&&a.jsx("div",{className:"picker-note",children:s}),i.map(l=>a.jsxs("button",{type:"button",role:"menuitem",className:`picker-item ${l.id===e?"is-on":""}`,onClick:()=>n(l.id),children:[a.jsx("span",{className:"picker-name",children:l.label}),a.jsx("span",{className:"picker-model",children:l.hint}),l.id===e&&a.jsx("span",{className:"picker-tick","aria-hidden":"true",children:"✓"})]},l.id)),r&&a.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":e===r.id,className:`picker-item is-bypass ${e===r.id?"is-on":""}`,title:r.hint,onClick:()=>n(e===r.id?o.current:r.id),children:[a.jsx("span",{className:"picker-name",children:r.label}),a.jsx("span",{className:"picker-switch",children:e===r.id?"Enabled":"Enable"})]})]})}const dD=/\.(png|jpe?g|gif|webp)$/i,Sve=100;function Fz(t){return`octiq.v2.history:${t||"new"}`}function fD(t){try{const e=JSON.parse(localStorage.getItem(Fz(t))||"[]");return Array.isArray(e)?e.filter(n=>typeof n=="string"):[]}catch{return[]}}function Cve(t,e){try{localStorage.setItem(Fz(t),JSON.stringify(e))}catch{}}function jve(t,e,n,s,i){if(i==="older"){if(!t.length)return{index:e,text:n,draft:s};const o=Math.min(e+1,t.length-1);return{index:o,text:t[o],draft:e===-1?n:s}}if(e<0)return{index:e,text:n,draft:s};const r=e-1;return{index:r,text:r<0?s:t[r],draft:s}}function Nve(t,e){return[t.trim(),...e.map(n=>n.trim())].filter(Boolean).join(`
97
+ `).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 Hpe(t){const e=[];for(let n=t.length-1;n>=0&&e.length<3;n--){const s=t[n],i=rz(s);i&&e.unshift(i)}return e}function f2(t){for(let e=t.length-1;e>=0;e--){if(t[e].role==="user")continue;const n=rz(t[e]);if(n)return n}}function IE(t){const e=[],n=i=>`${e.push(i)-1}`;return t.replace(/\\([\\`*_{}[\]()#+\-.!~|<>])/g,(i,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,(i,r)=>r.split("|").map(o=>o.trim()).filter(Boolean).join(" · ")).replace(/(`+)([^`]*?)\1/g,(i,r,o)=>n(o.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,(i,r)=>e[Number(r)])}async function Wpe(t,e,n){const s=await t();if(n())return[];if(!s.events.length)return e;let i=await rf(xh(),s.context,0,n);return i=await rf(i,s.events,0,n),i.messages}function qpe(t,e){return new Set(t.filter(n=>n.crossProject||!!e&&n.leadId===e).map(n=>n.chatKey))}function BE(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(i=>e(i.projectId,i.projectName)),s=t.unknownTaskCount?`, ${t.unknownTaskCount} ${t.unknownTaskCount===1?"task has":"tasks have"} no confirmed project`:"";return`${n.join(", ")}${s}, ${t.taskCount} ${t.taskCount===1?"task":"tasks"}`}function az(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 y1(t,e,n,s=!1){const i=`chat:${t.id}`;if(!e)return n&&!n.has(i)?{status:"home",destinations:[],taskCount:0,unknownTaskCount:0,homeProjectId:t.projectId}:{status:s?"unknown":"loading",destinations:[],taskCount:0,unknownTaskCount:0};const r=e.runs.filter(m=>m.coordinatorChatKey===i);if(r.length===0&&n===null)return{status:s?"unknown":"loading",destinations:[],taskCount:0,unknownTaskCount:0};if(!(r.length>0||!!n?.has(i)))return{status:"home",destinations:[],taskCount:0,unknownTaskCount:0,homeProjectId:t.projectId};const l=new Set(r.map(m=>m.id)),u=e.tasks.filter(m=>l.has(m.runId)).sort((m,g)=>g.updatedAt-m.updatedAt||m.id.localeCompare(g.id));if(u.length===0)return{status:"discussion",destinations:[],taskCount:0,unknownTaskCount:0};const h=new Map;let f=0;for(const m of u){if(!m.destination){f+=1;continue}h.has(m.destination.projectId)||h.set(m.destination.projectId,m.destination)}return h.size===0?{status:"unknown",destinations:[],taskCount:u.length,unknownTaskCount:f}:{status:"projects",destinations:[...h.values()],taskCount:u.length,unknownTaskCount:f}}function Upe(t,e,n,s){return t.filter(i=>{const r=y1(i,n,s);return r.status==="home"?r.homeProjectId===e:r.destinations.some(o=>o.projectId===e)}).sort((i,r)=>r.updatedAt-i.updatedAt)}function Vpe(t,e,n){const s=new Map;for(const i of t){const r=y1(i,e,n),o=r.status==="home"?r.homeProjectId?[r.homeProjectId]:[]:r.destinations.map(l=>l.projectId);for(const l of new Set(o))s.set(l,(s.get(l)??0)+1)}return s}const oz=new Set;function Kpe(t,e,n=qo,s=oz){return Upe(t,e,n,s)}function Gpe(t,e=qo,n=oz){return Vpe(t,e,n)}const z4=["#f87171","#fb923c","#fbbf24","#a3e635","#34d399","#22d3ee","#60a5fa","#a78bfa","#f472b6","#94a3b8"];function F4(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 b1(t){const e=t.color?.trim();if(e&&/^#[0-9a-f]{6}$/i.test(e))return e;const n=t.name||t.id;let s=0;for(let i=0;i<n.length;i+=1)s=s*31+n.charCodeAt(i)>>>0;return z4[s%z4.length]}function Ype(t){const e=[...(t.initial??"").trim()].slice(0,2).join("");return e?e.toLocaleUpperCase():[...t.name.trim()][0]?.toLocaleUpperCase()??"?"}function Mh({project:t,size:e="small",className:n=""}){const s=t.icon?.trim(),i={"--project-color":b1(t)};return a.jsx("span",{className:["project-avatar",`is-${e}`,s?"has-icon":"",n].filter(Boolean).join(" "),style:i,"aria-hidden":"true",children:s?a.jsx("img",{className:"project-avatar-image",src:s,alt:""}):a.jsx("span",{className:"project-avatar-text",children:Ype(t)})})}function H4(t,e){const n=new Map(t.map((l,u)=>[l.id,{chat:l,children:[],descendants:[],rank:u}])),s=new Map;for(const l of t){const u=e.get(l.id);if(!u||u===l.id||!n.has(u))continue;let h=u;for(;h&&h!==l.id;)h=s.get(h);h||s.set(l.id,u)}const i=[];for(const l of n.values()){const u=s.get(l.chat.id);u?n.get(u).children.push(l):i.push(l)}const r=l=>n.get(l.chat.id).rank,o=l=>{l.children.forEach(o),l.children.sort((u,h)=>r(u)-r(h)),l.descendants=l.children.flatMap(u=>[u.chat,...u.descendants]);for(const u of l.children)n.get(l.chat.id).rank=Math.min(r(l),r(u))};return i.forEach(o),i.sort((l,u)=>r(l)-r(u))}function p2(t,e){const n=t.tasks.find(i=>i.id===e.taskId);if(!n||!br(n)||t.attempts.some(i=>i.taskId===n.id&&["preparing","running"].includes(i.status)))return"Complete the task and settle its workers before archiving.";if(z_(t,n.runId).some(i=>!i.taskId||i.taskId===n.id))return"Resolve the open decision before archiving.";const s=n.workspace;return s?.abandoned?"Only workers for merged tasks can be archived.":!s||!["retained","cleaned"].includes(s.state)||!s.delivery?.merged||s.delivery.dirty?"Refresh delivery status to verify a clean, merged task before archiving.":null}function m2(t,e,n=!1){const s=new Set(e.attempts.filter(i=>i.archivedAt!=null).map(i=>i.workerChatKey.replace(/^chat:/,"")));return t.filter(i=>s.has(i.id)===n)}const Xpe=["needs","running","finished","planned"],Qpe={needs:"Needs you",running:"Running",finished:"Finished",planned:"Planned"},Zpe={needs:!1,running:!1,finished:!0,planned:!1},lz={needs:1/0,running:1/0,finished:3,planned:3},$E={running:"Running",needs:"Needs you",done:"Done",failed:"Failed"},x_=new Set(["planning","running","waiting"]);function w1(t){const e=Math.floor(Math.max(0,t)/6e4);return e<1?"<1m":e<60?`${e}m`:`${Math.floor(e/60)}h ${String(e%60).padStart(2,"0")}m`}function cz(t){const e=Math.max(0,Math.round(t));return e>=1e7?`${Math.round(e/1e6)}M`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:String(e)}function Jpe(t){if(!t||!Number.isFinite(t.input)||!Number.isFinite(t.output))return null;const e=t.input+t.output;return e>0?e:null}function uz(t){let e=0,n=!1;for(const s of t){const i=Jpe(s.usage);i!==null&&(e+=i,n=!0)}return n?e:null}function eme(t){return!t||!(t.window>0)||!(t.tokens>0)?null:Math.min(100,Math.round(t.tokens/t.window*100))}function tme(t){const e=[t.context?`ctx ${t.context}%`:null,t.tokens?cz(t.tokens):null,t.elapsedMs!==null&&t.elapsedMs>0?w1(t.elapsedMs):null].filter(Boolean);return e.length?e.join(" · "):null}function nme(t){return`${t.done}/${t.total} ${t.total===1?"step":"steps"}`}const sme=10*6e4;function ime(t,e,n){return!t||!e?.current||!e.step||e.at===null?null:{at:e.at,total:e.total,title:e.step,reportedAt:e.reportedAt,stale:n-e.reportedAt>sme}}function rme(t){return`${t.at}/${t.total}`}function ame(t){return t.replace(/\s+/g," ").trim()}function ome(t){return`${t.done} / ${t.total}`}const lme={plan:"Plan to approve",gate:"Asks a decision",failure:"Failed",question:"Asks a question",delivery:"Answer not delivered",permission:"Awaiting approval",safety:"Awaiting review",native:"Awaiting review",outage:"Safety check was down",handover:"Asks a handover"},y_="Waiting on the coordinator",hz="Retrying",W4=t=>`${t} automatic ${t===1?"retry":"retries"}`;function cme(t,e,n,s=null){const i=qN(t);if(!i)return null;const{move:r,kind:o}=i,l=i.because??null,u=t.retryLimit??0,h={move:r,kind:o,because:l};if(r==="coordinator"){const j=t.retriesUsed??0;return{...h,askCoordinator:!1,note:`Its coordinator is fixing it: ${j} of ${W4(u)} used. Nothing is asked of you.`}}if(r==="history")return{...h,askCoordinator:!1,note:l==="replaced"?"Another task replaced it. Nothing is owed for it.":"Its run was stopped, closed or archived. Nothing is owed for it."};const f=l==="coordinator_gone",m=l==="retries_used"?`Its ${W4(u)} are used.`:l==="escalated"?n?`Its coordinator asks you: ${n}`:"Its coordinator asks you to decide.":f?"The chat that coordinated this run is gone, so nobody retries it.":l==="time_limit"?"This peer request used up its working time.":"This failure waits on you.",g="stop or archive the run",x=l==="escalated"?"Answer it under Needs you above":null,b=e&&!e.blocked?`open this row for ${e.label}`:null,_=!e&&s?`open this row for ${s.label} to put it back to work with what you write`:null,k=[x,b,_].filter(Boolean),N=j=>j.charAt(0).toUpperCase()+j.slice(1);return k.length?{...h,askCoordinator:!1,note:`${m} ${N(k.join(", "))}, or ${g}.`}:e?.blocked?{...h,askCoordinator:!1,note:`${m} ${e.blocked}`}:f?{...h,askCoordinator:!1,note:`${m} ${N(g)} to put it away.`}:{...h,askCoordinator:!0,note:`${m} It cannot be started from here: ask the coordinator in its chat, or ${g}.`}}function b_(t,e,n,s,i){const r=s.person.find(h=>!h.failure);if(r)return{state:"needs",why:lme[r.kind],tone:"decide"};const o=qN(e);if(o?.move==="person")return{state:"failed",why:RC[o.kind],tone:"danger"};if(o?.move==="coordinator")return{state:"running",why:y_,tone:null};if(o?.move==="history"&&!e.supersededBy)return{state:"closed",why:RC[o.kind],tone:null};if(!o&&Sh(e))return{state:"failed",why:Om,tone:"danger"};if(sg(e))return{state:"done",why:null,tone:null};if(e.status==="cancelled")return{state:"closed",why:"Cancelled",tone:null};if(e.supersededBy)return{state:"closed",why:"Replaced",tone:null};if(t.status==="stopped")return{state:"closed",why:"Stopped",tone:null};if(s.coordinator.length)return{state:"running",why:y_,tone:"warn"};if(i?.kind==="stopped")return{state:"planned",why:i.label,tone:i.tone};const l=!!n&&e.activeAttemptId===n.id;if(zI(e))return l&&Bm(n)?{state:"running",why:$x[n.execution.state],tone:"warn"}:{state:"running",why:hz,tone:null};if(e.status==="failed")return{state:"failed",why:"Failed",tone:"danger"};const u=s.unsaid[0];if(u?.kind==="gate")return{state:"running",why:"Asks a decision",tone:null};if(e.status==="blocked")return u?{state:"running",why:"Decision recorded",tone:null}:{state:"failed",why:"Blocked",tone:"danger"};if(e.status==="running"){if(l&&n.execution){const h=n.execution.pendingTools?.["octiq:environment"];if(h)return{state:"running",why:h.startsWith("Waiting for environment capacity")?"Waiting for an environment slot":"Preparing environment",tone:null};if(Bm(n)||n.execution.state==="retrying")return{state:"running",why:$x[n.execution.state],tone:"warn"}}return l&&YN(n)==="proposed"?{state:"running",why:"Report proposed",tone:null}:n?.status==="preparing"&&!n.execution?{state:"running",why:"Preparing workspace",tone:null}:{state:"running",why:null,tone:null}}return{state:"planned",why:i?.label??null,tone:i?.tone??null}}const ume={needs:"needs",failed:"running",running:"running",done:"finished",closed:"finished",planned:"planned"};function hme(t,e){return e==="failed"&&ig(t)==="person"?"needs":ume[e]}function dme(t){return WN(t.task)?ig(t.task)==="person":t.state==="failed"}function fme(t,e,n){return n.state!=="running"||n.tone==="warn"||t.status!=="running"?!1:!!e&&t.activeAttemptId===e.id&&XN(e)}function dz(t,e,n,s,i,r=Yc(t,e,i)){const o=KN(t,n),l=r.tasks.get(n.id)??P_,u=f0(n,e,t.tasks,s),h=b_(e,n,o,l,u),f=hme(n,h.state),m=qN(n),g=m?.move==="person"?s6(n,e,t.tasks,t.attempts,r.gated.has(n.id)):null,x=m?.gateId?z_(t,e.id).find(L=>L.id===m.gateId)?.question??null:null,b=m?.move==="person"?i6(n,e):null,_=cme(n,g,x,b),k=QI(n,o,o?t.reports?.[o.workerChatKey]:void 0),N=k?{done:k.done,total:k.total}:null,j=t.attempts.filter(L=>L.taskId===n.id),M=new Map(t.tasks.map(L=>[L.id,L])),A=h.state==="running"||h.state==="needs",E=fme(n,o,h);return{task:n,attempt:o,...h,group:f,flight:E,step:ime(E,k,s),decisions:f==="needs"?l.person.length:0,failure:_&&(_.move==="person"||h.why===(_.move==="coordinator"?y_:RC[_.kind]))?_:null,hint:l.unsaid.length&&(h.state==="running"||h.state==="failed"||h.state==="planned")?qI:null,hold:h.state==="planned"?u:null,steps:N,percent:N?Math.round(N.done/N.total*100):h.state==="done"?100:null,model:o?.model||n.worker?.model||null,effort:o?.effort||n.worker?.effort||null,after:h.state!=="planned"?[]:n.dependsOn.flatMap(L=>{const O=M.get(L);return O&&!sg(O)?[O.title]:[]}),verdict:br(n)?n.verdict??null:null,elapsedMs:SV(t,n,s),tokens:uz(j),context:A&&o&&n.activeAttemptId===o.id?eme(o.context):null}}function fz(t,e){return t.planApproval?.status!=="pending"?!1:e.every(n=>n.state==="done"||n.state==="closed"||n.state==="planned"&&n.hold?.kind==="plan")}function pme(t,e){const n=new Map(e.map((r,o)=>[r,o])),s=(r,o)=>n.get(r)-n.get(o);if(t==="needs")return e;if(t==="finished"){const r=o=>o.attempt?.finishedAt??o.task.updatedAt;return[...e].sort((o,l)=>+(o.state==="closed")-+(l.state==="closed")||r(l)-r(o)||s(o,l))}if(t==="planned"){const r=o=>o.hold?.kind==="stopped"?0:o.hold?.tone==="warn"?1:o.hold?2:3;return[...e].sort((o,l)=>r(o)-r(l)||+(l.task.status==="ready")-+(o.task.status==="ready")||s(o,l))}const i=r=>r.state==="failed"?0:r.tone==="warn"?1:2;return[...e].sort((r,o)=>i(r)-i(o)||s(r,o))}function mme(t,e){const n=lz[t.key];return e||t.rows.length<=n+1?{rows:t.rows,more:0}:{rows:t.rows.slice(0,n),more:t.rows.length-n}}const Zc=(t,e,n)=>`${t} ${t===1?e:n}`;function gme(t){const e=t.rows.length;if(t.key!=="needs")return{label:`${t.label} · ${e}`,spoken:`${t.label}, ${Zc(e,"task","tasks")}`};const n=Zc(t.rows.reduce((s,i)=>s+i.decisions,0),"decision","decisions");return{label:`${t.label} · ${n}`,spoken:`${t.label}, ${n} in ${Zc(e,"task","tasks")}`}}function pz(t,e){const n=t.working?{text:`${t.working} working`,strong:!1}:null,s=t.failed?{text:`${t.failed} failed`,strong:!1}:null,i=t.runs>1?{text:`${t.runs} runs`,strong:!1}:null,r=t.stopped?{text:`${t.stopped} stopped`,strong:!1}:null;return(t.state==="needs"?[{text:t.planOnly?"Plan to approve":Zc(t.needs,"decision","decisions"),strong:!0},i??s??n??r]:t.state==="failed"?[{text:`${t.failed} failed`,strong:!0},i??n??r]:t.state==="done"?[e!==null&&e>0?{text:w1(e),strong:!1}:null,i]:[n,i??r]).filter(l=>!!l).slice(0,2)}function vme(t){const[e,...n]=t.side;return t.state==="failed"&&e?.strong?{word:e.text,side:n}:{word:t.word,side:t.side}}function xme(t,e){return br(e)?!0:e.status!=="cancelled"&&!e.supersededBy&&t.status!=="stopped"}function mz(t,e){const n=e.filter(r=>xme(t,r.task)),s=e.filter(dme).length,i=!e.some(r=>WN(r.task));return{done:n.filter(r=>sg(r.task)).length,total:n.length,failed:s+(i&&t.status==="failed"&&!s&&!e.some(r=>r.hold?.kind==="stopped")?1:0)}}function gz(t,e,n,s=Yc(t,e,n)){return mz(e,t.tasks.filter(i=>i.runId===e.id).map(i=>{const r=f0(i,e,t.tasks,0),{state:o}=b_(e,i,KN(t,i),s.tasks.get(i.id)??P_,r);return{task:i,state:o,hold:o==="planned"?r:null}}))}function yme(t){const e=i=>t.filter(r=>r.hold?.kind===i).length,[n,s]=[e("stopped"),e("reopen")];return[n?`${Zc(n,"task","tasks")} stopped by you: only your Start starts ${n===1?"it":"them"} again.`:null,s?`${Zc(s,"reopened task","reopened tasks")} held: the notice of ${s===1?"it":"them"} is not confirmed as saved yet.`:null].filter(i=>!!i)}function PE(t,e,n,s,i=Yc(t,e,s)){const r=t.tasks.filter(j=>j.runId===e.id),o=t.attempts.filter(j=>j.runId===e.id),l=r.map(j=>dz(t,e,j,n,s,i)),u=Xpe.flatMap(j=>{const M=l.filter(A=>A.group===j);return M.length?[{key:j,label:Qpe[j],rows:pme(j,M)}]:[]}),{done:h,total:f,failed:m}=mz(e,l),g=XI(t,e.id,n),x={tasks:{done:h,total:f},tokens:uz(o),elapsedMs:g},b=x_.has(e.status),_=i.person.length,k=l.filter(j=>j.flight).length;let N=null;if(_>0||f>0&&e.archivedAt==null&&e.status!=="closed"&&e.status!=="stopped"){const j=i.person.filter(X=>X.failure).length,M=_?j===_?"failed":"needs":m?"failed":h===f?"done":"running",A=l.filter(X=>X.failure?.move==="coordinator").length,E=[i.coordinator.length?`${i.coordinator.length} waiting on the coordinator.`:null,A?`${Zc(A,"failure","failures")} with the coordinator, which is fixing ${A===1?"it":"them"}: nothing is asked of you.`:null,i.unsaid.length?`${Zc(i.unsaid.length,"open decision","open decisions")}: the host does not say who ${i.unsaid.length===1?"it waits":"they wait"} on.`:null,...yme(l)].filter(X=>!!X),L=l.filter(X=>X.hold?.kind==="stopped").length,O={state:M,needs:_,failures:j,planOnly:_===1&&i.person[0].kind==="plan",failed:m,stopped:L,working:k,runs:1};N={...O,word:$E[M],done:h,total:f,percent:f?Math.round(h/f*100):0,label:f?`${h}/${f}`:r.length===0?"No tasks yet":e.status==="stopped"?"Run stopped":"No tasks left",side:pz(O,g),live:M==="running"&&b&&k>0,notes:E,signature:[e.id,M,`${h}/${f}`,_,m].join(":")}}return{rows:l,groups:u,tiles:x,strip:N}}function bme(t){return t.find(e=>x_.has(e.status)&&e.archivedAt==null)??t.find(e=>e.archivedAt==null&&e.status!=="closed"&&e.status!=="stopped")??null}function wme(t,e,n){const s=rg(t,n),i=b=>{const _=PE(t,b,e,n,s.runs.get(b.id)).strip;return _?[{run:b,strip:_}]:[]},r=t.runs.filter(b=>x_.has(b.status)&&b.archivedAt==null||!!s.runs.get(b.id)?.person.length).flatMap(i);if(r.length<2){if(r.length===1)return r[0];const b=bme(t.runs);return b?i(b)[0]??null:null}const o=r.find(b=>b.strip.state==="needs")??r.find(b=>b.strip.needs>0)??r.find(b=>b.strip.state==="failed")??r.find(b=>b.strip.live)??r[0],l=r.reduce((b,_)=>b+_.strip.needs,0),u=r.reduce((b,_)=>b+_.strip.failures,0),h=r.filter(b=>b.strip.needs>0),f=l?u===l?"failed":"needs":o.strip.state,m={state:f,needs:l,failures:u,planOnly:l===1&&h[0].strip.planOnly,failed:u?r.reduce((b,_)=>b+(_.strip.failures?_.strip.failed:0),0):o.strip.failed,stopped:o.strip.stopped,working:o.strip.working,runs:r.length},g=r.length-1,x=r.every(b=>x_.has(b.run.status)&&b.run.archivedAt==null);return{run:o.run,strip:{...o.strip,...m,word:$E[f],side:pz(m,null),notes:[`The bar is one of ${r.length} ${x?"live runs":"runs"} of this chat${o.strip.needs?", the one that waits on you":""}.`,...l>o.strip.needs?[`${Zc(l-o.strip.needs,"decision","decisions")} in ${g===1?"the other run":"the other runs"}.`]:[],...r.flatMap(b=>b.strip.notes)],signature:[o.run.id,f,`${o.strip.done}/${o.strip.total}`,l,m.failed,r.length].join(":")}}}const vz=40;function _me(t,e){const n=e.slice(0,e.indexOf(":"));return[...t.filter(s=>!s.startsWith(`${n}:`)),e].slice(-vz)}function kme(t,e){return!!e&&t.includes(e.signature)}function Sme(t){if(!t)return[];try{const e=JSON.parse(t);return Array.isArray(e)?e.filter(n=>typeof n=="string").slice(-vz):[]}catch{return[]}}const Lh=t=>["planning","running","waiting"].includes(t.status);function i0(t,e){if(!e)return qo;const n=t.runs.filter(i=>i.coordinatorChatKey===e).sort((i,r)=>Number(Lh(r))-Number(Lh(i))||r.createdAt-i.createdAt),s=new Set(n.map(i=>i.id));return{runs:n,reports:t.reports,tasks:t.tasks.filter(i=>s.has(i.runId)),...t.nativeDecisions?{nativeDecisions:t.nativeDecisions.filter(i=>s.has(i.runId))}:{},attempts:t.attempts.filter(i=>s.has(i.runId)),gates:t.gates.filter(i=>s.has(i.runId)),messages:t.messages.filter(i=>s.has(i.runId)),notifications:t.notifications?.filter(i=>s.has(i.runId))}}function Cme(t,e){const n=rg(t,e);return t.runs.find(s=>n.runs.get(s.id)?.person.length)??t.runs.find(s=>s.archivedAt==null)??t.runs[0]}function jme(t,e,n){const s=Yc(t,e,n),{done:i,total:r,failed:o}=gz(t,e,n,s),l=(...m)=>m.filter(Boolean).join(" · "),u=r?`${i}/${r} done`:null,h=o?`${o} failed`:null;if(s.person.length)return s.person.every(m=>m.failure)?{text:l(h,u),tone:"danger"}:{text:l($E.needs,h,u),tone:"decide"};if(o)return{text:l(h,u),tone:"danger"};const f=Im(e,t.tasks);return{text:l(f.charAt(0).toUpperCase()+f.slice(1),u),tone:null}}function Nme(t,e,n){const s=jme(t,e,n),i=t.tasks.length,r=t.tasks.filter(o=>o.runId===e.id).length;return t.runs.length<2||i===r?s:{...s,text:`${s.text} · ${i} ${i===1?"task":"tasks"} in ${t.runs.length} runs`}}function Ame(t,e){return e.archivedAt!=null?{text:`${t.title} · archived`,tone:null}:Sh(t)&&t.activeAttemptId===e.id?{text:`${t.title} · ${Om.toLowerCase()}`,tone:Vo(t)==="red"?"danger":null}:{text:`${t.title} · ${e.status}`,tone:null}}function Eme(t,e,n){const s=new Set(t.map(o=>o.id)),i=new Map(e.runs.map(o=>[o.id,o])),r=new Set;for(const o of e.tasks){const l=e.attempts.filter(f=>f.taskId===o.id).sort((f,m)=>m.number-f.number),u=l.find(f=>f.id===o.activeAttemptId)??l[0],h=i.get(o.runId)?.coordinatorChatKey.replace(/^chat:/,"");if(!(!u||!h||!s.has(h)||!s.has(u.workerChatKey.replace(/^chat:/,""))))for(const f of l)f.id!==u.id&&r.add(f.workerChatKey.replace(/^chat:/,""))}return m2(t,e).filter(o=>o.id===n||!r.has(o.id))}function xz(t,e){const n=t.teamId?e.find(s=>s.id===t.teamId):void 0;return n?{id:n.id,name:n.name}:null}function yz(t){const e=new Set(t.map(l=>l.id)),n=(l,u)=>l.name.localeCompare(u.name),s=l=>t.filter(u=>u.reportsTo===l).sort(n),i=[],r=new Set,o=(l,u)=>{if(!r.has(l.id)){r.add(l.id),i.push({agent:l,depth:u});for(const h of s(l.id))o(h,u+1)}};for(const l of t.filter(u=>!u.reportsTo||!e.has(u.reportsTo)).sort(n))o(l,0);return i}const r0={working:"Working",needs_you:"Needs you",failed:"Failed",blocked:"Blocked",stalled:"Stalled",queued:"Queued",idle:"Idle",unknown:"Unknown"},g2=["working","needs_you","failed","blocked","stalled","queued","unknown","idle"],q4=["needs_you","failed","blocked","stalled","working","queued","unknown","idle"],Mme=["planning","running","waiting"];function bz(t,e){const n=t.attempts.filter(s=>s.taskId===e.id);return n.find(s=>s.id===e.activeAttemptId)??[...n].sort((s,i)=>i.number-s.number)[0]}function wz(t,e,n,s,i){if(!e)return null;const r=s.person.find(h=>!h.failure);if(r)return{state:"needs_you",label:r.kind==="gate"?"Waiting on a decision":"Needs your approval"};if(s.person.length)return{state:"failed",label:b_(e,t,n,s,i).why??r0.failed,tone:"danger"};if(e.archivedAt||!(Mme.includes(e.status)||Vo(t)==="quiet"))return null;const o=b_(e,t,n,s,i);if(o.state==="failed")return{state:"failed",label:o.why??r0.failed,tone:"danger"};if(o.state==="done"||o.state==="closed")return null;const l=Vo(t)==="quiet";if(l||zI(t)){const h=!l&&!!n&&(n.execution?.state==="executing"||n.execution?.state==="waiting_tool");if(o.tone!=="warn")return{state:h?"working":"queued",label:o.why??hz}}if(s.coordinator.length)return{state:"blocked",label:"Waiting on the coordinator"};if([...s.nobody,...s.unsaid].some(h=>h.kind==="gate"))return{state:"blocked",label:"Decision open"};if(i)return{state:"queued",label:i.label,detail:i.detail,...i.tone?{tone:i.tone}:{}};if(t.status==="blocked")return{state:"blocked",label:"Blocked"};if(t.status==="pending"||t.status==="ready")return{state:"queued",label:t.status==="ready"?"Ready to start":"Queued"};if(!n)return{state:"queued",label:"Starting"};const u=n.execution?.state;if(u)switch(u){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 Lme(t,e){const n=new Map(t.runs.map(i=>[i.id,i])),s=rg(t,e);return t.tasks.filter(i=>{const r=bz(t,i),o=n.get(i.runId);return wz(i,o,r,_z(s,i),f0(i,o,t.tasks,0))?.state==="working"}).length}const _z=(t,e)=>t.runs.get(e.runId)?.tasks.get(e.id)??P_;function Tme(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 _b=(t,e)=>t.indexOf(e);function Rme(t){const{team:e,leads:n,snapshot:s,projects:i}=t;if(!e)return[];const r=new Map(i.map(j=>[j.id,j])),o=new Map((s?.runs??[]).map(j=>[j.id,j])),l=s?rg(s,t.held):null,u=new Map,h=new Map,f=(j,M)=>{u.set(j,[...u.get(j)??[],M])},m=(j,M,A,E)=>{const L=h.get(j);(!L||L.at<E)&&h.set(j,{chatKey:M,title:A,at:E})};for(const j of s?.tasks??[]){const M=j.assignee?.id;if(!M||!s)continue;const A=o.get(j.runId),E=bz(s,j);E&&t.chatExists(E.workerChatKey)&&m(M,E.workerChatKey,j.title,E.updatedAt);const L=wz(j,A,E,l?_z(l,j):P_,f0(j,A,s.tasks,t.now??0));if(!L)continue;const O=j.destination;f(M,{key:`task:${j.id}`,kind:"task",...L,title:j.title,project:O?{id:O.projectId,name:r.get(O.projectId)?.name??O.projectName}:null,chatKey:E?.workerChatKey??null,runId:j.runId,taskId:j.id,at:E?.updatedAt??j.updatedAt})}for(const j of n){if(!t.chatExists(j.chatKey))continue;const M=s?.runs.filter(X=>X.coordinatorChatKey===j.chatKey&&!X.archivedAt).sort((X,q)=>q.updatedAt-X.updatedAt)[0],A=t.chatTitle(j.chatKey)??M?.objective??"Conversation";m(j.leadId,j.chatKey,A,Math.max(j.createdAt,M?.updatedAt??0));const E=(s?.runs??[]).filter(X=>X.coordinatorChatKey===j.chatKey).flatMap(X=>l?.runs.get(X.id)?.person.filter(q=>!q.taskId)??[]),L=E.find(X=>X.kind==="plan"),O=Tme(t.leadActivity(j.chatKey),!!L,t.waitingOn(j.chatKey)+E.filter(X=>X.kind!=="plan").length);O&&f(j.leadId,{key:`lead:${j.chatKey}`,kind:"lead",...O,title:A,project:j.crossProject?null:r.get(j.projectId)??null,crossProject:!!j.crossProject,chatKey:j.chatKey,runId:L?.runId??M?.id,at:M?.updatedAt??j.createdAt})}const g=j=>{const M=[...u.get(j.id)??[]].sort((X,q)=>_b(q4,X.state)-_b(q4,q.state)||q.at-X.at),A={};for(const X of M)A[X.state]=(A[X.state]??0)+1;const E=[...M].sort((X,q)=>_b(g2,X.state)-_b(g2,q.state))[0],L=E?.state??(s?"idle":"unknown"),O=E?.label??(s?"Nothing in progress":"Work not loaded");return{...j,state:L,stateLabel:O,activities:M,counts:A,recent:h.get(j.id)??null}},x=new Map(e.map(j=>[j.id,j])),b=j=>{const M=j.reportsTo?x.get(j.reportsTo):void 0;return M?{id:M.id,name:M.name}:null},_=yz(e).map(({agent:j,depth:M})=>g({id:j.id,name:j.name,avatar:j.avatar,detail:t.providerLabel(j),effort:j.effort??null,reportsTo:b(j),role:j.role,scope:j.projectId?r.get(j.projectId)??{id:j.projectId,name:"Unknown project"}:null,team:xz(j,t.teams??[]),depth:M,removed:!1})),k=new Set(e.map(j=>j.id)),N=new Map;for(const j of s?.tasks??[])j.assignee&&!k.has(j.assignee.id)&&N.set(j.assignee.id,j.assignee.name);for(const j of n)k.has(j.leadId)||N.set(j.leadId,j.leadName);for(const[j,M]of N)u.get(j)?.length&&_.push(g({id:j,name:M,detail:"No longer registered",effort:null,reportsTo:null,role:"",scope:null,team:null,depth:0,removed:!0}));return _}function Dme(t){const e=new Map;for(const n of t)e.set(n.state,(e.get(n.state)??0)+1);return g2.filter(n=>e.has(n)).map(n=>({state:n,count:e.get(n)}))}function Ome(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));if(!n)return null;const s=t.tasks.filter(i=>i.runId===n.id);return{run:n,tasks:s,approvable:KI(n,s)!==null}}const _1=y.createContext([]),zE=y.createContext(()=>null);function L0(t){const e=y.useContext(_1);return t?e.find(n=>n.id===t):void 0}function Ime({deleting:t,disabled:e=!1,deleteMs:n,onDelete:s}){const i=t?"Cancel delete":"Delete this chat";return a.jsxs("button",{className:`icon-btn topbar-delete ${t?"is-going":""}`,type:"button","aria-label":i,title:i,disabled:e,onClick:s,children:[t?a.jsx(kz,{ms:n}):a.jsx(Bme,{}),a.jsx("span",{className:"topbar-action-label",children:t?"Undo":"Delete"})]})}function kz({ms:t}){return a.jsxs("svg",{className:"chat-drain",width:"17",height:"17",viewBox:"0 0 16 16","aria-hidden":"true",children:[a.jsx("circle",{className:"chat-drain-track",cx:"8",cy:"8",r:"6.6"}),a.jsx("circle",{className:"chat-drain-arc",cx:"8",cy:"8",r:"6.6",style:{animationDuration:`${t}ms`}}),a.jsx("path",{className:"chat-drain-x",d:"M9.9 6.1 6.1 9.9M6.1 6.1l3.8 3.8"})]})}function Bme(){return a.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:[a.jsx("path",{d:"M4 7h16"}),a.jsx("path",{d:"M9 7V4h6v3"}),a.jsx("path",{d:"m6 7 1 13h10l1-13"}),a.jsx("path",{d:"M10 11v5M14 11v5"})]})}function $me({chat:t,enabled:e,busy:n,getPreviewMessages:s,loadPreview:i,...r}){const o=y.useRef(null),l=y.useRef(void 0),[u,h]=y.useState(!1),f=y.useId(),m=()=>{clearTimeout(l.current),l.current=void 0},g=()=>{m(),h(!1)},x=()=>{m(),e&&(l.current=setTimeout(()=>h(!0),1500))},b=()=>{m(),l.current=setTimeout(()=>h(!1),160)};return y.useEffect(()=>(e||(clearTimeout(l.current),h(!1)),()=>clearTimeout(l.current)),[e]),y.useEffect(()=>{const _=k=>{k.key==="Escape"&&g()};return u&&document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[u]),a.jsxs(a.Fragment,{children:[a.jsx("button",{...r,ref:o,"aria-describedby":u&&e?f:void 0,onPointerEnter:_=>{_.pointerType==="mouse"&&x()},onPointerLeave:b,onFocus:_=>{_.currentTarget.matches(":focus-visible")&&x()},onBlur:g,onClick:_=>{g(),r.onClick?.(_)}}),u&&e&&a.jsx(Pme,{id:f,chat:t,anchor:o.current,messages:s?.(t.id),loadPreview:i,busy:n,onEnter:m,onLeave:b,onClose:g},t.id)]})}function Pme({id:t,chat:e,anchor:n,messages:s,loadPreview:i,busy:r,onEnter:o,onLeave:l,onClose:u}){const h=y.useRef(null),[f,m]=y.useState(e.messages),[g,x]=y.useState(s===void 0&&i?"loading":"ready"),[b,_]=y.useState({left:0,top:0}),k=s!==void 0;y.useEffect(()=>{if(k||!i){x("ready");return}let j=!1;x("loading");const M=setTimeout(()=>{j=!0,x("error")},8e3);return i(e,()=>j).then(A=>{j||(m(A),x("ready"))}).catch(()=>{j||x("error")}).finally(()=>clearTimeout(M)),()=>{j=!0,clearTimeout(M)}},[e.id,k,i]),y.useLayoutEffect(()=>{const j=()=>{const E=(n.closest(".chat")??n).getBoundingClientRect(),L=h.current.getBoundingClientRect(),O=E.right+12,X=O+L.width<=window.innerWidth-12?O:E.left-L.width-12;_({left:Math.max(12,Math.min(X,window.innerWidth-L.width-12)),top:Math.max(12,Math.min(E.top,window.innerHeight-L.height-12))})};j();const M=new ResizeObserver(j);M.observe(h.current),window.addEventListener("resize",u);const A=E=>{h.current?.contains(E.target)||u()};return document.addEventListener("scroll",A,!0),()=>{M.disconnect(),window.removeEventListener("resize",u),document.removeEventListener("scroll",A,!0)}},[n,u]);const N=Hpe(s??f);return Eo.createPortal(a.jsxs("div",{ref:h,id:t,role:"tooltip",className:"chat-preview",style:b,onPointerEnter:o,onPointerLeave:l,children:[a.jsxs("div",{className:"chat-preview-head",children:[a.jsx("strong",{children:e.title}),r&&a.jsx("span",{children:"Working…"})]}),a.jsx("div",{className:"chat-preview-label",children:"Latest conversation"}),N.map(j=>a.jsxs("div",{className:"chat-preview-message",children:[a.jsx("span",{children:j.speaker}),a.jsx("p",{children:j.text})]},j.id)),g==="loading"&&a.jsx("p",{className:"chat-preview-note",children:"Loading latest messages…"}),g==="error"&&a.jsx("p",{className:"chat-preview-note",children:"Preview unavailable. Open the chat to try again."}),g==="ready"&&!N.length&&a.jsx("p",{className:"chat-preview-note",children:"No messages yet."}),a.jsx("div",{className:"chat-preview-foot",children:"Click chat to open · Use ••• for actions"})]}),document.body)}function Sz({info:t,projects:e,limit:n=2,taskCount:s=!0}){const i=new Map(e.map(m=>[m.id,m]));if(t.status==="loading")return a.jsx("span",{className:"conversation-projects is-quiet","aria-label":"Work projects loading",children:"Projects loading…"});if(t.status==="discussion")return a.jsx("span",{className:"conversation-projects is-quiet",children:"Discussion"});if(t.status==="unknown")return a.jsx("span",{className:"conversation-projects is-quiet",children:"Project unknown"});if(t.status!=="projects")return null;const r=t.destinations.map(m=>{const g=i.get(m.projectId);return{id:m.projectId,name:g?.name??m.projectName??"Unknown project",style:g?{"--conversation-project-color":b1(g)}:void 0}}),o=r.slice(0,Math.max(1,n)),l=r.length-o.length,u=t.unknownTaskCount,h=BE(t,(m,g)=>i.get(m)?.name??g??"Unknown project"),f=`${t.taskCount} ${t.taskCount===1?"task":"tasks"}`;return a.jsxs("span",{className:"conversation-projects",title:h,"aria-label":`Work projects: ${h}`,children:[a.jsxs("span",{className:"conversation-project-chips","aria-hidden":"true",children:[o.map(m=>a.jsx("span",{className:`conversation-project-chip${m.style?" is-registered":""}`,style:m.style,children:m.name},m.id)),l>0&&a.jsxs("span",{className:"conversation-project-overflow",children:["+",l]}),u>0&&a.jsx("span",{className:"conversation-project-unknown",children:"+?"})]}),s&&a.jsx("span",{className:"conversation-project-task-count","aria-hidden":"true",children:f})]})}function Cz({info:t,projects:e}){const n=new Map(e.map(l=>[l.id,l])),s=az(t,l=>n.has(l)),i=s?n.get(s):void 0;if(i)return a.jsx(Mh,{project:i,size:"medium"});const r=t.status==="projects"&&t.destinations.length>1,o=t.status==="discussion";return a.jsx("span",{className:`project-avatar is-medium is-neutral${r?" is-several":""}${o?" is-discussion":""}`,"aria-hidden":"true",children:r?a.jsx(Hme,{}):o?a.jsx(zme,{}):t.status==="loading"?null:"?"})}function zme(){return a.jsx("svg",{viewBox:"0 0 16 16",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round","aria-hidden":"true",children:a.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 Fme(t,e){const n=az(t,i=>e.some(r=>r.id===i)),s=e.find(i=>i.id===n);return s?{"--chat-project-color":b1(s)}:void 0}function Hme(){return a.jsxs("svg",{viewBox:"0 0 16 16",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round","aria-hidden":"true",children:[a.jsx("rect",{x:"2.5",y:"5.5",width:"8",height:"8",rx:"2"}),a.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 U4({label:t,items:e,open:n,onOpenChange:s,className:i="",disabled:r=!1,icon:o}){const l=y.useRef(null),u=y.useId();return a.jsxs(a.Fragment,{children:[a.jsx("button",{ref:l,className:`sidebar-menu-trigger ${i}`,type:"button","aria-label":t,title:t,"aria-haspopup":"menu","aria-expanded":n,"aria-controls":n?u:void 0,disabled:r,onClick:h=>{h.currentTarget.focus(),s(!n)},onKeyDown:h=>{(h.key==="ArrowDown"||h.key==="ArrowUp")&&(h.preventDefault(),s(!0))},children:o??a.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[a.jsx("circle",{cx:"5",cy:"12",r:"1.7"}),a.jsx("circle",{cx:"12",cy:"12",r:"1.7"}),a.jsx("circle",{cx:"19",cy:"12",r:"1.7"})]})}),n&&!r&&a.jsx(Wme,{id:u,label:t,anchor:l,items:e,onClose:()=>s(!1)})]})}function Wme({id:t,label:e,anchor:n,items:s,onClose:i}){const r=y.useRef(null),o=y.useRef(!1),l=y.useRef(i);l.current=i,y.useLayoutEffect(()=>{const h=r.current,f=n.current;f.focus({preventScroll:!0}),h.showModal(),(h.querySelector('button[aria-checked="true"]:not(:disabled)')??h.querySelector("button:not(:disabled)"))?.focus({preventScroll:!0});const m=()=>{const _=f.getBoundingClientRect(),k=window.visualViewport,N=k?.offsetLeft??0,j=k?.offsetTop??0,M=k?.width??window.innerWidth,A=k?.height??window.innerHeight,E=h.getBoundingClientRect();h.style.left=`${Math.max(N+8,Math.min(_.right-E.width,N+M-E.width-8))}px`;const L=_.bottom+4,O=L+E.height<=j+A-8?L:_.top-E.height-4;h.style.top=`${Math.max(j+8,Math.min(O,j+A-E.height-8))}px`};m();const g=new ResizeObserver(m);g.observe(h);const x=()=>l.current(),b=_=>{(!(_.target instanceof Node)||!h.contains(_.target))&&x()};return window.addEventListener("resize",x),window.addEventListener("scroll",b,!0),window.visualViewport?.addEventListener("resize",x),()=>{g.disconnect(),h.close(),window.removeEventListener("resize",x),window.removeEventListener("scroll",b,!0),window.visualViewport?.removeEventListener("resize",x)}},[n]);const u=()=>{r.current?.close(),i()};return Eo.createPortal(a.jsx("dialog",{ref:r,id:t,className:"sidebar-dropdown",role:"menu","aria-label":e,onCancel:h=>{h.preventDefault(),u()},onPointerDown:h=>{o.current=h.target===h.currentTarget},onClick:h=>{o.current&&h.target===h.currentTarget&&u(),o.current=!1},onKeyDown:h=>{if(h.key==="Tab"){u();return}if(!["ArrowDown","ArrowUp","Home","End"].includes(h.key))return;h.preventDefault();const f=[...h.currentTarget.querySelectorAll("button:not(:disabled)")],m=f.indexOf(document.activeElement),g=h.key==="Home"?0:h.key==="End"?f.length-1:(m+(h.key==="ArrowDown"?1:-1)+f.length)%f.length;f[g]?.focus()},children:s.map(h=>a.jsxs("button",{type:"button",tabIndex:-1,role:h.checked===void 0?"menuitem":"menuitemradio","aria-checked":h.checked,className:[h.danger?"is-danger":"",h.checked?"is-checked":"",h.separator?"has-separator":""].filter(Boolean).join(" ")||void 0,disabled:h.disabled,title:h.title,onClick:()=>{h.keepOpen||u(),h.onSelect()},children:[h.icon,a.jsx("span",{children:h.label})]},h.id))}),document.body)}const V4=[],qme={forRow:()=>V4,forTask:()=>V4,held:new Map,reveal:()=>{}},jz=y.createContext(qme);function Tf(){return y.useContext(jz)}function k1({actions:t,subject:e,className:n=""}){const{reveal:s}=Tf();if(t.length===0)return null;const i=t1(t),r=xie(t),o=t.length>1;return a.jsxs("button",{type:"button",className:`pending-action-badge${n?` ${n}`:""}`,"data-kind":o?"several":t[0].kind,"data-tone":vie(t),"aria-label":`${i} for ${e}: ${r}. Show ${o?"the first one":"it"}`,title:`${r}. Click to show ${o?"the first one":"it"}.`,onClick:l=>{l.stopPropagation(),s(t[0])},children:[a.jsx(Vme,{}),a.jsx("span",{className:"pending-action-text",children:i})]})}function Ume(t,e=document){const n=[...e.querySelectorAll(yie(t))].map(i=>i.classList.contains("pending-target")?i.firstElementChild:i).find(i=>!!i&&i.getClientRects().length>0);if(!n)return!1;const s=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;return n.scrollIntoView?.({block:"center",behavior:s?"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 Vme(){return a.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:[a.jsx("circle",{cx:"12",cy:"12",r:"9"}),a.jsx("path",{d:"M12 7.5v5.5"}),a.jsx("path",{d:"M12 16.5h.01"})]})}const Kme=1,Gme=180,Yme="cubic-bezier(0.33, 1, 0.68, 1)";function Xme(t,e){const n=new Map;for(const[s,i]of e){const r=t.get(s);if(r===void 0)continue;const o=r-i;Math.abs(o)>=Kme&&n.set(s,o)}return n}function K4(t,e){const n=t.getBoundingClientRect().top,s=new Map;for(const i of t.querySelectorAll(e)){const r=i.dataset.row;r&&s.set(r,i.getBoundingClientRect().top-n)}return s}function Qme(t,e,n="[data-row]"){const s=y.useRef(null);s.current&&s.current.order!==e&&t.current&&(s.current={order:s.current.order,tops:K4(t.current,n)}),y.useLayoutEffect(()=>{const i=t.current;if(!i)return;const r=s.current,o=K4(i,n);if(s.current={order:e,tops:o},!r||r.order===e||typeof window>"u"||window.matchMedia?.("(prefers-reduced-motion: reduce)").matches)return;const l=Xme(r.tops,o);if(l.size)for(const u of i.querySelectorAll(n)){const h=u.dataset.row?l.get(u.dataset.row):void 0;h===void 0||typeof u.animate!="function"||u.animate([{transform:`translateY(${h}px)`},{transform:"translateY(0)"}],{duration:Gme,easing:Yme})}},[e,t,n])}const kb=new Set,Zme=new Map,Jme=new Map,Nz="octiq.chat.collapsed-agents",Az="octiq.chat.filter";function ege(){const t=ls(Az);return yY(t)?t:"active"}function tge(){try{const t=JSON.parse(ls(Nz)??"[]");return new Set(Array.isArray(t)?t.filter(e=>typeof e=="string"):[])}catch{return new Set}}function nge({orchestration:t=qo,ledgerSnapshot:e,ledgerUnavailable:n=!1,coordinatorChatKeys:s=kb,projects:i,shelved:r,deletedCount:o=0,onShowDeleted:l,conversations:u,currentConversation:h,running:f,busy:m,waiting:g=Zme,completing:x=kb,deleting:b=kb,leaving:_=kb,deleteMs:k=2e3,onPickConversation:N,getPreviewMessages:j,loadPreview:M,onNewChat:A,newLabel:E="New task",allowEmptyCreate:L=!0,onDelete:O,onPin:X,onToggleDone:q,onRename:$,onArchiveWorker:G,branches:B={},chatParents:F=Jme,onResize:z,onCollapse:W,onSearch:H,onSettings:U,onAgents:ee,onProjects:Q,onPullRequests:I,activeView:Y=null,projectsReady:J=!0,chatsReady:P=!0}){const ne=y.useMemo(()=>UN(u,F),[u,F]),[he,le]=y.useState(tge),[oe,ye]=y.useState(ege),[D,Oe]=y.useState(()=>new Set),[ze,Ce]=y.useState(!1),[ve,Ie]=y.useState(null),[ae,$e]=y.useState(null),[He,Wt]=y.useState(!1),[yt,Bt]=y.useState(!1),[Gt,qt]=y.useState(null),Nt=y.useContext(zE),ht=Tf(),Be=y.useRef(void 0),ue=y.useRef({x:0,y:0}),Te=y.useRef(!1),Pe=y.useRef(null),dt=y.useRef(new Set(ne.map(be=>be.id))),pe=gf(J),Qe=gf(P||u.length>0),Ze=[...i,...r],_t=e===void 0?t:e,bt=new Map(Ze.map(be=>[be.id,be])),Xt=new Map(ne.map(be=>[be.id,be])),St=m2(ne,t,!0),Wn=m2(ne,t);y.useEffect(()=>{Oe(be=>{const Et=new Set(be);for(const fn of be){const vs=Xt.get(fn);(!vs||(oe==="active"?!Hc(vs):oe!=="done"||Hc(vs)))&&Et.delete(fn)}return Et.size===be.size?be:Et})},[ne,oe]);const _n=He?St:HC(Wn,oe,h,D),_e=y.useMemo(()=>Eme(ne,t,h),[ne,t,h]),Ut=y.useMemo(()=>H4(HC(_e,oe,h,D),F),[_e,F,h,oe,D]),Lt=y.useMemo(()=>H4(_e,F),[_e,F]),$t=be=>!!be.chat.pinned||be.descendants.some(Et=>Et.pinned),gn=He?[]:Lt.filter($t),Xn=He?St.map(be=>({chat:be,children:[],descendants:[]})):Ut.filter(be=>!$t(be)),qn=y.useRef(null);Qme(qn,`${gn.map(be=>be.chat.id).join(",")}|${Xn.map(be=>be.chat.id).join(",")}`,".task-chat-list > li.chat-row[data-row]");const In=new Set;let ke=h?F.get(h):void 0;for(;ke&&!In.has(ke);)In.add(ke),ke=F.get(ke);const at=JSON.stringify([...In]);y.useEffect(()=>{const be=JSON.parse(at);le(Et=>be.some(fn=>Et.has(fn))?new Set([...Et].filter(fn=>!be.includes(fn))):Et)},[h,at]),y.useEffect(()=>{nn(Nz,JSON.stringify([...he]))},[he]),y.useEffect(()=>{nn(Az,oe)},[oe]),y.useEffect(()=>{dt.current=new Set(ne.map(be=>be.id))},[ne]),y.useEffect(()=>()=>clearTimeout(Be.current),[]);const Je=()=>clearTimeout(Be.current),vn=async(be,Et)=>{if(!(!G||yt)){Bt(!0),qt(null);try{await G(be,Et)}catch(fn){qt(fn instanceof Error?fn.message:String(fn))}finally{Bt(!1)}}},Ve=be=>{Oe(new Set),ye(be)},xt=be=>{const Et=Hc(be),fn=oe==="active"&&!Et||oe==="done"&&Et;Oe(vs=>{const zi=new Set(vs);return fn?zi.add(be.id):zi.delete(be.id),zi}),q(be.id)},Pt=be=>m.has(be)&&!g.has(be),Qn=({chat:be,children:Et,descendants:fn})=>{const vs=!he.has(be.id),zi=fn.filter(tt=>Pt(tt.id)).length,qs=fn.filter(tt=>$w(tt,h)).length,Bn=`chat-agents-${be.id}`,Ne=Xt.get(F.get(be.id)??""),We=b.has(be.id),ut=_.has(be.id),Rt=$w(be,h),zt=Hc(be),Js=bt.get(be.projectId),Dt=y1(be,_t,s,n),Cn=BE(Dt,(tt,on)=>bt.get(tt)?.name??on??"Unknown project"),Ln=Fme(Dt,Ze),sr=Js?.name??"Unknown project",Qt=t.attempts.find(tt=>tt.workerChatKey===`chat:${be.id}`),it=Qt&&t.tasks.find(tt=>tt.id===Qt.taskId),ui=Qt?.archivedAt!=null,Yl=Qt&&!ui?p2(t,Qt):null,ei=i0(t,`chat:${be.id}`),Ua=Cme(ei,ht.held),qr=!He&&ei.runs.length>0,Us=new Set(ei.attempts.map(tt=>tt.workerChatKey)),xs=qr?Et.filter(tt=>!Us.has(`chat:${tt.chat.id}`)):Et,Ur=xs.length>0,Vr=qr&&Us.has(`chat:${h}`),ua=Lme(ei,ht.held),ki=it&&Qt?Ame(it,Qt):Ua?Nme(ei,Ua,ht.held):null,Fi=ki?.text??null,ir=Dt.status==="home"?Qt?.branch||(Ne?"":B[be.projectId]):"",ti=ir?`${sr} | ${ir}`:sr,ys=eh(be.modelId??null),de=Nt(`chat:${be.id}`),Ge=f2(j?.(be.id)??be.messages),mt=He?[]:ht.forRow(be.id),$n=We?"Deleting…":Ge?.text??be.latestResponse??(Pt(be.id)?"Working…":"No response yet");return a.jsxs(rge,{id:be.id,entering:Qe==="settled"&&!dt.current.has(be.id),leaving:ut,children:[a.jsxs("div",{className:["chat",be.id===h?"is-on":"",f.has(be.id)?"is-live":"",Pt(be.id)?"is-busy":"",ua>0?"is-tasks-running":"",We?"is-going":"",ut?"is-leaving":"",be.pinned?"is-pinned":"",ve===be.id?"is-renaming":"",Rt?"is-unread":"",zt?"is-done":"",Vr?"is-worker-on":"",mt.length?"has-pending":"",x.has(be.id)?"is-completing":""].filter(Boolean).join(" "),style:Ln,children:[ve===be.id?a.jsx("form",{className:"chat-rename",onSubmit:tt=>{tt.preventDefault();const on=tt.currentTarget.elements.namedItem("chat-title");on instanceof HTMLInputElement&&on.value.trim()&&$(be.id,on.value),Ie(null)},children:a.jsx("input",{name:"chat-title",className:"chat-rename-input",defaultValue:be.title,"aria-label":"Chat title",maxLength:48,autoFocus:!0,onFocus:tt=>tt.currentTarget.select(),onBlur:tt=>{tt.currentTarget.value.trim()&&$(be.id,tt.currentTarget.value),Ie(null)},onKeyDown:tt=>{tt.key==="Escape"&&(tt.preventDefault(),Ie(null))}})}):a.jsx($me,{chat:be,enabled:!We&&!ut&&!ae,busy:m.has(be.id),getPreviewMessages:j,loadPreview:M,className:"chat-btn",type:"button","aria-label":`${Rt?"Unread, ":""}${be.title}, ${Cn}${ir?`, branch ${ir}`:""}${de?`, with ${de.name}`:ys?`, ${ys.name} ${ys.model}`:""}${Pt(be.id)?", working":f.has(be.id)?", session running":""}${x.has(be.id)?", completing":""}${ua>0?`, ${ua} ${ua===1?"task":"tasks"} running`:""}${mt.length?`, ${t1(mt)}`:""}${zt?", done":""}${be.pinned?", pinned":""}`,disabled:ut,"aria-current":be.id===h?"page":void 0,"aria-description":`${Ne?`Agent chat under ${Ne.title}. `:""}Hover to preview. Hold for chat actions.`,onPointerDown:tt=>{Je(),Te.current=!1,!(tt.pointerType==="mouse"||We||ut||!window.matchMedia("(max-width: 859.98px), (pointer: coarse)").matches)&&(ue.current={x:tt.clientX,y:tt.clientY},Be.current=setTimeout(()=>{Te.current=!0,$e(be.id)},500))},onPointerMove:tt=>{Math.hypot(tt.clientX-ue.current.x,tt.clientY-ue.current.y)>10&&Je()},onPointerUp:Je,onPointerCancel:Je,onContextMenu:tt=>{window.matchMedia("(max-width: 859.98px), (pointer: coarse)").matches&&(tt.preventDefault(),Je(),!We&&!ut&&$e(be.id))},onClick:()=>{if(Te.current){Te.current=!1;return}N(be)},children:a.jsxs("span",{className:"chat-summary",children:[a.jsxs("span",{className:"chat-heading",children:[Rt&&a.jsx("span",{className:"chat-unread-dot","aria-hidden":"true"}),a.jsx("span",{className:"chat-title",children:be.title}),a.jsx("time",{className:"chat-time",dateTime:new Date(be.updatedAt).toISOString(),title:new Date(be.updatedAt).toLocaleString(),children:FE(be.updatedAt)})]}),a.jsx("span",{className:"chat-snippet",children:IE($n)}),a.jsx(So,{inline:!0,when:!!Fi,children:a.jsx("span",{className:"chat-workflow-status","data-tone":ki?.tone??void 0,title:Fi??void 0,children:Fi})}),a.jsxs("span",{className:"chat-meta",children:[Dt.status==="home"?a.jsx("span",{className:"chat-project",children:a.jsx("span",{className:"chat-project-name",title:ti,children:ti})}):a.jsx(Sz,{info:Dt,projects:Ze,taskCount:!Ua}),de?a.jsxs("span",{className:"chat-model chat-persona",title:`${de.name}${ys?` · ${ys.name} ${ys.model}`:""}`,children:[a.jsx(Qs,{name:de.name,avatar:de.avatar,id:de.id??de.name,size:14,removed:de.removed,decorative:!0}),a.jsx("span",{children:de.name})]}):ys&&a.jsxs("span",{className:"chat-model",title:`Active model: ${ys.name} · ${ys.model}`,children:[a.jsx(Hm,{agent:ys.agent,size:10}),a.jsx("span",{children:ys.model})]})]})]})}),a.jsx(So,{when:ve!==be.id&&mt.length>0,className:"chat-pending-slot",children:a.jsx(k1,{className:"chat-pending",actions:mt,subject:be.title})}),a.jsxs("button",{className:"chat-badge",type:"button","aria-pressed":zt,title:zt?"Double-click or double-tap to mark not done":"Double-click or double-tap to mark done","aria-label":`${zt?"Mark not done":"Mark done"}: ${be.title}`,"aria-description":"Double-click or double-tap. With a keyboard, press Enter or Space.",disabled:We||ut,onBlur:()=>{Pe.current=null},onClick:tt=>{tt.stopPropagation();const on=Pe.current;Pe.current=null,tt.detail===0||on?.chatId===be.id&&tt.timeStamp-on.at<=500?xt(be):Pe.current={chatId:be.id,at:tt.timeStamp}},children:[a.jsx(Cz,{info:Dt,projects:Ze}),a.jsxs("svg",{className:"chat-badge-ring",viewBox:"0 0 32 32","aria-hidden":"true",children:[a.jsx("rect",{className:"chat-badge-track",x:"1",y:"1",width:"30",height:"30",rx:"8"}),a.jsx("rect",{className:"chat-badge-snake",x:"1",y:"1",width:"30",height:"30",rx:"8"}),a.jsx("rect",{className:"chat-badge-pellet",x:"1",y:"1",width:"30",height:"30",rx:"8"})]}),a.jsx("span",{className:"chat-badge-tick","aria-hidden":"true",children:a.jsx(sge,{done:zt})}),zt&&a.jsx("span",{className:"chat-badge-check","aria-hidden":"true",children:a.jsx(ige,{})}),be.pinned&&a.jsx("span",{className:"chat-badge-pin","aria-hidden":"true",children:a.jsx(X4,{})})]}),ve!==be.id&&a.jsx(U4,{className:"chat-actions-trigger",label:`Actions for ${be.title}`,open:ae===be.id,onOpenChange:tt=>$e(tt?be.id:null),disabled:ut,icon:We?a.jsx(kz,{ms:k}):void 0,items:[{id:"rename",label:"Rename chat",icon:a.jsx(pge,{}),disabled:We,onSelect:()=>Ie(be.id)},{id:"pin",label:be.pinned?"Unpin chat":"Pin chat",icon:a.jsx(X4,{}),disabled:We,onSelect:()=>X(be.id)},...Qt&&G?[{id:"archive",label:ui?"Restore worker":"Archive worker",icon:a.jsx(G4,{}),disabled:yt||!!Yl||!ui&&m.has(be.id),title:Yl??(ui?"Return this worker to the chat list.":"Hide this worker; its chat and task history are kept."),onSelect:()=>{vn(Qt.id,!ui)}}]:[],...Xd(be.id,F)?[]:[{id:"delete",label:We?"Cancel delete":"Delete chat",icon:a.jsx(Y4,{}),danger:!0,keepOpen:!We,onSelect:()=>O(be.id)}]]}),Ur&&a.jsxs("button",{className:"chat-children-toggle",type:"button","aria-label":`${vs?"Collapse":"Expand"} agent chats for ${be.title}`,"aria-expanded":vs,"aria-controls":Bn,disabled:ut,onClick:()=>le(tt=>{const on=new Set(tt);return on.has(be.id)?on.delete(be.id):on.add(be.id),on}),children:[a.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:a.jsx("path",{d:"m9 5 7 7-7 7"})}),a.jsx("span",{children:`${xs.length} ${xs.length===1?"agent":"agents"}`}),zi>0&&a.jsxs("span",{className:"chat-children-working",children:[zi," working"]}),qs>0&&a.jsxs("span",{className:"chat-children-unread",children:[qs," unread"]})]})]}),Ur&&a.jsx("div",{id:Bn,hidden:!vs,children:vs&&xs.length>0&&a.jsx("ul",{className:"chat-children","aria-label":`Agent chats for ${be.title}`,children:xs.map(Qn)})})]},be.id)},dn=()=>{Wt(!1),Oe(new Set)},gs=[...wY(Wn,oe).map(be=>({id:be.filter,label:be.label,checked:!He&&be.checked,onSelect:()=>{dn(),Ve(be.filter)}})),...St.length||He?[{id:"archived",label:`Archived workers (${St.length})`,icon:a.jsx(G4,{}),checked:He,separator:!0,onSelect:()=>{Wt(!0),Oe(new Set)}}]:[],...o&&l?[{id:"trash",label:`Deleted chats (${o})`,icon:a.jsx(Y4,{}),separator:!(St.length||He),onSelect:l}]:[]],nr=He?"Archived":WC[oe];return a.jsxs("nav",{className:`sidebar task-sidebar${pe==="settled"?"":` ${mh(pe)}`}`,"aria-label":"Chats",children:[a.jsxs("div",{className:"task-chat-scroll",children:[a.jsxs("div",{id:"chats-navigation",className:"sidebar-toolbar",children:[a.jsxs("div",{className:"sidebar-head",children:[a.jsx("img",{className:"sidebar-logo",src:"./icon-192.png",alt:"","aria-hidden":"true"}),a.jsxs("span",{className:"sidebar-title",children:["OctiqFlow ",a.jsxs("span",{className:"sidebar-version",children:["v","0.3.13"]})]}),W&&a.jsx("button",{className:"sidebar-collapse",type:"button",onClick:W,"aria-label":"Hide sidebar",title:"Hide sidebar",children:a.jsx(oge,{})})]}),a.jsxs("ul",{className:"sidebar-places","aria-label":"App",children:[a.jsx("li",{children:a.jsxs("button",{className:"sidebar-place sidebar-new-chat",type:"button",onClick:A,children:[a.jsx(lge,{}),a.jsx("span",{children:E})]})}),H&&a.jsx("li",{children:a.jsxs("button",{className:"sidebar-place",type:"button",onClick:H,"aria-current":Y==="search"?"page":void 0,children:[a.jsx(age,{}),a.jsx("span",{children:"Search chats"})]})}),Q&&a.jsx("li",{children:a.jsxs("button",{className:"sidebar-place",type:"button",onClick:Q,"aria-current":Y==="projects"?"page":void 0,children:[a.jsx(fge,{}),a.jsx("span",{children:"Projects"})]})}),ee&&a.jsx("li",{children:a.jsxs("button",{className:"sidebar-place",type:"button",onClick:ee,"aria-current":Y==="agents"?"page":void 0,children:[a.jsx(hge,{}),a.jsx("span",{children:"Agents"})]})}),I&&a.jsx("li",{children:a.jsxs("button",{className:"sidebar-place",type:"button",onClick:I,"aria-current":Y==="pulls"?"page":void 0,children:[a.jsx(dge,{}),a.jsx("span",{children:"Pull requests"})]})}),U&&a.jsx("li",{children:a.jsxs("button",{className:"sidebar-place",type:"button",onClick:U,"aria-current":Y==="settings"?"page":void 0,children:[a.jsx(uge,{}),a.jsx("span",{children:"Settings"})]})})]})]}),Gt&&a.jsxs("div",{className:"sidebar-archive-error",role:"alert",children:[Gt,a.jsx("button",{type:"button",onClick:()=>qt(null),children:"Dismiss"})]}),Qe==="held"?null:ne.length>0||He?a.jsxs("div",{ref:qn,className:`task-chat-content${Qe==="entering"?" enter-fade":""}`,children:[gn.length>0&&a.jsxs("section",{className:"sidebar-chat-section","aria-labelledby":"sidebar-pinned-heading",children:[a.jsx("h2",{id:"sidebar-pinned-heading",className:"sidebar-section-heading",children:"Pinned"}),a.jsx("ul",{className:"chat-list task-chat-list",children:gn.map(Qn)})]}),a.jsxs("section",{className:"sidebar-chat-section","aria-labelledby":"sidebar-recent-heading",children:[a.jsxs("div",{className:"sidebar-section-head",children:[a.jsx("h2",{id:"sidebar-recent-heading",className:"sidebar-section-heading",children:He?"Archived workers":"Recent"}),a.jsx(U4,{className:"sidebar-filter-trigger",label:`Show chats: ${nr}`,open:ze,onOpenChange:Ce,icon:a.jsxs(a.Fragment,{children:[a.jsx("span",{children:nr}),a.jsx(cge,{})]}),items:gs})]}),Xn.length>0?a.jsx("ul",{className:"chat-list task-chat-list",children:Xn.map(Qn)}):Zs()]})]}):a.jsxs("div",{className:"sidebar-empty",children:[a.jsx("span",{children:"No chats yet"}),L&&a.jsx("button",{type:"button",onClick:A,children:"Start your first chat"})]})]}),z&&a.jsx("span",{className:"nav-resizer",onPointerDown:z,role:"separator","aria-orientation":"vertical","aria-label":"Resize the chat column"})]});function Zs(){return He?a.jsxs("div",{className:"sidebar-empty",role:"status",children:[a.jsx("span",{children:"No archived workers."}),a.jsx("button",{type:"button",onClick:dn,children:"Show active chats"})]}):oe!=="active"?a.jsxs("div",{className:"sidebar-empty",role:"status",children:[a.jsx("span",{children:oe==="done"?"No chats are ticked off.":"Every chat is pinned."}),a.jsx("button",{type:"button",onClick:()=>Ve("active"),children:"Show active chats"})]}):Wn.some(Et=>Hc(Et)&&!Et.pinned)&&!_n.some(Et=>!Et.pinned)?a.jsxs("div",{className:"sidebar-empty",role:"status",children:[a.jsx("span",{children:"Every chat is ticked off."}),a.jsx("button",{type:"button",onClick:()=>Ve("done"),children:"Show done chats"})]}):a.jsx("div",{className:"sidebar-empty",role:"status",children:a.jsx("span",{children:gn.length>0?"Every active chat is pinned.":"No active chats."})})}}function sge({done:t}){return a.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:[a.jsx("circle",{cx:"12",cy:"12",r:"9"}),t&&a.jsx("path",{d:"m8 12 2.8 2.8L16 9.6"})]})}function ige(){return a.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:a.jsx("path",{d:"m5 12.5 4.5 4.5L19 7"})})}function FE(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 rge({id:t,entering:e,leaving:n,children:s}){const[i,r]=y.useState(()=>e&&!(typeof window<"u"&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches));return y.useEffect(()=>{if(!i)return;const o=requestAnimationFrame(()=>r(!1));return()=>cancelAnimationFrame(o)},[i]),a.jsx("li",{"data-row":t,className:["chat-row",i?"is-entering":"",n?"is-leaving":""].filter(Boolean).join(" "),children:a.jsx("div",{className:"chat-row-content",children:s})})}function age(){return a.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[a.jsx("circle",{cx:"11",cy:"11",r:"7"}),a.jsx("path",{d:"m20 20-4-4"})]})}function oge(){return a.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:[a.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),a.jsx("path",{d:"M9 4v16M15 10l-2 2 2 2"})]})}function lge(){return a.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:[a.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"}),a.jsx("path",{d:"m12 12 7.5-7.5a2.12 2.12 0 0 1 3 3L15 15l-4 1 1-4Z"})]})}function G4(){return a.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:[a.jsx("path",{d:"M4 7h16"}),a.jsx("path",{d:"M6 7v12h12V7"}),a.jsx("path",{d:"M3 4h18v3H3z"}),a.jsx("path",{d:"M10 11h4"})]})}function Y4(){return a.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:[a.jsx("path",{d:"M3 6h18"}),a.jsx("path",{d:"M8 6V4h8v2"}),a.jsx("path",{d:"m6 6 1 14h10l1-14"}),a.jsx("path",{d:"M10 10v6M14 10v6"})]})}function X4(){return a.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:[a.jsx("path",{d:"M12 17v5"}),a.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 cge(){return a.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:a.jsx("path",{d:"m6 9 6 6 6-6"})})}function uge(){return a.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:[a.jsx("circle",{cx:"12",cy:"12",r:"3"}),a.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 hge(){return a.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:[a.jsx("rect",{x:"9",y:"3",width:"6",height:"5",rx:"1"}),a.jsx("rect",{x:"3",y:"16",width:"6",height:"5",rx:"1"}),a.jsx("rect",{x:"15",y:"16",width:"6",height:"5",rx:"1"}),a.jsx("path",{d:"M12 8v4M6 16v-2h12v2"})]})}function dge(){return a.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:[a.jsx("circle",{cx:"6",cy:"5",r:"2"}),a.jsx("circle",{cx:"18",cy:"7",r:"2"}),a.jsx("circle",{cx:"6",cy:"19",r:"2"}),a.jsx("path",{d:"M6 7v10M8 5h4a6 6 0 0 1 6 6v-2"})]})}function fge(){return a.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:a.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 pge(){return a.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:[a.jsx("path",{d:"M12 20h9"}),a.jsx("path",{d:"M16.5 3.5a2.1 2.1 0 0 1 3 3L8 18l-4 1 1-4Z"})]})}const Ez=y.createContext(null);function a0(t){return y.useContext(Ez)?.[t]??null}function Sf({title:t,back:e,actions:n,root:s=!1,className:i}){const r=a0("heading"),o=a0("actions"),l=a.jsxs(a.Fragment,{children:[e&&a.jsxs("button",{type:"button",className:`workspace-back${s?" is-root":""}`,onClick:e.onClick,"aria-label":e.ariaLabel??`Back to ${e.label}`,title:e.ariaLabel??`Back to ${e.label}`,children:[a.jsx(mge,{}),a.jsx("span",{children:e.label})]}),a.jsx("div",{className:"workspace-heading",children:t})]}),u=n?a.jsx("div",{className:"workspace-actions",children:n}):null;return r?a.jsxs(a.Fragment,{children:[Eo.createPortal(l,r),n&&(o?Eo.createPortal(u,o):a.jsx("div",{className:"workspace-actions is-inline",children:n}))]}):a.jsxs("header",{className:`workspace-header${i?` ${i}`:""}`,children:[l,u]})}function mge(){return a.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:a.jsx("path",{d:"m15 18-6-6 6-6"})})}function gge({projects:t,shelved:e,conversations:n,selectedProjectId:s,busy:i,chatParents:r,ledgerSnapshot:o=qo,coordinatorChatKeys:l=new Set,allowNewTask:u=!0,onSelectProject:h,onOpenChat:f,onNewTask:m,onNewProject:g,onProjectSettings:x,onClose:b,onShowShelved:_,onRestoreProject:k}){const N=Tf(),j=y.useRef(null),M=y.useRef(!0),[A,E]=y.useState(!1),[L,O]=y.useState(null);y.useEffect(()=>{if(M.current){M.current=!1;return}j.current?.focus({preventScroll:!0}),O(null)},[s]);const X=UN(n,r),q=[...t,...e],$=s===null?null:q.find(F=>F.id===s)??null;if(s!==null){const F=$?Kpe(X,$.id,o,l??new Set):[],z=!!$&&e.some(W=>W.id===$.id);return a.jsxs("section",{className:"projects-page","aria-label":$?`${$.name} tasks`:"Project",children:[a.jsx(Sf,{back:{label:"Projects",ariaLabel:"Back to projects",onClick:()=>h(null)},title:a.jsxs(a.Fragment,{children:[$&&a.jsx(Mh,{project:$,size:"small"}),a.jsx("h1",{ref:j,tabIndex:-1,children:$?.name??"Project unavailable"})]}),actions:$&&a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",className:"projects-page-secondary",onClick:()=>x($.id),children:"Project settings"}),z&&k&&a.jsx("button",{type:"button",className:"projects-page-primary",disabled:A,onClick:async()=>{E(!0),O(null);try{await k($.id)}catch(W){O(W instanceof Error?W.message:String(W))}finally{E(!1)}},children:a.jsx("span",{children:A?"Restoring…":"Restore project"})}),u&&!z&&a.jsxs("button",{type:"button",className:"projects-page-primary",onClick:()=>m($.id),children:[a.jsx(Q4,{}),a.jsx("span",{children:"New task"})]})]})}),L&&a.jsx("p",{className:"projects-page-error",role:"alert",children:L}),a.jsxs("div",{className:"projects-page-body",children:[$&&($.primary_path||z)&&a.jsxs("p",{className:"projects-page-meta",title:$.primary_path,children:[$.primary_path??"Shelved",$.primary_path&&z?" · Shelved":""]}),$?F.length===0?a.jsxs("div",{className:"projects-page-empty",role:"status",children:[a.jsxs("p",{children:["No tasks in ",$.name," yet."]}),u&&!z&&a.jsx("button",{type:"button",onClick:()=>m($.id),children:"Start a task"})]}):a.jsxs(a.Fragment,{children:[a.jsx("h2",{className:"projects-page-count",children:F.length===1?"1 task":`${F.length} tasks`}),a.jsx("ul",{className:"projects-task-list","aria-label":`Tasks in ${$.name}`,children:F.map(W=>{const H=i.has(W.id),U=Hc(W),ee=N.forRow(W.id),Q=[H&&"Working",U&&"Done",W.pinned&&"Pinned"].filter(I=>!!I);return a.jsxs("li",{children:[a.jsxs("button",{type:"button",className:"projects-task",onClick:()=>f(W),"aria-label":[W.title,...ee.length?[t1(ee)]:[],...Q].join(", "),children:[a.jsxs("span",{className:"projects-task-line",children:[a.jsx("span",{className:"projects-task-title",children:W.title}),a.jsx("time",{dateTime:new Date(W.updatedAt).toISOString(),children:FE(W.updatedAt)})]}),a.jsxs("span",{className:"projects-task-line",children:[a.jsx("span",{className:"projects-task-snippet",children:IE(W.latestResponse??(H?"Working…":"No response yet"))}),Q.length>0&&a.jsx("span",{className:"projects-task-states","aria-hidden":"true",children:Q.map(I=>a.jsx("span",{className:`is-${I.toLowerCase()}`,children:I},I))})]})]}),a.jsx(k1,{className:"projects-task-pending",actions:ee,subject:W.title})]},W.id)})})]}):a.jsxs("div",{className:"projects-page-empty",role:"status",children:[a.jsx("p",{children:"This project was removed or is no longer in this profile."}),a.jsx("button",{type:"button",onClick:()=>h(null),children:"Show all projects"})]})]})]})}const G=Gpe(X,o,l??new Set),B=F=>{const z=G.get(F.id)??0;return a.jsx("li",{children:a.jsxs("button",{type:"button",className:"projects-row",onClick:()=>h(F.id),"aria-label":`${F.name}, ${z===1?"1 task":`${z} tasks`}`,children:[a.jsx(Mh,{project:F,size:"medium"}),a.jsxs("span",{className:"projects-row-text",children:[a.jsx("span",{className:"projects-row-name",children:F.name}),F.primary_path&&a.jsx("span",{className:"projects-row-path",children:F.primary_path})]}),a.jsx("span",{className:"projects-row-count","aria-hidden":"true",children:z}),a.jsx(vge,{})]})},F.id)};return a.jsxs("section",{className:"projects-page","aria-label":"Projects",children:[a.jsx(Sf,{root:!0,back:{label:"Chat",ariaLabel:"Back to chat",onClick:b},title:a.jsx("h1",{ref:j,tabIndex:-1,children:"Projects"}),actions:a.jsxs("button",{type:"button",className:"projects-page-primary",onClick:g,children:[a.jsx(Q4,{}),a.jsx("span",{children:"New project"})]})}),a.jsx("div",{className:"projects-page-body",children:q.length===0?a.jsxs("div",{className:"projects-page-empty",role:"status",children:[a.jsx("p",{children:"No projects yet."}),a.jsx("button",{type:"button",onClick:g,children:"Add a project"})]}):a.jsxs(a.Fragment,{children:[t.length>0&&a.jsx("h2",{className:"projects-page-count",children:t.length===1?"1 project":`${t.length} projects`}),t.length>0&&a.jsx("ul",{className:"projects-list","aria-label":"Projects",children:t.map(B)}),e.length>0&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"projects-page-subhead",children:[a.jsx("h2",{className:"projects-page-count",children:"Shelved"}),_&&a.jsx("button",{type:"button",className:"projects-page-link",onClick:_,children:"Restore shelved projects"})]}),a.jsx("ul",{className:"projects-list","aria-label":"Shelved projects",children:e.map(B)})]})]})})]})}function vge(){return a.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:a.jsx("path",{d:"m9 18 6-6-6-6"})})}function Q4(){return a.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:a.jsx("path",{d:"M12 5v14M5 12h14"})})}const Mz=t=>t.replace(/\s+/g," ").trim(),Z4=60,J4=t=>[...t].length;function xge(t){const e=/^\d{4}-\d{2}-\d{2}T\S+\s+(?:ERROR|WARN|WARNING)\s+(.+)$/is.exec(t.trim());return e?Mz(e[1]):null}function yge(t){const e=Mz(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=xge(t);if(n){const l=n.replace(/^[\w.-]+(?:::[\w.-]+)*:\s*/,"");return{key:`provider:${l.toLocaleLowerCase()}`,title:"The agent reported a background issue",detail:l,technical:t.trim()}}const s=/^(\d+) background task\(s\) interrupted when the provider process ended: (.+?)\. Retained output/i.exec(e);if(s){const l=Number(s[1]);return{key:`background-interrupted:${s[2].toLocaleLowerCase()}`,title:`${l} background ${l===1?"task":"tasks"} interrupted`,detail:e}}const i=pK(e);if(i)return{key:`jobs-interrupted:${i.labels.toLocaleLowerCase()}`,title:`${i.count} ${i.count===1?"job":"jobs"} interrupted`,detail:e};const r=`message:${e.toLocaleLowerCase()}`;if(J4(e)<=Z4)return{key:r,title:e};const o=/^([^:]+): /.exec(e)?.[1]??"";return{key:r,title:o&&J4(o)<=Z4?o:"Notice",detail:e}}function bge(t,e){return e<=0||t.length===0?"":e===1?t[0].title:`${e} notices`}function wge(t){const e=new Map;for(const n of t){const s=yge(n),i=e.get(s.key);i?e.set(s.key,{...i,detail:s.detail??i.detail,technical:s.technical??i.technical,count:i.count+1}):e.set(s.key,{...s,count:1})}return[...e.values()]}function _ge(){return a.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.5","aria-hidden":"true",children:[a.jsx("circle",{cx:"10",cy:"10",r:"7.25"}),a.jsx("path",{d:"M10 8.6v4.2",strokeLinecap:"round"}),a.jsx("circle",{cx:"10",cy:"5.9",r:".65",fill:"currentColor",stroke:"none"})]})}function kge({notices:t,onClear:e}){const[n,s]=y.useState(!1),i=y.useId(),r=y.useMemo(()=>wge(t),[t]);return r.length===0?null:a.jsxs("section",{className:`chat-notices ${n?"is-open":""}`,"aria-label":"Background notices",children:[a.jsxs("div",{className:"status-row",children:[a.jsxs("button",{className:"status-row-main chat-notices-toggle",type:"button","aria-expanded":n,"aria-controls":i,onClick:()=>s(o=>!o),children:[a.jsx("span",{className:"status-row-icon",children:a.jsx(_ge,{})}),a.jsx("span",{className:"status-row-text chat-notices-title",children:bge(r,t.length)}),a.jsx(RE,{})]}),a.jsx(DE,{label:"Clear all background notices",onClick:e})]}),n&&a.jsx("div",{className:"status-row-panel chat-notices-panel",id:i,children:r.map(o=>a.jsxs("article",{className:"chat-notice-item",children:[(r.length>1||o.count>1||!o.detail)&&a.jsxs("div",{className:"chat-notice-head",children:[a.jsx("span",{children:o.title}),o.count>1&&a.jsxs("span",{className:"chat-notice-count",children:[o.count," times"]})]}),o.detail&&a.jsx("p",{children:o.detail}),o.technical&&a.jsxs("details",{className:"chat-notice-technical",children:[a.jsx("summary",{children:"Technical details"}),a.jsx("pre",{children:o.technical})]})]},o.key))})]})}function Sge({chatId:t,connected:e,projectPath:n}){const[s,i]=y.useState(),r=y.useCallback(o=>{!t||!e||te.invoke("chat_task",{chatId:t,refresh:o}).then(i).catch(()=>{})},[t,e]);return y.useEffect(()=>r(!1),[r]),y.useEffect(()=>{if(!t||!e)return;const o=te.on("chat-task",u=>{u?.chatId===t&&i(u)}),l=te.on("chat-event",u=>{u?.key===`chat:${t}`&&u.event?.type==="octiq_chat_recovered"&&r(!0)});return()=>{o(),l()}},[t,e,r]),a.jsx(Cge,{workspace:s?.chatId===t?s.workspace:void 0,projectPath:n})}function Cge({workspace:t,projectPath:e,open:n=!1}){const[s,i]=y.useState(n),r=y.useId(),o=ife(t,e);return o?a.jsxs("div",{className:"chat-folder-gone",role:"status",children:[a.jsx("div",{className:"status-row",children:a.jsxs("button",{type:"button",className:"status-row-main","aria-expanded":s,"aria-controls":r,onClick:()=>i(l=>!l),children:[a.jsx("span",{className:"status-row-icon","data-tone":"warn","aria-hidden":"true",children:a.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[a.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"}),a.jsx("path",{d:"M9.5 11.5l5 5M14.5 11.5l-5 5"})]})}),a.jsx("span",{className:"status-row-label",children:o.label}),a.jsx("span",{className:"status-row-text",children:o.next}),a.jsx(RE,{})]})}),s&&a.jsxs("div",{className:"status-row-panel",id:r,children:[a.jsx("p",{className:"chat-folder-gone-path",children:o.path}),o.detail.map(l=>a.jsx("p",{children:l},l))]})]}):null}let eg=r6,eD=!1;const v2=new Set;let x2=new Set;function Lz(t){if(t!==eg){eg=t;for(const e of v2)e()}}function jge(t){return String(t?.message??t).includes("not available on this backend")}function Tz(t){const e=eg.rev;te.invoke("chat_jobs",t?{chatKey:t}:{}).then(n=>Lz(iK(eg,{jobs:n?.jobs,asked:e,chatKey:t},Date.now())),n=>{jge(n)||console.warn("chat_jobs failed",n)})}function y2(){eD||(eD=!0,te.on("chat-job",t=>Lz(sK(eg,t,Date.now()))),te.onState(t=>{t==="open"&&(x2=new Set,Tz())}))}function Nge(t){y2(),!x2.has(t)&&(x2.add(t),Tz(t))}const lw={snapshot(){return y2(),eg},subscribe(t){return y2(),v2.add(t),()=>v2.delete(t)}};function OS(t){const[e,n]=y.useState(()=>typeof window>"u"?!1:window.matchMedia(t).matches);return y.useEffect(()=>{const s=window.matchMedia(t);n(s.matches);const i=r=>n(r.matches);return s.addEventListener("change",i),()=>s.removeEventListener("change",i)},[t]),e}const Age="(min-width: 701px)",tD="(max-width: 859.98px)",Ege="(min-width: 1181px)",Rz=18,Mge=10,Lge=24,nD=1.5,Tge=350,Rge=.4,sD=.5,Dge=72;function Oge(t,e){return!e.open&&t.x>Rz?null:{phase:"watching",opening:!e.open,from:t,at:t,width:e.width}}function Ige(t,e){if(t.phase==="dropped")return t;const n={...t,at:e};if(t.phase==="swiping")return n;const s=e.x-t.from.x,i=e.y-t.from.y;if(e.t-t.from.t>Tge)return{...n,phase:"dropped"};const r=Math.abs(s),o=Math.abs(i);return o>Mge&&r<o*nD?{...n,phase:"dropped"}:r<Lge?n:(t.opening?s<0:s>0)?{...n,phase:"dropped"}:r<o*nD?{...n,phase:"dropped"}:{...n,phase:"swiping"}}function Dz(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 Bge(t){if(t.phase!=="swiping")return null;const e=t.at.x-t.from.x,n=t.at.t-t.from.t,s=n>0?e/n:0;if(Math.abs(e)>=Dge){if(s>sD)return"open";if(s<-sD)return"close"}return Dz(t)>Rge?"open":"close"}function $ge({enabled:t,open:e,onChange:n}){const s=y.useRef(e);s.current=e;const i=y.useRef(n);return i.current=n,y.useCallback(r=>{if(!(!r||!t))return Pge(r,()=>s.current,o=>i.current(o))},[t])}function Pge(t,e,n){let s=null,i=0;const r=()=>{s?.phase==="swiping"&&(i=Date.now()+700),s=null,t.removeAttribute("data-drawer-swiping"),t.style.removeProperty("--swipe-p")},o=m=>{if(r(),m.touches.length!==1)return;i=0;const g=m.touches[0],x=e();if(x){const _=window.getSelection();if(_&&_.rangeCount>0&&!_.isCollapsed)return}const b=t.querySelector(".sidebar")?.offsetWidth||t.clientWidth;s=Oge({x:g.clientX,y:g.clientY,t:m.timeStamp},{open:x,width:b}),s&&g.clientX<=Rz&&m.cancelable&&m.preventDefault()},l=m=>{if(!s)return;if(m.touches.length!==1||!m.cancelable)return r();const g=m.touches[0];if(s=Ige(s,{x:g.clientX,y:g.clientY,t:m.timeStamp}),s.phase==="dropped")return r();s.phase==="swiping"&&(m.preventDefault(),t.setAttribute("data-drawer-swiping",""),t.style.setProperty("--swipe-p",String(Dz(s))))},u=m=>{const g=s&&Bge(s);g&&m.cancelable&&m.preventDefault(),r(),g&&g==="open"!==e()&&n(g==="open")},h=m=>{s?.phase!=="swiping"&&Date.now()>=i||(m.preventDefault(),m.stopImmediatePropagation())},f=m=>{s?.phase!=="swiping"&&(m.key==="Enter"||m.key===" ")&&(i=0)};return t.addEventListener("touchstart",o,{passive:!1}),t.addEventListener("touchmove",l,{passive:!1}),t.addEventListener("touchend",u,{passive:!1}),t.addEventListener("touchcancel",r,{passive:!0}),t.addEventListener("click",h,!0),t.addEventListener("dblclick",h,!0),t.addEventListener("keydown",f,!0),()=>{t.removeEventListener("touchstart",o),t.removeEventListener("touchmove",l),t.removeEventListener("touchend",u),t.removeEventListener("touchcancel",r),t.removeEventListener("click",h,!0),t.removeEventListener("dblclick",h,!0),t.removeEventListener("keydown",f,!0),r()}}let oh,cw=0;function b2(t,e){const n=++cw;oh?.skipTransition(),oh=void 0;const s=document.documentElement;delete s.dataset.zenTransition;let i=!1;const r=()=>{n!==cw||i||(i=!0,Eo.flushSync(e))},o=()=>{n===cw&&(oh=void 0,delete s.dataset.zenTransition)},l=window.matchMedia("(prefers-reduced-motion: reduce)").matches;if(l||!document.startViewTransition){r(),l||document.querySelector(".app .main")?.animate?.([{opacity:.75},{opacity:1}],{duration:320,easing:"ease-out"});return}s.dataset.zenTransition=t;try{oh=document.startViewTransition(r),oh.ready.catch(()=>{}),oh.finished.then(o,()=>{r(),o()})}catch{r(),o()}}function iD(){cw++,oh?.skipTransition(),oh=void 0,delete document.documentElement.dataset.zenTransition}const zge={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 Fge(t){return t==="pi"?"codex":t==="antigravity"?"luna":t.startsWith("pi-")?t.slice(3):t}const Hge={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"}},Wge={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 HE({robot:t="sonnet",size:e=28,alert:n=!1,mood:s="idle",asleep:i=!1}){const r=Fge(t),o=Hge[r],l=`mascot-iris-${y.useId()}`,u=i?"asleep":s,h=u==="think",f=u==="work",m=f?8:r==="haiku"||r==="luna"||r==="fable"?12:11;return a.jsxs("span",{className:`mascot${n?" is-alert":""}${i?" is-asleep":""}`,"data-robot":t,"data-mood":s,"data-expression":u,style:{width:e,height:e,"--mascot-size":`${e}px`,"--robot-accent":zge[r].color},"aria-hidden":"true",children:[a.jsxs("svg",{className:"mascot-avatar",viewBox:"0 0 100 100",width:e,height:e,fill:"none",focusable:"false",children:[a.jsx("defs",{children:a.jsxs("linearGradient",{id:l,x1:"0",y1:"0",x2:"0",y2:"1",children:[a.jsx("stop",{className:"mascot-iris-dark",offset:"0"}),a.jsx("stop",{className:"mascot-iris-color",offset:".65"}),a.jsx("stop",{className:"mascot-iris-light",offset:"1"})]})}),a.jsxs("g",{className:"mascot-avatar-character",children:[a.jsx("path",{className:"mascot-fur mascot-ears",d:o.ears}),a.jsx("path",{className:"mascot-ear-inner",d:o.inner}),a.jsx("path",{className:"mascot-collar",d:"M 33 81 Q 50 77 67 81 L 74 94 Q 51 101 26 94 Z"}),a.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"}),a.jsx("path",{className:"mascot-collar-gem",d:"M 50 87 L 54 92 L 50 97 L 46 92 Z"}),a.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"}),a.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"}),a.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"}),a.jsx("path",{className:"mascot-fur mascot-fringe",d:o.fringe}),a.jsx("path",{className:"mascot-hair-shine",d:o.shine}),a.jsx("g",{className:`mascot-avatar-mark${r==="claude"||r==="codex"?" mascot-mark-lines":""}`,children:a.jsx("path",{d:o.mark})}),a.jsxs("g",{className:"mascot-avatar-face",strokeLinecap:"round",strokeLinejoin:"round",children:[a.jsxs("g",{className:"mascot-avatar-cheeks",children:[a.jsx("ellipse",{cx:"23",cy:"71",rx:"7",ry:"3.5"}),a.jsx("ellipse",{cx:"77",cy:"71",rx:"7",ry:"3.5"}),a.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"})]}),a.jsx("g",{className:"mascot-avatar-eyes",children:i?a.jsxs("g",{className:"mascot-sleep-eyes",children:[a.jsx("path",{d:"M 25 59 Q 33 67 41 59 M 59 59 Q 67 67 75 59"}),a.jsx("path",{className:"mascot-lower-lash",d:"M 26 61 L 24 63 M 74 61 L 76 63"})]}):[33,67].map((g,x)=>{const b=h?57+x*2:59,_=g+(h?2:0);return a.jsxs("g",{children:[a.jsx("ellipse",{className:"mascot-eye-white",cx:g,cy:b,rx:"10",ry:m+1}),a.jsx("ellipse",{className:"mascot-avatar-eye",cx:_,cy:b+1,rx:"7.7",ry:m,fill:`url(#${l})`}),a.jsx("ellipse",{className:"mascot-pupil",cx:_,cy:b,rx:"3.4",ry:m*.66}),a.jsx("path",{className:"mascot-iris-glow",d:`M ${_-4.5} ${b+m-3} Q ${_} ${b+m} ${_+4.5} ${b+m-3}`}),a.jsx("ellipse",{className:"mascot-eye-glint",cx:_-2.7,cy:b-m*.43,rx:"3",ry:"3.4"}),a.jsx("circle",{className:"mascot-eye-glint mascot-eye-glint-small",cx:_+3.5,cy:b+4,r:"1.4"}),a.jsx("path",{className:"mascot-upper-lash",d:`M ${g-10} ${b-3} Q ${g-8} ${b-m-3} ${g+1} ${b-m-1} Q ${g+7} ${b-m} ${g+10} ${b-4}`}),a.jsx("path",{className:"mascot-lower-lash",d:`M ${g-6} ${b+m} Q ${g} ${b+m+2} ${g+5} ${b+m}`})]},g)})}),(h||f)&&a.jsxs("g",{className:"mascot-eyebrows",children:[a.jsx("path",{d:h?"M 26 43 Q 32 39 39 42":"M 26 45 L 39 48"}),a.jsx("path",{d:h?"M 61 45 Q 67 42 74 44":"M 61 48 L 74 45"})]}),a.jsx("path",{className:"mascot-nose",d:"M 48.5 71 Q 50 70 51.5 71 L 50 72 Z"}),a.jsx("path",{className:"mascot-avatar-mouth",d:Wge[u]}),u==="idle"&&a.jsx("path",{className:"mascot-tongue",d:"M 47 81 Q 50 78 53 81 Q 50 84 47 81 Z"})]})]})]}),t.startsWith("pi")&&a.jsx("span",{className:"mascot-provider-badge","data-provider-mark":"pi",children:"P"}),t==="antigravity"&&a.jsx("span",{className:"mascot-provider-badge","data-provider-mark":"antigravity",children:"A"}),i&&a.jsx("span",{className:"mascot-z",children:"z"}),n&&a.jsx("span",{className:"mascot-task-dot"})]})}function Oz(t){if(/^[A-Za-z]:[\\/]/.test(t))return t.slice(0,3);const e=/^(?:\\\\|\/\/)[^\\/]+[\\/][^\\/]+/.exec(t);return e?e[0]:t.startsWith("/")?"/":null}function rD(t){return Oz(t)!==null}function aD(t){const e=Oz(t);if(!e)return null;const n=t.replace(e==="/"?/\/+$/:/[\\/]+$/,"");if(n.length<=e.length)return null;const s=e==="/"?n.lastIndexOf("/"):Math.max(n.lastIndexOf("/"),n.lastIndexOf("\\"));return s<e.length?e:n.slice(0,s)}function qge(t,e){return t.filter(n=>n.is_dir?!n.is_hidden&&!n.name.startsWith("."):e)}function WE({start:t,title:e,onPick:n,onClose:s,files:i=!1}){const[r,o]=y.useState(t),[l,u]=y.useState(t),[h,f]=y.useState([]),[m,g]=y.useState(null),[x,b]=y.useState(!0),_=y.useCallback(N=>{o(N),u(N)},[]);y.useEffect(()=>{let N=!0;return b(!0),te.invoke("list_dir",{path:r}).then(j=>{if(!N)return;f(qge(j??[],i)),g(null);const M=(j??[])[0];if(M&&!rD(r)){const A=aD(M.path);A&&(o(A),u(A))}}).catch(j=>{N&&(f([]),g(j.message))}).finally(()=>N&&b(!1)),()=>{N=!1}},[r,i]),y.useEffect(()=>{const N=j=>j.key==="Escape"&&s();return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[s]);const k=aD(r);return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"panel-scrim",onClick:s}),a.jsxs("div",{className:"fp-picker",role:"dialog","aria-label":e,children:[a.jsxs("header",{className:"fp-picker-head",children:[a.jsx("span",{className:"fp-picker-title",children:e}),a.jsx("button",{className:"panel-close",type:"button",onClick:s,"aria-label":"Close",children:"✕"})]}),a.jsxs("form",{className:"fp-picker-path",onSubmit:N=>{N.preventDefault(),_(l.trim())},children:[a.jsx("input",{className:"fp-picker-input",value:l,spellCheck:!1,autoCapitalize:"off",autoCorrect:"off",placeholder:"Folder path",onChange:N=>u(N.target.value)}),a.jsx("button",{className:"panel-btn",type:"submit",children:"Go"})]}),m&&a.jsx("div",{className:"panel-error",children:m}),a.jsxs("div",{className:"fp-picker-body",children:[k&&a.jsxs("button",{className:"fp-picker-row is-up",type:"button",onClick:()=>_(k),children:[a.jsx(oD,{}),a.jsx("span",{className:"fp-picker-name",children:".."})]}),x&&h.length===0&&!m&&a.jsx("div",{className:"dots","aria-label":"loading"}),!x&&h.length===0&&!m&&a.jsx("div",{className:"fp-picker-empty",children:i?"No files or visible folders in here.":"No visible folders in here."}),h.map(N=>a.jsxs("button",{className:`fp-picker-row ${N.is_dir?"":"is-file"}`,type:"button",onClick:()=>N.is_dir?_(N.path):n(N.path),children:[N.is_dir?a.jsx(oD,{}):a.jsx(Uge,{}),a.jsx("span",{className:"fp-picker-name",children:N.name})]},N.path))]}),a.jsxs("footer",{className:"fp-picker-foot",children:[a.jsx("div",{className:"fp-picker-here",title:r,children:a.jsx("bdi",{children:r})}),!i&&a.jsx("button",{className:"panel-btn is-primary",type:"button",disabled:!rD(r),onClick:()=>n(r),children:"Use this folder"})]})]})]})}function oD(){return a.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:a.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 Uge(){return a.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:[a.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z"}),a.jsx("path",{d:"M14 2v6h6"})]})}function Vge({onReference:t,onUpload:e}){return a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",role:"menuitem",className:"picker-item",onClick:t,children:[a.jsx("span",{className:"picker-name",children:"Reference a file"}),a.jsx("span",{className:"picker-model",children:"on the machine running the agents"})]}),a.jsxs("button",{type:"button",role:"menuitem",className:"picker-item",onClick:e,children:[a.jsx("span",{className:"picker-name",children:"Upload a file"}),a.jsx("span",{className:"picker-model",children:"from this device — up to 12 MB per file"})]})]})}function Pc(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}const Kge={isRepo:!1,current:"",branches:[],isWorktree:!1};function Gge({projects:t,projectId:e,onProject:n,branch:s,branches:i=Kge,onBranch:r,newWorktree:o,onNewWorktree:l,useSandbox:u=!1,onUseSandbox:h}){const f=t.filter(x=>Pc(x.name)!=="general"),m=s&&!i.branches.includes(s)?[s,...i.branches]:i.branches,g=i.loading?"Finding branches…":i.error?"Branches unavailable":i.isRepo?s||i.current||"No branch":"No Git repository";return a.jsxs("div",{className:"work-location enter-gated","aria-label":"Work location",children:[a.jsxs("label",{className:"work-location-field",title:"Project",children:[a.jsx(Yge,{}),a.jsx("span",{className:"sr-only",children:"Project"}),a.jsxs("select",{"aria-label":"Project",value:e??"",onChange:x=>n(x.target.value||null),children:[a.jsx("option",{value:"",children:"General"}),f.map(x=>a.jsx("option",{value:x.id,children:x.name},x.id))]})]}),a.jsx("span",{className:"work-location-divider","aria-hidden":"true"}),a.jsxs("label",{className:`work-location-field is-branch ${i.isRepo?"":"is-muted"}`,title:o?"Base branch":"Branch",children:[a.jsx(Xge,{}),a.jsx("span",{className:"sr-only",children:o?"Base branch":"Branch"}),a.jsxs("select",{"aria-label":o?"Base branch":"Branch",value:s,disabled:i.loading||!i.isRepo,onChange:x=>r(x.target.value),children:[!m.length&&a.jsx("option",{value:"",children:g}),m.map(x=>a.jsx("option",{value:x,children:x},x))]})]}),a.jsx("span",{className:"work-location-spacer"}),a.jsxs("label",{className:`worktree-choice ${i.isWorktree?"is-active":""}`,title:i.isWorktree?"This chat runs in a linked worktree":"Create a task branch in a new linked worktree",children:[a.jsx("input",{type:"checkbox",checked:o,disabled:!i.isRepo,onChange:x=>l(x.target.checked)}),a.jsx(Qge,{}),a.jsx("span",{children:"New worktree"})]}),a.jsxs("label",{className:"worktree-choice sandbox-choice",title:"Prepare local test services and a separate database for this chat",children:[a.jsx("input",{type:"checkbox",checked:u,onChange:x=>h?.(x.target.checked)}),a.jsx("span",{children:"Use sandbox"})]}),i.error&&a.jsx("span",{className:"work-location-error",role:"status",children:i.error})]})}function Yge(){return a.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:[a.jsx("path",{d:"M3 7.5h7l2 2h9v9.5H3z"}),a.jsx("path",{d:"M3 7.5V5h7l2 2h9v2.5"})]})}function Xge(){return a.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:[a.jsx("circle",{cx:"6",cy:"5",r:"2"}),a.jsx("circle",{cx:"18",cy:"7",r:"2"}),a.jsx("circle",{cx:"6",cy:"19",r:"2"}),a.jsx("path",{d:"M6 7v10M8 10h4a6 6 0 0 0 6-1"})]})}function Qge(){return a.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:[a.jsx("circle",{cx:"6",cy:"6",r:"2"}),a.jsx("circle",{cx:"18",cy:"6",r:"2"}),a.jsx("circle",{cx:"12",cy:"18",r:"2"}),a.jsx("path",{d:"M6 8v2a4 4 0 0 0 4 4h2M18 8v2a4 4 0 0 1-4 4h-2v2"})]})}function Zge(t){return`pasted.${(t.split("/")[1]||"png").replace("jpeg","jpg")}`}function Iz(t){const e=t;return e?.message||e?.name||String(t??"no reason given")}function Jge(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 (${Iz(t)}). Hold the box and choose Paste.`}async function eve(t){const e=[];let n="";for(const s of t){const i=s.types.find(r=>r.startsWith("image/"));if(i){const r=await s.getType(i);e.push(new File([r],Zge(i),{type:i}));continue}s.types.includes("text/plain")&&(n+=await(await s.getType("text/plain")).text())}return{files:e,text:n}}const IS="blank:new",tve=()=>({text:"",attached:[]});class Bz{held=new Map;keep(e,n){const s=e??IS;if(!n.text.trim()&&n.attached.length===0){this.held.delete(s);return}this.held.set(s,{text:n.text,attached:[...n.attached]})}take(e){const n=e??IS,s=this.held.get(n);return this.held.delete(n),s??tve()}forget(e){this.held.delete(e??IS)}}function nve(t){const{record:e,choice:n}=t,s=Hn(n.agent),i=e===null,r=o=>i||typeof o=="string"&&o!=="";return{model:(i||e?.modelId||t.reported)&&n.model?n.model:void 0,effort:r(e?.effort)?s.efforts.find(o=>o.id===t.effort)?.label:void 0,access:r(e?.permission)?s.access.find(o=>o.id===t.access)?.label:void 0}}function sve(t){return[t.model?.toLowerCase(),t.effort?.toLowerCase(),t.access].filter(e=>!!e).join(" · ")}function ive(t){const e=[t.model?.toLowerCase(),t.effort?.toLowerCase()].filter(n=>!!n).join(" · ");return{rest:e,access:t.access?`${e?" · ":""}${t.access}`:""}}function rve(t){return[{label:"Model",value:t.model},{label:"Effort",value:t.effort},{label:"Access",value:t.access}].filter(n=>!!n.value)}function ave(t,e){return[t!==void 0?`Last turn · ${(t/1e3).toFixed(1)}s`:"",e!==void 0?`Cost · $${e.toFixed(3)}`:""].filter(Boolean)}const $z={tight:!1,at:0};function ove(t,e,n=!1){return t.tight?n||e.clientWidth>t.at?$z:t:e.scrollWidth>e.clientWidth?{tight:!0,at:e.clientWidth}:t}const Pz={answer:"Waiting for your answer",approval:"Waiting for your approval",unknown:"Checking what waits on you",unchecked:"Could not check what waits on you"},lve="Check again",lD=t=>t==="answer"||t==="approval",cve=t=>t==="unknown"||t==="unchecked";function uve(t,e){return t.kind==="plan"?{chat:t.openChatId,wait:"approval"}:!t.chatId||t.cardMissing?null:t.kind==="permission"?{chat:t.chatId,wait:"approval"}:t.kind==="question"?{chat:t.chatId,wait:"answer"}:t.kind==="safety"&&!e.has(t.key)?{chat:t.chatId,wait:"answer"}:null}function hve(t,e=pve,n=dve){const s=new Map;for(const i of t){const r=uve(i,e);r&&!s.has(r.chat)&&s.set(r.chat,r.wait)}if(n.whole!=="read"){const i=n.whole==="unread"?"unknown":"unchecked";for(const r of n.restored)s.has(r)||s.set(r,i)}return s}const dve={whole:"read",restored:[]};function fve(t,e){const n=t.get(e);return cve(n)?"unknown":n!==void 0}const pve=new Set;function mve(t,e,n){const s=[];for(const[i,r]of Object.entries(t))if(r?.length)for(const o of n(r,e(i)).folded)s.push(`safety:${o.id}`);return s.sort()}function gve(t,e){const n=new Set;for(const s of t)e.has(s)||n.add(s);return n}function cD(t,e,n,s){const i=t.slice(n,s),r=(e==="codex"?/^([/$])(\S*)$/:/^(\/)(\S*)$/).exec(i);if(r)return{trigger:r[1],query:r[2],start:n,end:s}}function uD(t,e,n=t.length){const s=Math.max(0,Math.min(n,t.length));let i=s;for(;i>0&&!/\s/.test(t[i-1]);)i-=1;const r=t.slice(s).search(/\s/),o=r<0?t.length:s+r,l=cD(t,e,i,o);if(e==="claude")return i===0&&o===t.length?l:void 0;if(l)return l;let u=i;for(;u>0;){for(;u>0&&/\s/.test(t[u-1]);)u-=1;const h=u;for(;u>0&&!/\s/.test(t[u-1]);)u-=1;const f=cD(t,e,u,h);if(f)return f}}function hD(t,e){return e==="$"?t.replace(/^\//,"$"):t}function vve(t,e,n){const s=e.end<t.length&&/\s/.test(t[e.end])?n.trimEnd():n;return{text:t.slice(0,e.start)+s+t.slice(e.end),caret:e.start+s.length}}function xve(t,e){const n=Hn(t).models.filter(u=>u.flag),s=t==="claude"?n.filter(u=>["opus","sonnet","haiku","fable"].includes(u.flag)):[],i=e.models.flatMap(u=>{const h=B_(t,u.model,u.displayName,u.description??u.model);return h?[h]:[]}),r=[],o=new Set,l=e.source==="bundled"?n:[];for(const u of[...s,...i,...l]){const h=u.flag.toLowerCase();!h||o.has(h)||(o.add(h),r.push(u))}return r}const BS=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches;function yve(t){return t?null:"Enter to send · Shift+Enter for a new line"}function bve(t,e){return t?e?"avatar":null:"mascot"}const wve=8e3,_ve=typeof navigator<"u"&&!!navigator.clipboard&&!!(navigator.clipboard.read||navigator.clipboard.readText);function kve(t,e){const[n,s]=y.useState({}),[i,r]=y.useState({}),o=y.useRef(new Set),l=y.useCallback((f,m=!1)=>{f==="pi"||!m&&o.current.has(f)||(o.current.add(f),r(g=>({...g,[f]:{...g[f],loading:!0,error:void 0}})),te.invoke("agent_models",{agent:f}).then(g=>{s(x=>({...x,[f]:xve(f,g)})),r(x=>({...x,[f]:{loading:!1,note:g.note??void 0}}))}).catch(g=>{r(x=>({...x,[f]:{loading:!1,error:String(g?.message??g)}}))}))},[]);y.useEffect(()=>{if(t)for(const f of["claude","codex","antigravity"])e&&!e.includes(f)||l(f)},[t,e,l]);const u=y.useMemo(()=>Nf.flatMap(f=>n[f.id]??f.models),[n]),h=y.useCallback(f=>{o.current.delete(f),l(f,!0)},[l]);return{models:u,status:i,reload:h}}function zz({list:t,access:e,onPick:n,note:s}){const i=t.filter(l=>!l.bypass),r=t.find(l=>l.bypass),o=y.useRef(e===r?.id?i[i.length-1].id:e);return e!==r?.id&&(o.current=e),a.jsxs(a.Fragment,{children:[s&&a.jsx("div",{className:"picker-note",children:s}),i.map(l=>a.jsxs("button",{type:"button",role:"menuitem",className:`picker-item ${l.id===e?"is-on":""}`,onClick:()=>n(l.id),children:[a.jsx("span",{className:"picker-name",children:l.label}),a.jsx("span",{className:"picker-model",children:l.hint}),l.id===e&&a.jsx("span",{className:"picker-tick","aria-hidden":"true",children:"✓"})]},l.id)),r&&a.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":e===r.id,className:`picker-item is-bypass ${e===r.id?"is-on":""}`,title:r.hint,onClick:()=>n(e===r.id?o.current:r.id),children:[a.jsx("span",{className:"picker-name",children:r.label}),a.jsx("span",{className:"picker-switch",children:e===r.id?"Enabled":"Enable"})]})]})}const dD=/\.(png|jpe?g|gif|webp)$/i,Sve=100;function Fz(t){return`octiq.v2.history:${t||"new"}`}function fD(t){try{const e=JSON.parse(localStorage.getItem(Fz(t))||"[]");return Array.isArray(e)?e.filter(n=>typeof n=="string"):[]}catch{return[]}}function Cve(t,e){try{localStorage.setItem(Fz(t),JSON.stringify(e))}catch{}}function jve(t,e,n,s,i){if(i==="older"){if(!t.length)return{index:e,text:n,draft:s};const o=Math.min(e+1,t.length-1);return{index:o,text:t[o],draft:e===-1?n:s}}if(e<0)return{index:e,text:n,draft:s};const r=e-1;return{index:r,text:r<0?s:t[r],draft:s}}function Nve(t,e){return[t.trim(),...e.map(n=>n.trim())].filter(Boolean).join(`
98
98
 
99
99
  `)}function Ave({focusMode:t=!1,session:e,draftStore:n,focusOn:s,choice:i,onChoice:r,access:o,onAccess:l,onSend:u,onStop:h,putBack:f,onPutBack:m,busy:g,disabled:x,started:b,commands:_,onCommandOpen:k,onReloadSkills:N,skillsStatus:j,contextTokens:M,contextWindow:A,activity:E,turnStartedAt:L,turnTokens:O,turnApprox:X,thinking:q,thought:$,background:G,jobChat:B,effort:F,onEffort:z,lite:W,onLite:H,projects:U,projectId:ee,onProject:Q,branch:I,branches:Y,onBranch:J,newWorktree:P,onNewWorktree:ne,useSandbox:he,onUseSandbox:le,showWorkLocation:oe,cwd:ye,onTerminal:D,terminalOpen:Oe,onRestart:ze,installed:Ce,lastDurationMs:ve,lastCostUsd:Ie,runsAt:ae,waiting:$e,onRecheckWaits:He,turnWaits:Wt,identity:yt,advanced:Bt}){const[Gt,qt]=y.useState(""),[Nt,ht]=y.useState(!1);y.useEffect(()=>{ht(!1)},[t]);const[Be,ue]=y.useState(0),[Te,Pe]=y.useState(!1),[dt,pe]=y.useState(!1),Qe=y.useRef(null),[Ze,_t]=y.useState($z),bt=y.useCallback((de=!1)=>{const Ge=Qe.current;Ge&&_t(mt=>ove(mt,Ge,de))},[]);y.useLayoutEffect(()=>{const de=Qe.current;if(!de||typeof ResizeObserver>"u")return;const Ge=new ResizeObserver(()=>bt());Ge.observe(de);let mt=!0;return document.fonts?.ready.then(()=>{mt&&bt(!0)}),()=>{mt=!1,Ge.disconnect()}},[bt]);const Xt=[i.agent,i.model,o,F,yt?.name,!!Bt,!!D,t].join("|");y.useLayoutEffect(()=>bt(!0),[bt,Xt]),y.useLayoutEffect(()=>bt(),[bt,Ze.tight]);const[St,Wn]=y.useState(!1),[_n,_e]=y.useState(0),Ut=Hn(i.agent),Lt=Ut.access,$t=Ut.efforts,gn=$N(i.agent),Xn=Lt.find(de=>de.id===o)??Lt[0],qn=$t.find(de=>de.id===F)??$t[Math.floor($t.length/2)],In=y.useRef(null),ke=y.useRef(null),[at,Je]=y.useState(!1),[vn,Ve]=y.useState(!1),[xt,Pt]=y.useState([]),[Qn,dn]=y.useState(null),[gs,nr]=y.useState(null),[Zs,be]=y.useState(()=>fD(e)),[Et,fn]=y.useState(-1);y.useEffect(()=>{be(fD(e)),fn(-1)},[e]);const vs=de=>Ce!==void 0&&!Ce.includes(de),zi=Ce!==void 0&&Ce.length===0,qs=kve(Te||dt,Ce),Bn=y.useRef(""),[Ne,We]=y.useState(!1),ut=y.useCallback((de,Ge=!1)=>{const mt=jve(Zs,Et,Gt,Bn.current,de);if(Bn.current=mt.draft,fn(mt.index),qt(mt.text),!Ge)return;ue(mt.text.length);const $n=In.current;$n?.focus({preventScroll:!0}),requestAnimationFrame(()=>{$n&&$n.setSelectionRange($n.value.length,$n.value.length)})},[Zs,Et,Gt]),Rt=uD(Gt,i.agent,Be),zt=Rt?.query,Js=Rt!==void 0;y.useEffect(()=>{Js&&k?.()},[Js,k]);const Dt=zt===void 0?[]:(_??[]).filter(de=>de.id.toLowerCase().startsWith(zt.toLowerCase())).sort((de,Ge)=>+(Ge.id.toLowerCase()===zt.toLowerCase())-+(de.id.toLowerCase()===zt.toLowerCase())).slice(0,40),Cn=Js&&(Dt.length>0||!!N),Ln=zt!==void 0&&Dt[_n]?.id.toLowerCase()===zt.toLowerCase();y.useEffect(()=>{_e(de=>de<Dt.length?de:0)},[Dt.length]);function sr(de){const Ge=Rt??uD(Gt,i.agent,In.current?.selectionStart);if(!Ge)return;const mt=vve(Gt,Ge,hD(de.insert,Ge.trigger));qt(mt.text),ue(mt.caret),requestAnimationFrame(()=>{In.current?.focus(),In.current?.setSelectionRange(mt.caret,mt.caret)})}y.useEffect(()=>{const de=In.current;de&&(de.style.height="auto",de.style.height=`${Math.min(de.scrollHeight,420)}px`)},[Gt]);const Qt=y.useCallback(async de=>{for(const Ge of de){if(Ge.size>12*1024*1024){dn(`${Ge.name}: file is larger than 12 MB`);continue}try{const mt=await Ge.arrayBuffer();let $n="";const tt=new Uint8Array(mt);for(let Ka=0;Ka<tt.length;Ka+=8192)$n+=String.fromCharCode(...tt.subarray(Ka,Ka+8192));const on=(Ge.type.split("/")[1]||"bin").replace("jpeg","jpg"),hi=Ge.name||`pasted.${on}`,Va=dD.test(hi),Bh=await te.invoke("save_attachment",{dataBase64:btoa($n),extension:on,filename:hi});dn(null),Pt(Ka=>[...Ka,{path:Bh,name:hi,isImage:Va,url:Va?URL.createObjectURL(Ge):void 0}])}catch(mt){dn(String(mt.message??mt))}}},[]),it=y.useCallback(de=>{const Ge=In.current;if(!Ge){qt(mt=>mt+de);return}Ge.focus({preventScroll:!0}),Ge.setRangeText(de,Ge.selectionStart,Ge.selectionEnd,"end"),qt(Ge.value)},[]);y.useEffect(()=>Fre(de=>it(Ire(de,ye))),[it,ye]);const ui=y.useCallback(async()=>{const de=navigator.clipboard?.read?navigator.clipboard.read():null;dn(null);const Ge=mt=>{dn(Jge(mt)),In.current?.focus()};if(de){let mt;try{mt=await de}catch($n){Ge($n);return}try{const{files:$n,text:tt}=await eve(mt);$n.length&&await Qt($n),tt&&it(tt),!$n.length&&!tt&&dn("There is nothing to paste.")}catch($n){dn(`Could not read what is on the clipboard (${Iz($n)}).`)}return}try{const mt=await navigator.clipboard.readText();mt?it(mt):dn("There is nothing to paste.")}catch(mt){Ge(mt)}},[Qt,it]),Yl=y.useCallback(de=>{dn(null),Pt(Ge=>{const mt=new Set(Ge.map(tt=>tt.path)),$n=de.filter(tt=>tt&&!mt.has(tt)).map(tt=>({path:tt,name:tt.split("/").filter(Boolean).pop()??tt,isImage:dD.test(tt)}));return[...Ge,...$n]})},[]),ei=y.useCallback(de=>{for(const Ge of de)Ge.url&&URL.revokeObjectURL(Ge.url)},[]),Ua=y.useCallback(()=>{gs&&ei(gs.attached),nr({text:Gt,attached:xt}),qt(""),Pt([]),dn(null),fn(-1),Bn.current="",In.current?.focus()},[xt,gs,ei,Gt]),qr=y.useCallback(()=>{gs&&(qt(gs.text),Pt(gs.attached),nr(null),In.current?.focus())},[gs]);y.useEffect(()=>{if(!gs)return;if(Gt||xt.length){ei(gs.attached),nr(null);return}const de=setTimeout(()=>{ei(gs.attached),nr(null)},wve);return()=>clearTimeout(de)},[xt.length,gs,ei,Gt]);const Us=y.useRef({text:"",attached:[]});Us.current={text:Gt,attached:xt};const xs=y.useRef(n??new Bz),Ur=y.useRef(e);y.useLayoutEffect(()=>{if(!n)return;xs.current=n;const de=n.take(Ur.current);return(de.text||de.attached.length)&&(Us.current=de,qt(de.text),Pt(de.attached)),()=>n.keep(Ur.current,Us.current)},[n]),y.useEffect(()=>{if(Ur.current===e)return;xs.current.keep(Ur.current,Us.current),Ur.current=e;const de=xs.current.take(e);qt(de.text),Pt(de.attached),dn(null),Bn.current="",nr(Ge=>(Ge&&ei(Ge.attached),null))},[e,ei]);const Vr=y.useRef(null);y.useEffect(()=>{!f?.length||Vr.current===f||(Vr.current=f,qt(de=>Nve(de,f.map(Ge=>Ge.text))),Pt(de=>{const Ge=f.flatMap(mt=>mt.attachments);return[...de,...Ge.filter(mt=>!de.some($n=>$n.path===mt.path))]}),fn(-1),Bn.current="",m?.())},[f,m]);const ua=y.useRef(s);y.useEffect(()=>{ua.current!==s&&(ua.current=s,!(BS||x)&&In.current?.focus())},[s,x]);function ki(de){be(Ge=>{const mt=Ge[0]===de?Ge:[de,...Ge].slice(0,Sve);return Cve(e,mt),mt}),fn(-1),Bn.current=""}function Fi(){if(x)return;const de="👌 OK";u(de,[]),ki(de)}function ir(){const de=Gt.trim();!de&&xt.length===0||x||(u(de,xt),ki(de),qt(""),ei(xt),Pt([]),dn(null))}const ti=ave(ve,Ie),ys=ase(B);return a.jsxs("div",{className:`composer ${t?"composer-focus":""} ${t&&Nt?"focus-options-open":""}`,"data-composer-style":i.composerStyle,"data-model-id":i.id,children:[t&&a.jsx("div",{className:"focus-activity",role:"status","data-waiting":g&&$e||void 0,children:g&&$e?Pz[$e]:E||(g?"Working…":" ")}),!!$?.trim()&&a.jsx("div",{className:"think-live","aria-live":"off",children:a.jsx("span",{className:"think-live-text",children:$})}),a.jsxs("div",{className:"composer-hint",children:[a.jsx("span",{className:"composer-hint-said",children:a.jsx(cse,{tasks:G??[],chatKey:B,busy:g,children:g?a.jsx(Hve,{since:L,waits:Wt,waiting:$e??void 0,onRecheck:He,tokens:O,approx:X,activity:E,thinking:q,effort:qn.label.toLowerCase(),background:(G??[]).length>0||ys,robot:i.composerStyle,persona:yt}):(()=>{const de=E??yve(BS),Ge=bve(!!yt,de);return a.jsxs(a.Fragment,{children:[Ge==="avatar"&&yt?a.jsx(Qs,{name:yt.name,avatar:yt.avatar,id:yt.id??yt.name,size:18,removed:yt.removed,className:"composer-hint-avatar"}):Ge==="mascot"?a.jsx(HE,{robot:i.composerStyle,mood:"idle"}):null,de]})})()})}),a.jsxs("div",{className:"composer-history",role:"group","aria-label":"Sent message history",children:[a.jsx("button",{className:"history-step",type:"button","aria-label":"Show previous sent message",title:"Previous sent message",disabled:!Zs.length||Et>=Zs.length-1,onPointerDown:de=>de.preventDefault(),onClick:()=>ut("older",!0),children:a.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:a.jsx("path",{d:"m6 14 6-6 6 6"})})}),a.jsx("button",{className:"history-step",type:"button","aria-label":"Show next sent message",title:"Next sent message",disabled:Et<0,onPointerDown:de=>de.preventDefault(),onClick:()=>ut("newer",!0),children:a.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:a.jsx("path",{d:"m6 10 6 6 6-6"})})})]})]}),Cn&&a.jsxs("div",{className:"slash",children:[a.jsx("div",{className:"slash-head",children:a.jsx(Kt,{children:Dt.length?`${Dt.length} command${Dt.length===1?"":"s"} · ${Ln?"Enter to send":"Tab to complete"}`:"No matching skills"})}),N&&a.jsxs("div",{className:"skill-reload",children:[a.jsx("button",{type:"button",disabled:j==="loading",onClick:N,children:j==="loading"?"Reloading…":"Reload skills"}),j&&j!=="loading"&&a.jsx("span",{role:"alert",children:j})]}),a.jsx("ul",{className:"slash-list",role:"listbox",children:Dt.map((de,Ge)=>a.jsx("li",{children:a.jsx("button",{type:"button",role:"option","aria-selected":Ge===_n,className:`slash-item ${Ge===_n?"is-on":""}`,onMouseEnter:()=>_e(Ge),onClick:()=>sr(de),children:hD(de.label,Rt?.trigger??"/")})},de.id))})]}),Ne&&a.jsx(WE,{start:ye??"",title:"Reference a file",files:!0,onPick:de=>{Yl([de]),We(!1)},onClose:()=>We(!1)}),a.jsxs("div",{className:"composer-box",children:[(xt.length>0||Qn||gs)&&a.jsxs("div",{className:"attach",children:[xt.map(de=>a.jsxs("span",{className:`chip ${de.isImage?"is-image":""}`,title:de.path,children:[de.isImage?a.jsx(N7,{attachment:de}):a.jsx(Vve,{}),a.jsx("span",{className:"chip-name",children:de.name}),a.jsx("button",{className:"chip-x",type:"button","aria-label":`Remove ${de.name}`,onClick:()=>{ei([de]),Pt(Ge=>Ge.filter(mt=>mt.path!==de.path))},children:"✕"})]},de.path)),Qn&&a.jsx("span",{className:"attach-error",children:Qn}),gs&&a.jsxs("span",{className:"attach-undo",children:["Cleared.",a.jsx("button",{className:"attach-undo-btn",type:"button",onClick:qr,children:"Undo"})]})]}),a.jsx("div",{className:"composer-input-wrap",children:a.jsx("textarea",{ref:In,className:"composer-input","aria-label":"Message",rows:2,value:Gt,placeholder:x?"Chat unavailable":Ene(yt,i.name),disabled:x,onChange:de=>{Et>=0&&fn(-1),qt(de.target.value),ue(de.target.selectionStart)},onSelect:de=>ue(de.currentTarget.selectionStart),onPaste:de=>{const Ge=[...de.clipboardData?.files??[]];Ge.length&&(de.preventDefault(),Qt(Ge))},onKeyDown:de=>{if(Cn&&Dt.length>0){if(de.key==="ArrowDown"){de.preventDefault(),_e(hi=>(hi+1)%Dt.length);return}if(de.key==="ArrowUp"){de.preventDefault(),_e(hi=>(hi-1+Dt.length)%Dt.length);return}const on=de.key==="Enter"&&!de.shiftKey&&!de.metaKey&&!de.ctrlKey&&!de.altKey;if(de.key==="Tab"||on&&!Ln){de.preventDefault(),sr(Dt[_n]);return}if(de.key==="Escape"){de.preventDefault(),qt("");return}}const Ge=de.currentTarget,mt=Ge.selectionStart===0&&Ge.selectionEnd===0,$n=!Gt.slice(0,Ge.selectionStart).includes(`
100
100
  `),tt=!Gt.slice(Ge.selectionEnd).includes(`
@@ -375,7 +375,7 @@ Reporter: ${t.source.modelId??"Unknown"}`].join(`
375
375
  Attachments:
376
376
  ${n.join(`
377
377
  `)}`.trim()}function O0e(t){return{target:"home",projectId:t??null,prepare:!1,branch:"",newWorktree:!1,useSandbox:!1,chosenBy:"auto",reason:"The front desk only routes: it works from your home workspace and opens the right agent's chat.",crossProject:!1}}const I0e=["claude","codex","antigravity"];function B0e(t){return{name:"",role:"",agent:"claude",model:"sonnet",effort:"medium",access:"auto",projectId:t,reportsTo:null,teamId:null}}function $0e({on:t,onToggle:e,projects:n}){const[s,i]=y.useState([]),[r,o]=y.useState(!0),[l,u]=y.useState(""),[h,f]=y.useState(null),[m,g]=y.useState(!1),[x,b]=y.useState(null),[_,k]=y.useState(null),[N,j]=y.useState([]),[M,A]=y.useState(null),[E,L]=y.useState(null),[O,X]=y.useState(!1),[q,$]=y.useState(""),[G,B]=y.useState(""),[F,z]=y.useState(!1),[W,H]=y.useState(!1),U=y.useRef(q);U.current=q,y.useEffect(()=>{let ae=!0;Promise.all([yo(null,!0),k_(),Jz().catch(()=>null),hw().catch(()=>[]),S_().catch(()=>null),ND()]).then(([He,Wt,yt,Bt,Gt,qt])=>{ae&&(i(He),b(Wt?.id??null),k(yt),j(Bt),L(Gt?.id??null),$(qt.text),B(qt.text))}).catch(He=>{ae&&(H(!0),u(String(He.message??He)))}).finally(()=>{ae&&o(!1)});const $e=YE(()=>{yo(null,!0).then(He=>{ae&&i(He)}).catch(()=>{}),ND().then(He=>{ae&&(H(!1),B(Wt=>Wt===U.current?He.text:Wt),$(He.text))}).catch(()=>{})});return()=>{ae=!1,$e()}},[]);const ee=y.useMemo(()=>s.filter(ae=>!ae.projectId&&ae.id!==E),[s,E]),Q=async ae=>{u("");try{const $e=await l0e(ae);b($e?.id??null)}catch($e){u(String($e.message??$e))}},I=y.useMemo(()=>s.find(ae=>ae.id===E)??null,[s,E]),Y=async ae=>{u(""),X(!0);try{await ae()}catch($e){u(String($e.message??$e))}finally{X(!1)}},J=ae=>Y(async()=>{L((await u0e(ae))?.id??null)}),P=()=>Y(async()=>{const ae=await h0e({agent:"claude",...dw("claude")});i(await yo(null,!0)),L(ae.id)}),ne=ae=>Y(async()=>{I&&(await jD({id:I.id,name:I.name,role:I.role,agent:ae.agent,model:ae.model,effort:ae.effort,access:I.access,projectId:null,reportsTo:null,teamId:I.teamId??null}),i(await yo(null,!0)))}),he=async ae=>{u(""),z(!0);try{const $e=await i0e(ae);$($e.text),B($e.text)}catch($e){u(String($e.message??$e))}finally{z(!1)}},le=async ae=>{u("");try{k(await d0e(ae))}catch($e){u(String($e.message??$e))}},oe=!!_&&n.some(ae=>ae.id===_),ye=y.useMemo(()=>new Map(n.map(ae=>[ae.id,ae.name])),[n]),D=y.useMemo(()=>yz(s),[s]),Oe=async()=>{if(h){g(!0),u("");try{const ae=await jD({...h,projectId:h.projectId||null,reportsTo:h.reportsTo||null});ae.memoryError&&u(`${ae.name} was saved, but its memory note could not be created: ${ae.memoryError}`),i(await yo(null,!0)),f(null)}catch(ae){u(String(ae.message??ae))}finally{g(!1)}}},ze=async()=>{if(M){u("");try{await r0e(M),j(await hw()),A(null)}catch(ae){u(String(ae.message??ae))}}},Ce=async ae=>{u("");try{await a0e(ae.id),j(await hw()),i(await yo(null,!0)),M?.id===ae.id&&A(null),h?.teamId===ae.id&&f({...h,teamId:null})}catch($e){u(String($e.message??$e))}},ve=async ae=>{u("");try{await o0e(ae.id),i(await yo(null,!0)),b((await k_())?.id??null),L((await S_().catch(()=>null))?.id??null),h?.id===ae.id&&f(null)}catch($e){u(String($e.message??$e))}},Ie=({agent:ae,depth:$e})=>{const He=xz(ae,N);return a.jsxs("li",{className:"team-row",style:{"--team-depth":$e},children:[a.jsxs("div",{className:"team-row-head",children:[$e>0&&a.jsx("span",{className:"team-row-branch","aria-hidden":"true",children:"└"}),a.jsx(Qs,{name:ae.name,avatar:ae.avatar,id:ae.id,size:28,decorative:!0}),a.jsxs("span",{className:"team-row-copy",children:[a.jsxs("span",{className:"team-row-name",children:[a.jsx("bdi",{children:ae.name}),eF(ae)&&a.jsx("span",{className:"team-tag",title:"Fable and Astra can lead a task but cannot take one",children:"lead only"}),He&&a.jsx("span",{className:"team-tag team-badge",title:`On the team ${He.name}: may ask its teammates for help`,children:a.jsx("bdi",{children:He.name})})]}),a.jsxs("span",{className:"team-row-meta",children:[tr[ae.agent]," ",l0(ae),ae.effort?` · ${ae.effort}`:""," · ",ae.projectId?ye.get(ae.projectId)??"Removed project":"Every project"]})]}),a.jsxs("span",{className:"team-row-actions",children:[a.jsxs("button",{className:"vault-button team-row-action",type:"button","aria-label":`Edit ${ae.name}`,title:"Edit",onClick:()=>f({...ae,projectId:ae.projectId??null,reportsTo:ae.reportsTo??null,teamId:ae.teamId??null}),children:[a.jsx(iF,{}),a.jsx("span",{className:"team-row-action-text",children:"Edit"})]}),a.jsxs("button",{className:"vault-button team-row-action",type:"button","aria-label":`Remove ${ae.name}`,title:"Remove",onClick:()=>{ve(ae)},children:[a.jsx(rF,{}),a.jsx("span",{className:"team-row-action-text",children:"Remove"})]})]})]}),ae.role&&a.jsx(nF,{className:"team-row-role",text:ae.role,name:ae.name})]},ae.id)};return a.jsxs("section",{className:"settings-section team-settings","aria-labelledby":"settings-agents-title",children:[a.jsx("header",{className:"settings-section-head",children:a.jsxs("div",{children:[a.jsx("h2",{id:"settings-agents-title",children:"Agents"}),a.jsx("p",{children:"Register agents, then hand a task to one. It does the task, passes it on, or splits it across the others."})]})}),a.jsxs("div",{className:"settings-control-row",children:[a.jsxs("div",{className:"settings-control-copy",children:[a.jsx("h3",{children:"Agents mode"}),a.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."})]}),a.jsxs("button",{className:`set-switch${t?" is-on":""}`,type:"button",role:"switch","aria-checked":t,onClick:()=>e(!t),children:[a.jsx("span",{className:"set-switch-track","aria-hidden":"true"}),a.jsx("span",{className:"set-switch-text",children:t?"On":"Off"})]})]}),a.jsxs("div",{className:"settings-control-row team-choice-row",children:[a.jsxs("div",{className:"settings-control-copy",children:[a.jsx("h3",{children:"Talk to"}),a.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."})]}),a.jsxs("select",{className:"team-head-select","aria-label":"Lead you talk to across projects",value:x??"",disabled:r||ee.length===0,onChange:ae=>{Q(ae.target.value||null)},children:[a.jsx("option",{value:"",children:ee.length===0?"Add an agent for every project first":"No one"}),ee.map(ae=>a.jsxs("option",{value:ae.id,children:[ae.name,ae.role?` · ${sF(ae.role)}`:""]},ae.id))]})]}),a.jsx(H0e,{desk:I,roster:s,headId:x,loading:r,busy:O,onPick:ae=>{J(ae)},onCreate:()=>{P()},onSettings:ae=>{ne(ae)}}),a.jsxs("div",{className:"settings-control-row team-choice-row",children:[a.jsxs("div",{className:"settings-control-copy",children:[a.jsx("h3",{children:"Home workspace"}),a.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."})]}),a.jsxs("select",{className:"team-head-select","aria-label":"Home workspace for your lead",value:oe?_??"":"",disabled:r,onChange:ae=>{le(ae.target.value||null)},children:[a.jsx("option",{value:"",children:"General (default)"}),n.map(ae=>a.jsx("option",{value:ae.id,children:ae.name},ae.id))]})]}),a.jsx(z0e,{saved:q,text:G,loading:r,busy:F,unread:W,onChange:B,onSave:()=>{he(G)},onClear:()=>{he("")}}),a.jsxs("div",{className:"team-head",children:[a.jsx("h3",{children:"Registered agents"}),a.jsx("button",{className:"settings-primary",type:"button",onClick:()=>f(B0e(null)),disabled:!!h&&!h.id,children:"Add agent"})]}),l&&a.jsx("p",{className:"set-warn",role:"alert",children:l}),h&&a.jsx(W0e,{draft:h,team:s,teams:N,projects:n,saving:m,onChange:f,onSave:()=>{Oe()},onCancel:()=>f(null)}),r?a.jsx("p",{role:"status",className:"settings-note",children:"Loading agents…"}):s.length===0?a.jsxs("div",{className:"settings-empty",children:[a.jsx("strong",{children:"No agents yet"}),a.jsx("span",{children:"Add one with a name, a role and the model it runs on."})]}):a.jsxs("div",{className:"team-group",children:[a.jsx("h4",{children:"Org chart · agents at the top report to you"}),a.jsx("ul",{className:"team-list",children:D.map(Ie)})]}),a.jsx(F0e,{teams:N,agents:s,draft:M,projects:n,projectName:ae=>ye.get(ae),onDraft:A,onSave:()=>{ze()},onRemove:ae=>{Ce(ae)}})]})}function P0e({agents:t,selectedId:e,projectName:n,onPick:s,onManage:i,showManage:r=!0,label:o="Talk to"}){if(t.length===0)return a.jsx("div",{className:"lead-picker",children:a.jsxs("p",{className:"lead-picker-note",children:["No agent reports to you yet. ",a.jsx("button",{type:"button",onClick:i,children:"Add one in Settings"})," to start a conversation."]})});if(t.length===1&&t[0].id===e)return null;const l=t.some(f=>f.id===e)?e:t[0].id,u=R0e(t),h=f=>{const m={ArrowRight:1,ArrowDown:1,ArrowLeft:-1,ArrowUp:-1}[f.key],g=t.findIndex(b=>b.id===l),x=f.key==="Home"?0:f.key==="End"?t.length-1:m?(g+m+t.length)%t.length:-1;x<0||(f.preventDefault(),s(t[x]),f.currentTarget.querySelectorAll("[role=radio]")[x]?.focus())};return a.jsxs("div",{className:"lead-picker",children:[u&&a.jsxs("p",{className:"lead-picker-scope",children:["All in ",n(u)??"another project"]}),a.jsx("div",{className:"lead-picker-list",role:"radiogroup","aria-label":o,onKeyDown:h,children:t.map(f=>{const m=f.projectId?n(f.projectId)??"another project":null,g=u?null:m;return a.jsxs("button",{className:`lead-chip${f.id===e?" is-on":""}`,type:"button",role:"radio","aria-checked":f.id===e,tabIndex:f.id===l?0:-1,title:[f.role,m?`Works in ${m}`:"Works in any project",`${tr[f.agent]} ${l0(f)}`].filter(Boolean).join(`
378
- `),onClick:()=>s(f),children:[a.jsx(Qs,{name:f.name,avatar:f.avatar,id:f.id,size:20,decorative:!0}),a.jsx("span",{className:"lead-chip-name",children:f.name}),g&&a.jsx("span",{className:"lead-chip-meta",children:g})]},f.id)})}),r&&a.jsx("p",{className:"lead-picker-note",children:a.jsx("button",{type:"button",onClick:i,children:"Manage agents"})})]})}function QE({text:t,max:e}){const n=GE(t),s=n>e;return a.jsxs("small",{className:`team-field-count${s?" is-over":""}`,children:[n.toLocaleString("en-US")," / ",e.toLocaleString("en-US"),s?" · too long":""]})}function z0e({saved:t,text:e,loading:n,busy:s,unread:i=!1,onChange:r,onSave:o,onClear:l}){const u=e.trim()!==t.trim(),h=GE(e)>$S;return n=n||i,a.jsxs("form",{className:"agent-policy","aria-labelledby":"agent-policy-title",onSubmit:f=>{f.preventDefault(),u&&!h&&!i&&o()},children:[a.jsxs("div",{className:"team-field-head",children:[a.jsx("h3",{id:"agent-policy-title",children:"Agent policy"}),a.jsx(QE,{text:e,max:$S})]}),a.jsx("p",{className:"settings-note",id:"agent-policy-hint",children:"Shared rules for every agent. Prepended to every agent's brief, ahead of its persistent prompt and role, so rules everyone follows need not be copied into each role. Applies to new chats and tasks."}),a.jsx("textarea",{className:"agent-policy-text","aria-labelledby":"agent-policy-title","aria-describedby":"agent-policy-hint",value:e,maxLength:$S,rows:5,disabled:n||s,placeholder:"e.g. Work in a git worktree. Never push or release without asking.",onChange:f=>r(f.target.value)}),a.jsxs("div",{className:"agent-policy-actions",children:[a.jsx("button",{className:"vault-button",type:"button",disabled:n||s||!t,onClick:l,children:"Clear"}),a.jsx("button",{className:"settings-primary",type:"submit",disabled:n||s||!u||h,children:s?"Saving…":"Save policy"})]})]})}function iF(){return a.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:[a.jsx("path",{d:"M4 20h4L19 9a2.8 2.8 0 0 0-4-4L4 16v4Z"}),a.jsx("path",{d:"m13.5 6.5 4 4"})]})}function rF(){return a.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:[a.jsx("path",{d:"M4 7h16"}),a.jsx("path",{d:"M10 11v6M14 11v6"}),a.jsx("path",{d:"M6 7l1 13h10l1-13"}),a.jsx("path",{d:"M9 7V4h6v3"})]})}function F0e({teams:t,agents:e,draft:n,projects:s,projectName:i,onDraft:r,onSave:o,onRemove:l}){const u=a.jsxs("form",{className:"team-group-form","aria-label":n?.id?"Rename team":"New team",onSubmit:h=>{h.preventDefault(),o()},children:[a.jsx("input",{value:n?.name??"",maxLength:60,placeholder:"Team name","aria-label":"Team name",autoFocus:!0,onChange:h=>n&&r({...n,name:h.target.value})}),a.jsxs("select",{"aria-label":"Team available in",value:n?.projectId??"",onChange:h=>n&&r({...n,projectId:h.target.value||null}),children:[a.jsx("option",{value:"",children:"Every project"}),s.map(h=>a.jsx("option",{value:h.id,children:h.name},h.id))]}),a.jsx("button",{className:"vault-button",type:"button",onClick:()=>r(null),children:"Cancel"}),a.jsx("button",{className:"settings-primary",type:"submit",disabled:!n?.name.trim(),children:n?.id?"Save":"Add"})]});return a.jsxs("div",{className:"team-groups",children:[a.jsxs("div",{className:"team-head",children:[a.jsx("h3",{children:"Teams"}),a.jsx("button",{className:"vault-button",type:"button",disabled:!!n&&!n.id,onClick:()=>r({name:"",projectId:null}),children:"Add team"})]}),a.jsx("p",{className:"settings-note",children:"Agents on one team may ask each other questions while they work. Teammates answer; they never take the work, and a team changes no one's manager."}),n&&!n.id&&u,t.length>0&&a.jsx("ul",{className:"team-group-list","aria-label":"Teams",children:t.map(h=>{const f=e.filter(m=>m.teamId===h.id).length;return n?.id===h.id?a.jsx("li",{children:u},h.id):a.jsxs("li",{className:"team-group-row",children:[a.jsxs("span",{className:"team-group-copy",children:[a.jsx("span",{className:"team-row-name",children:a.jsx("bdi",{children:h.name})}),a.jsxs("span",{className:"team-row-meta",children:[f," ",f===1?"agent":"agents"," · ",h.projectId?i(h.projectId)??"Removed project":"Every project"]})]}),a.jsxs("span",{className:"team-row-actions",children:[a.jsxs("button",{className:"vault-button team-row-action",type:"button","aria-label":`Rename ${h.name}`,title:"Rename",onClick:()=>r({id:h.id,name:h.name,projectId:h.projectId??null}),children:[a.jsx(iF,{}),a.jsx("span",{className:"team-row-action-text",children:"Rename"})]}),a.jsxs("button",{className:"vault-button team-row-action",type:"button","aria-label":`Remove team ${h.name}`,title:"Remove team",onClick:()=>l(h),children:[a.jsx(rF,{}),a.jsx("span",{className:"team-row-action-text",children:"Remove"})]})]})]},h.id)})})]})}function aF({agent:t,model:e,effort:n,onProvider:s,onModel:i,onEffort:r,disabled:o}){return a.jsxs(a.Fragment,{children:[a.jsxs("label",{children:[a.jsx("span",{children:"Provider"}),a.jsx("select",{value:t,disabled:o,onChange:l=>s(l.target.value),children:I0e.map(l=>a.jsx("option",{value:l,children:tr[l]},l))})]}),a.jsxs("label",{children:[a.jsx("span",{children:"Model"}),a.jsx("select",{value:e,disabled:o,onChange:l=>i(l.target.value),children:XE(t).map(l=>a.jsx("option",{value:l.flag,children:l.model},l.id))})]}),a.jsxs("label",{children:[a.jsx("span",{children:"Effort"}),a.jsx("select",{value:n??"",disabled:o,onChange:l=>r(l.target.value),children:EC[t].map(l=>a.jsx("option",{value:l.id,children:l.label},l.id))})]})]})}function H0e({desk:t,roster:e,headId:n,loading:s,busy:i,onPick:r,onCreate:o,onSettings:l}){const u=e.filter(f=>!f.projectId),h=u.filter(f=>f.id!==t?.id&&MD(f,e,n));return a.jsxs("div",{className:"front-desk-block",children:[a.jsxs("div",{className:"settings-control-row team-choice-row",children:[a.jsxs("div",{className:"settings-control-copy",children:[a.jsx("h3",{children:"Front desk"}),a.jsx("p",{children:"Every new chat opens on it. It works out who should handle what you ask and opens that agent's chat once you confirm on a card. Its own chats are never listed."})]}),a.jsxs("select",{className:"team-head-select","aria-label":"Front desk",value:t?.id??"",disabled:s||i,onChange:f=>r(f.target.value||null),children:[a.jsx("option",{value:"",children:"No front desk"}),u.map(f=>{const m=f.id===t?.id?null:MD(f,e,n);return a.jsxs("option",{value:f.id,disabled:!!m,children:[f.name,m?" · not available":""]},f.id)})]})]}),h.length>0&&a.jsxs("p",{className:"settings-note front-desk-unavailable",children:["Not available: ",h.map(f=>f.name).join(", "),". The lead you talk to across projects and agents who manage others keep their own chats; a front desk's chats are hidden and it only routes."]}),t?a.jsxs("div",{className:"front-desk-model",role:"group","aria-label":`What ${t.name} runs on`,children:[a.jsx(aF,{agent:t.agent,model:t.model,effort:t.effort,disabled:i,onProvider:f=>l({agent:f,...dw(f)}),onModel:f=>l({agent:t.agent,model:f,effort:t.effort}),onEffort:f=>l({agent:t.agent,model:t.model,effort:f})}),a.jsxs("p",{className:"settings-note",children:["Now ",tr[t.agent]," ",l0(t),t.effort?` · ${t.effort}`:"",". Used from the next new chat."]})]}):a.jsxs("div",{className:"front-desk-create",children:[a.jsx("button",{className:"settings-primary",type:"button",disabled:s||i,onClick:o,children:"Create front desk"}),a.jsxs("span",{className:"settings-note",children:["A router on ",tr.claude," ",l0({agent:"claude",model:dw("claude").model}),", ",dw("claude").effort," effort. You can change what it runs on here after."]})]})]})}function W0e({draft:t,team:e,teams:n,projects:s,saving:i,onChange:r,onSave:o,onCancel:l}){const u=tL[t.agent],h=k=>r({...t,...k}),f=k=>{const N=XE(k)[0]?.flag??"",j=EC[k].some(A=>A.id===t.effort)?t.effort:EC[k][0]?.id,M=tL[k].some(A=>A.id===t.access)?t.access:"auto";r({...t,agent:k,model:N,effort:j,access:M})},m=eF(t),g=new Set;if(t.id){let k=!0;for(g.add(t.id);k;){k=!1;for(const N of e)N.reportsTo&&g.has(N.reportsTo)&&!g.has(N.id)&&(g.add(N.id),k=!0)}}const x=e.filter(k=>!g.has(k.id)&&(!k.projectId||k.projectId===(t.projectId||void 0))),b=AD(n,t.projectId),_=k=>{const N=!t.teamId||AD(n,k).some(j=>j.id===t.teamId);h({projectId:k,...N?{}:{teamId:null}})};return a.jsxs("form",{className:"team-form",onSubmit:k=>{k.preventDefault(),o()},children:[a.jsxs("label",{children:[a.jsx("span",{children:"Name"}),a.jsx("input",{value:t.name,maxLength:60,placeholder:"e.g. Reviewer",autoFocus:!0,onChange:k=>h({name:k.target.value})})]}),a.jsx(S0e,{name:t.name,role:t.role,avatar:t.avatar,agentId:t.id,onChange:k=>h({avatar:k})},t.id??"new"),a.jsxs("label",{className:"team-form-wide",children:[a.jsx("span",{children:"Role"}),a.jsx("textarea",{value:t.role,maxLength:s0e,rows:3,placeholder:"What this agent is good at, and what it should take on",onChange:k=>h({role:k.target.value})})]}),a.jsxs("label",{className:"team-form-wide",children:[a.jsxs("span",{className:"team-field-head",children:[a.jsx("span",{children:"Persistent prompt"}),a.jsx(QE,{text:t.persistentPrompt??"",max:CD})]}),a.jsx("textarea",{value:t.persistentPrompt??"",maxLength:CD,rows:4,"aria-describedby":"team-persistent-prompt-hint",placeholder:"Runbooks, tool rules, how this agent builds and checks its work",onChange:k=>h({persistentPrompt:k.target.value})}),a.jsx("small",{className:"team-field-note",id:"team-persistent-prompt-hint",children:"This agent's standing instructions. Sent ahead of its role in every brief it starts with, after the agent policy; never shown in the roster or to other agents. Applies to new chats and tasks."})]}),a.jsx(aF,{agent:t.agent,model:t.model,effort:t.effort,onProvider:f,onModel:k=>h({model:k}),onEffort:k=>h({effort:k})}),a.jsxs("label",{children:[a.jsx("span",{children:"Access"}),a.jsx("select",{value:t.access,onChange:k=>h({access:k.target.value}),children:u.map(k=>a.jsx("option",{value:k.id,children:k.label},k.id))}),Hn(t.agent).accessNote&&a.jsx("small",{className:"team-field-note",children:u.find(k=>k.id===t.access)?.hint})]}),a.jsxs("label",{children:[a.jsx("span",{children:"Reports to"}),a.jsxs("select",{value:t.reportsTo??"",onChange:k=>h({reportsTo:k.target.value||null}),children:[a.jsx("option",{value:"",children:"You"}),x.map(k=>a.jsx("option",{value:k.id,children:k.name},k.id))]})]}),a.jsxs("label",{children:[a.jsx("span",{children:"Available in"}),a.jsxs("select",{value:t.projectId??"",onChange:k=>_(k.target.value||null),children:[a.jsx("option",{value:"",children:"Every project"}),s.map(k=>a.jsx("option",{value:k.id,children:k.name},k.id))]})]}),a.jsxs("label",{children:[a.jsx("span",{children:"Team"}),a.jsxs("select",{value:t.teamId??"",onChange:k=>h({teamId:k.target.value||null}),children:[a.jsx("option",{value:"",children:"None"}),b.map(k=>a.jsx("option",{value:k.id,children:k.name},k.id))]})]}),m&&a.jsx("p",{className:"settings-note team-form-wide",children:"Fable and Astra can lead a task, but they cannot be given one."}),a.jsxs("div",{className:"team-form-actions team-form-wide",children:[a.jsx("button",{className:"vault-button",type:"button",onClick:l,children:"Cancel"}),a.jsx("button",{className:"settings-primary",type:"submit",disabled:i||!t.name.trim()||!t.model,children:i?"Saving…":t.id?"Save":"Add"})]})]})}function q0e(){const{snapshot:t,error:e,refresh:n}=DN(),[s,i]=y.useState(!1),[r,o]=y.useState(null),l=t?.defaultEnabled??!1;async function u(){i(!0),o(null);try{await te.invoke("sandbox_configure",{enabled:!l}),await n()}catch(h){o(String(h.message??h))}finally{i(!1)}}return a.jsxs("section",{className:"settings-section","aria-labelledby":"settings-sandbox-title",children:[a.jsx("header",{className:"settings-section-head",children:a.jsxs("div",{children:[a.jsx("h2",{id:"settings-sandbox-title",children:"Sandbox"}),a.jsx("p",{children:"Run a separate test app and database for each chat on the OctiqFlow host."})]})}),a.jsxs("div",{className:"settings-control-row",children:[a.jsxs("div",{className:"settings-control-copy",children:[a.jsx("h3",{children:"Use sandbox for new chats"}),a.jsx("p",{children:"Set the default. You can change the checkbox before starting each new chat."})]}),a.jsxs("button",{className:`set-switch${l?" is-on":""}`,type:"button",role:"switch","aria-label":"Use sandbox for new chats","aria-checked":l,disabled:s||!t,onClick:()=>{u()},children:[a.jsx("span",{className:"set-switch-track","aria-hidden":"true"}),a.jsx("span",{className:"set-switch-text",children:s?"…":l?"On":"Off"})]})]}),a.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)&&a.jsx("p",{className:"set-warn",role:"alert",children:r||e})]})}const zS=4e3;async function U0e(){return await te.invoke("personal_preferences",{})??{text:"",updatedAt:0}}async function V0e(t){return await te.invoke("personal_preferences_set",{text:t})}function K0e(){const[t,e]=y.useState(""),[n,s]=y.useState(""),[i,r]=y.useState(!0),[o,l]=y.useState(!1),[u,h]=y.useState(""),[f,m]=y.useState(!1),[g,x]=y.useState(!1);y.useEffect(()=>{let _=!0;return U0e().then(k=>{_&&(e(k.text),s(k.text))}).catch(k=>{_&&(x(!0),h(String(k)))}).finally(()=>{_&&r(!1)}),()=>{_=!1}},[]);async function b(_){l(!0),h(""),m(!1);try{const k=await V0e(_);e(k.text),s(k.text),m(!0)}catch(k){h(String(k))}finally{l(!1)}}return a.jsxs("section",{className:"settings-section","aria-labelledby":"preferences-title",children:[a.jsx("header",{className:"settings-section-head",children:a.jsxs("div",{children:[a.jsx("h2",{id:"preferences-title",children:"Personal preferences"}),a.jsx("p",{children:"How you like every agent to work with you, in your own words."})]})}),a.jsx(G0e,{saved:t,text:n,loading:i,busy:o,done:f,unread:g,onChange:_=>{s(_),m(!1)},onSave:()=>{b(n)},onClear:()=>{b("")}}),u&&a.jsx("p",{className:"set-warn",role:"alert",children:u})]})}function G0e({saved:t,text:e,loading:n,busy:s,done:i,unread:r=!1,onChange:o,onSave:l,onClear:u}){const h=e.trim()!==t.trim(),f=GE(e)>zS;return n=n||r,a.jsxs("form",{className:"agent-policy","aria-labelledby":"preferences-field",onSubmit:m=>{m.preventDefault(),h&&!f&&!r&&l()},children:[a.jsxs("div",{className:"team-field-head",children:[a.jsx("h3",{id:"preferences-field",children:"Added to every chat"}),a.jsx(QE,{text:e,max:zS})]}),a.jsx("p",{className:"settings-note",id:"preferences-hint",children:"Ends the system prompt of every chat OctiqFlow starts: any agent, any project, the front desk and task workers included. A chat that is already running picks up a change the next time it starts or resumes."}),a.jsx("textarea",{className:"agent-policy-text","aria-labelledby":"preferences-field","aria-describedby":"preferences-hint",value:e,maxLength:zS,rows:8,disabled:n||s,placeholder:"e.g. Reply in British English. Keep answers short and put the conclusion first. I work on a Mac.",onChange:m=>o(m.target.value)}),a.jsxs("div",{className:"agent-policy-actions",children:[i&&!h&&a.jsx("span",{className:"settings-note",role:"status",children:"Saved"}),a.jsx("button",{className:"vault-button",type:"button",disabled:n||s||!t,onClick:u,children:"Clear"}),a.jsx("button",{className:"settings-primary",type:"submit",disabled:n||s||!h||f,children:s?"Saving…":"Save preferences"})]})]})}const Y0e=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});function X0e(t,e){return Y0e.compare(t.name,e.name)||t.name.localeCompare(e.name)||t.id.localeCompare(e.id)}function Q0e({current:t,onPick:e,chatWidth:n=o0,onChatWidth:s,notify:i,onNotify:r,projects:o,onProject:l,agentsMode:u=!1,onAgentsMode:h,onFeedback:f,initialSection:m="projects",onClose:g}){const x=G=>{Yz(G),e(G)},[b,_]=y.useState(UC),[k,N]=y.useState(""),[j,M]=y.useState(!1),[A,E]=y.useState(m),L=K_()||ag()||F6(),O=async()=>{if(!j){M(!0),N("");try{if(i){await GY(),Hk(!1),r(!1,!1);return}const G=await KY();if(_(UC()),G==="on"){Hk(!0),r(!0,!0);return}if(G==="denied"){N("denied");return}if(G==="needs-install"){N("needs-install");return}const B=await FY();if(_(B),B!=="granted"){N("denied");return}Hk(!0),r(!0,!1)}finally{M(!1)}}},X=i&&b==="granted",q=__.find(G=>G.id===t)?.name??"Dark",$=[...o].sort(X0e);return a.jsxs("section",{className:"settings-page","aria-labelledby":"settings-title",children:[a.jsx(Sf,{root:!0,back:{label:"Chat",ariaLabel:"Back to chat",onClick:g},title:a.jsx("h1",{id:"settings-title",children:"Settings"})}),a.jsxs("div",{className:"settings-layout",children:[a.jsxs("nav",{className:"settings-nav","aria-label":"Settings sections",children:[a.jsxs("div",{className:"settings-nav-list",children:[a.jsx(Od,{section:"projects",label:"Projects",detail:`${o.length} ${o.length===1?"project":"projects"}`,active:A==="projects",onPick:E}),a.jsx(Od,{section:"preferences",label:"Personal preferences",detail:"In every chat's system prompt",active:A==="preferences",onPick:E}),h&&a.jsx(Od,{section:"agents",label:"Agents",detail:u?"Agents mode on":"Agents mode off",active:A==="agents",onPick:E}),L&&a.jsx(Od,{section:"notifications",label:"Notifications",detail:X?"On":"Off",active:A==="notifications",onPick:E}),a.jsx(Od,{section:"sandbox",label:"Sandbox",detail:"Local test environments",active:A==="sandbox",onPick:E}),a.jsx(Od,{section:"memory",label:"Memory Vault",detail:"Shared agent knowledge",active:A==="memory",onPick:E}),a.jsx(Od,{section:"appearance",label:"Appearance",detail:n===o0?q:`${q} · ${KE(n).name} chat`,active:A==="appearance",onPick:E}),f&&a.jsxs("button",{className:"settings-nav-item",type:"button","aria-haspopup":"dialog",onClick:f,children:[a.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:[a.jsx("path",{d:"M4 4h16v13H9l-5 4V4Z"}),a.jsx("path",{d:"M8 8h8M8 12h5"})]}),a.jsxs("span",{className:"settings-nav-copy",children:[a.jsx("span",{children:"Feedback inbox"}),a.jsx("small",{children:"Reports from your agents"})]})]})]}),a.jsxs("p",{className:"settings-nav-foot",children:["Switches apply automatically.",a.jsxs("span",{className:"settings-version",children:["OctiqFlow v","0.3.12"]})]})]}),a.jsxs("div",{className:"settings-content",children:[A==="preferences"&&a.jsx(K0e,{}),A==="sandbox"&&a.jsx(q0e,{}),A==="memory"&&a.jsx(e0e,{}),A==="agents"&&h&&a.jsx($0e,{on:u,onToggle:h,projects:$}),A==="projects"&&a.jsxs("section",{className:"settings-section","aria-labelledby":"settings-projects-title",children:[a.jsxs("header",{className:"settings-section-head",children:[a.jsxs("div",{children:[a.jsx("h2",{id:"settings-projects-title",children:"Projects"}),a.jsx("p",{children:"Manage names, folders, environment, links, and visibility."})]}),a.jsxs("button",{className:"settings-primary",type:"button",onClick:()=>l("new"),children:[a.jsx(J0e,{}),a.jsx("span",{children:"New project"})]})]}),o.length?a.jsx("div",{className:"settings-projects",children:$.map(G=>a.jsxs("button",{className:"settings-project",type:"button",onClick:()=>l(G.id),"aria-label":`Configure ${G.name}`,children:[a.jsx(Mh,{project:G,size:"medium"}),a.jsxs("span",{className:"settings-project-copy",children:[a.jsx("span",{className:"settings-project-name",children:G.name}),G.primary_path&&a.jsx("span",{className:"settings-project-path",title:G.primary_path,children:a.jsx("bdi",{children:G.primary_path})})]}),G.shelved&&a.jsx("span",{className:"settings-project-state",children:"Shelved"}),a.jsx(eye,{})]},G.id))}):a.jsxs("div",{className:"settings-empty",children:[a.jsx("strong",{children:"No projects yet"}),a.jsx("span",{children:"Create a project to give chats their own workspace."})]})]}),A==="notifications"&&L&&a.jsxs("section",{className:"settings-section","aria-labelledby":"settings-notifications-title",children:[a.jsx("header",{className:"settings-section-head",children:a.jsxs("div",{children:[a.jsx("h2",{id:"settings-notifications-title",children:"Notifications"}),a.jsx("p",{children:"Choose when OctiqFlow can bring a chat back to your attention."})]})}),a.jsxs("div",{className:"settings-control-row",children:[a.jsxs("div",{className:"settings-control-copy",children:[a.jsx("h3",{children:"Chat activity"}),a.jsx("p",{children:"Get a banner when a chat you are not watching finishes, needs permission, or asks you a question."})]}),a.jsxs("button",{className:`set-switch${X?" is-on":""}`,type:"button",role:"switch","aria-checked":X,disabled:j,onClick:O,children:[a.jsx("span",{className:"set-switch-track","aria-hidden":"true"}),a.jsx("span",{className:"set-switch-text",children:j?"…":X?"On":"Off"})]})]}),a.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."}),k==="needs-install"&&a.jsxs("p",{className:"set-warn",children:["iPhone and iPad only allow notifications for an app on the home screen. Tap Share, then ",a.jsx("b",{children:"Add to Home Screen"}),", open OctiqFlow from there, and turn this on again."]}),(k==="denied"||b==="denied")&&a.jsx("p",{className:"set-warn",children:"This browser is blocking notifications for OctiqFlow. Allow them in the site settings and come back."}),k==="failed"&&a.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"&&a.jsxs("section",{className:"settings-section settings-appearance","aria-labelledby":"settings-appearance-title",children:[a.jsx("header",{className:"settings-section-head",children:a.jsxs("div",{children:[a.jsx("h2",{id:"settings-appearance-title",children:"Appearance"}),a.jsx("p",{children:"Keep it light, stay focused in dark, add some colour with fun mode, ink it like a manga, go cinematic with 中国风, or go back to Windows XP."})]})}),a.jsx("div",{className:"thm-grid",role:"radiogroup","aria-label":"Appearance",children:__.map(G=>{const B=Gxe(G),F=G.id===t;return a.jsxs("button",{className:`thm${F?" is-on":""}`,"data-theme-id":G.id,type:"button",role:"radio","aria-checked":F,onClick:()=>x(G.id),children:[a.jsxs("span",{className:"thm-shot",style:{background:B.bg},"aria-hidden":"true",children:[a.jsx("span",{className:"thm-bar",style:{background:B.sunken}}),a.jsx("span",{className:"thm-card",style:{background:B.card}}),a.jsx("span",{className:"thm-line",style:{background:B.fg}}),a.jsx("span",{className:"thm-dot",style:{background:B.accent}})]}),a.jsx("span",{className:"thm-name",children:G.name})]},G.id)})}),s&&a.jsxs("div",{className:"settings-chat-width",children:[a.jsx("h3",{id:"settings-chat-width-title",children:"Chat width"}),a.jsx("p",{className:"settings-note",children:"How wide the conversation and the composer are drawn on this browser. Phones always use the whole screen."}),a.jsx("div",{className:"cw-grid",role:"radiogroup","aria-labelledby":"settings-chat-width-title",children:VE.map(G=>{const B=G.id===n,F=G.px==null?100:Math.round(G.px/1200*84);return a.jsxs("button",{className:`thm cw${B?" is-on":""}`,"data-chat-width":G.id,type:"button",role:"radio","aria-checked":B,onClick:()=>s(G.id),children:[a.jsx("span",{className:"cw-shot","aria-hidden":"true",children:a.jsx("span",{className:"cw-column",style:{width:`${F}%`}})}),a.jsx("span",{className:"thm-name",children:G.name}),a.jsx("span",{className:"cw-size",children:G.px==null?"No limit":`${G.px}px`})]},G.id)})})]})]})]})]})]})}function Od({section:t,label:e,detail:n,active:s,onPick:i}){return a.jsxs("button",{className:`settings-nav-item${s?" is-on":""}`,type:"button","aria-current":s?"page":void 0,onClick:()=>i(t),children:[a.jsx(Z0e,{section:t}),a.jsxs("span",{className:"settings-nav-copy",children:[a.jsx("span",{children:e}),a.jsx("small",{children:n})]})]})}function Z0e({section:t}){return t==="agents"?a.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:[a.jsx("circle",{cx:"9",cy:"8",r:"3"}),a.jsx("path",{d:"M3 20c0-3.3 2.7-6 6-6s6 2.7 6 6"}),a.jsx("circle",{cx:"17",cy:"9",r:"2.4"}),a.jsx("path",{d:"M16 14.2c2.9.3 5 2.6 5 5.8"})]}):t==="memory"?a.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:[a.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"}),a.jsx("path",{d:"M12 5v15"})]}):t==="projects"?a.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:[a.jsx("path",{d:"M3 7.5h7l2 2h9v9.5H3z"}),a.jsx("path",{d:"M3 7.5V5h7l2 2h6"})]}):t==="sandbox"?a.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:[a.jsx("path",{d:"m12 3 8 4.5v9L12 21l-8-4.5v-9L12 3Z"}),a.jsx("path",{d:"m4 7.5 8 4.5 8-4.5"}),a.jsx("path",{d:"M12 12v9"})]}):t==="preferences"?a.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:[a.jsx("circle",{cx:"12",cy:"8",r:"3.5"}),a.jsx("path",{d:"M5 20c0-3.9 3.1-7 7-7s7 3.1 7 7"})]}):t==="notifications"?a.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:[a.jsx("path",{d:"M18 8a6 6 0 0 0-12 0c0 7-3 7-3 9h18c0-2-3-2-3-9"}),a.jsx("path",{d:"M10 21h4"})]}):a.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:[a.jsx("circle",{cx:"12",cy:"12",r:"9"}),a.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"}),a.jsx("path",{d:"M3 12h18"})]})}function J0e(){return a.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:a.jsx("path",{d:"M12 5v14M5 12h14"})})}function eye(){return a.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:a.jsx("path",{d:"m9 18 6-6-6-6"})})}function oF(t){const[e,n]=y.useState(Date.now);t&&IC(t,Date.now());const s=t?$V(t,e):null,i=s===null?null:e+s;return y.useEffect(()=>{if(i===null)return;const r=window.setTimeout(()=>n(Date.now()),Math.max(0,i-Date.now()));return()=>window.clearTimeout(r)},[i]),e}const tye=["small","medium","large"],tg={small:"Small",medium:"Medium",large:"Large"},ZE={small:25,medium:75,large:150};async function nye(){return await te.invoke("agent_levels",{})}async function OD(t,e=0){return await te.invoke("agent_level_profile",{agentId:t,offset:e})}async function lF(t,e){return await te.invoke("orchestration_task_accept",{taskId:t,attemptId:e})}async function sye(t,e){await te.invoke("orchestration_task_size",{taskId:t,size:e})}function cF(t){const e=t.nextLevelXp-t.levelXp;return e<=0?0:Math.min(1,Math.max(0,(t.xp-t.levelXp)/e))}function uF(t){return`${Math.max(0,t.nextLevelXp-t.xp).toLocaleString("en-US")} XP to level ${t.level+1}`}function iye(t){if(t<1e3)return String(t);const e=[[1e9,"B"],[1e6,"M"],[1e3,"K"]];for(const[n,s]of e)if(t>=n){const i=t/n;return`${i>=100?Math.round(i):Number(i.toFixed(1))}${s}`}return String(t)}function rye(t){const e=!!t.activeAttemptId,n=!e&&(t.status==="pending"||t.status==="ready"),s=t.size??(e?void 0:"medium");return s?{size:s,editable:n,label:`${tg[s]} · ${ZE[s]} XP`}:{editable:!1,label:"Not recorded · earns no XP"}}function aye(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 hF(t){return t.kind==="person"?"you":t.agentName??"the lead"}function oye(t){return!br(t)||!t.assignee||!t.activeAttemptId?!1:t.acceptance?.attemptId!==t.activeAttemptId}function Lx(t){return new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}const lye={xp:0,level:1,levelXp:0,nextLevelXp:100};function cye({name:t,progress:e,onOpen:n}){const s=e??lye,i=`Level ${s.level} · ${s.xp.toLocaleString("en-US")} XP · ${uF(s)}`;return a.jsxs("button",{type:"button",className:"level-chip",onClick:n,title:i,"aria-label":`${t}: level ${s.level}, ${s.xp} XP. Open profile`,children:[a.jsxs("span",{className:"level-chip-text",children:["Lv ",s.level]}),a.jsx("span",{className:"level-chip-bar","aria-hidden":"true",children:a.jsx("span",{style:{width:`${Math.round(cF(s)*100)}%`}})})]})}function uye({progress:t,name:e}){return a.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:a.jsx("span",{style:{width:`${Math.round(cF(t)*100)}%`}})})}function hye(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 dye({record:t,onOpen:e}){const n=aye(t);return a.jsxs("li",{className:"xp-row",children:[a.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:[a.jsx("span",{className:"dash-item-title",children:t.title}),a.jsxs("span",{className:"dash-item-meta",children:[n.why??(t.size?tg[t.size]:"No size recorded")," · accepted by ",hF(t.acceptedBy)," · ",Lx(t.acceptedAt)]})]}),a.jsx("span",{className:t.xp>0?"xp-gain":"xp-gain is-zero",children:n.amount})]})}function fye({agent:t,connected:e,onOpenRun:n,onChanged:s}){const[i,r]=y.useState(null),[o,l]=y.useState([]),[u,h]=y.useState(""),[f,m]=y.useState(null),[g,x]=y.useState(""),[b,_]=y.useState(0);y.useEffect(()=>{if(!e)return;let E=!0;return OD(t.id,0).then(L=>{E&&(r(L),l([]),h(""))}).catch(L=>{E&&h(String(L.message??L))}),()=>{E=!1}},[t.id,e,b]);const k=i?[...i.history,...o]:[],N=async()=>{if(i){m("more");try{const E=await OD(t.id,k.length);l(L=>[...L,...E.history])}catch(E){h(String(E.message??E))}finally{m(null)}}},j=async(E,L)=>{m(E),x("");try{const O=await lF(E,L);x(O.awarded&&O.award?`Accepted. ${t.name} earned ${O.award.xp} XP.`:`Accepted. ${O.note??"No XP was paid."}`),_(X=>X+1),s()}catch(O){h(String(O.message??O))}finally{m(null)}},M=(E,L)=>{if(E)try{n(E,L)}catch(O){h(String(O.message??O))}},A=i?.usage;return a.jsxs("section",{className:"agent-profile","aria-label":`${t.name}'s profile`,children:[a.jsxs("header",{className:"agent-profile-head",children:[a.jsx(Qs,{name:t.name,avatar:t.avatar,id:t.id,size:44,removed:t.removed,decorative:!0}),a.jsxs("div",{className:"agent-profile-title",children:[a.jsx("h2",{children:a.jsx("bdi",{children:t.name})}),t.detail&&a.jsx("span",{className:"team-row-meta",children:a.jsx("bdi",{children:t.detail})})]})]}),u&&a.jsx("p",{className:"set-warn",role:"alert",children:u}),g&&a.jsx("p",{className:"agent-profile-notice",role:"status",children:g}),!i&&!u&&a.jsx("p",{className:"projects-page-meta",children:"Loading profile…"}),i&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"level-block",children:[a.jsxs("div",{className:"level-head",children:[a.jsxs("strong",{className:"level-number",children:["Level ",i.level]}),a.jsxs("span",{className:"level-xp",children:[i.xp.toLocaleString("en-US")," XP"]})]}),a.jsx(uye,{progress:i,name:t.name}),a.jsx("p",{className:"level-next",children:uF(i)})]}),a.jsxs("dl",{className:"agent-profile-stats",children:[a.jsxs("div",{children:[a.jsx("dt",{children:"Accepted tasks"}),a.jsxs("dd",{title:"Every task accepted for this agent, counted once for good, including those that earned no XP",children:[i.acceptedTasks.toLocaleString("en-US"),a.jsx("span",{className:"agent-profile-stat-note",children:"lifetime"})]})]}),a.jsxs("div",{children:[a.jsx("dt",{children:"Tokens used"}),a.jsx("dd",{title:A&&A.chats>0?`${A.total.toLocaleString("en-US")} tokens`:void 0,children:A?A.chats===0?"None recorded":iye(A.total):"Unavailable"})]})]}),i.awaiting.length>0&&a.jsxs("section",{className:"agent-profile-section","aria-label":"Waiting for acceptance",children:[a.jsx("h3",{children:"Waiting for acceptance"}),a.jsx("ul",{className:"agent-profile-list",children:i.awaiting.map(E=>a.jsxs("li",{className:"xp-row",children:[a.jsxs("button",{type:"button",className:"xp-row-open",onClick:()=>M(E.coordinatorChatKey,E.runId),"aria-label":`Open task: ${E.title}`,children:[a.jsx("span",{className:"dash-item-title",children:E.title}),a.jsxs("span",{className:"dash-item-meta",children:[E.size?tg[E.size]:"No size recorded",E.unscored?" · earns no XP":""," · finished ",Lx(E.finishedAt)]})]}),a.jsx("button",{type:"button",className:"vault-button xp-accept",disabled:f!==null||!e,onClick:()=>{j(E.taskId,E.attemptId)},children:f===E.taskId?"Accepting…":"Accept"})]},E.taskId))})]}),a.jsxs("section",{className:"agent-profile-section","aria-label":"XP history",children:[a.jsx("h3",{children:"XP history"}),k.length===0?a.jsx("p",{className:"projects-page-meta",children:"No accepted tasks yet."}):a.jsx("ul",{className:"agent-profile-list",children:k.map(E=>a.jsx(dye,{record:E,onOpen:()=>M(E.coordinatorChatKey,E.runId)},`${E.taskId}:${E.attemptId}`))}),k.length<i.historyTotal&&a.jsx("button",{type:"button",className:"dash-more",disabled:f!==null,onClick:()=>{N()},children:f==="more"?"Loading…":`Show more (${i.historyTotal-k.length})`})]}),A&&a.jsxs("details",{className:"agent-profile-details",children:[a.jsx("summary",{children:"Token usage"}),a.jsxs("dl",{className:"plan-card-facts",children:[a.jsx("dt",{children:"Input"}),a.jsxs("dd",{children:[A.usage.input.toLocaleString("en-US"),a.jsxs("span",{className:"plan-card-note",children:[A.usage.cachedInput.toLocaleString("en-US")," from cache",A.usage.cacheWrite>0?`, ${A.usage.cacheWrite.toLocaleString("en-US")} written to cache`:""]})]}),a.jsx("dt",{children:"Output"}),a.jsxs("dd",{children:[A.usage.output.toLocaleString("en-US"),A.reasoningReported&&a.jsxs("span",{className:"plan-card-note",children:[A.usage.reasoning.toLocaleString("en-US")," reasoning (Codex only)"]})]}),a.jsx("dt",{children:"Chats"}),a.jsx("dd",{children:hye(A)})]}),a.jsxs("p",{className:"agent-profile-fine",children:["Counted since ",Lx(A.since||i.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."]})]}),i.usageError&&a.jsx("p",{className:"set-warn",role:"alert",children:i.usageError}),a.jsxs("details",{className:"agent-profile-details",children:[a.jsx("summary",{children:"How levels work"}),a.jsxs("ul",{className:"agent-profile-rules",children:[a.jsxs("li",{children:["XP is paid when you or the responsible lead accept a finished task:"," ",i.rules.sizes.map(([E,L])=>`${tg[E].toLowerCase()} ${L}`).join(", "),"."]}),a.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."}),a.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."}),a.jsxs("li",{children:["Level 1 starts at 0 XP. Going from level L to L+1 takes ",i.rules.levelStep," × L XP."]}),a.jsx("li",{children:"Only accepted tasks in missions count. Work in ordinary chats is not scored."}),a.jsxs("li",{children:["Scoring began ",Lx(i.scoringSince),". Tasks finished before then are not scored."]}),a.jsx("li",{children:"Token usage is shown for information only. It does not affect XP."})]})]})]})]})}const ID=3;function pye({snapshot:t,ledgerError:e,connected:n,projects:s,running:i,busy:r,waitingOn:o,held:l,chatTitle:u,chatExists:h,onOpenChat:f,onOpenRun:m,onManage:g,onClose:x}){const[b,_]=y.useState(null),[k,N]=y.useState([]),[j,M]=y.useState([]),[A,E]=y.useState(""),[L,O]=y.useState(null),[X,q]=y.useState(new Set),[$,G]=y.useState(""),[B,F]=y.useState(new Map),[z,W]=y.useState(0),[H,U]=y.useState(null),ee=a0("heading"),Q=a0("actions"),I=!!ee&&!Q,Y=y.useMemo(()=>(t?.tasks??[]).filter(ae=>ae.acceptance).map(ae=>`${ae.id}:${ae.acceptance.attemptId}`).sort().join(","),[t]);y.useEffect(()=>{if(!n)return;let ae=!0;return nye().then($e=>{ae&&F(new Map(($e??[]).map(He=>[He.agentId,He])))}).catch(()=>{ae&&F(new Map)}),()=>{ae=!1}},[n,Y,z]),y.useEffect(()=>{if(!n)return;let ae=!0;Promise.all([yo(null,!0),L2(),hw().catch(()=>[])]).then(([He,Wt,yt])=>{ae&&(_(He),N(yt),M(Wt),E(""))}).catch(He=>{ae&&E(String(He.message??He))});const $e=YE(()=>{yo(null,!0).then(He=>{ae&&_(He)}).catch(()=>{})});return()=>{ae=!1,$e()}},[n]);const J=y.useMemo(()=>[...i].sort().join(",")+"|"+[...r].sort().join(","),[i,r]);y.useEffect(()=>{if(!n)return;let ae=!0;return te.invoke("chat_activity").then($e=>{ae&&O(new Map(($e??[]).map(He=>[He.key,He.busy])))}).catch(()=>{ae&&O(null)}),()=>{ae=!1}},[n,J]);const P=ae=>{const $e=ae.replace(/^chat:/,"");if(r.has($e))return"busy";const He=L?.get(ae);return He!==void 0?He?"busy":"idle":L?"ended":i.has($e)?"unknown":"ended"},ne=y.useMemo(()=>s.map(({id:ae,name:$e})=>({id:ae,name:$e})),[s]),he=oF(t?.tasks),le=Rme({team:b,leads:j,snapshot:t,projects:ne,teams:k,providerLabel:ae=>`${tr[ae.agent]} ${l0(ae)}`,chatTitle:u,chatExists:h,leadActivity:P,waitingOn:o,held:l,now:he}),oe=Dme(le),ye=!n||!!e,D=ae=>s.find($e=>$e.id===ae),Oe=ae=>{G("");try{if(ae.chatKey)f(ae.chatKey);else if(ae.runId){const $e=t?.runs.find(He=>He.id===ae.runId);$e&&m($e.coordinatorChatKey,$e.id)}}catch($e){G(String($e.message??$e))}},ze=ae=>!!ae.chatKey||!!ae.runId&&!!t?.runs.some($e=>$e.id===ae.runId),Ce=H?le.find(ae=>ae.id===H):void 0;if(H&&Ce)return a.jsxs("section",{className:"projects-page agents-dashboard","aria-label":"Agents",children:[a.jsx(Sf,{root:!0,back:{label:"All agents",ariaLabel:"Back to all agents",onClick:()=>U(null)},title:a.jsx("h1",{children:Ce.name}),actions:a.jsx("button",{type:"button",className:"projects-page-secondary",onClick:g,children:"Manage agents"})}),a.jsx("div",{className:"projects-page-body",children:a.jsx(fye,{agent:Ce,connected:n,onOpenRun:m,onChanged:()=>W(ae=>ae+1)})})]});const ve=ae=>q($e=>{const He=new Set($e);return He.has(ae)?He.delete(ae):He.add(ae),He}),Ie=a.jsx("button",{type:"button",className:"projects-page-secondary",onClick:g,children:"Manage agents"});return a.jsxs("section",{className:"projects-page agents-dashboard","aria-label":"Agents",children:[a.jsx(Sf,{root:!0,back:{label:"Chat",ariaLabel:"Back to chat",onClick:x},title:a.jsx("h1",{children:"Agents"}),actions:I?void 0:Ie}),a.jsxs("div",{className:"projects-page-body",children:[a.jsxs("div",{className:`dash-top${I?" has-manage":""}`,children:[a.jsx("p",{className:"projects-page-meta dash-summary","aria-live":"polite",children:b===null&&!A?"Loading agents…":oe.length===0?"Who is doing what":oe.map(({state:ae,count:$e})=>`${$e} ${r0[ae].toLowerCase()}`).join(" · ")}),I&&Ie]}),ye&&b!==null&&a.jsx("p",{className:"dash-stale",role:"status",children:n?"Could not refresh work. Showing the last known state.":"Disconnected. Showing the last known state."}),A&&a.jsx("p",{className:"set-warn",role:"alert",children:A}),$&&a.jsx("p",{className:"set-warn",role:"alert",children:$}),b!==null&&le.length===0?a.jsxs("div",{className:"settings-empty",children:[a.jsx("strong",{children:"No agents yet"}),a.jsx("button",{className:"vault-button",type:"button",onClick:g,children:"Add agents in Settings"})]}):a.jsx("ul",{className:"team-list agents-dashboard-list",children:le.map(ae=>a.jsx(gye,{row:ae,stale:ye,expanded:X.has(ae.id),onToggle:()=>ve(ae.id),appearance:D,canOpen:ze,onOpen:Oe,level:B.get(ae.id),onProfile:()=>U(ae.id),onOpenRecent:$e=>{G("");try{f($e)}catch(He){G(String(He.message??He))}}},ae.id))})]})]})}function mye({row:t}){const e=[a.jsx("bdi",{children:t.detail},"runs")];return t.removed||(t.effort&&e.push(t.effort),e.push(t.scope?a.jsx("bdi",{children:t.scope.name},"scope"):"All projects"),t.reportsTo&&e.push(a.jsxs("span",{children:["Reports to ",a.jsx("bdi",{children:t.reportsTo.name})]},"reports"))),a.jsx("span",{className:"team-row-meta dash-agent-meta",children:e.map((n,s)=>a.jsxs(y.Fragment,{children:[s>0&&a.jsx("span",{"aria-hidden":"true",children:" · "}),a.jsx("span",{className:"dash-meta-part",children:n})]},s))})}function gye({row:t,stale:e,expanded:n,onToggle:s,appearance:i,canOpen:r,onOpen:o,onOpenRecent:l,level:u,onProfile:h}){const f=t.state==="working"&&!e,m=n?t.activities:t.activities.slice(0,ID),g=Object.entries(t.counts).filter(([b])=>b!==t.state),x=r0[t.state];return a.jsxs("li",{className:"dash-agent","data-state":t.state,style:{"--team-depth":t.depth},children:[a.jsxs("div",{className:"dash-agent-head",children:[t.depth>0&&a.jsx("span",{className:"team-row-branch","aria-hidden":"true",children:"└"}),a.jsx(Qs,{name:t.name,avatar:t.avatar,id:t.id,size:28,removed:t.removed,className:f?"dash-avatar is-working":"dash-avatar",label:`${t.name}, ${x.toLowerCase()}`}),a.jsxs("span",{className:"team-row-copy",children:[a.jsxs("span",{className:"team-row-name",children:[a.jsx("bdi",{children:t.name}),!t.removed&&a.jsx(cye,{name:t.name,progress:u,onOpen:h}),t.team&&a.jsx("span",{className:"team-tag team-badge",title:`On the team ${t.team.name}`,children:a.jsx("bdi",{children:t.team.name})})]}),a.jsx(mye,{row:t})]}),a.jsxs("span",{className:"dash-agent-status",children:[a.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}),g.map(([b,_])=>a.jsxs("span",{className:`dash-count is-${b}`,children:[_," ",r0[b].toLowerCase()]},b))]})]}),t.role&&a.jsx(nF,{className:"dash-agent-role",text:t.role,name:t.name}),t.activities.length>0?a.jsxs("div",{className:"dash-agent-work",children:[m.map(b=>a.jsxs("button",{className:"dash-item",type:"button","data-state":b.state,"data-tone":b.tone,title:b.detail,"aria-description":b.detail,disabled:!r(b),onClick:()=>o(b),"aria-label":`${b.label}: ${b.title}${b.project?`, in ${b.project.name}`:""}. Open ${b.kind==="lead"?"conversation":"task"}`,children:[a.jsx("span",{className:`dash-dot is-${b.state}`,"aria-hidden":"true"}),a.jsxs("span",{className:"dash-item-copy",children:[a.jsx("span",{className:"dash-item-title",children:b.title}),a.jsxs("span",{className:"dash-item-meta",children:[a.jsx("span",{className:"dash-item-state",children:b.label}),b.project?a.jsxs("span",{className:"dash-item-project",children:[i(b.project.id)&&a.jsx(Mh,{project:i(b.project.id),size:"tiny"}),a.jsx("bdi",{children:b.project.name})]}):b.crossProject?a.jsx("span",{className:"dash-item-project",children:"Across projects"}):null]})]}),a.jsx("span",{className:"dash-item-open","aria-hidden":"true",children:"Open"})]},b.key)),t.activities.length>ID&&a.jsx("button",{className:"dash-more",type:"button","aria-expanded":n,onClick:s,children:n?"Show fewer":`Show all ${t.activities.length}`})]}):t.recent?a.jsx("div",{className:"dash-agent-work",children:a.jsxs("button",{className:"dash-recent",type:"button",onClick:()=>l(t.recent.chatKey),"aria-label":`Open last: ${t.recent.title}`,children:["Last: ",a.jsx("span",{className:"dash-item-title",children:t.recent.title})]})}):null]})}function vye({name:t,chats:e,now:n,onContinue:s}){if(!e.length)return null;const i=`Continue with ${t}`;return a.jsxs("section",{className:"hero-continue","aria-label":i,children:[a.jsx("h2",{className:"hero-continue-label",children:i}),a.jsx("ul",{className:"hero-continue-list",children:e.map(r=>{const o=r.opening?.trim()||"Your earlier conversation",l=Ha(r.createdAt,n);return a.jsx("li",{children:a.jsxs("button",{type:"button",className:"hero-continue-row",title:o,"aria-label":`Continue “${o}”, started ${l}`,onClick:()=>s(r),children:[a.jsx("span",{className:"hero-continue-text",children:o}),a.jsx("span",{className:"hero-continue-time",children:l})]})},r.chatKey)})})]})}function xye(t){return!!t.headId&&t.recipientId===t.headId}function yye(t){return(t??"").trim().toLowerCase()==="general"}function bye(t){const{toHead:e,project:n,homeId:s,repo:i,sandboxDefault:r}=t,o=t.overrides??{},l=Object.values(o).some(k=>k!==void 0);if(e)return{target:"home",projectId:s??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=o.projectId!==void 0?o.projectId:n?.id??null;if(!u||u===s||u===n?.id&&yye(n?.name))return{target:"home",projectId:u??s??null,prepare:!1,branch:"",newWorktree:!1,useSandbox:o.useSandbox??!1,chosenBy:l?"advanced":"auto",reason:"No code project: works from your home workspace.",crossProject:!1};const f=!!i&&!i.loading&&!i.error,m=o.branch??(f&&i.isRepo?i.current:""),g=o.newWorktree??!0,x=o.useSandbox??r,b=m||"the project's current branch",_=l?"Chosen under Advanced.":f&&!i.isRepo?"Not a Git repository: works in the project folder.":`New worktree from ${b}, so the primary checkout stays untouched.`;return{target:"project",projectId:u,prepare:!0,branch:m,newWorktree:g,useSandbox:x,chosenBy:l?"advanced":"auto",reason:_,crossProject:!1}}function wye(t,e,n,s){const i=t.filter(h=>h.width>0),r=h=>h.reduce((f,m)=>f+m.width,0)+n*Math.max(0,h.length-1);if(r(i)<=e)return[];const o=i.map((h,f)=>({item:h,index:f})).sort((h,f)=>h.item.keep-f.item.keep||f.index-h.index),l=new Set;let u=i;for(const{item:h}of o)if(l.add(h.id),u=u.filter(f=>f.id!==h.id),r(u)+(u.length?n:0)+s<=e)break;return i.filter(h=>l.has(h.id)).map(h=>h.id)}function dF(t,e,n){const s=Math.abs(t),i=s>1,r=s+n<e-1;return[i?"start":"",r?"end":""].filter(Boolean).join(" ")}function _ye(t){return t.onChat?t.actions>0||t.arriving?!0:!t.loaded&&(t.chat||t.remembered):!1}const fF="octiq.v2.actionBar";function kye(t){return!t.onChat||!t.loaded||t.arriving?null:t.actions>0?"1":"0"}const Sye=6e4,Cye=15e3,pF="octiq.v2.usage",mF={data:{claude:null,codex:null},stale:{claude:!0,codex:!0},asked:!1};function jye(){try{const t=JSON.parse(ls(pF)||"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}}}let gF=null,T2=0,Cb=null;const fw=new Set;function R2(){return gF??={...mF,data:jye()}}function BD(t){gF=t;for(const e of fw)e()}async function Mm(t){if(!(!t&&Date.now()-T2<Cye)){T2=Date.now();try{const e=await te.invoke("usage_summary"),n=(r,o)=>r?.available?r:o?.available?o:r??o??null,s=R2().data,i={claude:n(e?.claude,s.claude),codex:n(e?.codex,s.codex)};nn(pF,JSON.stringify({claude:i.claude?.available?i.claude:s.claude,codex:i.codex?.available?i.codex:s.codex})),BD({data:i,stale:{claude:!e?.claude?.available,codex:!e?.codex?.available},asked:!0})}catch{BD({...R2(),stale:{claude:!0,codex:!0},asked:!0})}}}function Nye(t){if(fw.add(t),!Cb){Mm(T2===0);const e=setInterval(()=>{Mm(!0)},Sye),n=()=>document.visibilityState==="visible"&&void Mm(!1);document.addEventListener("visibilitychange",n),window.addEventListener("focus",n),Cb=()=>{clearInterval(e),document.removeEventListener("visibilitychange",n),window.removeEventListener("focus",n)}}return()=>{fw.delete(t),fw.size===0&&(Cb?.(),Cb=null)}}function vF(){return y.useSyncExternalStore(Nye,R2,()=>mF)}const Aye=60,Eye=85,xF={claude:"Claude",codex:"Codex"};function JE(t){return t>=Eye?"is-danger":t>=Aye?"is-warn":""}const Tx=t=>Math.min(100,Math.max(0,t));function yF(t,e=Date.now()){if(!t)return"";const n=t-e/1e3;if(n<=0)return"resetting";const s=Math.floor(n/3600),i=Math.floor(n%3600/60);return s>=24?`resets in ${Math.floor(s/24)}d ${s%24}h`:s?`resets in ${s}h ${i}m`:`resets in ${i}m`}function bF(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,s)=>s.window.percent>n.window.percent?s:n)}function Mye(t){let e=null;for(const n of["claude","codex"]){const s=bF(t[n]);if(!s)continue;const i=Tx(s.window.percent);(!e||i>e.percent)&&(e={provider:n,label:s.label,percent:i})}return e}function Lye(t){const e=["claude","codex"].flatMap(n=>{const s=bF(t[n]);return s?[`${xF[n]} ${s.label} ${Math.round(Tx(s.window.percent))}%`]:[]});return e.length?`Plan usage: ${e.join(", ")}`:"Plan usage: no reading yet"}const wF="No reading yet.";function Tye(t){const e=t.trim();return e?e[0].toUpperCase()+e.slice(1):"Model"}function Rye(t,e){const n=[];for(const s of["claude","codex"]){const i=xF[s],r=t[s],o={provider:s,stale:e[s],note:r?.note||void 0},l=n.length;r?.fiveHour&&n.push({...o,key:`${s}:5h`,label:`${i} 5h`,name:`${i} 5-hour window`,percent:Tx(r.fiveHour.percent),resetsAt:r.fiveHour.resetsAt}),r?.weekly&&n.push({...o,key:`${s}:week`,label:`${i} week`,name:`${i} weekly window`,percent:Tx(r.weekly.percent),resetsAt:r.weekly.resetsAt});for(const u of r?.models??[]){const h=Tye(u.name);n.push({...o,key:`${s}:week:${u.name}`,label:`${h} week`,name:`${i} weekly window for ${h}`,percent:Tx(u.percent),resetsAt:u.resetsAt})}n.length===l&&n.push({provider:s,key:s,label:i,name:i,percent:null,stale:!1,note:r?.note||(r?"Plan usage is not available.":wF)})}return n}function _F(t){return`${Number.isInteger(t)?t:t.toFixed(1)}%`}function kF(t,e=Date.now()){return t.percent===null?`${t.name}: ${t.note??wF}`:[`${t.name}: ${_F(t.percent)} used`,yF(t.resetsAt,e),t.stale?"last known":"",t.note??""].filter(Boolean).join(" · ")}function Dye(t,e=Date.now()){return t.length?`Plan usage. ${t.map(n=>kF(n,e)).join(". ")}`:"Plan usage: no reading yet"}const Oye=180;function Iye({antigravity:t=!1}={}){const e=vF(),{data:n,stale:s,asked:i}=e,[r,o]=y.useState(null),l=y.useRef(null),u=!!(n.claude||n.codex),h=gf(u),f=y.useCallback(()=>{l.current&&clearTimeout(l.current),l.current=null},[]);if(y.useEffect(()=>f,[f]),!u)return i?null:a.jsx("div",{className:"usage gate-held","aria-hidden":"true",children:a.jsxs("span",{className:"usage-btn enter-gated",children:[a.jsx($D,{}),a.jsx("span",{className:"usage-val",children:"00%"})]})});const m=Mye(n);return a.jsxs("div",{className:`usage ${mh(h)}`,onPointerEnter:g=>{g.pointerType==="mouse"&&(f(),o(x=>x??"hover"),Mm(!1))},onPointerLeave:g=>{g.pointerType==="mouse"&&(f(),l.current=setTimeout(()=>o(x=>x==="hover"?null:x),Oye))},children:[a.jsxs("button",{className:`usage-btn enter-gated${m&&s[m.provider]?" is-stale":""}`,type:"button","aria-label":Lye(n),"aria-haspopup":"dialog","aria-expanded":r!==null,title:"Plan usage — hover or tap for every window",onClick:()=>{f(),o(g=>g==="pin"?null:"pin"),Mm(!0)},children:[a.jsx($D,{}),a.jsx("span",{className:`usage-val ${m?JE(m.percent):""}`,children:m?a.jsx(Kt,{children:`${Math.round(m.percent)}%`}):"—"})]}),r&&a.jsxs(a.Fragment,{children:[r==="pin"&&a.jsx("div",{className:"usage-scrim",onClick:()=>o(null)}),a.jsx(SF,{feed:e,antigravity:t})]})]})}function Bye(){const t=vF();return a.jsx($ye,{feed:t,onAsk:Mm})}function $ye({feed:t,onAsk:e,now:n=Date.now(),initiallyOpen:s=!1}){const[i,r]=y.useState(s),o=y.useRef(null),l=y.useRef(null),u=y.useRef(null),{data:h,stale:f,asked:m}=t,g=y.useCallback(()=>{const k=l.current;if(!k||!o.current)return;const N=dF(k.scrollLeft,k.scrollWidth,k.clientWidth);o.current.dataset.cut!==N&&(o.current.dataset.cut=N)},[]);y.useLayoutEffect(()=>{g();const k=l.current;if(!k||typeof ResizeObserver>"u")return;const N=new ResizeObserver(g);return N.observe(k),k.firstElementChild&&N.observe(k.firstElementChild),()=>N.disconnect()},[g,m]);const x=m||!!(h.claude||h.codex),b=gf(x),_=x?Rye(h,f):[];return a.jsxs("div",{className:`usage-strip ${mh(b)}`,ref:o,onKeyDown:k=>{k.key!=="Escape"||!i||(k.preventDefault(),r(!1),u.current?.focus())},children:[a.jsx("div",{className:"usage-strip-scroll",ref:l,onScroll:g,children:x&&a.jsx("button",{ref:u,className:"usage-strip-btn enter-gated",type:"button","aria-label":Dye(_,n),"aria-haspopup":"dialog","aria-expanded":i,onClick:()=>{r(k=>!k),e?.(!0)},children:_.map(k=>{const N=k.percent===null?"":JE(k.percent);return a.jsxs("span",{className:`usage-cell${k.stale?" is-stale":""}`,"data-provider":k.provider,title:kF(k,n),children:[a.jsx("span",{className:"usage-cell-label",children:k.label}),k.percent===null?a.jsx("span",{className:"usage-cell-none",children:"—"}):a.jsxs(a.Fragment,{children:[a.jsx("span",{className:`usage-track ${N}`,children:a.jsx("span",{className:"usage-fill",style:{width:`${k.percent}%`}})}),a.jsx("span",{className:`usage-val ${N}`,children:a.jsx(Kt,{children:`${Math.round(k.percent)}%`})})]})]},k.key)})})}),i&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"usage-scrim",onClick:()=>r(!1)}),a.jsx(SF,{feed:t,antigravity:!1})]})]})}function SF({feed:t,antigravity:e}){return a.jsxs("div",{className:"usage-pop",role:"dialog","aria-label":"Plan usage",children:[a.jsx(PD,{name:"Claude",provider:t.data.claude,stale:t.stale.claude}),a.jsx(PD,{name:"Codex",provider:t.data.codex,stale:t.stale.codex}),e&&a.jsxs("section",{className:"usage-block",children:[a.jsx("header",{className:"usage-block-head",children:a.jsx("span",{className:"usage-block-name",children:"Antigravity"})}),a.jsx("div",{className:"usage-empty",children:"Antigravity does not report plan usage."})]})]})}function $D(){return a.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:[a.jsx("path",{d:"M4.5 18a9 9 0 1 1 15 0"}),a.jsx("path",{d:"m12 13 3.5-4"}),a.jsx("circle",{cx:"12",cy:"13",r:"1"})]})}function PD({name:t,provider:e,stale:n}){return a.jsxs("section",{className:"usage-block",children:[a.jsxs("header",{className:"usage-block-head",children:[a.jsx("span",{className:"usage-block-name",children:t}),e?.plan&&a.jsx("span",{className:"usage-plan",children:e.plan}),n&&a.jsx("span",{className:"usage-stale",children:"last known"})]}),e?a.jsxs(a.Fragment,{children:[a.jsx(FS,{label:"5 hours",window:e.fiveHour}),a.jsx(FS,{label:"Week",window:e.weekly}),(e.models??[]).map(s=>a.jsx(FS,{label:`Week · ${s.name}`,window:s},s.name)),e.note&&a.jsx("div",{className:"usage-empty",children:e.note})]}):a.jsx("div",{className:"usage-empty",children:"No reading yet."})]})}function FS({label:t,window:e}){if(!e)return null;const n=Math.min(100,Math.max(0,e.percent));return a.jsxs("div",{className:"usage-row",children:[a.jsx("span",{className:"usage-row-label",children:t}),a.jsx("span",{className:`usage-track ${JE(n)}`,children:a.jsx("span",{className:"usage-fill",style:{width:`${n}%`}})}),a.jsx("span",{className:"usage-val",children:a.jsx(Kt,{children:_F(n)})}),a.jsx("span",{className:"usage-reset",children:a.jsx(Kt,{children:yF(e.resetsAt)})})]})}const Lm="octiq-git-changed";function Pye(t){const e=new Set;for(const n of t)for(const s of[n.primary_path,...n.paths??[]])s?.trim()&&e.add(s);return[...e]}function zye(t){return[...new Set(t.flatMap(e=>e.primary_path?.trim()?[e.primary_path]:[]))]}function Fye(t,e){const n=new Map(e.map(i=>[i.path,i])),s={};for(const i of t){if(!i.primary_path)continue;const r=n.get(i.primary_path);r?.is_repo&&r.branch&&(s[i.id]=r.branch)}return s}const Hye={added:{letter:"A",cls:"is-add"},deleted:{letter:"D",cls:"is-del"},renamed:{letter:"R",cls:"is-ren"},untracked:{letter:"U",cls:"is-new"}},Wye={letter:"M",cls:"is-mod"},CF=["rebase","merge","ff-only"],zD="octiq.v2.gitPullMode",qye="octiq.v2.gitWidth",Uye={initial:380,min:280,max:680},Vye=/^(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 jF(t){return t?[t.primary_path??"",...t.paths??[]].filter(e=>e.trim()!=="").join(`
378
+ `),onClick:()=>s(f),children:[a.jsx(Qs,{name:f.name,avatar:f.avatar,id:f.id,size:20,decorative:!0}),a.jsx("span",{className:"lead-chip-name",children:f.name}),g&&a.jsx("span",{className:"lead-chip-meta",children:g})]},f.id)})}),r&&a.jsx("p",{className:"lead-picker-note",children:a.jsx("button",{type:"button",onClick:i,children:"Manage agents"})})]})}function QE({text:t,max:e}){const n=GE(t),s=n>e;return a.jsxs("small",{className:`team-field-count${s?" is-over":""}`,children:[n.toLocaleString("en-US")," / ",e.toLocaleString("en-US"),s?" · too long":""]})}function z0e({saved:t,text:e,loading:n,busy:s,unread:i=!1,onChange:r,onSave:o,onClear:l}){const u=e.trim()!==t.trim(),h=GE(e)>$S;return n=n||i,a.jsxs("form",{className:"agent-policy","aria-labelledby":"agent-policy-title",onSubmit:f=>{f.preventDefault(),u&&!h&&!i&&o()},children:[a.jsxs("div",{className:"team-field-head",children:[a.jsx("h3",{id:"agent-policy-title",children:"Agent policy"}),a.jsx(QE,{text:e,max:$S})]}),a.jsx("p",{className:"settings-note",id:"agent-policy-hint",children:"Shared rules for every agent. Prepended to every agent's brief, ahead of its persistent prompt and role, so rules everyone follows need not be copied into each role. Applies to new chats and tasks."}),a.jsx("textarea",{className:"agent-policy-text","aria-labelledby":"agent-policy-title","aria-describedby":"agent-policy-hint",value:e,maxLength:$S,rows:5,disabled:n||s,placeholder:"e.g. Work in a git worktree. Never push or release without asking.",onChange:f=>r(f.target.value)}),a.jsxs("div",{className:"agent-policy-actions",children:[a.jsx("button",{className:"vault-button",type:"button",disabled:n||s||!t,onClick:l,children:"Clear"}),a.jsx("button",{className:"settings-primary",type:"submit",disabled:n||s||!u||h,children:s?"Saving…":"Save policy"})]})]})}function iF(){return a.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:[a.jsx("path",{d:"M4 20h4L19 9a2.8 2.8 0 0 0-4-4L4 16v4Z"}),a.jsx("path",{d:"m13.5 6.5 4 4"})]})}function rF(){return a.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:[a.jsx("path",{d:"M4 7h16"}),a.jsx("path",{d:"M10 11v6M14 11v6"}),a.jsx("path",{d:"M6 7l1 13h10l1-13"}),a.jsx("path",{d:"M9 7V4h6v3"})]})}function F0e({teams:t,agents:e,draft:n,projects:s,projectName:i,onDraft:r,onSave:o,onRemove:l}){const u=a.jsxs("form",{className:"team-group-form","aria-label":n?.id?"Rename team":"New team",onSubmit:h=>{h.preventDefault(),o()},children:[a.jsx("input",{value:n?.name??"",maxLength:60,placeholder:"Team name","aria-label":"Team name",autoFocus:!0,onChange:h=>n&&r({...n,name:h.target.value})}),a.jsxs("select",{"aria-label":"Team available in",value:n?.projectId??"",onChange:h=>n&&r({...n,projectId:h.target.value||null}),children:[a.jsx("option",{value:"",children:"Every project"}),s.map(h=>a.jsx("option",{value:h.id,children:h.name},h.id))]}),a.jsx("button",{className:"vault-button",type:"button",onClick:()=>r(null),children:"Cancel"}),a.jsx("button",{className:"settings-primary",type:"submit",disabled:!n?.name.trim(),children:n?.id?"Save":"Add"})]});return a.jsxs("div",{className:"team-groups",children:[a.jsxs("div",{className:"team-head",children:[a.jsx("h3",{children:"Teams"}),a.jsx("button",{className:"vault-button",type:"button",disabled:!!n&&!n.id,onClick:()=>r({name:"",projectId:null}),children:"Add team"})]}),a.jsx("p",{className:"settings-note",children:"Agents on one team may ask each other questions while they work. Teammates answer; they never take the work, and a team changes no one's manager."}),n&&!n.id&&u,t.length>0&&a.jsx("ul",{className:"team-group-list","aria-label":"Teams",children:t.map(h=>{const f=e.filter(m=>m.teamId===h.id).length;return n?.id===h.id?a.jsx("li",{children:u},h.id):a.jsxs("li",{className:"team-group-row",children:[a.jsxs("span",{className:"team-group-copy",children:[a.jsx("span",{className:"team-row-name",children:a.jsx("bdi",{children:h.name})}),a.jsxs("span",{className:"team-row-meta",children:[f," ",f===1?"agent":"agents"," · ",h.projectId?i(h.projectId)??"Removed project":"Every project"]})]}),a.jsxs("span",{className:"team-row-actions",children:[a.jsxs("button",{className:"vault-button team-row-action",type:"button","aria-label":`Rename ${h.name}`,title:"Rename",onClick:()=>r({id:h.id,name:h.name,projectId:h.projectId??null}),children:[a.jsx(iF,{}),a.jsx("span",{className:"team-row-action-text",children:"Rename"})]}),a.jsxs("button",{className:"vault-button team-row-action",type:"button","aria-label":`Remove team ${h.name}`,title:"Remove team",onClick:()=>l(h),children:[a.jsx(rF,{}),a.jsx("span",{className:"team-row-action-text",children:"Remove"})]})]})]},h.id)})})]})}function aF({agent:t,model:e,effort:n,onProvider:s,onModel:i,onEffort:r,disabled:o}){return a.jsxs(a.Fragment,{children:[a.jsxs("label",{children:[a.jsx("span",{children:"Provider"}),a.jsx("select",{value:t,disabled:o,onChange:l=>s(l.target.value),children:I0e.map(l=>a.jsx("option",{value:l,children:tr[l]},l))})]}),a.jsxs("label",{children:[a.jsx("span",{children:"Model"}),a.jsx("select",{value:e,disabled:o,onChange:l=>i(l.target.value),children:XE(t).map(l=>a.jsx("option",{value:l.flag,children:l.model},l.id))})]}),a.jsxs("label",{children:[a.jsx("span",{children:"Effort"}),a.jsx("select",{value:n??"",disabled:o,onChange:l=>r(l.target.value),children:EC[t].map(l=>a.jsx("option",{value:l.id,children:l.label},l.id))})]})]})}function H0e({desk:t,roster:e,headId:n,loading:s,busy:i,onPick:r,onCreate:o,onSettings:l}){const u=e.filter(f=>!f.projectId),h=u.filter(f=>f.id!==t?.id&&MD(f,e,n));return a.jsxs("div",{className:"front-desk-block",children:[a.jsxs("div",{className:"settings-control-row team-choice-row",children:[a.jsxs("div",{className:"settings-control-copy",children:[a.jsx("h3",{children:"Front desk"}),a.jsx("p",{children:"Every new chat opens on it. It works out who should handle what you ask and opens that agent's chat once you confirm on a card. Its own chats are never listed."})]}),a.jsxs("select",{className:"team-head-select","aria-label":"Front desk",value:t?.id??"",disabled:s||i,onChange:f=>r(f.target.value||null),children:[a.jsx("option",{value:"",children:"No front desk"}),u.map(f=>{const m=f.id===t?.id?null:MD(f,e,n);return a.jsxs("option",{value:f.id,disabled:!!m,children:[f.name,m?" · not available":""]},f.id)})]})]}),h.length>0&&a.jsxs("p",{className:"settings-note front-desk-unavailable",children:["Not available: ",h.map(f=>f.name).join(", "),". The lead you talk to across projects and agents who manage others keep their own chats; a front desk's chats are hidden and it only routes."]}),t?a.jsxs("div",{className:"front-desk-model",role:"group","aria-label":`What ${t.name} runs on`,children:[a.jsx(aF,{agent:t.agent,model:t.model,effort:t.effort,disabled:i,onProvider:f=>l({agent:f,...dw(f)}),onModel:f=>l({agent:t.agent,model:f,effort:t.effort}),onEffort:f=>l({agent:t.agent,model:t.model,effort:f})}),a.jsxs("p",{className:"settings-note",children:["Now ",tr[t.agent]," ",l0(t),t.effort?` · ${t.effort}`:"",". Used from the next new chat."]})]}):a.jsxs("div",{className:"front-desk-create",children:[a.jsx("button",{className:"settings-primary",type:"button",disabled:s||i,onClick:o,children:"Create front desk"}),a.jsxs("span",{className:"settings-note",children:["A router on ",tr.claude," ",l0({agent:"claude",model:dw("claude").model}),", ",dw("claude").effort," effort. You can change what it runs on here after."]})]})]})}function W0e({draft:t,team:e,teams:n,projects:s,saving:i,onChange:r,onSave:o,onCancel:l}){const u=tL[t.agent],h=k=>r({...t,...k}),f=k=>{const N=XE(k)[0]?.flag??"",j=EC[k].some(A=>A.id===t.effort)?t.effort:EC[k][0]?.id,M=tL[k].some(A=>A.id===t.access)?t.access:"auto";r({...t,agent:k,model:N,effort:j,access:M})},m=eF(t),g=new Set;if(t.id){let k=!0;for(g.add(t.id);k;){k=!1;for(const N of e)N.reportsTo&&g.has(N.reportsTo)&&!g.has(N.id)&&(g.add(N.id),k=!0)}}const x=e.filter(k=>!g.has(k.id)&&(!k.projectId||k.projectId===(t.projectId||void 0))),b=AD(n,t.projectId),_=k=>{const N=!t.teamId||AD(n,k).some(j=>j.id===t.teamId);h({projectId:k,...N?{}:{teamId:null}})};return a.jsxs("form",{className:"team-form",onSubmit:k=>{k.preventDefault(),o()},children:[a.jsxs("label",{children:[a.jsx("span",{children:"Name"}),a.jsx("input",{value:t.name,maxLength:60,placeholder:"e.g. Reviewer",autoFocus:!0,onChange:k=>h({name:k.target.value})})]}),a.jsx(S0e,{name:t.name,role:t.role,avatar:t.avatar,agentId:t.id,onChange:k=>h({avatar:k})},t.id??"new"),a.jsxs("label",{className:"team-form-wide",children:[a.jsx("span",{children:"Role"}),a.jsx("textarea",{value:t.role,maxLength:s0e,rows:3,placeholder:"What this agent is good at, and what it should take on",onChange:k=>h({role:k.target.value})})]}),a.jsxs("label",{className:"team-form-wide",children:[a.jsxs("span",{className:"team-field-head",children:[a.jsx("span",{children:"Persistent prompt"}),a.jsx(QE,{text:t.persistentPrompt??"",max:CD})]}),a.jsx("textarea",{value:t.persistentPrompt??"",maxLength:CD,rows:4,"aria-describedby":"team-persistent-prompt-hint",placeholder:"Runbooks, tool rules, how this agent builds and checks its work",onChange:k=>h({persistentPrompt:k.target.value})}),a.jsx("small",{className:"team-field-note",id:"team-persistent-prompt-hint",children:"This agent's standing instructions. Sent ahead of its role in every brief it starts with, after the agent policy; never shown in the roster or to other agents. Applies to new chats and tasks."})]}),a.jsx(aF,{agent:t.agent,model:t.model,effort:t.effort,onProvider:f,onModel:k=>h({model:k}),onEffort:k=>h({effort:k})}),a.jsxs("label",{children:[a.jsx("span",{children:"Access"}),a.jsx("select",{value:t.access,onChange:k=>h({access:k.target.value}),children:u.map(k=>a.jsx("option",{value:k.id,children:k.label},k.id))}),Hn(t.agent).accessNote&&a.jsx("small",{className:"team-field-note",children:u.find(k=>k.id===t.access)?.hint})]}),a.jsxs("label",{children:[a.jsx("span",{children:"Reports to"}),a.jsxs("select",{value:t.reportsTo??"",onChange:k=>h({reportsTo:k.target.value||null}),children:[a.jsx("option",{value:"",children:"You"}),x.map(k=>a.jsx("option",{value:k.id,children:k.name},k.id))]})]}),a.jsxs("label",{children:[a.jsx("span",{children:"Available in"}),a.jsxs("select",{value:t.projectId??"",onChange:k=>_(k.target.value||null),children:[a.jsx("option",{value:"",children:"Every project"}),s.map(k=>a.jsx("option",{value:k.id,children:k.name},k.id))]})]}),a.jsxs("label",{children:[a.jsx("span",{children:"Team"}),a.jsxs("select",{value:t.teamId??"",onChange:k=>h({teamId:k.target.value||null}),children:[a.jsx("option",{value:"",children:"None"}),b.map(k=>a.jsx("option",{value:k.id,children:k.name},k.id))]})]}),m&&a.jsx("p",{className:"settings-note team-form-wide",children:"Fable and Astra can lead a task, but they cannot be given one."}),a.jsxs("div",{className:"team-form-actions team-form-wide",children:[a.jsx("button",{className:"vault-button",type:"button",onClick:l,children:"Cancel"}),a.jsx("button",{className:"settings-primary",type:"submit",disabled:i||!t.name.trim()||!t.model,children:i?"Saving…":t.id?"Save":"Add"})]})]})}function q0e(){const{snapshot:t,error:e,refresh:n}=DN(),[s,i]=y.useState(!1),[r,o]=y.useState(null),l=t?.defaultEnabled??!1;async function u(){i(!0),o(null);try{await te.invoke("sandbox_configure",{enabled:!l}),await n()}catch(h){o(String(h.message??h))}finally{i(!1)}}return a.jsxs("section",{className:"settings-section","aria-labelledby":"settings-sandbox-title",children:[a.jsx("header",{className:"settings-section-head",children:a.jsxs("div",{children:[a.jsx("h2",{id:"settings-sandbox-title",children:"Sandbox"}),a.jsx("p",{children:"Run a separate test app and database for each chat on the OctiqFlow host."})]})}),a.jsxs("div",{className:"settings-control-row",children:[a.jsxs("div",{className:"settings-control-copy",children:[a.jsx("h3",{children:"Use sandbox for new chats"}),a.jsx("p",{children:"Set the default. You can change the checkbox before starting each new chat."})]}),a.jsxs("button",{className:`set-switch${l?" is-on":""}`,type:"button",role:"switch","aria-label":"Use sandbox for new chats","aria-checked":l,disabled:s||!t,onClick:()=>{u()},children:[a.jsx("span",{className:"set-switch-track","aria-hidden":"true"}),a.jsx("span",{className:"set-switch-text",children:s?"…":l?"On":"Off"})]})]}),a.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)&&a.jsx("p",{className:"set-warn",role:"alert",children:r||e})]})}const zS=4e3;async function U0e(){return await te.invoke("personal_preferences",{})??{text:"",updatedAt:0}}async function V0e(t){return await te.invoke("personal_preferences_set",{text:t})}function K0e(){const[t,e]=y.useState(""),[n,s]=y.useState(""),[i,r]=y.useState(!0),[o,l]=y.useState(!1),[u,h]=y.useState(""),[f,m]=y.useState(!1),[g,x]=y.useState(!1);y.useEffect(()=>{let _=!0;return U0e().then(k=>{_&&(e(k.text),s(k.text))}).catch(k=>{_&&(x(!0),h(String(k)))}).finally(()=>{_&&r(!1)}),()=>{_=!1}},[]);async function b(_){l(!0),h(""),m(!1);try{const k=await V0e(_);e(k.text),s(k.text),m(!0)}catch(k){h(String(k))}finally{l(!1)}}return a.jsxs("section",{className:"settings-section","aria-labelledby":"preferences-title",children:[a.jsx("header",{className:"settings-section-head",children:a.jsxs("div",{children:[a.jsx("h2",{id:"preferences-title",children:"Personal preferences"}),a.jsx("p",{children:"How you like every agent to work with you, in your own words."})]})}),a.jsx(G0e,{saved:t,text:n,loading:i,busy:o,done:f,unread:g,onChange:_=>{s(_),m(!1)},onSave:()=>{b(n)},onClear:()=>{b("")}}),u&&a.jsx("p",{className:"set-warn",role:"alert",children:u})]})}function G0e({saved:t,text:e,loading:n,busy:s,done:i,unread:r=!1,onChange:o,onSave:l,onClear:u}){const h=e.trim()!==t.trim(),f=GE(e)>zS;return n=n||r,a.jsxs("form",{className:"agent-policy","aria-labelledby":"preferences-field",onSubmit:m=>{m.preventDefault(),h&&!f&&!r&&l()},children:[a.jsxs("div",{className:"team-field-head",children:[a.jsx("h3",{id:"preferences-field",children:"Added to every chat"}),a.jsx(QE,{text:e,max:zS})]}),a.jsx("p",{className:"settings-note",id:"preferences-hint",children:"Ends the system prompt of every chat OctiqFlow starts: any agent, any project, the front desk and task workers included. A chat that is already running picks up a change the next time it starts or resumes."}),a.jsx("textarea",{className:"agent-policy-text","aria-labelledby":"preferences-field","aria-describedby":"preferences-hint",value:e,maxLength:zS,rows:8,disabled:n||s,placeholder:"e.g. Reply in British English. Keep answers short and put the conclusion first. I work on a Mac.",onChange:m=>o(m.target.value)}),a.jsxs("div",{className:"agent-policy-actions",children:[i&&!h&&a.jsx("span",{className:"settings-note",role:"status",children:"Saved"}),a.jsx("button",{className:"vault-button",type:"button",disabled:n||s||!t,onClick:u,children:"Clear"}),a.jsx("button",{className:"settings-primary",type:"submit",disabled:n||s||!h||f,children:s?"Saving…":"Save preferences"})]})]})}const Y0e=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});function X0e(t,e){return Y0e.compare(t.name,e.name)||t.name.localeCompare(e.name)||t.id.localeCompare(e.id)}function Q0e({current:t,onPick:e,chatWidth:n=o0,onChatWidth:s,notify:i,onNotify:r,projects:o,onProject:l,agentsMode:u=!1,onAgentsMode:h,onFeedback:f,initialSection:m="projects",onClose:g}){const x=G=>{Yz(G),e(G)},[b,_]=y.useState(UC),[k,N]=y.useState(""),[j,M]=y.useState(!1),[A,E]=y.useState(m),L=K_()||ag()||F6(),O=async()=>{if(!j){M(!0),N("");try{if(i){await GY(),Hk(!1),r(!1,!1);return}const G=await KY();if(_(UC()),G==="on"){Hk(!0),r(!0,!0);return}if(G==="denied"){N("denied");return}if(G==="needs-install"){N("needs-install");return}const B=await FY();if(_(B),B!=="granted"){N("denied");return}Hk(!0),r(!0,!1)}finally{M(!1)}}},X=i&&b==="granted",q=__.find(G=>G.id===t)?.name??"Dark",$=[...o].sort(X0e);return a.jsxs("section",{className:"settings-page","aria-labelledby":"settings-title",children:[a.jsx(Sf,{root:!0,back:{label:"Chat",ariaLabel:"Back to chat",onClick:g},title:a.jsx("h1",{id:"settings-title",children:"Settings"})}),a.jsxs("div",{className:"settings-layout",children:[a.jsxs("nav",{className:"settings-nav","aria-label":"Settings sections",children:[a.jsxs("div",{className:"settings-nav-list",children:[a.jsx(Od,{section:"projects",label:"Projects",detail:`${o.length} ${o.length===1?"project":"projects"}`,active:A==="projects",onPick:E}),a.jsx(Od,{section:"preferences",label:"Personal preferences",detail:"In every chat's system prompt",active:A==="preferences",onPick:E}),h&&a.jsx(Od,{section:"agents",label:"Agents",detail:u?"Agents mode on":"Agents mode off",active:A==="agents",onPick:E}),L&&a.jsx(Od,{section:"notifications",label:"Notifications",detail:X?"On":"Off",active:A==="notifications",onPick:E}),a.jsx(Od,{section:"sandbox",label:"Sandbox",detail:"Local test environments",active:A==="sandbox",onPick:E}),a.jsx(Od,{section:"memory",label:"Memory Vault",detail:"Shared agent knowledge",active:A==="memory",onPick:E}),a.jsx(Od,{section:"appearance",label:"Appearance",detail:n===o0?q:`${q} · ${KE(n).name} chat`,active:A==="appearance",onPick:E}),f&&a.jsxs("button",{className:"settings-nav-item",type:"button","aria-haspopup":"dialog",onClick:f,children:[a.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:[a.jsx("path",{d:"M4 4h16v13H9l-5 4V4Z"}),a.jsx("path",{d:"M8 8h8M8 12h5"})]}),a.jsxs("span",{className:"settings-nav-copy",children:[a.jsx("span",{children:"Feedback inbox"}),a.jsx("small",{children:"Reports from your agents"})]})]})]}),a.jsxs("p",{className:"settings-nav-foot",children:["Switches apply automatically.",a.jsxs("span",{className:"settings-version",children:["OctiqFlow v","0.3.13"]})]})]}),a.jsxs("div",{className:"settings-content",children:[A==="preferences"&&a.jsx(K0e,{}),A==="sandbox"&&a.jsx(q0e,{}),A==="memory"&&a.jsx(e0e,{}),A==="agents"&&h&&a.jsx($0e,{on:u,onToggle:h,projects:$}),A==="projects"&&a.jsxs("section",{className:"settings-section","aria-labelledby":"settings-projects-title",children:[a.jsxs("header",{className:"settings-section-head",children:[a.jsxs("div",{children:[a.jsx("h2",{id:"settings-projects-title",children:"Projects"}),a.jsx("p",{children:"Manage names, folders, environment, links, and visibility."})]}),a.jsxs("button",{className:"settings-primary",type:"button",onClick:()=>l("new"),children:[a.jsx(J0e,{}),a.jsx("span",{children:"New project"})]})]}),o.length?a.jsx("div",{className:"settings-projects",children:$.map(G=>a.jsxs("button",{className:"settings-project",type:"button",onClick:()=>l(G.id),"aria-label":`Configure ${G.name}`,children:[a.jsx(Mh,{project:G,size:"medium"}),a.jsxs("span",{className:"settings-project-copy",children:[a.jsx("span",{className:"settings-project-name",children:G.name}),G.primary_path&&a.jsx("span",{className:"settings-project-path",title:G.primary_path,children:a.jsx("bdi",{children:G.primary_path})})]}),G.shelved&&a.jsx("span",{className:"settings-project-state",children:"Shelved"}),a.jsx(eye,{})]},G.id))}):a.jsxs("div",{className:"settings-empty",children:[a.jsx("strong",{children:"No projects yet"}),a.jsx("span",{children:"Create a project to give chats their own workspace."})]})]}),A==="notifications"&&L&&a.jsxs("section",{className:"settings-section","aria-labelledby":"settings-notifications-title",children:[a.jsx("header",{className:"settings-section-head",children:a.jsxs("div",{children:[a.jsx("h2",{id:"settings-notifications-title",children:"Notifications"}),a.jsx("p",{children:"Choose when OctiqFlow can bring a chat back to your attention."})]})}),a.jsxs("div",{className:"settings-control-row",children:[a.jsxs("div",{className:"settings-control-copy",children:[a.jsx("h3",{children:"Chat activity"}),a.jsx("p",{children:"Get a banner when a chat you are not watching finishes, needs permission, or asks you a question."})]}),a.jsxs("button",{className:`set-switch${X?" is-on":""}`,type:"button",role:"switch","aria-checked":X,disabled:j,onClick:O,children:[a.jsx("span",{className:"set-switch-track","aria-hidden":"true"}),a.jsx("span",{className:"set-switch-text",children:j?"…":X?"On":"Off"})]})]}),a.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."}),k==="needs-install"&&a.jsxs("p",{className:"set-warn",children:["iPhone and iPad only allow notifications for an app on the home screen. Tap Share, then ",a.jsx("b",{children:"Add to Home Screen"}),", open OctiqFlow from there, and turn this on again."]}),(k==="denied"||b==="denied")&&a.jsx("p",{className:"set-warn",children:"This browser is blocking notifications for OctiqFlow. Allow them in the site settings and come back."}),k==="failed"&&a.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"&&a.jsxs("section",{className:"settings-section settings-appearance","aria-labelledby":"settings-appearance-title",children:[a.jsx("header",{className:"settings-section-head",children:a.jsxs("div",{children:[a.jsx("h2",{id:"settings-appearance-title",children:"Appearance"}),a.jsx("p",{children:"Keep it light, stay focused in dark, add some colour with fun mode, ink it like a manga, go cinematic with 中国风, or go back to Windows XP."})]})}),a.jsx("div",{className:"thm-grid",role:"radiogroup","aria-label":"Appearance",children:__.map(G=>{const B=Gxe(G),F=G.id===t;return a.jsxs("button",{className:`thm${F?" is-on":""}`,"data-theme-id":G.id,type:"button",role:"radio","aria-checked":F,onClick:()=>x(G.id),children:[a.jsxs("span",{className:"thm-shot",style:{background:B.bg},"aria-hidden":"true",children:[a.jsx("span",{className:"thm-bar",style:{background:B.sunken}}),a.jsx("span",{className:"thm-card",style:{background:B.card}}),a.jsx("span",{className:"thm-line",style:{background:B.fg}}),a.jsx("span",{className:"thm-dot",style:{background:B.accent}})]}),a.jsx("span",{className:"thm-name",children:G.name})]},G.id)})}),s&&a.jsxs("div",{className:"settings-chat-width",children:[a.jsx("h3",{id:"settings-chat-width-title",children:"Chat width"}),a.jsx("p",{className:"settings-note",children:"How wide the conversation and the composer are drawn on this browser. Phones always use the whole screen."}),a.jsx("div",{className:"cw-grid",role:"radiogroup","aria-labelledby":"settings-chat-width-title",children:VE.map(G=>{const B=G.id===n,F=G.px==null?100:Math.round(G.px/1200*84);return a.jsxs("button",{className:`thm cw${B?" is-on":""}`,"data-chat-width":G.id,type:"button",role:"radio","aria-checked":B,onClick:()=>s(G.id),children:[a.jsx("span",{className:"cw-shot","aria-hidden":"true",children:a.jsx("span",{className:"cw-column",style:{width:`${F}%`}})}),a.jsx("span",{className:"thm-name",children:G.name}),a.jsx("span",{className:"cw-size",children:G.px==null?"No limit":`${G.px}px`})]},G.id)})})]})]})]})]})]})}function Od({section:t,label:e,detail:n,active:s,onPick:i}){return a.jsxs("button",{className:`settings-nav-item${s?" is-on":""}`,type:"button","aria-current":s?"page":void 0,onClick:()=>i(t),children:[a.jsx(Z0e,{section:t}),a.jsxs("span",{className:"settings-nav-copy",children:[a.jsx("span",{children:e}),a.jsx("small",{children:n})]})]})}function Z0e({section:t}){return t==="agents"?a.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:[a.jsx("circle",{cx:"9",cy:"8",r:"3"}),a.jsx("path",{d:"M3 20c0-3.3 2.7-6 6-6s6 2.7 6 6"}),a.jsx("circle",{cx:"17",cy:"9",r:"2.4"}),a.jsx("path",{d:"M16 14.2c2.9.3 5 2.6 5 5.8"})]}):t==="memory"?a.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:[a.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"}),a.jsx("path",{d:"M12 5v15"})]}):t==="projects"?a.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:[a.jsx("path",{d:"M3 7.5h7l2 2h9v9.5H3z"}),a.jsx("path",{d:"M3 7.5V5h7l2 2h6"})]}):t==="sandbox"?a.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:[a.jsx("path",{d:"m12 3 8 4.5v9L12 21l-8-4.5v-9L12 3Z"}),a.jsx("path",{d:"m4 7.5 8 4.5 8-4.5"}),a.jsx("path",{d:"M12 12v9"})]}):t==="preferences"?a.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:[a.jsx("circle",{cx:"12",cy:"8",r:"3.5"}),a.jsx("path",{d:"M5 20c0-3.9 3.1-7 7-7s7 3.1 7 7"})]}):t==="notifications"?a.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:[a.jsx("path",{d:"M18 8a6 6 0 0 0-12 0c0 7-3 7-3 9h18c0-2-3-2-3-9"}),a.jsx("path",{d:"M10 21h4"})]}):a.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:[a.jsx("circle",{cx:"12",cy:"12",r:"9"}),a.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"}),a.jsx("path",{d:"M3 12h18"})]})}function J0e(){return a.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:a.jsx("path",{d:"M12 5v14M5 12h14"})})}function eye(){return a.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:a.jsx("path",{d:"m9 18 6-6-6-6"})})}function oF(t){const[e,n]=y.useState(Date.now);t&&IC(t,Date.now());const s=t?$V(t,e):null,i=s===null?null:e+s;return y.useEffect(()=>{if(i===null)return;const r=window.setTimeout(()=>n(Date.now()),Math.max(0,i-Date.now()));return()=>window.clearTimeout(r)},[i]),e}const tye=["small","medium","large"],tg={small:"Small",medium:"Medium",large:"Large"},ZE={small:25,medium:75,large:150};async function nye(){return await te.invoke("agent_levels",{})}async function OD(t,e=0){return await te.invoke("agent_level_profile",{agentId:t,offset:e})}async function lF(t,e){return await te.invoke("orchestration_task_accept",{taskId:t,attemptId:e})}async function sye(t,e){await te.invoke("orchestration_task_size",{taskId:t,size:e})}function cF(t){const e=t.nextLevelXp-t.levelXp;return e<=0?0:Math.min(1,Math.max(0,(t.xp-t.levelXp)/e))}function uF(t){return`${Math.max(0,t.nextLevelXp-t.xp).toLocaleString("en-US")} XP to level ${t.level+1}`}function iye(t){if(t<1e3)return String(t);const e=[[1e9,"B"],[1e6,"M"],[1e3,"K"]];for(const[n,s]of e)if(t>=n){const i=t/n;return`${i>=100?Math.round(i):Number(i.toFixed(1))}${s}`}return String(t)}function rye(t){const e=!!t.activeAttemptId,n=!e&&(t.status==="pending"||t.status==="ready"),s=t.size??(e?void 0:"medium");return s?{size:s,editable:n,label:`${tg[s]} · ${ZE[s]} XP`}:{editable:!1,label:"Not recorded · earns no XP"}}function aye(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 hF(t){return t.kind==="person"?"you":t.agentName??"the lead"}function oye(t){return!br(t)||!t.assignee||!t.activeAttemptId?!1:t.acceptance?.attemptId!==t.activeAttemptId}function Lx(t){return new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}const lye={xp:0,level:1,levelXp:0,nextLevelXp:100};function cye({name:t,progress:e,onOpen:n}){const s=e??lye,i=`Level ${s.level} · ${s.xp.toLocaleString("en-US")} XP · ${uF(s)}`;return a.jsxs("button",{type:"button",className:"level-chip",onClick:n,title:i,"aria-label":`${t}: level ${s.level}, ${s.xp} XP. Open profile`,children:[a.jsxs("span",{className:"level-chip-text",children:["Lv ",s.level]}),a.jsx("span",{className:"level-chip-bar","aria-hidden":"true",children:a.jsx("span",{style:{width:`${Math.round(cF(s)*100)}%`}})})]})}function uye({progress:t,name:e}){return a.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:a.jsx("span",{style:{width:`${Math.round(cF(t)*100)}%`}})})}function hye(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 dye({record:t,onOpen:e}){const n=aye(t);return a.jsxs("li",{className:"xp-row",children:[a.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:[a.jsx("span",{className:"dash-item-title",children:t.title}),a.jsxs("span",{className:"dash-item-meta",children:[n.why??(t.size?tg[t.size]:"No size recorded")," · accepted by ",hF(t.acceptedBy)," · ",Lx(t.acceptedAt)]})]}),a.jsx("span",{className:t.xp>0?"xp-gain":"xp-gain is-zero",children:n.amount})]})}function fye({agent:t,connected:e,onOpenRun:n,onChanged:s}){const[i,r]=y.useState(null),[o,l]=y.useState([]),[u,h]=y.useState(""),[f,m]=y.useState(null),[g,x]=y.useState(""),[b,_]=y.useState(0);y.useEffect(()=>{if(!e)return;let E=!0;return OD(t.id,0).then(L=>{E&&(r(L),l([]),h(""))}).catch(L=>{E&&h(String(L.message??L))}),()=>{E=!1}},[t.id,e,b]);const k=i?[...i.history,...o]:[],N=async()=>{if(i){m("more");try{const E=await OD(t.id,k.length);l(L=>[...L,...E.history])}catch(E){h(String(E.message??E))}finally{m(null)}}},j=async(E,L)=>{m(E),x("");try{const O=await lF(E,L);x(O.awarded&&O.award?`Accepted. ${t.name} earned ${O.award.xp} XP.`:`Accepted. ${O.note??"No XP was paid."}`),_(X=>X+1),s()}catch(O){h(String(O.message??O))}finally{m(null)}},M=(E,L)=>{if(E)try{n(E,L)}catch(O){h(String(O.message??O))}},A=i?.usage;return a.jsxs("section",{className:"agent-profile","aria-label":`${t.name}'s profile`,children:[a.jsxs("header",{className:"agent-profile-head",children:[a.jsx(Qs,{name:t.name,avatar:t.avatar,id:t.id,size:44,removed:t.removed,decorative:!0}),a.jsxs("div",{className:"agent-profile-title",children:[a.jsx("h2",{children:a.jsx("bdi",{children:t.name})}),t.detail&&a.jsx("span",{className:"team-row-meta",children:a.jsx("bdi",{children:t.detail})})]})]}),u&&a.jsx("p",{className:"set-warn",role:"alert",children:u}),g&&a.jsx("p",{className:"agent-profile-notice",role:"status",children:g}),!i&&!u&&a.jsx("p",{className:"projects-page-meta",children:"Loading profile…"}),i&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"level-block",children:[a.jsxs("div",{className:"level-head",children:[a.jsxs("strong",{className:"level-number",children:["Level ",i.level]}),a.jsxs("span",{className:"level-xp",children:[i.xp.toLocaleString("en-US")," XP"]})]}),a.jsx(uye,{progress:i,name:t.name}),a.jsx("p",{className:"level-next",children:uF(i)})]}),a.jsxs("dl",{className:"agent-profile-stats",children:[a.jsxs("div",{children:[a.jsx("dt",{children:"Accepted tasks"}),a.jsxs("dd",{title:"Every task accepted for this agent, counted once for good, including those that earned no XP",children:[i.acceptedTasks.toLocaleString("en-US"),a.jsx("span",{className:"agent-profile-stat-note",children:"lifetime"})]})]}),a.jsxs("div",{children:[a.jsx("dt",{children:"Tokens used"}),a.jsx("dd",{title:A&&A.chats>0?`${A.total.toLocaleString("en-US")} tokens`:void 0,children:A?A.chats===0?"None recorded":iye(A.total):"Unavailable"})]})]}),i.awaiting.length>0&&a.jsxs("section",{className:"agent-profile-section","aria-label":"Waiting for acceptance",children:[a.jsx("h3",{children:"Waiting for acceptance"}),a.jsx("ul",{className:"agent-profile-list",children:i.awaiting.map(E=>a.jsxs("li",{className:"xp-row",children:[a.jsxs("button",{type:"button",className:"xp-row-open",onClick:()=>M(E.coordinatorChatKey,E.runId),"aria-label":`Open task: ${E.title}`,children:[a.jsx("span",{className:"dash-item-title",children:E.title}),a.jsxs("span",{className:"dash-item-meta",children:[E.size?tg[E.size]:"No size recorded",E.unscored?" · earns no XP":""," · finished ",Lx(E.finishedAt)]})]}),a.jsx("button",{type:"button",className:"vault-button xp-accept",disabled:f!==null||!e,onClick:()=>{j(E.taskId,E.attemptId)},children:f===E.taskId?"Accepting…":"Accept"})]},E.taskId))})]}),a.jsxs("section",{className:"agent-profile-section","aria-label":"XP history",children:[a.jsx("h3",{children:"XP history"}),k.length===0?a.jsx("p",{className:"projects-page-meta",children:"No accepted tasks yet."}):a.jsx("ul",{className:"agent-profile-list",children:k.map(E=>a.jsx(dye,{record:E,onOpen:()=>M(E.coordinatorChatKey,E.runId)},`${E.taskId}:${E.attemptId}`))}),k.length<i.historyTotal&&a.jsx("button",{type:"button",className:"dash-more",disabled:f!==null,onClick:()=>{N()},children:f==="more"?"Loading…":`Show more (${i.historyTotal-k.length})`})]}),A&&a.jsxs("details",{className:"agent-profile-details",children:[a.jsx("summary",{children:"Token usage"}),a.jsxs("dl",{className:"plan-card-facts",children:[a.jsx("dt",{children:"Input"}),a.jsxs("dd",{children:[A.usage.input.toLocaleString("en-US"),a.jsxs("span",{className:"plan-card-note",children:[A.usage.cachedInput.toLocaleString("en-US")," from cache",A.usage.cacheWrite>0?`, ${A.usage.cacheWrite.toLocaleString("en-US")} written to cache`:""]})]}),a.jsx("dt",{children:"Output"}),a.jsxs("dd",{children:[A.usage.output.toLocaleString("en-US"),A.reasoningReported&&a.jsxs("span",{className:"plan-card-note",children:[A.usage.reasoning.toLocaleString("en-US")," reasoning (Codex only)"]})]}),a.jsx("dt",{children:"Chats"}),a.jsx("dd",{children:hye(A)})]}),a.jsxs("p",{className:"agent-profile-fine",children:["Counted since ",Lx(A.since||i.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."]})]}),i.usageError&&a.jsx("p",{className:"set-warn",role:"alert",children:i.usageError}),a.jsxs("details",{className:"agent-profile-details",children:[a.jsx("summary",{children:"How levels work"}),a.jsxs("ul",{className:"agent-profile-rules",children:[a.jsxs("li",{children:["XP is paid when you or the responsible lead accept a finished task:"," ",i.rules.sizes.map(([E,L])=>`${tg[E].toLowerCase()} ${L}`).join(", "),"."]}),a.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."}),a.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."}),a.jsxs("li",{children:["Level 1 starts at 0 XP. Going from level L to L+1 takes ",i.rules.levelStep," × L XP."]}),a.jsx("li",{children:"Only accepted tasks in missions count. Work in ordinary chats is not scored."}),a.jsxs("li",{children:["Scoring began ",Lx(i.scoringSince),". Tasks finished before then are not scored."]}),a.jsx("li",{children:"Token usage is shown for information only. It does not affect XP."})]})]})]})]})}const ID=3;function pye({snapshot:t,ledgerError:e,connected:n,projects:s,running:i,busy:r,waitingOn:o,held:l,chatTitle:u,chatExists:h,onOpenChat:f,onOpenRun:m,onManage:g,onClose:x}){const[b,_]=y.useState(null),[k,N]=y.useState([]),[j,M]=y.useState([]),[A,E]=y.useState(""),[L,O]=y.useState(null),[X,q]=y.useState(new Set),[$,G]=y.useState(""),[B,F]=y.useState(new Map),[z,W]=y.useState(0),[H,U]=y.useState(null),ee=a0("heading"),Q=a0("actions"),I=!!ee&&!Q,Y=y.useMemo(()=>(t?.tasks??[]).filter(ae=>ae.acceptance).map(ae=>`${ae.id}:${ae.acceptance.attemptId}`).sort().join(","),[t]);y.useEffect(()=>{if(!n)return;let ae=!0;return nye().then($e=>{ae&&F(new Map(($e??[]).map(He=>[He.agentId,He])))}).catch(()=>{ae&&F(new Map)}),()=>{ae=!1}},[n,Y,z]),y.useEffect(()=>{if(!n)return;let ae=!0;Promise.all([yo(null,!0),L2(),hw().catch(()=>[])]).then(([He,Wt,yt])=>{ae&&(_(He),N(yt),M(Wt),E(""))}).catch(He=>{ae&&E(String(He.message??He))});const $e=YE(()=>{yo(null,!0).then(He=>{ae&&_(He)}).catch(()=>{})});return()=>{ae=!1,$e()}},[n]);const J=y.useMemo(()=>[...i].sort().join(",")+"|"+[...r].sort().join(","),[i,r]);y.useEffect(()=>{if(!n)return;let ae=!0;return te.invoke("chat_activity").then($e=>{ae&&O(new Map(($e??[]).map(He=>[He.key,He.busy])))}).catch(()=>{ae&&O(null)}),()=>{ae=!1}},[n,J]);const P=ae=>{const $e=ae.replace(/^chat:/,"");if(r.has($e))return"busy";const He=L?.get(ae);return He!==void 0?He?"busy":"idle":L?"ended":i.has($e)?"unknown":"ended"},ne=y.useMemo(()=>s.map(({id:ae,name:$e})=>({id:ae,name:$e})),[s]),he=oF(t?.tasks),le=Rme({team:b,leads:j,snapshot:t,projects:ne,teams:k,providerLabel:ae=>`${tr[ae.agent]} ${l0(ae)}`,chatTitle:u,chatExists:h,leadActivity:P,waitingOn:o,held:l,now:he}),oe=Dme(le),ye=!n||!!e,D=ae=>s.find($e=>$e.id===ae),Oe=ae=>{G("");try{if(ae.chatKey)f(ae.chatKey);else if(ae.runId){const $e=t?.runs.find(He=>He.id===ae.runId);$e&&m($e.coordinatorChatKey,$e.id)}}catch($e){G(String($e.message??$e))}},ze=ae=>!!ae.chatKey||!!ae.runId&&!!t?.runs.some($e=>$e.id===ae.runId),Ce=H?le.find(ae=>ae.id===H):void 0;if(H&&Ce)return a.jsxs("section",{className:"projects-page agents-dashboard","aria-label":"Agents",children:[a.jsx(Sf,{root:!0,back:{label:"All agents",ariaLabel:"Back to all agents",onClick:()=>U(null)},title:a.jsx("h1",{children:Ce.name}),actions:a.jsx("button",{type:"button",className:"projects-page-secondary",onClick:g,children:"Manage agents"})}),a.jsx("div",{className:"projects-page-body",children:a.jsx(fye,{agent:Ce,connected:n,onOpenRun:m,onChanged:()=>W(ae=>ae+1)})})]});const ve=ae=>q($e=>{const He=new Set($e);return He.has(ae)?He.delete(ae):He.add(ae),He}),Ie=a.jsx("button",{type:"button",className:"projects-page-secondary",onClick:g,children:"Manage agents"});return a.jsxs("section",{className:"projects-page agents-dashboard","aria-label":"Agents",children:[a.jsx(Sf,{root:!0,back:{label:"Chat",ariaLabel:"Back to chat",onClick:x},title:a.jsx("h1",{children:"Agents"}),actions:I?void 0:Ie}),a.jsxs("div",{className:"projects-page-body",children:[a.jsxs("div",{className:`dash-top${I?" has-manage":""}`,children:[a.jsx("p",{className:"projects-page-meta dash-summary","aria-live":"polite",children:b===null&&!A?"Loading agents…":oe.length===0?"Who is doing what":oe.map(({state:ae,count:$e})=>`${$e} ${r0[ae].toLowerCase()}`).join(" · ")}),I&&Ie]}),ye&&b!==null&&a.jsx("p",{className:"dash-stale",role:"status",children:n?"Could not refresh work. Showing the last known state.":"Disconnected. Showing the last known state."}),A&&a.jsx("p",{className:"set-warn",role:"alert",children:A}),$&&a.jsx("p",{className:"set-warn",role:"alert",children:$}),b!==null&&le.length===0?a.jsxs("div",{className:"settings-empty",children:[a.jsx("strong",{children:"No agents yet"}),a.jsx("button",{className:"vault-button",type:"button",onClick:g,children:"Add agents in Settings"})]}):a.jsx("ul",{className:"team-list agents-dashboard-list",children:le.map(ae=>a.jsx(gye,{row:ae,stale:ye,expanded:X.has(ae.id),onToggle:()=>ve(ae.id),appearance:D,canOpen:ze,onOpen:Oe,level:B.get(ae.id),onProfile:()=>U(ae.id),onOpenRecent:$e=>{G("");try{f($e)}catch(He){G(String(He.message??He))}}},ae.id))})]})]})}function mye({row:t}){const e=[a.jsx("bdi",{children:t.detail},"runs")];return t.removed||(t.effort&&e.push(t.effort),e.push(t.scope?a.jsx("bdi",{children:t.scope.name},"scope"):"All projects"),t.reportsTo&&e.push(a.jsxs("span",{children:["Reports to ",a.jsx("bdi",{children:t.reportsTo.name})]},"reports"))),a.jsx("span",{className:"team-row-meta dash-agent-meta",children:e.map((n,s)=>a.jsxs(y.Fragment,{children:[s>0&&a.jsx("span",{"aria-hidden":"true",children:" · "}),a.jsx("span",{className:"dash-meta-part",children:n})]},s))})}function gye({row:t,stale:e,expanded:n,onToggle:s,appearance:i,canOpen:r,onOpen:o,onOpenRecent:l,level:u,onProfile:h}){const f=t.state==="working"&&!e,m=n?t.activities:t.activities.slice(0,ID),g=Object.entries(t.counts).filter(([b])=>b!==t.state),x=r0[t.state];return a.jsxs("li",{className:"dash-agent","data-state":t.state,style:{"--team-depth":t.depth},children:[a.jsxs("div",{className:"dash-agent-head",children:[t.depth>0&&a.jsx("span",{className:"team-row-branch","aria-hidden":"true",children:"└"}),a.jsx(Qs,{name:t.name,avatar:t.avatar,id:t.id,size:28,removed:t.removed,className:f?"dash-avatar is-working":"dash-avatar",label:`${t.name}, ${x.toLowerCase()}`}),a.jsxs("span",{className:"team-row-copy",children:[a.jsxs("span",{className:"team-row-name",children:[a.jsx("bdi",{children:t.name}),!t.removed&&a.jsx(cye,{name:t.name,progress:u,onOpen:h}),t.team&&a.jsx("span",{className:"team-tag team-badge",title:`On the team ${t.team.name}`,children:a.jsx("bdi",{children:t.team.name})})]}),a.jsx(mye,{row:t})]}),a.jsxs("span",{className:"dash-agent-status",children:[a.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}),g.map(([b,_])=>a.jsxs("span",{className:`dash-count is-${b}`,children:[_," ",r0[b].toLowerCase()]},b))]})]}),t.role&&a.jsx(nF,{className:"dash-agent-role",text:t.role,name:t.name}),t.activities.length>0?a.jsxs("div",{className:"dash-agent-work",children:[m.map(b=>a.jsxs("button",{className:"dash-item",type:"button","data-state":b.state,"data-tone":b.tone,title:b.detail,"aria-description":b.detail,disabled:!r(b),onClick:()=>o(b),"aria-label":`${b.label}: ${b.title}${b.project?`, in ${b.project.name}`:""}. Open ${b.kind==="lead"?"conversation":"task"}`,children:[a.jsx("span",{className:`dash-dot is-${b.state}`,"aria-hidden":"true"}),a.jsxs("span",{className:"dash-item-copy",children:[a.jsx("span",{className:"dash-item-title",children:b.title}),a.jsxs("span",{className:"dash-item-meta",children:[a.jsx("span",{className:"dash-item-state",children:b.label}),b.project?a.jsxs("span",{className:"dash-item-project",children:[i(b.project.id)&&a.jsx(Mh,{project:i(b.project.id),size:"tiny"}),a.jsx("bdi",{children:b.project.name})]}):b.crossProject?a.jsx("span",{className:"dash-item-project",children:"Across projects"}):null]})]}),a.jsx("span",{className:"dash-item-open","aria-hidden":"true",children:"Open"})]},b.key)),t.activities.length>ID&&a.jsx("button",{className:"dash-more",type:"button","aria-expanded":n,onClick:s,children:n?"Show fewer":`Show all ${t.activities.length}`})]}):t.recent?a.jsx("div",{className:"dash-agent-work",children:a.jsxs("button",{className:"dash-recent",type:"button",onClick:()=>l(t.recent.chatKey),"aria-label":`Open last: ${t.recent.title}`,children:["Last: ",a.jsx("span",{className:"dash-item-title",children:t.recent.title})]})}):null]})}function vye({name:t,chats:e,now:n,onContinue:s}){if(!e.length)return null;const i=`Continue with ${t}`;return a.jsxs("section",{className:"hero-continue","aria-label":i,children:[a.jsx("h2",{className:"hero-continue-label",children:i}),a.jsx("ul",{className:"hero-continue-list",children:e.map(r=>{const o=r.opening?.trim()||"Your earlier conversation",l=Ha(r.createdAt,n);return a.jsx("li",{children:a.jsxs("button",{type:"button",className:"hero-continue-row",title:o,"aria-label":`Continue “${o}”, started ${l}`,onClick:()=>s(r),children:[a.jsx("span",{className:"hero-continue-text",children:o}),a.jsx("span",{className:"hero-continue-time",children:l})]})},r.chatKey)})})]})}function xye(t){return!!t.headId&&t.recipientId===t.headId}function yye(t){return(t??"").trim().toLowerCase()==="general"}function bye(t){const{toHead:e,project:n,homeId:s,repo:i,sandboxDefault:r}=t,o=t.overrides??{},l=Object.values(o).some(k=>k!==void 0);if(e)return{target:"home",projectId:s??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=o.projectId!==void 0?o.projectId:n?.id??null;if(!u||u===s||u===n?.id&&yye(n?.name))return{target:"home",projectId:u??s??null,prepare:!1,branch:"",newWorktree:!1,useSandbox:o.useSandbox??!1,chosenBy:l?"advanced":"auto",reason:"No code project: works from your home workspace.",crossProject:!1};const f=!!i&&!i.loading&&!i.error,m=o.branch??(f&&i.isRepo?i.current:""),g=o.newWorktree??!0,x=o.useSandbox??r,b=m||"the project's current branch",_=l?"Chosen under Advanced.":f&&!i.isRepo?"Not a Git repository: works in the project folder.":`New worktree from ${b}, so the primary checkout stays untouched.`;return{target:"project",projectId:u,prepare:!0,branch:m,newWorktree:g,useSandbox:x,chosenBy:l?"advanced":"auto",reason:_,crossProject:!1}}function wye(t,e,n,s){const i=t.filter(h=>h.width>0),r=h=>h.reduce((f,m)=>f+m.width,0)+n*Math.max(0,h.length-1);if(r(i)<=e)return[];const o=i.map((h,f)=>({item:h,index:f})).sort((h,f)=>h.item.keep-f.item.keep||f.index-h.index),l=new Set;let u=i;for(const{item:h}of o)if(l.add(h.id),u=u.filter(f=>f.id!==h.id),r(u)+(u.length?n:0)+s<=e)break;return i.filter(h=>l.has(h.id)).map(h=>h.id)}function dF(t,e,n){const s=Math.abs(t),i=s>1,r=s+n<e-1;return[i?"start":"",r?"end":""].filter(Boolean).join(" ")}function _ye(t){return t.onChat?t.actions>0||t.arriving?!0:!t.loaded&&(t.chat||t.remembered):!1}const fF="octiq.v2.actionBar";function kye(t){return!t.onChat||!t.loaded||t.arriving?null:t.actions>0?"1":"0"}const Sye=6e4,Cye=15e3,pF="octiq.v2.usage",mF={data:{claude:null,codex:null},stale:{claude:!0,codex:!0},asked:!1};function jye(){try{const t=JSON.parse(ls(pF)||"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}}}let gF=null,T2=0,Cb=null;const fw=new Set;function R2(){return gF??={...mF,data:jye()}}function BD(t){gF=t;for(const e of fw)e()}async function Mm(t){if(!(!t&&Date.now()-T2<Cye)){T2=Date.now();try{const e=await te.invoke("usage_summary"),n=(r,o)=>r?.available?r:o?.available?o:r??o??null,s=R2().data,i={claude:n(e?.claude,s.claude),codex:n(e?.codex,s.codex)};nn(pF,JSON.stringify({claude:i.claude?.available?i.claude:s.claude,codex:i.codex?.available?i.codex:s.codex})),BD({data:i,stale:{claude:!e?.claude?.available,codex:!e?.codex?.available},asked:!0})}catch{BD({...R2(),stale:{claude:!0,codex:!0},asked:!0})}}}function Nye(t){if(fw.add(t),!Cb){Mm(T2===0);const e=setInterval(()=>{Mm(!0)},Sye),n=()=>document.visibilityState==="visible"&&void Mm(!1);document.addEventListener("visibilitychange",n),window.addEventListener("focus",n),Cb=()=>{clearInterval(e),document.removeEventListener("visibilitychange",n),window.removeEventListener("focus",n)}}return()=>{fw.delete(t),fw.size===0&&(Cb?.(),Cb=null)}}function vF(){return y.useSyncExternalStore(Nye,R2,()=>mF)}const Aye=60,Eye=85,xF={claude:"Claude",codex:"Codex"};function JE(t){return t>=Eye?"is-danger":t>=Aye?"is-warn":""}const Tx=t=>Math.min(100,Math.max(0,t));function yF(t,e=Date.now()){if(!t)return"";const n=t-e/1e3;if(n<=0)return"resetting";const s=Math.floor(n/3600),i=Math.floor(n%3600/60);return s>=24?`resets in ${Math.floor(s/24)}d ${s%24}h`:s?`resets in ${s}h ${i}m`:`resets in ${i}m`}function bF(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,s)=>s.window.percent>n.window.percent?s:n)}function Mye(t){let e=null;for(const n of["claude","codex"]){const s=bF(t[n]);if(!s)continue;const i=Tx(s.window.percent);(!e||i>e.percent)&&(e={provider:n,label:s.label,percent:i})}return e}function Lye(t){const e=["claude","codex"].flatMap(n=>{const s=bF(t[n]);return s?[`${xF[n]} ${s.label} ${Math.round(Tx(s.window.percent))}%`]:[]});return e.length?`Plan usage: ${e.join(", ")}`:"Plan usage: no reading yet"}const wF="No reading yet.";function Tye(t){const e=t.trim();return e?e[0].toUpperCase()+e.slice(1):"Model"}function Rye(t,e){const n=[];for(const s of["claude","codex"]){const i=xF[s],r=t[s],o={provider:s,stale:e[s],note:r?.note||void 0},l=n.length;r?.fiveHour&&n.push({...o,key:`${s}:5h`,label:`${i} 5h`,name:`${i} 5-hour window`,percent:Tx(r.fiveHour.percent),resetsAt:r.fiveHour.resetsAt}),r?.weekly&&n.push({...o,key:`${s}:week`,label:`${i} week`,name:`${i} weekly window`,percent:Tx(r.weekly.percent),resetsAt:r.weekly.resetsAt});for(const u of r?.models??[]){const h=Tye(u.name);n.push({...o,key:`${s}:week:${u.name}`,label:`${h} week`,name:`${i} weekly window for ${h}`,percent:Tx(u.percent),resetsAt:u.resetsAt})}n.length===l&&n.push({provider:s,key:s,label:i,name:i,percent:null,stale:!1,note:r?.note||(r?"Plan usage is not available.":wF)})}return n}function _F(t){return`${Number.isInteger(t)?t:t.toFixed(1)}%`}function kF(t,e=Date.now()){return t.percent===null?`${t.name}: ${t.note??wF}`:[`${t.name}: ${_F(t.percent)} used`,yF(t.resetsAt,e),t.stale?"last known":"",t.note??""].filter(Boolean).join(" · ")}function Dye(t,e=Date.now()){return t.length?`Plan usage. ${t.map(n=>kF(n,e)).join(". ")}`:"Plan usage: no reading yet"}const Oye=180;function Iye({antigravity:t=!1}={}){const e=vF(),{data:n,stale:s,asked:i}=e,[r,o]=y.useState(null),l=y.useRef(null),u=!!(n.claude||n.codex),h=gf(u),f=y.useCallback(()=>{l.current&&clearTimeout(l.current),l.current=null},[]);if(y.useEffect(()=>f,[f]),!u)return i?null:a.jsx("div",{className:"usage gate-held","aria-hidden":"true",children:a.jsxs("span",{className:"usage-btn enter-gated",children:[a.jsx($D,{}),a.jsx("span",{className:"usage-val",children:"00%"})]})});const m=Mye(n);return a.jsxs("div",{className:`usage ${mh(h)}`,onPointerEnter:g=>{g.pointerType==="mouse"&&(f(),o(x=>x??"hover"),Mm(!1))},onPointerLeave:g=>{g.pointerType==="mouse"&&(f(),l.current=setTimeout(()=>o(x=>x==="hover"?null:x),Oye))},children:[a.jsxs("button",{className:`usage-btn enter-gated${m&&s[m.provider]?" is-stale":""}`,type:"button","aria-label":Lye(n),"aria-haspopup":"dialog","aria-expanded":r!==null,title:"Plan usage — hover or tap for every window",onClick:()=>{f(),o(g=>g==="pin"?null:"pin"),Mm(!0)},children:[a.jsx($D,{}),a.jsx("span",{className:`usage-val ${m?JE(m.percent):""}`,children:m?a.jsx(Kt,{children:`${Math.round(m.percent)}%`}):"—"})]}),r&&a.jsxs(a.Fragment,{children:[r==="pin"&&a.jsx("div",{className:"usage-scrim",onClick:()=>o(null)}),a.jsx(SF,{feed:e,antigravity:t})]})]})}function Bye(){const t=vF();return a.jsx($ye,{feed:t,onAsk:Mm})}function $ye({feed:t,onAsk:e,now:n=Date.now(),initiallyOpen:s=!1}){const[i,r]=y.useState(s),o=y.useRef(null),l=y.useRef(null),u=y.useRef(null),{data:h,stale:f,asked:m}=t,g=y.useCallback(()=>{const k=l.current;if(!k||!o.current)return;const N=dF(k.scrollLeft,k.scrollWidth,k.clientWidth);o.current.dataset.cut!==N&&(o.current.dataset.cut=N)},[]);y.useLayoutEffect(()=>{g();const k=l.current;if(!k||typeof ResizeObserver>"u")return;const N=new ResizeObserver(g);return N.observe(k),k.firstElementChild&&N.observe(k.firstElementChild),()=>N.disconnect()},[g,m]);const x=m||!!(h.claude||h.codex),b=gf(x),_=x?Rye(h,f):[];return a.jsxs("div",{className:`usage-strip ${mh(b)}`,ref:o,onKeyDown:k=>{k.key!=="Escape"||!i||(k.preventDefault(),r(!1),u.current?.focus())},children:[a.jsx("div",{className:"usage-strip-scroll",ref:l,onScroll:g,children:x&&a.jsx("button",{ref:u,className:"usage-strip-btn enter-gated",type:"button","aria-label":Dye(_,n),"aria-haspopup":"dialog","aria-expanded":i,onClick:()=>{r(k=>!k),e?.(!0)},children:_.map(k=>{const N=k.percent===null?"":JE(k.percent);return a.jsxs("span",{className:`usage-cell${k.stale?" is-stale":""}`,"data-provider":k.provider,title:kF(k,n),children:[a.jsx("span",{className:"usage-cell-label",children:k.label}),k.percent===null?a.jsx("span",{className:"usage-cell-none",children:"—"}):a.jsxs(a.Fragment,{children:[a.jsx("span",{className:`usage-track ${N}`,children:a.jsx("span",{className:"usage-fill",style:{width:`${k.percent}%`}})}),a.jsx("span",{className:`usage-val ${N}`,children:a.jsx(Kt,{children:`${Math.round(k.percent)}%`})})]})]},k.key)})})}),i&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"usage-scrim",onClick:()=>r(!1)}),a.jsx(SF,{feed:t,antigravity:!1})]})]})}function SF({feed:t,antigravity:e}){return a.jsxs("div",{className:"usage-pop",role:"dialog","aria-label":"Plan usage",children:[a.jsx(PD,{name:"Claude",provider:t.data.claude,stale:t.stale.claude}),a.jsx(PD,{name:"Codex",provider:t.data.codex,stale:t.stale.codex}),e&&a.jsxs("section",{className:"usage-block",children:[a.jsx("header",{className:"usage-block-head",children:a.jsx("span",{className:"usage-block-name",children:"Antigravity"})}),a.jsx("div",{className:"usage-empty",children:"Antigravity does not report plan usage."})]})]})}function $D(){return a.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:[a.jsx("path",{d:"M4.5 18a9 9 0 1 1 15 0"}),a.jsx("path",{d:"m12 13 3.5-4"}),a.jsx("circle",{cx:"12",cy:"13",r:"1"})]})}function PD({name:t,provider:e,stale:n}){return a.jsxs("section",{className:"usage-block",children:[a.jsxs("header",{className:"usage-block-head",children:[a.jsx("span",{className:"usage-block-name",children:t}),e?.plan&&a.jsx("span",{className:"usage-plan",children:e.plan}),n&&a.jsx("span",{className:"usage-stale",children:"last known"})]}),e?a.jsxs(a.Fragment,{children:[a.jsx(FS,{label:"5 hours",window:e.fiveHour}),a.jsx(FS,{label:"Week",window:e.weekly}),(e.models??[]).map(s=>a.jsx(FS,{label:`Week · ${s.name}`,window:s},s.name)),e.note&&a.jsx("div",{className:"usage-empty",children:e.note})]}):a.jsx("div",{className:"usage-empty",children:"No reading yet."})]})}function FS({label:t,window:e}){if(!e)return null;const n=Math.min(100,Math.max(0,e.percent));return a.jsxs("div",{className:"usage-row",children:[a.jsx("span",{className:"usage-row-label",children:t}),a.jsx("span",{className:`usage-track ${JE(n)}`,children:a.jsx("span",{className:"usage-fill",style:{width:`${n}%`}})}),a.jsx("span",{className:"usage-val",children:a.jsx(Kt,{children:_F(n)})}),a.jsx("span",{className:"usage-reset",children:a.jsx(Kt,{children:yF(e.resetsAt)})})]})}const Lm="octiq-git-changed";function Pye(t){const e=new Set;for(const n of t)for(const s of[n.primary_path,...n.paths??[]])s?.trim()&&e.add(s);return[...e]}function zye(t){return[...new Set(t.flatMap(e=>e.primary_path?.trim()?[e.primary_path]:[]))]}function Fye(t,e){const n=new Map(e.map(i=>[i.path,i])),s={};for(const i of t){if(!i.primary_path)continue;const r=n.get(i.primary_path);r?.is_repo&&r.branch&&(s[i.id]=r.branch)}return s}const Hye={added:{letter:"A",cls:"is-add"},deleted:{letter:"D",cls:"is-del"},renamed:{letter:"R",cls:"is-ren"},untracked:{letter:"U",cls:"is-new"}},Wye={letter:"M",cls:"is-mod"},CF=["rebase","merge","ff-only"],zD="octiq.v2.gitPullMode",qye="octiq.v2.gitWidth",Uye={initial:380,min:280,max:680},Vye=/^(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 jF(t){return t?[t.primary_path??"",...t.paths??[]].filter(e=>e.trim()!=="").join(`
379
379
  `):""}function Kye(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 Gye(t){const e=t.lastIndexOf("/");return e<0?{dir:"",name:t}:{dir:t.slice(0,e),name:t.slice(e+1)}}function Yye({project:t,open:e,onToggle:n}){const[s,i]=y.useState([]),[r,o]=y.useState(null),l=t?.primary_path??"",u=jF(t),h=y.useMemo(()=>u?u.split(`
380
380
  `):[],[u]);y.useEffect(()=>{if(h.length===0){i([]);return}let x=!0;const b=()=>{te.invoke("git_status_summary",{paths:h}).then(k=>{if(!x)return;const N=k??[];i(Kye(N)),o(N.find(j=>j.is_repo&&j.path===l)??null)}).catch(()=>{x&&i([])})};window.addEventListener("focus",b),window.addEventListener(Lm,b);const _=te.onState(k=>{k==="open"&&b()});return()=>{x=!1,window.removeEventListener("focus",b),window.removeEventListener(Lm,b),_()}},[h,l]);const f=s.reduce((x,b)=>x+b.changed,0),m=s.reduce((x,b)=>x+b.ahead,0),g=y.useMemo(()=>{if(s.length===0)return[];const x=s.filter(b=>b.repo_root!==r?.repo_root);return r?[r,...x]:x},[s,r]);return a.jsxs("button",{className:`gitp-toggle ${e?"is-on":""}`,type:"button","aria-expanded":e,"aria-label":["Git",f>0?`${f} changed`:null,m>0?`${m} to push`:null].filter(Boolean).join(", "),title:t?[`Git — ${t.name}`,...g.map((x,b)=>{const _=x.repo_root.split("/").pop()??x.repo_root,k=[x.changed>0?`${x.changed} changed`:"clean",x.ahead>0?`↑${x.ahead} to push`:null].filter(Boolean).join(" · ");return`${_} · ${x.branch||"(detached)"} · ${k}${b===0&&r?" — this chat":""}`})].join(`
381
381
  `):"Git",onClick:n,children:[a.jsx(tbe,{}),a.jsx("span",{className:"topbar-action-label",children:"Git"}),f>0&&a.jsx("span",{className:"gitp-badge",children:a.jsx(Br,{value:f})}),m>0&&a.jsxs("span",{className:"gitp-badge is-ahead",children:["↑",a.jsx(Br,{value:m})]})]})}function Xye({project:t,open:e,persistent:n=!1,onClose:s}){const[i,r]=y.useState(null),[o,l]=y.useState(null),[u,h]=y.useState(!1),[f,m]=y.useState({}),[g,x]=y.useState({}),[b,_]=y.useState(""),[k,N]=y.useState(null),[j,M]=y.useState(!1),{width:A,startDrag:E,entered:L}=qm(qye,Uye),[O,X]=y.useState(()=>{const J=localStorage.getItem(zD);return CF.includes(J)?J:"rebase"}),q=jF(t),$=y.useMemo(()=>q?q.split(`
@@ -509,7 +509,7 @@ ${n.map(i=>`- ${i.path}`).join(`
509
509
 
510
510
  Files to look at:
511
511
  ${gt.map(Mt=>`- ${Mt}`).join(`
512
- `)}`.trim());const Vt=C;if(Z&&qe){try{C=await ED(nt(Ae),fe.id,Z.id,C,!1)}catch(Mt){return Lt(`Could not reach ${Z.name}: ${String(Mt.message??Mt)}`),!1}Jl.current.add(Ae),jg(new Set(Jl.current))}else if(Z){try{C=await ED(nt(Ae),fe.id,Z.id,C,Se)}catch(Rs){return Lt(`Could not hand the task to ${Z.name}: ${String(Rs.message??Rs)}`),!1}const Mt={chatKey:nt(Ae),leadId:Z.id,leadName:Z.name,projectId:fe.id,crossProject:Se||void 0,createdAt:Date.now()};zf(Rs=>[...Rs.filter(Na=>Na.chatKey!==Mt.chatKey),Mt])}if(D||Oe(Ae),C.trim()==="/clear"){const Mt=nt(Ae);return da.current.has(Ae)&&te.invoke("chat_send",{key:Mt,text:C,recordUser:!1}).catch(()=>{}),te.invoke("chat_forget",{key:Mt}).catch(()=>{}),Kr.current.delete(Ae),Ja.current.forget(Ae),Za.current.delete(Ae),QM(Ae),si.current.own(Mt),Tt(Ae,Rs=>({...xh(),sessionId:Rs.sessionId})),ye(Rs=>{const Na=Rs.map(Aa=>Aa.id===Ae?{...Aa,messages:[],seq:0,updatedAt:Date.now()}:Aa);return Ni(Na),Na}),!0}const Vs=ha.current.get(Ae);if(Vs)try{await Vs}catch{return!1}const Zn=js.current.has(Ae),Vi=Zn?QO(yn.current[Ae]?.messages??[]):void 0;xn.current[Ae]={projectId:fe.id,modelId:Ct.id,access:Pn,effort:us};const en=_C(),Ts=nwe(KD(sr.current,nt(Ae)));Tt(Ae,Mt=>$k(Mt,C,T.map(Rs=>({path:Rs.path,name:Rs.name,isImage:!!Rs.isImage})),void 0,en)),lc.current.add(en);const Ou=Mt=>Tt(Ae,Rs=>kEe(Rs,en,Mt,da.current.has(Ae)));try{const Mt=bn.current.find(Rn=>Rn.id===Ae),Rs=Mt?.cwd??yn.current[Ae]?.cwd;let Na=Rs??fe.primary_path??"",Aa;const Ad=!Rs&&!!ot&&ot.id===fe.id&&(ie?ie.prepare&&ie.target==="project":Pc(ot.name)!=="general"),ho=ie?ie.branch:qt,Ds=ie?ie.newWorktree:ue,cv=ie?ie.useSandbox:dt??Pe.snapshot?.defaultEnabled??!1,vy=Mt?void 0:{projectId:fe.id,projectName:fe.name,path:fe.primary_path??"",baseBranch:Ad?ho||(ot?.id===fe.id?ht.current:""):"",newWorktree:Ad&&Ds,useSandbox:cv,prepare:Ad,chosenBy:ie?ie.chosenBy:"person",reason:ie?.reason??"",decidedAt:Date.now()};if(Ad&&ot)try{const Rn=await te.invoke("git_prepare_chat_workspace",{path:ot.primary_path??"",branch:ho,newWorktree:Ds,prompt:Vt,chatId:Ae});Na=Rn.cwd,Nt(Rn.branch),Be(ln=>({isRepo:Rn.is_repo,current:Rn.branch,branches:Rn.branch&&!ln.branches.includes(Rn.branch)?[Rn.branch,...ln.branches]:ln.branches,isWorktree:Rn.is_worktree})),Tt(Ae,ln=>({...ln,cwd:Na}))}catch(Rn){Aa=Rn}const Ks=Date.now(),Ki=CL(Mt,{...Mt??{},id:Ae,projectId:fe.id,title:Mt?.title??Gb(Vt),latestResponse:Mt?.latestResponse,customTitle:Mt?.customTitle,sessionId:yn.current[Ae]?.sessionId??Mt?.sessionId,cwd:Aa?Mt?.cwd:Na,messages:yn.current[Ae]?.messages??Mt?.messages??[],modelId:Ct.id,permission:Pn,effort:us,createdAt:Mt?.createdAt??Ks,updatedAt:Ks,pinned:Mt?.pinned??!1,generation:Mt?.generation,launch:Mt?.launch??vy});if(qe||ye(Rn=>{const ln=[Ki,...Rn.filter(gi=>gi.id!==Ae)];return Ni(ln),ln}),qe||Tv({id:Ki.id,projectId:Ki.projectId,title:Ki.title,latestResponse:Ki.latestResponse,customTitle:Ki.customTitle,sessionId:Ki.sessionId??null,cwd:Ki.cwd??null,modelId:Ki.modelId??null,access:Ki.permission??null,createdAt:Ki.createdAt,updatedAt:Ki.updatedAt,pinned:Ki.pinned??!1,generation:Ki.generation,launch:Ki.launch}),Aa)return Ou(Aa),!1;if(!Zn&&da.current.has(Ae))try{return await te.invoke("chat_send",{key:nt(Ae),text:C,images:rt,turnId:en,seenPlans:Ts,safetyBlock:V}),!0}catch(Rn){if(!String(Rn.message??Rn).includes("no such chat"))return Ou(Rn),!1}const uv=Zn?null:yn.current[Ae]?.sessionId??bn.current.find(Rn=>Rn.id===Ae)?.sessionId??null;si.current.holds(nt(Ae))||(uv?await ii(Ae,bn.current.find(Rn=>Rn.id===Ae)?.seq).catch(()=>{}):si.current.own(nt(Ae))),$(Rn=>new Set(Rn).add(Ae));try{return await te.invoke("chat_start",{key:nt(Ae),cwd:Na,fallbackCwd:fe.primary_path??null,useSandbox:Mt?!1:ie?ie.useSandbox:dt??Pe.snapshot?.defaultEnabled??null,extraDirs:fe.paths??[],env:fe.env??{},agent:Ct.agent,model:Ct.flag||null,access:Pn,effort:us,lite:nl,images:rt,prompt:C,handoff:Vi??null,turnId:en,seenPlans:Ts,safetyBlock:V,resume:uv}),Zn&&js.current.delete(Ae),!0}catch(Rn){if(!Zn&&String(Rn.message??Rn).includes("already running"))try{return await te.invoke("chat_send",{key:nt(Ae),text:C,images:rt,turnId:en,seenPlans:Ts,safetyBlock:V}),!0}catch(ln){Ou(ln)}else Ou(Rn);return $(ln=>{const gi=new Set(ln);return gi.delete(Ae),gi}),!1}}finally{lc.current.delete(en),dl(Ae).catch(()=>{})}},[ot,pu,qt,ue,dt,Pe.snapshot?.defaultEnabled,Ct,Pn,us,nl,D,Tt,ii,dl,jn,hs,wn,Ar,cu,n,it,as,ht]),q1=y.useCallback(async C=>{const T=n.find(Ae=>Ae.id===C.projectId);if(!T)throw new Error("The selected project is no longer available.");if(!C.cwd)throw new Error("The selected repository has no working directory.");const V=crypto.randomUUID(),Z=Date.now(),ie=C.access??Pn,Se={...xh(),cwd:C.cwd},fe={id:V,projectId:T.id,title:C.title,customTitle:!0,cwd:C.cwd,messages:[],modelId:Ct.id,permission:ie,effort:us,createdAt:Z,updatedAt:Z};await te.invoke("chat_index_save",{meta:{...fe,messages:void 0,sessionId:null,access:ie,pinned:!1,generation:0}}),xn.current[V]={projectId:T.id,modelId:Ct.id,access:ie,effort:us},si.current.own(nt(V)),Tt(V,()=>Se);const rt=[fe,...bn.current.filter(Ae=>Ae.id!==V)];bn.current=rt,ye(rt),Ni(rt);let gt=!1;return{chatId:V,start:async()=>{if(gt)throw new Error("This PR agent chat has already been started.");gt=!0;const Ae=_C(),qe=Date.now(),Vt=$k(yn.current[V]??Se,C.prompt,[],qe,Ae);Tt(V,()=>Vt);const Vs=bn.current.map(Zn=>Zn.id===V?{...Zn,messages:Vt.messages,updatedAt:qe}:Zn);bn.current=Vs,ye(Vs),Ni(Vs),lc.current.add(Ae),$(Zn=>new Set(Zn).add(V));try{await te.invoke("chat_start",{key:nt(V),cwd:C.cwd,extraDirs:T.paths??[],env:T.env??{},agent:Ct.agent,model:Ct.flag||null,access:ie,effort:us,lite:nl,images:[],prompt:C.prompt,handoff:null,turnId:Ae,resume:null})}catch(Zn){const Vi=String(Zn?.message??Zn);throw Tt(V,en=>({...en,busy:!1,messages:en.messages.map(Ts=>Ts.turnId===Ae?{...Ts,delivery:"unknown",queueError:Vi}:Ts),notices:[...en.notices,`Could not start this PR agent: ${Vi}`].slice(-8)})),$(en=>{const Ts=new Set(en);return Ts.delete(V),Ts}),Zn}finally{lc.current.delete(Ae)}}}},[n,Ct,Pn,us,nl,Tt]);y.useEffect(()=>{!Ge||Ge.id!==D||it||(mt(null),Lr(Ge.text))},[Ge,D,it,Lr]);const ws=y.useCallback(()=>{!D||!da.current.has(D)||(Tt(D,C=>({...C,stopping:!0})),te.invoke("chat_interrupt",{key:nt(D)}).catch(()=>{}))},[D,Tt]),Zr=J1e(t,D,y.useCallback((C,T)=>{T&&$(V=>{if(!V.has(C))return V;const Z=new Set(V);return Z.delete(C),Z})},[])),ep=y.useMemo(()=>Sfe(Zr.state),[Zr.state]),[ud,tp]=y.useState(null),np=y.useCallback(C=>{const T=bn.current.find(Z=>Z.id===C),V=n.find(Z=>Z.id===T?.projectId)??ot;return{cwd:T?.cwd??yn.current[C]?.cwd??V?.primary_path??"",fallbackCwd:V?.primary_path??null,useSandbox:!1,extraDirs:V?.paths??[],env:V?.env??{},agent:Ct.agent,model:Ct.flag||null,access:Pn,effort:us,lite:nl,resume:yn.current[C]?.sessionId??T?.sessionId??null}},[n,ot,Ct,Pn,us,nl]),Ug=y.useCallback(async(C,T)=>{tp(null),await Zr.complete(C,np(C),T)==="completing"&&$(Z=>Z.has(C)?Z:new Set(Z).add(C))},[Zr.complete,np]),Vg=y.useCallback(async(C,T)=>{const V=await wa.start(C,T,np(C));return V===S1||V.delivered&&V.state!=="told"&&$(Z=>Z.has(C)?Z:new Set(Z).add(C)),V},[wa.start,np]),sp=k0(),qi=y.useCallback(async(C,T)=>{await sp({title:"Close this mission?",body:"Once git confirms the merge, its worktree is removed and its local branch deleted. The remote branch and the history are kept.",confirmLabel:"Close mission"})&&await Zr.closeMission(C,T)},[sp,Zr.closeMission]),os=y.useCallback((C,T)=>{if(!D||t!=="open")return;const V=D;cc.current.run({chatId:V,turnId:C,action:T,read:()=>yn.current[V]??ix,patch:Z=>Tt(V,Z),invoke:Z=>te.invoke(Z,{key:nt(V),turnId:C}),refresh:async()=>{await ii(V),await dl(V)},reclaim:Z=>Jh(V,C,Z)})},[D,t,Tt,ii,dl,Jh]),ip=y.useCallback(C=>os(C,"cancel"),[os]),hd=y.useCallback(C=>os(C,"start"),[os]),rp=y.useCallback(C=>{if(!D)return;const T=yn.current[D];if(!T?.messages.some(Z=>Z.turnId===C&&(Z.queueLost||Z.delivery==="unknown")&&!Z.echo&&!Z.takenUp))return;const V=T.messages.find(Z=>Z.turnId===C);V&&Zh(Z=>({...Z,[D]:[...Z[D]??[],YO(V)]}))},[D]),Kg=y.useCallback(C=>{if(!D)return;const T=D;yn.current[T]?.messages.some(Z=>Z.turnId===C&&Z.queueLost&&!Z.echo&&!Z.takenUp)&&te.invoke("chat_dismiss_unsent",{key:nt(T),turnId:C}).then(Z=>{Z!==!1&&Tt(T,ie=>({...ie,messages:ie.messages.filter(Se=>Se.turnId!==C)}))}).catch(Z=>Tt(T,ie=>({...ie,notices:[...ie.notices,String(Z.message??Z)]})))},[D,Tt]),co=y.useCallback(C=>{if(!D||!da.current.has(D))return!1;const T=_C();return Tt(D,V=>$k(V,C,[],void 0,T)),te.invoke("chat_send",{key:nt(D),text:C,turnId:T}).catch(()=>{}),!0},[D,Tt]),dd=y.useCallback(C=>{const T=Ct;if(C.id===T.id)return;const V=zd(C.agent,Pn);Do(C),nn(Wb,C.id),V!==Pn&&(el(V),nn(em,V));const Z=ox(C.agent,us);if(Z!==us&&(tl(Z),nn(rx,Z),D&&xn.current[D]&&(xn.current[D].effort=Z)),D&&xn.current[D]&&(xn.current[D].modelId=C.id),!D||Xe.messages.length===0)return;const ie=D,Se=yn.current[ie]?.sessionId??bn.current.find(Ae=>Ae.id===ie)?.sessionId;js.current.add(ie);const fe=(Ae,qe)=>{ye(Vt=>{const Vs=Vt.map(Zn=>Zn.id===ie?{...Zn,modelId:Ae.id,sessionId:qe}:Zn);return Ni(Vs),Vs})},rt=()=>{const Ae=eh(xn.current[ie]?.modelId??null)??C;Tt(ie,qe=>({...qe,sessionId:void 0,model:Ae.flag||void 0,modelAsked:!1,commands:void 0,contextTokens:void 0,contextWindow:void 0}))};if(fe(C),rt(),ha.current.has(ie))return;const gt=(da.current.has(ie)?te.invoke("chat_retarget",{key:nt(ie)}):Promise.resolve()).then(()=>{$(Ae=>{if(!Ae.has(ie))return Ae;const qe=new Set(Ae);return qe.delete(ie),qe}),rt()}).catch(Ae=>{throw js.current.delete(ie),Do(T),nn(Wb,T.id),el(Pn),nn(em,Pn),tl(us),nn(rx,us),xn.current[ie]&&(xn.current[ie].modelId=T.id),fe(T,Se),Tt(ie,qe=>({...qe,sessionId:Se,model:T.flag||qe.model,notices:[...qe.notices,`Could not switch models: ${String(Ae?.message??Ae)}`].slice(-8)})),Ae}).finally(()=>ha.current.delete(ie));ha.current.set(ie,gt)},[Xe.messages.length,us,Pn,Ct,D,Tt]),Gg=y.useCallback(C=>{tl(C),nn(rx,C),D&&xn.current[D]&&(xn.current[D].effort=C);const T=Fq(Ct.agent,"effort",C);T&&co(T)||D&&or(D)},[D,or,Ct.agent,co]),ap=y.useCallback((C,T)=>{const V=eh(xn.current[C]?.modelId??null)?.agent??"claude";return Rm(V,T)},[]),Au=y.useCallback((C,T)=>{or(C);const V=Qa.current[C],Z=V?ap(C,V):"That access level";Tt(C,ie=>({...ie,notices:[...ie.notices,`${Z} needs a fresh agent: ${T}. The conversation is kept — say anything to carry on.`].slice(-8)}))},[or,Tt,ap]);tc.current=Au;const X0=y.useCallback(()=>{const C=D;C&&(te.invoke("chat_restart",{key:nt(C)}).catch(()=>or(C)),$(T=>{if(!T.has(C))return T;const V=new Set(T);return V.delete(C),V}),Tt(C,T=>({...T,notices:[...T.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)})))},[D,or,Tt]),fd=CEe({chats:O,running:q,known:G&&t==="open"}),$o=!!D&&fd.has(D),pd=y.useMemo(()=>it||!D?[]:KD(Cn.snapshot,nt(D)),[Cn.snapshot,D,it]),Yg=!it&&Xe.busy&&!$o,op=y.useCallback(C=>[...n,...u].find(T=>T.id===C)?.name,[n,u]),{handovers:xc,decide:Q0}=b1e(),md=y.useMemo(()=>it||!D?BT([],null):BT(xc,nt(D)),[xc,D,it]),gd=y.useCallback((C,T)=>{di.current({conversationId:cx(C),projectId:T})},[]),[Eu,Mu]=y.useState(null),Sa=y.useRef(null),Lu={chat:D,shown:Gr,unavailable:!!bt},lp=y.useRef(Lu);lp.current=Lu;const ml=y.useCallback(C=>{const T=Sa.current;!T||T.id!==C||(Sa.current=null,gw(T.id))},[]),cp=y.useCallback(C=>Mu(T=>T===C?null:T),[]);y.useEffect(()=>{if(!Eu)return;const C=window.setTimeout(()=>{Mu(null),ml(Eu)},a5e);return()=>window.clearTimeout(C)},[Eu,ml]),y.useEffect(()=>{Mu(null)},[D,bt]),y.useEffect(()=>{const C=Sa.current;if(!C)return;const T=n9(C,lp.current);T?Sa.current=T:ml(C.id)},[Lu.chat,Lu.shown,Lu.unavailable,ml]);const up=y.useMemo(()=>Kse(md.outgoing,Eu),[md,Eu]),Xg=y.useCallback(async(C,T)=>{if(T==="confirm"){Mu(C);const Se=Sa.current;Se&&Se.id!==C&&ml(Se.id),Sa.current={id:C,from:rl.current,to:null,arrived:!1}}let Z;try{Z=await Q0(C,T)}catch(Se){throw cp(C),ml(C),Se}const ie=Z.targetChatKey;if(yh(Z)&&Z.status==="confirmed"&&ie){if(Z.to.agentId){const fe={chatKey:ie,leadId:Z.to.agentId,leadName:Z.to.name,projectId:Z.destination.projectId,crossProject:Z.route?.crossProject||void 0,createdAt:Z.decidedAt??Date.now()};zf(rt=>[...rt.filter(gt=>gt.chatKey!==ie),fe])}gd(ie,Z.destination.projectId);const Se=Sa.current;if(Se?.id===C&&H_e(Se,lp.current)){const fe=cx(ie);Se.to=fe,r9(C,()=>Q_e(fe))}else Se?.id===C&&(Sa.current=null),gw(C);L2().then(zf,()=>{})}else cp(C),Sa.current?.id===C&&(Sa.current=null),yh(Z)&&gw(C);return Z},[Q0,gd,cp,ml]),[yc,Z0]=y.useState([]),vd=Ns&&!!wn;y.useEffect(()=>{if(!vd||t!=="open")return;let C=!0;return c0e().then(T=>{C&&Z0(T)}),()=>{C=!1}},[vd,wn?.id,t]);const hp=y.useMemo(()=>{const C=new Set(xc.filter(T=>yh(T)&&T.status==="confirmed").map(T=>T.sourceChatKey));return A0e(yc,wn,C)},[yc,wn,xc]),J0=y.useCallback(async C=>{if(!wn)return;const T=cx(C.chatKey);Jl.current.add(T),jg(new Set(Jl.current));let V=rr??n.find(ie=>ie.name.trim().toLowerCase()==="general")?.id;if(!V)try{V=(await pu())?.id}catch{V=void 0}if(!V)return;const Z=TD(wn);ji({id:T,projectId:V,title:C.opening??wn.name,messages:yn.current[T]?.messages??[],modelId:Z?.choice.id,permission:Z?.access,effort:Z?.effort,createdAt:C.createdAt,updatedAt:C.createdAt}),Z&&tl(Z.effort)},[wn,rr,n,pu,ji]),dp=y.useCallback(C=>bn.current.find(T=>T.id===cx(C))?.projectId??null,[]),fp=y.useMemo(()=>Vse(md),[md]),Qg=y.useMemo(()=>Qse(Xe.messages,fp.settled),[Xe.messages,fp.settled]),{head:ey,marks:ty}=y.useMemo(()=>y1e(Gse(fp,new Map(JSON.parse(Qg))),gd,dp),[fp,Qg,gd,dp]),pp=Xe.busy&&!$o,Zg=D?Jo[D]:void 0,gl=y.useMemo(()=>VO(Zg??[],pp),[Zg,pp]),xd=$Ae(it?null:D,pp),ny=xd.toast&&gl.folded.some(C=>C.id===xd.toast?.blockId)?xd.toast:null,[mp,sy]=y.useState(null),gp=xd.clear,U1=y.useCallback(C=>{sy(T=>({id:C,n:(T?.n??0)+1})),gp()},[gp]),yd=y.useCallback(C=>{D&&Sg(T=>({...T,[D]:(T[D]??[]).filter(V=>V.id!==C)}))},[D,Sg]),Jg=y.useCallback((C,T)=>Lr(C,[],T),[Lr]),bd=zA(D??"",[...pd.filter(C=>C.pending).map(C=>`plan:${C.run.id}`),...up.map(C=>`handover:${C.id}`),...it?[]:gl.folded.map(C=>`safety:${C.id}`)]),vp=D&&!it?Cg[D]:void 0,iy=y.useMemo(()=>!D||it?null:{questions:vp??[],onDone:C=>$0(T=>({...T,[D]:(T[D]??[]).filter(V=>!C.includes(V.id))}))},[D,it,vp,$0]),ry=y.useMemo(()=>{const C=pd.some(Z=>Z.pending)?a.jsx(gwe,{plans:pd,drafting:Yg,projectName:op,late:bd}):null,T=up.length?a.jsx(p1e,{outgoing:up,onDecide:Xg,late:bd}):null,V=!it&&gl.folded.length?a.jsx(aEe,{blocks:gl.folded,reveal:mp,late:bd,onSafetyAnswered:yd,onContinue:Jg}):null;return C||T||V?a.jsxs(a.Fragment,{children:[V,T,C]}):void 0},[pd,Yg,op,up,Xg,it,gl,mp,yd,Jg,bd]),V1=y.useCallback(C=>{const T=D&&xn.current[D]?.access||Pn;if(el(C),nn(em,C),!D||(xn.current[D]&&(xn.current[D].access=C),!da.current.has(D)))return;Qa.current[D]=C;const V=D;te.invoke("chat_set_access",{key:nt(V),access:C}).catch(Z=>{const ie=String(Z.message??Z),Se=vEe(ie);if(Se!=="nothing"){if(Se==="put-back"){delete Qa.current[V],xn.current[V]&&(xn.current[V].access=T),V===rl.current&&(el(T),nn(em,T)),Tt(V,fe=>({...fe,notices:[...fe.notices,ie].slice(-8)}));return}Au(V,ie)}})},[D,Au,Pn,Tt]),ay=y.useCallback(async(C,T)=>{let V=null;if(da.current.has(C)){Qa.current[C]=T;try{await te.invoke("chat_set_access",{key:nt(C),access:T})}catch(Z){const ie=String(Z.message??Z);if(!ie.includes("no such chat")){if(!ie.includes("needs a fresh agent"))throw new Error(ie);V=ie}}}C===rl.current&&(el(T),nn(em,T)),xn.current[C]&&(xn.current[C].access=T),V&&Au(C,V)},[Au]),oy=y.useCallback(async(C,T)=>{const V=Uc(C);if(!V)return;const Z=(Se,fe)=>C.local?Promise.resolve():te.invoke("access_request_answer",{id:C.id,decision:Se,error:fe??null}).catch(()=>{}),ie=()=>{C.local?Tt(V,Se=>({...Se,accessNeed:void 0})):P0(Se=>({...Se,[V]:(Se[V]??[]).filter(fe=>fe.id!==C.id)}))};if(T==="decline"){await Z("declined"),ie();return}try{await ay(V,C.requested)}catch(Se){const fe=String(Se.message??Se);if(xEe(fe,!!C.wait)==="keep")throw Se;await Z("failed",fe),ie();return}await Z("raised"),ie()},[ay,Tt,P0]),bc=y.useMemo(()=>{const C=Xe.accessNeed;if(!D||!C)return null;const T=Uq("antigravity",C.requested);return qq(Pn,T)?null:{id:`refusal:${D}`,chatKey:nt(D),agent:"antigravity",current:Pn,requested:T,reason:C.reason,takes:"between-turns",wait:!1,local:!0}},[Xe.accessNeed,D,Pn]),ev=y.useMemo(()=>[...D?Bf[D]??[]:[],...bc?[bc]:[]],[Bf,D,bc]),xp=async C=>{if(!ot)throw new Error("Choose a project before starting a mission.");if(it)throw new Error("Start runs from the main chat.");if(Ct.agent==="pi")throw new Error("Choose Codex, Claude or Antigravity as the main agent.");const T=D??crypto.randomUUID(),V=ha.current.get(T);if(V&&await V,yn.current[T]?.busy)throw new Error("Wait for the main agent's turn to finish before starting a run.");const Z=bn.current.find(rt=>rt.id===T),ie=Date.now(),Se={...Z??{},id:T,projectId:ot.id,title:Z?.title??Gb(C),cwd:Z?.cwd??yn.current[T]?.cwd??ot.primary_path,sessionId:js.current.has(T)?void 0:yn.current[T]?.sessionId??Z?.sessionId,messages:yn.current[T]?.messages??Z?.messages??[],modelId:Ct.id,permission:Pn,effort:us,createdAt:Z?.createdAt??ie,updatedAt:ie};await te.invoke("chat_index_save",{meta:{...Se,messages:void 0,sessionId:Se.sessionId??null,access:Pn,pinned:Se.pinned??!1,generation:Se.generation??0}}),xn.current[T]={projectId:ot.id,modelId:Ct.id,access:Pn,effort:us};const fe=[Se,...bn.current.filter(rt=>rt.id!==T)];return bn.current=fe,ye(fe),Ni(fe),Z||si.current.own(nt(T)),Tt(T,rt=>({...rt,cwd:Se.cwd})),Vr(rt=>({...rt,[T]:!0})),ki(rt=>({...rt,[T]:"run"})),Oe(T),nt(T)},ly=async C=>{const T=C.coordinatorChatKey.replace(/^chat:/,""),V=ha.current.get(T);V&&await V;const Z=js.current.has(T),ie=Z?QO(yn.current[T]?.messages??[])??"[]":void 0;await te.invoke("orchestration_master_start",{actorChatKey:C.coordinatorChatKey,runId:C.id,agent:Ct.agent,model:Ct.flag||null,access:Pn,effort:us,lite:nl,handoff:ie??null}),Z&&js.current.delete(T),$(Se=>new Set(Se).add(T))},Tu=(C,T)=>{const V=C.replace(/^chat:/,""),Z=bn.current.find(ie=>ie.id===V);if(!Z)throw new Error("This chat is not available yet. Wait for the chat list to sync and try again.");if(T){if(Xd(V,Qt))throw new Error("Send this decision in the main chat.");mt({id:V,text:T})}ki(ie=>({...ie,[V]:"chat"})),Es(Z)},Ru=!ui&&!!Cn.error,tv=y.useMemo(()=>({...F0,orchestration_snapshot:ui?"answered":Ru?"failed":"asked"}),[F0,ui,Ru]),wc=y.useMemo(()=>die({orchestration:Ln,parents:Qt,asks:lu,safetyBlocks:Jo,questions:Cg,accessRequests:Bf,handovers:xc,sources:tv,late:H0}),[Ln,Qt,lu,Jo,Cg,Bf,xc,tv,H0]),Ca=wc.actions,ja=wc.held,wd=y.useMemo(()=>mve(Jo,C=>!!O[C]?.busy&&!fd.has(C),VO).join(" "),[Jo,O,fd]),yp=y.useMemo(()=>Object.keys(O).filter(C=>eY(O[C])).sort().join(" "),[O]),vl=y.useMemo(()=>hve(Ca,new Set(wd?wd.split(" "):[]),{whole:wc.whole,restored:yp?yp.split(" "):[]}),[Ca,wd,wc.whole,yp]),_c=y.useMemo(()=>gve(hc,vl),[hc,vl]),nv=wc.whole;y.useEffect(()=>{const C=Date.now();for(const T of Object.keys(O))Tt(T,V=>ZG(V,fve(vl,T),C,nv))},[O,vl,nv,Tt]);const sv=D&&vl.get(D)||null,cy=y.useCallback(()=>{z0(),Jc.refresh().catch(()=>{})},[z0]),_d=y.useMemo(()=>Ca.filter(C=>C.cardMissing).map(C=>C.key).sort().join(" "),[Ca]);y.useEffect(()=>{_d&&t==="open"&&Vh()},[_d,t,Vh]);const[bp,Du]=y.useState(null),[wp,_p]=y.useState(null),kd=y.useCallback((C,T)=>{Vr(V=>({...V,[C]:!0})),ki(V=>({...V,[C]:"run"})),Du({chatKey:nt(C),runId:T,nonce:Date.now()})},[]),[Sd,Ls]=y.useState(null),pi=y.useCallback(C=>{if(!kt)return;const T=Date.now();Vr(V=>({...V,[kt]:!0})),ki(V=>({...V,[kt]:"run"})),Du({chatKey:nt(kt),runId:C.runId,taskId:C.id,nonce:T}),$h(kt),ku(!0),Zo(null),Ls({taskId:C.id,nonce:T})},[kt,ku]);y.useEffect(()=>{if(!Sd)return;const C=Date.now();let T=requestAnimationFrame(function V(){if(Uwe(Sd.taskId)||Date.now()-C>3e3){Ls(null);return}T=requestAnimationFrame(V)});return()=>cancelAnimationFrame(T)},[Sd]);const uy=y.useMemo(()=>oke(wa.plan,Cn.snapshot,Date.now(),ja),[wa.plan,Cn.snapshot,ja]),iv=y.useCallback(C=>{const T=bn.current.find(V=>V.id===C.openChatId);T&&(C.surface==="run"&&C.runId?kd(T.id,C.runId):ki(V=>({...V,[T.id]:"chat"})),Es(T),_p({action:C,nonce:Date.now()}),C.cardMissing&&Vh())},[Es,kd,Vh]);y.useEffect(()=>{if(!wp)return;const{action:C}=wp,T=Date.now();let V=!1,Z=requestAnimationFrame(function ie(){if(Ume(C.key)){_p(null),Du(null);return}if(!V&&C.kind==="plan"&&C.runId&&Date.now()-T>1200&&(V=!0,kd(C.openChatId,C.runId)),Date.now()-T>4e3){_p(null),Du(null);return}Z=requestAnimationFrame(ie)});return()=>cancelAnimationFrame(Z)},[wp,kd]);const rv=y.useMemo(()=>y$(Ca),[Ca]),hy=y.useMemo(()=>{const C=fie(Ca);return{forRow:T=>C.get(T)??eI,forTask:T=>rv.get(T)??eI,held:ja,reveal:iv}},[Ca,rv,ja,iv]),Cd=y.useMemo(()=>({snapshot:Cn.snapshot,stop:async C=>{await te.invoke("orchestration_task_stop",{taskId:C}),await Jc.refresh().catch(()=>{})}}),[Cn.snapshot]),kp=y.useMemo(()=>lbe(on,ja),[on,ja]),[jd,dy]=y.useState(()=>Sme(ls(lI))),xl=y.useMemo(()=>it||!D?null:wme(ir,Date.now(),ja),[it,D,ir,ja]),Sp=!!xl&&!kme(jd,xl.strip),av=()=>{if(!xl)return;const C=_me(jd,xl.strip.signature);dy(C),nn(lI,JSON.stringify(C))},fy=()=>{!xl||!D||(kd(D,xl.run.id),Va&&ku(!0))},py=async()=>{const[C,T,V]=await Promise.all([k_().catch(()=>sl),yo(null,!0).catch(()=>ni),S_().catch(()=>Zl)]);if($f(C),W0(V),Ag(T),LD(T,C?.id).length===0){ds();return}wu()},my=y.useMemo(()=>oe.filter(C=>!Xd(C.id,Qt)).map(({id:C,title:T,projectId:V,cwd:Z})=>({id:C,title:T,projectId:V,cwd:Z,busy:O[C]?.busy??q.has(C)})),[oe,Qt,O,q]),ov=y.useCallback(C=>{const T=bn.current.find(V=>V.id===C);T&&Es(T)},[Es]);if(t==="unauthorized")return a.jsx(Gve,{});const kc=C=>{z(!1),H(C==="pulls"),ee(C==="projects"?{projectId:null}:null),I(C==="search"),zt(C==="settings"),il(C==="agents")},mi=(C,T,V,Z={})=>({id:C,keep:T,node:V,...Z}),Ui=!Hi&&!Bn,Cp=mfe({kind:D?M4({key:nt(D),worker:it,frontDesk:ec.has(D)}):"worker",completing:!!D&&ep.has(D),connected:t==="open"}),Nd=kt?a5(wa.plan):0,jp=C=>kt&&a.jsx(Mke,{page:C,plan:wa.plan,chatId:kt,said:wa.said,error:wa.held?.error,unread:!wa.held,startTurnLost:Tfe(Xe.messages,wa.plan?.started?.turnId),flying:uy,connected:t==="open",onClose:()=>mc(!1,kt,C),onStart:T=>Vg(kt,T),onOpenTask:pi},kt),Np=Bn?[]:[Ui&&Va&&mi("tasks",100,a.jsx(f_e,{tasks:kp.tasks,decisions:kp.decisions,open:!Ro,onToggle:()=>{Ro&&$h(D),(!Ro||Bh)&&ku(Ro)}}),{attention:Ro?kp.decisions:0}),Ui&&kt&&mi("plan",95,a.jsx(jke,{questions:Nd,open:oo,onToggle:()=>{Er.setOpen(!1),mc(!oo,kt,Ve)}}),{attention:oo?0:Nd}),Ui&&D&&mi("preview",90,a.jsx(M1e,{count:u9(Er.images).length,open:Er.open,onClick:()=>Er.setOpen(!Er.open)})),Ui&&hl&&mi("git",85,a.jsx(Yye,{project:hl,open:Ql&&!Xr,onToggle:()=>{Er.setOpen(!1),ld(Xr||!Ql)}})),Ui&&ot&&!bt&&mi("focus",80,a.jsx(JO,{onClick:Pt})),!jn&&mi("new",70,a.jsxs("button",{className:"icon-btn new-chat",type:"button","aria-label":"Start new task",title:"Start new task",onClick:wu,children:[a.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:a.jsx("path",{d:"M12 5v14M5 12h14"})}),a.jsx("span",{className:"topbar-action-label",children:"New task"})]})),Ui&&D&&mi("details",60,a.jsx(p9,{action:!0,chatId:D,connected:t==="open",context:fi,busy:Xe.busy&&!$o,waiting:sv})),Ui&&Xe.agents.length>0&&mi("agents",66,a.jsx(zpe,{count:Xe.agents.length,open:!If&&!Xr,onToggle:()=>{Er.setOpen(!1),cd(Xr||If)}})),Ui&&Gf.length>0&&mi("pinned",64,a.jsx(U1e,{count:Gf.length,open:kr&&!Xr,onToggle:()=>{Er.setOpen(!1),pc(Xr||!kr)}})),Ui&&Xn&&Ve&&mi("width",30,a.jsx(Q1e,{expanded:at,onToggle:od})),Ui&&!jn&&!it&&mi("run",68,a.jsxs("button",{className:`orch-toggle${ys==="run"&&hi?" is-on":""}`,type:"button",title:on.runs.length?"Open this chat's runs":"Start a supervised run","aria-label":on.runs.length?"Open this chat's runs":"Start a supervised run",onClick:()=>{Vr(C=>({...C,[Fi]:!0})),de("run"),ku(!0)},children:[a.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:[a.jsx("circle",{cx:"5.5",cy:"12",r:"2.2"}),a.jsx("circle",{cx:"18.5",cy:"6",r:"2.2"}),a.jsx("circle",{cx:"18.5",cy:"18",r:"2.2"}),a.jsx("path",{d:"M7.7 12h3.1a2.2 2.2 0 0 0 2.2-2.2V8.2A2.2 2.2 0 0 1 15.2 6h1.1M7.7 12h3.1a2.2 2.2 0 0 1 2.2 2.2v1.6a2.2 2.2 0 0 0 2.2 2.2h1.1"})]}),a.jsx("span",{className:"topbar-action-label",children:"Run"})]})),pA()&&mi("reload",40,a.jsx(Z1e,{})),Ui&&D&&mi("copy-id",20,a.jsx(Lke,{chatId:D})),Ui&&D&&Cp.shown&&mi("complete",50,a.jsx(Ffe,{action:Cp,onClick:()=>tp(D)})),Ui&&D&&!it&&mi("delete",10,a.jsx(Ime,{deleting:Qf.has(D),disabled:ur.has(D),deleteMs:kC,onDelete:()=>Ms(D)}),{separated:!0})].filter(C=>!!C),Ap={onChat:Ui,actions:Np.length,loaded:f,arriving:!!St},lv=_ye({...Ap,chat:!!D||!!St,remembered:g}),uo=Ve&&(lv||Np.length>0),Ep=a.jsx(Iye,{antigravity:eo?.includes("antigravity")??!1}),gy=D?Ca.filter(C=>C.surface==="chat"&&C.openChatId===D).length:0;return a.jsx(nse,{value:lw,children:a.jsx(Ez.Provider,{value:Et,children:a.jsx(_1.Provider,{value:jn?ni:r5e,children:a.jsx(zE.Provider,{value:cl,children:a.jsx(jz.Provider,{value:hy,children:a.jsx(u$.Provider,{value:Cd,children:a.jsxs("div",{ref:Ne,className:`app ${Bn?"projects-screen":""} ${Je?"nav-shut":""} ${at?"chat-wide":""} ${xt?"focus-mode":""}`,style:xt?$Ee(dn):Qxe(nr,at),children:[xt&&a.jsxs("div",{className:"focus-mode-tools",children:[a.jsx(zEe,{fontSize:dn,onChange:gs}),a.jsx(JO,{active:!0,onClick:Qn})]}),a.jsx(nge,{projects:n,projectsReady:f,chatsReady:Ze,shelved:u,deletedCount:k.length,onShowDeleted:()=>M(!0),conversations:Bo,chatParents:Qt,orchestration:Ln,ledgerSnapshot:Cn.snapshot,ledgerUnavailable:Bg,coordinatorChatKeys:so,getPreviewMessages:C=>si.current.holds(nt(C))?O[C]?.messages:void 0,loadPreview:V0,currentConversation:D,running:q,busy:hc,waiting:vl,completing:ep,deleting:Qf,leaving:ur,deleteMs:kC,onPickConversation:C=>{Es(C)},onNewChat:jn?()=>{py()}:wu,newLabel:jn?"New conversation":"New task",allowEmptyCreate:!jn,onDelete:Ms,onPin:Zf,onToggleDone:ju,onRename:vc,onArchiveWorker:async(C,T)=>{const V=Ln.attempts.find(ie=>ie.id===C),Z=Ln.runs.find(ie=>ie.id===V?.runId);if(!Z)throw new Error("This worker's run is unavailable. Reconnect and try again.");await te.invoke("orchestration_worker_archive",{actorChatKey:Z.coordinatorChatKey,attemptId:C,archived:T})},branches:i,onResize:Ve?void 0:vs.startDrag,onCollapse:Ve?void 0:()=>{_u(!1),requestAnimationFrame(()=>fn.current?.focus())},onSearch:()=>kc("search"),onSettings:()=>kc("settings"),onAgents:jn?()=>kc("agents"):void 0,onProjects:()=>kc("projects"),onPullRequests:()=>kc("pulls"),activeView:Q?"search":U?"projects":Wf&&jn?"agents":W?"pulls":Rt?"settings":null}),a.jsxs("div",{className:"shell-main",children:[a.jsxs("header",{className:"topbar",children:[a.jsxs("div",{className:"topbar-leading",children:[Bn?a.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:[a.jsx("img",{className:"topbar-logo",src:"./icon-192.png",alt:"","aria-hidden":"true"}),a.jsxs("span",{className:"topbar-identity",children:[a.jsx("span",{className:"topbar-name",children:"Chats"}),a.jsxs("span",{className:"topbar-version",children:["OctiqFlow v","0.3.12"]})]})]}):(Ve||Je)&&a.jsxs("button",{ref:fn,className:`topbar-nav${Ve?"":" is-brand"}`,type:"button","aria-label":Ve?"Show chats":"Show sidebar",title:Ve?"Show chats":"Show sidebar · OctiqFlow v0.3.12","aria-expanded":!1,disabled:!Ve&&at,onClick:()=>{Ve?(ke(!1),z(!0)):(_u(!0),requestAnimationFrame(()=>document.querySelector(".sidebar-collapse")?.focus()))},children:[!Ve&&a.jsx("img",{className:"topbar-nav-logo",src:"./icon-192.png",alt:"","aria-hidden":"true"}),a.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:[a.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),a.jsx("path",{d:"M9 4v16M13 10l2 2-2 2"})]})]}),a.jsx("div",{className:"topbar-page",ref:J,hidden:!Hi||Bn}),!Bn&&!Hi&&a.jsxs("span",{className:`topbar-chat enter-gated ${mh(x)}`,title:ot?.primary_path,children:[ot&&a.jsx(Mh,{project:ot,size:"small",className:"topbar-project-avatar"}),a.jsx("span",{className:"topbar-name",children:ot?.name??(D?"Chat":jn?sl?.name??"CTO":"New chat")})]}),a.jsx("div",{className:"topbar-context",ref:le,hidden:Hi||Bn}),a.jsx(Yve,{state:t})]}),(Bn||Ve&&!uo)&&a.jsx("div",{className:"topbar-actions",children:Bn?a.jsxs("button",{className:"projects-return",type:"button","aria-label":"Return to chat",title:"Return to chat",onClick:()=>z(!1),children:[a.jsx("span",{children:"Return to chat"}),a.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:a.jsx("path",{d:"M5 12h14m-6-6 6 6-6 6"})})]}):Ep})]}),!Bn&&a.jsx(Dke,{className:mh(x),actions:Np,scrolls:Ve,reserved:lv,seen:kye(Ap),lead:!Ve&&a.jsx("div",{className:"topbar-page-actions",ref:ne,hidden:!Hi}),end:uo?Ep:null}),!Ve&&a.jsx(Bye,{}),a.jsxs("div",{className:"body",id:"dock",children:[a.jsxs("main",{className:"main",hidden:Bn,ref:qs,children:[W&&a.jsx(YEe,{projects:n,initialProjectId:o,chats:my,agent:{provider:Hn(Ct.agent).name,model:Ct.model,access:Rm(Ct.agent,Pn)},connected:t==="open",onClose:()=>H(!1),onPrepareChat:q1,onOpenChat:ov}),U&&a.jsx(gge,{projects:n,shelved:u,conversations:oe,selectedProjectId:U.projectId,busy:_c,chatParents:Qt,ledgerSnapshot:Cn.snapshot,coordinatorChatKeys:so,allowNewTask:!jn,onSelectProject:C=>ee({projectId:C}),onOpenChat:Es,onNewTask:C=>{wu(),l(C)},onNewProject:()=>ut("new"),onProjectSettings:ut,onShowShelved:()=>_(!0),onRestoreProject:async C=>{await te.invoke("set_workspace_shelved",{id:C,shelved:!1}),await ma()},onClose:()=>ee(null)}),Q&&a.jsx(vxe,{conversations:Bo,chatParents:Qt,projects:[...n,...u],ledgerSnapshot:Cn.snapshot,ledgerUnavailable:Bg,coordinatorChatKeys:so,searchChats:to,onOpenChat:Es,onClose:()=>I(!1),deletedCount:k.length,onShowDeleted:()=>M(!0)}),Rt&&a.jsx(Q0e,{current:Fh,onPick:Qo,chatWidth:nr,onChatWidth:be,notify:Rg,onNotify:(C,T)=>{z1(C),Og(C&&T)},projects:[...n,...u],onProject:ut,agentsMode:jn,onAgentsMode:$1,onFeedback:()=>Dt(!0),initialSection:Mg,onClose:()=>{zt(!1),Hf("projects")}}),Wf&&jn&&a.jsx(pye,{snapshot:Cn.snapshot,ledgerError:Cn.error,connected:t==="open",projects:[...n,...u],running:q,busy:hc,held:ja,waitingOn:C=>{const T=C.replace(/^chat:/,"");return Ca.filter(V=>V.chatId===T).length},chatTitle:C=>oe.find(T=>nt(T.id)===C)?.title,chatExists:C=>oe.some(T=>nt(T.id)===C),onOpenChat:C=>{Tu(C),il(!1)},onOpenRun:(C,T)=>{Tu(C);const V=C.replace(/^chat:/,"");Vr(Z=>({...Z,[V]:!0})),ki(Z=>({...Z,[V]:"run"})),Xl(Z=>({...Z,[C]:T})),il(!1)},onManage:ds,onClose:()=>il(!1)}),!Hi&&va&&jp(!0),a.jsx("div",{className:`chat-app-surface ${mh(x)}`,hidden:Hi||va,children:bt?a.jsxs("div",{className:"hero",role:"status",children:[a.jsx("h1",{className:"hero-title",children:"Chat unavailable"}),a.jsx("p",{children:"This chat was deleted or is no longer in this profile. Choose another chat from the chat list."})]}):a.jsxs(a.Fragment,{children:[(!it||hi)&&a.jsx(d_e,{snapshot:on,orchestrated:hi,view:ys,focusMode:xt,split:Va,unified:hi,selectedRun:zh,worker:it,held:qr,onBackToMain:it&&(Ga??tt)&&!(hi&&(iu||ys==="run"))?()=>Tu(Ga??tt):void 0,onOpenBeside:it&&D&&!xt&&bu(nt(D))?()=>oc(nt(D)):void 0,besideTitle:Ci?.title,readOnly:it,planPending:!!zg?.approvable,pendingApprovals:gy,onView:de}),a.jsxs("div",{className:`workflow-surfaces${iu?" is-split":""}`,children:[hi&&a.jsxs("div",{className:`workflow-run-surface ${mh(xs)}`,hidden:Va?Ro:ys!=="run",style:{"--run-w":`${zi.width}px`},children:[iu&&a.jsx("div",{className:"workflow-run-resizer",role:"separator","aria-orientation":"vertical","aria-label":"Resize the run column",onPointerDown:zi.startDrag}),!qr&&a.jsx(Dwe,{embedded:!0,sharedHeading:!0,project:ot,coordinatorKey:tt,allowManualRun:!jn,pendingApprovals:it?0:gy,focusRun:bp&&bp.chatKey===tt?bp:null,projectName:C=>[...n,...u].find(T=>T.id===C)?.name,onSelectedRunChange:yg,coordinatorBusy:!it&&Xe.busy&&!$o,currentChatKey:D?nt(D):null,initialSnapshot:Ln,currentCwd:ya,onEnsureCoordinator:xp,onStartMaster:ly,onOpenChat:Tu,onClose:()=>de("chat"),onOpenBeside:xt?void 0:oc,besideChatKey:Jt?nt(Jt):null,setupContext:a.jsxs("div",{className:"workflow-setup-context",children:[a.jsxs("label",{children:["Project",a.jsxs("select",{"aria-label":"Run project",value:ot?.id??"",disabled:!!D,onChange:C=>ao(C.target.value||null),children:[a.jsx("option",{value:"",children:"Choose a project"}),n.map(C=>a.jsx("option",{value:C.id,children:C.name},C.id))]})]}),a.jsxs("label",{children:["Main agent",a.jsxs("select",{"aria-label":"Main agent",value:Ct.id,onChange:C=>{const T=Ba.find(V=>V.id===C.target.value);T&&dd(T)},children:[Ct.agent==="pi"&&a.jsx("option",{value:Ct.id,disabled:!0,children:"Choose Codex, Claude or Antigravity"}),Ba.filter(C=>C.agent!=="pi"&&(!eo||eo.includes(C.agent))).map(C=>a.jsxs("option",{value:C.id,children:[C.name," · ",C.model]},C.id))]})]}),a.jsx("p",{children:"Keep talking in Chat. Worker providers are independent of the main agent."})]})})]}),a.jsxs("div",{className:"workflow-chat-surface",hidden:Vn,ref:Wt,children:[Jt&&Un&&!gu&&a.jsx(Jke,{showing:ve,taskTitle:Un.title,onShow:Ie,onClose:Fg}),a.jsxs("div",{className:`beside-panes${ed?" is-split":""}`,children:[a.jsxs("div",{className:"beside-pane is-main",hidden:!td,...Jt?{role:"region","aria-label":"Main chat"}:{},children:[ed&&a.jsx(Zke,{persona:ul}),it&&!hi&&a.jsx("div",{className:"read-only-strip",children:a.jsx(n5,{})}),D&&Lg[D]&&Xe.messages.length>0&&a.jsx("div",{className:"chat-sync-note",role:"status",children:a.jsx("span",{children:"Updating conversation…"})}),Xe.messages.length===0&&D&&Lg[D]?a.jsxs("div",{className:"hero is-waiting",children:[a.jsx("div",{className:"dots","aria-label":"opening"}),a.jsxs("p",{className:"hero-sub",children:["opening “",hu[D]?.title??oe.find(C=>C.id===D)?.title??"the session","”…"]})]}):Xe.messages.length===0&&it?a.jsxs("div",{className:"hero",children:[a.jsx("h1",{className:"hero-title",children:"Agent conversation"}),a.jsx("p",{className:"hero-sub",children:"The agent's progress will appear here. Send instructions in the main chat."})]}):Xe.messages.length===0&&ir.runs.length>0?a.jsxs("div",{className:"hero",children:[a.jsx("h2",{className:"hero-title",children:"Main chat"}),a.jsx("p",{className:"hero-sub",children:"Talk with the main agent here. Select a task to follow its conversation."})]}):Xe.messages.length===0?a.jsxs("div",{className:`hero enter-gated ${ot?"":"hero-start"}${Ns?" is-agent-welcome":""}`,children:[a.jsx("h1",{className:"hero-title",children:Ns&&hs?`Talk to ${hs.name}`:Ns&&Ar.length>0?"Choose who you talk to":Ns?ot?`What's the task in ${ot.name}?`:"What's the task?":ot?`What do you want to do in ${ot.name}?`:"What should we work on?"}),Ns&&hs&&a.jsx(j0e,{name:hs.name,role:hs.role??"",greeting:Yr?E0e:void 0,scope:Yr?"Your front desk":xa?"Works across every project":`Works ${hs.projectId?`only in ${ot?.name??"its project"}`:"in any project"}`,how:Yr?"Say what you need. It finds the right agent and project, shows you who on a card, and opens that agent's chat with your request once you confirm.":xa?"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."},hs.id),(!ot||Ns)&&Ut&&a.jsx("p",{className:"hero-route-error",role:"alert",children:Ut}),Ns&&Yr&&wn&&a.jsx(vye,{name:wn.name,chats:hp,now:Date.now(),onContinue:C=>{J0(C)}}),Ns&&wn&&(Yr?a.jsxs("button",{className:"hero-link hero-roster-toggle",type:"button","aria-expanded":Ng,onClick:()=>Pf(C=>!C),children:["Talk to someone else",a.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:a.jsx("path",{d:"m6 9 6 6 6-6"})})]}):a.jsxs("button",{className:"hero-link hero-roster-toggle",type:"button",onClick:()=>{Ff(null),Pf(!1)},children:["Back to ",wn.name]})),Ns&&(!wn||Ng)&&a.jsx(P0e,{agents:wn?$g:Ar,selectedId:Yr?null:hs?.id??null,projectName:C=>n.find(T=>T.id===C)?.name,onPick:Hg,onManage:ds,showManage:!1,label:wn?"Talk to someone else":"Talk to"}),Ns&&a.jsxs("div",{className:"hero-links",children:[a.jsx("button",{className:"hero-link",type:"button",onClick:ds,children:"Manage agents"}),ot&&!it&&a.jsx(bD,{projectPath:ya,onResume:Xf})]}),Xe.sessionId&&(D&&hu[D]?a.jsxs("p",{className:"hero-sub",children:["continuing “",hu[D].title,"” ·"," ",Hn(hu[D].agent).name,hu[D].problem&&a.jsxs("span",{className:"hero-warn",children:[" ","· could not read it back (",hu[D].problem,"). Typing still carries on the session."]})]}):a.jsx("p",{className:"hero-sub",children:"continuing an earlier session"})),ot&&!it&&!Ns&&a.jsx(bD,{projectPath:ya,onResume:Xf})]}):a.jsx("div",{className:"chat-body",children:a.jsx(P7,{value:ya,children:a.jsx(YB,{value:Yf,children:a.jsx(ZB,{value:dc,children:a.jsxs("div",{className:"chat-main",children:[a.jsx(A$.Provider,{value:iy,children:a.jsx(sz,{messages:Xe.messages,tail:ry,head:ey,marks:ty,hasEarlier:!!D&&Ja.current.hasEarlier(D),loadingEarlier:!!D&&!!Xh[D]?.loading,earlierError:D?Xh[D]?.error:void 0,onLoadEarlier:K0,busy:Xe.busy&&!$o,stoppedAt:Xe.stoppedAt,compactingSince:Xe.compactingSince,conversationId:D??void 0,hostName:jT(ul,Hn(Ct.agent).name),hostPersona:ul,onCancelQueued:!it&&t==="open"?ip:void 0,onStartQueued:!it&&t==="open"?hd:void 0,onRestoreUnsent:it?void 0:rp,onDismissUnsent:it?void 0:Kg,onSetting:it?void 0:Lr,agentByTool:ad,onOpenAgent:gn})}),!it&&a.jsx(uEe,{toast:ny,onDetails:U1,onDone:gp}),uc&&a.jsx(Dpe,{run:uc,messages:Xe.messages,onBack:()=>gn(null)})]})})})})}),D&&a.jsx(So,{when:!!(ar||ba),scope:D,children:(ar||ba)&&a.jsxs("div",{className:`failure ${ar?.outOfCredit||ba?"is-quota":""}`,role:"alert",children:[ar&&!ba&&a.jsx("button",{className:"failure-close",type:"button","aria-label":"Dismiss",onClick:()=>{NY(D,ar),Tt(D,C=>({...C,failure:void 0}))},children:"×"}),a.jsx("div",{className:"failure-title",children:ar?.title??"Auto-resume scheduled"}),ar?.detail&&a.jsx("div",{className:"failure-detail",children:ar.detail}),ba&&a.jsxs("div",{className:"auto-resume-row",children:[a.jsxs("span",{children:["OctiqFlow will resume this ",ba.agent==="pi"?"Pi":tr[ba.agent]," session around"," ",new Date(ba.runAt*1e3).toLocaleString([],{dateStyle:"medium",timeStyle:"short"}),"."]}),!it&&a.jsx("button",{className:"auto-resume-cancel",type:"button",onClick:()=>{te.invoke("chat_cancel_auto_resume",{key:nt(D)}).catch(C=>{Tt(D,T=>({...T,notices:[...T.notices,`Could not cancel auto-resume: ${String(C.message??C)}`]}))})},children:"Cancel auto-resume"})]}),ar?.link&&a.jsx("a",{className:"failure-link",href:ar.link,target:"_blank",rel:"noreferrer noopener",children:ar.link})]})}),D&&!it&&a.jsx(KO,{scope:D,asks:lu[D]??[],safetyBlocks:gl.cards,onPermissionAnswered:C=>B0(T=>({...T,[D]:(T[D]??[]).filter(V=>V.id!==C)})),onSafetyAnswered:yd,onContinue:(C,T)=>Lr(C,[],T),accessRequests:ev,onAccessAnswer:oy}),D&&a.jsx(So,{when:!!Pe.snapshot?.environments[nt(D)]?.enabled,scope:D,children:Pe.snapshot?.environments[nt(D)]?.enabled&&a.jsx(rq,{environment:Pe.snapshot.environments[nt(D)],running:Xe.busy,onRefresh:Pe.refresh},D)}),Df&&hl&&a.jsx(gAe,{project:hl,onCommandsChanged:ma,onHide:()=>{Hh(!1),nn(CC,"0")}},hl.id),wg.map(C=>{const T=Jo[C]??[],V=T.filter(lj),Z=T.filter(fe=>!lj(fe));if((lu[C]?.length??0)+T.length===0)return null;const ie=oe.find(fe=>fe.id===C)?.title??"agent",Se=fe=>a.jsx(KO,{asks:fe===V?[]:lu[C]??[],safetyBlocks:fe,onPermissionAnswered:rt=>B0(gt=>({...gt,[C]:(gt[C]??[]).filter(Ae=>Ae.id!==rt)})),onSafetyAnswered:rt=>Sg(gt=>({...gt,[C]:(gt[C]??[]).filter(Ae=>Ae.id!==rt)})),onContinue:(rt,gt)=>Lr(`For your worker chat ${C}:
512
+ `)}`.trim());const Vt=C;if(Z&&qe){try{C=await ED(nt(Ae),fe.id,Z.id,C,!1)}catch(Mt){return Lt(`Could not reach ${Z.name}: ${String(Mt.message??Mt)}`),!1}Jl.current.add(Ae),jg(new Set(Jl.current))}else if(Z){try{C=await ED(nt(Ae),fe.id,Z.id,C,Se)}catch(Rs){return Lt(`Could not hand the task to ${Z.name}: ${String(Rs.message??Rs)}`),!1}const Mt={chatKey:nt(Ae),leadId:Z.id,leadName:Z.name,projectId:fe.id,crossProject:Se||void 0,createdAt:Date.now()};zf(Rs=>[...Rs.filter(Na=>Na.chatKey!==Mt.chatKey),Mt])}if(D||Oe(Ae),C.trim()==="/clear"){const Mt=nt(Ae);return da.current.has(Ae)&&te.invoke("chat_send",{key:Mt,text:C,recordUser:!1}).catch(()=>{}),te.invoke("chat_forget",{key:Mt}).catch(()=>{}),Kr.current.delete(Ae),Ja.current.forget(Ae),Za.current.delete(Ae),QM(Ae),si.current.own(Mt),Tt(Ae,Rs=>({...xh(),sessionId:Rs.sessionId})),ye(Rs=>{const Na=Rs.map(Aa=>Aa.id===Ae?{...Aa,messages:[],seq:0,updatedAt:Date.now()}:Aa);return Ni(Na),Na}),!0}const Vs=ha.current.get(Ae);if(Vs)try{await Vs}catch{return!1}const Zn=js.current.has(Ae),Vi=Zn?QO(yn.current[Ae]?.messages??[]):void 0;xn.current[Ae]={projectId:fe.id,modelId:Ct.id,access:Pn,effort:us};const en=_C(),Ts=nwe(KD(sr.current,nt(Ae)));Tt(Ae,Mt=>$k(Mt,C,T.map(Rs=>({path:Rs.path,name:Rs.name,isImage:!!Rs.isImage})),void 0,en)),lc.current.add(en);const Ou=Mt=>Tt(Ae,Rs=>kEe(Rs,en,Mt,da.current.has(Ae)));try{const Mt=bn.current.find(Rn=>Rn.id===Ae),Rs=Mt?.cwd??yn.current[Ae]?.cwd;let Na=Rs??fe.primary_path??"",Aa;const Ad=!Rs&&!!ot&&ot.id===fe.id&&(ie?ie.prepare&&ie.target==="project":Pc(ot.name)!=="general"),ho=ie?ie.branch:qt,Ds=ie?ie.newWorktree:ue,cv=ie?ie.useSandbox:dt??Pe.snapshot?.defaultEnabled??!1,vy=Mt?void 0:{projectId:fe.id,projectName:fe.name,path:fe.primary_path??"",baseBranch:Ad?ho||(ot?.id===fe.id?ht.current:""):"",newWorktree:Ad&&Ds,useSandbox:cv,prepare:Ad,chosenBy:ie?ie.chosenBy:"person",reason:ie?.reason??"",decidedAt:Date.now()};if(Ad&&ot)try{const Rn=await te.invoke("git_prepare_chat_workspace",{path:ot.primary_path??"",branch:ho,newWorktree:Ds,prompt:Vt,chatId:Ae});Na=Rn.cwd,Nt(Rn.branch),Be(ln=>({isRepo:Rn.is_repo,current:Rn.branch,branches:Rn.branch&&!ln.branches.includes(Rn.branch)?[Rn.branch,...ln.branches]:ln.branches,isWorktree:Rn.is_worktree})),Tt(Ae,ln=>({...ln,cwd:Na}))}catch(Rn){Aa=Rn}const Ks=Date.now(),Ki=CL(Mt,{...Mt??{},id:Ae,projectId:fe.id,title:Mt?.title??Gb(Vt),latestResponse:Mt?.latestResponse,customTitle:Mt?.customTitle,sessionId:yn.current[Ae]?.sessionId??Mt?.sessionId,cwd:Aa?Mt?.cwd:Na,messages:yn.current[Ae]?.messages??Mt?.messages??[],modelId:Ct.id,permission:Pn,effort:us,createdAt:Mt?.createdAt??Ks,updatedAt:Ks,pinned:Mt?.pinned??!1,generation:Mt?.generation,launch:Mt?.launch??vy});if(qe||ye(Rn=>{const ln=[Ki,...Rn.filter(gi=>gi.id!==Ae)];return Ni(ln),ln}),qe||Tv({id:Ki.id,projectId:Ki.projectId,title:Ki.title,latestResponse:Ki.latestResponse,customTitle:Ki.customTitle,sessionId:Ki.sessionId??null,cwd:Ki.cwd??null,modelId:Ki.modelId??null,access:Ki.permission??null,createdAt:Ki.createdAt,updatedAt:Ki.updatedAt,pinned:Ki.pinned??!1,generation:Ki.generation,launch:Ki.launch}),Aa)return Ou(Aa),!1;if(!Zn&&da.current.has(Ae))try{return await te.invoke("chat_send",{key:nt(Ae),text:C,images:rt,turnId:en,seenPlans:Ts,safetyBlock:V}),!0}catch(Rn){if(!String(Rn.message??Rn).includes("no such chat"))return Ou(Rn),!1}const uv=Zn?null:yn.current[Ae]?.sessionId??bn.current.find(Rn=>Rn.id===Ae)?.sessionId??null;si.current.holds(nt(Ae))||(uv?await ii(Ae,bn.current.find(Rn=>Rn.id===Ae)?.seq).catch(()=>{}):si.current.own(nt(Ae))),$(Rn=>new Set(Rn).add(Ae));try{return await te.invoke("chat_start",{key:nt(Ae),cwd:Na,fallbackCwd:fe.primary_path??null,useSandbox:Mt?!1:ie?ie.useSandbox:dt??Pe.snapshot?.defaultEnabled??null,extraDirs:fe.paths??[],env:fe.env??{},agent:Ct.agent,model:Ct.flag||null,access:Pn,effort:us,lite:nl,images:rt,prompt:C,handoff:Vi??null,turnId:en,seenPlans:Ts,safetyBlock:V,resume:uv}),Zn&&js.current.delete(Ae),!0}catch(Rn){if(!Zn&&String(Rn.message??Rn).includes("already running"))try{return await te.invoke("chat_send",{key:nt(Ae),text:C,images:rt,turnId:en,seenPlans:Ts,safetyBlock:V}),!0}catch(ln){Ou(ln)}else Ou(Rn);return $(ln=>{const gi=new Set(ln);return gi.delete(Ae),gi}),!1}}finally{lc.current.delete(en),dl(Ae).catch(()=>{})}},[ot,pu,qt,ue,dt,Pe.snapshot?.defaultEnabled,Ct,Pn,us,nl,D,Tt,ii,dl,jn,hs,wn,Ar,cu,n,it,as,ht]),q1=y.useCallback(async C=>{const T=n.find(Ae=>Ae.id===C.projectId);if(!T)throw new Error("The selected project is no longer available.");if(!C.cwd)throw new Error("The selected repository has no working directory.");const V=crypto.randomUUID(),Z=Date.now(),ie=C.access??Pn,Se={...xh(),cwd:C.cwd},fe={id:V,projectId:T.id,title:C.title,customTitle:!0,cwd:C.cwd,messages:[],modelId:Ct.id,permission:ie,effort:us,createdAt:Z,updatedAt:Z};await te.invoke("chat_index_save",{meta:{...fe,messages:void 0,sessionId:null,access:ie,pinned:!1,generation:0}}),xn.current[V]={projectId:T.id,modelId:Ct.id,access:ie,effort:us},si.current.own(nt(V)),Tt(V,()=>Se);const rt=[fe,...bn.current.filter(Ae=>Ae.id!==V)];bn.current=rt,ye(rt),Ni(rt);let gt=!1;return{chatId:V,start:async()=>{if(gt)throw new Error("This PR agent chat has already been started.");gt=!0;const Ae=_C(),qe=Date.now(),Vt=$k(yn.current[V]??Se,C.prompt,[],qe,Ae);Tt(V,()=>Vt);const Vs=bn.current.map(Zn=>Zn.id===V?{...Zn,messages:Vt.messages,updatedAt:qe}:Zn);bn.current=Vs,ye(Vs),Ni(Vs),lc.current.add(Ae),$(Zn=>new Set(Zn).add(V));try{await te.invoke("chat_start",{key:nt(V),cwd:C.cwd,extraDirs:T.paths??[],env:T.env??{},agent:Ct.agent,model:Ct.flag||null,access:ie,effort:us,lite:nl,images:[],prompt:C.prompt,handoff:null,turnId:Ae,resume:null})}catch(Zn){const Vi=String(Zn?.message??Zn);throw Tt(V,en=>({...en,busy:!1,messages:en.messages.map(Ts=>Ts.turnId===Ae?{...Ts,delivery:"unknown",queueError:Vi}:Ts),notices:[...en.notices,`Could not start this PR agent: ${Vi}`].slice(-8)})),$(en=>{const Ts=new Set(en);return Ts.delete(V),Ts}),Zn}finally{lc.current.delete(Ae)}}}},[n,Ct,Pn,us,nl,Tt]);y.useEffect(()=>{!Ge||Ge.id!==D||it||(mt(null),Lr(Ge.text))},[Ge,D,it,Lr]);const ws=y.useCallback(()=>{!D||!da.current.has(D)||(Tt(D,C=>({...C,stopping:!0})),te.invoke("chat_interrupt",{key:nt(D)}).catch(()=>{}))},[D,Tt]),Zr=J1e(t,D,y.useCallback((C,T)=>{T&&$(V=>{if(!V.has(C))return V;const Z=new Set(V);return Z.delete(C),Z})},[])),ep=y.useMemo(()=>Sfe(Zr.state),[Zr.state]),[ud,tp]=y.useState(null),np=y.useCallback(C=>{const T=bn.current.find(Z=>Z.id===C),V=n.find(Z=>Z.id===T?.projectId)??ot;return{cwd:T?.cwd??yn.current[C]?.cwd??V?.primary_path??"",fallbackCwd:V?.primary_path??null,useSandbox:!1,extraDirs:V?.paths??[],env:V?.env??{},agent:Ct.agent,model:Ct.flag||null,access:Pn,effort:us,lite:nl,resume:yn.current[C]?.sessionId??T?.sessionId??null}},[n,ot,Ct,Pn,us,nl]),Ug=y.useCallback(async(C,T)=>{tp(null),await Zr.complete(C,np(C),T)==="completing"&&$(Z=>Z.has(C)?Z:new Set(Z).add(C))},[Zr.complete,np]),Vg=y.useCallback(async(C,T)=>{const V=await wa.start(C,T,np(C));return V===S1||V.delivered&&V.state!=="told"&&$(Z=>Z.has(C)?Z:new Set(Z).add(C)),V},[wa.start,np]),sp=k0(),qi=y.useCallback(async(C,T)=>{await sp({title:"Close this mission?",body:"Once git confirms the merge, its worktree is removed and its local branch deleted. The remote branch and the history are kept.",confirmLabel:"Close mission"})&&await Zr.closeMission(C,T)},[sp,Zr.closeMission]),os=y.useCallback((C,T)=>{if(!D||t!=="open")return;const V=D;cc.current.run({chatId:V,turnId:C,action:T,read:()=>yn.current[V]??ix,patch:Z=>Tt(V,Z),invoke:Z=>te.invoke(Z,{key:nt(V),turnId:C}),refresh:async()=>{await ii(V),await dl(V)},reclaim:Z=>Jh(V,C,Z)})},[D,t,Tt,ii,dl,Jh]),ip=y.useCallback(C=>os(C,"cancel"),[os]),hd=y.useCallback(C=>os(C,"start"),[os]),rp=y.useCallback(C=>{if(!D)return;const T=yn.current[D];if(!T?.messages.some(Z=>Z.turnId===C&&(Z.queueLost||Z.delivery==="unknown")&&!Z.echo&&!Z.takenUp))return;const V=T.messages.find(Z=>Z.turnId===C);V&&Zh(Z=>({...Z,[D]:[...Z[D]??[],YO(V)]}))},[D]),Kg=y.useCallback(C=>{if(!D)return;const T=D;yn.current[T]?.messages.some(Z=>Z.turnId===C&&Z.queueLost&&!Z.echo&&!Z.takenUp)&&te.invoke("chat_dismiss_unsent",{key:nt(T),turnId:C}).then(Z=>{Z!==!1&&Tt(T,ie=>({...ie,messages:ie.messages.filter(Se=>Se.turnId!==C)}))}).catch(Z=>Tt(T,ie=>({...ie,notices:[...ie.notices,String(Z.message??Z)]})))},[D,Tt]),co=y.useCallback(C=>{if(!D||!da.current.has(D))return!1;const T=_C();return Tt(D,V=>$k(V,C,[],void 0,T)),te.invoke("chat_send",{key:nt(D),text:C,turnId:T}).catch(()=>{}),!0},[D,Tt]),dd=y.useCallback(C=>{const T=Ct;if(C.id===T.id)return;const V=zd(C.agent,Pn);Do(C),nn(Wb,C.id),V!==Pn&&(el(V),nn(em,V));const Z=ox(C.agent,us);if(Z!==us&&(tl(Z),nn(rx,Z),D&&xn.current[D]&&(xn.current[D].effort=Z)),D&&xn.current[D]&&(xn.current[D].modelId=C.id),!D||Xe.messages.length===0)return;const ie=D,Se=yn.current[ie]?.sessionId??bn.current.find(Ae=>Ae.id===ie)?.sessionId;js.current.add(ie);const fe=(Ae,qe)=>{ye(Vt=>{const Vs=Vt.map(Zn=>Zn.id===ie?{...Zn,modelId:Ae.id,sessionId:qe}:Zn);return Ni(Vs),Vs})},rt=()=>{const Ae=eh(xn.current[ie]?.modelId??null)??C;Tt(ie,qe=>({...qe,sessionId:void 0,model:Ae.flag||void 0,modelAsked:!1,commands:void 0,contextTokens:void 0,contextWindow:void 0}))};if(fe(C),rt(),ha.current.has(ie))return;const gt=(da.current.has(ie)?te.invoke("chat_retarget",{key:nt(ie)}):Promise.resolve()).then(()=>{$(Ae=>{if(!Ae.has(ie))return Ae;const qe=new Set(Ae);return qe.delete(ie),qe}),rt()}).catch(Ae=>{throw js.current.delete(ie),Do(T),nn(Wb,T.id),el(Pn),nn(em,Pn),tl(us),nn(rx,us),xn.current[ie]&&(xn.current[ie].modelId=T.id),fe(T,Se),Tt(ie,qe=>({...qe,sessionId:Se,model:T.flag||qe.model,notices:[...qe.notices,`Could not switch models: ${String(Ae?.message??Ae)}`].slice(-8)})),Ae}).finally(()=>ha.current.delete(ie));ha.current.set(ie,gt)},[Xe.messages.length,us,Pn,Ct,D,Tt]),Gg=y.useCallback(C=>{tl(C),nn(rx,C),D&&xn.current[D]&&(xn.current[D].effort=C);const T=Fq(Ct.agent,"effort",C);T&&co(T)||D&&or(D)},[D,or,Ct.agent,co]),ap=y.useCallback((C,T)=>{const V=eh(xn.current[C]?.modelId??null)?.agent??"claude";return Rm(V,T)},[]),Au=y.useCallback((C,T)=>{or(C);const V=Qa.current[C],Z=V?ap(C,V):"That access level";Tt(C,ie=>({...ie,notices:[...ie.notices,`${Z} needs a fresh agent: ${T}. The conversation is kept — say anything to carry on.`].slice(-8)}))},[or,Tt,ap]);tc.current=Au;const X0=y.useCallback(()=>{const C=D;C&&(te.invoke("chat_restart",{key:nt(C)}).catch(()=>or(C)),$(T=>{if(!T.has(C))return T;const V=new Set(T);return V.delete(C),V}),Tt(C,T=>({...T,notices:[...T.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)})))},[D,or,Tt]),fd=CEe({chats:O,running:q,known:G&&t==="open"}),$o=!!D&&fd.has(D),pd=y.useMemo(()=>it||!D?[]:KD(Cn.snapshot,nt(D)),[Cn.snapshot,D,it]),Yg=!it&&Xe.busy&&!$o,op=y.useCallback(C=>[...n,...u].find(T=>T.id===C)?.name,[n,u]),{handovers:xc,decide:Q0}=b1e(),md=y.useMemo(()=>it||!D?BT([],null):BT(xc,nt(D)),[xc,D,it]),gd=y.useCallback((C,T)=>{di.current({conversationId:cx(C),projectId:T})},[]),[Eu,Mu]=y.useState(null),Sa=y.useRef(null),Lu={chat:D,shown:Gr,unavailable:!!bt},lp=y.useRef(Lu);lp.current=Lu;const ml=y.useCallback(C=>{const T=Sa.current;!T||T.id!==C||(Sa.current=null,gw(T.id))},[]),cp=y.useCallback(C=>Mu(T=>T===C?null:T),[]);y.useEffect(()=>{if(!Eu)return;const C=window.setTimeout(()=>{Mu(null),ml(Eu)},a5e);return()=>window.clearTimeout(C)},[Eu,ml]),y.useEffect(()=>{Mu(null)},[D,bt]),y.useEffect(()=>{const C=Sa.current;if(!C)return;const T=n9(C,lp.current);T?Sa.current=T:ml(C.id)},[Lu.chat,Lu.shown,Lu.unavailable,ml]);const up=y.useMemo(()=>Kse(md.outgoing,Eu),[md,Eu]),Xg=y.useCallback(async(C,T)=>{if(T==="confirm"){Mu(C);const Se=Sa.current;Se&&Se.id!==C&&ml(Se.id),Sa.current={id:C,from:rl.current,to:null,arrived:!1}}let Z;try{Z=await Q0(C,T)}catch(Se){throw cp(C),ml(C),Se}const ie=Z.targetChatKey;if(yh(Z)&&Z.status==="confirmed"&&ie){if(Z.to.agentId){const fe={chatKey:ie,leadId:Z.to.agentId,leadName:Z.to.name,projectId:Z.destination.projectId,crossProject:Z.route?.crossProject||void 0,createdAt:Z.decidedAt??Date.now()};zf(rt=>[...rt.filter(gt=>gt.chatKey!==ie),fe])}gd(ie,Z.destination.projectId);const Se=Sa.current;if(Se?.id===C&&H_e(Se,lp.current)){const fe=cx(ie);Se.to=fe,r9(C,()=>Q_e(fe))}else Se?.id===C&&(Sa.current=null),gw(C);L2().then(zf,()=>{})}else cp(C),Sa.current?.id===C&&(Sa.current=null),yh(Z)&&gw(C);return Z},[Q0,gd,cp,ml]),[yc,Z0]=y.useState([]),vd=Ns&&!!wn;y.useEffect(()=>{if(!vd||t!=="open")return;let C=!0;return c0e().then(T=>{C&&Z0(T)}),()=>{C=!1}},[vd,wn?.id,t]);const hp=y.useMemo(()=>{const C=new Set(xc.filter(T=>yh(T)&&T.status==="confirmed").map(T=>T.sourceChatKey));return A0e(yc,wn,C)},[yc,wn,xc]),J0=y.useCallback(async C=>{if(!wn)return;const T=cx(C.chatKey);Jl.current.add(T),jg(new Set(Jl.current));let V=rr??n.find(ie=>ie.name.trim().toLowerCase()==="general")?.id;if(!V)try{V=(await pu())?.id}catch{V=void 0}if(!V)return;const Z=TD(wn);ji({id:T,projectId:V,title:C.opening??wn.name,messages:yn.current[T]?.messages??[],modelId:Z?.choice.id,permission:Z?.access,effort:Z?.effort,createdAt:C.createdAt,updatedAt:C.createdAt}),Z&&tl(Z.effort)},[wn,rr,n,pu,ji]),dp=y.useCallback(C=>bn.current.find(T=>T.id===cx(C))?.projectId??null,[]),fp=y.useMemo(()=>Vse(md),[md]),Qg=y.useMemo(()=>Qse(Xe.messages,fp.settled),[Xe.messages,fp.settled]),{head:ey,marks:ty}=y.useMemo(()=>y1e(Gse(fp,new Map(JSON.parse(Qg))),gd,dp),[fp,Qg,gd,dp]),pp=Xe.busy&&!$o,Zg=D?Jo[D]:void 0,gl=y.useMemo(()=>VO(Zg??[],pp),[Zg,pp]),xd=$Ae(it?null:D,pp),ny=xd.toast&&gl.folded.some(C=>C.id===xd.toast?.blockId)?xd.toast:null,[mp,sy]=y.useState(null),gp=xd.clear,U1=y.useCallback(C=>{sy(T=>({id:C,n:(T?.n??0)+1})),gp()},[gp]),yd=y.useCallback(C=>{D&&Sg(T=>({...T,[D]:(T[D]??[]).filter(V=>V.id!==C)}))},[D,Sg]),Jg=y.useCallback((C,T)=>Lr(C,[],T),[Lr]),bd=zA(D??"",[...pd.filter(C=>C.pending).map(C=>`plan:${C.run.id}`),...up.map(C=>`handover:${C.id}`),...it?[]:gl.folded.map(C=>`safety:${C.id}`)]),vp=D&&!it?Cg[D]:void 0,iy=y.useMemo(()=>!D||it?null:{questions:vp??[],onDone:C=>$0(T=>({...T,[D]:(T[D]??[]).filter(V=>!C.includes(V.id))}))},[D,it,vp,$0]),ry=y.useMemo(()=>{const C=pd.some(Z=>Z.pending)?a.jsx(gwe,{plans:pd,drafting:Yg,projectName:op,late:bd}):null,T=up.length?a.jsx(p1e,{outgoing:up,onDecide:Xg,late:bd}):null,V=!it&&gl.folded.length?a.jsx(aEe,{blocks:gl.folded,reveal:mp,late:bd,onSafetyAnswered:yd,onContinue:Jg}):null;return C||T||V?a.jsxs(a.Fragment,{children:[V,T,C]}):void 0},[pd,Yg,op,up,Xg,it,gl,mp,yd,Jg,bd]),V1=y.useCallback(C=>{const T=D&&xn.current[D]?.access||Pn;if(el(C),nn(em,C),!D||(xn.current[D]&&(xn.current[D].access=C),!da.current.has(D)))return;Qa.current[D]=C;const V=D;te.invoke("chat_set_access",{key:nt(V),access:C}).catch(Z=>{const ie=String(Z.message??Z),Se=vEe(ie);if(Se!=="nothing"){if(Se==="put-back"){delete Qa.current[V],xn.current[V]&&(xn.current[V].access=T),V===rl.current&&(el(T),nn(em,T)),Tt(V,fe=>({...fe,notices:[...fe.notices,ie].slice(-8)}));return}Au(V,ie)}})},[D,Au,Pn,Tt]),ay=y.useCallback(async(C,T)=>{let V=null;if(da.current.has(C)){Qa.current[C]=T;try{await te.invoke("chat_set_access",{key:nt(C),access:T})}catch(Z){const ie=String(Z.message??Z);if(!ie.includes("no such chat")){if(!ie.includes("needs a fresh agent"))throw new Error(ie);V=ie}}}C===rl.current&&(el(T),nn(em,T)),xn.current[C]&&(xn.current[C].access=T),V&&Au(C,V)},[Au]),oy=y.useCallback(async(C,T)=>{const V=Uc(C);if(!V)return;const Z=(Se,fe)=>C.local?Promise.resolve():te.invoke("access_request_answer",{id:C.id,decision:Se,error:fe??null}).catch(()=>{}),ie=()=>{C.local?Tt(V,Se=>({...Se,accessNeed:void 0})):P0(Se=>({...Se,[V]:(Se[V]??[]).filter(fe=>fe.id!==C.id)}))};if(T==="decline"){await Z("declined"),ie();return}try{await ay(V,C.requested)}catch(Se){const fe=String(Se.message??Se);if(xEe(fe,!!C.wait)==="keep")throw Se;await Z("failed",fe),ie();return}await Z("raised"),ie()},[ay,Tt,P0]),bc=y.useMemo(()=>{const C=Xe.accessNeed;if(!D||!C)return null;const T=Uq("antigravity",C.requested);return qq(Pn,T)?null:{id:`refusal:${D}`,chatKey:nt(D),agent:"antigravity",current:Pn,requested:T,reason:C.reason,takes:"between-turns",wait:!1,local:!0}},[Xe.accessNeed,D,Pn]),ev=y.useMemo(()=>[...D?Bf[D]??[]:[],...bc?[bc]:[]],[Bf,D,bc]),xp=async C=>{if(!ot)throw new Error("Choose a project before starting a mission.");if(it)throw new Error("Start runs from the main chat.");if(Ct.agent==="pi")throw new Error("Choose Codex, Claude or Antigravity as the main agent.");const T=D??crypto.randomUUID(),V=ha.current.get(T);if(V&&await V,yn.current[T]?.busy)throw new Error("Wait for the main agent's turn to finish before starting a run.");const Z=bn.current.find(rt=>rt.id===T),ie=Date.now(),Se={...Z??{},id:T,projectId:ot.id,title:Z?.title??Gb(C),cwd:Z?.cwd??yn.current[T]?.cwd??ot.primary_path,sessionId:js.current.has(T)?void 0:yn.current[T]?.sessionId??Z?.sessionId,messages:yn.current[T]?.messages??Z?.messages??[],modelId:Ct.id,permission:Pn,effort:us,createdAt:Z?.createdAt??ie,updatedAt:ie};await te.invoke("chat_index_save",{meta:{...Se,messages:void 0,sessionId:Se.sessionId??null,access:Pn,pinned:Se.pinned??!1,generation:Se.generation??0}}),xn.current[T]={projectId:ot.id,modelId:Ct.id,access:Pn,effort:us};const fe=[Se,...bn.current.filter(rt=>rt.id!==T)];return bn.current=fe,ye(fe),Ni(fe),Z||si.current.own(nt(T)),Tt(T,rt=>({...rt,cwd:Se.cwd})),Vr(rt=>({...rt,[T]:!0})),ki(rt=>({...rt,[T]:"run"})),Oe(T),nt(T)},ly=async C=>{const T=C.coordinatorChatKey.replace(/^chat:/,""),V=ha.current.get(T);V&&await V;const Z=js.current.has(T),ie=Z?QO(yn.current[T]?.messages??[])??"[]":void 0;await te.invoke("orchestration_master_start",{actorChatKey:C.coordinatorChatKey,runId:C.id,agent:Ct.agent,model:Ct.flag||null,access:Pn,effort:us,lite:nl,handoff:ie??null}),Z&&js.current.delete(T),$(Se=>new Set(Se).add(T))},Tu=(C,T)=>{const V=C.replace(/^chat:/,""),Z=bn.current.find(ie=>ie.id===V);if(!Z)throw new Error("This chat is not available yet. Wait for the chat list to sync and try again.");if(T){if(Xd(V,Qt))throw new Error("Send this decision in the main chat.");mt({id:V,text:T})}ki(ie=>({...ie,[V]:"chat"})),Es(Z)},Ru=!ui&&!!Cn.error,tv=y.useMemo(()=>({...F0,orchestration_snapshot:ui?"answered":Ru?"failed":"asked"}),[F0,ui,Ru]),wc=y.useMemo(()=>die({orchestration:Ln,parents:Qt,asks:lu,safetyBlocks:Jo,questions:Cg,accessRequests:Bf,handovers:xc,sources:tv,late:H0}),[Ln,Qt,lu,Jo,Cg,Bf,xc,tv,H0]),Ca=wc.actions,ja=wc.held,wd=y.useMemo(()=>mve(Jo,C=>!!O[C]?.busy&&!fd.has(C),VO).join(" "),[Jo,O,fd]),yp=y.useMemo(()=>Object.keys(O).filter(C=>eY(O[C])).sort().join(" "),[O]),vl=y.useMemo(()=>hve(Ca,new Set(wd?wd.split(" "):[]),{whole:wc.whole,restored:yp?yp.split(" "):[]}),[Ca,wd,wc.whole,yp]),_c=y.useMemo(()=>gve(hc,vl),[hc,vl]),nv=wc.whole;y.useEffect(()=>{const C=Date.now();for(const T of Object.keys(O))Tt(T,V=>ZG(V,fve(vl,T),C,nv))},[O,vl,nv,Tt]);const sv=D&&vl.get(D)||null,cy=y.useCallback(()=>{z0(),Jc.refresh().catch(()=>{})},[z0]),_d=y.useMemo(()=>Ca.filter(C=>C.cardMissing).map(C=>C.key).sort().join(" "),[Ca]);y.useEffect(()=>{_d&&t==="open"&&Vh()},[_d,t,Vh]);const[bp,Du]=y.useState(null),[wp,_p]=y.useState(null),kd=y.useCallback((C,T)=>{Vr(V=>({...V,[C]:!0})),ki(V=>({...V,[C]:"run"})),Du({chatKey:nt(C),runId:T,nonce:Date.now()})},[]),[Sd,Ls]=y.useState(null),pi=y.useCallback(C=>{if(!kt)return;const T=Date.now();Vr(V=>({...V,[kt]:!0})),ki(V=>({...V,[kt]:"run"})),Du({chatKey:nt(kt),runId:C.runId,taskId:C.id,nonce:T}),$h(kt),ku(!0),Zo(null),Ls({taskId:C.id,nonce:T})},[kt,ku]);y.useEffect(()=>{if(!Sd)return;const C=Date.now();let T=requestAnimationFrame(function V(){if(Uwe(Sd.taskId)||Date.now()-C>3e3){Ls(null);return}T=requestAnimationFrame(V)});return()=>cancelAnimationFrame(T)},[Sd]);const uy=y.useMemo(()=>oke(wa.plan,Cn.snapshot,Date.now(),ja),[wa.plan,Cn.snapshot,ja]),iv=y.useCallback(C=>{const T=bn.current.find(V=>V.id===C.openChatId);T&&(C.surface==="run"&&C.runId?kd(T.id,C.runId):ki(V=>({...V,[T.id]:"chat"})),Es(T),_p({action:C,nonce:Date.now()}),C.cardMissing&&Vh())},[Es,kd,Vh]);y.useEffect(()=>{if(!wp)return;const{action:C}=wp,T=Date.now();let V=!1,Z=requestAnimationFrame(function ie(){if(Ume(C.key)){_p(null),Du(null);return}if(!V&&C.kind==="plan"&&C.runId&&Date.now()-T>1200&&(V=!0,kd(C.openChatId,C.runId)),Date.now()-T>4e3){_p(null),Du(null);return}Z=requestAnimationFrame(ie)});return()=>cancelAnimationFrame(Z)},[wp,kd]);const rv=y.useMemo(()=>y$(Ca),[Ca]),hy=y.useMemo(()=>{const C=fie(Ca);return{forRow:T=>C.get(T)??eI,forTask:T=>rv.get(T)??eI,held:ja,reveal:iv}},[Ca,rv,ja,iv]),Cd=y.useMemo(()=>({snapshot:Cn.snapshot,stop:async C=>{await te.invoke("orchestration_task_stop",{taskId:C}),await Jc.refresh().catch(()=>{})}}),[Cn.snapshot]),kp=y.useMemo(()=>lbe(on,ja),[on,ja]),[jd,dy]=y.useState(()=>Sme(ls(lI))),xl=y.useMemo(()=>it||!D?null:wme(ir,Date.now(),ja),[it,D,ir,ja]),Sp=!!xl&&!kme(jd,xl.strip),av=()=>{if(!xl)return;const C=_me(jd,xl.strip.signature);dy(C),nn(lI,JSON.stringify(C))},fy=()=>{!xl||!D||(kd(D,xl.run.id),Va&&ku(!0))},py=async()=>{const[C,T,V]=await Promise.all([k_().catch(()=>sl),yo(null,!0).catch(()=>ni),S_().catch(()=>Zl)]);if($f(C),W0(V),Ag(T),LD(T,C?.id).length===0){ds();return}wu()},my=y.useMemo(()=>oe.filter(C=>!Xd(C.id,Qt)).map(({id:C,title:T,projectId:V,cwd:Z})=>({id:C,title:T,projectId:V,cwd:Z,busy:O[C]?.busy??q.has(C)})),[oe,Qt,O,q]),ov=y.useCallback(C=>{const T=bn.current.find(V=>V.id===C);T&&Es(T)},[Es]);if(t==="unauthorized")return a.jsx(Gve,{});const kc=C=>{z(!1),H(C==="pulls"),ee(C==="projects"?{projectId:null}:null),I(C==="search"),zt(C==="settings"),il(C==="agents")},mi=(C,T,V,Z={})=>({id:C,keep:T,node:V,...Z}),Ui=!Hi&&!Bn,Cp=mfe({kind:D?M4({key:nt(D),worker:it,frontDesk:ec.has(D)}):"worker",completing:!!D&&ep.has(D),connected:t==="open"}),Nd=kt?a5(wa.plan):0,jp=C=>kt&&a.jsx(Mke,{page:C,plan:wa.plan,chatId:kt,said:wa.said,error:wa.held?.error,unread:!wa.held,startTurnLost:Tfe(Xe.messages,wa.plan?.started?.turnId),flying:uy,connected:t==="open",onClose:()=>mc(!1,kt,C),onStart:T=>Vg(kt,T),onOpenTask:pi},kt),Np=Bn?[]:[Ui&&Va&&mi("tasks",100,a.jsx(f_e,{tasks:kp.tasks,decisions:kp.decisions,open:!Ro,onToggle:()=>{Ro&&$h(D),(!Ro||Bh)&&ku(Ro)}}),{attention:Ro?kp.decisions:0}),Ui&&kt&&mi("plan",95,a.jsx(jke,{questions:Nd,open:oo,onToggle:()=>{Er.setOpen(!1),mc(!oo,kt,Ve)}}),{attention:oo?0:Nd}),Ui&&D&&mi("preview",90,a.jsx(M1e,{count:u9(Er.images).length,open:Er.open,onClick:()=>Er.setOpen(!Er.open)})),Ui&&hl&&mi("git",85,a.jsx(Yye,{project:hl,open:Ql&&!Xr,onToggle:()=>{Er.setOpen(!1),ld(Xr||!Ql)}})),Ui&&ot&&!bt&&mi("focus",80,a.jsx(JO,{onClick:Pt})),!jn&&mi("new",70,a.jsxs("button",{className:"icon-btn new-chat",type:"button","aria-label":"Start new task",title:"Start new task",onClick:wu,children:[a.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:a.jsx("path",{d:"M12 5v14M5 12h14"})}),a.jsx("span",{className:"topbar-action-label",children:"New task"})]})),Ui&&D&&mi("details",60,a.jsx(p9,{action:!0,chatId:D,connected:t==="open",context:fi,busy:Xe.busy&&!$o,waiting:sv})),Ui&&Xe.agents.length>0&&mi("agents",66,a.jsx(zpe,{count:Xe.agents.length,open:!If&&!Xr,onToggle:()=>{Er.setOpen(!1),cd(Xr||If)}})),Ui&&Gf.length>0&&mi("pinned",64,a.jsx(U1e,{count:Gf.length,open:kr&&!Xr,onToggle:()=>{Er.setOpen(!1),pc(Xr||!kr)}})),Ui&&Xn&&Ve&&mi("width",30,a.jsx(Q1e,{expanded:at,onToggle:od})),Ui&&!jn&&!it&&mi("run",68,a.jsxs("button",{className:`orch-toggle${ys==="run"&&hi?" is-on":""}`,type:"button",title:on.runs.length?"Open this chat's runs":"Start a supervised run","aria-label":on.runs.length?"Open this chat's runs":"Start a supervised run",onClick:()=>{Vr(C=>({...C,[Fi]:!0})),de("run"),ku(!0)},children:[a.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:[a.jsx("circle",{cx:"5.5",cy:"12",r:"2.2"}),a.jsx("circle",{cx:"18.5",cy:"6",r:"2.2"}),a.jsx("circle",{cx:"18.5",cy:"18",r:"2.2"}),a.jsx("path",{d:"M7.7 12h3.1a2.2 2.2 0 0 0 2.2-2.2V8.2A2.2 2.2 0 0 1 15.2 6h1.1M7.7 12h3.1a2.2 2.2 0 0 1 2.2 2.2v1.6a2.2 2.2 0 0 0 2.2 2.2h1.1"})]}),a.jsx("span",{className:"topbar-action-label",children:"Run"})]})),pA()&&mi("reload",40,a.jsx(Z1e,{})),Ui&&D&&mi("copy-id",20,a.jsx(Lke,{chatId:D})),Ui&&D&&Cp.shown&&mi("complete",50,a.jsx(Ffe,{action:Cp,onClick:()=>tp(D)})),Ui&&D&&!it&&mi("delete",10,a.jsx(Ime,{deleting:Qf.has(D),disabled:ur.has(D),deleteMs:kC,onDelete:()=>Ms(D)}),{separated:!0})].filter(C=>!!C),Ap={onChat:Ui,actions:Np.length,loaded:f,arriving:!!St},lv=_ye({...Ap,chat:!!D||!!St,remembered:g}),uo=Ve&&(lv||Np.length>0),Ep=a.jsx(Iye,{antigravity:eo?.includes("antigravity")??!1}),gy=D?Ca.filter(C=>C.surface==="chat"&&C.openChatId===D).length:0;return a.jsx(nse,{value:lw,children:a.jsx(Ez.Provider,{value:Et,children:a.jsx(_1.Provider,{value:jn?ni:r5e,children:a.jsx(zE.Provider,{value:cl,children:a.jsx(jz.Provider,{value:hy,children:a.jsx(u$.Provider,{value:Cd,children:a.jsxs("div",{ref:Ne,className:`app ${Bn?"projects-screen":""} ${Je?"nav-shut":""} ${at?"chat-wide":""} ${xt?"focus-mode":""}`,style:xt?$Ee(dn):Qxe(nr,at),children:[xt&&a.jsxs("div",{className:"focus-mode-tools",children:[a.jsx(zEe,{fontSize:dn,onChange:gs}),a.jsx(JO,{active:!0,onClick:Qn})]}),a.jsx(nge,{projects:n,projectsReady:f,chatsReady:Ze,shelved:u,deletedCount:k.length,onShowDeleted:()=>M(!0),conversations:Bo,chatParents:Qt,orchestration:Ln,ledgerSnapshot:Cn.snapshot,ledgerUnavailable:Bg,coordinatorChatKeys:so,getPreviewMessages:C=>si.current.holds(nt(C))?O[C]?.messages:void 0,loadPreview:V0,currentConversation:D,running:q,busy:hc,waiting:vl,completing:ep,deleting:Qf,leaving:ur,deleteMs:kC,onPickConversation:C=>{Es(C)},onNewChat:jn?()=>{py()}:wu,newLabel:jn?"New conversation":"New task",allowEmptyCreate:!jn,onDelete:Ms,onPin:Zf,onToggleDone:ju,onRename:vc,onArchiveWorker:async(C,T)=>{const V=Ln.attempts.find(ie=>ie.id===C),Z=Ln.runs.find(ie=>ie.id===V?.runId);if(!Z)throw new Error("This worker's run is unavailable. Reconnect and try again.");await te.invoke("orchestration_worker_archive",{actorChatKey:Z.coordinatorChatKey,attemptId:C,archived:T})},branches:i,onResize:Ve?void 0:vs.startDrag,onCollapse:Ve?void 0:()=>{_u(!1),requestAnimationFrame(()=>fn.current?.focus())},onSearch:()=>kc("search"),onSettings:()=>kc("settings"),onAgents:jn?()=>kc("agents"):void 0,onProjects:()=>kc("projects"),onPullRequests:()=>kc("pulls"),activeView:Q?"search":U?"projects":Wf&&jn?"agents":W?"pulls":Rt?"settings":null}),a.jsxs("div",{className:"shell-main",children:[a.jsxs("header",{className:"topbar",children:[a.jsxs("div",{className:"topbar-leading",children:[Bn?a.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:[a.jsx("img",{className:"topbar-logo",src:"./icon-192.png",alt:"","aria-hidden":"true"}),a.jsxs("span",{className:"topbar-identity",children:[a.jsx("span",{className:"topbar-name",children:"Chats"}),a.jsxs("span",{className:"topbar-version",children:["OctiqFlow v","0.3.13"]})]})]}):(Ve||Je)&&a.jsxs("button",{ref:fn,className:`topbar-nav${Ve?"":" is-brand"}`,type:"button","aria-label":Ve?"Show chats":"Show sidebar",title:Ve?"Show chats":"Show sidebar · OctiqFlow v0.3.13","aria-expanded":!1,disabled:!Ve&&at,onClick:()=>{Ve?(ke(!1),z(!0)):(_u(!0),requestAnimationFrame(()=>document.querySelector(".sidebar-collapse")?.focus()))},children:[!Ve&&a.jsx("img",{className:"topbar-nav-logo",src:"./icon-192.png",alt:"","aria-hidden":"true"}),a.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:[a.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),a.jsx("path",{d:"M9 4v16M13 10l2 2-2 2"})]})]}),a.jsx("div",{className:"topbar-page",ref:J,hidden:!Hi||Bn}),!Bn&&!Hi&&a.jsxs("span",{className:`topbar-chat enter-gated ${mh(x)}`,title:ot?.primary_path,children:[ot&&a.jsx(Mh,{project:ot,size:"small",className:"topbar-project-avatar"}),a.jsx("span",{className:"topbar-name",children:ot?.name??(D?"Chat":jn?sl?.name??"CTO":"New chat")})]}),a.jsx("div",{className:"topbar-context",ref:le,hidden:Hi||Bn}),a.jsx(Yve,{state:t})]}),(Bn||Ve&&!uo)&&a.jsx("div",{className:"topbar-actions",children:Bn?a.jsxs("button",{className:"projects-return",type:"button","aria-label":"Return to chat",title:"Return to chat",onClick:()=>z(!1),children:[a.jsx("span",{children:"Return to chat"}),a.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:a.jsx("path",{d:"M5 12h14m-6-6 6 6-6 6"})})]}):Ep})]}),!Bn&&a.jsx(Dke,{className:mh(x),actions:Np,scrolls:Ve,reserved:lv,seen:kye(Ap),lead:!Ve&&a.jsx("div",{className:"topbar-page-actions",ref:ne,hidden:!Hi}),end:uo?Ep:null}),!Ve&&a.jsx(Bye,{}),a.jsxs("div",{className:"body",id:"dock",children:[a.jsxs("main",{className:"main",hidden:Bn,ref:qs,children:[W&&a.jsx(YEe,{projects:n,initialProjectId:o,chats:my,agent:{provider:Hn(Ct.agent).name,model:Ct.model,access:Rm(Ct.agent,Pn)},connected:t==="open",onClose:()=>H(!1),onPrepareChat:q1,onOpenChat:ov}),U&&a.jsx(gge,{projects:n,shelved:u,conversations:oe,selectedProjectId:U.projectId,busy:_c,chatParents:Qt,ledgerSnapshot:Cn.snapshot,coordinatorChatKeys:so,allowNewTask:!jn,onSelectProject:C=>ee({projectId:C}),onOpenChat:Es,onNewTask:C=>{wu(),l(C)},onNewProject:()=>ut("new"),onProjectSettings:ut,onShowShelved:()=>_(!0),onRestoreProject:async C=>{await te.invoke("set_workspace_shelved",{id:C,shelved:!1}),await ma()},onClose:()=>ee(null)}),Q&&a.jsx(vxe,{conversations:Bo,chatParents:Qt,projects:[...n,...u],ledgerSnapshot:Cn.snapshot,ledgerUnavailable:Bg,coordinatorChatKeys:so,searchChats:to,onOpenChat:Es,onClose:()=>I(!1),deletedCount:k.length,onShowDeleted:()=>M(!0)}),Rt&&a.jsx(Q0e,{current:Fh,onPick:Qo,chatWidth:nr,onChatWidth:be,notify:Rg,onNotify:(C,T)=>{z1(C),Og(C&&T)},projects:[...n,...u],onProject:ut,agentsMode:jn,onAgentsMode:$1,onFeedback:()=>Dt(!0),initialSection:Mg,onClose:()=>{zt(!1),Hf("projects")}}),Wf&&jn&&a.jsx(pye,{snapshot:Cn.snapshot,ledgerError:Cn.error,connected:t==="open",projects:[...n,...u],running:q,busy:hc,held:ja,waitingOn:C=>{const T=C.replace(/^chat:/,"");return Ca.filter(V=>V.chatId===T).length},chatTitle:C=>oe.find(T=>nt(T.id)===C)?.title,chatExists:C=>oe.some(T=>nt(T.id)===C),onOpenChat:C=>{Tu(C),il(!1)},onOpenRun:(C,T)=>{Tu(C);const V=C.replace(/^chat:/,"");Vr(Z=>({...Z,[V]:!0})),ki(Z=>({...Z,[V]:"run"})),Xl(Z=>({...Z,[C]:T})),il(!1)},onManage:ds,onClose:()=>il(!1)}),!Hi&&va&&jp(!0),a.jsx("div",{className:`chat-app-surface ${mh(x)}`,hidden:Hi||va,children:bt?a.jsxs("div",{className:"hero",role:"status",children:[a.jsx("h1",{className:"hero-title",children:"Chat unavailable"}),a.jsx("p",{children:"This chat was deleted or is no longer in this profile. Choose another chat from the chat list."})]}):a.jsxs(a.Fragment,{children:[(!it||hi)&&a.jsx(d_e,{snapshot:on,orchestrated:hi,view:ys,focusMode:xt,split:Va,unified:hi,selectedRun:zh,worker:it,held:qr,onBackToMain:it&&(Ga??tt)&&!(hi&&(iu||ys==="run"))?()=>Tu(Ga??tt):void 0,onOpenBeside:it&&D&&!xt&&bu(nt(D))?()=>oc(nt(D)):void 0,besideTitle:Ci?.title,readOnly:it,planPending:!!zg?.approvable,pendingApprovals:gy,onView:de}),a.jsxs("div",{className:`workflow-surfaces${iu?" is-split":""}`,children:[hi&&a.jsxs("div",{className:`workflow-run-surface ${mh(xs)}`,hidden:Va?Ro:ys!=="run",style:{"--run-w":`${zi.width}px`},children:[iu&&a.jsx("div",{className:"workflow-run-resizer",role:"separator","aria-orientation":"vertical","aria-label":"Resize the run column",onPointerDown:zi.startDrag}),!qr&&a.jsx(Dwe,{embedded:!0,sharedHeading:!0,project:ot,coordinatorKey:tt,allowManualRun:!jn,pendingApprovals:it?0:gy,focusRun:bp&&bp.chatKey===tt?bp:null,projectName:C=>[...n,...u].find(T=>T.id===C)?.name,onSelectedRunChange:yg,coordinatorBusy:!it&&Xe.busy&&!$o,currentChatKey:D?nt(D):null,initialSnapshot:Ln,currentCwd:ya,onEnsureCoordinator:xp,onStartMaster:ly,onOpenChat:Tu,onClose:()=>de("chat"),onOpenBeside:xt?void 0:oc,besideChatKey:Jt?nt(Jt):null,setupContext:a.jsxs("div",{className:"workflow-setup-context",children:[a.jsxs("label",{children:["Project",a.jsxs("select",{"aria-label":"Run project",value:ot?.id??"",disabled:!!D,onChange:C=>ao(C.target.value||null),children:[a.jsx("option",{value:"",children:"Choose a project"}),n.map(C=>a.jsx("option",{value:C.id,children:C.name},C.id))]})]}),a.jsxs("label",{children:["Main agent",a.jsxs("select",{"aria-label":"Main agent",value:Ct.id,onChange:C=>{const T=Ba.find(V=>V.id===C.target.value);T&&dd(T)},children:[Ct.agent==="pi"&&a.jsx("option",{value:Ct.id,disabled:!0,children:"Choose Codex, Claude or Antigravity"}),Ba.filter(C=>C.agent!=="pi"&&(!eo||eo.includes(C.agent))).map(C=>a.jsxs("option",{value:C.id,children:[C.name," · ",C.model]},C.id))]})]}),a.jsx("p",{children:"Keep talking in Chat. Worker providers are independent of the main agent."})]})})]}),a.jsxs("div",{className:"workflow-chat-surface",hidden:Vn,ref:Wt,children:[Jt&&Un&&!gu&&a.jsx(Jke,{showing:ve,taskTitle:Un.title,onShow:Ie,onClose:Fg}),a.jsxs("div",{className:`beside-panes${ed?" is-split":""}`,children:[a.jsxs("div",{className:"beside-pane is-main",hidden:!td,...Jt?{role:"region","aria-label":"Main chat"}:{},children:[ed&&a.jsx(Zke,{persona:ul}),it&&!hi&&a.jsx("div",{className:"read-only-strip",children:a.jsx(n5,{})}),D&&Lg[D]&&Xe.messages.length>0&&a.jsx("div",{className:"chat-sync-note",role:"status",children:a.jsx("span",{children:"Updating conversation…"})}),Xe.messages.length===0&&D&&Lg[D]?a.jsxs("div",{className:"hero is-waiting",children:[a.jsx("div",{className:"dots","aria-label":"opening"}),a.jsxs("p",{className:"hero-sub",children:["opening “",hu[D]?.title??oe.find(C=>C.id===D)?.title??"the session","”…"]})]}):Xe.messages.length===0&&it?a.jsxs("div",{className:"hero",children:[a.jsx("h1",{className:"hero-title",children:"Agent conversation"}),a.jsx("p",{className:"hero-sub",children:"The agent's progress will appear here. Send instructions in the main chat."})]}):Xe.messages.length===0&&ir.runs.length>0?a.jsxs("div",{className:"hero",children:[a.jsx("h2",{className:"hero-title",children:"Main chat"}),a.jsx("p",{className:"hero-sub",children:"Talk with the main agent here. Select a task to follow its conversation."})]}):Xe.messages.length===0?a.jsxs("div",{className:`hero enter-gated ${ot?"":"hero-start"}${Ns?" is-agent-welcome":""}`,children:[a.jsx("h1",{className:"hero-title",children:Ns&&hs?`Talk to ${hs.name}`:Ns&&Ar.length>0?"Choose who you talk to":Ns?ot?`What's the task in ${ot.name}?`:"What's the task?":ot?`What do you want to do in ${ot.name}?`:"What should we work on?"}),Ns&&hs&&a.jsx(j0e,{name:hs.name,role:hs.role??"",greeting:Yr?E0e:void 0,scope:Yr?"Your front desk":xa?"Works across every project":`Works ${hs.projectId?`only in ${ot?.name??"its project"}`:"in any project"}`,how:Yr?"Say what you need. It finds the right agent and project, shows you who on a card, and opens that agent's chat with your request once you confirm.":xa?"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."},hs.id),(!ot||Ns)&&Ut&&a.jsx("p",{className:"hero-route-error",role:"alert",children:Ut}),Ns&&Yr&&wn&&a.jsx(vye,{name:wn.name,chats:hp,now:Date.now(),onContinue:C=>{J0(C)}}),Ns&&wn&&(Yr?a.jsxs("button",{className:"hero-link hero-roster-toggle",type:"button","aria-expanded":Ng,onClick:()=>Pf(C=>!C),children:["Talk to someone else",a.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:a.jsx("path",{d:"m6 9 6 6 6-6"})})]}):a.jsxs("button",{className:"hero-link hero-roster-toggle",type:"button",onClick:()=>{Ff(null),Pf(!1)},children:["Back to ",wn.name]})),Ns&&(!wn||Ng)&&a.jsx(P0e,{agents:wn?$g:Ar,selectedId:Yr?null:hs?.id??null,projectName:C=>n.find(T=>T.id===C)?.name,onPick:Hg,onManage:ds,showManage:!1,label:wn?"Talk to someone else":"Talk to"}),Ns&&a.jsxs("div",{className:"hero-links",children:[a.jsx("button",{className:"hero-link",type:"button",onClick:ds,children:"Manage agents"}),ot&&!it&&a.jsx(bD,{projectPath:ya,onResume:Xf})]}),Xe.sessionId&&(D&&hu[D]?a.jsxs("p",{className:"hero-sub",children:["continuing “",hu[D].title,"” ·"," ",Hn(hu[D].agent).name,hu[D].problem&&a.jsxs("span",{className:"hero-warn",children:[" ","· could not read it back (",hu[D].problem,"). Typing still carries on the session."]})]}):a.jsx("p",{className:"hero-sub",children:"continuing an earlier session"})),ot&&!it&&!Ns&&a.jsx(bD,{projectPath:ya,onResume:Xf})]}):a.jsx("div",{className:"chat-body",children:a.jsx(P7,{value:ya,children:a.jsx(YB,{value:Yf,children:a.jsx(ZB,{value:dc,children:a.jsxs("div",{className:"chat-main",children:[a.jsx(A$.Provider,{value:iy,children:a.jsx(sz,{messages:Xe.messages,tail:ry,head:ey,marks:ty,hasEarlier:!!D&&Ja.current.hasEarlier(D),loadingEarlier:!!D&&!!Xh[D]?.loading,earlierError:D?Xh[D]?.error:void 0,onLoadEarlier:K0,busy:Xe.busy&&!$o,stoppedAt:Xe.stoppedAt,compactingSince:Xe.compactingSince,conversationId:D??void 0,hostName:jT(ul,Hn(Ct.agent).name),hostPersona:ul,onCancelQueued:!it&&t==="open"?ip:void 0,onStartQueued:!it&&t==="open"?hd:void 0,onRestoreUnsent:it?void 0:rp,onDismissUnsent:it?void 0:Kg,onSetting:it?void 0:Lr,agentByTool:ad,onOpenAgent:gn})}),!it&&a.jsx(uEe,{toast:ny,onDetails:U1,onDone:gp}),uc&&a.jsx(Dpe,{run:uc,messages:Xe.messages,onBack:()=>gn(null)})]})})})})}),D&&a.jsx(So,{when:!!(ar||ba),scope:D,children:(ar||ba)&&a.jsxs("div",{className:`failure ${ar?.outOfCredit||ba?"is-quota":""}`,role:"alert",children:[ar&&!ba&&a.jsx("button",{className:"failure-close",type:"button","aria-label":"Dismiss",onClick:()=>{NY(D,ar),Tt(D,C=>({...C,failure:void 0}))},children:"×"}),a.jsx("div",{className:"failure-title",children:ar?.title??"Auto-resume scheduled"}),ar?.detail&&a.jsx("div",{className:"failure-detail",children:ar.detail}),ba&&a.jsxs("div",{className:"auto-resume-row",children:[a.jsxs("span",{children:["OctiqFlow will resume this ",ba.agent==="pi"?"Pi":tr[ba.agent]," session around"," ",new Date(ba.runAt*1e3).toLocaleString([],{dateStyle:"medium",timeStyle:"short"}),"."]}),!it&&a.jsx("button",{className:"auto-resume-cancel",type:"button",onClick:()=>{te.invoke("chat_cancel_auto_resume",{key:nt(D)}).catch(C=>{Tt(D,T=>({...T,notices:[...T.notices,`Could not cancel auto-resume: ${String(C.message??C)}`]}))})},children:"Cancel auto-resume"})]}),ar?.link&&a.jsx("a",{className:"failure-link",href:ar.link,target:"_blank",rel:"noreferrer noopener",children:ar.link})]})}),D&&!it&&a.jsx(KO,{scope:D,asks:lu[D]??[],safetyBlocks:gl.cards,onPermissionAnswered:C=>B0(T=>({...T,[D]:(T[D]??[]).filter(V=>V.id!==C)})),onSafetyAnswered:yd,onContinue:(C,T)=>Lr(C,[],T),accessRequests:ev,onAccessAnswer:oy}),D&&a.jsx(So,{when:!!Pe.snapshot?.environments[nt(D)]?.enabled,scope:D,children:Pe.snapshot?.environments[nt(D)]?.enabled&&a.jsx(rq,{environment:Pe.snapshot.environments[nt(D)],running:Xe.busy,onRefresh:Pe.refresh},D)}),Df&&hl&&a.jsx(gAe,{project:hl,onCommandsChanged:ma,onHide:()=>{Hh(!1),nn(CC,"0")}},hl.id),wg.map(C=>{const T=Jo[C]??[],V=T.filter(lj),Z=T.filter(fe=>!lj(fe));if((lu[C]?.length??0)+T.length===0)return null;const ie=oe.find(fe=>fe.id===C)?.title??"agent",Se=fe=>a.jsx(KO,{asks:fe===V?[]:lu[C]??[],safetyBlocks:fe,onPermissionAnswered:rt=>B0(gt=>({...gt,[C]:(gt[C]??[]).filter(Ae=>Ae.id!==rt)})),onSafetyAnswered:rt=>Sg(gt=>({...gt,[C]:(gt[C]??[]).filter(Ae=>Ae.id!==rt)})),onContinue:(rt,gt)=>Lr(`For your worker chat ${C}:
513
513
 
514
514
  ${rt}
515
515